Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
kristoffer tølbøll
1,337 PointsCan add a room event in textadventure game?
Hello,
i have these classes for a textadventure game that i am making.
public class RoomDef
{
public void defRooms(ArrayList<RoomInfo> rooms)
{
//Adding null, as there is currently no events, later milestone
rooms.add(new RoomInfo("\nWelcome to the starting room, which is a safe spot"
+ "\nYes, somewhere nearby is colossal cave, where others have found fortunes in treasure and gold."
+ "\nThough it is rumored that some who enter are never seen again."
+ "\nMagic is said to work in the cave."
+ "\nyou are inside a building, a well house for a large spring"
+ "\nThere are some keys on the ground here."
+ "\nThis dungeon contains a BIG treasure, which has a lot of positive items and wishes, such as being eternal rich and alive",
0, null)); //Starting room, which is room 1
rooms.add(new RoomInfo("\nWelcome into the entrance, be carefull, you may encounter hideous monsters ahead",
1, null)); //room 2
rooms.add(new RoomInfo("\nWelcome to the pool room, you can go for a swim... or not",
2, null)); //room 3
rooms.add(new RoomInfo("\nWelcome to the living room, there is an item on the floor, pick it up",
3, null)); //room 4
(code continues....)
} }
i have another class where i define the info about the room.
public class RoomInfo
{
private String roomEventText;
private int roomNumber;
private int roomEvent;
private RoomInfo north, south, east, west;
private String enterRoom;
private Event eve;
}
(with Getters and Setter).
Lastly i have my event class, which defines the vent (currently sat to null in my Room Def class).
public class Event { private String eventText; private int life;
private Event(String eventText, int life)
{
this.eventText = eventText;
this.life = life;
}
//applying the event
public void applyEvent(PlayerInfo player)
{
player.setCurrentHealth(life);
}
public String getEventText()
{
return eventText;
}
public void setEventText(String eventText)
{
this.eventText = eventText;
}
public int getLife()
{
return life;
}
public void setLife(int life)
{
this.life = life;
}
}
As of now the event should just display, a text and either add or subtract lift from the player.
How do i do this???
Derek Markman
16,291 PointsDerek Markman
16,291 PointsI would suggest that you re-upload your existing code and format it correctly so that it is readable on the forums.