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("Bats nearby!");
     }
 }
 public override void Update()
 {
     if (isAdjacentToPlayer())
     {
         FakeConsole.WriteLine("I feel a draft!");
     }
 }
Beispiel #4
0
        //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 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!");
            }
        }
Beispiel #8
0
 // 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("");
 }
Beispiel #9
0
        // 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("  Click a room to move to it");
            FakeConsole.WriteLine("  or press S to shoot");
        }
Beispiel #10
0
        public void Update()
        {
            // 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)
            {
                int roomClicked = getRoomClicked();
                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();
                        }
                    }
                    else // Invalid room
                    {
                        FakeConsole.WriteLine("Not possible.");
                    }
                }

                // Check if user pressed S to go into shoot mode
                KeyboardState kb = Keyboard.GetState();
                if (kb.IsKeyDown(Keys.S))
                {
                    currentState     = GameState.PICKING_SHOOT_ROOMS;
                    arrowPath        = new List <int>();
                    lastFiredPath    = new List <int>();
                    arrowPathValid   = true;
                    currentArrowRoom = Player.Position;
                    FakeConsole.WriteLine("Click up to 5 rooms to shoot through");
                    FakeConsole.WriteLine("Press enter when finished");
                }
            }
            // If in shoot mode, see what user has inputed
            if (currentState == GameState.PICKING_SHOOT_ROOMS)
            {
                // Check if user hit enter, if so, shoot the arrow and finish the turn
                KeyboardState kb          = Keyboard.GetState();
                int           roomClicked = getRoomClicked();

                if (kb.IsKeyDown(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;
                    }
                }
                // If a room was clicked, try to add it to the arrow path
                else if (roomClicked != -1)
                {
                    // 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;
                        }
                    }
                    // 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;
                        }
                    }
                }
            }
        }