diff --git a/project/src/main/java/de/unistuttgart/informatik/fius/jvk/provided/entity/Sooty_mans.java b/project/src/main/java/de/unistuttgart/informatik/fius/jvk/provided/entity/Sooty_mans.java index 92764053..2a22419a 100644 --- a/project/src/main/java/de/unistuttgart/informatik/fius/jvk/provided/entity/Sooty_mans.java +++ b/project/src/main/java/de/unistuttgart/informatik/fius/jvk/provided/entity/Sooty_mans.java @@ -20,7 +20,7 @@ public class Sooty_mans extends Totoro { /** - * changes the appearance of the player in the game from Neo to Morpheus + * changes the appearance of the player in the game from Totoro to Sooty_mans */ @Override protected String getTextureHandle() { @@ -31,5 +31,4 @@ protected String getTextureHandle() { * TODO: Implement the operations of sooty_mans here * */ - } diff --git a/project/src/main/java/de/unistuttgart/informatik/fius/jvk/provided/entity/Totoro.java b/project/src/main/java/de/unistuttgart/informatik/fius/jvk/provided/entity/Totoro.java index a6433a46..c063310d 100644 --- a/project/src/main/java/de/unistuttgart/informatik/fius/jvk/provided/entity/Totoro.java +++ b/project/src/main/java/de/unistuttgart/informatik/fius/jvk/provided/entity/Totoro.java @@ -8,6 +8,7 @@ package de.unistuttgart.informatik.fius.jvk.provided.entity; +import de.unistuttgart.informatik.fius.icge.simulation.Position; import de.unistuttgart.informatik.fius.icge.simulation.inspection.InspectionAttribute; import de.unistuttgart.informatik.fius.icge.simulation.inspection.InspectionMethod; import de.unistuttgart.informatik.fius.jvk.Texture; @@ -88,7 +89,7 @@ public boolean canCollectNut() { * * @return a List of all Nuts on Totoros field */ - public List getCurrentlyCollectableCoins() { + public List getCurrentlyCollectableNuts() { return this.getCurrentlyCollectableEntities(Nut.class, true); } @@ -130,4 +131,6 @@ public void setNutsInPocket(int amountOfNuts) { public int getNutsInPocket() { return this.getInventory().get(Nut.class, true).size(); } + + } diff --git a/project/src/main/java/de/unistuttgart/informatik/fius/jvk/provided/programs/SafeWalkProgram.java b/project/src/main/java/de/unistuttgart/informatik/fius/jvk/provided/programs/SafeWalkProgram.java new file mode 100644 index 00000000..19aefea9 --- /dev/null +++ b/project/src/main/java/de/unistuttgart/informatik/fius/jvk/provided/programs/SafeWalkProgram.java @@ -0,0 +1,15 @@ +package de.unistuttgart.informatik.fius.jvk.provided.programs; + +import de.unistuttgart.informatik.fius.icge.simulation.programs.Program; +import de.unistuttgart.informatik.fius.jvk.provided.entity.Totoro; + + +public class SafeWalkProgram implements Program { + + @Override + public void run(Totoro totoro) { + if (totoro.canMove()) { + totoro.move(); + } + } +} diff --git a/project/src/main/java/de/unistuttgart/informatik/fius/jvk/tasks/Sheet2Task7.java b/project/src/main/java/de/unistuttgart/informatik/fius/jvk/tasks/Sheet2Task7.java new file mode 100644 index 00000000..96473235 --- /dev/null +++ b/project/src/main/java/de/unistuttgart/informatik/fius/jvk/tasks/Sheet2Task7.java @@ -0,0 +1,35 @@ +package de.unistuttgart.informatik.fius.jvk.tasks; + +import de.unistuttgart.informatik.fius.icge.simulation.Position; +import de.unistuttgart.informatik.fius.icge.simulation.Simulation; +import de.unistuttgart.informatik.fius.icge.simulation.tasks.Task; +import de.unistuttgart.informatik.fius.icge.simulation.tools.PlayfieldModifier; +import de.unistuttgart.informatik.fius.jvk.provided.entity.*; +import de.unistuttgart.informatik.fius.jvk.provided.factories.*; +import de.unistuttgart.informatik.fius.jvk.provided.shapes.*; + +public class Sheet2Task7 implements Task { + + @Override + public void run(Simulation sim) { + PlayfieldModifier pm = new PlayfieldModifier(sim.getPlayfield()); + Totoro totoro1 = new Totoro(); + Totoro totoro2 = new Totoro(); + Totoro totoro3 = new Totoro(); + Totoro totoro4 = new Totoro(); + pm.placeEntityAt(totoro1, new Position(0, 2)); + pm.placeEntityAt(totoro4, new Position(0, 0)); + pm.placeEntityAt(totoro3, new Position(2, 2)); + pm.placeEntityAt(totoro2, new Position(2, 0)); + totoro4.setNutsInPocket(42); + totoro2.setNutsInPocket(42); + totoro1.turnClockWise(); + totoro3.setNutsInPocket(13); + totoro3.turnClockWise(); + totoro1.setNutsInPocket(7); + totoro3.turnClockWise(); + + + } + +} diff --git a/project/src/main/java/de/unistuttgart/informatik/fius/jvk/tasks/Sheet3Task3.java b/project/src/main/java/de/unistuttgart/informatik/fius/jvk/tasks/Sheet3Task3.java index 3ed86c32..34ff83b6 100644 --- a/project/src/main/java/de/unistuttgart/informatik/fius/jvk/tasks/Sheet3Task3.java +++ b/project/src/main/java/de/unistuttgart/informatik/fius/jvk/tasks/Sheet3Task3.java @@ -30,17 +30,18 @@ public void run(Simulation sim) { pm.placeEntityAt(totoro, new Position(0, 0)); //Implementation here - + } private void movePattern(Totoro totoro) { } - private void dropFourCoinsAndTurnLeft(Totoro totoro) { + private void dropFourNutsAndTurnLeft(Totoro totoro) { //write the Code for f) here //make totoro drop four nuts //make totoro turn Left + } } diff --git a/project/src/main/java/de/unistuttgart/informatik/fius/jvk/tasks/Sheet4Task4.java b/project/src/main/java/de/unistuttgart/informatik/fius/jvk/tasks/Sheet4Task4.java index ee0f6242..4861eea8 100644 --- a/project/src/main/java/de/unistuttgart/informatik/fius/jvk/tasks/Sheet4Task4.java +++ b/project/src/main/java/de/unistuttgart/informatik/fius/jvk/tasks/Sheet4Task4.java @@ -18,6 +18,7 @@ import de.unistuttgart.informatik.fius.icge.simulation.tools.*; import de.unistuttgart.informatik.fius.jvk.provided.entity.*; import de.unistuttgart.informatik.fius.jvk.provided.factories.*; +import de.unistuttgart.informatik.fius.jvk.provided.programs.SafeWalkProgram; import de.unistuttgart.informatik.fius.jvk.provided.shapes.*; @@ -36,6 +37,7 @@ public void run(Simulation sim) { Line obstacle = new Line(new Position(3, -rng.nextInt(5)), new Position(3, rng.nextInt(10))); pm.placeEntityAtEachPosition(new BushFactory(), obstacle); // put your implementation below this comment + } } diff --git a/project/src/main/java/de/unistuttgart/informatik/fius/jvk/verifier/Sheet2Task7Verifier.java b/project/src/main/java/de/unistuttgart/informatik/fius/jvk/verifier/Sheet2Task7Verifier.java new file mode 100644 index 00000000..f28bc759 --- /dev/null +++ b/project/src/main/java/de/unistuttgart/informatik/fius/jvk/verifier/Sheet2Task7Verifier.java @@ -0,0 +1,158 @@ +package de.unistuttgart.informatik.fius.jvk.verifier; + +import java.util.ArrayList; +import java.util.List; +import java.util.Iterator; +import java.util.stream.Collectors; + +import de.unistuttgart.informatik.fius.icge.simulation.Position; +import de.unistuttgart.informatik.fius.icge.simulation.Simulation; +import de.unistuttgart.informatik.fius.icge.simulation.TaskVerifier; +import de.unistuttgart.informatik.fius.icge.simulation.actions.*; +import de.unistuttgart.informatik.fius.icge.ui.TaskInformation; +import de.unistuttgart.informatik.fius.icge.ui.TaskVerificationStatus; +import de.unistuttgart.informatik.fius.jvk.provided.BasicTaskInformation; +import de.unistuttgart.informatik.fius.jvk.provided.entity.Nut; + + +public class Sheet2Task7Verifier implements TaskVerifier { + + private BasicTaskInformation task; + + private BasicTaskInformation taskB = new BasicTaskInformation("b) Find the differences between the totoros.", "Find the differences between the totoros.", TaskVerificationStatus.SUCCESSFUL); + + private ActionLog actionLog; + + public Sheet2Task7Verifier() { + List subTasks = new ArrayList<>(); + subTasks.add(this.taskB); + this.task = new BasicTaskInformation("Sheet 2 Task 7", "Learn how differentiate objects and classes", subTasks); + } + + @Override + public void attachToSimulation(Simulation sim) { + this.actionLog = sim.getActionLog(); + } + + @Override + public void verify() { + System.out.println("Verify"); + List spawnActions = this.actionLog.getActionsOfType(EntitySpawnAction.class, true); + + List coinPositions = spawnActions.stream() + .filter((action) -> (action.getEntity() instanceof Nut)) + .map((action) -> action.getPosition()) + .sorted((a, b) -> { + if (a.getY() < b.getY()) return -1; + if (a.getY() == b.getY()) { + if (a.getX() < b.getX()) return -1; + if (a.getX() == b.getX()) return 0; + } + return 1; + }) + .collect(Collectors.toList()); + + // subtask b) + int nrOfCoinsSpawned = coinPositions.size(); + if (nrOfCoinsSpawned >= 5) { + this.taskB = this.taskB.updateStatus(TaskVerificationStatus.SUCCESSFUL); + } + + List subTasks = new ArrayList<>(); + subTasks.add(this.taskB); + + if (subTasks.stream().allMatch(subTask -> subTask.getTaskStatus().equals(TaskVerificationStatus.SUCCESSFUL))) { + this.task = this.task.updateStatus(TaskVerificationStatus.SUCCESSFUL); + } + + this.task = this.task.updateSubTasks(subTasks); + } + + /** + * Check if a field with at least {@code nrOfCoins} exists. + */ + private boolean checkMultiCoinsField(List coinPositions, int nrOfCoins) { + Position currentPos = null; + int currentCount = 0; + + Iterator positions = coinPositions.iterator(); + + while (positions.hasNext()) { + Position p = positions.next(); + if (currentPos == null || !p.equals(currentPos)) { + if (currentCount == nrOfCoins) { // found field with right coincount + return true; + } + currentPos = p; + currentCount = 0; + } + currentCount++; + if (!positions.hasNext()) { // special check for end of list + if (currentCount == nrOfCoins) { // found field with right coincount + return true; + } + } + } + + return false; + } + + /** + * Count the number of horizontal lines of length {@code lineLength}. + */ + private int countLines(List coinPositions, int lineLength) { + if(coinPositions.isEmpty()){ + return 0; + } + int currentX = coinPositions.get(0).getX(); + int currentY = coinPositions.get(0).getY(); + int rowCount = 0; + int currentLength = 0; + + int lineCount = 0; + + Iterator positions = coinPositions.iterator(); + + while (positions.hasNext()) { + Position p = positions.next(); + if (currentY == p.getY()) { + if (currentX + currentLength == p.getX()) { + currentLength++; + if (!positions.hasNext()) { + // special check for end of Iterator + if (currentLength == lineLength) { + // only count lines of the exact length specified + lineCount++; + } + } + } else { + if (currentLength == lineLength) { + // only count lines of the exact length specified + lineCount++; + } + currentX = p.getX(); + currentLength = 1; + } + } else { + if (currentLength == lineLength) { + // only count lines of the exact length specified + lineCount++; + } + // start new row + currentY = p.getY(); + currentX = p.getX(); + currentLength = 1; + } + } + + return lineCount; + } + + @Override + public TaskInformation getTaskInformation() { + return this.task; + } + + + +} diff --git a/project/src/main/java/de/unistuttgart/informatik/fius/jvk/verifier/Sheet3Task2Verifier.java b/project/src/main/java/de/unistuttgart/informatik/fius/jvk/verifier/Sheet3Task2Verifier.java index d522306b..bd33e75a 100644 --- a/project/src/main/java/de/unistuttgart/informatik/fius/jvk/verifier/Sheet3Task2Verifier.java +++ b/project/src/main/java/de/unistuttgart/informatik/fius/jvk/verifier/Sheet3Task2Verifier.java @@ -30,7 +30,7 @@ public class Sheet3Task2Verifier implements TaskVerifier { private BasicTaskInformation taskC = new BasicTaskInformation("c) walk straight", "Walk straight until you are on a field with one or more nuts."); private BasicTaskInformation taskD = new BasicTaskInformation("d) left or right", "Turn right on a field with exactly one nut, but don't forget to collect the nut."); private BasicTaskInformation taskE = new BasicTaskInformation( - "d) the other direction", "When on a field with more than one nut turn left, and collect one of the nuts before stepping of the field." + "e) the other direction", "When on a field with more than one nut turn left, and collect one of the nuts before stepping of the field." ); private BasicTaskInformation taskF = new BasicTaskInformation("f) don't walk into bushes", "Before you walk into a bush you should turn around."); private BasicTaskInformation taskG = new BasicTaskInformation("g) enough food", "Walk until you have collected 20 nuts or step on a field with exactly 9 nuts"); diff --git a/sheets/4/figures/playfield.png b/sheets/4/figures/playfield.png index 96e2177d..448f721c 100644 Binary files a/sheets/4/figures/playfield.png and b/sheets/4/figures/playfield.png differ diff --git a/sheets/4/figures/smily.png b/sheets/4/figures/smily.png index 1466534d..2716616a 100644 Binary files a/sheets/4/figures/smily.png and b/sheets/4/figures/smily.png differ diff --git a/sheets/vorkurs.cls b/sheets/vorkurs.cls index 7b6974ef..ac9ad9d8 100644 --- a/sheets/vorkurs.cls +++ b/sheets/vorkurs.cls @@ -58,9 +58,6 @@ \usetikzlibrary{matrix} \tcbuselibrary{listings,breakable} - -\RequirePackage{cleveref} -\crefname{Bild}{Bild}{Bilder} %% Testing... \RequirePackage{lipsum} %\RequirePackage{todo}