Exemple #1
0
        /// <summary>
        /// Observes the given tiles made by player input and updates the game
        /// board accordingly
        /// </summary>
        /// <param name="currentTile">The current tile that the chosen player
        /// piece is.</param>
        /// <param name="afterTile">The tile that the chosen player piece
        /// desires to move to.</param>
        /// <param name="currentPlayer">Will observe the current player to
        /// correctly determine who is the enemy tile</param>
        private void UpdateGame(
            Tile currentTile, Tile afterTile, Tilestate currentPlayer)
        {
            switch (currentTile.CanMoveBetweenTile(afterTile, currentPlayer))
            {
            case MoveList.Impossible:
                userInterface.ErrorMessage(ErrorCode.IllMove);

                break;

            case MoveList.Possible:
                gameBoard.UpdateSimple(
                    currentTile, afterTile);

                gameBoard.Turn++;
                break;

            case MoveList.Enemy:
                gameBoard.UpdateEnemy(
                    currentTile, afterTile);

                gameBoard.Turn++;
                break;
            }
        }
Exemple #2
0
        /// <summary>
        /// Obtains the tile between two tiles.
        /// </summary>
        /// <param name="target">The target tile that will be compared alongside
        /// the instanced tile</param>
        /// <param name="playerState">Verifies which player is calling the
        /// method</param>
        /// <returns>The tile between</returns>
        public Tile GetTileBetween(Tile target, Tilestate playerState)
        {
            Tile     betweenTile = null;
            Position selfPos     = new Position(0, 0).IndToPos(index);
            Position targetPos   = new Position(0, 0).IndToPos(target.index);
            Position betweenPos  = new Position(0, 0);



            foreach (Tile t in Neighbours)
            {
                if (t == null)
                {
                    continue;
                }

                foreach (Tile s in target.Neighbours)
                {
                    if (s == null)
                    {
                        continue;
                    }

                    if (s.index == t.index)
                    {
                        bool aux = false;
                        betweenPos.IndToPos(s.index);

                        if (betweenPos.Row == targetPos.Row &&
                            betweenPos.Row == selfPos.Row)
                        {
                            aux = true;
                        }

                        if (CheckBetweenPossibilities(targetPos, selfPos))
                        {
                            aux = true;
                        }

                        if (aux)
                        {
                            if (t.State != playerState)
                            {
                                betweenTile = t;
                            }
                        }
                    }
                }
            }


            return(betweenTile);
        }
Exemple #3
0
 /// <summary>
 /// Selects the players turns at the start of the game
 /// </summary>
 /// <param name="firstPlayer">The selected player's color, that will
 /// determine who begins and who plays at each turn.</param>
 public void SelectPlayersTurn(Tilestate firstPlayer)
 {
     if (firstPlayer == Tilestate.Black)
     {
         // Selects Black to be the first player to play
         this.firstPlayer = firstPlayer;
         secondPlayer     = Tilestate.White;
     }
     else if (firstPlayer == Tilestate.White)
     {
         // Selects White to be the first player to play
         this.firstPlayer = firstPlayer;
         secondPlayer     = Tilestate.Black;
     }
     else
     {
         //Error message probably
     }
 }
Exemple #4
0
        /// <summary>
        /// Used in ShowBoard(). Observes the tile state and transforms it
        /// in a char symbol.
        /// </summary>
        /// <param name="state">A specific tile's state to decide what char
        /// it will return</param>
        /// <returns>A char representing a tile.</returns>
        private char StateToChar(Tilestate state)
        {
            // Initializes the char that will be returned
            char displayChar = ' ';

            switch (state)
            {
            case Tilestate.Empty:
                displayChar = '.';
                break;

            case Tilestate.Black:
                displayChar = 'B';
                break;

            case Tilestate.White:
                displayChar = 'W';
                break;
            }

            return(displayChar);
        }
Exemple #5
0
        /// <summary>
        /// A method that observes if a player can move between a tile.
        /// </summary>
        /// <param name="targetTile">The tile that the player wants to move to
        /// </param>
        /// <param name="playerState">The current player calling the method
        /// </param>
        /// <returns>A movelist enum refering the possibilities (Impossible to
        /// move), (Possible to move), (If can jump over enemy)</returns>
        public MoveList CanMoveBetweenTile(
            Tile targetTile, Tilestate playerState)
        {
            MoveList canMove = MoveList.Possible;
            MoveList aux     = MoveList.Impossible;

            foreach (Tile t in Neighbours)
            {
                if (t == null)
                {
                    continue;
                }

                if (t.index == targetTile.index)
                {
                    aux = MoveList.Possible;
                }
            }
            canMove = aux;

            if (canMove == MoveList.Impossible)
            {
                if (GetTileBetween(targetTile, playerState) != null)
                {
                    canMove = MoveList.Enemy;
                }
            }


            if (targetTile.State != Tilestate.Empty)
            {
                canMove = MoveList.Impossible;
            }

            return(canMove);
        }
Exemple #6
0
 /// <summary>
 /// Displays the current turn information.
 /// </summary>
 /// <param name="turn">The current numeric turn</param>
 /// <param name="player">The player of this turn</param>
 public void MessageTurn(int turn, Tilestate player)
 {
     Console.WriteLine($"\nTURN {turn}");
     Console.WriteLine($"{player} Piece Player round");
 }
Exemple #7
0
 /// <summary>
 /// Shows which player won at the end.
 /// </summary>
 /// <param name="winner">Defines who won the previous game.</param>
 public void MessageWinGame(Tilestate winner)
 {
     Console.WriteLine($"Congratulations, {winner} Player! You win!");
 }