Skip to content

Commit

Permalink
Player B starts with bonus moves
Browse files Browse the repository at this point in the history
  • Loading branch information
fiicere committed Sep 26, 2012
1 parent bef220d commit c1b6809
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions Mazebuilder/src/com/mazebuilder/gameplay/players/ChaserPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public final class ChaserPlayer implements Player {
private static final int BONUS_INTERVAL = 2;
private static final int BONUSES_TO_JUMP = 2;
private static final int MOVEMENTS_PER_TURN = 2;
private static final int STARTING_BONUS_MOVEMENTS = 1;

private final PlayerRenderer renderer;
private final String name;
Expand All @@ -31,6 +32,10 @@ public ChaserPlayer(PlayerRenderer renderer, String name) {
this.name = name;
this.bonuses = EnumMultiset.create(Direction.class);
this.rand = new Random();

for(int i = 0; i < STARTING_BONUS_MOVEMENTS; i++){
newBonus();
}
}

@Override
Expand All @@ -53,26 +58,30 @@ public void startTurn() {
System.out.println("Chaser's turn!");
remainingMoves = MOVEMENTS_PER_TURN;
turnsToBonus--;
if (turnsToBonus == 0) {
SoundEffects.playChaserGetBonus();
turnsToBonus = BONUS_INTERVAL;
switch (rand.nextInt(4)) {
case 0:
bonuses.add(Direction.LEFT);
break;
case 1:
bonuses.add(Direction.UP);
break;
case 2:
bonuses.add(Direction.RIGHT);
break;
case 3:
bonuses.add(Direction.DOWN);
break;
}
if (turnsToBonus == 0) {
SoundEffects.playChaserGetBonus();
newBonus();
}
System.out.println(getBonuses());
}

public void newBonus(){
turnsToBonus = BONUS_INTERVAL;
switch (rand.nextInt(4)) {
case 0:
bonuses.add(Direction.LEFT);
break;
case 1:
bonuses.add(Direction.UP);
break;
case 2:
bonuses.add(Direction.RIGHT);
break;
case 3:
bonuses.add(Direction.DOWN);
break;
}
}

@Override
public Multiset<Direction> getBonuses() {
Expand All @@ -94,6 +103,7 @@ public boolean spendBonus(Direction d) {
return bonuses.remove(d);
}


@Override
public boolean canMove() {
return remainingMoves > 0;
Expand Down

0 comments on commit c1b6809

Please sign in to comment.