From 016688acf72857e04537441f8d164653478548af Mon Sep 17 00:00:00 2001 From: Jelle Van De Sijpe Date: Sun, 15 Mar 2020 15:30:12 +0100 Subject: [PATCH 1/6] bug fix if --- .../BlockStructure/Blocks/CavityBlock.java | 20 ------------------- .../System/BlockStructure/Blocks/IfBlock.java | 7 +++++++ .../BlockStructure/Blocks/WhileBlock.java | 20 +++++++++++++++++++ 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/main/java/System/BlockStructure/Blocks/CavityBlock.java b/src/main/java/System/BlockStructure/Blocks/CavityBlock.java index 7adef17d..e5e8baf2 100644 --- a/src/main/java/System/BlockStructure/Blocks/CavityBlock.java +++ b/src/main/java/System/BlockStructure/Blocks/CavityBlock.java @@ -91,26 +91,6 @@ public boolean hasNext() { } } - /** - * Get the next block to execute, this depends on the evaluation of the condition of this block. - * If the condition is true, the next block is the first in the cavity, otherwise, the next block - * is the first block under the while. - * - * @return The next block to execute - */ - @Override - public Block getNext() { - if (getFunctionality().getEvaluation()) { - setAlreadyRan(false); - return cavitySubConnector.getConnectedBlock(); - } - else if(getCavitySubConnector().isConnected()) { - cavitySubConnector.getConnectedBlock().reset(); - } - setAlreadyRan(true); - return super.getNext(); - } - /** * Checks whether or not this cavity block has proper connections. * diff --git a/src/main/java/System/BlockStructure/Blocks/IfBlock.java b/src/main/java/System/BlockStructure/Blocks/IfBlock.java index 8384691d..6fe2cad6 100644 --- a/src/main/java/System/BlockStructure/Blocks/IfBlock.java +++ b/src/main/java/System/BlockStructure/Blocks/IfBlock.java @@ -21,6 +21,13 @@ public IfBlock(CavityFunctionality cavityFunctionality) { super(cavityFunctionality); } + /** + * Get the next block to execute, this depends on the evaluation of the condition of this block. + * If the condition is true, the next block is the first in the cavity, otherwise, the next block + * is the first block under the while. + * + * @return The next block to execute + */ @Override public Block getNext() { if (getFunctionality().getEvaluation()) { diff --git a/src/main/java/System/BlockStructure/Blocks/WhileBlock.java b/src/main/java/System/BlockStructure/Blocks/WhileBlock.java index 41fc35c5..1dbc2026 100644 --- a/src/main/java/System/BlockStructure/Blocks/WhileBlock.java +++ b/src/main/java/System/BlockStructure/Blocks/WhileBlock.java @@ -21,6 +21,26 @@ public WhileBlock(CavityFunctionality functionality) { super(functionality); } + /** + * Get the next block to execute, this depends on the evaluation of the condition of this block. + * If the condition is true, the next block is the first in the cavity, otherwise, the next block + * is the first block under the while. + * + * @return The next block to execute + */ + @Override + public Block getNext() { + if (getFunctionality().getEvaluation()) { + setAlreadyRan(false); + return getCavitySubConnector().getConnectedBlock(); + } + else if(getCavitySubConnector().isConnected()) { + getCavitySubConnector().getConnectedBlock().reset(); + } + setAlreadyRan(true); + return super.getNext(); + } + /** * Returns the next block if any other block didn't have a next block to run. * From 20f66f888c91a6aba67440c26cdf8b21c6d6e14b Mon Sep 17 00:00:00 2001 From: Jelle Van De Sijpe Date: Sun, 15 Mar 2020 15:59:37 +0100 Subject: [PATCH 2/6] error add and block comments --- src/main/java/Controllers/GUItoSystemInterface.java | 7 ++++++- src/main/java/GUI/Blocks/GUIBlock.java | 13 +++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/Controllers/GUItoSystemInterface.java b/src/main/java/Controllers/GUItoSystemInterface.java index 994c49c6..d57d49f4 100644 --- a/src/main/java/Controllers/GUItoSystemInterface.java +++ b/src/main/java/Controllers/GUItoSystemInterface.java @@ -39,7 +39,12 @@ public GUIBlock createNewGUIBlock(String id, int x, int y) { } } - public Block getBlockFromGUIBlock(GUIBlock block) { + public Block getBlockFromGUIBlock(GUIBlock block) throws IllegalArgumentException { + + if (conversionTable.containsKey(block)) { + throw new IllegalArgumentException("The given GUI block is not present in the conversion table!"); + } + return conversionTable.get(block); } diff --git a/src/main/java/GUI/Blocks/GUIBlock.java b/src/main/java/GUI/Blocks/GUIBlock.java index ea9d2c59..e9637bb5 100644 --- a/src/main/java/GUI/Blocks/GUIBlock.java +++ b/src/main/java/GUI/Blocks/GUIBlock.java @@ -262,8 +262,6 @@ else if ((intersectingConnectorSub = findCollidingConnector(subConnectors, other } if (controller.isValidConnection(main, sub, intersectingConnectorSub.getId())) { - - if (!mainConnector.isConnected()) { setPosition(staticBlockConnectorPosition.getX() + (getX() - draggedBlockConnectorPosition.getX()), staticBlockConnectorPosition.getY() + (getY() - draggedBlockConnectorPosition.getY())); main.mainConnector.connect(intersectingConnectorSub); @@ -277,6 +275,7 @@ else if ((intersectingConnectorSub = findCollidingConnector(subConnectors, other other.changeHeight(main.getHeight(), main); } } + Pcontroller.addBlockToPA(getHighest()); } @@ -295,12 +294,18 @@ public GUIBlock getHighest() { } } - // TODO doc + /** + * Reset the height of the block structure connected to this block's main connector + * as if the current block and its connected sub-blocks where added to the block structure. + */ public void resetHeight() { changeHeight(getHeight(), this); } - // TODO doc + /** + * Decrease the height of the block structure connected to this block's main connector + * as if the current block and its connected sub-blocks where removed from the block structure. + */ public void disconnectHeight() { changeHeight(-getHeight(), this); } From e583cae3a626c4bbd5ed28f1985f1fe91f1388a9 Mon Sep 17 00:00:00 2001 From: Jelle Van De Sijpe Date: Sun, 15 Mar 2020 16:51:16 +0100 Subject: [PATCH 3/6] controller fix --- .../Controllers/ConnectionController.java | 10 +++---- .../Controllers/GUItoSystemInterface.java | 2 +- .../java/Controllers/ProgramController.java | 22 ++++++--------- src/main/java/GUI/BlockrCanvas.java | 19 +++++++++++-- src/main/java/GUI/Blocks/GUIBlock.java | 15 +++++----- .../java/GUI/Components/GUIBlockHandler.java | 22 ++++++++------- src/main/java/GUI/Panel/ProgramAreaPanel.java | 28 +++++++++++++------ src/main/java/GUI/ProgramGUI.java | 5 +++- 8 files changed, 74 insertions(+), 49 deletions(-) diff --git a/src/main/java/Controllers/ConnectionController.java b/src/main/java/Controllers/ConnectionController.java index f5b92c69..3e976063 100644 --- a/src/main/java/Controllers/ConnectionController.java +++ b/src/main/java/Controllers/ConnectionController.java @@ -11,22 +11,22 @@ public class ConnectionController { private final GUItoSystemInterface converter; - private final PABlockHandler handler; + private final PABlockHandler blockHandler; - public ConnectionController(GUItoSystemInterface converter, PABlockHandler handler) { + public ConnectionController(GUItoSystemInterface converter, PABlockHandler blockHandler) { this.converter = converter; - this.handler = handler; + this.blockHandler = blockHandler; } public void connectBlocks(GUIBlock withMain, GUIBlock withSub, String connectionID) { Block mainBlock = converter.getBlockFromGUIBlock(withMain); SubConnector subConnector = converter.getSubConnectorFromGUIBlockWithID(withSub, connectionID); - handler.connectToExistingBlock(mainBlock, subConnector); + blockHandler.connectToExistingBlock(mainBlock, subConnector); } public void disconnectBlock(GUIBlock withMain) { Block mainBlock = converter.getBlockFromGUIBlock(withMain); - handler.disconnectInPA(mainBlock); + blockHandler.disconnectInPA(mainBlock); } public boolean isValidConnection(GUIBlock withMain, GUIBlock withSub, String connectionID) { diff --git a/src/main/java/Controllers/GUItoSystemInterface.java b/src/main/java/Controllers/GUItoSystemInterface.java index d57d49f4..6368ae2d 100644 --- a/src/main/java/Controllers/GUItoSystemInterface.java +++ b/src/main/java/Controllers/GUItoSystemInterface.java @@ -41,7 +41,7 @@ public GUIBlock createNewGUIBlock(String id, int x, int y) { public Block getBlockFromGUIBlock(GUIBlock block) throws IllegalArgumentException { - if (conversionTable.containsKey(block)) { + if (!conversionTable.containsKey(block)) { throw new IllegalArgumentException("The given GUI block is not present in the conversion table!"); } diff --git a/src/main/java/Controllers/ProgramController.java b/src/main/java/Controllers/ProgramController.java index f840fea0..c7185efd 100644 --- a/src/main/java/Controllers/ProgramController.java +++ b/src/main/java/Controllers/ProgramController.java @@ -10,10 +10,14 @@ public class ProgramController { - private final PABlockHandler blockHandler = new PABlockHandler(); private final LevelLoader loader = new LevelLoader(); - private final GUItoSystemInterface converter = new GUItoSystemInterface(blockHandler); - private final ConnectionController controller = new ConnectionController(converter, blockHandler); + private final GUItoSystemInterface converter; + private final PABlockHandler blockHandler; + + public ProgramController(GUItoSystemInterface converter, PABlockHandler blockHandler) { + this.converter = converter; + this.blockHandler = blockHandler; + } public void addBlockToPA(GUIBlock block) { Block toAdd = converter.getBlockFromGUIBlock(block); @@ -29,8 +33,7 @@ public void deleteFromPA(GUIBlock block) { } public void deleteAsProgram(GUIBlock block) { - Block toDelete = converter.getBlockFromGUIBlock(block); - blockHandler.deleteProgram(toDelete); + blockHandler.deleteProgram(converter.getBlockFromGUIBlock(block)); } public boolean reachedMaxBlocks() { @@ -47,10 +50,7 @@ public GUIBlock getHightlightedBlock() { } public GUIBlock getBlock(String ID, int x, int y) { - if (!reachedMaxBlocks()) { - return converter.createNewGUIBlock(ID, x, y); - } - return null; + return converter.createNewGUIBlock(ID, x, y); } public void resetProgram() { @@ -69,8 +69,4 @@ public void subscribeListener(ProgramListener listener) { public void unsubscribeListener(ProgramListener listener) { blockHandler.getPA().unsubscribe(listener); } - - public ConnectionController getController() { - return controller; - } } diff --git a/src/main/java/GUI/BlockrCanvas.java b/src/main/java/GUI/BlockrCanvas.java index ec18d243..d4dd7229 100644 --- a/src/main/java/GUI/BlockrCanvas.java +++ b/src/main/java/GUI/BlockrCanvas.java @@ -1,5 +1,7 @@ package GUI; +import Controllers.ConnectionController; +import Controllers.GUItoSystemInterface; import Controllers.ProgramController; import GUI.Blocks.GUIBlock; import GUI.Components.GUIBlockHandler; @@ -8,6 +10,7 @@ import GUI.Panel.GameWorldPanel; import GUI.Panel.PalettePanel; import GUI.Panel.ProgramAreaPanel; +import System.Logic.ProgramArea.PABlockHandler; import java.awt.*; import java.awt.event.KeyEvent; @@ -25,7 +28,8 @@ public class BlockrCanvas extends CanvasWindow { private GUIBlockHandler blockHandler; private GUIBlock previousBlock; - private ProgramController programController = new ProgramController(); + private ProgramController programController; + private ConnectionController connectionController; /** * Initializes a CanvasWindow object. @@ -40,7 +44,9 @@ protected BlockrCanvas(String title, int width, int height, String imagePackName this.height = height; GamePanel.setImageLibrary(ImagePreLoader.createImageLibrary(imagePackName)); + setControllers(); setPanels(); + blockHandler = new GUIBlockHandler(palettePanel, programAreaPanel); } @@ -61,13 +67,13 @@ protected void paint(Graphics g) { @Override protected void handleMouseEvent(int id, int x, int y, int clickCount) { super.handleMouseEvent(id, x, y, clickCount); - blockHandler.handleMouseEvent(id, x, y, programController); + blockHandler.handleMouseEvent(id, x, y); repaint(); } private void setPanels() { palettePanel = new PalettePanel(0, 0, (int)(width * PALETTE_WIDTH_RATIO), height, programController); - programAreaPanel = new ProgramAreaPanel((int)(width * PALETTE_WIDTH_RATIO),0, (int)(width * PROGRAMAREA_WIDTH_RATIO), height, programController); + programAreaPanel = new ProgramAreaPanel((int)(width * PALETTE_WIDTH_RATIO),0, (int)(width * PROGRAMAREA_WIDTH_RATIO), height, programController, connectionController); gameWorldPanel = new GameWorldPanel((int)(width * PALETTE_WIDTH_RATIO) + (int)(width * PROGRAMAREA_WIDTH_RATIO),0, (int)(width * GAMEWORLD_WIDTH_RATIO), height, programController); } @@ -93,4 +99,11 @@ protected void handleKeyEvent(int id, int keyCode, char keyChar) { repaint(); } + + private void setControllers() { + PABlockHandler blockHandler = new PABlockHandler(); + GUItoSystemInterface converter = new GUItoSystemInterface(blockHandler); + connectionController = new ConnectionController(converter, blockHandler); + programController = new ProgramController(converter, blockHandler); + } } diff --git a/src/main/java/GUI/Blocks/GUIBlock.java b/src/main/java/GUI/Blocks/GUIBlock.java index e9637bb5..6cfcbe22 100644 --- a/src/main/java/GUI/Blocks/GUIBlock.java +++ b/src/main/java/GUI/Blocks/GUIBlock.java @@ -236,24 +236,23 @@ public boolean intersectsWithConnector(GUIBlock other) { } // TODO doc - public void connectWithStaticBlock(GUIBlock other, ProgramController Pcontroller) { + public void connectWithStaticBlock(GUIBlock other, ProgramController programController, ConnectionController connectionController) { GUIConnector intersectingConnectorSub; - ConnectionController controller = Pcontroller.getController(); Position staticBlockConnectorPosition, draggedBlockConnectorPosition; GUIBlock main, sub; if ((intersectingConnectorSub = findCollidingConnector(other.subConnectors, mainConnector)) != null) { main = this; sub = other; - Pcontroller.deleteAsProgram(this); + programController.deleteAsProgram(this); draggedBlockConnectorPosition = mainConnector.getCollisionCircle().getPosition(); staticBlockConnectorPosition = intersectingConnectorSub.getCollisionCircle().getPosition(); } else if ((intersectingConnectorSub = findCollidingConnector(subConnectors, other.mainConnector)) != null) { sub = this; main = other; - Pcontroller.deleteAsProgram(other); + programController.deleteAsProgram(other); staticBlockConnectorPosition = other.mainConnector.getCollisionCircle().getPosition(); draggedBlockConnectorPosition = intersectingConnectorSub.getCollisionCircle().getPosition(); } @@ -261,22 +260,22 @@ else if ((intersectingConnectorSub = findCollidingConnector(subConnectors, other throw new IllegalArgumentException("Given block does not have a colliding connector!"); } - if (controller.isValidConnection(main, sub, intersectingConnectorSub.getId())) { + if (connectionController.isValidConnection(main, sub, intersectingConnectorSub.getId())) { if (!mainConnector.isConnected()) { setPosition(staticBlockConnectorPosition.getX() + (getX() - draggedBlockConnectorPosition.getX()), staticBlockConnectorPosition.getY() + (getY() - draggedBlockConnectorPosition.getY())); main.mainConnector.connect(intersectingConnectorSub); - controller.connectBlocks(main, sub, intersectingConnectorSub.getId()); + connectionController.connectBlocks(main, sub, intersectingConnectorSub.getId()); changeHeight(main.getHeight(), main); } else { other.setPosition(draggedBlockConnectorPosition.getX() + (other.getX() - staticBlockConnectorPosition.getX()), draggedBlockConnectorPosition.getY() + (other.getY() - staticBlockConnectorPosition.getY())); main.mainConnector.connect(intersectingConnectorSub); - controller.connectBlocks(main, sub, intersectingConnectorSub.getId()); + connectionController.connectBlocks(main, sub, intersectingConnectorSub.getId()); other.changeHeight(main.getHeight(), main); } } - Pcontroller.addBlockToPA(getHighest()); + programController.addBlockToPA(getHighest()); } /** diff --git a/src/main/java/GUI/Components/GUIBlockHandler.java b/src/main/java/GUI/Components/GUIBlockHandler.java index eef7751f..8a960ea9 100644 --- a/src/main/java/GUI/Components/GUIBlockHandler.java +++ b/src/main/java/GUI/Components/GUIBlockHandler.java @@ -1,11 +1,13 @@ package GUI.Components; +import Controllers.ConnectionController; import Controllers.ProgramController; import GUI.Blocks.GUIBlock; import GUI.CollisionShapes.CollisionRectangle; import GUI.Panel.GamePanel; import GUI.Panel.PalettePanel; import GUI.Panel.ProgramAreaPanel; +import System.Logic.ProgramArea.Program; import Utility.Position; import java.awt.event.MouseEvent; @@ -27,13 +29,13 @@ public GUIBlockHandler(PalettePanel palette, ProgramAreaPanel programArea) { this.programArea = programArea; } - public void handleMouseEvent(int id, int x, int y, ProgramController programController) { + public void handleMouseEvent(int id, int x, int y) { if (id == MouseEvent.MOUSE_PRESSED) { handleMousePressed(x, y); } else if (id == MouseEvent.MOUSE_RELEASED) { - handleMouseReleased(programController); + handleMouseReleased(); } else if (id == MouseEvent.MOUSE_DRAGGED) { handleMouseDragged(x, y); @@ -64,15 +66,15 @@ private void handleMousePressed(int x, int y) { } } - private void handleMouseReleased(ProgramController programController) { + private void handleMouseReleased() { if (draggedBlock != null) { if (isInPanel(programArea.getPanelRectangle(), draggedBlocks)) { if (blockSourcePanel == palette) { - handleBlockFromPaletteToProgramArea(programController); + handleBlockFromPaletteToProgramArea(); } else if (blockSourcePanel == programArea) { - handleBlockFromProgramAreaToProgramArea(programController); + handleBlockFromProgramAreaToProgramArea(); } } else if (isInPanelAny(palette.getPanelRectangle(), draggedBlocks)) { @@ -95,7 +97,7 @@ private void handleMouseDragged(int x, int y) { } } - private void handleBlockFromPaletteToProgramArea(ProgramController programController) { + private void handleBlockFromPaletteToProgramArea() { GUIBlock newBlock = palette.getNewBlock(draggedBlock.getId(), draggedBlock.getX(), draggedBlock.getY()); draggedBlock.setPosition(lastValidPosition.getX(), lastValidPosition.getY()); @@ -108,11 +110,11 @@ private void handleBlockFromPaletteToProgramArea(ProgramController programContro programArea.addBlockToProgramAreaControllerCall(draggedBlock); } else { - draggedBlock.connectWithStaticBlock(connectedBlock.get(), programController); + draggedBlock.connectWithStaticBlock(connectedBlock.get(), programArea.getProgramController(), programArea.getConnectionController()); } } - private void handleBlockFromProgramAreaToProgramArea(ProgramController programController) { + private void handleBlockFromProgramAreaToProgramArea() { boolean connectionFound = false; programArea.disconnectInProgramArea(draggedBlock); draggedBlock.disconnectMainConnector(); @@ -122,13 +124,13 @@ private void handleBlockFromProgramAreaToProgramArea(ProgramController programCo Optional connectedBlock = programArea.getBlocks().stream().filter(b -> b.intersectsWithConnector(block)).findAny(); if (connectedBlock.isPresent()) { - block.connectWithStaticBlock(connectedBlock.get(), programController); + block.connectWithStaticBlock(connectedBlock.get(), programArea.getProgramController(), programArea.getConnectionController()); connectionFound = true; break; } } if (!connectionFound) { - programController.addBlockToPA(draggedBlocks.get(0)); + programArea.addBlockToProgramAreaControllerCall(draggedBlocks.get(0)); } } diff --git a/src/main/java/GUI/Panel/ProgramAreaPanel.java b/src/main/java/GUI/Panel/ProgramAreaPanel.java index c6f2ad55..64f5dbc7 100644 --- a/src/main/java/GUI/Panel/ProgramAreaPanel.java +++ b/src/main/java/GUI/Panel/ProgramAreaPanel.java @@ -1,5 +1,6 @@ package GUI.Panel; +import Controllers.ConnectionController; import Controllers.ProgramController; import Controllers.ProgramListener; import GUI.Blocks.GUIBlock; @@ -12,12 +13,23 @@ public class ProgramAreaPanel extends GamePanel implements ProgramListener { private List blocks = new ArrayList<>(); - private ProgramController controller; + private ProgramController programController; + private ConnectionController connectionController; - public ProgramAreaPanel(int cornerX, int cornerY, int width, int height, ProgramController controller) { + public ProgramAreaPanel(int cornerX, int cornerY, int width, int height, ProgramController programController, + ConnectionController connectionController) { super(cornerX, cornerY, width, height); - this.controller = controller; - controller.subscribeListener(this); + this.programController = programController; + this.connectionController = connectionController; + programController.subscribeListener(this); + } + + public ProgramController getProgramController() { + return programController; + } + + public ConnectionController getConnectionController() { + return connectionController; } public void addBlockToProgramArea(GUIBlock block) { @@ -25,18 +37,18 @@ public void addBlockToProgramArea(GUIBlock block) { } public void addBlockToProgramAreaControllerCall(GUIBlock block) { - controller.addBlockToPA(block); + programController.addBlockToPA(block); } public void disconnectInProgramArea(GUIBlock GUIBlock) { - controller.getController().disconnectBlock(GUIBlock); - controller.resetProgram(); + connectionController.disconnectBlock(GUIBlock); + programController.resetProgram(); } public void deleteBlockFromProgramArea(List GUIBlocks) { blocks.removeAll(GUIBlocks); for (GUIBlock block:GUIBlocks) { - controller.deleteFromPA(block); + programController.deleteFromPA(block); } } diff --git a/src/main/java/GUI/ProgramGUI.java b/src/main/java/GUI/ProgramGUI.java index 4e80d735..78ff6228 100644 --- a/src/main/java/GUI/ProgramGUI.java +++ b/src/main/java/GUI/ProgramGUI.java @@ -1,7 +1,11 @@ package GUI; +import Controllers.ConnectionController; +import Controllers.GUItoSystemInterface; +import Controllers.ProgramController; import System.GameWorld.Level.LevelLoader; +import System.Logic.ProgramArea.PABlockHandler; import java.awt.*; @@ -9,7 +13,6 @@ public class ProgramGUI { public static void main(String args[]) throws Exception { LevelLoader loader = new LevelLoader(); loader.loadLevel(); - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); BlockrCanvas canvas = new BlockrCanvas("Blockr", screenSize.width, screenSize.height); java.awt.EventQueue.invokeLater(canvas::show); From 9ad6fe427353c3224922037a68d8adcdfaec00da Mon Sep 17 00:00:00 2001 From: Jelle Van De Sijpe Date: Sun, 15 Mar 2020 17:16:54 +0100 Subject: [PATCH 4/6] guiblock comments --- src/main/java/GUI/Blocks/GUIBlock.java | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/java/GUI/Blocks/GUIBlock.java b/src/main/java/GUI/Blocks/GUIBlock.java index 6cfcbe22..9ba1ae88 100644 --- a/src/main/java/GUI/Blocks/GUIBlock.java +++ b/src/main/java/GUI/Blocks/GUIBlock.java @@ -235,8 +235,28 @@ public boolean intersectsWithConnector(GUIBlock other) { return findCollidingConnector(subConnectors, other.mainConnector) != null || findCollidingConnector(other.subConnectors, mainConnector) != null; } - // TODO doc - public void connectWithStaticBlock(GUIBlock other, ProgramController programController, ConnectionController connectionController) { + /** + * The current dragged block or set of blocks this block is in is being connected with a given + * static block if possible, while using the given program controller and connection controller to handle + * program and connection actions. + * + * @param other The given static block + * @param programController The given program controller + * @param connectionController The given connection controller + * + * @post The height of this block and its connected set of blocks is changed accordingly. + * @post The position of this block set is changed accordingly to the type of completed connection. + * + * @effect The main connector of this block is connected to a sub connector of the given static block, if possible. + * @effect A sub connector of this block is connected to the main connector of the given static block, if possible. + * @effect The connection controller adds a logical system connection depending on the type of connection. + * @effect The program controller adds the highest block from the set this block is in to the logical program area. + * @effect The height of the given static block and its connected set of blocks is changed accordingly. + * @effect The position of the static block set is changed accordingly to the type of completed connection. + * + * @throws IllegalArgumentException When the given block does not have a colliding connector + */ + public void connectWithStaticBlock(GUIBlock other, ProgramController programController, ConnectionController connectionController) throws IllegalArgumentException{ GUIConnector intersectingConnectorSub; Position staticBlockConnectorPosition, draggedBlockConnectorPosition; From c3367de0f6ad9d0340a326cf694cbedf2f26053f Mon Sep 17 00:00:00 2001 From: Jelle Van De Sijpe Date: Sun, 15 Mar 2020 17:23:45 +0100 Subject: [PATCH 5/6] loader comments --- .../java/Controllers/LevelDataLoader.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main/java/Controllers/LevelDataLoader.java b/src/main/java/Controllers/LevelDataLoader.java index 2e156ec8..8f8bce56 100644 --- a/src/main/java/Controllers/LevelDataLoader.java +++ b/src/main/java/Controllers/LevelDataLoader.java @@ -7,24 +7,51 @@ import java.awt.*; +/** + * A class used as a static level data loader. + * Is only used as a first loader to load the level data the first time. + * + * @author Alpha-team + */ public class LevelDataLoader { + /** + * Return the current robot position + * @return the current robot position + */ public Position getRobotPosition() { return new Position(GameState.getCurrentLevel().getRobot().getX(), GameState.getCurrentLevel().getRobot().getY()); } + /** + * Return the current robot direction + * @return the current robot direction + */ public Direction getRobotDirection() { return GameState.getCurrentLevel().getRobot().getDirection(); } + /** + * Return the current grid size + * @return the current grid size + */ public Position getGridSize() { return new Position(GameState.getCurrentLevel().getGrid().getWidth(), GameState.getCurrentLevel().getGrid().getHeight()); } + /** + * Return the current array of grid cells + * @return the current array of grid cells + */ public Cell[][] getGridCells() { return GameState.getCurrentLevel().getGrid().getCells(); } + /** + * Subscribe the given robot listener to the current robot observer. + * + * @param listener the given robot listener. + */ public void subscribe(RobotListener listener) { GameState.getCurrentLevel().getRobot().subscribe(listener); } From d28d8d995314b063b1466ee9ee2cbf503c960ae3 Mon Sep 17 00:00:00 2001 From: Jelle Van De Sijpe Date: Sun, 15 Mar 2020 17:35:50 +0100 Subject: [PATCH 6/6] added comments --- .../java/GUI/Components/GUIBlockHandler.java | 73 ++++++++++++++++++- .../java/GUI/Components/GUIConnector.java | 6 +- 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/src/main/java/GUI/Components/GUIBlockHandler.java b/src/main/java/GUI/Components/GUIBlockHandler.java index 8a960ea9..b76926f6 100644 --- a/src/main/java/GUI/Components/GUIBlockHandler.java +++ b/src/main/java/GUI/Components/GUIBlockHandler.java @@ -1,13 +1,10 @@ package GUI.Components; -import Controllers.ConnectionController; -import Controllers.ProgramController; import GUI.Blocks.GUIBlock; import GUI.CollisionShapes.CollisionRectangle; import GUI.Panel.GamePanel; import GUI.Panel.PalettePanel; import GUI.Panel.ProgramAreaPanel; -import System.Logic.ProgramArea.Program; import Utility.Position; import java.awt.event.MouseEvent; @@ -15,6 +12,11 @@ import java.util.List; import java.util.Optional; +/** + * A class used to handle GUI blocks. + * + * @author Alpha-team + */ public class GUIBlockHandler { private final PalettePanel palette; @@ -29,6 +31,14 @@ public GUIBlockHandler(PalettePanel palette, ProgramAreaPanel programArea) { this.programArea = programArea; } + /** + * Handle the current mouse event with the given id, x and y coordinate. + * @param id the given mouse event id + * @param x the given mouse x-coordinate + * @param y the given mouse y-coordinate + * + * @effect The right mouse event is handled accordingly. + */ public void handleMouseEvent(int id, int x, int y) { if (id == MouseEvent.MOUSE_PRESSED) { @@ -42,6 +52,11 @@ else if (id == MouseEvent.MOUSE_DRAGGED) { } } + /** + * todo + * @param x + * @param y + */ private void handleMousePressed(int x, int y) { boolean paletteBlockContainsMouse = AnyContains(palette.getBlocks(), x, y); @@ -66,6 +81,9 @@ private void handleMousePressed(int x, int y) { } } + /** + * todo + */ private void handleMouseReleased() { if (draggedBlock != null) { @@ -91,12 +109,23 @@ else if (isInPanelAny(palette.getPanelRectangle(), draggedBlocks)) { } } + /** + * Handle the event where the mouse is dragged with the given x and y coordinates of the mouse. + * + * @param x the given x-coordinate of the mouse + * @param y the given y-coordinate of the mouse + * + * @effect The position of the dragged block is updated accordingly. + */ private void handleMouseDragged(int x, int y) { if (draggedBlock != null) { draggedBlock.setPosition(x + dragDelta.getX(), y + dragDelta.getY()); } } + /** + * todo + */ private void handleBlockFromPaletteToProgramArea() { GUIBlock newBlock = palette.getNewBlock(draggedBlock.getId(), draggedBlock.getX(), draggedBlock.getY()); @@ -114,12 +143,15 @@ private void handleBlockFromPaletteToProgramArea() { } } + /** + * todo + */ private void handleBlockFromProgramAreaToProgramArea() { + boolean connectionFound = false; programArea.disconnectInProgramArea(draggedBlock); draggedBlock.disconnectMainConnector(); - for (GUIBlock block : draggedBlocks) { Optional connectedBlock = programArea.getBlocks().stream().filter(b -> b.intersectsWithConnector(block)).findAny(); @@ -134,6 +166,13 @@ private void handleBlockFromProgramAreaToProgramArea() { } } + /** + * Handle the event where the dragged gui bock goes from a certain position to the palette + * + * @effect Disconnect the dragged block from its previous set of blocks. + * @effect Reset the position of the original palette block if the dragged block came from the palette. + * @effect Delete the block from the program area if the dragged block came from the program area. + */ private void handleBlockToPalette() { programArea.disconnectInProgramArea(draggedBlock); @@ -147,14 +186,40 @@ else if (blockSourcePanel == programArea) { } } + /** + * Return whether any block in the given list of gui blocks contains the point defined + * by the given x and y coordinate. + * + * @param blocks the given list of gui blocks + * @param x the given x-coordinate + * @param y the given y-coordinate + * + * @return whether any block in the given list of gui blocks contains the point. + */ private boolean AnyContains(List blocks, int x, int y) { return blocks.stream().anyMatch(b -> b.contains(x, y)); } + /** + * Checks if a given gui block is in a given collision rectangle panel. + * + * @param panel the given panel + * @param blocks the given gui block + * + * @return if the given gui block is in the given panel. + */ private boolean isInPanel(CollisionRectangle panel, List blocks) { return blocks.stream().allMatch(b -> b.isInside(panel)); } + /** + * Checks if a given list of guiblocks is in a given collision rectangle panel. + * + * @param panel the given panel + * @param blocks the given list of gui blocks + * + * @return if the given list of gui blocks is in the given panel. + */ private boolean isInPanelAny(CollisionRectangle panel, List blocks) { return blocks.stream().anyMatch(b -> b.isInside(panel)); } diff --git a/src/main/java/GUI/Components/GUIConnector.java b/src/main/java/GUI/Components/GUIConnector.java index b488977c..b2348d9f 100644 --- a/src/main/java/GUI/Components/GUIConnector.java +++ b/src/main/java/GUI/Components/GUIConnector.java @@ -4,7 +4,11 @@ import GUI.Blocks.GUIBlock; import java.awt.*; - +/** + * A class used as a GUI connector to connect GUI Blocks visually. + * + * @author Alpha-team + */ public class GUIConnector { /**