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

Completo juego TicTacToe #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

anarod13
Copy link

@anarod13 anarod13 commented Mar 9, 2022

No description provided.

const gameEnded = false;
const [tiles,setTiles] = React.useState(['','','','','','','','','']);
const [currentPlayer,setCurrentPlayer]= React.useState(initialPlayer);
const [winner,setWinner] = React.useState(null);
Copy link
Collaborator

Choose a reason for hiding this comment

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

en general, está bueno tratar de tener la menor cantidad de states posible. como el winner se puede sacar a partir del estado actual de los tiles, no es necesario que sea un state aparte. Si reemplazás esta línea por const winner = getWinner(tiles), debería andar igual y te ahorrás tener que setear el winner en setTileTo y restart

Comment on lines 111 to 128
<div className='tictactoe-row'>
<div className='square' value={tiles[0]} onClick={()=>{setTileTo(0, currentPlayer)}}>{tiles[0]}</div>
<div className='square' value={tiles[1]} onClick={()=>{setTileTo(1, currentPlayer)}}>{tiles[1]}</div>
<div className='square' value={tiles[2]} onClick={()=>{setTileTo(2, currentPlayer)}}>{tiles[2]}</div>
</div>
<div className='tictactoe-row'>
<div className='square' value={tiles[3]} onClick={()=>{setTileTo(3, currentPlayer)}}>{tiles[3]}
</div>
<div className='square' value={tiles[4]} onClick={()=>{setTileTo(4, currentPlayer)}}>{tiles[4]}
</div>
<div className='square' value={tiles[5]} onClick={()=>{setTileTo(5, currentPlayer)}}>{tiles[5]}
</div>
</div>
<div className='tictactoe-row'>
<div className='square' value={tiles[6]} onClick={()=>{setTileTo(6, currentPlayer)}}>{tiles[6]}</div>
<div className='square' value={tiles[7]} onClick={()=>{setTileTo(7, currentPlayer)}}>{tiles[7]}</div>
<div className='square' value={tiles[8]} onClick={()=>{setTileTo(8, currentPlayer)}}>{tiles[8]}</div>
</div> </div>
Copy link
Collaborator

Choose a reason for hiding this comment

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

acá se repite bastante código, se te ocurre como hacerlo más simple? capaz con un par de .map()s?

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.

2 participants