To make a long story short:
I need the command String taken in to be used as a method call and the object name given to be used as the object that executes the method.
(user-inputted object in string format).(user-inputted command in string format);
public class World
{
Area CurrentArea;
Area PreviousArea;
Scanner in = new Scanner(System.in);
public void goToArea(Area whichArea)
{
PreviousArea = CurrentArea;
CurrentArea = whichArea;
}
}
public class Area
{
Scanner in = new Scanner(System.in);
String description;//tells the person about the area, like "you find yourself in a dungeon" or stuff like that
String name;
boolean canWarehouse;//please don't comment on this stupidly long list
boolean canRoof;
boolean canBasement;
boolean canRoom;
boolean canDocks;
boolean canBoat;
boolean canShip;
boolean canBridge;
boolean canUtil;
boolean canHeater;
public Area(String aDescription, String aName, boolean warehouse, boolean roof, boolean basement, boolean pirateRoom, boolean docks, boolean ship, boolean boat, boolean bridge, boolean utilityRoom, boolean heaterRoom)//i know this is way inefficient
{
description = aDescription;
name = aName;
canWarehouse = warehouse;
canRoof = roof;
canBasement = basement;
canPirateRoom = pirateRoom;
canDocks = docks;
canShip = ship;
canBoat = boat;
canBridge = bridge;
canUtil = utilityRoom;
canHeater = heaterRoom;
}
public void command(String command)
{
if (command == "examine")
{
System.out.println("What would you like to examine?");
String jimmy = in.next();
//now what? I want to reference all existing objects here to the String named jimmy to find any matches
}
}
}
public class Thing
{
String name;
String containerName;//which area it is in
boolean taken = false;//did the person pick it up
boolean takeable = false;//can the person pick it up
boolean local = false;//is it in the current area
boolean moveable = false;//can it be moved
boolean openable = false;//can it be opened
boolean attackable = false;//can it be attacked
String examine;//what is the object's description when examined
public Thing(String aName,String aContainer,boolean isTakeable,boolean isLocal,boolean isMoveable,boolean isOpenable,boolean isAttackable,String isExaminable)
{
containerName = aContainer;
name = aName;
takeable = isTakeable;
local = isLocal;
moveable = isMoveable;
openable = isOpenable;
attackable = isAttackable;
examinable = isExaminable;
}
public void getObject()
{
if (takeable && local)
{
taken = true;
}
else
{
System.out.println("You cannot get this object");
}
}
public boolean getTaken()//checks if an object the user is trying to use has been picked up yet
{
return taken;
}
public String getContainer()//returns the object's area it is in
{
return containerName;
}
}Thanks a lot for any help. I'm guessing this knowledge is very important to all Java coding, turning a String into an object's name or command.
Edited by Ryan 3000, 06 March 2008 - 05:43 PM.



This topic is locked
Back to top








