Esempio n. 1
0
 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";
         }
     }
 }
Esempio n. 2
0
        // 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"));
            }
        }
Esempio n. 3
0
    // 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);
    }
Esempio n. 4
0
 public void PlayerMoved()
 {
     if (CurrentTurn == Turn.PlayerX)
     {
         if (PlayerX.GetType() == typeof(HumanPlayer))
         {
             PlayerX.OnPlayerMoved();
         }
     }
     else
     {
         if (PlayerO.GetType() == typeof(HumanPlayer))
         {
             PlayerO.OnPlayerMoved();
         }
     }
 }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        // 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;
                }
            }
        }
Esempio n. 7
0
        public override void Update(Player player, ref int buffIndex)
        {
            PlayerX p = (PlayerX)player.GetModPlayer(mod, "PlayerX");

            p.inscribed = true;
        }
Esempio n. 8
0
        public override void Update(Player player, ref int buffIndex)
        {
            PlayerX p = (PlayerX)(player.GetModPlayer(mod, "PlayerX"));

            p.empowered = true;
        }
Esempio n. 9
0
 get => new Location(PlayerX, PlayerY, PlayerZ);