aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/fr/umlv
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/fr/umlv')
-rw-r--r--src/main/java/fr/umlv/java/wallj/block/Block.java47
-rw-r--r--src/main/java/fr/umlv/java/wallj/block/BlockFactory.java5
-rw-r--r--src/main/java/fr/umlv/java/wallj/block/BombBlock.java59
-rw-r--r--src/main/java/fr/umlv/java/wallj/block/GarbageBlock.java23
-rw-r--r--src/main/java/fr/umlv/java/wallj/block/JBoxBlock.java36
-rw-r--r--src/main/java/fr/umlv/java/wallj/block/RobotBlock.java49
-rw-r--r--src/main/java/fr/umlv/java/wallj/block/SolidDef.java45
-rw-r--r--src/main/java/fr/umlv/java/wallj/block/TrashBlock.java23
-rw-r--r--src/main/java/fr/umlv/java/wallj/block/WallBlock.java23
-rw-r--r--src/main/java/fr/umlv/java/wallj/context/Game.java1
-rw-r--r--src/main/java/fr/umlv/java/wallj/context/Stage.java (renamed from src/main/java/fr/umlv/java/wallj/block/Stage.java)9
-rw-r--r--src/main/java/fr/umlv/java/wallj/controller/BlockController.java21
-rw-r--r--src/main/java/fr/umlv/java/wallj/controller/BlockControllerFactory.java49
-rw-r--r--src/main/java/fr/umlv/java/wallj/controller/BombDisplayController.java35
-rw-r--r--src/main/java/fr/umlv/java/wallj/controller/BombPhysicsController.java26
-rw-r--r--src/main/java/fr/umlv/java/wallj/controller/GarbageDisplayController.java30
-rw-r--r--src/main/java/fr/umlv/java/wallj/controller/GarbagePhysicsController.java25
-rw-r--r--src/main/java/fr/umlv/java/wallj/controller/PhysicsController.java12
-rw-r--r--src/main/java/fr/umlv/java/wallj/controller/RobotDisplayController.java30
-rw-r--r--src/main/java/fr/umlv/java/wallj/controller/RobotPhysicsController.java26
-rw-r--r--src/main/java/fr/umlv/java/wallj/controller/StagePhysicsController.java4
-rw-r--r--src/main/java/fr/umlv/java/wallj/controller/TrashDisplayController.java30
-rw-r--r--src/main/java/fr/umlv/java/wallj/controller/TrashPhysicsController.java25
-rw-r--r--src/main/java/fr/umlv/java/wallj/controller/WallDisplayController.java30
-rw-r--r--src/main/java/fr/umlv/java/wallj/controller/WallPhysicsController.java26
25 files changed, 254 insertions, 435 deletions
diff --git a/src/main/java/fr/umlv/java/wallj/block/Block.java b/src/main/java/fr/umlv/java/wallj/block/Block.java
index ba299b4..7ae9c06 100644
--- a/src/main/java/fr/umlv/java/wallj/block/Block.java
+++ b/src/main/java/fr/umlv/java/wallj/block/Block.java
@@ -1,15 +1,11 @@
1package fr.umlv.java.wallj.block; 1package fr.umlv.java.wallj.block;
2 2
3import fr.umlv.java.wallj.board.TileVec2; 3import fr.umlv.java.wallj.board.TileVec2;
4import fr.umlv.java.wallj.context.Context;
5import fr.umlv.java.wallj.context.Updateable; 4import fr.umlv.java.wallj.context.Updateable;
6import fr.umlv.java.wallj.controller.BlockController;
7import fr.umlv.java.wallj.controller.Controller;
8import fr.umlv.java.wallj.event.Event;
9import org.jbox2d.common.Vec2; 5import org.jbox2d.common.Vec2;
6import org.jbox2d.dynamics.World;
10 7
11import java.util.*; 8import java.util.*;
12import java.util.stream.Collectors;
13 9
14/** 10/**
15 * A block. 11 * A block.
@@ -17,29 +13,13 @@ import java.util.stream.Collectors;
17 * @author Pacien TRAN-GIRARD 13 * @author Pacien TRAN-GIRARD
18 */ 14 */
19public abstract class Block implements Updateable { 15public abstract class Block implements Updateable {
20
21 private final BlockType type; 16 private final BlockType type;
22 private List<Controller> controllers;
23 private Vec2 pos;
24 17
25 /** 18 /**
26 * @param type type of block 19 * @param type type of block
27 * @param pos initial position
28 */ 20 */
29 Block(BlockType type, Vec2 pos) { 21 Block(BlockType type) {
30 this.type = Objects.requireNonNull(type); 22 this.type = Objects.requireNonNull(type);
31 this.pos = Objects.requireNonNull(pos).clone();
32 }
33
34 void setControllers(List<BlockController> l) {
35 controllers = Collections.unmodifiableList(new LinkedList<>(Objects.requireNonNull(l)));
36 }
37
38 /**
39 * @param pos new position to set
40 */
41 public void setPos(Vec2 pos) {
42 this.pos = Objects.requireNonNull(pos).clone();
43 } 23 }
44 24
45 /** 25 /**
@@ -50,28 +30,19 @@ public abstract class Block implements Updateable {
50 } 30 }
51 31
52 /** 32 /**
53 * @return the current position
54 */
55 public Vec2 getPos() {
56 return pos.clone();
57 }
58
59 /**
60 * @return the current tile position 33 * @return the current tile position
61 */ 34 */
62 public TileVec2 getTile() { 35 public TileVec2 getTile() {
63 return TileVec2.of(pos); 36 return TileVec2.of(getPos());
64 } 37 }
65 38
66 /** 39 /**
67 * @param ctx execution context 40 * @return the current position
68 * @return list of generated events
69 */ 41 */
70 @Override 42 public abstract Vec2 getPos();
71 public List<Event> update(Context ctx) {
72 return controllers.stream()
73 .flatMap(controller -> controller.update(ctx).stream())
74 .collect(Collectors.toList());
75 }
76 43
44 /**
45 * @param world a JBox2D world
46 */
47 public abstract void link(World world);
77} 48}
diff --git a/src/main/java/fr/umlv/java/wallj/block/BlockFactory.java b/src/main/java/fr/umlv/java/wallj/block/BlockFactory.java
index 951d182..acd280f 100644
--- a/src/main/java/fr/umlv/java/wallj/block/BlockFactory.java
+++ b/src/main/java/fr/umlv/java/wallj/block/BlockFactory.java
@@ -1,7 +1,6 @@
1package fr.umlv.java.wallj.block; 1package fr.umlv.java.wallj.block;
2 2
3import fr.umlv.java.wallj.board.TileVec2; 3import fr.umlv.java.wallj.board.TileVec2;
4import fr.umlv.java.wallj.controller.BlockControllerFactory;
5import org.jbox2d.common.Vec2; 4import org.jbox2d.common.Vec2;
6 5
7/** 6/**
@@ -30,9 +29,7 @@ public final class BlockFactory {
30 } 29 }
31 30
32 public static Block build(BlockType type, TileVec2 pos) { 31 public static Block build(BlockType type, TileVec2 pos) {
33 Block block = forType(type, pos.toVec2()); 32 return forType(type, pos.toVec2());
34 if (block != null) block.setControllers(BlockControllerFactory.build(block));
35 return block;
36 } 33 }
37 34
38 private BlockFactory() { 35 private BlockFactory() {
diff --git a/src/main/java/fr/umlv/java/wallj/block/BombBlock.java b/src/main/java/fr/umlv/java/wallj/block/BombBlock.java
index de7a3b9..f58f1cc 100644
--- a/src/main/java/fr/umlv/java/wallj/block/BombBlock.java
+++ b/src/main/java/fr/umlv/java/wallj/block/BombBlock.java
@@ -1,28 +1,69 @@
1package fr.umlv.java.wallj.block; 1package fr.umlv.java.wallj.block;
2 2
3import fr.umlv.java.wallj.board.TileVec2;
4import fr.umlv.java.wallj.context.Context;
5import fr.umlv.java.wallj.context.GraphicsContext;
6import fr.umlv.java.wallj.event.Event;
3import org.jbox2d.common.Vec2; 7import org.jbox2d.common.Vec2;
8import org.jbox2d.dynamics.BodyType;
9
10import java.awt.*;
11import java.time.Duration;
12import java.util.Arrays;
13import java.util.Collections;
14import java.util.List;
4 15
5/** 16/**
6 * A bomb block. 17 * A bomb block.
7 * 18 *
8 * @author Pacien TRAN-GIRARD 19 * @author Pacien TRAN-GIRARD
20 * @author Adam NAILI
9 */ 21 */
10public class BombBlock extends Block { 22public class BombBlock extends JBoxBlock {
11 23 private static final Duration TIME_INCREMENT = Duration.ofSeconds(1);
12 private static final int INITIAL_TIMER = 1; // sec 24 private static final Duration MIN_TIME = Duration.ofSeconds(1);
25 private static final Duration MAX_TIME = Duration.ofSeconds(9);
13 26
14 private int timer = INITIAL_TIMER; 27 private Duration timer = MIN_TIME;
15 28
16 BombBlock(Vec2 pos) { 29 BombBlock(Vec2 pos) {
17 super(BlockType.BOMB, pos); 30 super(BlockType.BOMB, BodyType.STATIC, SolidDef.squareShape(), pos);
31 }
32
33 private void incrementTimer() {
34 timer = timer.compareTo(MAX_TIME) <= 0 ? timer.plus(TIME_INCREMENT) : MIN_TIME;
35 }
36
37 private void decrementTimer(Duration d) {
38 if (timer.isNegative()) throw new IllegalStateException("This bomb has already exploded.");
39 timer = timer.minus(d);
18 } 40 }
19 41
20 public void setTimer(int sec) { 42 @Override
21 timer = sec; 43 public List<Event> update(Context context) {
44 if (containsUpdateEvent(context.getEvents())) incrementTimer();
45 paint(context.getGraphicsContext());