public Arrow(Room room) { role = "Arrow"; this.room = room; }
public void setRoom(Room room) { this.room = room; }
public void roomReset(Room back) { Room temp = this.back; this.back = back; left = temp; }
public void setBack(Room back) { this.back = back; }
public void setRight(Room right) { this.right = right; }
public void setLeft(Room left) { this.left = left; }
public Agent(Room room) { role = ""; this.room = room; }
private Room getNextRoom(int roomNum, Room currRoom) { // Check if the next room is to the left or to the right if (currRoom.getLeft().getRoomNum() == roomNum) { return currRoom.getLeft(); } else if (currRoom.getRight().getRoomNum() == roomNum) { return currRoom.getRight(); } else { return null; } }
public String shoot(int roomNum) { Random random = new Random(); int nextRoomNum = 0; Room[] rooms = new Room[5]; Room nextRoom = getNextRoom(roomNum, JamesBond.getRoom()); if (nextRoom == null) { return "Cannot Shoot"; } maxArrows--; rooms[0] = nextRoom; int i = 1; while (i < maxRoomsToShoot) { nextRoomNum = random.Next(1, 2); if (nextRoomNum == 1) { nextRoomNum = nextRoom.getLeft().getRoomNum(); } else { nextRoomNum = nextRoom.getRight().getRoomNum(); } nextRoom = getNextRoom(nextRoomNum, rooms[i-1]); rooms[i] = nextRoom; i++; } for (int j = 0; j < rooms.Length; j++) { Creature creature = rooms[j].getCreature(); if (creature != null) { String role = creature.getRole(); if (role.Equals("Wumpus")) { return "win"; } } } if (maxArrows == 0) { return "lose"; } return "Nothing happened"; }