summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2015-11-21 10:36:18 +0100
committerPacien TRAN-GIRARD2015-11-21 10:36:18 +0100
commit655ac88f4e73b2df532a451aedf5a561ea1b0d2c (patch)
treeef6f914a465575f313e2b280bf0639d87a4cbd58
parent56279eb59ccdea48b18daa027a5095d861b4e2f4 (diff)
downloadmaze-solver-655ac88f4e73b2df532a451aedf5a561ea1b0d2c.tar.gz
Import project structure
-rw-r--r--img/Animal/Bear.pngbin0 -> 2783 bytes
-rw-r--r--img/Animal/Hamster.pngbin0 -> 3553 bytes
-rw-r--r--img/Animal/Monkey.pngbin0 -> 3242 bytes
-rw-r--r--img/Animal/Mouse.pngbin0 -> 4565 bytes
-rw-r--r--img/Animal/Panda.pngbin0 -> 3339 bytes
-rw-r--r--img/Animal/SpaceInvader.pngbin0 -> 5679 bytes
-rw-r--r--img/Predator/Blinky.pngbin0 -> 754 bytes
-rw-r--r--img/Predator/Clyde.pngbin0 -> 782 bytes
-rw-r--r--img/Predator/Inky.pngbin0 -> 761 bytes
-rw-r--r--img/Predator/Pinky.pngbin0 -> 789 bytes
-rw-r--r--img/Prey/PacMan.big.pngbin0 -> 500 bytes
-rw-r--r--img/Prey/PacMan.pngbin0 -> 363 bytes
-rw-r--r--img/tiles/exit.pngbin0 -> 226 bytes
-rw-r--r--img/tiles/free.pngbin0 -> 221 bytes
-rw-r--r--img/tiles/nothing.pngbin0 -> 222 bytes
-rw-r--r--img/tiles/start.pngbin0 -> 225 bytes
-rw-r--r--img/tiles/wall.pngbin0 -> 222 bytes
-rw-r--r--img/unknown.pngbin0 -> 347 bytes
-rw-r--r--labyrinth.txt16
-rw-r--r--src/ch/epfl/maze/graphics/Animation.java245
-rw-r--r--src/ch/epfl/maze/graphics/Display.java543
-rw-r--r--src/ch/epfl/maze/graphics/GraphicComponent.java237
-rw-r--r--src/ch/epfl/maze/main/Console.java162
-rw-r--r--src/ch/epfl/maze/main/Program.java106
-rw-r--r--src/ch/epfl/maze/physical/Animal.java77
-rw-r--r--src/ch/epfl/maze/physical/Daedalus.java136
-rw-r--r--src/ch/epfl/maze/physical/Maze.java79
-rw-r--r--src/ch/epfl/maze/physical/Predator.java59
-rw-r--r--src/ch/epfl/maze/physical/Prey.java55
-rw-r--r--src/ch/epfl/maze/physical/World.java146
-rw-r--r--src/ch/epfl/maze/physical/pacman/Blinky.java39
-rw-r--r--src/ch/epfl/maze/physical/pacman/Clyde.java40
-rw-r--r--src/ch/epfl/maze/physical/pacman/Inky.java40
-rw-r--r--src/ch/epfl/maze/physical/pacman/PacMan.java32
-rw-r--r--src/ch/epfl/maze/physical/pacman/Pinky.java39
-rw-r--r--src/ch/epfl/maze/physical/zoo/Bear.java46
-rw-r--r--src/ch/epfl/maze/physical/zoo/Hamster.java43
-rw-r--r--src/ch/epfl/maze/physical/zoo/Monkey.java41
-rw-r--r--src/ch/epfl/maze/physical/zoo/Mouse.java41
-rw-r--r--src/ch/epfl/maze/physical/zoo/Panda.java43
-rw-r--r--src/ch/epfl/maze/physical/zoo/SpaceInvader.java52
-rw-r--r--src/ch/epfl/maze/simulation/DaedalusSimulation.java364
-rw-r--r--src/ch/epfl/maze/simulation/MazeSimulation.java211
-rw-r--r--src/ch/epfl/maze/simulation/Simulation.java84
-rw-r--r--src/ch/epfl/maze/tests/AnimalTest.java100
-rw-r--r--src/ch/epfl/maze/tests/Competition.java163
-rw-r--r--src/ch/epfl/maze/tests/DaedalusTest.java123
-rw-r--r--src/ch/epfl/maze/tests/GhostsTest.java149
-rw-r--r--src/ch/epfl/maze/tests/MazeTest.java91
-rw-r--r--src/ch/epfl/maze/tests/WorldTest.java330
-rw-r--r--src/ch/epfl/maze/tests/ZooTest.java209
-rw-r--r--src/ch/epfl/maze/util/Action.java101
-rw-r--r--src/ch/epfl/maze/util/Direction.java235
-rw-r--r--src/ch/epfl/maze/util/LabyrinthGenerator.java533
-rw-r--r--src/ch/epfl/maze/util/Statistics.java197
-rw-r--r--src/ch/epfl/maze/util/Vector2D.java228
56 files changed, 5435 insertions, 0 deletions
diff --git a/img/Animal/Bear.png b/img/Animal/Bear.png
new file mode 100644
index 0000000..1ba6ec6
--- /dev/null
+++ b/img/Animal/Bear.png
Binary files differ
diff --git a/img/Animal/Hamster.png b/img/Animal/Hamster.png
new file mode 100644
index 0000000..3aadd70
--- /dev/null
+++ b/img/Animal/Hamster.png
Binary files differ
diff --git a/img/Animal/Monkey.png b/img/Animal/Monkey.png
new file mode 100644
index 0000000..bcea339
--- /dev/null
+++ b/img/Animal/Monkey.png
Binary files differ
diff --git a/img/Animal/Mouse.png b/img/Animal/Mouse.png
new file mode 100644
index 0000000..6b9e95d
--- /dev/null
+++ b/img/Animal/Mouse.png
Binary files differ
diff --git a/img/Animal/Panda.png b/img/Animal/Panda.png
new file mode 100644
index 0000000..199238a
--- /dev/null
+++ b/img/Animal/Panda.png
Binary files differ
diff --git a/img/Animal/SpaceInvader.png b/img/Animal/SpaceInvader.png
new file mode 100644
index 0000000..cd9ebe8
--- /dev/null
+++ b/img/Animal/SpaceInvader.png
Binary files differ
diff --git a/img/Predator/Blinky.png b/img/Predator/Blinky.png
new file mode 100644
index 0000000..7143fd2
--- /dev/null
+++ b/img/Predator/Blinky.png
Binary files differ
diff --git a/img/Predator/Clyde.png b/img/Predator/Clyde.png
new file mode 100644
index 0000000..04c7c30
--- /dev/null
+++ b/img/Predator/Clyde.png
Binary files differ
diff --git a/img/Predator/Inky.png b/img/Predator/Inky.png
new file mode 100644
index 0000000..f6efa4a
--- /dev/null
+++ b/img/Predator/Inky.png
Binary files differ
diff --git a/img/Predator/Pinky.png b/img/Predator/Pinky.png
new file mode 100644
index 0000000..d50102e
--- /dev/null
+++ b/img/Predator/Pinky.png
Binary files differ
diff --git a/img/Prey/PacMan.big.png b/img/Prey/PacMan.big.png
new file mode 100644
index 0000000..c1b0e17
--- /dev/null
+++ b/img/Prey/PacMan.big.png
Binary files differ
diff --git a/img/Prey/PacMan.png b/img/Prey/PacMan.png
new file mode 100644
index 0000000..d766f25
--- /dev/null
+++ b/img/Prey/PacMan.png
Binary files differ
diff --git a/img/tiles/exit.png b/img/tiles/exit.png
new file mode 100644
index 0000000..5286a5a
--- /dev/null
+++ b/img/tiles/exit.png
Binary files differ
diff --git a/img/tiles/free.png b/img/tiles/free.png
new file mode 100644
index 0000000..1804c42
--- /dev/null
+++ b/img/tiles/free.png
Binary files differ
diff --git a/img/tiles/nothing.png b/img/tiles/nothing.png
new file mode 100644
index 0000000..5219d54
--- /dev/null
+++ b/img/tiles/nothing.png
Binary files differ
diff --git a/img/tiles/start.png b/img/tiles/start.png
new file mode 100644
index 0000000..ff429b6
--- /dev/null
+++ b/img/tiles/start.png
Binary files differ
diff --git a/img/tiles/wall.png b/img/tiles/wall.png
new file mode 100644
index 0000000..c216e26
--- /dev/null
+++ b/img/tiles/wall.png
Binary files differ
diff --git a/img/unknown.png b/img/unknown.png
new file mode 100644
index 0000000..97c58b8
--- /dev/null
+++ b/img/unknown.png
Binary files differ
diff --git a/labyrinth.txt b/labyrinth.txt
new file mode 100644
index 0000000..4b7a42b
--- /dev/null
+++ b/labyrinth.txt
@@ -0,0 +1,16 @@
1
2To load this labyrinth, write :
3
4 int[][] labyrinth = LabyrinthGenerator.readFromFile("labyrinth.txt");
5
61 2 1 1 1 1 1 1 1 1 1
71 0 0 0 0 1 0 0 0 0 1
81 0 1 1 1 1 1 0 1 0 1
91 0 1 0 0 0 0 0 1 0 1
101 0 1 0 1 1 1 0 1 0 1
111 0 0 0 1 0 1 0 1 1 1
121 1 1 1 1 0 1 0 1 0 3
131 0 0 0 0 0 1 0 1 0 1
141 0 1 1 1 1 1 0 1 0 1
151 0 0 0 0 0 0 0 0 0 1
161 1 1 1 1 1 1 1 1 1 1 \ No newline at end of file
diff --git a/src/ch/epfl/maze/graphics/Animation.java b/src/ch/epfl/maze/graphics/Animation.java
new file mode 100644
index 0000000..0502a92
--- /dev/null
+++ b/src/ch/epfl/maze/graphics/Animation.java
@@ -0,0 +1,245 @@
1package ch.epfl.maze.graphics;
2
3import java.awt.Graphics2D;
4import java.awt.image.BufferedImage;
5import java.awt.image.ImageObserver;
6import java.io.File;
7import java.io.IOException;
8import java.util.HashMap;
9import java.util.List;
10import java.util.Map;
11import java.util.TreeMap;
12
13import javax.imageio.ImageIO;
14
15import ch.epfl.maze.physical.Animal;
16import ch.epfl.maze.util.Action;
17import ch.epfl.maze.util.Direction;
18import ch.epfl.maze.util.Vector2D;
19
20/**
21 * Handles the animation of a {@code Simulation} by extrapolating the positions
22 * of animals.
23 *
24 */
25
26public final class Animation {
27
28 /** Default number of waiting frames to display when animation is aborting. */
29 public static final int DEFAULT_WAITING_FRAMES = 2;
30
31 /** Maps animals identity to graphical components that will be animated. */
32 private Map<Integer, GraphicComponent> mGraphMap;
33
34 /** Buffer of images of animals. Key format: "superclass.class" */
35 private Map<String, BufferedImage> mImages;
36
37 /** Drawing ratio variable. */
38 private float mRatio;
39
40 /** Control variable. */
41 private boolean mDone;
42
43 /** Current number of waiting frames, to prevent screen from flashing. */
44 private int mWaitingFrames;
45
46 /**
47 * Constructs an animation handler that will animate animals on a graphic
48 * environment by extrapolating their position.
49 *
50 * @param animals
51 * The {@code List} of animals that will be shown on the first
52 * frame
53 */
54
55 public Animation(List<Animal> animals) {
56 mGraphMap = new TreeMap<Integer, GraphicComponent>();
57 mImages = new HashMap<String, BufferedImage>();
58
59 // sanity check
60 if (animals != null) {
61 // puts default action to draw animals and loads corresponding image
62 Action none = new Action(Direction.NONE);
63 for (int i = 0; i < animals.size(); i++) {
64 Animal animal = animals.get(i);
65 BufferedImage img = loadImage(animal);
66 Vector2D position = animal.getPosition().mul(Display.SQUARE_SIZE);
67
68 mGraphMap.put(i, new GraphicComponent(img, position, none));
69 }
70 }
71
72 // default values
73 mDone = true;
74 mWaitingFrames = 0;
75 }
76
77 /**
78 * Asks the animation to update an animal on the screen with a corresponding
79 * action. The animal is identified by a number, so it can be overwritten in
80 * case of a future update.
81 *
82 * @param animal
83 * Animal to update with action
84 * @param id
85 * Unique identifier for animal
86 * @param action
87 * Action that animal needs to perform
88 */
89
90 public void update(Animal animal, int id, Action action) {
91 // sanity checks
92 if (action == null) {
93 action = new Action(Direction.NONE, false);
94 }
95 if (animal != null) {
96 // retrieves BufferedImage
97 String folder = animal.getClass().getSuperclass().getSimpleName();
98 String file = animal.getClass().getSimpleName();
99 BufferedImage img = mImages.get(folder + "." + file);