From 05fdb77c98a66cde27c4f80ea7808bb9dbf8bf8e Mon Sep 17 00:00:00 2001 From: "Wyatt J. Miller" Date: Sat, 19 Sep 2020 12:43:21 -0400 Subject: [PATCH] glue code --- .../com/wyattjmiller/tictactoeapp/Gameboard.kt | 17 ++++++++++++----- .../wyattjmiller/tictactoeapp/MainActivity.kt | 6 ++++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/wyattjmiller/tictactoeapp/Gameboard.kt b/app/src/main/java/com/wyattjmiller/tictactoeapp/Gameboard.kt index c66f58d..0e4e285 100644 --- a/app/src/main/java/com/wyattjmiller/tictactoeapp/Gameboard.kt +++ b/app/src/main/java/com/wyattjmiller/tictactoeapp/Gameboard.kt @@ -3,6 +3,7 @@ package com.wyattjmiller.tictactoeapp class Gameboard { private var mGameState: GameState private var mGamePiece: GamePiece + var stats: Stats = Stats() enum class GameState { None, @@ -37,20 +38,26 @@ class Gameboard { if (gameState == MainActivity.GameOption.Won) { when (mGameState) { GameState.GamePlayerTurnX -> { - Stats().updateGamesWon(mGameState) mGameState = GameState.GamePlayerWinX + stats.updateGamesWon(mGameState) + } + GameState.GamePlayerTurnO -> { + mGameState = GameState.GamePlayerWinO + stats.updateGamesWon(mGameState) } - GameState.GamePlayerTurnO -> mGameState = GameState.GamePlayerWinO } - Stats().updateGamesPlayed() + stats.updateGamesPlayed() } else { - if (gameState == MainActivity.GameOption.Cats) mGameState = GameState.GameCat else { + if (gameState == MainActivity.GameOption.Cats) { + mGameState = GameState.GameCat + stats.updateGamesWon(mGameState) + } else { when (mGameState) { GameState.GamePlayerTurnX -> mGameState = GameState.GamePlayerTurnO GameState.GamePlayerTurnO -> mGameState = GameState.GamePlayerTurnX } - Stats().updatePiecePlaced() + stats.updatePiecePlaced() } } } diff --git a/app/src/main/java/com/wyattjmiller/tictactoeapp/MainActivity.kt b/app/src/main/java/com/wyattjmiller/tictactoeapp/MainActivity.kt index d153740..cbc6423 100644 --- a/app/src/main/java/com/wyattjmiller/tictactoeapp/MainActivity.kt +++ b/app/src/main/java/com/wyattjmiller/tictactoeapp/MainActivity.kt @@ -30,8 +30,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { // Private variables - other variables private lateinit var mAllButtonList: List