/// <summary> /// Checks if someone won /// </summary> public void CheckGameState() { if (winner == IdentifyWinner.NULL) { //if there is empty spots game continues else game is over foreach (var spot in spotValues) { if (spot == Game.SpotState.empty) { GameState = true; break; } else { GameState = false; } } //if there is no empty spots and winner is null -> it's draw if (GameState != true) { winner = IdentifyWinner.draw; } } }
public GameLogic() { winSegments = new short[3] { 0, 0, 0 }; tileValues = new BoxState[maxSize]; winner = new IdentifyWinner(); }
/// <summary> /// Game constructor /// </summary> public Game() { winSegments = new short[3] { 0, 0, 0 }; spotValues = new SpotState[9]; winner = new IdentifyWinner(); foundWinPattern = false; PlayerTurn = true; GameState = true; }
public TicTac() { this.winSegments = new short[3] { 0, 0, 0 }; this.tileValues = new BoxState[9]; this.winner = new IdentifyWinner(); this.foundPattern = false; this.PlayerState = true; this.GameState = true; }
public void DefaultTileInit() { for (int i = 0; i < maxSize; ++i) { tileValues[i] = BoxState.free; } winner = IdentifyWinner.NULL; FoundPattern = false; FirstPlayerState = true; GameState = true; }
/// <summary> /// initialize board with all empty spots /// </summary> public void InitialBoard() { //all empty spots for (int i = 0; i < maxSize; ++i) { spotValues[i] = SpotState.empty; } //first turn is player's turn winner = IdentifyWinner.NULL; foundWinPattern = false; PlayerTurn = true; GameState = true; }
/// <summary> /// Get winner of game /// </summary> /// <param name="tempstate"></param> public void GetWinner(SpotState spotstate) { if (GameState != false) { GetWin(spotstate); if (foundWinPattern) { if (spotstate == SpotState.X) { winner = IdentifyWinner.player; } else if (spotstate == SpotState.O) { winner = IdentifyWinner.computer; } } CheckGameState(); } }
public void GetWinner(BoxState tempstate) { if (this.GameState != false) { Getwin(tempstate); if (FoundPattern) { if (tempstate == BoxState.cross) { winner = IdentifyWinner.player1; } else if (tempstate == BoxState.zero) { winner = IdentifyWinner.player2; } } CheckGameState(); } } ///
public void getWinner(BoxState tempstate) { if (this.GameState != false) { getwin(tempstate); if (foundPattern) { if (tempstate == BoxState.cross) { winner = IdentifyWinner.player; } else if (tempstate == BoxState.zero) { winner = IdentifyWinner.computer; } } this.checkGameState(); } }
public void CheckGameState() { if (this.winner == IdentifyWinner.NULL) { foreach (var tile in this.tileValues) { if (tile == BoxState.free) { this.GameState = true; break; } else { this.GameState = false; } } if (this.GameState != true) { winner = IdentifyWinner.stalemate; } } }
public void IdentifyWinnerSub() { IdentifyWinner.Invoke(); }