Esempio n. 1
0
 public void Rendering(Board board, Player p1, Player p2, Portals pRed, Portals pBlue, Portals pYellow)
 {
     ActvGhosts(p1, p2);
     CapturedGhosts(p1, p2);
     EscapedGhosts(p1, p2);
     PlayerTurn(board);
     BattleRules();
     DrawMap(board, p1, p2, pRed, pBlue, pYellow);
 }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;

            Board board = new Board();

            Player p1 = new Player();
            Player p2 = new Player();


            Portals redPortal = new Portals('\u2191', ConsoleColor.Red,
                                            new Position(0, 2), PortalState.North);
            Portals bluePortal = new Portals('\u2193', ConsoleColor.Blue,
                                             new Position(4, 2), PortalState.South);
            Portals yellowPortal = new Portals('\u2192', ConsoleColor.Yellow,
                                               new Position(2, 4), PortalState.East);

            Render render = new Render();

            CheckforWin checkforWin = new CheckforWin();

            Movement movement = new Movement();

            GhostRespawn ghostRespawn = new GhostRespawn();

            GameLoop gameLoop = new GameLoop();

            Setup setup = new Setup();

            setup.SetPlayerSpaces(render, board, p1, p2, redPortal, bluePortal,
                                  yellowPortal, p1.insideGhosts, p1.runawayGhosts,
                                  p1.lockedGhosts, p1.ghostList);


            gameLoop.RunGameLoop(board, render, p1, p2, movement, ghostRespawn,
                                 checkforWin, redPortal, bluePortal, yellowPortal, p1.ghostList);
        }
Esempio n. 3
0
        public void RunGameLoop(Board board, Render render, Player p1,
                                Player p2, Movement movement, GhostRespawn ghostRespawn,
                                CheckforWin checkforWin, Portals pRed, Portals pBlue,
                                Portals pYellow, Ghost[] originalList)
        {
            p1.insideGhosts  = p1.InsideGhostUpdate(originalList);
            p1.runawayGhosts = p1.RunawayGhostUpdate(originalList);
            p1.lockedGhosts  = p1.LockedGhostUpdate(originalList);
            p2.insideGhosts  = p2.InsideGhostUpdate(originalList);
            p2.runawayGhosts = p2.RunawayGhostUpdate(originalList);
            p2.lockedGhosts  = p2.LockedGhostUpdate(originalList);



            while (checkforWin.Check(p1, p2) == RoomState.Undecided)
            {
                // Print all display elements on screen
                render.Rendering(board, p1, p2, pRed, pBlue, pYellow);

                Console.WriteLine("What do you want to do?");
                Console.WriteLine("1 - Move");
                Console.WriteLine("2 - Rescue\n");

                int option = 0;

                while (option != 1 && option != 2)
                {
                    option = Convert.ToInt32(Console.ReadLine());
                    if (option != 1 && option != 2)
                    {
                        Console.WriteLine("Please select a valid option.");
                    }

                    if (board.currentTurn == RoomState.P1 && option == 2 &&
                        p1.lockedGhosts.Length == 0)
                    {
                        Console.WriteLine("You have no ghosts" +
                                          " in the dungeon.");
                        Console.WriteLine("\nWhat do you want to do?");
                        Console.WriteLine("1 - Move");
                        Console.WriteLine("2 - Rescue");
                        option = 0;
                    }
                    if (board.currentTurn == RoomState.P2 && option == 2 &&
                        p2.lockedGhosts.Length == 0)
                    {
                        Console.WriteLine("You have no ghosts" +
                                          " in the dungeon.");
                        Console.WriteLine("\nWhat do you want to do?");
                        Console.WriteLine("1 - Move");
                        Console.WriteLine("2 - Rescue");
                        option = 0;
                    }
                }

                if (option == 1)
                {
                    if (board.currentTurn == RoomState.P1)
                    {
                        movement.Move(board, p1, p2);
                    }
                    else if (board.currentTurn == RoomState.P2)
                    {
                        movement.Move(board, p2, p1);
                    }
                }

                else
                {
                    if (board.currentTurn == RoomState.P1)
                    {
                        if (ghostRespawn.IsThereGhostToRescue(board, p1)
                            == true)
                        {
                            ghostRespawn.Respawn(board, p1, p2);
                        }
                    }
                    else
                    {
                        if (ghostRespawn.IsThereGhostToRescue(board, p2)
                            == true)
                        {
                            ghostRespawn.Respawn(board, p2, p1);
                        }
                    }
                }
                board.ChangeTurn();
            }
        }
Esempio n. 4
0
        // Method that draws the map and Player's Ghosts.
        public void DrawMap(Board board, Player p1, Player p2, Portals pRed,
                            Portals pBlue, Portals pYellow)
        {
            int rows    = 5;
            int columns = 5;
            int lines   = 7;
            int space   = 0;


            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < lines; j++)
                {
                    for (int k = 0; k < columns; k++)
                    {
                        space = i * 5 + k;

                        switch (j)
                        {
                        //This row defines the top limit of the map grid.
                        case 0:
                            Console.Write("+-------------");
                            if (space == 4 || space == 9 || space == 14 ||
                                space == 19 || space == 24)
                            {
                                Console.Write("+");
                            }
                            break;

                        /*In this case (1), the number of the room is
                         * shown. This Appears in the top left corner of
                         * the room. */
                        case 1:
                            Console.Write("|");
                            //This specific condition deals with house
                            //numbers below 10 (having the correct number
                            //õf spaces).
                            if ((space + 1) < 10)
                            {
                                Console.Write($"{space + 1}          " +
                                              $"  ");
                            }
                            //This specific condition deals with house
                            //numbers from and above 10 (having the correct
                            //number of spaces).
                            else
                            {
                                Console.Write($"{space + 1}          " +
                                              $" ");
                            }
                            //This condition specificly draws the division
                            //between the diferent houses.
                            if (space == 4 || space == 9 || space == 14 ||
                                space == 19 || space == 24)
                            {
                                Console.Write("|");
                            }
                            break;

                        case 2:
                            Console.Write("|");
                            if (board.type[i, k] == RoomType.Red)
                            {
                                Console.BackgroundColor = ConsoleColor.Red;
                            }
                            else if (board.type[i, k] ==
                                     RoomType.Blue)
                            {
                                Console.BackgroundColor =
                                    ConsoleColor.Blue;
                            }
                            else if (board.type[i, k] ==
                                     RoomType.Yellow)
                            {
                                Console.BackgroundColor =
                                    ConsoleColor.Yellow;
                            }
                            Console.Write("             ");
                            Console.BackgroundColor = ConsoleColor.Black;
                            if (space == 4 || space == 9 || space == 14 ||
                                space == 19 || space == 24)
                            {
                                Console.Write("|");
                            }
                            break;

                        case 3:
                            if (board.state[i, k] == RoomState.P1)
                            {
                                Console.Write("|      P1     ");
                            }
                            else if (board.state[i, k] == RoomState.P2)
                            {
                                Console.Write("|      P2     ");
                            }
                            else
                            {
                                Console.Write("|             ");
                            }

                            if (space == 4 || space == 9 || space == 14 ||
                                space == 19 || space == 24)
                            {
                                Console.Write("|");
                            }
                            break;

                        case 4:
                            Console.Write("|");
                            if (space == 2)
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.Write($"      {pRed.symbol}    " +
                                              $"  ");
                                Console.ForegroundColor = ConsoleColor.
                                                          White;
                            }
                            else if (space == 14)
                            {
                                Console.ForegroundColor = ConsoleColor.
                                                          Yellow;
                                Console.Write($"      {pYellow.symbol}   " +
                                              $"   ");
                                Console.ForegroundColor = ConsoleColor.
                                                          White;
                            }
                            else if (space == 22)
                            {
                                Console.ForegroundColor = ConsoleColor.
                                                          Blue;
                                Console.Write($"      {pBlue.symbol}   " +
                                              $"   ");
                                Console.ForegroundColor = ConsoleColor.
                                                          White;
                            }

                            else
                            {
                                Console.Write("             ");
                            }



                            if (space == 4 || space == 9 || space == 14 ||
                                space == 19 || space == 24)
                            {
                                Console.Write("|");
                            }
                            break;

                        case 5:
                            if (board.state[i, k] == RoomState.P1)
                            {
                                for (int l = 0; l < p1.insideGhosts.Length;
                                     l++)
                                {
                                    if (p1.insideGhosts[l].position.Row == i &&
                                        p1.insideGhosts[l].position.
                                        Column == k)
                                    {
                                        Console.Write($"|" +
                                                      $"      {p1.insideGhosts[l].name}" +
                                                      $"     ");
                                    }
                                }
                            }
                            else if (board.state[i, k] == RoomState.P2)
                            {
                                for (int l = 0; l < p2.insideGhosts.Length;
                                     l++)
                                {
                                    if (p2.insideGhosts[l].position.Row == i &&
                                        p2.insideGhosts[l].position.
                                        Column == k)
                                    {
                                        Console.Write($"|" +
                                                      $"      {p2.insideGhosts[l].name}" +
                                                      $"     ");
                                    }
                                }
                            }


                            if (space == 4 || space == 9 || space == 14 ||
                                space == 19 || space == 24)
                            {
                                Console.Write("|");
                            }
                            break;

                        case 6:
                            Console.Write("|             ");
                            if (space == 4 || space == 9 || space == 14 ||
                                space == 19 || space == 24)
                            {
                                Console.Write("|");
                            }
                            break;
                        }
                    }
                    Console.Write("\n");
                }
            }
            Console.Write("+-------------+-------------+-------------+" +
                          "-------------+-------------+\n\n");
        }
Esempio n. 5
0
        public void SetPlayerSpaces(Render render, Board board, Player p1,
                                    Player p2, Portals pRed, Portals pBlue, Portals pYellow,
                                    Ghost[] insideGhosts, Ghost[] runawayGhosts, Ghost[] lockedGhosts, Ghost[] ghostList)
        {
            board.currentTurn = RoomState.P1;
            render.Rendering(board, p1, p2, pRed, pBlue, pYellow);
            DefinePosition(board, p1, ref insideGhosts, runawayGhosts, lockedGhosts, ghostList);
            board.ChangeTurn();
            render.Rendering(board, p1, p2, pRed, pBlue, pYellow);


            DefinePosition(board, p2, ref insideGhosts, runawayGhosts, lockedGhosts, ghostList);
            render.Rendering(board, p1, p2, pRed, pBlue, pYellow);


            DefinePosition(board, p2, ref insideGhosts, runawayGhosts, lockedGhosts, ghostList);
            board.ChangeTurn();
            render.Rendering(board, p1, p2, pRed, pBlue, pYellow);

            DefinePosition(board, p1, ref insideGhosts, runawayGhosts, lockedGhosts, ghostList);
            board.ChangeTurn();
            render.Rendering(board, p1, p2, pRed, pBlue, pYellow);


            DefinePosition(board, p2, ref insideGhosts, runawayGhosts, lockedGhosts, ghostList);
            board.ChangeTurn();
            render.Rendering(board, p1, p2, pRed, pBlue, pYellow);


            DefinePosition(board, p1, ref insideGhosts, runawayGhosts, lockedGhosts, ghostList);
            board.ChangeTurn();
            render.Rendering(board, p1, p2, pRed, pBlue, pYellow);


            DefinePosition(board, p2, ref insideGhosts, runawayGhosts, lockedGhosts, ghostList);
            board.ChangeTurn();
            render.Rendering(board, p1, p2, pRed, pBlue, pYellow);


            DefinePosition(board, p1, ref insideGhosts, runawayGhosts, lockedGhosts, ghostList);
            board.ChangeTurn();
            render.Rendering(board, p1, p2, pRed, pBlue, pYellow);


            DefinePosition(board, p2, ref insideGhosts, runawayGhosts, lockedGhosts, ghostList);
            board.ChangeTurn();
            render.Rendering(board, p1, p2, pRed, pBlue, pYellow);


            DefinePosition(board, p1, ref insideGhosts, runawayGhosts, lockedGhosts, ghostList);
            board.ChangeTurn();
            render.Rendering(board, p1, p2, pRed, pBlue, pYellow);


            DefinePosition(board, p2, ref insideGhosts, runawayGhosts, lockedGhosts, ghostList);
            board.ChangeTurn();
            render.Rendering(board, p1, p2, pRed, pBlue, pYellow);


            DefinePosition(board, p1, ref insideGhosts, runawayGhosts, lockedGhosts, ghostList);
            board.ChangeTurn();
            render.Rendering(board, p1, p2, pRed, pBlue, pYellow);


            DefinePosition(board, p2, ref insideGhosts, runawayGhosts, lockedGhosts, ghostList);
            board.ChangeTurn();
            render.Rendering(board, p1, p2, pRed, pBlue, pYellow);


            DefinePosition(board, p1, ref insideGhosts, runawayGhosts, lockedGhosts, ghostList);
            board.ChangeTurn();
            render.Rendering(board, p1, p2, pRed, pBlue, pYellow);


            DefinePosition(board, p2, ref insideGhosts, runawayGhosts, lockedGhosts, ghostList);
            board.ChangeTurn();
            render.Rendering(board, p1, p2, pRed, pBlue, pYellow);


            DefinePosition(board, p1, ref insideGhosts, runawayGhosts, lockedGhosts, ghostList);
            board.ChangeTurn();
            render.Rendering(board, p1, p2, pRed, pBlue, pYellow);


            DefinePosition(board, p2, ref insideGhosts, runawayGhosts, lockedGhosts, ghostList);
            board.ChangeTurn();
            render.Rendering(board, p1, p2, pRed, pBlue, pYellow);


            DefinePosition(board, p1, ref insideGhosts, runawayGhosts, lockedGhosts, ghostList);
        }