Skip to content

Commit

Permalink
Added jumping logic, updated DefaultBoard and Player
Browse files Browse the repository at this point in the history
  • Loading branch information
obi1kenobi committed Sep 23, 2012
1 parent f279756 commit 2174f89
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
25 changes: 24 additions & 1 deletion Mazebuilder/src/com/mazebuilder/gameplay/DefaultBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,30 @@ public Location movePlayer(Player p, Direction d) {

@Override
public Location jumpPlayer(Player p, Direction d, Direction... bonusesToSpend) {
throw new RuntimeException("Not implemented.");
Preconditions.checkArgument(p.canJump(), "Player " + p.getName() + " cannot jump walls.");
Location l = getPlayerLocation(p);
if (walls.isWall(l, d)) {
Location moved = l.move(d);
if (isBoardLocation(moved)) {
Preconditions.checkArgument(bonusesToSpend.length == p.bonusesToJump());
if (p.bonusesEqual() && bonusesToSpend.length > 0) {
Preconditions.checkNotNull(bonusesToSpend[0]);
Direction b = bonusesToSpend[0];
for (Direction bonus : bonusesToSpend) {
if (!b.equals(bonus)) {
return l;
}
}
}

for (Direction bonus : bonusesToSpend) {
p.spendBonus(bonus);
}
l = moved;
players.put(p, l);
}
}
return l;
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions Mazebuilder/src/com/mazebuilder/gameplay/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public interface Player extends Renderable {
/** Returns the number of bonuses the player needs to spend to jump a wall **/
int bonusesToJump();

/** Returns true if the bonuses spent to jump should be equal, or false otherwise. **/
boolean bonusesEqual();

/** Removes a bonus from the player. **/
boolean spendBonus(Direction d);

Expand Down

0 comments on commit 2174f89

Please sign in to comment.