diff --git a/app/src/main/java/com/wyattjmiller/tictactoeapp/Gameboard.kt b/app/src/main/java/com/wyattjmiller/tictactoeapp/Gameboard.kt index 5357ed7..c66f58d 100644 --- a/app/src/main/java/com/wyattjmiller/tictactoeapp/Gameboard.kt +++ b/app/src/main/java/com/wyattjmiller/tictactoeapp/Gameboard.kt @@ -1,24 +1,88 @@ package com.wyattjmiller.tictactoeapp -class Gameboard() { +class Gameboard { + private var mGameState: GameState + private var mGamePiece: GamePiece + enum class GameState { - GameStart, + None, GamePlayerTurnX, GamePlayerTurnO, GamePlayerWinX, GamePlayerWinO, - GameExit + GameCat } - enum class GamePiece { + private enum class GamePiece { None, X, O } + fun startGame() { + this.mGameState = GameState.GamePlayerTurnX + this.mGamePiece = GamePiece.X + } + fun resetGame() { + mGameState = GameState.GamePlayerTurnX + mGamePiece = GamePiece.X + } - companion object { } + fun placePlayerPiece(): String { + return mGamePiece.toString() + } - init { } + fun updateState(gameState: MainActivity.GameOption) { + if (gameState == MainActivity.GameOption.Won) { + when (mGameState) { + GameState.GamePlayerTurnX -> { + Stats().updateGamesWon(mGameState) + mGameState = GameState.GamePlayerWinX + } + GameState.GamePlayerTurnO -> mGameState = GameState.GamePlayerWinO + } + + Stats().updateGamesPlayed() + } else { + if (gameState == MainActivity.GameOption.Cats) mGameState = GameState.GameCat else { + when (mGameState) { + GameState.GamePlayerTurnX -> mGameState = GameState.GamePlayerTurnO + GameState.GamePlayerTurnO -> mGameState = GameState.GamePlayerTurnX + } + Stats().updatePiecePlaced() + } + } + } + + fun updateGameText(): String { + return when (mGameState) { + GameState.GamePlayerTurnX -> "It's Player's X turn!" + GameState.GamePlayerTurnO -> "It's Player's O turn!" + GameState.GamePlayerWinX -> "Player X wins!" + GameState.GamePlayerWinO -> "Player O wins!" + GameState.GameCat -> "Cat's game!" + else -> "" + } + } + + fun getNextPlayerPiece() { + when (mGamePiece) { + GamePiece.X -> { + mGamePiece = GamePiece.O + } + GamePiece.O -> { + mGamePiece = GamePiece.X + } + GamePiece.None -> { + // this shouldn't happen, ever + GamePiece.None + } + } + } + + init { + this.mGameState = GameState.None + this.mGamePiece = GamePiece.None + } } \ No newline at end of file