예제 #1
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");
        }
예제 #2
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;
                        }
                    }
                }
            }
        }