Exemple #1
0
        /// <summary>
        /// Responsible for setting the position (x,y) and the color of the ghost
        /// </summary>
        /// <param name="player1">Gets all the information from the player 1</param>
        /// <param name="player2">Gets all the information from the player 2</param>
        /// <param name="ghosts">Gets the information from ghosts</param>
        /// <param name="i">Which cycle the for loop in main is in</param>
        public void SetStartPositions(Player player1, Player player2, Ghosts ghosts, int i)
        {
            //checks if it's the second loop
            if (i != 1)
            {
                //Tells the player what to choose and which turn it is
                Console.WriteLine("First choose a position: 1 - 25\nThen choose a color:\n1 - blue\n2 - red\n3 - Yellow");
                Console.WriteLine("Player 1 Turn:");

                //Gets the position from the class Player and saves it in posP1
                posP1 = player1.GetPosition(player1, ghosts, true);

                //A loop that checks if the player states are the same
                while (player1.ghost1.GhostState[posP1.Row, posP1.Column]
                       == player2.ghost1.GhostState[posP1.Row, posP1.Column])
                {
                    //Sends a message to the user
                    Console.WriteLine("There's already a player there");
                    //sets the state on the coordinates in posP1 to none
                    player1.ghost1.GhostState[posP1.Row, posP1.Column] = State.none;
                    //Gets the position from the class Player and saves it in posP1
                    posP1 = player1.GetPosition(player1, ghosts, true);
                }
            }

            if (i != 10)
            {
                //Tells the player what to choose and which turn it is
                Console.WriteLine("First choose a position: 1 - 25\nThen choose a color:\n1 - blue\n2 - red\n3 - Yellow");
                Console.WriteLine("Player 2 Turn:");

                //Gets the position from the class Player and saves it in posP2
                posP2 = player2.GetPosition(player2, ghosts, true);

                //A loop that checks if the player states are the same
                while (player1.ghost1.GhostState[posP2.Row, posP2.Column]
                       == player2.ghost1.GhostState[posP2.Row, posP2.Column])
                {
                    //Sends a message to the user
                    Console.WriteLine("There's already a player there");
                    //sets the state on the coordinates in posP1 to none
                    player2.ghost1.GhostState[posP2.Row, posP2.Column] = State.none;
                    //Gets the position from the class Player and saves it in posP1
                    posP2 = player2.GetPosition(player2, ghosts, true);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Returns the position of the player along with it's state
        /// </summary>
        /// <param name="targetPlayer">Gets all the information of the player that is being checked</param>
        /// <param name="ghost">Gets the information on ghosts</param>
        /// <param name="Start">Gets a Boolean depending on being on the start or the main loop</param>
        /// <returns>A position in coordinates depending on where the player placed the ghost</returns>
        public Position GetPosition(Player targetPlayer, Ghosts ghost, bool Start)
        {
            //Creates a new instance of coordinates
            Coordinates coordinates = new Coordinates();
            //Asks for input about the position and the color the player wants
            int position    = Convert.ToInt32(Console.ReadLine());
            int ghost_color = Convert.ToInt32(Console.ReadLine());
            //Gets the position in (x,y) from the class cordinates
            Position desiredCoordinate = coordinates.CheckPos(position);

            //Checks if it's the start of the program or the main loop
            if (!Start)
            {
                //Gets a value from combat and sets CanPlace to it.
                canPlace = combat.dungeon.RetriveDungeons(ghost_color);
            }

            //Checks the boolean can place, true by default altered by the Dungeon Class
            if (canPlace)
            {
                //Goes to Compare and checks if the Player can place the ghost or not, sets the result to canPlace
                canPlace = comparer.ComparePlayerToBoard(targetPlayer, board, desiredCoordinate, ghost_color);

                //A loop stopping the user from not putting an answer
                if (canPlace != true)
                {
                    //Sends a message to the user
                    Console.WriteLine("Please choose a valid place to put your ghost");
                    //returns to the beggining of the function
                    GetPosition(targetPlayer, ghost, Start);
                }
                //returns the position (y,x) the user wants
                return(desiredCoordinate);
            }
            //Returns nothing
            return(null);
        }
Exemple #3
0
        static void Main()
        {
            //Creates a new board
            Board board = new Board();
            //Creates a new Renderer to be used here
            Renderer renderer = new Renderer();
            //Creates an instance of ghosts
            Ghosts ghosts = new Ghosts();
            //Creates a new Win checker
            WinChecker checker = new WinChecker();
            //Creates 2 players from the Player class
            Player player1 = new Player();
            Player player2 = new Player();
            //Creates an instance of the movement to be used here
            Movement move = new Movement();
            //Creates a new start to be used to place the players
            Start start = new Start();

            //Defines a Boolean to keep the main loop running
            bool loop = true;
            //Controls which player is
            int turn = 1;

            //Runs the cycle 10 times to put all the 9 ghosts of each player
            for (int i = 0; i < 10; i++)
            {
                //Makes an aesthetic change allowing the second player to put 2 ghost without the board in the middle
                if (i != 1)
                {
                    renderer.Render(board, player1, player2);
                }
                //Gets the positions and states of the players
                start.SetStartPositions(player1, player2, ghosts, i);
            }

            //The main loop of the games
            while (loop)
            {
                //Draws the field
                renderer.Render(board, player1, player2);
                //checks if the Player1 or player 2 ghost is near an exit
                loop = checker.CheckNearExit(player1, move, 1);
                loop = checker.CheckNearExit(player2, move, 2);
                //If a player wins ends the loop
                if (loop == false)
                {
                    break;
                }

                //Sends the user a message
                Console.WriteLine("What do you want to do?\n1 - move a ghost\n2 - get a ghost from the dungeon");

                //Looks for input of the user
                int input = Convert.ToInt32(Console.ReadLine());
                //Checks if the turn is 1
                if (turn == 1)
                {
                    //sends the user a message
                    Console.WriteLine("Player 1 Turn");
                    //If the input is 1 the player can move a ghost
                    if (input == 1)
                    {
                        move.Move(player1, player2);
                    }
                    //If the input is 2 the player can put a new ghost
                    else if (input == 2)
                    {
                        player1.GetPosition(player1, ghosts, false);
                    }
                    //Checks if the user put a correct input, passes the turns
                    if (input == 1 || input == 2)
                    {
                        turn++;
                    }
                    //If the condition is not met sends the user a warning
                    else
                    {
                        Console.WriteLine("Please insert 1 or 2");
                    }
                    //**The user was supposed to be asked again after this but it does not**//
                }

                //Looks for input of the user
                input = Convert.ToInt32(Console.ReadLine());
                //Checks if the turn is 1
                if (turn == 2)
                {
                    //sends the user a message
                    Console.WriteLine("Player 2 Turn");
                    //If the input is 1 the player can move a ghost
                    if (input == 1)
                    {
                        move.Move(player2, player1);
                    }
                    //If the input is 2 the player can put a new ghost
                    else if (input == 2)
                    {
                        player2.GetPosition(player1, ghosts, false);
                    }
                    //Checks if the user put a correct input, passes the turns
                    if (input == 1 || input == 2)
                    {
                        turn--;
                    }
                    //If the condition is not met sends the user a warning
                    else
                    {
                        Console.WriteLine("Please insert 1 or 2");
                    }
                    //**The user was supposed to be asked again after this but it does not**//
                }
            }
            //Stops the program from closing automatically after winning
            Console.ReadLine();
        }