Esempio n. 1
0
        public void MoveWumpus(bool trivia)
        {
            // Get stuff from Map
            Room   WumpusRoom = new Room(MyMap.getWumpusRoom());
            Random myR        = MyMap.r;
            Room   NewRoom    = WumpusRoom;

            // Get adj rooms
            Room[] wAdjRooms = MyCave.loadCaveandRoom(WumpusRoom.getDecimalForm());
            // obtain number of rooms to move per turn from Wumpus
            // CHECK TRIVIA
            int n = MyWumpus.Move(false);

            // loop
            for (int i = 0; i < n; i++)
            {
                // (get all adjacent rooms
                wAdjRooms = MyCave.loadCaveandRoom(WumpusRoom.getDecimalForm());
                // Eliminate all chambers from wAdjRooms
                for (int k = 1; k < wAdjRooms.Length; k++)
                {
                    if (wAdjRooms[k] != null)
                    {
                        if (i != n - 1)
                        {
                            if (wAdjRooms[k].RoomNumber == 0)
                            {
                                wAdjRooms[k] = null;
                            }
                        }
                    }
                }
                // loop: choose randomly one of the rooms and check to make sure it is valid
                int j;
                do
                {
                    j       = myR.Next(wAdjRooms.Length - 1) + 1;
                    NewRoom = wAdjRooms[j];
                } while (MyMap.isRoomNotOkay(NewRoom, 'w'));
                // set wumpus room to the new room)
                MyMap.setWumpusRoom(NewRoom.getIntegerForm());
            }
        }
Esempio n. 2
0
        public void MoveWumpus(bool trivia)
        {
            // Get stuff from Map
            Room   WumpusRoom = new Room(MyMap.getWumpusRoom());
            Random myR        = MyMap.r;
            Room   NewRoom    = WumpusRoom;

            // Get adj rooms
            Room[] wAdjRooms = MyCave.getConnectedRooms(WumpusRoom.getDecimalForm());
            // obtain number of rooms to move per turn from Wumpus
            // CHECK TRIVIA
            int n = MyWumpus.Move(false);

            // loop
            for (int i = 0; i < n; i++)
            {
                // (get all adjacent rooms
                wAdjRooms = MyCave.getConnectedRooms(WumpusRoom.getDecimalForm());
                // Eliminate all chambers from wAdjRooms
                for (int k = 1; k < wAdjRooms.Length; k++)
                {
                    if (wAdjRooms[k] != null)
                    {
                        if (i != n - 1 && n != 1)
                        {
                            if (wAdjRooms[k].RoomNumber == 0)
                            {
                                wAdjRooms[k] = null;
                            }
                        }
                    }
                }
                // loop: choose randomly one of the rooms and check to make sure it is valid
                int  j;
                bool temp = false;
                for (int k = 0; k < 15; k++)
                {
                    j       = myR.Next(wAdjRooms.Length - 1) + 1;
                    NewRoom = wAdjRooms[j];
                    if (!MyMap.isRoomNotOkay(NewRoom, 'w'))
                    {
                        temp = true;
                        break;
                    }
                }
                if (temp)
                {
                    MyMap.setWumpusRoom(NewRoom.getIntegerForm());
                }
                else
                {
                    RandomizeRoom('w');
                }
                //do
                //{
                //    j = myR.Next(wAdjRooms.Length - 1) + 1;
                //    NewRoom = wAdjRooms[j];
                //} while (MyMap.isRoomNotOkay(NewRoom, 'w'));
                // set wumpus room to the new room)
            }
        }