summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2015-11-21 10:44:42 +0100
committerPacien TRAN-GIRARD2015-11-21 10:44:42 +0100
commit90bd766f361083f6fd9e39ff080c83fcc606832f (patch)
treedf81a931c9565a4b227068680087f58fdace1859 /src
parent655ac88f4e73b2df532a451aedf5a561ea1b0d2c (diff)
downloadmaze-solver-90bd766f361083f6fd9e39ff080c83fcc606832f.tar.gz
Reformat imported code
Diffstat (limited to 'src')
-rw-r--r--src/ch/epfl/maze/graphics/Animation.java453
-rw-r--r--src/ch/epfl/maze/graphics/Display.java1030
-rw-r--r--src/ch/epfl/maze/graphics/GraphicComponent.java432
-rw-r--r--src/ch/epfl/maze/main/Console.java273
-rw-r--r--src/ch/epfl/maze/main/Program.java124
-rw-r--r--src/ch/epfl/maze/physical/Animal.java104
-rw-r--r--src/ch/epfl/maze/physical/Daedalus.java238
-rw-r--r--src/ch/epfl/maze/physical/Maze.java105
-rw-r--r--src/ch/epfl/maze/physical/Predator.java89
-rw-r--r--src/ch/epfl/maze/physical/Prey.java81
-rw-r--r--src/ch/epfl/maze/physical/World.java259
-rw-r--r--src/ch/epfl/maze/physical/pacman/Blinky.java40
-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.java29
-rw-r--r--src/ch/epfl/maze/physical/pacman/Pinky.java40
-rw-r--r--src/ch/epfl/maze/physical/zoo/Bear.java64
-rw-r--r--src/ch/epfl/maze/physical/zoo/Hamster.java56
-rw-r--r--src/ch/epfl/maze/physical/zoo/Monkey.java54
-rw-r--r--src/ch/epfl/maze/physical/zoo/Mouse.java54
-rw-r--r--src/ch/epfl/maze/physical/zoo/Panda.java52
-rw-r--r--src/ch/epfl/maze/physical/zoo/SpaceInvader.java58
-rw-r--r--src/ch/epfl/maze/simulation/DaedalusSimulation.java681
-rw-r--r--src/ch/epfl/maze/simulation/MazeSimulation.java381
-rw-r--r--src/ch/epfl/maze/simulation/Simulation.java108
-rw-r--r--src/ch/epfl/maze/tests/AnimalTest.java169
-rw-r--r--src/ch/epfl/maze/tests/Competition.java263
-rw-r--r--src/ch/epfl/maze/tests/DaedalusTest.java209
-rw-r--r--src/ch/epfl/maze/tests/GhostsTest.java246
-rw-r--r--src/ch/epfl/maze/tests/MazeTest.java117
-rw-r--r--src/ch/epfl/maze/tests/WorldTest.java625
-rw-r--r--src/ch/epfl/maze/tests/ZooTest.java364
-rw-r--r--src/ch/epfl/maze/util/Action.java149
-rw-r--r--src/ch/epfl/maze/util/Direction.java445
-rw-r--r--src/ch/epfl/maze/util/LabyrinthGenerator.java1032
-rw-r--r--src/ch/epfl/maze/util/Statistics.java357
-rw-r--r--src/ch/epfl/maze/util/Vector2D.java426
37 files changed, 4543 insertions, 4744 deletions
diff --git a/src/ch/epfl/maze/graphics/Animation.java b/src/ch/epfl/maze/graphics/Animation.java
index 0502a92..47e0fc8 100644
--- a/src/ch/epfl/maze/graphics/Animation.java
+++ b/src/ch/epfl/maze/graphics/Animation.java
@@ -1,6 +1,12 @@
1package ch.epfl.maze.graphics; 1package ch.epfl.maze.graphics;
2 2
3import java.awt.Graphics2D; 3import ch.epfl.maze.physical.Animal;
4import ch.epfl.maze.util.Action;
5import ch.epfl.maze.util.Direction;
6import ch.epfl.maze.util.Vector2D;
7
8import javax.imageio.ImageIO;
9import java.awt.*;
4import java.awt.image.BufferedImage; 10import java.awt.image.BufferedImage;
5import java.awt.image.ImageObserver; 11import java.awt.image.ImageObserver;
6import java.io.File; 12import java.io.File;
@@ -10,236 +16,231 @@ import java.util.List;
10import java.util.Map; 16import java.util.Map;
11import java.util.TreeMap; 17import java.util.TreeMap;
12 18
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/** 19/**
21 * Handles the animation of a {@code Simulation} by extrapolating the positions 20 * Handles the animation of a {@code Simulation} by extrapolating the positions
22 * of animals. 21 * of animals.
23 *
24 */ 22 */
25 23
26public final class Animation { 24public final class Animation {
27 25
28 /** Default number of waiting frames to display when animation is aborting. */ 26 /**
29 public static final int DEFAULT_WAITING_FRAMES = 2; 27 * Default number of waiting frames to display when animation is aborting.
30 28 */
31 /** Maps animals identity to graphical components that will be animated. */ 29 public static final int DEFAULT_WAITING_FRAMES = 2;
32 private Map<Integer, GraphicComponent> mGraphMap; 30
33 31 /**
34 /** Buffer of images of animals. Key format: "superclass.class" */ 32 * Maps animals identity to graphical components that will be animated.
35 private Map<String, BufferedImage> mImages; 33 */
36 34 private Map<Integer, GraphicComponent> mGraphMap;
37 /** Drawing ratio variable. */ 35
38 private float mRatio; 36 /**
39 37 * Buffer of images of animals. Key format: "superclass.class"
40 /** Control variable. */ 38 */
41 private boolean mDone; 39 private Map<String, BufferedImage> mImages;
42 40
43 /** Current number of waiting frames, to prevent screen from flashing. */ 41 /**
44 private int mWaitingFrames; 42 * Drawing ratio variable.
45 43 */
46 /** 44 private float mRatio;
47 * Constructs an animation handler that will animate animals on a graphic 45
48 * environment by extrapolating their position. 46 /**
49 * 47 * Control variable.
50 * @param animals 48 */
51 * The {@code List} of animals that will be shown on the first 49 private boolean mDone;
52 * frame 50
53 */ 51 /**
54 52 * Current number of waiting frames, to prevent screen from flashing.
55 public Animation(List<Animal> animals) { 53 */
56 mGraphMap = new TreeMap<Integer, GraphicComponent>(); 54 private int mWaitingFrames;
57 mImages = new HashMap<String, BufferedImage>(); 55
58 56 /**
59 // sanity check 57 * Constructs an animation handler that will animate animals on a graphic
60 if (animals != null) { 58 * environment by extrapolating their position.
61 // puts default action to draw animals and loads corresponding image 59 *
62 Action none = new Action(Direction.NONE); 60 * @param animals The {@code List} of animals that will be shown on the first
63 for (int i = 0; i < animals.size(); i++) { 61 * frame
64 Animal animal = animals.get(i); 62 */
65 BufferedImage img = loadImage(animal); 63
66 Vector2D position = animal.getPosition().mul(Display.SQUARE_SIZE); 64 public Animation(List<Animal> animals) {
67 65 mGraphMap = new TreeMap<Integer, GraphicComponent>();
68 mGraphMap.put(i, new GraphicComponent(img, position, none)); 66 mImages = new HashMap<String, BufferedImage>();
69 } 67
70 } 68 // sanity check
71 69 if (animals != null) {
72 // default values 70 // puts default action to draw animals and loads corresponding image
73 mDone = true; 71 Action none = new Action(Direction.NONE);
74 mWaitingFrames = 0; 72 for (int i = 0; i < animals.size(); i++) {
75 } 73 Animal animal = animals.get(i);
76 74 BufferedImage img = loadImage(animal);
77 /** 75 Vector2D position = animal.getPosition().mul(Display.SQUARE_SIZE);
78 * Asks the animation to update an animal on the screen with a corresponding 76
79 * action. The animal is identified by a number, so it can be overwritten in 77 mGraphMap.put(i, new GraphicComponent(img, position, none));
80 * case of a future update. 78 }
81 * 79 }
82 * @param animal 80
83 * Animal to update with action 81 // default values
84 * @param id 82 mDone = true;
85 * Unique identifier for animal 83 mWaitingFrames = 0;
86 * @param action 84 }
87 * Action that animal needs to perform 85
88 */ 86 /**
89 87 * Asks the animation to update an animal on the screen with a corresponding
90 public void update(Animal animal, int id, Action action) { 88 * action. The animal is identified by a number, so it can be overwritten in
91 // sanity checks 89 * case of a future update.
92 if (action == null) { 90 *
93 action = new Action(Direction.NONE, false); 91 * @param animal Animal to update with action
94 } 92 * @param id Unique identifier for animal
95 if (animal != null) { 93 * @param action Action that animal needs to perform
96 // retrieves BufferedImage 94 */
97 String folder = animal.getClass().getSuperclass().getSimpleName(); 95
98 String file = animal.getClass().getSimpleName(); 96 public void update(Animal animal, int id, Action action) {
99 BufferedImage img = mImages.get(folder + "." + file); 97 // sanity checks
100 if (img == null) { 98 if (action == null) {
101 img = loadImage(animal); 99 action = new Action(Direction.NONE, false);
102 } 100 }
103 101 if (animal != null) {
104 // transforms position 102 // retrieves BufferedImage
105 Vector2D position = animal.