glue code
This commit is contained in:
parent
ddffc25db6
commit
05fdb77c98
@ -3,6 +3,7 @@ package com.wyattjmiller.tictactoeapp
|
|||||||
class Gameboard {
|
class Gameboard {
|
||||||
private var mGameState: GameState
|
private var mGameState: GameState
|
||||||
private var mGamePiece: GamePiece
|
private var mGamePiece: GamePiece
|
||||||
|
var stats: Stats = Stats()
|
||||||
|
|
||||||
enum class GameState {
|
enum class GameState {
|
||||||
None,
|
None,
|
||||||
@ -37,20 +38,26 @@ class Gameboard {
|
|||||||
if (gameState == MainActivity.GameOption.Won) {
|
if (gameState == MainActivity.GameOption.Won) {
|
||||||
when (mGameState) {
|
when (mGameState) {
|
||||||
GameState.GamePlayerTurnX -> {
|
GameState.GamePlayerTurnX -> {
|
||||||
Stats().updateGamesWon(mGameState)
|
|
||||||
mGameState = GameState.GamePlayerWinX
|
mGameState = GameState.GamePlayerWinX
|
||||||
|
stats.updateGamesWon(mGameState)
|
||||||
|
}
|
||||||
|
GameState.GamePlayerTurnO -> {
|
||||||
|
mGameState = GameState.GamePlayerWinO
|
||||||
|
stats.updateGamesWon(mGameState)
|
||||||
}
|
}
|
||||||
GameState.GamePlayerTurnO -> mGameState = GameState.GamePlayerWinO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Stats().updateGamesPlayed()
|
stats.updateGamesPlayed()
|
||||||
} else {
|
} else {
|
||||||
if (gameState == MainActivity.GameOption.Cats) mGameState = GameState.GameCat else {
|
if (gameState == MainActivity.GameOption.Cats) {
|
||||||
|
mGameState = GameState.GameCat
|
||||||
|
stats.updateGamesWon(mGameState)
|
||||||
|
} else {
|
||||||
when (mGameState) {
|
when (mGameState) {
|
||||||
GameState.GamePlayerTurnX -> mGameState = GameState.GamePlayerTurnO
|
GameState.GamePlayerTurnX -> mGameState = GameState.GamePlayerTurnO
|
||||||
GameState.GamePlayerTurnO -> mGameState = GameState.GamePlayerTurnX
|
GameState.GamePlayerTurnO -> mGameState = GameState.GamePlayerTurnX
|
||||||
}
|
}
|
||||||
Stats().updatePiecePlaced()
|
stats.updatePiecePlaced()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
|
|||||||
// Private variables - other variables
|
// Private variables - other variables
|
||||||
private lateinit var mAllButtonList: List<Button>
|
private lateinit var mAllButtonList: List<Button>
|
||||||
private var mGameWon: GameOption = GameOption.No
|
private var mGameWon: GameOption = GameOption.No
|
||||||
private var mGameboard = Gameboard()
|
var mGameboard = Gameboard()
|
||||||
private var mStats = Stats()
|
|
||||||
|
|
||||||
enum class GameOption {
|
enum class GameOption {
|
||||||
Won,
|
Won,
|
||||||
@ -151,6 +150,9 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
|
|||||||
|
|
||||||
fun clickGameStats(view: View?) {
|
fun clickGameStats(view: View?) {
|
||||||
// dialog appears for game stats
|
// dialog appears for game stats
|
||||||
|
val dialog = StatsDialogFragment()
|
||||||
|
dialog.sendStats(mGameboard.stats)
|
||||||
|
dialog.show(supportFragmentManager, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkGameState(button: Button) {
|
private fun checkGameState(button: Button) {
|
||||||
|
Loading…
Reference in New Issue
Block a user