Esempio n. 1
0
        /// <summary>
        /// this method gets a ghost, its position and a new position to where
        /// the player wants to move it, and updates the portals if there's
        /// been a battle between ghosts. it doesn't return anything.
        /// </summary>
        /// <param name="piece"> the current ghost type</param>
        /// <param name="newPos"> the position to which it's been moved</param>
        /// <param name="oldPos"> the position it was originally in</param>
        private static void MovePiece(BoardPiece piece, Position newPos, Position oldPos)
        {

            // placing the piece in the new position and updating the board
            board.pieces[newPos.Row, newPos.Col] = 
                GameBoard.GetBoardSettings(newPos);
            board.pieces[oldPos.Row, oldPos.Col] = piece;

            // send piece information to UpdatePortal to check if rotation is due

            board.pieces[newPos.Row, newPos.Col] = GameBoard.GetBoardSettings(newPos);
            board.pieces[oldPos.Row, oldPos.Col] = piece;

            board.UpdatePortal(piece.color);
        }
Esempio n. 2
0
        /// <summary>
        /// this method places all the different pieces on the board
        /// </summary>
        internal GameBoard()
        {
            // initialise variable to convert symbols to string for rendering
            string c;

            // declare the string
            c = Convert.ToString((char)Symbols.Corridor);

            // place pieces on the piece array and set their colour and symbol
            pieces = new BoardPiece[width, height];
            pieces[0, 0] = new BoardPiece(c, ConsoleColor.Blue);
            pieces[0, 1] = new BoardPiece(c, ConsoleColor.Red);
            pieces[0, 2] = new RedPortal(Direction.up);
            pieces[0, 3] = new BoardPiece(c, ConsoleColor.Blue);
            pieces[0, 4] = new BoardPiece(c, ConsoleColor.Red);

            pieces[1, 0] = new BoardPiece(c, ConsoleColor.Yellow);
            pieces[1, 1] = new Mirror();
            pieces[1, 2] = new BoardPiece(c, ConsoleColor.Yellow);
            pieces[1, 3] = new Mirror();
            pieces[1, 4] = new BoardPiece(c, ConsoleColor.Yellow);

            pieces[2, 0] = new BoardPiece(c, ConsoleColor.Red);
            pieces[2, 1] = new BoardPiece(c, ConsoleColor.Blue);
            pieces[2, 2] = new BoardPiece(c, ConsoleColor.Red);
            pieces[2, 3] = new BoardPiece(c, ConsoleColor.Blue);
            pieces[2, 4] = new YellowPortal(Direction.right);

            pieces[3, 0] = new BoardPiece(c, ConsoleColor.Blue);
            pieces[3, 1] = new Mirror();
            pieces[3, 2] = new BoardPiece(c, ConsoleColor.Yellow);
            pieces[3, 3] = new Mirror();
            pieces[3, 4] = new BoardPiece(c, ConsoleColor.Red);

            pieces[4, 0] = new BoardPiece(c, ConsoleColor.Yellow);
            pieces[4, 1] = new BoardPiece(c, ConsoleColor.Red);
            pieces[4, 2] = new BluePortal(Direction.down);
            pieces[4, 3] = new BoardPiece(c, ConsoleColor.Blue);
            pieces[4, 4] = new BoardPiece(c, ConsoleColor.Yellow);

            
        }
Esempio n. 3
0
        /// <summary>
        /// this method checks what ghost lost a fight and calls the portal
        /// update function in the Portal class in order to turn it, sends
        /// the ghost to the dungeon
        /// </summary>
        /// <param name="piece">checks the ghost that lost</param>
        internal void OnPieceLost(BoardPiece piece)
        {
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    // finds the portal with the colour that matches the ghost
                    if (pieces[i, j] is Portals portal &&
                        portal.color == piece.color)
                    {
                        // rotates the portal
                        portal.Turn();
                        UpdatePortal(portal.color);
                        break;
                    }
                }
            }

            // checks the ghost that lost and sends it to the dungeon
            if (piece is Ghosts ghost)
            {
                dungeonGhosts.Add(ghost);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// this method returns nothing. it's purpose is to update the board
        /// </summary>
        private static void Update()
        {

            // if the dungeon has any ghost belonging to this player
            if (board.CountdungeonGhostsForPlayer(currentPlayer) > 0)
            {
                Console.WriteLine("Do you wish to move(m) or revive(r) " +
                    "a ghost in the dungeon?");
                // if player chose to revive
                if (Console.ReadLine().ToUpper() == "R")
                {
                    // get the ghost's position from the dungeon
                    Console.WriteLine("Input ghost's dungeon coordinates");

            if (board.CountdungeonGhostsForPlayer(currentPlayer) > 0)
            {
                Console.WriteLine("Quer mover ou ressuscitar um fantasma? (R/F)");
                if (Console.ReadLine().ToUpper() == "R")
                {
                    Console.WriteLine("Que fantasma que ressuscitar?");

                    Ghosts ghost = board.GetDungeonGhost(Console.ReadLine());

                    if (ghost != null)
                    {
                        BoardPiece fPiece = null;
                        Position fPos = null;


                        // ask player to place ghost on the board from dungeon
                        do
                        {
                            // get input on board
                            Console.WriteLine("Input position on board");

                        do
                        {
                            Console.WriteLine("Que posição quer por o fantasma?");

                            fPos = Player.GetPosition(board);
                            fPiece = board.GetPiece(fPos);
                        }
                        while (fPiece is Ghosts || fPiece is Portals);


                        // place ghost back on board
                        board.pieces[fPos.Row, fPos.Col] = ghost;

                        // remove dungeon ghost

                        board.pieces[fPos.Row, fPos.Col] = ghost;

                        board.dungeonGhosts.Remove(ghost);

                        board.UpdatePortal(ghost.color);
                    }

                    return;
                }
            }
           
            // set the default pieces to null to use and replace them later
            BoardPiece piece = null;

            // get a variable of Position type to simplify use
            Position pos;

            // to ask the player which ghost they want to move and getting it
            do
            {
                Console.WriteLine("Que fantasma quer mover?");
                pos = Player.GetPosition(board);
                piece = board.GetPiece(pos);
            }
            // do while piece belongs to the player
            while (!(piece is Ghosts ghost && ghost.player == currentPlayer));

            // auxiliary piece to check types of corridors that aren't ghosts
            BoardPiece auxPiece;
            Position auxPosition; 
            bool isValidPosition;
            
            // declare the new piece's values as null to use for different types
            auxPiece = null;
            auxPosition = null;
            isValidPosition = false;

            // ask player where to move the piece and check for it's validity
            do
            {

                // get coordinates of new position


                Console.WriteLine("Where do you want to move it to?");

                auxPosition = Player.GetPosition(board);
                auxPiece = board.GetPiece(auxPosition);

                // check if the movement is within possible moves

                uint abs1 = (uint)Math.Abs(auxPosition.Row - pos.Row);
                uint abs2 = (uint)Math.Abs(auxPosition.Col - pos.Col);

                isValidPosition = (abs1 <= 1 && abs2 <= 1 && abs1 + abs2 <= 1);
            }
            while (auxPiece is Portals || !isValidPosition);


            // if the piece moved to is a ghost

            if (auxPiece is Ghosts ghosts)
            {
                if (((Ghosts)piece).checkWinner(ghosts))
                {
                    MovePiece(piece, pos, auxPosition);
                    board.OnPieceLost(auxPiece);
                }
                else
                {
                    board.pieces[pos.Row, pos.Col] = GameBoard.GetBoardSettings(pos);
                    board.OnPieceLost(piece);
                }
            }

            // if moved to mirror

            else if (auxPiece is Mirror mirror)
            {
                BoardPiece auxMirror = null;
                Position mirrorPos = null;

                uint mirrorCount = board.CountMirrors();

                
                // if player is in a mirror

                if (mirrorCount > 1)
                {
                    do
                    {

                        // ask what mirror to move to and check validity
                        Console.WriteLine("Which Mirror to teleport to?");

                        Console.WriteLine("Para que espelho que ir?");

                        mirrorPos = Player.GetPosition(board);
                        auxMirror = board.GetPiece(mirrorPos);

                    } while (!(auxMirror is Mirror));


                    // setting the new position
                    board.pieces[pos.Row, pos.Col] = 
                        GameBoard.GetBoardSettings(pos);
                    board.pieces[mirrorPos.Row, mirrorPos.Col] = piece;

                    // update portal rotation if necessary

                    board.pieces[pos.Row, pos.Col] = GameBoard.GetBoardSettings(pos);
                    board.pieces[mirrorPos.Row, mirrorPos.Col] = piece;


                    board.UpdatePortal(piece.color);
                }
                else
                    MovePiece(piece, pos, auxPosition);
            }
            else
                MovePiece(piece, pos, auxPosition);
        }
    }
}