added gameboard model
This commit is contained in:
parent
06036cf5f5
commit
e8bbc08fab
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
||||
companion object { }
|
||||
|
||||
init { }
|
||||
fun startGame() {
|
||||
this.mGameState = GameState.GamePlayerTurnX
|
||||
this.mGamePiece = GamePiece.X
|
||||
}
|
||||
|
||||
fun resetGame() {
|
||||
mGameState = GameState.GamePlayerTurnX
|
||||
mGamePiece = GamePiece.X
|
||||
}
|
||||
|
||||
fun placePlayerPiece(): String {
|
||||
return mGamePiece.toString()
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user