public void testNeighbors(Room rm1, Room rm2) { Debug.Write("testNeighbors :"); if (rm1.hasNeighbor(rm2) && rm2.hasNeighbor(rm1)) { Debug.Write("Room " + rm1.id + " and Room " + rm2.id + " are neighbors"); } else { if(!(rm1.hasNeighbor(rm2))) Debug.Write("Room " + rm1.id + " is not connected to Room " + rm2.id + "."); if(!(rm2.hasNeighbor(rm1))) Debug.Write("Room " + rm2.id + " is not connected to Room " + rm1.id + "."); } Debug.Write("\n"); }
public void fly(List<Room> path, Room current, Wumpus target) { //Random rand = new Random(); location = current; location.addOccupant(this); int flightLength = 0; //TODO: this is ugly, clean up later foreach (Room room in path){ //check current length of flight if (flightLength < maxFlight){ if (location.hasOccupant(target)){ target.die(); //Console.WriteLine("Aha! You got the Wumpus!"); return; } //check if rooms are connected if (location.hasNeighbor(room)){ move(room); } else{ //Console.WriteLine("Room " + (location.id + 1) + " is not neighbors with Room " + // (room.id + 1) + "! Picking another room..."); int i = Random.Range(0, location.neighbors.Count - 1); move(location.neighbors[i]); } if (location == current){ //Console.WriteLine("Ouch! The arrow got you!"); break; } flightLength++; } } //Console.WriteLine("Missed!"); target.wake(); //wake the wumpus if you miss used = true; }