Skip to content

Pine: Kayla H. & Mac P. #58

Open
mac6551 wants to merge 12 commits intoAda-C16:mainfrom
mac6551:main
Open

Pine: Kayla H. & Mac P. #58
mac6551 wants to merge 12 commits intoAda-C16:mainfrom
mac6551:main

Conversation

@mac6551
Copy link
Copy Markdown

@mac6551 mac6551 commented Dec 22, 2021

No description provided.

Copy link
Copy Markdown

@alope107 alope107 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job! State is managed well and callbacks are nicely passed through components. One small thing is that the game allows you to keep on playing even once someone has won and the winner can possibly change. You don't need to implement it, but you might consider what changes your code would need to prevent this. Great work and great display of your knowledge of React!

Comment thread src/App.js
Comment on lines +33 to +45
const boardCopy = squares.map((row) => {
row.forEach((column) => {
if (column.id === id) {
if (column.value === '') {
if (player === PLAYER_1) {
column.value = PLAYER_1;
} else {
column.value = PLAYER_2;
}
}
}
});
return row;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of map!

Comment thread src/App.js
Comment on lines +47 to +52
setSquares(boardCopy);
if (player === PLAYER_1) {
setPlayer(PLAYER_2);
} else {
setPlayer(PLAYER_1);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job updating state.

Comment thread src/App.js
if (
squares[r][c + 2].value === squares[r + 1][c + 1].value &&
squares[r + 1][c + 1].value === squares[r + 2][c].value &&
squares[r][c].value != ''
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to use strict inequality !== instead of normal inequality !=.

Comment thread src/App.js
// all three squares have the same value.
let r = 0;
let c = 0;
let winner = '...';
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider having this be a top-level const like PLAYER_1 or PLAYER_2.

Comment thread src/App.js
Comment on lines +90 to +91
setWinner(winner);
return winner;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unclear why some winning lines return the winner and others do not.

Comment thread src/App.js
</header>
<main>
<Board squares={squares} />
<Board squares={squares} onClickCallback={onSquareClickCallback} />
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job passing callback!

Comment thread src/App.js
checkForWinner();
};

const checkForWinner = () => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider additional logic that prevents the game from continuing once someone has won.

Comment thread src/components/Board.js

}
console.log('genereate square components func', squares);
const squareComponents = [].concat(...squares);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One slightly simpler way to do this is const squareComponents = [...squares];

Comment thread src/components/Board.js
<Square
value={square.value}
id={square.id}
onClickCallback={onClickCallback}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job continuing to pass state down.

Comment thread src/components/Board.js
value={square.value}
id={square.id}
onClickCallback={onClickCallback}
key={square.id}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job remembering key!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants