liammann/JavaCoursework

The "back" command - bug, or?

Closed this issue · 1 comments

When writing the "back" command, it said that when used it should go back to the previous room. If it is used consecutively, then it should go back and forth between the same room. What I have done so far does this, but with the introduction of the "back n" command, there is potential for a bug, as demonstrated:

"->" means goes to (a linear movement)

locations: room -> hallway -> kitchen

{goto room}
...location: room
{goto hallway}
...location: hallway
{back}
...location: room
{back}
...location: hallway /* this is correct, since it jumps back and forth between two rooms */
{goto kitchen}
...location: kitchen
{back 2}
...location: room
{back}
...location: kitchen

For the last back command, would going back a single step from "room" mean undoing the "back 2" command, and so going back to the kitchen (therefore jumping two locations in one go)? If so, then it works correct. Or would it mean going back a single step only, which would be to the hallway - and so if we instead replaced the last "back" command as "back 2" then it should go back to the kitchen?

The sheet wasn't really clear about this, so if we can't think of a proper implementation of this then I'll have to pester Robert again.

I've reimplemented the back command to work differently than before (and therefore different to the above). If everyone could test it and see if it works as they would have expected, then that would be helpful.