Question

you wish to design a dungeon-crawl style video game which you can model as a directed graph. The dungeon is constructed of ro
0 1
Add a comment Improve this question Transcribed image text
Answer #1

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

<terminated Test (1) [Java Application] C:\Program Files Vava\jre1.8.0_211\bin\javaw.exe (19-Oct-2019, 9:46:19 am) hall Its

Thank you. please upvote.

Add a comment
Know the answer?
Add Answer to:
you wish to design a dungeon-crawl style video game which you can model as a directed...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Game Description: Most of you have played a very interesting game “Snake” on your old Nokia...

    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...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT