forked from helloplz/MazeBuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added players. Updated board accordingly.
- Loading branch information
1 parent
27e7102
commit ee48319
Showing
5 changed files
with
198 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
Mazebuilder/src/com/mazebuilder/gameplay/ChaserPlayer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.mazebuilder.gameplay; | ||
|
||
import java.util.Random; | ||
|
||
import org.newdawn.slick.Graphics; | ||
|
||
import com.google.common.collect.EnumMultiset; | ||
import com.google.common.collect.Multiset; | ||
import com.google.common.collect.Multisets; | ||
import com.mazebuilder.renderer.PlayerRenderer; | ||
|
||
public final class ChaserPlayer implements Player { | ||
|
||
private final PlayerRenderer renderer; | ||
private final String name; | ||
private final Multiset<Direction> bonuses; | ||
private final Random rand; | ||
|
||
private int turnsToBonus = BONUS_INTERVAL; | ||
|
||
private static final boolean BONUSES_EQUAL = true; | ||
private static final int BONUS_INTERVAL = 2; | ||
private static final int BONUSES_TO_JUMP = 2; | ||
|
||
public ChaserPlayer(PlayerRenderer renderer, String name) { | ||
this.renderer = renderer; | ||
this.name = name; | ||
this.bonuses = EnumMultiset.create(Direction.class); | ||
this.rand = new Random(); | ||
} | ||
|
||
@Override | ||
public void render(Graphics g, int xOffset, int yOffset) { | ||
renderer.drawPlayer(g, xOffset, yOffset); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public boolean canJump() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void executeTurn() { | ||
turnsToBonus--; | ||
if (turnsToBonus == 0) { | ||
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() { | ||
return Multisets.unmodifiableMultiset(bonuses); | ||
} | ||
|
||
@Override | ||
public int bonusesToJump() { | ||
return BONUSES_TO_JUMP; | ||
} | ||
|
||
@Override | ||
public boolean bonusesEqual() { | ||
return BONUSES_EQUAL; | ||
} | ||
|
||
@Override | ||
public boolean spendBonus(Direction d) { | ||
return bonuses.remove(d); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
Mazebuilder/src/com/mazebuilder/gameplay/RunnerPlayer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.mazebuilder.gameplay; | ||
|
||
import org.newdawn.slick.Graphics; | ||
|
||
import com.google.common.collect.EnumMultiset; | ||
import com.google.common.collect.Multiset; | ||
import com.mazebuilder.renderer.PlayerRenderer; | ||
|
||
public final class RunnerPlayer implements Player { | ||
|
||
private final PlayerRenderer renderer; | ||
private final String name; | ||
private final Multiset<Direction> bonuses; | ||
|
||
public RunnerPlayer(PlayerRenderer renderer, String name) { | ||
this.renderer = renderer; | ||
this.name = name; | ||
this.bonuses = EnumMultiset.create(Direction.class); | ||
} | ||
|
||
@Override | ||
public void render(Graphics g, int xOffset, int yOffset) { | ||
renderer.drawPlayer(g, xOffset, yOffset); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public boolean canJump() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void executeTurn() { | ||
// no-op | ||
} | ||
|
||
@Override | ||
public Multiset<Direction> getBonuses() { | ||
return bonuses; | ||
} | ||
|
||
@Override | ||
public int bonusesToJump() { | ||
return Integer.MAX_VALUE; | ||
} | ||
|
||
@Override | ||
public boolean bonusesEqual() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean spendBonus(Direction d) { | ||
throw new RuntimeException("Cannot spend bonus - RunnerPlayer is not allowed to have bonuses."); | ||
} | ||
|
||
} |