lmari’s blog

Data analytics, machine learning & front end development

Game Development - Tetris in React

f:id:lmari:20200112012206j:plain

First game development. Starter files can be found here.

Troubleshooting:

1. Solution to the absence of src folder in react app:

npm rm -g create-react-app
npm install -g create-react-app
npx create-react-app my-app

 

2. forEach is not a function in hooks>useStage.js

f:id:lmari:20200112012718j:plain

stackoverflow.com

So I changed line 28 and 29 from

player.tetromino.forEach((row, y) => {
row.forEach((value, x) => {

to:

[...player.tetromino].forEach(function(row, y) {
Array.from(row).forEach((value, x) => {

f:id:lmari:20200112012904j:plain

3. It turns out the Start button isn't working.It shows a blank gaming screen with no tetrominoes. The console shows:

[HMR] Waiting for update signal from WDS

f:id:lmari:20200112013707j:plain

The suggested solution is to create projects with:

npx create-react-app project-name --scripts-version 3.2.0

Soon I found out it has to do with StartButton.js. I leftout a chunk of code in styled components. What was I thinking?

const StyledStartButton = styled.button`
box-sizing: border-box;

margin: 0 0 20px 0;
padding: 20px;
min-height: 30px;
width: 100%;
border-radius: 20px;
border: none;
color: white;
background: #333;
font-family: Pixel, Arial, Helvetica, sans-serif;
font-size: 1rem;
outline: none;
cursor: pointer;
`;

And the game worked after inserting the code :)

Coding my first game was fun, especially Tetraminos.js and usePlayer.js:

f:id:lmari:20200112014028j:plain

f:id:lmari:20200112014352j:plain