open doors and clean up close #5
This commit is contained in:
1 parent
abedbeef7e
commit
52f6e300b7
39 files changed
+278
-149
No files matched your search
@@ -56,3 +56,11 @@ BoxTests-job:
|
||||
script:
|
||||
- source /opt/local/bin/java17.env
|
||||
- ./gradlew test --tests "BoxTests"
|
||||
DoorTests-job:
|
||||
needs:
|
||||
- job: build-job
|
||||
artifacts: false
|
||||
stage: tests
|
||||
script:
|
||||
- source /opt/local/bin/java17.env
|
||||
- ./gradlew test --tests "DoorTests"
|
||||
Vendored
+2
-1
@@ -1,3 +1,4 @@
|
||||
{
|
||||
"java.configuration.updateBuildConfiguration": "automatic"
|
||||
"java.configuration.updateBuildConfiguration": "automatic",
|
||||
"C_Cpp.default.configurationProvider": "ms-vscode.makefile-tools",
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package fr.ubx.poo.ubomb;
|
||||
|
||||
import fr.ubx.poo.ubomb.view.*;
|
||||
import fr.ubx.poo.ubomb.view.GameLauncherView;
|
||||
import javafx.application.Application;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
@@ -4,16 +4,21 @@
|
||||
|
||||
package fr.ubx.poo.ubomb.engine;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import fr.ubx.poo.ubomb.game.Direction;
|
||||
import fr.ubx.poo.ubomb.game.Game;
|
||||
import fr.ubx.poo.ubomb.game.Position;
|
||||
import fr.ubx.poo.ubomb.go.character.Monster;
|
||||
import fr.ubx.poo.ubomb.go.character.Player;
|
||||
import fr.ubx.poo.ubomb.view.ImageResource;
|
||||
import fr.ubx.poo.ubomb.view.Sprite;
|
||||
import fr.ubx.poo.ubomb.view.SpriteFactory;
|
||||
import fr.ubx.poo.ubomb.view.SpriteMonster;
|
||||
import fr.ubx.poo.ubomb.view.SpritePlayer;
|
||||
import fr.ubx.poo.ubomb.view.sprite.Sprite;
|
||||
import fr.ubx.poo.ubomb.view.sprite.SpriteFactory;
|
||||
import fr.ubx.poo.ubomb.view.sprite.SpriteMonster;
|
||||
import fr.ubx.poo.ubomb.view.sprite.SpritePlayer;
|
||||
import javafx.animation.AnimationTimer;
|
||||
import javafx.animation.TranslateTransition;
|
||||
import javafx.application.Platform;
|
||||
@@ -29,11 +34,6 @@ import javafx.scene.text.TextAlignment;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.util.Duration;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public final class GameEngine {
|
||||
|
||||
private static AnimationTimer gameLoop;
|
||||
@@ -49,6 +49,7 @@ public final class GameEngine {
|
||||
|
||||
public GameEngine(Game game, final Stage stage) {
|
||||
this.stage = stage;
|
||||
stage.setResizable(false);
|
||||
this.game = game;
|
||||
this.level = game.getLevel();
|
||||
this.player = game.player();
|
||||
@@ -79,10 +80,9 @@ public final class GameEngine {
|
||||
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
Group root = new Group();
|
||||
private void initGroup() {
|
||||
layer = new Pane();
|
||||
|
||||
Group root = new Group();
|
||||
int height = game.grid().height();
|
||||
int width = game.grid().width();
|
||||
int sceneWidth = width * ImageResource.SIZE;
|
||||
@@ -90,30 +90,22 @@ public final class GameEngine {
|
||||
Scene scene = new Scene(root, sceneWidth, (double) sceneHeight + StatusBar.height);
|
||||
scene.getStylesheets().add(getClass().getResource("/css/application.css").toExternalForm());
|
||||
stage.setScene(scene);
|
||||
stage.setResizable(false);
|
||||
stage.sizeToScene();
|
||||
stage.centerOnScreen();
|
||||
stage.hide();
|
||||
stage.show();
|
||||
input = new Input(scene);
|
||||
root.getChildren().add(layer);
|
||||
statusBar = new StatusBar(root, sceneWidth, sceneHeight, game);
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
this.initGroup();
|
||||
this.initSprites();
|
||||
}
|
||||
|
||||
private void changeLevel() {
|
||||
Group root = new Group();
|
||||
int height = game.grid().height();
|
||||
int width = game.grid().width();
|
||||
int sceneWidth = width * ImageResource.SIZE;
|
||||
int sceneHeight = height * ImageResource.SIZE;
|
||||
Scene scene = new Scene(root, sceneWidth, (double) sceneHeight + StatusBar.height);
|
||||
scene.getStylesheets().add(getClass().getResource("/css/application.css").toExternalForm());
|
||||
stage.setScene(scene);
|
||||
stage.sizeToScene();
|
||||
input = new Input(scene);
|
||||
root.getChildren().add(layer);
|
||||
statusBar = new StatusBar(root, sceneWidth, sceneHeight, game);
|
||||
this.initGroup();
|
||||
sprites.forEach(Sprite::remove);
|
||||
sprites.clear();
|
||||
this.initSprites();
|
||||
@@ -134,7 +126,7 @@ public final class GameEngine {
|
||||
// Graphic update
|
||||
cleanupSprites();
|
||||
render();
|
||||
statusBar.update(game);
|
||||
statusBar.update();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -163,8 +155,7 @@ public final class GameEngine {
|
||||
Position playerPosition = this.player.getPosition();
|
||||
for (Sprite sprite : sprites) {
|
||||
if (sprite.getPosition().equals(playerPosition)) {
|
||||
Monster m = new Monster(playerPosition);
|
||||
if (m.equals(sprite.getGameObject()) && !this.player.isInvisible(now)) {
|
||||
if (sprite.getGameObject() instanceof Monster && !this.player.isInvisible(now)) {
|
||||
this.player.addLives(-1);
|
||||
this.player.setInvisibilityStart(now);
|
||||
}
|
||||
@@ -185,6 +176,8 @@ public final class GameEngine {
|
||||
player.requestMove(Direction.RIGHT);
|
||||
} else if (input.isMoveUp()) {
|
||||
player.requestMove(Direction.UP);
|
||||
} else if (input.isKey()) {
|
||||
player.openDoor();
|
||||
}
|
||||
input.clear();
|
||||
}
|
||||
@@ -199,6 +192,8 @@ public final class GameEngine {
|
||||
Scene scene = new Scene(root, msg.length() * 50, 200, Color.WHITE);
|
||||
stage.setScene(scene);
|
||||
input = new Input(scene);
|
||||
stage.centerOnScreen();
|
||||
stage.hide();
|
||||
stage.show();
|
||||
new AnimationTimer() {
|
||||
public void handle(long now) {
|
||||
|
||||
@@ -42,8 +42,8 @@ public final class Input {
|
||||
|
||||
public Input(Scene scene) {
|
||||
this.scene = scene;
|
||||
scene.addEventFilter(KeyEvent.KEY_PRESSED, keyPressedEventHandler);
|
||||
scene.addEventFilter(KeyEvent.KEY_RELEASED, keyReleasedEventHandler);
|
||||
this.scene.addEventFilter(KeyEvent.KEY_PRESSED, keyPressedEventHandler);
|
||||
this.scene.addEventFilter(KeyEvent.KEY_RELEASED, keyReleasedEventHandler);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
|
||||
@@ -71,8 +71,8 @@ public class StatusBar {
|
||||
return group;
|
||||
}
|
||||
|
||||
public void update(Game game) {
|
||||
Player player = game.player();
|
||||
public void update() {
|
||||
Player player = this.game.player();
|
||||
lives.setText(String.valueOf(player.getLives()));
|
||||
bombRange.setText(String.valueOf(player.getBombRange()));
|
||||
availableBombs.setText(String.valueOf(player.getAvailableBombs()));
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
package fr.ubx.poo.ubomb.engine;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Timer {
|
||||
private final long duration;
|
||||
private long startTime;
|
||||
|
||||
@@ -12,24 +12,44 @@ public enum Direction {
|
||||
public Position nextPosition(Position pos, int delta) {
|
||||
return new Position(pos.x(), pos.y() - delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction opposit() {
|
||||
return Direction.DOWN;
|
||||
}
|
||||
},
|
||||
RIGHT {
|
||||
@Override
|
||||
public Position nextPosition(Position pos, int delta) {
|
||||
return new Position(pos.x() + delta, pos.y());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction opposit() {
|
||||
return Direction.LEFT;
|
||||
}
|
||||
},
|
||||
DOWN {
|
||||
@Override
|
||||
public Position nextPosition(Position pos, int delta) {
|
||||
return new Position(pos.x(), pos.y() + delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction opposit() {
|
||||
return Direction.UP;
|
||||
}
|
||||
},
|
||||
LEFT {
|
||||
@Override
|
||||
public Position nextPosition(Position pos, int delta) {
|
||||
return new Position(pos.x() - delta, pos.y());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction opposit() {
|
||||
return Direction.RIGHT;
|
||||
}
|
||||
},
|
||||
;
|
||||
|
||||
@@ -42,6 +62,8 @@ public enum Direction {
|
||||
|
||||
public abstract Position nextPosition(Position pos, int delta);
|
||||
|
||||
public abstract Direction opposit();
|
||||
|
||||
public Position nextPosition(Position pos) {
|
||||
return nextPosition(pos, 1);
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package fr.ubx.poo.ubomb.game;
|
||||
|
||||
public class Door {
|
||||
|
||||
}
|
||||
@@ -5,8 +5,8 @@ import fr.ubx.poo.ubomb.go.character.Monster;
|
||||
import fr.ubx.poo.ubomb.go.character.Player;
|
||||
import fr.ubx.poo.ubomb.go.decor.Box;
|
||||
import fr.ubx.poo.ubomb.go.decor.Decor;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.DoorNextOpened;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.DoorPrevOpened;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.DoorNext;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.DoorPrev;
|
||||
import fr.ubx.poo.ubomb.launcher.MapException;
|
||||
|
||||
import java.util.LinkedList;
|
||||
@@ -98,10 +98,10 @@ public class Game {
|
||||
Decor d = this.grid[this.level].get(p);
|
||||
if (d != null) {
|
||||
if (next) {
|
||||
if (d instanceof DoorPrevOpened)
|
||||
if (d instanceof DoorPrev)
|
||||
return p;
|
||||
} else {
|
||||
if (d instanceof DoorNextOpened)
|
||||
if (d instanceof DoorNext)
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package fr.ubx.poo.ubomb.game;
|
||||
|
||||
import fr.ubx.poo.ubomb.go.decor.bonus.*;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.DoorNextClosed;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.DoorNextOpened;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.DoorPrevOpened;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.DoorNext;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.DoorPrev;
|
||||
import fr.ubx.poo.ubomb.go.decor.*;
|
||||
import fr.ubx.poo.ubomb.launcher.Entity;
|
||||
import fr.ubx.poo.ubomb.launcher.MapLevel;
|
||||
@@ -22,13 +21,13 @@ public class Level implements Grid {
|
||||
|
||||
public Level(MapLevel entities) {
|
||||
this.entities = entities;
|
||||
this.width = entities.width();
|
||||
this.height = entities.height();
|
||||
this.width = this.entities.width();
|
||||
this.height = this.entities.height();
|
||||
|
||||
for (int i = 0; i < width; i++)
|
||||
for (int j = 0; j < height; j++) {
|
||||
Position position = new Position(i, j);
|
||||
Entity entity = entities.get(i, j);
|
||||
Entity entity = this.entities.get(i, j);
|
||||
if (entity == null)
|
||||
continue;
|
||||
switch (entity) {
|
||||
@@ -45,13 +44,13 @@ public class Level implements Grid {
|
||||
elements.put(position, new Princess(position));
|
||||
break;
|
||||
case DoorNextClosed:
|
||||
elements.put(position, new DoorNextClosed(position));
|
||||
elements.put(position, new DoorNext(position, false));
|
||||
break;
|
||||
case DoorPrevOpened:
|
||||
elements.put(position, new DoorPrevOpened(position));
|
||||
elements.put(position, new DoorPrev(position));
|
||||
break;
|
||||
case DoorNextOpened:
|
||||
elements.put(position, new DoorNextOpened(position));
|
||||
elements.put(position, new DoorNext(position, true));
|
||||
break;
|
||||
case BombRangeInc:
|
||||
elements.put(position, new BombRangeInc(position));
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package fr.ubx.poo.ubomb.go;
|
||||
|
||||
import fr.ubx.poo.ubomb.go.decor.bonus.*;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.DoorNextOpened;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.DoorPrevOpened;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.DoorNext;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.DoorPrev;
|
||||
|
||||
// Double dispatch visitor pattern
|
||||
public interface TakeVisitor {
|
||||
@@ -11,9 +11,9 @@ public interface TakeVisitor {
|
||||
|
||||
void take(Princess p);
|
||||
|
||||
void take(DoorNextOpened door);
|
||||
void take(DoorNext door);
|
||||
|
||||
void take(DoorPrevOpened door);
|
||||
void take(DoorPrev door);
|
||||
|
||||
void take(BombNumberInc BNI);
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import fr.ubx.poo.ubomb.go.Movable;
|
||||
public abstract class Character extends GameObject implements Movable {
|
||||
private Direction direction;
|
||||
private boolean moveRequested = false;
|
||||
private long invisibilityStart = 0;
|
||||
|
||||
public Character(Position position) {
|
||||
super(position);
|
||||
@@ -28,6 +29,14 @@ public abstract class Character extends GameObject implements Movable {
|
||||
moveRequested = true;
|
||||
}
|
||||
|
||||
public long getInvisibilityStart() {
|
||||
return invisibilityStart;
|
||||
}
|
||||
|
||||
public void setInvisibilityStart(long invisibilityStart) {
|
||||
this.invisibilityStart = invisibilityStart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doMove(Direction direction) {
|
||||
// This method is called only if the move is possible, do not check again
|
||||
|
||||
@@ -8,7 +8,6 @@ import fr.ubx.poo.ubomb.game.Position;
|
||||
//fusion Monster + Player (movable)
|
||||
//princess reste seule car =/= movable
|
||||
public class Monster extends Character {
|
||||
private long invisibilityStart = 0;
|
||||
|
||||
public Monster(Position position) {
|
||||
super(position);
|
||||
|
||||
@@ -11,8 +11,8 @@ import fr.ubx.poo.ubomb.go.*;
|
||||
import fr.ubx.poo.ubomb.go.decor.Box;
|
||||
import fr.ubx.poo.ubomb.go.decor.Decor;
|
||||
import fr.ubx.poo.ubomb.go.decor.bonus.*;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.DoorNextOpened;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.DoorPrevOpened;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.DoorNext;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.DoorPrev;
|
||||
|
||||
public class Player extends Character implements TakeVisitor {
|
||||
private int lives;
|
||||
@@ -22,7 +22,6 @@ public class Player extends Character implements TakeVisitor {
|
||||
private int keys;
|
||||
|
||||
private boolean takenPrincess = false;
|
||||
private long invisibilityStart = 0;
|
||||
|
||||
public Player(Game game, Position position) {
|
||||
super(game, position);
|
||||
@@ -34,16 +33,8 @@ public class Player extends Character implements TakeVisitor {
|
||||
this.lives = game.configuration().playerLives();
|
||||
}
|
||||
|
||||
public long getInvisibilityStart() {
|
||||
return invisibilityStart;
|
||||
}
|
||||
|
||||
public void setInvisibilityStart(long invisibilityStart) {
|
||||
this.invisibilityStart = invisibilityStart;
|
||||
}
|
||||
|
||||
public boolean isInvisible(long now) {
|
||||
return (this.invisibilityStart + this.game.configuration().playerInvisibilityTime() * 1000000) - now > 0;
|
||||
return (this.getInvisibilityStart() + this.game.configuration().playerInvisibilityTime() * 1000000) - now > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -169,12 +160,13 @@ public class Player extends Character implements TakeVisitor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void take(DoorNextOpened door) {
|
||||
this.game.addLevel(1);
|
||||
public void take(DoorNext door) {
|
||||
if (door.isOpen())
|
||||
this.game.addLevel(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void take(DoorPrevOpened door) {
|
||||
public void take(DoorPrev door) {
|
||||
this.game.addLevel(-1);
|
||||
}
|
||||
|
||||
@@ -185,4 +177,15 @@ public class Player extends Character implements TakeVisitor {
|
||||
Decor tmp = game.grid().get(nextPos);
|
||||
return tmp != null && tmp.walkableBy(box);
|
||||
}
|
||||
|
||||
public void openDoor() {
|
||||
if (this.keys <= 0)
|
||||
return;
|
||||
Position nextPos = this.getDirection().nextPosition(this.getPosition());
|
||||
if (this.game.grid().get(nextPos) instanceof DoorNext dn && !dn.isOpen()) {
|
||||
dn.setOpen(true);
|
||||
dn.setModified(true);
|
||||
this.keys--;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package fr.ubx.poo.ubomb.go.decor.bonus;
|
||||
|
||||
import fr.ubx.poo.ubomb.game.Position;
|
||||
import fr.ubx.poo.ubomb.go.character.Player;
|
||||
import fr.ubx.poo.ubomb.go.Takeable;
|
||||
|
||||
public class BombNumberDec extends Bonus {
|
||||
public BombNumberDec(Position position) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package fr.ubx.poo.ubomb.go.decor.bonus;
|
||||
|
||||
import fr.ubx.poo.ubomb.game.Position;
|
||||
import fr.ubx.poo.ubomb.go.character.Player;
|
||||
import fr.ubx.poo.ubomb.go.Takeable;
|
||||
|
||||
public class BombNumberInc extends Bonus {
|
||||
public BombNumberInc(Position position) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package fr.ubx.poo.ubomb.go.decor.bonus;
|
||||
|
||||
import fr.ubx.poo.ubomb.game.Position;
|
||||
import fr.ubx.poo.ubomb.go.character.Player;
|
||||
import fr.ubx.poo.ubomb.go.Takeable;
|
||||
|
||||
public class BombRangeDec extends Bonus {
|
||||
public BombRangeDec(Position position) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package fr.ubx.poo.ubomb.go.decor.bonus;
|
||||
|
||||
import fr.ubx.poo.ubomb.game.Position;
|
||||
import fr.ubx.poo.ubomb.go.character.Player;
|
||||
import fr.ubx.poo.ubomb.go.Takeable;
|
||||
|
||||
public class BombRangeInc extends Bonus {
|
||||
public BombRangeInc(Position position) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package fr.ubx.poo.ubomb.go.decor.bonus;
|
||||
|
||||
import fr.ubx.poo.ubomb.game.Position;
|
||||
import fr.ubx.poo.ubomb.go.character.Player;
|
||||
import fr.ubx.poo.ubomb.go.Takeable;
|
||||
|
||||
public class Heart extends Bonus {
|
||||
public Heart(Position position) {
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package fr.ubx.poo.ubomb.go.decor.doors;
|
||||
|
||||
import fr.ubx.poo.ubomb.game.Position;
|
||||
import fr.ubx.poo.ubomb.go.Takeable;
|
||||
import fr.ubx.poo.ubomb.go.character.Player;
|
||||
import fr.ubx.poo.ubomb.go.decor.Decor;
|
||||
|
||||
public abstract class Door extends Decor implements Takeable {
|
||||
|
||||
private boolean open;
|
||||
|
||||
public Door(Position p, boolean open) {
|
||||
super(p);
|
||||
this.open = open;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean walkableBy(Player player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object arg0) {
|
||||
return (arg0 instanceof Door d) && d.isOpen() == this.isOpen() && super.equals(arg0);
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
return open;
|
||||
}
|
||||
|
||||
public void setOpen(boolean open) {
|
||||
this.open = open;
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -3,10 +3,10 @@ package fr.ubx.poo.ubomb.go.decor.doors;
|
||||
import fr.ubx.poo.ubomb.game.Position;
|
||||
import fr.ubx.poo.ubomb.go.character.Player;
|
||||
|
||||
public class DoorNextOpened extends Doors {
|
||||
public class DoorNext extends Door {
|
||||
|
||||
public DoorNextOpened(Position position) {
|
||||
super(position);
|
||||
public DoorNext(Position p, boolean open) {
|
||||
super(p, open);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -16,7 +16,7 @@ public class DoorNextOpened extends Doors {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object arg0) {
|
||||
return arg0 instanceof DoorNextOpened && super.equals(arg0);
|
||||
return arg0 instanceof DoorNext && super.equals(arg0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package fr.ubx.poo.ubomb.go.decor.doors;
|
||||
|
||||
import fr.ubx.poo.ubomb.game.Position;
|
||||
|
||||
public class DoorNextClosed extends Doors {
|
||||
|
||||
public DoorNextClosed(Position position) {
|
||||
super(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object arg0) {
|
||||
return arg0 instanceof DoorNextClosed && super.equals(arg0);
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -3,10 +3,10 @@ package fr.ubx.poo.ubomb.go.decor.doors;
|
||||
import fr.ubx.poo.ubomb.game.Position;
|
||||
import fr.ubx.poo.ubomb.go.character.Player;
|
||||
|
||||
public class DoorPrevOpened extends Doors {
|
||||
public class DoorPrev extends Door {
|
||||
|
||||
public DoorPrevOpened(Position position) {
|
||||
super(position);
|
||||
public DoorPrev(Position position) {
|
||||
super(position, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -16,6 +16,6 @@ public class DoorPrevOpened extends Doors {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object arg0) {
|
||||
return arg0 instanceof DoorPrevOpened && super.equals(arg0);
|
||||
return arg0 instanceof DoorPrev && super.equals(arg0);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package fr.ubx.poo.ubomb.go.decor.doors;
|
||||
|
||||
import fr.ubx.poo.ubomb.game.Position;
|
||||
import fr.ubx.poo.ubomb.go.Takeable;
|
||||
import fr.ubx.poo.ubomb.go.Walkable;
|
||||
import fr.ubx.poo.ubomb.go.character.Player;
|
||||
import fr.ubx.poo.ubomb.go.decor.Decor;
|
||||
|
||||
public abstract class Doors extends Decor implements Takeable {
|
||||
public Doors(Position position) {
|
||||
super(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean walkableBy(Player player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object arg0) {
|
||||
return (arg0 instanceof Doors) && super.equals(arg0);
|
||||
}
|
||||
}
|
||||
@@ -6,14 +6,10 @@ import fr.ubx.poo.ubomb.game.Grid;
|
||||
import fr.ubx.poo.ubomb.game.NonStaticObject;
|
||||
import fr.ubx.poo.ubomb.game.Level;
|
||||
import fr.ubx.poo.ubomb.game.Position;
|
||||
import fr.ubx.poo.ubomb.go.GameObject;
|
||||
import fr.ubx.poo.ubomb.go.character.Monster;
|
||||
import fr.ubx.poo.ubomb.go.decor.Box;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
public class GameLauncher {
|
||||
|
||||
@@ -3,7 +3,6 @@ package fr.ubx.poo.ubomb.view;
|
||||
import fr.ubx.poo.ubomb.engine.GameEngine;
|
||||
import fr.ubx.poo.ubomb.game.Game;
|
||||
import fr.ubx.poo.ubomb.launcher.GameLauncher;
|
||||
import fr.ubx.poo.ubomb.launcher.MapLevel;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.input.KeyCombination;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package fr.ubx.poo.ubomb.view;
|
||||
|
||||
import fr.ubx.poo.ubomb.game.Direction;
|
||||
import javafx.scene.image.Image;
|
||||
|
||||
public class ImageResourceFactory {
|
||||
private ImageResourceFactory() {
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
* Copyright (c) 2020. Laurent Réveillère
|
||||
*/
|
||||
|
||||
package fr.ubx.poo.ubomb.view;
|
||||
package fr.ubx.poo.ubomb.view.sprite;
|
||||
|
||||
import fr.ubx.poo.ubomb.game.Position;
|
||||
import fr.ubx.poo.ubomb.go.GameObject;
|
||||
@@ -0,0 +1,23 @@
|
||||
package fr.ubx.poo.ubomb.view.sprite;
|
||||
|
||||
import fr.ubx.poo.ubomb.go.GameObject;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.Door;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.layout.Pane;
|
||||
|
||||
import static fr.ubx.poo.ubomb.view.ImageResource.*;
|
||||
|
||||
public class SpriteDoor extends Sprite {
|
||||
|
||||
public SpriteDoor(Pane layer, Door door) {
|
||||
super(layer, null, (GameObject) door);
|
||||
updateImage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateImage() {
|
||||
Door door = (Door) this.getGameObject();
|
||||
Image image = door.isOpen() ? DOOR_OPENED.getImage() : DOOR_CLOSED.getImage();
|
||||
setImage(image);
|
||||
}
|
||||
}
|
||||
+8
-8
@@ -2,14 +2,14 @@
|
||||
* Copyright (c) 2020. Laurent Réveillère
|
||||
*/
|
||||
|
||||
package fr.ubx.poo.ubomb.view;
|
||||
package fr.ubx.poo.ubomb.view.sprite;
|
||||
|
||||
import fr.ubx.poo.ubomb.go.GameObject;
|
||||
import fr.ubx.poo.ubomb.go.character.Monster;
|
||||
import fr.ubx.poo.ubomb.go.decor.bonus.*;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.DoorNextClosed;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.DoorNextOpened;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.DoorPrevOpened;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.Door;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.DoorNext;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.DoorPrev;
|
||||
import fr.ubx.poo.ubomb.go.decor.*;
|
||||
import javafx.scene.layout.Pane;
|
||||
|
||||
@@ -42,10 +42,10 @@ public final class SpriteFactory {
|
||||
return new Sprite(layer, BONUS_BOMB_NB_DEC.getImage(), gameObject);
|
||||
if (gameObject instanceof Heart)
|
||||
return new Sprite(layer, HEART.getImage(), gameObject);
|
||||
if (gameObject instanceof DoorNextClosed)
|
||||
return new Sprite(layer, DOOR_CLOSED.getImage(), gameObject);
|
||||
if (gameObject instanceof DoorNextOpened || gameObject instanceof DoorPrevOpened)
|
||||
return new Sprite(layer, DOOR_OPENED.getImage(), gameObject);
|
||||
if (gameObject instanceof DoorNext dn && !dn.isOpen())
|
||||
return new SpriteDoor(layer, dn);
|
||||
if (gameObject instanceof DoorNext || gameObject instanceof DoorPrev)
|
||||
return new SpriteDoor(layer, (Door) gameObject);
|
||||
throw new RuntimeException("Unsupported sprite for decor " + gameObject);
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
package fr.ubx.poo.ubomb.view;
|
||||
package fr.ubx.poo.ubomb.view.sprite;
|
||||
|
||||
import fr.ubx.poo.ubomb.go.character.Monster;
|
||||
import fr.ubx.poo.ubomb.view.ImageResourceFactory;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.layout.Pane;
|
||||
|
||||
+2
-1
@@ -2,9 +2,10 @@
|
||||
* Copyright (c) 2020. Laurent Réveillère
|
||||
*/
|
||||
|
||||
package fr.ubx.poo.ubomb.view;
|
||||
package fr.ubx.poo.ubomb.view.sprite;
|
||||
|
||||
import fr.ubx.poo.ubomb.go.character.Player;
|
||||
import fr.ubx.poo.ubomb.view.ImageResourceFactory;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.layout.Pane;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
package maps;
|
||||
|
||||
import static fr.ubx.poo.ubomb.launcher.Entity.*;
|
||||
|
||||
import fr.ubx.poo.ubomb.launcher.Entity;
|
||||
@@ -1,10 +1,11 @@
|
||||
package maps;
|
||||
|
||||
import static fr.ubx.poo.ubomb.launcher.Entity.*;
|
||||
|
||||
import fr.ubx.poo.ubomb.go.decor.Box;
|
||||
import fr.ubx.poo.ubomb.launcher.Entity;
|
||||
import fr.ubx.poo.ubomb.launcher.MapLevel;
|
||||
|
||||
public class TestPropVerif extends MapLevel {
|
||||
public class MapTestLoadFromFile extends MapLevel {
|
||||
private static final Entity[][] level1 = {
|
||||
{ Empty, Empty, Empty, Empty, Empty, Empty, Empty, Empty, Empty, Empty, Box, Box },
|
||||
{ Stone, Stone, Stone, Stone, Tree, Tree, Tree, Tree, Tree, BombRangeInc, BombRangeDec, Empty },
|
||||
@@ -16,7 +17,7 @@ public class TestPropVerif extends MapLevel {
|
||||
private static final int WIDTH = level1[0].length;
|
||||
private static final int HEIGHT = level1.length;
|
||||
|
||||
public TestPropVerif() {
|
||||
public MapTestLoadFromFile() {
|
||||
super(WIDTH, HEIGHT);
|
||||
for (int i = 0; i < WIDTH; i++)
|
||||
for (int j = 0; j < HEIGHT; j++)
|
||||
@@ -1,3 +1,5 @@
|
||||
package tests;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@@ -13,7 +15,7 @@ import fr.ubx.poo.ubomb.game.NonStaticObject;
|
||||
import fr.ubx.poo.ubomb.game.Position;
|
||||
import fr.ubx.poo.ubomb.go.character.Player;
|
||||
import fr.ubx.poo.ubomb.go.decor.Box;
|
||||
import fr.ubx.poo.ubomb.launcher.MapException;
|
||||
import maps.MapLevelTest;
|
||||
|
||||
public class BoxTests {
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package tests;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import fr.ubx.poo.ubomb.game.Configuration;
|
||||
import fr.ubx.poo.ubomb.game.Direction;
|
||||
import fr.ubx.poo.ubomb.game.Game;
|
||||
import fr.ubx.poo.ubomb.game.Level;
|
||||
import fr.ubx.poo.ubomb.game.Position;
|
||||
import fr.ubx.poo.ubomb.go.character.Player;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.DoorNext;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.DoorPrev;
|
||||
import fr.ubx.poo.ubomb.launcher.MapException;
|
||||
import maps.MapLevelTest;
|
||||
|
||||
public class DoorTests {
|
||||
|
||||
private Game game;
|
||||
private Player player;
|
||||
private DoorNext doorNextClosed;
|
||||
private DoorNext doorNextOpened;
|
||||
private DoorPrev doorprev;
|
||||
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
Configuration configuration = new Configuration(new Position(0, 0), 2, 5, 4000, 5, 1000);
|
||||
this.game = new Game(configuration, new Level(new MapLevelTest()));
|
||||
this.player = game.player();
|
||||
this.doorNextClosed = (DoorNext) this.game.grid().get(new Position(1, 12));
|
||||
this.doorNextOpened = (DoorNext) this.game.grid().get(new Position(1, 13));
|
||||
this.doorprev = (DoorPrev) this.game.grid().get(new Position(1, 14));
|
||||
}
|
||||
|
||||
private void verifDoors(boolean nextClosed, boolean nextOpened) {
|
||||
assertTrue(this.doorNextClosed.isOpen() == nextClosed);
|
||||
assertTrue(this.doorNextOpened.isOpen() == nextOpened);
|
||||
assertTrue(this.doorprev.isOpen());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openDoor() {
|
||||
verifDoors(false, true);
|
||||
this.player.openDoor();
|
||||
verifDoors(false, true);
|
||||
for (Direction d : Direction.values()) {
|
||||
Position positionPlayer = d.opposit().nextPosition(this.doorNextClosed.getPosition());
|
||||
this.player.setPosition(positionPlayer);
|
||||
this.player.requestMove(d);
|
||||
this.player.openDoor();
|
||||
verifDoors(false, true);
|
||||
this.player.addKeys(1);
|
||||
this.player.openDoor();
|
||||
verifDoors(true, true);
|
||||
this.doorNextClosed.setOpen(false);
|
||||
verifDoors(false, true);
|
||||
}
|
||||
this.player.setPosition(this.doorNextClosed.getPosition());
|
||||
this.player.openDoor();
|
||||
verifDoors(false, true);
|
||||
this.player.setPosition(this.player.getDirection().opposit().nextPosition(this.doorNextClosed.getPosition()));
|
||||
this.player.addKeys(1);
|
||||
this.player.openDoor();
|
||||
this.player.requestMove(this.player.getDirection());
|
||||
try {
|
||||
this.player.update(0);
|
||||
} catch (MapException e) {
|
||||
return;
|
||||
}
|
||||
assertTrue(false, "this assert shouldn't be executed");
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
package tests;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@@ -13,9 +15,11 @@ import fr.ubx.poo.ubomb.game.Position;
|
||||
import fr.ubx.poo.ubomb.go.character.Monster;
|
||||
import fr.ubx.poo.ubomb.go.decor.Decor;
|
||||
import fr.ubx.poo.ubomb.go.decor.Tree;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.DoorNextClosed;
|
||||
import fr.ubx.poo.ubomb.go.decor.doors.DoorNext;
|
||||
import fr.ubx.poo.ubomb.launcher.GameLauncher;
|
||||
import fr.ubx.poo.ubomb.launcher.MapLevel;
|
||||
import maps.MapLevelTest;
|
||||
import maps.MapTestLoadFromFile;
|
||||
|
||||
public class GameTests {
|
||||
|
||||
@@ -38,7 +42,7 @@ public class GameTests {
|
||||
String filePath = new File("").getAbsolutePath();
|
||||
Game gToTest = GameLauncher.load(filePath + "/src/test/world/test.properties");
|
||||
assertNotNull(gToTest);
|
||||
MapLevel mapTest = new TestPropVerif();
|
||||
MapLevel mapTest = new MapTestLoadFromFile();
|
||||
Configuration configuration = new Configuration(new Position(0, 0), 3, 30, 4000, 5, 10000);
|
||||
Level level = new Level(mapTest);
|
||||
Game gVerif = new Game(configuration, level);
|
||||
@@ -74,6 +78,6 @@ public class GameTests {
|
||||
assertTrue(gToTest.player().getPosition().equals(gToTest.configuration().playerPosition()));
|
||||
gToTest.addLevel(1);
|
||||
assertTrue(gToTest.grid().get(new Position(7, 0)).equals(new Tree(new Position(7, 0))));
|
||||
assertTrue(gToTest.grid().get(new Position(1, 1)).equals(new DoorNextClosed(new Position(1, 1))));
|
||||
assertTrue(gToTest.grid().get(new Position(1, 1)).equals(new DoorNext(new Position(1, 1), false)));
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
package tests;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -10,6 +12,7 @@ import fr.ubx.poo.ubomb.game.Level;
|
||||
import fr.ubx.poo.ubomb.game.Position;
|
||||
import fr.ubx.poo.ubomb.go.character.Player;
|
||||
import fr.ubx.poo.ubomb.launcher.MapException;
|
||||
import maps.MapLevelTest;
|
||||
|
||||
public class PlayerTests {
|
||||
|
||||
@@ -25,6 +28,9 @@ public class PlayerTests {
|
||||
|
||||
@Test
|
||||
public void playerMoves() {
|
||||
assertTrue(this.player.getAvailableBombs() == this.player.getNbBombsMax());
|
||||
this.player.update(0);
|
||||
assertTrue(this.player.getAvailableBombs() == this.player.getNbBombsMax());
|
||||
int i = 0, j = 0;
|
||||
assertTrue(this.player.getDirection().equals(Direction.DOWN));
|
||||
this.player.requestMove(Direction.UP);
|
||||
Reference in new issue
Block a user