Skip to content

Commit

Permalink
Better Time article and "time" command.
Browse files Browse the repository at this point in the history
  • Loading branch information
mafagafogigante committed Mar 5, 2015
1 parent 23473d3 commit dd92e63
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 31 deletions.
74 changes: 44 additions & 30 deletions src/main/java/org/dungeon/creatures/Hero.java
Original file line number Diff line number Diff line change
Expand Up @@ -532,24 +532,6 @@ public int destroyItem(IssuedCommand issuedCommand) {
return 0;
}

boolean hasClock() {
for (Item item : getInventory().getItems()) {
if (item.isClock()) {
return true;
}
}
return false;
}

Item getClock() {
for (Item item : getInventory().getItems()) {
if (item.isClock()) {
return item;
}
}
return null;
}

void equipWeapon(Item weapon) {
if (hasWeapon()) {
if (getWeapon() == weapon) {
Expand Down Expand Up @@ -604,24 +586,56 @@ public void printAge() {

/**
* Makes the hero read the current date and time as well as he can.
* <p/>
* The easiest-to-access unbroken clock of the Hero is used to get the time. If the Hero has no unbroken clock, the
* easiest-to-access broken clock is used. Lastly, if the Hero does not have a clock at all, time is not read.
*
* @return how many seconds the action lasted.
* @return how many seconds the action took
*/
public int printDateAndTime() {
World world = getLocation().getWorld();
int timeSpent = 2;
if (hasClock()) {
if (hasWeapon() && getWeapon().isClock() && !getWeapon().isBroken()) {
// Reading the time from an equipped clock is the fastest possible action.
timeSpent += 2;
} else {
// The hero needed to pick up a watch or something from his inventory, consuming more time.
timeSpent += 8;
// TODO: improve code readability and reduce code repetition.
Item clock = null;
int timeSpent = 0;
if (hasWeapon() && getWeapon().isClock()) {
if (!getWeapon().isBroken()) {
clock = getWeapon();
timeSpent = 4;
} else { // The Hero is equipping a broken clock: check if he has a working one in his inventory.
for (Item item : getInventory().getItems()) {
if (item.isClock() && !item.isBroken()) {
clock = item;
timeSpent = 10;
break;
}
}
if (clock == null) {
clock = getWeapon(); // The Hero does not have a working clock in his inventory: use the equipped one.
timeSpent = 4;
}
}
} else { // The Hero is not equipping a clock.
Item brokenClock = null;
for (Item item : getInventory().getItems()) {
if (item.isClock()) {
if (item.isBroken() && brokenClock == null) {
brokenClock = item;
} else {
clock = item;
timeSpent = 10;
break;
}
}
}
if (brokenClock != null) {
timeSpent = 10;
clock = brokenClock;
}
// Prints whatever the clock shows.
IO.writeString(getClock().getClockComponent().getTimeString());
}
if (clock != null) {
IO.writeString(clock.getClockComponent().getTimeString());
}

World world = getLocation().getWorld();
Date worldDate = world.getWorldDate();
IO.writeString("You think it is " + worldDate.toDateString() + ".");

Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/wiki.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ ARTICLE: Sleeping
CONTENT: The character can sleep when it is dark, waking up when it is dawn. During the sleep, the character may dream.

ARTICLE: Time
CONTENT: Time passes after every turn. How much each turn lasts, however, depends on what the character did.
CONTENT: Time passes after every turn. How much each turn lasts, however, depends on what the character did. Watches\
are used to keep precise track of time. Looking the time (using a watch) costs a little time, though. The character\
needs about four seconds to see what time it is in an equipped watch and around ten seconds to look up the time in a\
clock placed on his or hers backpack. A broken watch usually displays the time it broke. If the character is equipping\
a broken watch but has a working one in his or hers backpack, any attempt to look up the time will result in the\
character picking up the watch in his or hers backpack.

ARTICLE: Tomes
CONTENT: Tomes are books that can teach a skill for the player character.

0 comments on commit dd92e63

Please sign in to comment.