From af4bd7aa377637f9c9b7cbbfa372aa46679d6f9d Mon Sep 17 00:00:00 2001 From: fiicere Date: Wed, 26 Sep 2012 04:28:30 -0400 Subject: [PATCH] Implemented Jumping --- .../gameplay/players/ChaserPlayer.java | 4 +- .../com/mazebuilder/root/GameplayState.java | 146 +++++++++++++----- 2 files changed, 107 insertions(+), 43 deletions(-) diff --git a/Mazebuilder/src/com/mazebuilder/gameplay/players/ChaserPlayer.java b/Mazebuilder/src/com/mazebuilder/gameplay/players/ChaserPlayer.java index 1b3b906..10018b2 100644 --- a/Mazebuilder/src/com/mazebuilder/gameplay/players/ChaserPlayer.java +++ b/Mazebuilder/src/com/mazebuilder/gameplay/players/ChaserPlayer.java @@ -62,6 +62,7 @@ public void startTurn() { SoundEffects.playChaserGetBonus(); newBonus(); } + System.out.println("CHASER PLAYER HAS THE FOLLOWING BONUSES:"); System.out.println(getBonuses()); } @@ -100,6 +101,7 @@ public boolean bonusesEqual() { @Override public boolean spendBonus(Direction d) { + System.out.println("Chaser has used a bonus \"" + d.toString() + "\" move"); return bonuses.remove(d); } @@ -114,5 +116,5 @@ public int spendMove() { SoundEffects.playChaserMove(); return --remainingMoves; } - + } diff --git a/Mazebuilder/src/com/mazebuilder/root/GameplayState.java b/Mazebuilder/src/com/mazebuilder/root/GameplayState.java index 5649ebd..2a9460d 100644 --- a/Mazebuilder/src/com/mazebuilder/root/GameplayState.java +++ b/Mazebuilder/src/com/mazebuilder/root/GameplayState.java @@ -39,6 +39,8 @@ public class GameplayState extends BasicGameState { private static final int INITIAL_WALLS_YPOS = 3; //private static final int CHASER_TURN_MILLIS = 5000; + private static Direction jumping = null; + private GameContainer gameContainer; private final Board board = new DefaultBoard(new SimpleBoardRenderer(), BOARD_WIDTH, BOARD_HEIGHT); private final RunnerPlayer runner = new RunnerPlayer(new RunnerPlayerRenderer(), "A"); @@ -85,54 +87,114 @@ public int getID() { @Override public void keyPressed(int key, char c) { - displayBonuses(); - switch (c){ - // Regular Moves - case 'w': - if (chaser.canMove()){ - board.movePlayer(chaser, Direction.UP); - } - break; - case 'a': - if (chaser.canMove()){ - board.movePlayer(chaser, Direction.LEFT); - } - break; - case 's': - if (chaser.canMove()){ - board.movePlayer(chaser, Direction.DOWN); + //JUMPing key presses + if (jumping != null){ + switch (c){ + // Regular Moves + case 'w': + board.jumpPlayer(chaser, jumping, Direction.UP, Direction.UP); + break; + case 'a': + board.jumpPlayer(chaser, jumping, Direction.LEFT, Direction.LEFT); + break; + case 's': + board.jumpPlayer(chaser, jumping, Direction.DOWN, Direction.DOWN); + break; + case 'd': + board.jumpPlayer(chaser, jumping, Direction.RIGHT, Direction.RIGHT); + break; + case ' ': + System.out.println("Jump Cancelled"); + jumping = null; } - break; - case 'd': - if (chaser.canMove()){ - board.movePlayer(chaser, Direction.RIGHT); + jumping = null; + } + //NON-JUMP key presses + else{ + switch (c){ + // Regular Moves + case 'w': + if (chaser.canMove()){ + if(!board.movePlayer(chaser, Direction.UP)){ + jumping = Direction.UP; + handleJump(); + } + } + break; + case 'a': + if (chaser.canMove()){ + if(!board.movePlayer(chaser, Direction.LEFT)){ + jumping = Direction.LEFT; + handleJump(); + } + } + break; + case 's': + if (chaser.canMove()){ + if(!board.movePlayer(chaser, Direction.DOWN)){ + jumping = Direction.DOWN; + handleJump(); + } + } + break; + case 'd': + if (chaser.canMove()){ + if(!board.movePlayer(chaser, Direction.RIGHT)){ + jumping = Direction.RIGHT; + handleJump(); + } + } + break; + // Special Moves + case 'W': + board.movePlayerWithBonus(chaser, Direction.UP); + break; + case 'A': + board.movePlayerWithBonus(chaser, Direction.LEFT); + break; + case 'S': + board.movePlayerWithBonus(chaser, Direction.DOWN); + break; + case 'D': + board.movePlayerWithBonus(chaser, Direction.RIGHT); + break; + case ' ': + if(!runner.canMove() && !runner.canWall()){ + runner.startTurn(); + } } - break; - // Special Moves - case 'W': - board.movePlayerWithBonus(chaser, Direction.UP); - break; - case 'A': - board.movePlayerWithBonus(chaser, Direction.LEFT); - break; - case 'S': - board.movePlayerWithBonus(chaser, Direction.DOWN); - break; - case 'D': - board.movePlayerWithBonus(chaser, Direction.RIGHT); - break; - case ' ': - runner.startTurn(); } } - //Shows the list of all bonuses held by chaserPlayer - public void displayBonuses(){ - System.out.println("CHASER PLAYER HAS THE FOLLOWING BONUSES:"); - Multiset m = chaser.getBonuses(); - for(Direction d:Direction.values()){ - System.out.println(m.count(d) + " " + d.toString()+"s"); + public void handleJump(){ + Multiset m = chaser.getBonuses(); + int up = m.count(Direction.UP); + int down = m.count(Direction.DOWN); + int left = m.count(Direction.LEFT); + int right = m.count(Direction.RIGHT); + boolean hasJump = false; + + if (up >= chaser.bonusesToJump()){ + System.out.println("Press W to use 2 bonus \"UP\" movements to jump the wall"); + hasJump = true; + } + if (down >= chaser.bonusesToJump()){ + System.out.println("Press S to use 2 bonus \"DOWN\" movements to jump the wall"); + hasJump = true; } + if (left >= chaser.bonusesToJump()){ + System.out.println("Press A to use 2 bonus \"LEFT\" movements to jump the wall"); + hasJump = true; + } + if (right >= chaser.bonusesToJump()){ + System.out.println("Press D to use 2 bonus \"RIGHT\" movements to jump the wall"); + hasJump = true; + } + if (!hasJump){ + System.out.println("You do not have matching bonuses. You cannot jump the wall"); + } + System.out.println("Press SPACE to quit without jumping"); + } @Override