diff options
author | Adam NAILI | 2018-02-01 20:58:24 +0100 |
---|---|---|
committer | Adam NAILI | 2018-02-01 20:58:24 +0100 |
commit | a07c49065165b2f896684a57d647f2b1a13b68ca (patch) | |
tree | dc825b31d14503208e8250a001b5ec128afb81c1 /src/main/java/fr/umlv | |
parent | 5bff076cc86aa7c09baea850c3617ee2c1253594 (diff) | |
parent | 735be27e8802740cf0986bb6d14e720234889aae (diff) | |
download | wallj-a07c49065165b2f896684a57d647f2b1a13b68ca.tar.gz |
Merge branch 'master' of https://github.com/pacien/upem-java-wallj
Diffstat (limited to 'src/main/java/fr/umlv')
40 files changed, 487 insertions, 502 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 d3c349e..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,44 +1,25 @@ | |||
1 | package fr.umlv.java.wallj.block; | 1 | package fr.umlv.java.wallj.block; |
2 | 2 | ||
3 | import fr.umlv.java.wallj.board.TileVec2; | 3 | import fr.umlv.java.wallj.board.TileVec2; |
4 | import fr.umlv.java.wallj.context.Context; | 4 | import fr.umlv.java.wallj.context.Updateable; |
5 | import fr.umlv.java.wallj.controller.BlockController; | ||
6 | import fr.umlv.java.wallj.controller.Controller; | ||
7 | import fr.umlv.java.wallj.event.Event; | ||
8 | import org.jbox2d.common.Vec2; | 5 | import org.jbox2d.common.Vec2; |
6 | import org.jbox2d.dynamics.World; | ||
9 | 7 | ||
10 | import java.util.*; | 8 | import java.util.*; |
11 | import java.util.stream.Collectors; | ||
12 | 9 | ||
13 | /** | 10 | /** |
14 | * A block. | 11 | * A block. |
15 | * | 12 | * |
16 | * @author Pacien TRAN-GIRARD | 13 | * @author Pacien TRAN-GIRARD |
17 | */ | 14 | */ |
18 | public abstract class Block { | 15 | public abstract class Block implements Updateable { |
19 | |||
20 | private final BlockType type; | 16 | private final BlockType type; |
21 | private List<Controller> controllers; | ||
22 | private Vec2 pos; | ||
23 | 17 | ||
24 | /** | 18 | /** |
25 | * @param type type of block | 19 | * @param type type of block |
26 | * @param pos initial position | ||
27 | */ | 20 | */ |
28 | Block(BlockType type, Vec2 pos) { | 21 | Block(BlockType type) { |
29 | this.type = Objects.requireNonNull(type); | 22 | this.type = Objects.requireNonNull(type); |
30 | this.pos = Objects.requireNonNull(pos).clone(); | ||
31 | } | ||
32 | |||
33 | void setControllers(List<BlockController> l) { | ||
34 | controllers = Collections.unmodifiableList(new LinkedList<>(Objects.requireNonNull(l))); | ||
35 | } | ||
36 | |||
37 | /** | ||
38 | * @param pos new position to set | ||
39 | */ | ||
40 | public void setPos(Vec2 pos) { | ||
41 | this.pos = Objects.requireNonNull(pos).clone(); | ||
42 | } | 23 | } |
43 | 24 | ||
44 | /** | 25 | /** |
@@ -49,27 +30,19 @@ public abstract class Block { | |||
49 | } | 30 | } |
50 | 31 | ||
51 | /** | 32 | /** |
52 | * @return the current position | ||
53 | */ | ||
54 | public Vec2 getPos() { | ||
55 | return pos.clone(); | ||
56 | } | ||
57 | |||
58 | /** | ||
59 | * @return the current tile position | 33 | * @return the current tile position |
60 | */ | 34 | */ |
61 | public TileVec2 getTile() { | 35 | public TileVec2 getTile() { |
62 | return TileVec2.of(pos); | 36 | return TileVec2.of(getPos()); |
63 | } | 37 | } |
64 | 38 | ||
65 | /** | 39 | /** |
66 | * @param ctx execution context | 40 | * @return the current position |
67 | * @return list of generated events | ||
68 | */ | 41 | */ |
69 | public List<Event> update(Context ctx) { | 42 | public abstract Vec2 getPos(); |
70 | return controllers.stream() | ||
71 | .flatMap(controller -> controller.update(ctx).stream()) | ||
72 | .collect(Collectors.toList()); | ||
73 | } | ||
74 | 43 | ||
44 | /** | ||
45 | * @param world a JBox2D world | ||
46 | */ | ||
47 | public abstract void link(World world); | ||
75 | } | 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 @@ | |||
1 | package fr.umlv.java.wallj.block; | 1 | package fr.umlv.java.wallj.block; |
2 | 2 | ||
3 | import fr.umlv.java.wallj.board.TileVec2; | 3 | import fr.umlv.java.wallj.board.TileVec2; |
4 | import fr.umlv.java.wallj.controller.BlockControllerFactory; | ||
5 | import org.jbox2d.common.Vec2; | 4 | import 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 @@ | |||
1 | package fr.umlv.java.wallj.block; | 1 | package fr.umlv.java.wallj.block; |
2 | 2 | ||
3 | import fr.umlv.java.wallj.board.TileVec2; | ||
4 | import fr.umlv.java.wallj.context.Context; | ||
5 | import fr.umlv.java.wallj.context.GraphicsContext; | ||
6 | import fr.umlv.java.wallj.event.Event; | ||
3 | import org.jbox2d.common.Vec2; | 7 | import org.jbox2d.common.Vec2; |
8 | import org.jbox2d.dynamics.BodyType; | ||
9 | |||
10 | import java.awt.*; | ||
11 | import java.time.Duration; | ||
12 | import java.util.Arrays; | ||
13 | import java.util.Collections; | ||
14 | import 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 | ||