Here i am providing the code. Hope it helps. please give me a like. it helps me a lot.
class Room{
private String name, description;
private Room north, east, west, south;
public Room(String name, String description) {
this.name = name;
this.description =
description;
}
public String getExits() {
String str="";
//creating exit if the value is not
null
if(north!=null)
str +="[N]orth:
"+north.getName()+"\n";
if(east != null)
str+="[E]ast:
"+east.getName()+"\n";
if(west != null)
str+="[W]est:
"+west.getName()+"\n";
if(south != null)
str+="[S]outh:
"+south.getName()+"\n";
return str;
}
//all getters method
public String getName() {
return name;
}
public Room getNorth() {
return north;
}
public Room getEast() {
return east;
}
public Room getWest() {
return west;
}
public Room getSouth() {
return south;
}
//setters for exit
public void setExits(Room n, Room e, Room w, Room s)
{
north = n;
east = e;
west = w;
south = s;
}
@Override
public String toString() {
return
name+"\n"+description+"\n"+getExits();
}
}
public class Test {//driver class
public static void main(String[] args){
Room hall = new Room("hall", "It's dark.");
Room bed = new Room("Bed", "Tiny room.");
Room bath = new Room("Bath", "Toilets here.");
Room dine = new Room("Dining", "Table &
chairs.");
hall.setExits(bed, bath, dine, null);
System.out.println(hall);
}
}
Output
Thank you. please upvote.
you wish to design a dungeon-crawl style video game which you can model as a directed...
Game Description: Most of you have played a very interesting game “Snake” on your old Nokia phones (Black & White). Now it is your time to create it with more interesting colors and features. When the game is started a snake is controlled by up, down, left and right keys to eat food which appears on random locations. By eating food snake’s length increases one unit and player’s score increases by 5 points. Food disappears after 15 seconds and appears...