Created
December 13, 2019 10:19
-
-
Save SidneyMachara/cbbbc516b81bac15a77022a2328cba4a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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