CrazyGaz
04-25-2007, 07:13 PM
Hi there,
I have a couple classes. Room and LockedRoom which is an extension of (and therefore inherits from) Room.
My code is
private void goRoom(String direction)
{
text = "";
Room nextRoom = curRoom.currentRoom.getExit(direction);
if (nextRoom.getClass().getName() == "LockedRoom")
{
LockedRoom nextRoom2 = curRoom.currentRoom.getExit(direction);
if (nextRoom2.returnLocked() == true)
{
text += "The Room is locked.";
}
}
I cannot get the Class without defining it as a room first. However it should only try to define nextRoom2 if it is a LockedRoom, but when I try to run this, it says "incompatible types - found Room but Expected LockedRoom.
Cheers,
Gaz.
I have a couple classes. Room and LockedRoom which is an extension of (and therefore inherits from) Room.
My code is
private void goRoom(String direction)
{
text = "";
Room nextRoom = curRoom.currentRoom.getExit(direction);
if (nextRoom.getClass().getName() == "LockedRoom")
{
LockedRoom nextRoom2 = curRoom.currentRoom.getExit(direction);
if (nextRoom2.returnLocked() == true)
{
text += "The Room is locked.";
}
}
I cannot get the Class without defining it as a room first. However it should only try to define nextRoom2 if it is a LockedRoom, but when I try to run this, it says "incompatible types - found Room but Expected LockedRoom.
Cheers,
Gaz.