This commit is contained in:
2025-02-25 12:20:24 +01:00
parent b77ad010ee
commit f175e8a91d
3 changed files with 41 additions and 1 deletions

View File

@@ -15,7 +15,7 @@ public class CommandWords
{ {
// a constant array that holds all valid command words // a constant array that holds all valid command words
private static final String[] validCommands = { private static final String[] validCommands = {
"go", "quit", "help", "look", "status", "take", "drop", "say" "go", "quit", "help", "look", "status", "take", "drop", "say", "eat"
}; };
/** /**

View File

@@ -1,5 +1,8 @@
package de.szut.zuul; package de.szut.zuul;
import java.sql.SQLOutput;
import java.util.Random;
/** /**
* This class is the main class of the "World of Zuul" application. * This class is the main class of the "World of Zuul" application.
* "World of Zuul" is a very simple, text based adventure game. Users * "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)); 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)); 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 // initialise room exits
marketsquare.setExit("north", tavern); marketsquare.setExit("north", tavern);
marketsquare.setExit("east", templePyramid); marketsquare.setExit("east", templePyramid);
@@ -166,6 +177,7 @@ public class Game
System.out.println("Chat what?"); System.out.println("Chat what?");
} }
} }
case "eat" -> eatMuffin(command);
} }
return wantToQuit; return wantToQuit;
@@ -282,4 +294,23 @@ public class Game
} }
showStatus(); 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?");
}
}
} }

View File

@@ -1,6 +1,7 @@
package de.szut.zuul; package de.szut.zuul;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Random;
public class Player { public class Player {
private Room currentRoom; private Room currentRoom;
@@ -39,6 +40,14 @@ public class Player {
return null; return null;
} }
public double getLoadCapacity() {
return loadCapacity;
}
public double eatMuffin() {
loadCapacity += new Random().nextInt(11);
return loadCapacity;
}
private double calculateWeight() { private double calculateWeight() {
double load = 0; double load = 0;
for (Item item : items) { for (Item item : items) {