forked from IF-LK-2020/cheese-champion-1
CheeseChampion
This commit is contained in:
parent
86db7da2be
commit
830c997d39
|
@ -2,15 +2,14 @@
|
|||
public class CheeseChampion {
|
||||
|
||||
// TODO: Ersetze ??? durch die passende Datenstruktur
|
||||
private ??? eingang;
|
||||
private ??? seitengang;
|
||||
private ??? ausgang;
|
||||
private Queue<Maus> eingang;
|
||||
private Stack<Maus> seitengang;
|
||||
private Queue<Maus> ausgang;
|
||||
|
||||
public CheeseChampion() {
|
||||
// TODO: Ersetze ??? durch die passende Datenstruktur
|
||||
eingang = ???;
|
||||
seitengang = ???;
|
||||
ausgang = ???;
|
||||
eingang = new Queue<>();
|
||||
seitengang = new Stack<>();
|
||||
ausgang = new Queue<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,7 +19,9 @@ public class CheeseChampion {
|
|||
* @see java.util.Random
|
||||
*/
|
||||
public void erzeugeMaeuse( int anzahl ) {
|
||||
// TODO: Erzeuge hier "anzahl" Mäuse mit zufälliger Stärke
|
||||
for (int i = 0; i < anzahl; i++) {
|
||||
eingang.enqueue(new Maus(i, (int) (Math.random() * 100)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,7 +30,41 @@ public class CheeseChampion {
|
|||
* Siehe im Buch auf Seite 88 für eine Beschreibung des Kampfes.
|
||||
*/
|
||||
public void kampf() {
|
||||
// TODO: Implemenitere hier den Mäusekampf
|
||||
Maus maus1 = eingang.front();
|
||||
Maus maus2 = seitengang.top();
|
||||
if (maus1 != null) {
|
||||
if (maus2 != null) {
|
||||
if (maus1.getStrength() > maus2.getStrength()) {
|
||||
seitengang.push(maus1);
|
||||
eingang.dequeue();
|
||||
} else {
|
||||
ausgang.enqueue(maus2);
|
||||
seitengang.pop();
|
||||
}
|
||||
} else {
|
||||
seitengang.push(maus1);
|
||||
eingang.dequeue();
|
||||
}
|
||||
} else {
|
||||
if (maus2 != null) {
|
||||
ausgang.enqueue(maus2);
|
||||
seitengang.pop();
|
||||
} else {
|
||||
System.out.println("Fertig.");
|
||||
while (!ausgang.isEmpty()){
|
||||
System.out.print("#" + ausgang.front().getNumber() + ", ");
|
||||
ausgang.dequeue();
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void alleKämpfe() {
|
||||
while (!eingang.isEmpty() || !seitengang.isEmpty()) {
|
||||
kampf();
|
||||
}
|
||||
kampf();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,5 +88,4 @@ public class CheeseChampion {
|
|||
eingang.enqueue( new Maus(10, 38) );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
15
Maus.java
15
Maus.java
|
@ -4,6 +4,19 @@
|
|||
*/
|
||||
public class Maus {
|
||||
|
||||
TODO: Implementiere die Maus nach der Beschreibung
|
||||
private int number;
|
||||
private int strength;
|
||||
|
||||
public Maus(int number, int strength) {
|
||||
this.number = number;
|
||||
this.strength = strength;
|
||||
}
|
||||
|
||||
public int getStrength() {
|
||||
return strength;
|
||||
}
|
||||
|
||||
public int getNumber() {
|
||||
return number;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,29 @@
|
|||
#BlueJ package file
|
||||
dependency1.from=Stack
|
||||
dependency1.to=StackNode
|
||||
dependency1.from=CheeseChampion
|
||||
dependency1.to=Queue
|
||||
dependency1.type=UsesDependency
|
||||
dependency2.from=StackTest
|
||||
dependency2.to=Stack
|
||||
dependency2.from=CheeseChampion
|
||||
dependency2.to=Maus
|
||||
dependency2.type=UsesDependency
|
||||
editor.fx.0.height=777
|
||||
editor.fx.0.width=1123
|
||||
editor.fx.0.x=101
|
||||
editor.fx.0.y=23
|
||||
objectbench.height=95
|
||||
objectbench.width=776
|
||||
dependency3.from=CheeseChampion
|
||||
dependency3.to=Stack
|
||||
dependency3.type=UsesDependency
|
||||
editor.fx.0.height=1000
|
||||
editor.fx.0.width=1296
|
||||
editor.fx.0.x=-8
|
||||
editor.fx.0.y=-8
|
||||
objectbench.height=92
|
||||
objectbench.width=1256
|
||||
package.divider.horizontal=0.6
|
||||
package.divider.vertical=0.8118081180811808
|
||||
package.editor.height=433
|
||||
package.editor.width=653
|
||||
package.editor.x=140
|
||||
package.editor.y=80
|
||||
package.frame.height=600
|
||||
package.frame.width=800
|
||||
package.numDependencies=2
|
||||
package.numTargets=3
|
||||
package.divider.vertical=0.8901220865704772
|
||||
package.editor.height=795
|
||||
package.editor.width=1145
|
||||
package.editor.x=0
|
||||
package.editor.y=0
|
||||
package.frame.height=1000
|
||||
package.frame.width=1296
|
||||
package.numDependencies=3
|
||||
package.numTargets=4
|
||||
package.showExtends=true
|
||||
package.showUses=true
|
||||
project.charset=UTF-8
|
||||
|
@ -30,23 +33,30 @@ readme.width=47
|
|||
readme.x=10
|
||||
readme.y=10
|
||||
target1.height=50
|
||||
target1.name=StackNode
|
||||
target1.name=CheeseChampion
|
||||
target1.showInterface=false
|
||||
target1.type=ClassTarget
|
||||
target1.width=160
|
||||
target1.x=70
|
||||
target1.y=60
|
||||
target1.width=130
|
||||
target1.x=200
|
||||
target1.y=220
|
||||
target2.height=50
|
||||
target2.name=StackTest
|
||||
target2.name=Maus
|
||||
target2.showInterface=false
|
||||
target2.type=UnitTestTargetJunit4
|
||||
target2.width=90
|
||||
target2.x=430
|
||||
target2.y=110
|
||||
target2.type=ClassTarget
|
||||
target2.width=80
|
||||
target2.x=70
|
||||
target2.y=70
|
||||
target3.height=50
|
||||
target3.name=Stack
|
||||
target3.name=Queue
|
||||
target3.showInterface=false
|
||||
target3.type=ClassTarget
|
||||
target3.width=160
|
||||
target3.x=80
|
||||
target3.y=300
|
||||
target3.x=410
|
||||
target3.y=180
|
||||
target4.height=50
|
||||
target4.name=Stack
|
||||
target4.showInterface=false
|
||||
target4.type=ClassTarget
|
||||
target4.width=160
|
||||
target4.x=600
|
||||
target4.y=180
|
||||
|
|
Loading…
Reference in New Issue