Skip to content

Instantly share code, notes, and snippets.

@timkeresey
Last active August 5, 2020 00:35
Show Gist options
  • Save timkeresey/d9cc51586197ff4ae500710292297f66 to your computer and use it in GitHub Desktop.
Save timkeresey/d9cc51586197ff4ae500710292297f66 to your computer and use it in GitHub Desktop.

Planning

Game Class

  • Method 1: A way to keep track of the data for the game board.

    • Will take player.token data and populate the game.board array at the position corresponding to the board grid.
    • Will increment turnCounter by 1.
    • insert player.token data at index of event target.
    • Will only allow that index space to be filled if it is an empty string.
    • call board display function that displays game.board array on the DOM.
    • call method that toggles to the next player.
  • Method 2: A way to keep track of which player's turn it currently is.

    • Will toggle between player instances, on each turn.
    • The turn property will start with player1 and be called after each token placement to switch the value of turn property to player2 for the next turn, and so on.
  • Method 3: A way to check the Game's board data for win conditions (3 consecutive).

    • Will determine whether or not player.token data occupies a combination of indices that constitute a winning sequence.
    • After each turn (run at end of method 1), this function will loop through the board array.
    • If any player has ids in all 3 indeces of any of the 8 winning index place combos, that player wins.
    • change value of winner property to a string of winning player.
  • Method 4: A way to detect when a game is a draw.

    • A draw will be determined if no winning index combination sequences are met.
    • After each turn, loop through the board array.
    • If no elements of the array are empty strings, and the value of the winner property is an empty string, change the value of draw property to true.
  • (Call at end on method 3)

  • Method 5: A way to save a winning Game's board data to the correct player's wins array.

    • When a winning sequence is met by a player, then the game instance data will be stored in that player instance's player.wins array.
    • the game instance will be saved to the player.wins array of the player determined by the value of the game.winner property.
  • Method 6: A way to reset the Game's board to begin a new game.

  • This will execute a timeout, then reset the game.board array back to empty strings at all indices after a game is completed.

  • Will clear the DOM of the previous game, then instatiate a new game object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment