public void Respawn(Board board, Player currentPlayer, Player adversary) { Console.WriteLine("\nWhat ghost do you want to save?"); for (int i = 0; i < currentPlayer.lockedGhosts.Length; i++) { Console.WriteLine($"{i+1} - " + $"{currentPlayer.lockedGhosts[i].name}"); } int option = 0; while (option < 1 || option > currentPlayer.lockedGhosts.Length) { option = Convert.ToInt32(Console.ReadLine()); if (option < 1 || option > currentPlayer.lockedGhosts.Length) { Console.WriteLine("Please select a valid option."); } } Ghost savedGhost = currentPlayer.lockedGhosts[option - 1]; board.ChangeTurn(); Console.WriteLine("\nWhere does the adversary want to" + " put the ghost?"); Console.WriteLine("Space has to be free and the same" + " color as the ghost."); Console.WriteLine("Can't be a mirror or a portal (1-25)"); bool validSpace = false; option = 0; Position wantedPosition; /* Opponent decides where he wants to put the ghost. * Ghost is put in said position, if it is a valid one */ while (validSpace == false) { option = Convert.ToInt32(Console.ReadLine()); if (option >= 1 || option <= 25) { wantedPosition = currentPlayer.PositionForNumber(option); if (savedGhost.color == ConsoleColor.Red && board.type[wantedPosition.Row, wantedPosition.Column] == RoomType.Red && board.state[wantedPosition.Row, wantedPosition.Column] == RoomState.Undecided) { MakeChanges(currentPlayer, savedGhost, wantedPosition, GhostState.Inside); validSpace = true; } else if (savedGhost.color == ConsoleColor.Blue && board.type[wantedPosition.Row, wantedPosition.Column] == RoomType.Blue && board.state[wantedPosition.Row, wantedPosition.Column] == RoomState.Undecided) { MakeChanges(currentPlayer, savedGhost, wantedPosition, GhostState.Inside); validSpace = true; } else if (savedGhost.color == ConsoleColor.Yellow && board.type[wantedPosition.Row, wantedPosition.Column] == RoomType.Yellow && board.state[wantedPosition.Row, wantedPosition.Column] == RoomState.Undecided) { MakeChanges(currentPlayer, savedGhost, wantedPosition, GhostState.Inside); validSpace = true; } else { Console.WriteLine("That position is unavailable."); } } else { Console.WriteLine("Please select a valid option."); } } board.ChangeTurn(); }
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(); } }
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); }