//public override void Update() //{ // // Ask for player's choice this move // PlayerChoice choice = QueryChoice(); // // Shoot an arrow // if (choice == PlayerChoice.SHOOT) // { // var arrowPath = QueryShoot(); // if (arrowPath.Length > 0) // ShootArrow(arrowPath); // } // // Move to a room // else if (choice == PlayerChoice.MOVE) // { // var room = QueryMove(); // Move(room); // } //} //private PlayerChoice QueryChoice() //{ // // Loop until valid input received // while (true) // { // FakeConsole.Write("Your move: [S]hoot, [M]ove, or [Q]uit? "); // char key = FakeConsole.ReadKey(false).KeyChar; // FakeConsole.WriteLine(); // if (key == 's' || key == 'S') // return PlayerChoice.SHOOT; // else if (key == 'm' || key == 'M') // return PlayerChoice.MOVE; // else if (key == 'q' || key == 'Q') // Environment.Exit(0); // else // FakeConsole.WriteLine("That is not a valid option. Try again."); // } //} //private int QueryMove() //{ // // Loop until valid input received // while (true) // { // FakeConsole.Write("Where to? "); // string line = FakeConsole.ReadLine(); // int room; // if (Int32.TryParse(line, out room)) // { // var adjRooms = Map.getAdjacentRooms(Position); // if (adjRooms.Contains(room)) // { // return room; // } // else // Cannot move to that room // { // FakeConsole.WriteLine("Not Possible"); // } // } // else // { // FakeConsole.WriteLine("That's not a valid number. Try again."); // } // } //} //private int[] QueryShoot() //{ // // Query number of rooms // int num; // while (true) // { // FakeConsole.Write("No. of rooms (0-5)? "); // string line = FakeConsole.ReadLine(); // if (Int32.TryParse(line, out num)) // { // if (0 <= num && num <= 5) // break; // FakeConsole.WriteLine("Number of rooms must be between 0 and 5."); // } // else // FakeConsole.WriteLine("That's not a valid number."); // } // int[] result = new int[num]; // int[] input = new int[num]; // if (num == 0) // { // FakeConsole.WriteLine("Okay, suit yourself..."); // return result; // } // // keeps track of if player gave a valid path so far or not // bool valid = true; // int currentRoom = Position; // // Query a room for the number of rooms specified // for (int k = 0; k < num; k++) // { // int room; // while (true) // { // FakeConsole.Write("Room #? "); // string line = FakeConsole.ReadLine(); // if (Int32.TryParse(line, out room)) // { // if (1 <= room && room <= Map.NumRooms) // { // input[k] = room; // // Arrow takes A-B-A path // // use input instead of result to evaluate only player input // if(k > 1 && input[k-2] == room || k == 1 && room == Position) // { // FakeConsole.WriteLine("Arrows aren't that crooked - try another room"); // } // // The player's path is correct so far, shoot where he said // else if(valid && Map.isAdjacent(currentRoom, room)) // { // result[k] = room; // currentRoom = result[k]; // break; // } // // The player messed up the path, so shoot somewhere random // else // { // valid = false; // var adjRooms = Map.getAdjacentRooms(currentRoom); // // Remove possibility for A-B-A path // if (k > 0) // { // var forbiddenRoom = (k == 1) ? Position : result[k - 2]; // // If there is a room that creates a A-B-A path, remove it // if (adjRooms.Contains(forbiddenRoom)) // { // var tempRooms = new int[adjRooms.Length - 1]; // int j = 0; // foreach (var adjRoom in adjRooms) // if (adjRoom != forbiddenRoom) // tempRooms[j++] = adjRoom; // adjRooms = tempRooms; // } // } // result[k] = adjRooms[Map.random.Next(adjRooms.Length)]; // currentRoom = result[k]; // break; // } // } // else // Input isn't a real room on the map // { // FakeConsole.WriteLine("That room doesn't exist."); // } // } // else // Input is an invalid number // { // FakeConsole.WriteLine("That's not a valid number."); // } // } // } // return result; //} public void ShootArrow(int[] rooms) { if (rooms.Length == 0) { return; } Arrows--; foreach (int room in rooms) { FakeConsole.WriteLine("" + room); // Shot the wumpus if (Map.Wumpus.Position == room) { FakeConsole.WriteLine("Aha! You got the Wumpus!"); Map.EndGame(true); return; } // Shot yourself if (Position == room) { FakeConsole.WriteLine("Ouch! Arrow got you!"); Map.EndGame(false); return; } } FakeConsole.WriteLine("Missed!"); // Ran out of arrows and died if (Arrows == 0) { FakeConsole.WriteLine("You ran out of arrows! (and you somehow die from this)"); Map.EndGame(false); } }
public override void Update() { if (isAdjacentToPlayer()) { FakeConsole.WriteLine("Bats nearby!"); } }
public override void AffectPlayer() { // Lose the game FakeConsole.WriteLine("YYYIIIIEEEE . . . fell in a pit"); Map.lastHazardRoom = Position; Map.EndGame(false); }
public override void Update() { if (isAdjacentToPlayer()) { FakeConsole.WriteLine("I feel a draft!"); } }
public override void AffectPlayer() { // Move player to random room FakeConsole.WriteLine("Zap--Super Bat snatch! Elsewhereville for you!"); Map.Player.Move(Map.random.Next(20) + 1); Map.lastHazardRoom = Position; Map.HazardCheck(); }
public override void AffectPlayer() { // Wake up if sleeping Map.lastHazardRoom = Position; if (Sleeping) { FakeConsole.WriteLine("... Ooops! Bumped a Wumpus"); Sleeping = false; } // Lose the game if awake else { FakeConsole.WriteLine("The Wumpus caught you!"); Map.EndGame(false); } }
public override void Update() { // Move to random adj room if not sleeping if (!Sleeping) { if (Map.random.Next(4) != 0) // 75% chance to move { var adjRooms = Map.getAdjacentRooms(Position); Move(adjRooms[Map.random.Next(3)]); } } // Smell a wumpus if next to player if (isAdjacentToPlayer()) { FakeConsole.WriteLine("I smell a Wumpus!"); } }
// End the game, pass in true for win, false for lose public void EndGame(bool won) { currentState = GameState.GAME_OVER; if (won) { FakeConsole.WriteLine("Hee hee hee - the Wumpus'll getcha next time!!"); } else { FakeConsole.WriteLine("You died. Game Over."); } playing = false; FakeConsole.WriteLine(""); FakeConsole.WriteLine("Press 1 to play again"); FakeConsole.WriteLine("Press 2 to play with new"); FakeConsole.WriteLine(" random locations for hazards"); FakeConsole.WriteLine(""); }
// Beginning of turn logic public void UpdateTurn() { var adjRooms = getAdjacentRooms(Player.Position); // Update Wumpus first Wumpus.Update(); // Check for adjacent hazards (in entity updates) foreach (Entity entity in Entities) { entity.Update(); } // Tell the player where they are FakeConsole.WriteLine("You are in room " + Player.Position); FakeConsole.WriteLine("Tunnels lead to " + adjRooms[0] + ", " + adjRooms[1] + ", and " + adjRooms[2]); FakeConsole.WriteLine("Your move:"); FakeConsole.WriteLine(" Left/Right to select a room"); FakeConsole.WriteLine(" press Enter to move to selected room"); FakeConsole.WriteLine(" press S to shoot"); }
public void Update() { // Define camera positions for INIT and WAITING_ON_MOVE states Vector3 position, target; position = Player.PositionCoords + cameraPositionOffset; target = new Vector3(roomPositions[facingRoom], 0); Vector3 direction = target - position; direction.Normalize(); direction *= 200; position -= direction; // Update keyboard state oldKeyboardState = currentKeyboardState; currentKeyboardState = Keyboard.GetState(); // If just beginning, start a turn and wait for player's move if (currentState == GameState.INIT) { UpdateTurn(); currentState = GameState.WAITING_ON_MOVE; } // If waiting on player's move, see if they did anything yet if (currentState == GameState.WAITING_ON_MOVE) { // Left and Right keys change the selected/facing room if (wasKeyPressed(Keys.Left)) { int[] adjRooms = getAdjacentRooms(Player.Position); int index = Array.IndexOf(adjRooms, facingRoom) - 1; if (index < 0) { index = adjRooms.Length - 1; } facingRoom = adjRooms[index]; } else if (wasKeyPressed(Keys.Right)) { int[] adjRooms = getAdjacentRooms(Player.Position); int index = Array.IndexOf(adjRooms, facingRoom) + 1; if (index >= adjRooms.Length) { index = 0; } facingRoom = adjRooms[index]; } // Enter makes player go to selected/facing room int roomClicked = (wasKeyPressed(Keys.Enter)) ? facingRoom : -1; int oldRoom = Player.Position; if (roomClicked != -1) { // Valid room movement input if (isAdjacent(Player.Position, roomClicked)) { lastHazardRoom = -1; arrowPath = new List <int>(); lastFiredPath = new List <int>(); Player.Move(roomClicked); HazardCheck(); if (playing) { UpdateTurn(); } facingRoom = getAdjacentRooms(Player.Position)[0]; if (facingRoom == oldRoom) { facingRoom = getAdjacentRooms(Player.Position)[1]; } } else // Invalid room { FakeConsole.WriteLine("Not possible."); } } // Check if user pressed S to go into shoot mode if (wasKeyPressed(Keys.S)) { currentState = GameState.PICKING_SHOOT_ROOMS; arrowPath = new List <int>(); lastFiredPath = new List <int>(); arrowPathValid = true; currentArrowRoom = Player.Position; FakeConsole.WriteLine("Select up to 5 rooms to shoot through"); FakeConsole.WriteLine("Press S to choose a room to shoot"); FakeConsole.WriteLine("Press enter when finished"); } } // If in shoot mode, see what user has inputed if (currentState == GameState.PICKING_SHOOT_ROOMS) { // Update camera for picking rooms to shoot position = new Vector3(roomPositions[currentArrowRoom], 0) + cameraPositionOffset; target = new Vector3(roomPositions[facingRoom], 0); direction = target - position; direction.Normalize(); direction *= 200; position -= direction; int roomClicked = wasKeyPressed(Keys.S) ? facingRoom : -1; // Check if user hit enter, if so, shoot the arrow and finish the turn if (wasKeyPressed(Keys.Enter)) { if (arrowPath.Count == 0) { FakeConsole.WriteLine("Okay, suit yourself..."); } lastFiredPath = arrowPath; Player.ShootArrow(arrowPath.ToArray()); HazardCheck(); if (playing) { UpdateTurn(); currentState = GameState.WAITING_ON_MOVE; facingRoom = getAdjacentRooms(Player.Position)[0]; } } // Left and Right to select room to shoot. Makes sure not to allow selecting room that causes A-B-A path if (wasKeyPressed(Keys.Left)) { var adjRooms = getAdjacentRooms(currentArrowRoom); int index = 0; if (arrowPath.Count > 0) { var forbiddenRoom = (arrowPath.Count == 1) ? Player.Position : arrowPath[arrowPath.Count - 2]; if (adjRooms.Contains(forbiddenRoom)) // prevent A-B-A path { var tempRooms = new int[adjRooms.Length - 1]; int j = 0; foreach (var adjRoom in adjRooms) { if (adjRoom != forbiddenRoom) { tempRooms[j++] = adjRoom; } } adjRooms = tempRooms; } index = Array.IndexOf(adjRooms, facingRoom) - 1; if (index < 0) { index = adjRooms.Length - 1; } } facingRoom = adjRooms[index]; } if (wasKeyPressed(Keys.Right)) { var adjRooms = getAdjacentRooms(currentArrowRoom); int index = 0; if (arrowPath.Count > 0) { var forbiddenRoom = (arrowPath.Count == 1) ? Player.Position : arrowPath[arrowPath.Count - 2]; if (adjRooms.Contains(forbiddenRoom)) // prevent A-B-A path { var tempRooms = new int[adjRooms.Length - 1]; int j = 0; foreach (var adjRoom in adjRooms) { if (adjRoom != forbiddenRoom) { tempRooms[j++] = adjRoom; } } adjRooms = tempRooms; } index = Array.IndexOf(adjRooms, facingRoom) + 1; if (index >= adjRooms.Length) { index = 0; } } facingRoom = adjRooms[index]; } // If a room was selected, try to add it to the arrow path else if (roomClicked != -1) { int oldArrowRoom = currentArrowRoom; // Player inputed room that would cause A-B-A path, don't accept if (arrowPath.Count > 1 && arrowPath[arrowPath.Count - 2] == roomClicked || arrowPath.Count == 1 && roomClicked == Player.Position) { FakeConsole.WriteLine("Arrows aren't that crooked - try another room"); } // Player has entered valid path so far, so accept his input if correct else if (arrowPathValid && isAdjacent(currentArrowRoom, roomClicked)) { arrowPath.Add(roomClicked); currentArrowRoom = roomClicked; } // Player inputted an invalid room, so pick one at random else { arrowPathValid = false; var adjRooms = getAdjacentRooms(currentArrowRoom); if (arrowPath.Count > 0) { var forbiddenRoom = (arrowPath.Count == 1) ? Player.Position : arrowPath[arrowPath.Count - 2]; if (adjRooms.Contains(forbiddenRoom)) // prevent A-B-A path { var tempRooms = new int[adjRooms.Length - 1]; int j = 0; foreach (var adjRoom in adjRooms) { if (adjRoom != forbiddenRoom) { tempRooms[j++] = adjRoom; } } adjRooms = tempRooms; } var pickRoom = adjRooms[random.Next(adjRooms.Length)]; arrowPath.Add(pickRoom); currentArrowRoom = pickRoom; } } facingRoom = getAdjacentRooms(currentArrowRoom)[0]; if (facingRoom == oldArrowRoom) { facingRoom = getAdjacentRooms(currentArrowRoom)[1]; } // Max rooms hit, fire the arrow if (arrowPath.Count == 5) { lastFiredPath = arrowPath; Player.ShootArrow(arrowPath.ToArray()); HazardCheck(); if (playing) { UpdateTurn(); currentState = GameState.WAITING_ON_MOVE; facingRoom = getAdjacentRooms(Player.Position)[0]; } } } } // When the game is over, switch to overview camera position to see the whole map if (!playing) { position = new Vector3(); for (int k = 1; k < roomPositions.Length; k++) { position.X += roomPositions[k].X; position.Y += roomPositions[k].Y; } position /= 20; position.Z = 500; target = new Vector3(position.X, position.Y, 0); position.Y -= 10; } camera.update(position, target); }