public Room(int RoomNumber, Point Position) { this.RoomNumber = RoomNumber; this.Position = Position; AdjRooms = new Room[6]; ConnectedRooms = new bool[6]; }
// All parameters with default values public Room(int room, Room[] adjRooms = null, bool player = false, bool wumpus = false, Hazard hazard = null) { roomNumber = room; adjacentRooms = adjRooms; this.player = player; this.wumpus = wumpus; this.hazard = hazard; }
// Start room public Player(Room start) { room = start; arrows = new Arrow[]{ new Arrow(), new Arrow(), new Arrow(), new Arrow(), new Arrow() }; }
/****************************************************************************************** * Constructors *****************************************************************************************/ // No parameters public Player() { room = null; arrows = new Arrow[]{ new Arrow(), new Arrow(), new Arrow(), new Arrow(), new Arrow() }; }
private static void ChooseConnectedRooms(Room room) { int numberConnectedRooms = room.ConnectedRooms.Count(c => c); int minToAdd = 0; // If the room already has a connected path, don't need to add anymore if (numberConnectedRooms == 0) minToAdd = 1; // Since random.Next is exclusive for upper bound, the max number of paths is 3 int maxToAdd = 4; foreach (Room AdjRoom in room.AdjRooms) { //If an adjacent room is already full on paths, decrease the max by one if (AdjRoom.ConnectedRooms.Count(c => c) == 3) maxToAdd--; } //Ensure that the max is greater than or equal to the min maxToAdd = (maxToAdd - numberConnectedRooms > minToAdd) ? maxToAdd - numberConnectedRooms : minToAdd; //Ensure that the room cannot have more than 3 paths and at least one path int numberPathsToAdd = random.Next(minToAdd, maxToAdd); //Use while loop to add that many number of paths int counter = 0; while (counter < numberPathsToAdd) { //The position that the hallway will try to be put int number = random.Next(0, room.ConnectedRooms.Length); //The number of paths that the adjacent room has, has to be kept at or below 3 int numberConnectedRoomsAdjRoom = room.AdjRooms[number].ConnectedRooms.Count(c => c); //Only works if there is not already a path there and that adjacent room has less than 3 paths if (!room.ConnectedRooms[number] && numberConnectedRoomsAdjRoom < 3) { room.ConnectedRooms[number] = true; //Open the pathway in the adjacent room //0 corresponds with 3, 1 with 4, and 2 with 5 room.AdjRooms[number].ConnectedRooms[(number + 3) % 6] = true; //only increase counter if success is found counter++; } } }
private static void ShuffleHazards() { Room[] hazardRooms = new Room[5]; int counter = 0; while (counter < hazardRooms.Length) { Room nextRoom = Cave.Rooms[random.Next(Cave.Rooms.Length)]; if (!hazardRooms.Contains(nextRoom)) { hazardRooms[counter] = nextRoom; counter++; } } OsamaRoom = hazardRooms[0]; Helicopter1 = hazardRooms[1]; Helicopter2 = hazardRooms[2]; Oil1 = hazardRooms[3]; Oil2 = hazardRooms[4]; }
public static void InitializeMap() { do { // Initialize the room objects with numbers and positions for (int counter = 0; counter < Rooms.Length; counter++) { // Use Point to describe the offset coordinates from the top left Point position = new Point(counter % numColumns, counter % numRows); Room room = new Room(counter, position); Rooms[counter] = room; } // Initialize the adjacent and connected rooms for (int counter = 0; counter < Rooms.Length; counter++) { InitializeAdjacentRooms(Rooms[counter]); ChooseConnectedRooms(Rooms[counter]); } RandomizeRoomNumbers(); } while (!CheckMap()); }
public Map(int seed) { // Need a random to generate the map. _random = new Random(seed); // Create the empty rooms. Rows = 10; Columns = 10; var lastRow = (Rows-1) * Columns; _rooms = new Room[Rows * Columns]; for (var i = 0; i < _rooms.Length; i++) { var north = i < Columns ? -1 : i - Columns; var east = ((i+1)%Columns) == 0 ? -1 : i+1; var south = i >= lastRow ? -1 : i + Columns; var west = (i % Columns) == 0 ? -1 : i-1; var room = new Room(i, north, east, south, west); _rooms[i] = room; } // Pick some random spots for traps. var trapCount = Rows; for (var t = 0; t < trapCount; t++) { var i = _random.Next(_rooms.Length); _rooms[i].HasTrap = true; } PlaceWeapon(); // Randomly place the monster in a room without traps or a weapon. var monsterRooms = _rooms.Where(e => !e.HasTrap && e.Index != WeaponRoom).ToArray(); AlienRoom = monsterRooms[_random.Next(monsterRooms.Length)].Index; // Pick a random location for the player. var startRooms = _rooms.Where(e => !e.HasTrap && e.Index != WeaponRoom && e.Index != AlienRoom).ToArray(); PlayerRoomIndex = startRooms[_random.Next(startRooms.Length)].Index; }
// Type and room public Hazard(string type, Room room) { this.type = type; this.room = room; }
// Room and Sleep state public Wumpus(Room room, bool state) { this.room = room; awake = state; alive = true; }
// Room public Wumpus(Room room) { this.room = room; awake = false; alive = true; }
/****************************************************************************************** * Constructors *****************************************************************************************/ //No parameters public Wumpus() { room = null; awake = false; alive = true; }
/****************************************************************************************** * Move Wumpus * * @property random - Random number generator * * Once awake, the Wumpus has a 75% chance of moving each turn *****************************************************************************************/ public void move() { Random random = new Random(); // Move Wumpus if (random.Next(1, 100) >= 25) { room = room.randomRoom(); } // Check to see if killed player if (room.Number == Game.Player.Room.Number) { Game.Player.Alive = false; } }
private static void InitializeAdjacentRooms(Room room) { // Even or odd column int columnParity = room.Position.X % 2; // Starts with the room above and moves clockwise for (int counter = 0; counter < room.AdjRooms.Length; counter++) { room.AdjRooms[counter] = FindRoom(new Point(room.Position.X + directions[columnParity, counter].X, room.Position.Y + directions[columnParity, counter].Y)); } }
public static void InitializeMap() { Hazards = new Room[]{OsamaRoom, Helicopter1, Helicopter2, Oil1, Oil2}; ShuffleHazards(); }
/****************************************************************************************** * Move Player * * @property rooms - Array of rooms to send to trajectory * * Sets the room room for the player to the Room object in the map corresponding to * the integer room number entered. *****************************************************************************************/ public void move(int roomNumber) { room = Game.Map[roomNumber]; }
/****************************************************************************************** * Instructions *****************************************************************************************/ static void newGame(ref Room playerStart, ref Room wumpusStart) { /************************************************************************************** * Create new instanaces of the game pieces *************************************************************************************/ Game.Player = new Player(); Game.Wumpus = new Wumpus(); Game.Superbats = new Hazard[]{ new Hazard("superbat"), new Hazard("superbat"), }; Game.Pits = new Hazard[] { new Hazard("pit"), new Hazard("pit"), }; /************************************************************************************** * Reinitialize the board *************************************************************************************/ Game.initBoard(); /************************************************************************************** * Change the start room for the player and the Wumpus *************************************************************************************/ playerStart = Game.Player.Room; wumpusStart = Game.Wumpus.Room; }
// Type public Hazard(string type) { room = null; this.type = type; }
/****************************************************************************************** * Constructors *****************************************************************************************/ // No parameters public Hazard() { room = null; type = "None"; }
// Start room and arrows public Player(Room start, Arrow[] arrows) { room = start; this.arrows = arrows; }
/****************************************************************************************** * Shoot Arrow * * @property rooms - Array of rooms to send to trajectory * * First convert the integer room numbers to Room objects via the map. Then set the * trajectory for the arrow. The arrow will check if it hit the Wumpus and return the * result. *****************************************************************************************/ public bool shoot(Arrow arrow, int[] roomNumbers) { Room[] rooms = new Room[5]; // Convert each roomNumber into a room foreach (int room in roomNumbers) { rooms[room - 1] = Game.Map[room]; } // Set trajectory (Shoot arrow) arrow.Trajectory = rooms; // Return whether the arrow killed the Wumpus return arrow.KillWumpus; }
/****************************************************************************************** * Select Rooms * * Prompt user for room number. If invalid input is received, prompt user to try * again. Valid input must be a number and cannot be in the the previously * selected room. * * Return selected rooms * * @parameter numRooms - Number of rooms to select * @property rooms - Array holding the rooms *****************************************************************************************/ static Room[] selectRooms(int numRooms) { Room[] rooms = new Room[numRooms]; /************************************************************************************** * Process each room * * @property roomInput - String input from the player * @property room - The integer once parsed of the room number *************************************************************************************/ for (int i = 0; i < numRooms; i++) { string roomInput = "a"; int room = -1; while (!int.TryParse(roomInput, out room) || (room < 0 || room > 20)) { /****************************************************************************** * Turn Status ******************************************************************************/ turnStatus(); Console.Write("Room{0} #: ", i+1); roomInput = Console.ReadLine(); /****************************************************************************** * Is the input valid? *****************************************************************************/ if (!int.TryParse(roomInput, out room) || room < 0 || room > 20) Game.Status = "Invalid room number - Try again!"; /****************************************************************************** * Is the arrow path valid? *****************************************************************************/ if ((i > 1 && room == rooms[i-2].Number) || (i < 2 && room == Game.Player.Room.Number)) { Game.Status = "Arrows are not that crooked! Try again!"; roomInput = "Invalid"; // Force the loop to continue } } // End get room number /********************************************************************************** * Add room to the array of rooms **********************************************************************************/ rooms[i] = Game.Map[room]; } // End get room numbers loop return rooms; }
// Trajectory public Arrow(Room[] traj) { trajectory = traj; shot = true; killWumpus = false; }
private static void FloodFill(bool[] VisitedRooms, Room room) { VisitedRooms[room.RoomNumber] = true; for (int counter = 0; counter < room.ConnectedRooms.Length; counter++) { //If room is connected in that direction and that room has not yet been visited if (room.ConnectedRooms[counter] && !VisitedRooms[room.AdjRooms[counter].RoomNumber]) { FloodFill(VisitedRooms, room.AdjRooms[counter]); } } }
public Room() { AdjRooms = new Room[6]; ConnectedRooms = new bool[6]; }