From e9303c68e414c57c3968ec84992fd3b9a85dd314 Mon Sep 17 00:00:00 2001 From: ericnerdo Date: Tue, 26 Apr 2016 00:43:58 +0200 Subject: [PATCH 1/3] getZPMCount() added to Player --- cicaprojekt/Player.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cicaprojekt/Player.java b/cicaprojekt/Player.java index 472f8df..667381c 100644 --- a/cicaprojekt/Player.java +++ b/cicaprojekt/Player.java @@ -30,4 +30,8 @@ public class Player extends PlayerBase { public void shootStargate(Stargate stargate) { this.currentTile.getAdjacentTile(facingDirection).spawnStargate(stargate, facingDirection); } + + public int getZPMCount(){ + return zpmContainer.size(); + } } From b37606b86f5e135df6e47716f580cc4d1f48c93f Mon Sep 17 00:00:00 2001 From: ericnerdo Date: Tue, 26 Apr 2016 00:44:47 +0200 Subject: [PATCH 2/3] attribute boolean destroyed and its getter added to PlayerBase --- cicaprojekt/PlayerBase.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cicaprojekt/PlayerBase.java b/cicaprojekt/PlayerBase.java index d58d94b..7e25fc6 100644 --- a/cicaprojekt/PlayerBase.java +++ b/cicaprojekt/PlayerBase.java @@ -5,11 +5,13 @@ public class PlayerBase implements Destroyable { protected Tile currentTile; protected Direction facingDirection; protected String name; + protected boolean destroyed; public PlayerBase(String name, Tile startTile, Direction startDirection) { this.name = name; currentTile = startTile; facingDirection = startDirection; + destroyed = false; } @Override @@ -18,6 +20,7 @@ public class PlayerBase implements Destroyable { } public void destroy() { + destroyed = true; } public Tile getCurrentTile() { @@ -78,4 +81,8 @@ public class PlayerBase implements Destroyable { public void setFacingDirection(Direction direction) { facingDirection = direction; } + + public boolean isDestroyed(){ + return destroyed; + } } From 848350394f26d617b3681f9f40b72c5ea1f99fab Mon Sep 17 00:00:00 2001 From: ericnerdo Date: Tue, 26 Apr 2016 00:46:09 +0200 Subject: [PATCH 3/3] Tester methods modified --- cicaprojekt/Tester.java | 163 ++++++++++++++++++++-------------------- 1 file changed, 81 insertions(+), 82 deletions(-) diff --git a/cicaprojekt/Tester.java b/cicaprojekt/Tester.java index ed23c43..9899054 100644 --- a/cicaprojekt/Tester.java +++ b/cicaprojekt/Tester.java @@ -43,7 +43,7 @@ public class Tester { } } - void boxLift(String param) { + String boxLift(String param) { switch (param) { case "O" : oneill.boxLift(); @@ -52,9 +52,10 @@ public class Tester { jaffa.boxLift(); break; } + return "box lifted"; } - void boxDrop(String param) { + String boxDrop(String param) { switch (param) { case "O" : oneill.boxDrop(); @@ -63,6 +64,7 @@ public class Tester { oneill.boxDrop(); break; } + return "box dropped"; } void shootONeillsGun(String param) { @@ -76,26 +78,29 @@ public class Tester { } } - void rotate(String playerParam, String directionParam) { + String rotate(String playerParam, String directionParam) { switch (playerParam) { case "O" : switch (directionParam) { case "L" : oneill.rotateLeft(); - break; + return oneill.getFacingDirection().toString(); case "R" : oneill.rotateRight(); - break; + return oneill.getFacingDirection().toString(); + default: return "Hiba, nem fordult!"; } case "J" : switch (directionParam) { case "L" : jaffa.rotateLeft(); - break; + return jaffa.getFacingDirection().toString(); case "R" : jaffa.rotateRight(); - break; + return jaffa.getFacingDirection().toString(); + default: return "Hiba, nem fordult!"; } + default: return "Hiba, nem létező játékos!"; } } @@ -108,6 +113,12 @@ public class Tester { return blue + " " + yellow + " " + red + " " + green; } + String getConnectedGateOpen(Scale s){ + if(s.getGateConnected().isOpen()) + return "gate open"; + else return "gate closed"; + } + /* custom Test annotation */ @Target(ElementType.METHOD) // it's for methods @Retention(RetentionPolicy.RUNTIME) // we want to retain annotations in runtime @@ -134,31 +145,31 @@ public class Tester { @Test boolean moveTest() throws IOException{ - boolean succes = true; + boolean success = true; loadMap("moveTest"); String listOfPlayers = listPlayers(); if(!listOfPlayers.equals("ONeill: 1, 1 Jaffa: -666, -666 Replicator: -666, -666")) - succes = false; + success = false; move("O"); listOfPlayers = listPlayers(); if(!listOfPlayers.equals("ONeill: 1, 2 Jaffa: -666, -666 Replicator: -666, -666")) - succes = false; + success = false; System.out.print("moveTest: "); - if(succes) + if(success) System.out.println("Sikeres!"); else System.out.println("Sikertelen!"); - return succes; + return success; } @Test boolean testStargates() throws IOException{ - boolean succes = true; + boolean success = true; loadMap("testStargates"); shootONeillsGun("B"); @@ -167,7 +178,7 @@ public class Tester { String listOfStargates = listStargates(); if(!listOfStargates.equals("BlueStargate: 5, 10 YellowStargate: 10, 5 RedStargate: not spawned GreenStargate: not spawned")) - succes = false; + success = false; move("O"); move("O"); @@ -175,95 +186,70 @@ public class Tester { String listOfPlayers = listPlayers(); if(!listOfPlayers.equals("ONeill: 5, 9 Jaffa: -666, -666 Replicator: -666, -666")) - succes = false; + success = false; System.out.print("testStargates: "); - if(succes) + if(success) System.out.println("Sikeres!"); else System.out.println("Sikertelen!"); - return succes; + return success; } @Test - boolean testExtraZPM(){ - String[] commands = {"loadMap testExtraZPMs\n", - "listZPMs\n", - "move O\n", - "move O\n", - "listZPMs\n"}; - - String[] expectedOutputs = {}; - - loadMap("testExtraZPMs"); - - boolean results = testOnSequenceOfCommands(commands, expectedOutputs); - - System.out.print("testExtraZPMs: "); - if(results) - System.out.println("Sikeres!"); - else System.out.println("Sikertelen!"); - - return results; - } - boolean testScalesAndGates() throws IOException { - boolean succes = true; - - String[] commands = {"loadMap testScalesAndGates\n", - "boxLift O\n", - "rotate O L\n", - "boxDrop O\n"}; - - String[] expectedOutputs = {"door open\n"}; + boolean success = true; loadMap("testScalesAndGates"); boxLift("O"); rotate("O", "L"); boxDrop("O"); + String gateOpen = getConnectedGateOpen((Scale)oneill.getCurrentTile().getAdjacentTile(oneill.facingDirection)); + + if(!gateOpen.equals("gate open")) + success = false; + System.out.print("testScalesAndGates: "); - if(succes) + if(success) System.out.println("Sikeres!"); else System.out.println("Sikertelen!"); - return succes; + return success; } @Test - boolean gapTest(){ - String[] commands = {"loadMap gapTest\n", - "move O\n"}; - - String[] expectedOutputs = {}; - boolean results = testOnSequenceOfCommands(commands, expectedOutputs); + boolean gapTest() throws IOException{ + loadMap("gapTest"); + move("O"); + + boolean success = oneill.isDestroyed(); + System.out.print("gapTest: "); - if(results) + if(success) System.out.println("Sikeres!"); else System.out.println("Sikertelen!"); - return results; + return success; } @Test boolean ZPMTest() throws IOException{ - boolean succes = true; - - String[] commands = {"loadMap ZPMTest\n", - "move O\n"}; - - String[] expectedOutputs = {}; + boolean success = true; loadMap("ZPMTest"); move("O"); + if(oneill.getZPMCount() != 1) + success = false; + System.out.print("ZPMTest: "); - if(succes) + if(success) System.out.println("Sikeres!"); else System.out.println("Sikertelen!"); - return succes; + return success; } @Test @@ -297,35 +283,48 @@ public class Tester { return results; } - + @Test - boolean rotationTest() { - String[] commands = {"loadMap rotationTest\n", - "Rotate O L\n", - "Rotate O R\n"}; - - String[] expectedOutputs = {}; - boolean results = testOnSequenceOfCommands(commands, expectedOutputs); + boolean rotationTest() throws IOException { + boolean success = true; + + loadMap("rotationTest"); + if(!rotate("O", "L").equals("WEST")) + success = false; + + if(!rotate("O", "R").equals("NORTH")) + success = false; + System.out.print("rotationTest: "); + if(success) + System.out.println("Sikeres!"); + else System.out.println("Sikertelen!"); + + return success; } @Test - boolean testBoxes(){ - String[] commands = {"loadMap testBoxes\n", - "boxLift\n", - "boxDrop\n"}; + boolean testBoxes() throws IOException{ + boolean success = true; - String[] expectedOutputs = {"boc3 lifted\n", - "box3 dropped\n"}; - - boolean results = testOnSequenceOfCommands(commands, expectedOutputs); + loadMap("testBoxes"); + + if(!boxLift("O").equals("box lifted")) + success = false; + + if(!boxDrop("O").equals("box dropped")) + success = false; System.out.print("testBoxes: "); - if(results) + if(success) System.out.println("Sikeres!"); else System.out.println("Sikertelen!"); - return results; + return success; + } + + private boolean testOnSequenceOfCommands(String[] commands, String[] expectedOutputs) { + return true; } }