Created
May 27, 2019 16:29
-
-
Save sometowngeek/5f0de509a1c93bb87dffcb3f06918a95 to your computer and use it in GitHub Desktop.
This file contains 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
public class TicTacToe extends JFrame { | |
private boolean initialized; // Default = false | |
private XOButtons buttons; | |
private int scorePlayer1; | |
private int scorePlayer2; | |
// Reset the board | |
// Reset the markers, etc. | |
public void resetGame() { | |
this.scorePlayer1 = 0; | |
this.scorePlayer2 = 0; | |
this.buttons.resetMarkers(); | |
} | |
// Set up frame, buttons, score, etc. | |
public void newGame(){ | |
// If the application has not been initialized for the first time, | |
// setup the frame with everything else | |
if (!initialized){ | |
buttons = new XOButtons(); | |
// Set up frame | |
} | |
// Otherwise, reset the game | |
else { | |
buttons.resetMarkers(); | |
// Do other stuff... | |
} | |
} | |
// Play the game | |
public void play(){ | |
// For each round, | |
// a player chooses where to put their "X" or "O" | |
// add scores, etc. | |
// Then at the end of each round | |
if (this.buttons.winCheck()) | |
this.resetGame(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment