コード例 #1
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);
        }
コード例 #2
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();
            }
        }