Skip to content

Instantly share code, notes, and snippets.

@SidneyMachara
Created December 13, 2019 10:19
Show Gist options
  • Save SidneyMachara/cbbbc516b81bac15a77022a2328cba4a to your computer and use it in GitHub Desktop.
Save SidneyMachara/cbbbc516b81bac15a77022a2328cba4a to your computer and use it in GitHub Desktop.
void play(int gameBtnId){
if( gameOver ){
return;
}
setState((){
if( activePlayer.playerHandle == "playerOne" ){
buttonsList[gameBtnId].text = "X";
buttonsList[gameBtnId].bg = Colors.red;
playerOne.playerMoves.add(buttonsList[gameBtnId].id); //add the btn to playerOne's collection
if( playerWon(playerOne.playerMoves) ){
print("one wins");
gameOver = true;
}
activePlayer = playerTwo;
//disable GameBtn
buttonsList[gameBtnId].enabled = false;
}
else if( activePlayer.playerHandle == "playerTwo" ){
buttonsList[gameBtnId].text = "0";
buttonsList[gameBtnId].bg = Colors.black;
playerTwo.playerMoves.add(buttonsList[gameBtnId].id); //add the btn to playerTwo's collection
if( playerWon(playerTwo.playerMoves)){
print("two wins");
gameOver = true;
}
activePlayer = playerOne;
//disable GameBtn
buttonsList[gameBtnId].enabled = false;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment