zuul 7
This commit is contained in:
@@ -15,7 +15,7 @@ public class CommandWords
|
||||
{
|
||||
// a constant array that holds all valid command words
|
||||
private static final String[] validCommands = {
|
||||
"go", "quit", "help", "look", "status", "take", "drop", "say"
|
||||
"go", "quit", "help", "look", "status", "take", "drop", "say", "eat"
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package de.szut.zuul;
|
||||
|
||||
import java.sql.SQLOutput;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* This class is the main class of the "World of Zuul" application.
|
||||
* "World of Zuul" is a very simple, text based adventure game. Users
|
||||
@@ -62,6 +65,14 @@ public class Game
|
||||
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));
|
||||
|
||||
// add muffins to random rooms
|
||||
Room[] rooms = {marketsquare, templePyramid, tavern, sacrificialSite, hut, jungle, secretPassage, cave, beach, basement, wizardsRoom};
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < 3; i++) { // Add 3 muffins to random rooms
|
||||
int randomIndex = random.nextInt(rooms.length);
|
||||
rooms[randomIndex].putItem(new Item("Muffin", "a delicious muffin", 0.2));
|
||||
}
|
||||
|
||||
// initialise room exits
|
||||
marketsquare.setExit("north", tavern);
|
||||
marketsquare.setExit("east", templePyramid);
|
||||
@@ -166,6 +177,7 @@ public class Game
|
||||
System.out.println("Chat what?");
|
||||
}
|
||||
}
|
||||
case "eat" -> eatMuffin(command);
|
||||
}
|
||||
|
||||
return wantToQuit;
|
||||
@@ -282,4 +294,23 @@ public class Game
|
||||
}
|
||||
showStatus();
|
||||
}
|
||||
private void eatMuffin(Command command)
|
||||
{
|
||||
if (command.hasSecondWord()) {
|
||||
if (command.getSecondWord().equals("Muffin")) {
|
||||
Item item = player.getCurrentRoom().removeItem("Muffin");
|
||||
if (item != null) {
|
||||
player.eatMuffin();
|
||||
System.out.println("You ate a muffin. Your load capacity is now " + player.getLoadCapacity());
|
||||
showStatus();
|
||||
} else {
|
||||
System.out.println("There is no muffin in this room.");
|
||||
}
|
||||
} else {
|
||||
System.out.println("Eat what?");
|
||||
}
|
||||
} else {
|
||||
System.out.println("Eat what?");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.szut.zuul;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Random;
|
||||
|
||||
public class Player {
|
||||
private Room currentRoom;
|
||||
@@ -39,6 +40,14 @@ public class Player {
|
||||
return null;
|
||||
}
|
||||
|
||||
public double getLoadCapacity() {
|
||||
return loadCapacity;
|
||||
}
|
||||
public double eatMuffin() {
|
||||
loadCapacity += new Random().nextInt(11);
|
||||
return loadCapacity;
|
||||
}
|
||||
|
||||
private double calculateWeight() {
|
||||
double load = 0;
|
||||
for (Item item : items) {
|
||||
|
||||
Reference in New Issue
Block a user