public void NewMove(string mark, Position move) { GameGrid.PlaceInGrid(mark, move); if (CurrentTurnMark == "X") { PlayerX.AddMove(move); } else { PlayerO.AddMove(move); } CheckWinner(); TurnNumber++; if (!HasFinished) { if (CurrentTurnMark == "X") { CurrentTurnMark = "O"; } else { CurrentTurnMark = "X"; } } }
// Returns a string describing the state of the game public override string ToString() { string xName = PlayerX.GetType().Name; string oName = PlayerO.GetType().Name; if (Status == null) { // Game is ongoing return(Turn + $" : It's {(Turn == CellState.X ? xName : oName)} turn"); } else { // Game is finished // Did someone make an illegal move? if (overrideWinner != CellState.Undecided) { return(string.Format( "Game Over : {0} wins since {1} made illegal move", Status == CellState.X ? xName : oName, Status != CellState.X ? xName : oName)); } // Game ended within the rules return("Game Over : " + (Status != CellState.Undecided ? $"{Status} ({(Status == CellState.X ? xName : oName)}) wins" : "It's a draw")); } }
// Make an automatic move private void DoAutoPlay() { // Choose move Vector2Int pos = Turn == CellState.X ? PlayerX.Play(gameBoard, Turn) : PlayerO.Play(gameBoard, Turn); // Perform the actual move Move(pos); }
public void PlayerMoved() { if (CurrentTurn == Turn.PlayerX) { if (PlayerX.GetType() == typeof(HumanPlayer)) { PlayerX.OnPlayerMoved(); } } else { if (PlayerO.GetType() == typeof(HumanPlayer)) { PlayerO.OnPlayerMoved(); } } }
public override int GetHashCode() { int hash = 1; if (LayerIndex != 0) { hash ^= LayerIndex.GetHashCode(); } if (InstanceId != 0) { hash ^= InstanceId.GetHashCode(); } if (PlayerX != 0) { hash ^= PlayerX.GetHashCode(); } if (PlayerY != 0) { hash ^= PlayerY.GetHashCode(); } return(hash); }
// Other methods /// <summary> /// Start the game /// </summary> public async void Start() { while (_isGameRunning) { if (CurrentTurn == Turn.PlayerX) { await PlayerX.MoveAsync(); if (_board.IsWin(Board.ElementType.X)) { GameOver("X wins!!!", _board.WinningIndexes); break; } CurrentTurn = Turn.PlayerO; } else { await PlayerO.MoveAsync(); if (_board.IsWin(Board.ElementType.O)) { GameOver("O wins!!!", _board.WinningIndexes); break; } CurrentTurn = Turn.PlayerX; } TurnChanged.Invoke(); if (!_board.IsMovesLeft()) { GameOver("Tie"); break; } } }
public override void Update(Player player, ref int buffIndex) { PlayerX p = (PlayerX)player.GetModPlayer(mod, "PlayerX"); p.inscribed = true; }
public override void Update(Player player, ref int buffIndex) { PlayerX p = (PlayerX)(player.GetModPlayer(mod, "PlayerX")); p.empowered = true; }
get => new Location(PlayerX, PlayerY, PlayerZ);