From 00d6b788396d314354f8f00fdbc884c80450d9d7 Mon Sep 17 00:00:00 2001 From: pacien Date: Wed, 10 Jan 2018 19:43:24 +0100 Subject: No CRLF. thanks. Signed-off-by: pacien --- src/main/java/fr/umlv/java/wallj/board/Board.java | 136 ++++++++--------- .../fr/umlv/java/wallj/board/BoardConverter.java | 10 +- .../java/fr/umlv/java/wallj/board/BoardParser.java | 142 +++++++++--------- .../fr/umlv/java/wallj/board/BoardValidator.java | 10 +- .../java/fr/umlv/java/wallj/board/TileVec2.java | 166 ++++++++++----------- .../java/fr/umlv/java/wallj/context/Context.java | 98 ++++++------ src/main/java/fr/umlv/java/wallj/context/Game.java | 130 ++++++++-------- .../umlv/java/wallj/context/GraphicsContext.java | 124 +++++++-------- .../fr/umlv/java/wallj/context/InputHandler.java | 120 +++++++-------- .../fr/umlv/java/wallj/context/ScreenManager.java | 76 +++++----- .../java/wallj/controller/BlockController.java | 42 +++--- .../wallj/controller/BlockControllerFactory.java | 98 ++++++------ .../wallj/controller/BombDisplayController.java | 50 +++---- .../wallj/controller/BombPhysicsController.java | 50 +++---- .../fr/umlv/java/wallj/controller/Controller.java | 20 +-- .../java/wallj/controller/DisplayController.java | 24 +-- .../umlv/java/wallj/controller/GameController.java | 24 +-- .../wallj/controller/GarbageDisplayController.java | 50 +++---- .../wallj/controller/GarbagePhysicsController.java | 50 +++---- .../java/wallj/controller/PhysicsController.java | 24 +-- .../wallj/controller/RobotDisplayController.java | 50 +++---- .../wallj/controller/RobotPhysicsController.java | 50 +++---- .../java/wallj/controller/StageController.java | 24 +-- .../wallj/controller/TrashDisplayController.java | 50 +++---- .../wallj/controller/TrashPhysicsController.java | 50 +++---- .../wallj/controller/WallDisplayController.java | 50 +++---- .../wallj/controller/WallPhysicsController.java | 50 +++---- .../fr/umlv/java/wallj/event/AddBombEvent.java | 26 ++-- .../fr/umlv/java/wallj/event/ConfirmEvent.java | 10 +- .../fr/umlv/java/wallj/event/DropBombEvent.java | 10 +- src/main/java/fr/umlv/java/wallj/event/Event.java | 8 +- .../fr/umlv/java/wallj/event/MoveRobotEvent.java | 28 ++-- src/main/java/fr/umlv/java/wallj/model/Block.java | 150 +++++++++---------- .../fr/umlv/java/wallj/model/BlockFactory.java | 84 +++++------ .../java/fr/umlv/java/wallj/model/BlockType.java | 114 +++++++------- .../java/fr/umlv/java/wallj/model/BombBlock.java | 62 ++++---- .../fr/umlv/java/wallj/model/GarbageBlock.java | 38 ++--- .../java/fr/umlv/java/wallj/model/RobotBlock.java | 38 ++--- src/main/java/fr/umlv/java/wallj/model/Stage.java | 10 +- .../java/fr/umlv/java/wallj/model/TrashBlock.java | 38 ++--- .../java/fr/umlv/java/wallj/model/WallBlock.java | 38 ++--- .../java/fr/umlv/java/wallj/utils/PathFinder.java | 10 +- .../java/fr/umlv/java/wallj/viewer/Viewer.java | 66 ++++---- 43 files changed, 1249 insertions(+), 1249 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/fr/umlv/java/wallj/board/Board.java b/src/main/java/fr/umlv/java/wallj/board/Board.java index c697cc2..a4ac421 100644 --- a/src/main/java/fr/umlv/java/wallj/board/Board.java +++ b/src/main/java/fr/umlv/java/wallj/board/Board.java @@ -1,68 +1,68 @@ -package fr.umlv.java.wallj.board; - -import fr.umlv.java.wallj.model.BlockType; -import fr.umlv.java.wallj.utils.Matrix; - -/** - * An immutable BlockType matrix. - * - * @author Pacien TRAN-GIRARD - */ -public final class Board { - - /** - * Board Builder - */ - public static final class Builder { - private final BlockType[][] map; - - /** - * @param width width in tiles - * @param height height in tiles - */ - public Builder(int width, int height) { - this.map = new BlockType[width][height]; - } - - /** - * @param pos the tile position vector - * @param type the BlockType to set - * @return the Builder - */ - public Builder setBlockTypeAt(TileVec2 pos, BlockType type) { - map[pos.getCol()][pos.getRow()] = type; - return this; - } - - /** - * @return the immutable Board - */ - public Board build() { - return new Board(map); - } - } - - private final BlockType[][] map; - - private Board(BlockType[][] map) { - int w = Matrix.getWidth(map), h = Matrix.getHeight(map); - this.map = new BlockType[h][w]; - for (int row = 0; row < h; ++row) System.arraycopy(map[row], 0, this.map[row], 0, w); - } - - /** - * @param pos the tile position vector - * @return the element at the given position - */ - public BlockType getBlockTypeAt(TileVec2 pos) { - return map[pos.getCol()][pos.getRow()]; - } - - /** - * @return the dimension of the Board - */ - public TileVec2 getDim() { - return TileVec2.of(Matrix.getWidth(map), Matrix.getHeight(map)); - } - -} +package fr.umlv.java.wallj.board; + +import fr.umlv.java.wallj.model.BlockType; +import fr.umlv.java.wallj.utils.Matrix; + +/** + * An immutable BlockType matrix. + * + * @author Pacien TRAN-GIRARD + */ +public final class Board { + + /** + * Board Builder + */ + public static final class Builder { + private final BlockType[][] map; + + /** + * @param width width in tiles + * @param height height in tiles + */ + public Builder(int width, int height) { + this.map = new BlockType[width][height]; + } + + /** + * @param pos the tile position vector + * @param type the BlockType to set + * @return the Builder + */ + public Builder setBlockTypeAt(TileVec2 pos, BlockType type) { + map[pos.getCol()][pos.getRow()] = type; + return this; + } + + /** + * @return the immutable Board + */ + public Board build() { + return new Board(map); + } + } + + private final BlockType[][] map; + + private Board(BlockType[][] map) { + int w = Matrix.getWidth(map), h = Matrix.getHeight(map); + this.map = new BlockType[h][w]; + for (int row = 0; row < h; ++row) System.arraycopy(map[row], 0, this.map[row], 0, w); + } + + /** + * @param pos the tile position vector + * @return the element at the given position + */ + public BlockType getBlockTypeAt(TileVec2 pos) { + return map[pos.getCol()][pos.getRow()]; + } + + /** + * @return the dimension of the Board + */ + public TileVec2 getDim() { + return TileVec2.of(Matrix.getWidth(map), Matrix.getHeight(map)); + } + +} diff --git a/src/main/java/fr/umlv/java/wallj/board/BoardConverter.java b/src/main/java/fr/umlv/java/wallj/board/BoardConverter.java index 4f67458..9f5736a 100644 --- a/src/main/java/fr/umlv/java/wallj/board/BoardConverter.java +++ b/src/main/java/fr/umlv/java/wallj/board/BoardConverter.java @@ -1,5 +1,5 @@ -package fr.umlv.java.wallj.board; - -public class BoardConverter { - //TODO -} +package fr.umlv.java.wallj.board; + +public class BoardConverter { + //TODO +} diff --git a/src/main/java/fr/umlv/java/wallj/board/BoardParser.java b/src/main/java/fr/umlv/java/wallj/board/BoardParser.java index 3d8386a..a9dca27 100644 --- a/src/main/java/fr/umlv/java/wallj/board/BoardParser.java +++ b/src/main/java/fr/umlv/java/wallj/board/BoardParser.java @@ -1,71 +1,71 @@ -package fr.umlv.java.wallj.board; - -import fr.umlv.java.wallj.model.BlockType; -import fr.umlv.java.wallj.utils.Matrix; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; -import java.util.ListIterator; -import java.util.stream.Collectors; - -/** - * Board deserializer. - * - * @author Pacien TRAN-GIRARD - */ -public final class BoardParser { - - private static Board buildBoard(List> map) { - if (!Matrix.isShapeValid(map)) throw new IllegalArgumentException("Board must be rectangular."); - - Board.Builder b = new Board.Builder(Matrix.getWidth(map), Matrix.getHeight(map)); - for (ListIterator> line = map.listIterator(); line.hasNext(); ) - for (ListIterator block = line.next().listIterator(); block.hasNext(); ) - b.setBlockTypeAt(TileVec2.of(line.previousIndex(), block.nextIndex()), block.next()); - - return b.build(); - } - - private static BlockType parseChar(int c) { - switch (c) { - case ' ': - return BlockType.FREE; - case 'W': - return BlockType.WALL; - case 'T': - return BlockType.TRASH; - case 'G': - return BlockType.GARBAGE; - default: - return null; - } - } - - private static List parseLine(String line) { - return line.chars() - .mapToObj(BoardParser::parseChar) - .collect(Collectors.toList()); - } - - /** - * Parses a block from a file. - * - * @param filePath path to the map file - * @return the parsed Board - * @throws IOException any IO exception that happened while reading the file - */ - public static Board parse(Path filePath) throws IOException { - return buildBoard(Files.lines(filePath) - .filter(s -> !s.isEmpty()) - .map(String::trim) - .map(BoardParser::parseLine) - .collect(Collectors.toList())); - } - - private BoardParser() { - // static class - } - -} +package fr.umlv.java.wallj.board; + +import fr.umlv.java.wallj.model.BlockType; +import fr.umlv.java.wallj.utils.Matrix; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.ListIterator; +import java.util.stream.Collectors; + +/** + * Board deserializer. + * + * @author Pacien TRAN-GIRARD + */ +public final class BoardParser { + + private static Board buildBoard(List> map) { + if (!Matrix.isShapeValid(map)) throw new IllegalArgumentException("Board must be rectangular."); + + Board.Builder b = new Board.Builder(Matrix.getWidth(map), Matrix.getHeight(map)); + for (ListIterator> line = map.listIterator(); line.hasNext(); ) + for (ListIterator block = line.next().listIterator(); block.hasNext(); ) + b.setBlockTypeAt(TileVec2.of(line.previousIndex(), block.nextIndex()), block.next()); + + return b.build(); + } + + private static BlockType parseChar(int c) { + switch (c) { + case ' ': + return BlockType.FREE; + case 'W': + return BlockType.WALL; + case 'T': + return BlockType.TRASH; + case 'G': + return BlockType.GARBAGE; + default: + return null; + } + } + + private static List parseLine(String line) { + return line.chars() + .mapToObj(BoardParser::parseChar) + .collect(Collectors.toList()); + } + + /** + * Parses a block from a file. + * + * @param filePath path to the map file + * @return the parsed Board + * @throws IOException any IO exception that happened while reading the file + */ + public static Board parse(Path filePath) throws IOException { + return buildBoard(Files.lines(filePath) + .filter(s -> !s.isEmpty()) + .map(String::trim) + .map(BoardParser::parseLine) + .collect(Collectors.toList())); + } + + private BoardParser() { + // static class + } + +} diff --git a/src/main/java/fr/umlv/java/wallj/board/BoardValidator.java b/src/main/java/fr/umlv/java/wallj/board/BoardValidator.java index 98bf4be..0e51bc6 100644 --- a/src/main/java/fr/umlv/java/wallj/board/BoardValidator.java +++ b/src/main/java/fr/umlv/java/wallj/board/BoardValidator.java @@ -1,5 +1,5 @@ -package fr.umlv.java.wallj.board; - -public class BoardValidator { - //TODO -} +package fr.umlv.java.wallj.board; + +public class BoardValidator { + //TODO +} diff --git a/src/main/java/fr/umlv/java/wallj/board/TileVec2.java b/src/main/java/fr/umlv/java/wallj/board/TileVec2.java index 6ccd116..60a2b75 100644 --- a/src/main/java/fr/umlv/java/wallj/board/TileVec2.java +++ b/src/main/java/fr/umlv/java/wallj/board/TileVec2.java @@ -1,83 +1,83 @@ -package fr.umlv.java.wallj.board; - -import org.jbox2d.common.Vec2; - -import java.util.Objects; - -/** - * A typed immutable tile coordinate vector containing the coordinates of a Tile in a Board. - * - * @author Pacien TRAN-GIRARD - */ -public final class TileVec2 { - - private static final int TILE_DIM = 20; - - /** - * @param row the row - * @param col the column - * @return a corresponding tile vector - */ - public static TileVec2 of(int row, int col) { - return new TileVec2(row, col); - } - - /** - * @param v a JBox2D Vec2 vector - * @return the coordinates of the tile containing the given point - */ - public static TileVec2 of(Vec2 v) { - return new TileVec2((int) (v.x / TILE_DIM), (int) (v.y / TILE_DIM)); - } - - private final int row, col; - - private TileVec2(int row, int col) { - this.row = row; - this.col = col; - } - - /** - * @return the row - */ - public int getRow() { - return row; - } - - /** - * @return the column - */ - public int getCol() { - return col; - } - - /** - * @return the corresponding JBox2D coordinates of the top-left corner of the tile - */ - public Vec2 toVec2() { - return new Vec2(row * TILE_DIM, col * TILE_DIM); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof TileVec2)) return false; - TileVec2 tileVec2 = (TileVec2) o; - return row == tileVec2.row && - col == tileVec2.col; - } - - @Override - public int hashCode() { - return Objects.hash(row, col); - } - - @Override - public String toString() { - return "TileVec2{" + - "row=" + row + - ", col=" + col + - '}'; - } - -} +package fr.umlv.java.wallj.board; + +import org.jbox2d.common.Vec2; + +import java.util.Objects; + +/** + * A typed immutable tile coordinate vector containing the coordinates of a Tile in a Board. + * + * @author Pacien TRAN-GIRARD + */ +public final class TileVec2 { + + private static final int TILE_DIM = 20; + + /** + * @param row the row + * @param col the column + * @return a corresponding tile vector + */ + public static TileVec2 of(int row, int col) { + return new TileVec2(row, col); + } + + /** + * @param v a JBox2D Vec2 vector + * @return the coordinates of the tile containing the given point + */ + public static TileVec2 of(Vec2 v) { + return new TileVec2((int) (v.x / TILE_DIM), (int) (v.y / TILE_DIM)); + } + + private final int row, col; + + private TileVec2(int row, int col) { + this.row = row; + this.col = col; + } + + /** + * @return the row + */ + public int getRow() { + return row; + } + + /** + * @return the column + */ + public int getCol() { + return col; + } + + /** + * @return the corresponding JBox2D coordinates of the top-left corner of the tile + */ + public Vec2 toVec2() { + return new Vec2(row * TILE_DIM, col * TILE_DIM); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof TileVec2)) return false; + TileVec2 tileVec2 = (TileVec2) o; + return row == tileVec2.row && + col == tileVec2.col; + } + + @Override + public int hashCode() { + return Objects.hash(row, col); + } + + @Override + public String toString() { + return "TileVec2{" + + "row=" + row + + ", col=" + col + + '}'; + } + +} diff --git a/src/main/java/fr/umlv/java/wallj/context/Context.java b/src/main/java/fr/umlv/java/wallj/context/Context.java index 1f188de..de9c461 100644 --- a/src/main/java/fr/umlv/java/wallj/context/Context.java +++ b/src/main/java/fr/umlv/java/wallj/context/Context.java @@ -1,49 +1,49 @@ -package fr.umlv.java.wallj.context; - -import fr.umlv.java.wallj.event.Event; -import fr.umlv.java.wallj.model.Stage; - -import java.util.List; -import java.util.Objects; - -/** - * A context used to store the current state of the application at one tick - */ -public final class Context { - //TODO Class Context - private final Stage stage; - private final List events; - private final GraphicsContext graphicsContext; - - /** - * @param stage the current stage - * @param events the list of events of the tick - * @param graphicsContext the current graphics context - */ - public Context(Stage stage, List events, GraphicsContext graphicsContext) { - this.stage = Objects.requireNonNull(stage); - this.events = Objects.requireNonNull(events); - this.graphicsContext = Objects.requireNonNull(graphicsContext); - } - - /** - * @return the stage - */ - public Stage getStage() { - return stage; - } - - /** - * @return the list of events - */ - public List getEvents() { - return events; - } - - /** - * @return the graphics context - */ - public GraphicsContext getGraphicsContext() { - return graphicsContext; - } -} +package fr.umlv.java.wallj.context; + +import fr.umlv.java.wallj.event.Event; +import fr.umlv.java.wallj.model.Stage; + +import java.util.List; +import java.util.Objects; + +/** + * A context used to store the current state of the application at one tick + */ +public final class Context { + //TODO Class Context + private final Stage stage; + private final List events; + private final GraphicsContext graphicsContext; + + /** + * @param stage the current stage + * @param events the list of events of the tick + * @param graphicsContext the current graphics context + */ + public Context(Stage stage, List events, GraphicsContext graphicsContext) { + this.stage = Objects.requireNonNull(stage); + this.events = Objects.requireNonNull(events); + this.graphicsContext = Objects.requireNonNull(graphicsContext); + } + + /** + * @return the stage + */ + public Stage getStage() { + return stage; + } + + /** + * @return the list of events + */ + public List getEvents() { + return events; + } + + /** + * @return the graphics context + */ + public GraphicsContext getGraphicsContext() { + return graphicsContext; + } +} diff --git a/src/main/java/fr/umlv/java/wallj/context/Game.java b/src/main/java/fr/umlv/java/wallj/context/Game.java index ba7cb58..53f61b4 100644 --- a/src/main/java/fr/umlv/java/wallj/context/Game.java +++ b/src/main/java/fr/umlv/java/wallj/context/Game.java @@ -1,65 +1,65 @@ -package fr.umlv.java.wallj.context; - -import fr.umlv.java.wallj.board.Board; -import fr.umlv.java.wallj.controller.GameController; - -import java.util.Collections; -import java.util.List; -import java.util.NoSuchElementException; -import java.util.Objects; - -/** - * A game. - */ -public final class Game { - //TODO - private final GameController gameController; - private int indexBoard; - private final List boards; - - /** - * @param gameController the controller of the game - * @param boards the list of boards charged for the game - */ - public Game(GameController gameController, List boards) { - this.gameController = Objects.requireNonNull(gameController); - Objects.requireNonNull(boards); - if (boards.isEmpty()) { - throw new IllegalArgumentException("The list of boards is empty, not able to create a correct game from this."); - } - this.boards = Collections.unmodifiableList(boards); - this.indexBoard = 0; - } - - /** - * @return the game controller - */ - public GameController getGameController() { - return gameController; - } - - /** - * @return the current board of the game. - */ - public Board getCurrentBoard() { - return boards.get(indexBoard); - } - - /** - * @return a boolean on the condition of having a next Board in our game. - */ - public boolean hasNextBoard() { - return indexBoard + 1 < boards.size(); - } - - /** - * @return the next board - */ - public Board nextBoard() { - if (indexBoard >= boards.size()) { - throw new NoSuchElementException("No more board for the game."); - } - indexBoard++; - return boards.get(indexBoard); - } -} +package fr.umlv.java.wallj.context; + +import fr.umlv.java.wallj.board.Board; +import fr.umlv.java.wallj.controller.GameController; + +import java.util.Collections; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Objects; + +/** + * A game. + */ +public final class Game { + //TODO + private final GameController gameController; + private int indexBoard; + private final List boards; + + /** + * @param gameController the controller of the game + * @param boards the list of boards charged for the game + */ + public Game(GameController gameController, List boards) { + this.gameController = Objects.requireNonNull(gameController); + Objects.requireNonNull(boards); + if (boards.isEmpty()) { + throw new IllegalArgumentException("The list of boards is empty, not able to create a correct game from this."); + } + this.boards = Collections.unmodifiableList(boards); + this.indexBoard = 0; + } + + /** + * @return the game controller + */ + public GameController getGameController() { + return gameController; + } + + /** + * @return the current board of the game. + */ + public Board getCurrentBoard() { + return boards.get(indexBoard); + } + + /** + * @return a boolean on the condition of having a next Board in our game. + */ + public boolean hasNextBoard() { + return indexBoard + 1 < boards.size(); + } + + /** + * @return the next board + */ + public Board nextBoard() { + if (indexBoard >= boards.size()) { + throw new NoSuchElementException("No more board for the game."); + } + indexBoard++; + return boards.get(indexBoard); + } +} diff --git a/src/main/java/fr/umlv/java/wallj/context/GraphicsContext.java b/src/main/java/fr/umlv/java/wallj/context/GraphicsContext.java index 46c326a..9d5ec0d 100644 --- a/src/main/java/fr/umlv/java/wallj/context/GraphicsContext.java +++ b/src/main/java/fr/umlv/java/wallj/context/GraphicsContext.java @@ -1,62 +1,62 @@ -package fr.umlv.java.wallj.context; - -import fr.umlv.zen5.ScreenInfo; -import org.jbox2d.common.Vec2; - -import java.awt.*; -import java.awt.geom.Ellipse2D; -import java.awt.geom.Rectangle2D; -import java.util.Objects; - -/** - * A context of the current graphic status of the application. - */ -public final class GraphicsContext { - //TODO Class GraphicsContext - private final Graphics2D graphics2D; - private final ScreenInfo screenInfo; - - /** - * @param graphics2D the current drawable canvas - * @param screenInfo the informations about the screen - */ - public GraphicsContext(Graphics2D graphics2D, ScreenInfo screenInfo) { - this.graphics2D = Objects.requireNonNull(graphics2D); - this.screenInfo = Objects.requireNonNull(screenInfo); - } - - /** - * @return the drawable canvas - */ - public Graphics2D getGraphics2D() { - return graphics2D; - } - - /** - * @return the screen informations - */ - public ScreenInfo getScreenInfo() { - return screenInfo; - } - - /** - * @param color the color of the circle - * @param position the upper left corner of the rectangle frame that contains the circle - * @param size size of the circle - */ - public void paintCircle(Color color, Vec2 position, float size) { - graphics2D.setColor(color); - graphics2D.fill(new Ellipse2D.Float(position.x, position.y, size, size)); - } - - /** - * @param color the color of the rectangle - * @param position the upper left corner of the rectangle - * @param width width of the rectangle - * @param height height of the rectangle - */ - public void paintRectangle(Color color, Vec2 position, float width, float height) { - graphics2D.setColor(color); - graphics2D.fill(new Rectangle2D.Float(position.x, position.y, width, height)); - } -} +package fr.umlv.java.wallj.context; + +import fr.umlv.zen5.ScreenInfo; +import org.jbox2d.common.Vec2; + +import java.awt.*; +import java.awt.geom.Ellipse2D; +import java.awt.geom.Rectangle2D; +import java.util.Objects; + +/** + * A context of the current graphic status of the application. + */ +public final class GraphicsContext { + //TODO Class GraphicsContext + private final Graphics2D graphics2D; + private final ScreenInfo screenInfo; + + /** + * @param graphics2D the current drawable canvas + * @param screenInfo the informations about the screen + */ + public GraphicsContext(Graphics2D graphics2D, ScreenInfo screenInfo) { + this.graphics2D = Objects.requireNonNull(graphics2D); + this.screenInfo = Objects.requireNonNull(screenInfo); + } + + /** + * @return the drawable canvas + */ + public Graphics2D getGraphics2D() { + return graphics2D; + } + + /** + * @return the screen informations + */ + public ScreenInfo getScreenInfo() { + return screenInfo; + } + + /** + * @param color the color of the circle + * @param position the upper left corner of the rectangle frame that contains the circle + * @param size size of the circle + */ + public void paintCircle(Color color, Vec2 position, float size) { + graphics2D.setColor(color); + graphics2D.fill(new Ellipse2D.Float(position.x, position.y, size, size)); + } + + /** + * @param color the color of the rectangle + * @param position the upper left corner of the rectangle + * @param width width of the rectangle + * @param height height of the rectangle + */ + public void paintRectangle(Color color, Vec2 position, float width, float height) { + graphics2D.setColor(color); + graphics2D.fill(new Rectangle2D.Float(position.x, position.y, width, height)); + } +} diff --git a/src/main/java/fr/umlv/java/wallj/context/InputHandler.java b/src/main/java/fr/umlv/java/wallj/context/InputHandler.java index 171f665..e3546fa 100644 --- a/src/main/java/fr/umlv/java/wallj/context/InputHandler.java +++ b/src/main/java/fr/umlv/java/wallj/context/InputHandler.java @@ -1,60 +1,60 @@ -package fr.umlv.java.wallj.context; - -import fr.umlv.java.wallj.board.TileVec2; -import fr.umlv.java.wallj.event.DropBombEvent; -import fr.umlv.java.wallj.event.MoveRobotEvent; -import fr.umlv.zen5.ApplicationContext; -import fr.umlv.zen5.Event; -import fr.umlv.zen5.KeyboardKey; -import org.jbox2d.common.Vec2; - -import java.awt.geom.Point2D; -import java.util.LinkedList; -import java.util.List; -import java.util.Objects; - - -/** - * Treats the inputs from the keyboard and mouse provided by Zen 5 and creates Events meaningful for the game. - */ -public final class InputHandler { - //TODO Class InputHandler - private final ApplicationContext applicationContext; - - /** - * @param applicationContext the Zen5 application context - */ - public InputHandler(ApplicationContext applicationContext) { - this.applicationContext = Objects.requireNonNull(applicationContext); - } - - /** - * @return the list of events converted from Zen 5 events to game events - */ - List getEvents() { - LinkedList events = new LinkedList<>(); - fr.umlv.zen5.Event event = applicationContext.pollEvent(); - if (event != null) { - Event.Action action = event.getAction(); - Point2D.Float location = event.getLocation(); - if (location != null) { //Mouse Handling - if (action == Event.Action.POINTER_DOWN) { - Vec2 mouseLocation = new Vec2(location.x, location.y); - TileVec2 mouseTileLocation = TileVec2.of(mouseLocation); - events.add(new MoveRobotEvent(mouseTileLocation)); - } - } - KeyboardKey keyboardKey = event.getKey(); - if (keyboardKey != null) { //Keyboard Handling - if (action == Event.Action.KEY_PRESSED) { - switch (keyboardKey) { - case SPACE: - events.add(new DropBombEvent()); - break; - } - } - } - } - return events; - } -} +package fr.umlv.java.wallj.context; + +import fr.umlv.java.wallj.board.TileVec2; +import fr.umlv.java.wallj.event.DropBombEvent; +import fr.umlv.java.wallj.event.MoveRobotEvent; +import fr.umlv.zen5.ApplicationContext; +import fr.umlv.zen5.Event; +import fr.umlv.zen5.KeyboardKey; +import org.jbox2d.common.Vec2; + +import java.awt.geom.Point2D; +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; + + +/** + * Treats the inputs from the keyboard and mouse provided by Zen 5 and creates Events meaningful for the game. + */ +public final class InputHandler { + //TODO Class InputHandler + private final ApplicationContext applicationContext; + + /** + * @param applicationContext the Zen5 application context + */ + public InputHandler(ApplicationContext applicationContext) { + this.applicationContext = Objects.requireNonNull(applicationContext); + } + + /** + * @return the list of events converted from Zen 5 events to game events + */ + List getEvents() { + LinkedList events = new LinkedList<>(); + fr.umlv.zen5.Event event = applicationContext.pollEvent(); + if (event != null) { + Event.Action action = event.getAction(); + Point2D.Float location = event.getLocation(); + if (location != null) { //Mouse Handling + if (action == Event.Action.POINTER_DOWN) { + Vec2 mouseLocation = new Vec2(location.x, location.y); + TileVec2 mouseTileLocation = TileVec2.of(mouseLocation); + events.add(new MoveRobotEvent(mouseTileLocation)); + } + } + KeyboardKey keyboardKey = event.getKey(); + if (keyboardKey != null) { //Keyboard Handling + if (action == Event.Action.KEY_PRESSED) { + switch (keyboardKey) { + case SPACE: + events.add(new DropBombEvent()); + break; + } + } + } + } + return events; + } +} diff --git a/src/main/java/fr/umlv/java/wallj/context/ScreenManager.java b/src/main/java/fr/umlv/java/wallj/context/ScreenManager.java index 9d6255f..d687246 100644 --- a/src/main/java/fr/umlv/java/wallj/context/ScreenManager.java +++ b/src/main/java/fr/umlv/java/wallj/context/ScreenManager.java @@ -1,38 +1,38 @@ -package fr.umlv.java.wallj.context; - -import fr.umlv.zen5.ApplicationContext; -import fr.umlv.zen5.ScreenInfo; -import org.jbox2d.common.Vec2; - -import java.awt.Graphics2D; -import java.util.Objects; - -/** - * Cleans the GraphicsContext - */ -public final class ScreenManager { - //TODO Class ScreenManager - private final ApplicationContext applicationContext; - private final Graphics2D graphics2D; - - /** - * - * @param applicationContext the current application context - * @param graphics2D the current graphics2D - */ - public ScreenManager(ApplicationContext applicationContext, Graphics2D graphics2D) { - this.applicationContext = Objects.requireNonNull(applicationContext); - this.graphics2D = Objects.requireNonNull(graphics2D); - } - - /** - * - * @return a graphic context - */ - public GraphicsContext clearScreen() { - ScreenInfo screenInfo = applicationContext.getScreenInfo(); - GraphicsContext graphicsContext = new GraphicsContext(graphics2D, screenInfo); - graphicsContext.paintRectangle(graphics2D.getBackground(), new Vec2(0, 0), screenInfo.getWidth(), screenInfo.getHeight()); - return graphicsContext; - } -} +package fr.umlv.java.wallj.context; + +import fr.umlv.zen5.ApplicationContext; +import fr.umlv.zen5.ScreenInfo; +import org.jbox2d.common.Vec2; + +import java.awt.Graphics2D; +import java.util.Objects; + +/** + * Cleans the GraphicsContext + */ +public final class ScreenManager { + //TODO Class ScreenManager + private final ApplicationContext applicationContext; + private final Graphics2D graphics2D; + + /** + * + * @param applicationContext the current application context + * @param graphics2D the current graphics2D + */ + public ScreenManager(ApplicationContext applicationContext, Graphics2D graphics2D) { + this.applicationContext = Objects.requireNonNull(applicationContext); + this.graphics2D = Objects.requireNonNull(graphics2D); + } + + /** + * + * @return a graphic context + */ + public GraphicsContext clearScreen() { + ScreenInfo screenInfo = applicationContext.getScreenInfo(); + GraphicsContext graphicsContext = new GraphicsContext(graphics2D, screenInfo); + graphicsContext.paintRectangle(graphics2D.getBackground(), new Vec2(0, 0), screenInfo.getWidth(), screenInfo.getHeight()); + return graphicsContext; + } +} diff --git a/src/main/java/fr/umlv/java/wallj/controller/BlockController.java b/src/main/java/fr/umlv/java/wallj/controller/BlockController.java index bafa74a..1e0279e 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/BlockController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/BlockController.java @@ -1,21 +1,21 @@ -package fr.umlv.java.wallj.controller; - -import fr.umlv.java.wallj.context.Context; -import fr.umlv.java.wallj.event.Event; -import fr.umlv.java.wallj.model.Block; - -import java.util.List; -import java.util.Objects; - -public abstract class BlockController implements Controller { - - private final Block block; - - BlockController(Block block) { - this.block = Objects.requireNonNull(block); - } - - //TODO Check UML to implement BlockController - public abstract List update(Context context); - -} +package fr.umlv.java.wallj.controller; + +import fr.umlv.java.wallj.context.Context; +import fr.umlv.java.wallj.event.Event; +import fr.umlv.java.wallj.model.Block; + +import java.util.List; +import java.util.Objects; + +public abstract class BlockController implements Controller { + + private final Block block; + + BlockController(Block block) { + this.block = Objects.requireNonNull(block); + } + + //TODO Check UML to implement BlockController + public abstract List update(Context context); + +} diff --git a/src/main/java/fr/umlv/java/wallj/controller/BlockControllerFactory.java b/src/main/java/fr/umlv/java/wallj/controller/BlockControllerFactory.java index 89d45ca..f0d17ab 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/BlockControllerFactory.java +++ b/src/main/java/fr/umlv/java/wallj/controller/BlockControllerFactory.java @@ -1,49 +1,49 @@ -package fr.umlv.java.wallj.controller; - -import fr.umlv.java.wallj.model.*; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -/** - * A block controller factory. - * "I am the man who arranges the blocks that descend upon me from up above..." - * - * @author Pacien TRAN-GIRARD - */ -public final class BlockControllerFactory { - - /** - * @implNote no Lists.of in JDK8 - */ - private static List listOf(BlockController... controllers) { - return Collections.unmodifiableList(Arrays.asList(controllers)); - } - - /** - * Builds the controllers for the given block. - * - * @param b block - * @return list of controllers - */ - public static List build(Block b) { - if (b instanceof WallBlock) - return listOf(new WallPhysicsController((WallBlock) b), new WallDisplayController((WallBlock) b)); - if (b instanceof TrashBlock) - return listOf(new TrashPhysicsController((TrashBlock) b), new TrashDisplayController((TrashBlock) b)); - if (b instanceof GarbageBlock) - return listOf(new GarbagePhysicsController((GarbageBlock) b), new GarbageDisplayController((GarbageBlock) b)); - if (b instanceof RobotBlock) - return listOf(new RobotPhysicsController((RobotBlock) b), new RobotDisplayController((RobotBlock) b)); - if (b instanceof BombBlock) - return listOf(new BombPhysicsController((BombBlock) b), new BombDisplayController((BombBlock) b)); - - return Collections.emptyList(); - } - - private BlockControllerFactory() { - // static class - } - -} +package fr.umlv.java.wallj.controller; + +import fr.umlv.java.wallj.model.*; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * A block controller factory. + * "I am the man who arranges the blocks that descend upon me from up above..." + * + * @author Pacien TRAN-GIRARD + */ +public final class BlockControllerFactory { + + /** + * @implNote no Lists.of in JDK8 + */ + private static List listOf(BlockController... controllers) { + return Collections.unmodifiableList(Arrays.asList(controllers)); + } + + /** + * Builds the controllers for the given block. + * + * @param b block + * @return list of controllers + */ + public static List build(Block b) { + if (b instanceof WallBlock) + return listOf(new WallPhysicsController((WallBlock) b), new WallDisplayController((WallBlock) b)); + if (b instanceof TrashBlock) + return listOf(new TrashPhysicsController((TrashBlock) b), new TrashDisplayController((TrashBlock) b)); + if (b instanceof GarbageBlock) + return listOf(new GarbagePhysicsController((GarbageBlock) b), new GarbageDisplayController((GarbageBlock) b)); + if (b instanceof RobotBlock) + return listOf(new RobotPhysicsController((RobotBlock) b), new RobotDisplayController((RobotBlock) b)); + if (b instanceof BombBlock) + return listOf(new BombPhysicsController((BombBlock) b), new BombDisplayController((BombBlock) b)); + + return Collections.emptyList(); + } + + private BlockControllerFactory() { + // static class + } + +} diff --git a/src/main/java/fr/umlv/java/wallj/controller/BombDisplayController.java b/src/main/java/fr/umlv/java/wallj/controller/BombDisplayController.java index 3347b73..aa652a8 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/BombDisplayController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/BombDisplayController.java @@ -1,25 +1,25 @@ -package fr.umlv.java.wallj.controller; - -import fr.umlv.java.wallj.context.Context; -import fr.umlv.java.wallj.event.Event; -import fr.umlv.java.wallj.model.BombBlock; - -import java.util.List; -import java.util.Objects; - -public class BombDisplayController extends DisplayController { - - private final BombBlock bomb; - - BombDisplayController(BombBlock bomb) { - super(bomb); - this.bomb = Objects.requireNonNull(bomb); - } - - @Override - public List update(Context context) { - //TODO - return null; - } - -} +package fr.umlv.java.wallj.controller; + +import fr.umlv.java.wallj.context.Context; +import fr.umlv.java.wallj.event.Event; +import fr.umlv.java.wallj.model.BombBlock; + +import java.util.List; +import java.util.Objects; + +public class BombDisplayController extends DisplayController { + + private final BombBlock bomb; + + BombDisplayController(BombBlock bomb) { + super(bomb); + this.bomb = Objects.requireNonNull(bomb); + } + + @Override + public List update(Context context) { + //TODO + return null; + } + +} diff --git a/src/main/java/fr/umlv/java/wallj/controller/BombPhysicsController.java b/src/main/java/fr/umlv/java/wallj/controller/BombPhysicsController.java index 02f00a3..45a3626 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/BombPhysicsController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/BombPhysicsController.java @@ -1,25 +1,25 @@ -package fr.umlv.java.wallj.controller; - -import fr.umlv.java.wallj.context.Context; -import fr.umlv.java.wallj.event.Event; -import fr.umlv.java.wallj.model.BombBlock; - -import java.util.List; -import java.util.Objects; - -public class BombPhysicsController extends PhysicsController { - - private final BombBlock bomb; - - BombPhysicsController(BombBlock bomb) { - super(bomb); - this.bomb = Objects.requireNonNull(bomb); - } - - @Override - public List update(Context context) { - //TODO - return null; - } - -} +package fr.umlv.java.wallj.controller; + +import fr.umlv.java.wallj.context.Context; +import fr.umlv.java.wallj.event.Event; +import fr.umlv.java.wallj.model.BombBlock; + +import java.util.List; +import java.util.Objects; + +public class BombPhysicsController extends PhysicsController { + + private final BombBlock bomb; + + BombPhysicsController(BombBlock bomb) { + super(bomb); + this.bomb = Objects.requireNonNull(bomb); + } + + @Override + public List update(Context context) { + //TODO + return null; + } + +} diff --git a/src/main/java/fr/umlv/java/wallj/controller/Controller.java b/src/main/java/fr/umlv/java/wallj/controller/Controller.java index 6a28d62..20218ff 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/Controller.java +++ b/src/main/java/fr/umlv/java/wallj/controller/Controller.java @@ -1,10 +1,10 @@ -package fr.umlv.java.wallj.controller; - -import fr.umlv.java.wallj.context.Context; -import fr.umlv.java.wallj.event.Event; - -import java.util.List; - -public interface Controller { - List update(Context context); -} +package fr.umlv.java.wallj.controller; + +import fr.umlv.java.wallj.context.Context; +import fr.umlv.java.wallj.event.Event; + +import java.util.List; + +public interface Controller { + List update(Context context); +} diff --git a/src/main/java/fr/umlv/java/wallj/controller/DisplayController.java b/src/main/java/fr/umlv/java/wallj/controller/DisplayController.java index 4b31a1c..b2524ee 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/DisplayController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/DisplayController.java @@ -1,12 +1,12 @@ -package fr.umlv.java.wallj.controller; - -import fr.umlv.java.wallj.model.Block; - -public abstract class DisplayController extends BlockController { - - DisplayController(Block block) { - super(block); - } - - //TODO -} +package fr.umlv.java.wallj.controller; + +import fr.umlv.java.wallj.model.Block; + +public abstract class DisplayController extends BlockController { + + DisplayController(Block block) { + super(block); + } + + //TODO +} diff --git a/src/main/java/fr/umlv/java/wallj/controller/GameController.java b/src/main/java/fr/umlv/java/wallj/controller/GameController.java index a18bebe..63fed82 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/GameController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/GameController.java @@ -1,12 +1,12 @@ -package fr.umlv.java.wallj.controller; - -import fr.umlv.java.wallj.context.Context; - -public class GameController implements Controller { - //TODO - - @Override - public void update(Context context) { - - } -} +package fr.umlv.java.wallj.controller; + +import fr.umlv.java.wallj.context.Context; + +public class GameController implements Controller { + //TODO + + @Override + public void update(Context context) { + + } +} diff --git a/src/main/java/fr/umlv/java/wallj/controller/GarbageDisplayController.java b/src/main/java/fr/umlv/java/wallj/controller/GarbageDisplayController.java index 3b16f45..e878fb2 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/GarbageDisplayController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/GarbageDisplayController.java @@ -1,25 +1,25 @@ -package fr.umlv.java.wallj.controller; - -import fr.umlv.java.wallj.context.Context; -import fr.umlv.java.wallj.event.Event; -import fr.umlv.java.wallj.model.GarbageBlock; - -import java.util.List; -import java.util.Objects; - -public class GarbageDisplayController extends DisplayController { - - private final GarbageBlock garbage; - - GarbageDisplayController(GarbageBlock garbage) { - super(garbage); - this.garbage = Objects.requireNonNull(garbage); - } - - @Override - public List update(Context context) { - //TODO - return null; - } - -} +package fr.umlv.java.wallj.controller; + +import fr.umlv.java.wallj.context.Context; +import fr.umlv.java.wallj.event.Event; +import fr.umlv.java.wallj.model.GarbageBlock; + +import java.util.List; +import java.util.Objects; + +public class GarbageDisplayController extends DisplayController { + + private final GarbageBlock garbage; + + GarbageDisplayController(GarbageBlock garbage) { + super(garbage); + this.garbage = Objects.requireNonNull(garbage); + } + + @Override + public List update(Context context) { + //TODO + return null; + } + +} diff --git a/src/main/java/fr/umlv/java/wallj/controller/GarbagePhysicsController.java b/src/main/java/fr/umlv/java/wallj/controller/GarbagePhysicsController.java index 672af19..81e45aa 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/GarbagePhysicsController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/GarbagePhysicsController.java @@ -1,25 +1,25 @@ -package fr.umlv.java.wallj.controller; - -import fr.umlv.java.wallj.context.Context; -import fr.umlv.java.wallj.event.Event; -import fr.umlv.java.wallj.model.GarbageBlock; - -import java.util.List; -import java.util.Objects; - -public class GarbagePhysicsController extends PhysicsController { - - private final GarbageBlock garbage; - - GarbagePhysicsController(GarbageBlock garbage) { - super(garbage); - this.garbage = Objects.requireNonNull(garbage); - } - - @Override - public List update(Context context) { - //TODO - return null; - } - -} +package fr.umlv.java.wallj.controller; + +import fr.umlv.java.wallj.context.Context; +import fr.umlv.java.wallj.event.Event; +import fr.umlv.java.wallj.model.GarbageBlock; + +import java.util.List; +import java.util.Objects; + +public class GarbagePhysicsController extends PhysicsController { + + private final GarbageBlock garbage; + + GarbagePhysicsController(GarbageBlock garbage) { + super(garbage); + this.garbage = Objects.requireNonNull(garbage); + } + + @Override + public List update(Context context) { + //TODO + return null; + } + +} diff --git a/src/main/java/fr/umlv/java/wallj/controller/PhysicsController.java b/src/main/java/fr/umlv/java/wallj/controller/PhysicsController.java index f32790a..f329ebc 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/PhysicsController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/PhysicsController.java @@ -1,12 +1,12 @@ -package fr.umlv.java.wallj.controller; - -import fr.umlv.java.wallj.model.Block; - -public abstract class PhysicsController extends BlockController { - - PhysicsController(Block block) { - super(block); - } - - //TODO -} +package fr.umlv.java.wallj.controller; + +import fr.umlv.java.wallj.model.Block; + +public abstract class PhysicsController extends BlockController { + + PhysicsController(Block block) { + super(block); + } + + //TODO +} diff --git a/src/main/java/fr/umlv/java/wallj/controller/RobotDisplayController.java b/src/main/java/fr/umlv/java/wallj/controller/RobotDisplayController.java index a846152..96ba68c 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/RobotDisplayController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/RobotDisplayController.java @@ -1,25 +1,25 @@ -package fr.umlv.java.wallj.controller; - -import fr.umlv.java.wallj.context.Context; -import fr.umlv.java.wallj.event.Event; -import fr.umlv.java.wallj.model.RobotBlock; - -import java.util.List; -import java.util.Objects; - -public class RobotDisplayController extends DisplayController { - - private final RobotBlock robot; - - RobotDisplayController(RobotBlock robot) { - super(robot); - this.robot = Objects.requireNonNull(robot); - } - - @Override - public List update(Context context) { - //TODO - return null; - } - -} +package fr.umlv.java.wallj.controller; + +import fr.umlv.java.wallj.context.Context; +import fr.umlv.java.wallj.event.Event; +import fr.umlv.java.wallj.model.RobotBlock; + +import java.util.List; +import java.util.Objects; + +public class RobotDisplayController extends DisplayController { + + private final RobotBlock robot; + + RobotDisplayController(RobotBlock robot) { + super(robot); + this.robot = Objects.requireNonNull(robot); + } + + @Override + public List update(Context context) { + //TODO + return null; + } + +} diff --git a/src/main/java/fr/umlv/java/wallj/controller/RobotPhysicsController.java b/src/main/java/fr/umlv/java/wallj/controller/RobotPhysicsController.java index c863c7f..f320480 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/RobotPhysicsController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/RobotPhysicsController.java @@ -1,25 +1,25 @@ -package fr.umlv.java.wallj.controller; - -import fr.umlv.java.wallj.context.Context; -import fr.umlv.java.wallj.event.Event; -import fr.umlv.java.wallj.model.RobotBlock; - -import java.util.List; -import java.util.Objects; - -public class RobotPhysicsController extends PhysicsController { - - private final RobotBlock robot; - - RobotPhysicsController(RobotBlock robot) { - super(robot); - this.robot = Objects.requireNonNull(robot); - } - - @Override - public List update(Context context) { - //TODO - return null; - } - -} +package fr.umlv.java.wallj.controller; + +import fr.umlv.java.wallj.context.Context; +import fr.umlv.java.wallj.event.Event; +import fr.umlv.java.wallj.model.RobotBlock; + +import java.util.List; +import java.util.Objects; + +public class RobotPhysicsController extends PhysicsController { + + private final RobotBlock robot; + + RobotPhysicsController(RobotBlock robot) { + super(robot); + this.robot = Objects.requireNonNull(robot); + } + + @Override + public List update(Context context) { + //TODO + return null; + } + +} diff --git a/src/main/java/fr/umlv/java/wallj/controller/StageController.java b/src/main/java/fr/umlv/java/wallj/controller/StageController.java index 6c13eb1..912b500 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/StageController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/StageController.java @@ -1,12 +1,12 @@ -package fr.umlv.java.wallj.controller; - -import fr.umlv.java.wallj.context.Context; - -public class StageController implements Controller { - //TODO - - @Override - public void update(Context context) { - - } -} +package fr.umlv.java.wallj.controller; + +import fr.umlv.java.wallj.context.Context; + +public class StageController implements Controller { + //TODO + + @Override + public void update(Context context) { + + } +} diff --git a/src/main/java/fr/umlv/java/wallj/controller/TrashDisplayController.java b/src/main/java/fr/umlv/java/wallj/controller/TrashDisplayController.java index d981154..dfba9be 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/TrashDisplayController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/TrashDisplayController.java @@ -1,25 +1,25 @@ -package fr.umlv.java.wallj.controller; - -import fr.umlv.java.wallj.context.Context; -import fr.umlv.java.wallj.event.Event; -import fr.umlv.java.wallj.model.TrashBlock; - -import java.util.List; -import java.util.Objects; - -public class TrashDisplayController extends DisplayController { - - private final TrashBlock trash; - - TrashDisplayController(TrashBlock trash) { - super(trash); - this.trash = Objects.requireNonNull(trash); - } - - @Override - public List update(Context context) { - //TODO - return null; - } - -} +package fr.umlv.java.wallj.controller; + +import fr.umlv.java.wallj.context.Context; +import fr.umlv.java.wallj.event.Event; +import fr.umlv.java.wallj.model.TrashBlock; + +import java.util.List; +import java.util.Objects; + +public class TrashDisplayController extends DisplayController { + + private final TrashBlock trash; + + TrashDisplayController(TrashBlock trash) { + super(trash); + this.trash = Objects.requireNonNull(trash); + } + + @Override + public List update(Context context) { + //TODO + return null; + } + +} diff --git a/src/main/java/fr/umlv/java/wallj/controller/TrashPhysicsController.java b/src/main/java/fr/umlv/java/wallj/controller/TrashPhysicsController.java index 117f5a2..62e4af5 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/TrashPhysicsController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/TrashPhysicsController.java @@ -1,25 +1,25 @@ -package fr.umlv.java.wallj.controller; - -import fr.umlv.java.wallj.context.Context; -import fr.umlv.java.wallj.event.Event; -import fr.umlv.java.wallj.model.TrashBlock; - -import java.util.List; -import java.util.Objects; - -public class TrashPhysicsController extends PhysicsController { - - private final TrashBlock trash; - - TrashPhysicsController(TrashBlock trash) { - super(trash); - this.trash = Objects.requireNonNull(trash); - } - - @Override - public List update(Context context) { - //TODO - return null; - } - -} +package fr.umlv.java.wallj.controller; + +import fr.umlv.java.wallj.context.Context; +import fr.umlv.java.wallj.event.Event; +import fr.umlv.java.wallj.model.TrashBlock; + +import java.util.List; +import java.util.Objects; + +public class TrashPhysicsController extends PhysicsController { + + private final TrashBlock trash; + + TrashPhysicsController(TrashBlock trash) { + super(trash); + this.trash = Objects.requireNonNull(trash); + } + + @Override + public List update(Context context) { + //TODO + return null; + } + +} diff --git a/src/main/java/fr/umlv/java/wallj/controller/WallDisplayController.java b/src/main/java/fr/umlv/java/wallj/controller/WallDisplayController.java index b0a41ed..3700acb 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/WallDisplayController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/WallDisplayController.java @@ -1,25 +1,25 @@ -package fr.umlv.java.wallj.controller; - -import fr.umlv.java.wallj.context.Context; -import fr.umlv.java.wallj.event.Event; -import fr.umlv.java.wallj.model.WallBlock; - -import java.util.List; -import java.util.Objects; - -public class WallDisplayController extends BlockController { - - private final WallBlock wall; - - WallDisplayController(WallBlock wall) { - super(wall); - this.wall = Objects.requireNonNull(wall); - } - - @Override - public List update(Context context) { - //TODO - return null; - } - -} +package fr.umlv.java.wallj.controller; + +import fr.umlv.java.wallj.context.Context; +import fr.umlv.java.wallj.event.Event; +import fr.umlv.java.wallj.model.WallBlock; + +import java.util.List; +import java.util.Objects; + +public class WallDisplayController extends BlockController { + + private final WallBlock wall; + + WallDisplayController(WallBlock wall) { + super(wall); + this.wall = Objects.requireNonNull(wall); + } + + @Override + public List update(Context context) { + //TODO + return null; + } + +} diff --git a/src/main/java/fr/umlv/java/wallj/controller/WallPhysicsController.java b/src/main/java/fr/umlv/java/wallj/controller/WallPhysicsController.java index 6131449..146ca34 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/WallPhysicsController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/WallPhysicsController.java @@ -1,25 +1,25 @@ -package fr.umlv.java.wallj.controller; - -import fr.umlv.java.wallj.context.Context; -import fr.umlv.java.wallj.event.Event; -import fr.umlv.java.wallj.model.WallBlock; - -import java.util.List; -import java.util.Objects; - -public class WallPhysicsController extends PhysicsController { - - private final WallBlock wall; - - WallPhysicsController(WallBlock wall) { - super(wall); - this.wall = Objects.requireNonNull(wall); - } - - @Override - public List update(Context context) { - //TODO - return null; - } - -} +package fr.umlv.java.wallj.controller; + +import fr.umlv.java.wallj.context.Context; +import fr.umlv.java.wallj.event.Event; +import fr.umlv.java.wallj.model.WallBlock; + +import java.util.List; +import java.util.Objects; + +public class WallPhysicsController extends PhysicsController { + + private final WallBlock wall; + + WallPhysicsController(WallBlock wall) { + super(wall); + this.wall = Objects.requireNonNull(wall); + } + + @Override + public List update(Context context) { + //TODO + return null; + } + +} diff --git a/src/main/java/fr/umlv/java/wallj/event/AddBombEvent.java b/src/main/java/fr/umlv/java/wallj/event/AddBombEvent.java index e726911..eef0329 100644 --- a/src/main/java/fr/umlv/java/wallj/event/AddBombEvent.java +++ b/src/main/java/fr/umlv/java/wallj/event/AddBombEvent.java @@ -1,13 +1,13 @@ -package fr.umlv.java.wallj.event; - -import fr.umlv.java.wallj.board.TileVec2; - -import java.util.Objects; - -public final class AddBombEvent implements InputEvent { - TileVec2 tileVec2; - - public AddBombEvent(TileVec2 tileVec2) { - this.tileVec2 = Objects.requireNonNull(tileVec2); - } -} +package fr.umlv.java.wallj.event; + +import fr.umlv.java.wallj.board.TileVec2; + +import java.util.Objects; + +public final class AddBombEvent implements InputEvent { + TileVec2 tileVec2; + + public AddBombEvent(TileVec2 tileVec2) { + this.tileVec2 = Objects.requireNonNull(tileVec2); + } +} diff --git a/src/main/java/fr/umlv/java/wallj/event/ConfirmEvent.java b/src/main/java/fr/umlv/java/wallj/event/ConfirmEvent.java index 4af9884..16b0d8b 100644 --- a/src/main/java/fr/umlv/java/wallj/event/ConfirmEvent.java +++ b/src/main/java/fr/umlv/java/wallj/event/ConfirmEvent.java @@ -1,5 +1,5 @@ -package fr.umlv.java.wallj.event; - -public class ConfirmEvent implements InputEvent { - //TODO Class ConfirmEvent -} +package fr.umlv.java.wallj.event; + +public class ConfirmEvent implements InputEvent { + //TODO Class ConfirmEvent +} diff --git a/src/main/java/fr/umlv/java/wallj/event/DropBombEvent.java b/src/main/java/fr/umlv/java/wallj/event/DropBombEvent.java index 5d07622..d0ac956 100644 --- a/src/main/java/fr/umlv/java/wallj/event/DropBombEvent.java +++ b/src/main/java/fr/umlv/java/wallj/event/DropBombEvent.java @@ -1,5 +1,5 @@ -package fr.umlv.java.wallj.event; - -public final class DropBombEvent implements InputEvent { - //TODO Class DropBombEvent -} +package fr.umlv.java.wallj.event; + +public final class DropBombEvent implements InputEvent { + //TODO Class DropBombEvent +} diff --git a/src/main/java/fr/umlv/java/wallj/event/Event.java b/src/main/java/fr/umlv/java/wallj/event/Event.java index 143842a..034e345 100644 --- a/src/main/java/fr/umlv/java/wallj/event/Event.java +++ b/src/main/java/fr/umlv/java/wallj/event/Event.java @@ -1,4 +1,4 @@ -package fr.umlv.java.wallj.event; - -public interface Event { -} +package fr.umlv.java.wallj.event; + +public interface Event { +} diff --git a/src/main/java/fr/umlv/java/wallj/event/MoveRobotEvent.java b/src/main/java/fr/umlv/java/wallj/event/MoveRobotEvent.java index 5ccff92..7b3e115 100644 --- a/src/main/java/fr/umlv/java/wallj/event/MoveRobotEvent.java +++ b/src/main/java/fr/umlv/java/wallj/event/MoveRobotEvent.java @@ -1,14 +1,14 @@ -package fr.umlv.java.wallj.event; - -import fr.umlv.java.wallj.board.TileVec2; - -import java.util.Objects; - -public class MoveRobotEvent implements InputEvent { - //TODO Class MoveRobotEvent - TileVec2 tileVec2; - - public MoveRobotEvent(TileVec2 tileVec2) { - this.tileVec2 = Objects.requireNonNull(tileVec2); - } -} +package fr.umlv.java.wallj.event; + +import fr.umlv.java.wallj.board.TileVec2; + +import java.util.Objects; + +public class MoveRobotEvent implements InputEvent { + //TODO Class MoveRobotEvent + TileVec2 tileVec2; + + public MoveRobotEvent(TileVec2 tileVec2) { + this.tileVec2 = Objects.requireNonNull(tileVec2); + } +} diff --git a/src/main/java/fr/umlv/java/wallj/model/Block.java b/src/main/java/fr/umlv/java/wallj/model/Block.java index a929b8f..7f32087 100644 --- a/src/main/java/fr/umlv/java/wallj/model/Block.java +++ b/src/main/java/fr/umlv/java/wallj/model/Block.java @@ -1,75 +1,75 @@ -package fr.umlv.java.wallj.model; - -import fr.umlv.java.wallj.board.TileVec2; -import fr.umlv.java.wallj.context.Context; -import fr.umlv.java.wallj.controller.BlockController; -import fr.umlv.java.wallj.controller.Controller; -import fr.umlv.java.wallj.event.Event; -import org.jbox2d.common.Vec2; - -import java.util.*; -import java.util.stream.Collectors; - -/** - * A block. - * - * @author Pacien TRAN-GIRARD - */ -public abstract class Block { - - private final BlockType type; - private List controllers; - private Vec2 pos; - - /** - * @param type type of block - * @param pos initial position - */ - Block(BlockType type, Vec2 pos) { - this.type = Objects.requireNonNull(type); - this.pos = Objects.requireNonNull(pos).clone(); - } - - void setControllers(List l) { - controllers = Collections.unmodifiableList(new LinkedList<>(Objects.requireNonNull(l))); - } - - /** - * @param pos new position to set - */ - public void setPos(Vec2 pos) { - this.pos = Objects.requireNonNull(pos).clone(); - } - - /** - * @return the block type - */ - public BlockType getType() { - return type; - } - - /** - * @return the current position - */ - public Vec2 getPos() { - return pos.clone(); - } - - /** - * @return the current tile position - */ - public TileVec2 getTile() { - return TileVec2.of(pos); - } - - /** - * @param ctx execution context - * @return list of generated events - */ - public List update(Context ctx) { - return controllers.stream() - .flatMap(controller -> controller.update(ctx).stream()) - .collect(Collectors.toList()); - } - -} +package fr.umlv.java.wallj.model; + +import fr.umlv.java.wallj.board.TileVec2; +import fr.umlv.java.wallj.context.Context; +import fr.umlv.java.wallj.controller.BlockController; +import fr.umlv.java.wallj.controller.Controller; +import fr.umlv.java.wallj.event.Event; +import org.jbox2d.common.Vec2; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * A block. + * + * @author Pacien TRAN-GIRARD + */ +public abstract class Block { + + private final BlockType type; + private List controllers; + private Vec2 pos; + + /** + * @param type type of block + * @param pos initial position + */ + Block(BlockType type, Vec2 pos) { + this.type = Objects.requireNonNull(type); + this.pos = Objects.requireNonNull(pos).clone(); + } + + void setControllers(List l) { + controllers = Collections.unmodifiableList(new LinkedList<>(Objects.requireNonNull(l))); + } + + /** + * @param pos new position to set + */ + public void setPos(Vec2 pos) { + this.pos = Objects.requireNonNull(pos).clone(); + } + + /** + * @return the block type + */ + public BlockType getType() { + return type; + } + + /** + * @return the current position + */ + public Vec2 getPos() { + return pos.clone(); + } + + /** + * @return the current tile position + */ + public TileVec2 getTile() { + return TileVec2.of(pos); + } + + /** + * @param ctx execution context + * @return list of generated events + */ + public List update(Context ctx) { + return controllers.stream() + .flatMap(controller -> controller.update(ctx).stream()) + .collect(Collectors.toList()); + } + +} diff --git a/src/main/java/fr/umlv/java/wallj/model/BlockFactory.java b/src/main/java/fr/umlv/java/wallj/model/BlockFactory.java index 12a0a94..b39b420 100644 --- a/src/main/java/fr/umlv/java/wallj/model/BlockFactory.java +++ b/src/main/java/fr/umlv/java/wallj/model/BlockFactory.java @@ -1,42 +1,42 @@ -package fr.umlv.java.wallj.model; - -import fr.umlv.java.wallj.board.TileVec2; -import fr.umlv.java.wallj.controller.BlockControllerFactory; -import org.jbox2d.common.Vec2; - -/** - * A block factory. - * - * @author Pacien TRAN-GIRARD - */ -public final class BlockFactory { - - private static Block forType(BlockType t, Vec2 pos) { - switch (t) { - case WALL: - return new WallBlock(pos); - case TRASH: - return new TrashBlock(pos); - case GARBAGE: - return n