Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pine: Kayla H. & Mac P. #58

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Pine: Kayla H. & Mac P. #58

wants to merge 12 commits into from

Conversation

mac6551
Copy link

@mac6551 mac6551 commented Dec 22, 2021

No description provided.

Copy link

@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 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;

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 on lines +47 to +52
setSquares(boardCopy);
if (player === PLAYER_1) {
setPlayer(PLAYER_2);
} else {
setPlayer(PLAYER_1);
}

Choose a reason for hiding this comment

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

Good job updating state.

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 != ''

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 !=.

// all three squares have the same value.
let r = 0;
let c = 0;
let winner = '...';

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 on lines +90 to +91
setWinner(winner);
return winner;

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.

</header>
<main>
<Board squares={squares} />
<Board squares={squares} onClickCallback={onSquareClickCallback} />

Choose a reason for hiding this comment

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

Good job passing callback!

}

checkForWinner();
};

const checkForWinner = () => {

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.


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

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];

<Square
value={square.value}
id={square.id}
onClickCallback={onClickCallback}

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.

value={square.value}
id={square.id}
onClickCallback={onClickCallback}
key={square.id}

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