-
Notifications
You must be signed in to change notification settings - Fork 80
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
base: main
Are you sure you want to change the base?
Conversation
… to all squares and not just the first column
… to all squares and not just the first column
…e is an empty string
There was a problem hiding this 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!
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice use of map!
setSquares(boardCopy); | ||
if (player === PLAYER_1) { | ||
setPlayer(PLAYER_2); | ||
} else { | ||
setPlayer(PLAYER_1); | ||
} |
There was a problem hiding this comment.
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 != '' |
There was a problem hiding this comment.
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 = '...'; |
There was a problem hiding this comment.
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
.
setWinner(winner); | ||
return winner; |
There was a problem hiding this comment.
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} /> |
There was a problem hiding this comment.
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 = () => { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job remembering key
!
No description provided.