zuul6
This commit is contained in:
@@ -51,6 +51,17 @@ public class Game
|
|||||||
basement = new Room("in a basement");
|
basement = new Room("in a basement");
|
||||||
wizardsRoom = new Room("in a wizards room");
|
wizardsRoom = new Room("in a wizards room");
|
||||||
|
|
||||||
|
// add items to rooms
|
||||||
|
marketsquare.putItem(new Item("Bogen", "ein Bogen aus Holz", 0.5));
|
||||||
|
cave.putItem(new Item("Schatz", "eine kleine Schatztruhe mit Münzen", 7.5));
|
||||||
|
wizardsRoom.putItem(new Item("Pfeile", "ein Köcher mit diversen Pfeilen", 1));
|
||||||
|
jungle.putItem(new Item("Pflanze", "eine Heilpflanze", 0.5));
|
||||||
|
jungle.putItem(new Item("Kakao", "ein kleiner Kakaobaum", 5));
|
||||||
|
sacrificialSite.putItem(new Item("Messer", "ein sehr scharfes, großes Messer", 1));
|
||||||
|
hut.putItem(new Item("Speer", "ein Speer mit dazugehöriger Schleuder", 5.0));
|
||||||
|
tavern.putItem(new Item("Nahrung", "ein Teller mit deftigem Fleisch und Maisbrei", 0.5));
|
||||||
|
basement.putItem(new Item("Schmuck", "ein sehr hübscher Kopfschmuck", 1));
|
||||||
|
|
||||||
// initialise room exits
|
// initialise room exits
|
||||||
marketsquare.setExit("north", tavern);
|
marketsquare.setExit("north", tavern);
|
||||||
marketsquare.setExit("east", templePyramid);
|
marketsquare.setExit("east", templePyramid);
|
||||||
|
|||||||
28
src/de/szut/zuul/Item.java
Normal file
28
src/de/szut/zuul/Item.java
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package de.szut.zuul;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class Item {
|
||||||
|
private String name;
|
||||||
|
private String description;
|
||||||
|
private double weight;
|
||||||
|
public Item(String name, String description, double weight) {
|
||||||
|
this.name = name;
|
||||||
|
this.description = description;
|
||||||
|
this.weight = weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Item{name='" + name + "', description='" + description + "', weight=" + weight + "}";
|
||||||
|
}
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
public double getWeight() {
|
||||||
|
return weight;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,7 +20,7 @@ public class Room
|
|||||||
{
|
{
|
||||||
private String description;
|
private String description;
|
||||||
private HashMap<String, Room> roomExits;
|
private HashMap<String, Room> roomExits;
|
||||||
|
private HashMap<String, Item> items;
|
||||||
/**
|
/**
|
||||||
* Create a room described "description". Initially, it has
|
* Create a room described "description". Initially, it has
|
||||||
* no exits. "description" is something like "a kitchen" or
|
* no exits. "description" is something like "a kitchen" or
|
||||||
@@ -31,6 +31,7 @@ public class Room
|
|||||||
{
|
{
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.roomExits = new HashMap<>();
|
this.roomExits = new HashMap<>();
|
||||||
|
this.items = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,7 +50,7 @@ public class Room
|
|||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
public String getLongDescription() {
|
public String getLongDescription() {
|
||||||
return "You are " + getDescription() + "\nExits: " + exitsToString();
|
return "You are " + getDescription() + "\nExits: " + exitsToString() + "\nItems in this room:\n" + getItemDescription();
|
||||||
}
|
}
|
||||||
public String exitsToString() {
|
public String exitsToString() {
|
||||||
StringBuilder exitsInString = new StringBuilder();
|
StringBuilder exitsInString = new StringBuilder();
|
||||||
@@ -63,4 +64,31 @@ public class Room
|
|||||||
public Room getExits(String direction) {
|
public Room getExits(String direction) {
|
||||||
return roomExits.get(direction);
|
return roomExits.get(direction);
|
||||||
}
|
}
|
||||||
|
public void putItem(Item newItem) {
|
||||||
|
items.put(newItem.getName(), newItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Item removeItem(String itemName) {
|
||||||
|
return items.remove(itemName);
|
||||||
|
}
|
||||||
|
private String getItemDescription() {
|
||||||
|
if (items.isEmpty()) {
|
||||||
|
return "No items in this room.";
|
||||||
|
}
|
||||||
|
StringBuilder itemDescription = new StringBuilder();
|
||||||
|
for (Item item : items.values()) {
|
||||||
|
itemDescription.append("- ")
|
||||||
|
.append(item.getName()).append(", ")
|
||||||
|
.append(item.getDescription()).append(", ")
|
||||||
|
.append(item.getWeight()).append("kg\n");
|
||||||
|
}
|
||||||
|
return itemDescription.toString().trim();
|
||||||
|
}
|
||||||
|
public String itemsToString() {
|
||||||
|
StringBuilder itemsInString = new StringBuilder();
|
||||||
|
for (String itemName : items.keySet()) {
|
||||||
|
itemsInString.append(itemName).append(" ");
|
||||||
|
}
|
||||||
|
return itemsInString.toString().trim();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user