Skip to content

Commit

Permalink
Merge pull request #75 from UnGuZartex/Testing
Browse files Browse the repository at this point in the history
Testing
  • Loading branch information
UnGuZartex authored May 25, 2020
2 parents 889ac60 + 968da9d commit c6f2a75
Show file tree
Hide file tree
Showing 111 changed files with 7,818 additions and 1,289 deletions.
Binary file modified gameJars/RobotGameWorld-latest.jar
Binary file not shown.
Binary file modified gameJars/mygame-latest.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package Controllers.ControllerClasses;

import Controllers.BlockLinkDatabase;
import Controllers.Utility.IGUISystemBlockLink;
import GUI.Blocks.IGUIBlock;
import System.BlockStructure.Blocks.Block;
import System.Logic.ProgramArea.PABlockHandler;
import System.Logic.ProgramArea.Handlers.PABlockHandler;

/**
* Controller class to handle the blocks in the system.
*
* @invar A block handler controller must have an effective database link.
* | blockDatabase != null
* @invar A block handler controller must have an effective pa block handler.
* | blockHandler != null
* @invar A block handler controller must have a valid block link.
* | isValidIGUISystemBlockLink(blockLink)
* @invar A block handler controller must have a valid pa block handler.
* | isValidPABlockHandler(blockHandler)
*
* @author Alpha-team
*/
public class BlockHandlerController {

/**
* Variable referring to the block data base of this block handler controller.
* Variable referring to the block link of this block handler controller.
*/
private final BlockLinkDatabase blockDatabase;
private final IGUISystemBlockLink blockLink;
/**
* Variable referring to the block handler of the block handler controller.
*/
Expand All @@ -29,41 +29,62 @@ public class BlockHandlerController {
/**
* Initialise a new block handler controller with given block database and pa block handler.
*
* @param blockDatabase The database for this block handler controller.
* @param blockLink The block link for this block handler controller.
* @param blockHandler The pa block handler for this block handler controller.
*
* @post The database of this block handler controller is set to the given database.
* @post The pa block handler of this block handler controller is set to the given pa block handler.
*
* @throws IllegalArgumentException
* When the given database is not effective.
* When the given block link is not valid.
* @throws IllegalArgumentException
* When the given pa block handler is not effective.
* When the given pa block handler is not valid.
*/
public BlockHandlerController(BlockLinkDatabase blockDatabase, PABlockHandler blockHandler) throws IllegalArgumentException {
if (blockDatabase == null) {
throw new IllegalArgumentException("The given block database is not effective!");
public BlockHandlerController(IGUISystemBlockLink blockLink, PABlockHandler blockHandler) throws IllegalArgumentException {
if (!isValidIGUISystemBlockLink(blockLink)) {
throw new IllegalArgumentException("The given block database is not valid!");
}
if (blockHandler == null) {
throw new IllegalArgumentException("The given block handler is not effective");
if (!isValidPABlockHandler(blockHandler)) {
throw new IllegalArgumentException("The given block handler is not valid");
}
this.blockDatabase = blockDatabase;
this.blockLink = blockLink;
this.blockHandler = blockHandler;
}

/**
* Checks whether or not the given block link is valid.
*
* @param blockLink The block link to check.
*
* @return True if and only if the given block link is effective.
*/
public static boolean isValidIGUISystemBlockLink(IGUISystemBlockLink blockLink) {
return blockLink != null;
}

/**
* Checks whether or not the given pa block handler is valid.
*
* @param blockHandler The pa block handler to check.
*
* @return True if and only if the given pa block handler is effective.
*/
public static boolean isValidPABlockHandler(PABlockHandler blockHandler) {
return blockHandler != null;
}

/**
* Get a block with the given index and add it to the program area.
*
* @param block The gui block to connect.
* @param index The index of the block in the palette.
*
* @effect The given block and a new block from the palette is added to the database.
* @effect The new block from the palette is added to the program area.
* @effect The given block and a new block from the system palette is added to the database.
* @effect The new block from the palette is added to the program area as a program.
*/
public void addBlockToPA(IGUIBlock block, int index) {
blockDatabase.addBlockPair(block, blockHandler.getFromPalette(index));
Block toAdd = blockDatabase.getBlockFromGUIBlock(block);
blockHandler.addToPA(toAdd);
blockLink.addBlockPair(block, blockHandler.getFromPalette(index));
addExistingBlockAsProgram(block);
}

/**
Expand All @@ -75,9 +96,23 @@ public void addBlockToPA(IGUIBlock block, int index) {
* area is deleted.
*/
public void deleteFromPA(IGUIBlock block) {
Block toDelete = blockDatabase.getBlockFromGUIBlock(block);
blockDatabase.removeBlock(block);
Block toDelete = blockLink.getBlockFromGUIBlock(block);
blockHandler.deleteProgram(toDelete);
blockLink.removeBlock(block);
}

/**
* Add the given block to the program area as a potential program.
*
* @param block The block to add.
*
* @pre The given block is already linked with a system block.
*
* @effect The compatible system block is received and added to the program area.
*/
public void addExistingBlockAsProgram(IGUIBlock block) {
Block toAdd = blockLink.getBlockFromGUIBlock(block);
blockHandler.addToPA(toAdd);
}

/**
Expand All @@ -88,6 +123,6 @@ public void deleteFromPA(IGUIBlock block) {
*/
public IGUIBlock getHighlightedBlock() {
Block highlightedBlock = blockHandler.getPA().getNextBlockInProgram();
return (highlightedBlock != null) ? blockDatabase.getGUIBlockFromBlock(highlightedBlock) : null;
return (highlightedBlock != null) ? blockLink.getGUIBlockFromBlock(highlightedBlock) : null;
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package Controllers.ControllerClasses;

import Controllers.BlockLinkDatabase;
import Controllers.Utility.IGUISystemBlockLink;
import GUI.Blocks.IGUIBlock;
import System.BlockStructure.Blocks.Block;
import System.BlockStructure.Connectors.MainConnector;
import System.BlockStructure.Connectors.SubConnector;
import System.Logic.ProgramArea.PABlockHandler;
import System.Logic.ProgramArea.Handlers.PABlockHandler;

/**
* A controller class for the connections between GUI and system.
*
* @invar A connection controller must have an effective block link database.
* | converter != null
* @invar A connection controller must have an effective pa block handler.
* | blockHandler != null
* @invar A connection controller must have a valid block link database.
* | isValidIGUISystemBlockLink(converter)
* @invar A connection controller must have a valid pa block handler.
* | isValidPABlockHandler(blockHandler)
*
* @author Alpha-team
*/
Expand All @@ -22,7 +22,7 @@ public class ConnectionController {
/**
* Variable referring to the block link database of this controller.
*/
private final BlockLinkDatabase converter;
private final IGUISystemBlockLink converter;
/**
* Variable referring to the pa block handler of this controller.
*/
Expand All @@ -38,21 +38,43 @@ public class ConnectionController {
* @post The block handler of this controller is set to the given block handler.
*
* @throws IllegalArgumentException
* When the given converter is not effective.
* When the given converter is not valid.
* @throws IllegalArgumentException
* When the given block handler is not effective.
* When the given block handler is not valid.
*/
public ConnectionController(BlockLinkDatabase converter, PABlockHandler blockHandler) throws IllegalArgumentException {
if (converter == null) {
throw new IllegalArgumentException("The given converter is not effective!");
public ConnectionController(IGUISystemBlockLink converter, PABlockHandler blockHandler) throws IllegalArgumentException {
if (!isValidIGUISystemBlockLink(converter)) {
throw new IllegalArgumentException("The given converter is not valid!");
}
if (blockHandler == null) {
throw new IllegalArgumentException("The given block handler is not effective!");
if (!isValidPABlockHandler(blockHandler)) {
throw new IllegalArgumentException("The given block handler is not valid!");
}
this.converter = converter;
this.blockHandler = blockHandler;
}

/**
* Checks whether or not the given block link is valid.
*
* @param blockLink The block link to check.
*
* @return True if and only if the given block link is effective.
*/
public static boolean isValidIGUISystemBlockLink(IGUISystemBlockLink blockLink) {
return blockLink != null;
}

/**
* Checks whether or not the given pa block handler is valid.
*
* @param blockHandler The pa block handler to check.
*
* @return True if and only if the given pa block handler is effective.
*/
public static boolean isValidPABlockHandler(PABlockHandler blockHandler) {
return blockHandler != null;
}

/**
* Connect the block in the block handler equal to the given blocks.
*
Expand All @@ -73,7 +95,7 @@ public void connectBlocks(IGUIBlock withMain, IGUIBlock withSub, int subConnecto
*
* @param withMain The gui block of which its system block should be disconnected.
*
* @effect The block compatibel with the given gui block is disconnected in on
* @effect The block compatible with the given gui block is disconnected in on
* its main connector.
*/
public void disconnectBlock(IGUIBlock withMain) {
Expand All @@ -82,7 +104,7 @@ public void disconnectBlock(IGUIBlock withMain) {
}

/**
* Checks whether or not the given gui blocks can connect.
* Checks whether the given gui blocks can connect.
*
* @param withMain The block to connect through its main connector.
* @param withSub The block to connect through a sub connector.
Expand Down
55 changes: 37 additions & 18 deletions src/main/java/Controllers/ControllerClasses/HistoryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
/**
* Controller used for handling the history of ui commands.
*
* @invar The history controller must have an effective command history at all time.
* | history != null
* @invar The history controller must have an effective program area at all time.
* | programArea != null
* @invar The history controller must have a valid command history at all time.
* | isValidCommandHistory(history)
* @invar The history controller must have a valid program area at all time.
* | isValidProgramArea(programArea)
*
* @author Alhpa-team
*/
public class HistoryController {
Expand All @@ -34,21 +35,43 @@ public class HistoryController {
* @post The program area is set to the given program area.
*
* @throws IllegalArgumentException
* When the given history is not effective.
* When the given history is not valid.
* @throws IllegalArgumentException
* When the given program area is not effective.
* When the given program area is not valid.
*/
public HistoryController(CommandHistory history, ProgramArea programArea) throws IllegalArgumentException {
if (history == null) {
throw new IllegalArgumentException("The given history is null!");
if (!isValidCommandHistory(history)) {
throw new IllegalArgumentException("The given history is not valid!");
}
if (programArea == null) {
throw new IllegalArgumentException("The given program area is null!");
if (!isValidProgramArea(programArea)) {
throw new IllegalArgumentException("The given program area not valid!");
}
this.history = history;
this.programArea = programArea;
}

/**
* Checks whether or not the given command history is valid.
*
* @param history The command history to check.
*
* @return True if and only if the given command history is effective.
*/
public static boolean isValidCommandHistory(CommandHistory history) {
return history != null;
}

/**
* Checks whether or not the given program area is valid.
*
* @param programArea The program area to check.
*
* @return True if and only if the given program area is effective.
*/
public static boolean isValidProgramArea(ProgramArea programArea) {
return programArea != null;
}

/**
* Execute a command and add it to the history.
*
Expand All @@ -61,22 +84,18 @@ public void execute(Command command) {
}

/**
* Execute a program step command in the program area,
* if possible.
* Execute a program step command in the program area.
*
* @Effect The program area adds a program run command to the history,
* if possible.
* @Effect The program area adds a program run command to the history,.
*/
public void executeProgramRunCommand() {
programArea.addProgramRunCommand();
}

/**
* Execute a program reset command in the program area,
* if possible.
* Execute a program reset command in the program area, if possible.
*
* @Effect The program area adds a program reset command to the history,
* if possible.
* @Effect The program area adds a program reset command to the history.
*/
public void executeProgramResetCommand() {
programArea.addProgramResetCommand();
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/Controllers/ListenerInterfaces/CallListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package Controllers.ListenerInterfaces;

/**
* An interface for objects which listen to call blocks.
*
* @author Alhpa-team
*/
public interface CallListener {

/**
* Event to call when the procedure is deleted.
*/
void onProcedureDeleted();
}
29 changes: 29 additions & 0 deletions src/main/java/Controllers/ListenerInterfaces/PaletteListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package Controllers.ListenerInterfaces;

/**
* An interface for listeners to a palette.
*
* @author Alpha-team
*/
public interface PaletteListener {

/**
* Event to call when a procedure is deleted.
*
* @param index The index of the call block in the palette of the deleted procedure.
*/
void procedureDeleted(int index);

/**
* Event to call when a procedure is created.
*/
void procedureCreated();

/**
* This event is called when the program area has either reached its max blocks, or
* the current amount of blocks is under the max blocks again.
*
* @param reachedMaxBlocks the given boolean indicating if the number of max blocks in the program area is reached.
*/
void onMaxBlocksReached(boolean reachedMaxBlocks);
}
Loading

0 comments on commit c6f2a75

Please sign in to comment.