Correctly roll dice and print result

This commit is contained in:
Arne Keller 2020-02-28 12:14:28 +01:00
parent fffc21a73e
commit c0aa7d29e6
6 changed files with 205 additions and 13 deletions

124
game2_input.txt Normal file
View File

@ -0,0 +1,124 @@
startn
metal
metal
metal
metal
metal
metal
metal
metal
metal
metal
metal
metal
metal
metal
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
wood
wood
wood
wood
wood
wood
metal
metal
plastic
plastic
wood
wood
wood
wood
wood
wood
wood
wood
wood
wood
plastic
plastic
plastic
plastic
spider
spider
spider
spider
spider
snake
snake
snake
snake
snake
tiger
tiger
tiger
tiger
tiger
thunderstorm
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
draw
build?
build axe
build club
build fireplace
build shack
build sailingraft
rollD6 1
build hangglider
rollD6 3
list-buildings
build ballon

70
game2_output.txt Normal file
View File

@ -0,0 +1,70 @@
OK
metal
metal
metal
metal
metal
metal
metal
metal
metal
metal
metal
metal
metal
metal
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
wood
wood
wood
wood
wood
wood
metal
metal
plastic
plastic
wood
wood
wood
wood
wood
wood
wood
wood
wood
wood
plastic
plastic
plastic
plastic
axe
ballon
club
fireplace
hangglider
sailingraft
shack
steamboat
OK
OK
OK
OK
OK
lose
OK
lose
shack
fireplace
club
axe
OK

View File

@ -13,6 +13,11 @@ class MainTest {
cmpInOut("game1_input.txt", "game1_output.txt"); cmpInOut("game1_input.txt", "game1_output.txt");
} }
@Test
void game2() throws IOException {
cmpInOut("game2_input.txt", "game2_output.txt");
}
@Test @Test
void commands1() throws IOException { void commands1() throws IOException {
cmpInOut("commands1_input.txt", "commands1_output.txt"); cmpInOut("commands1_input.txt", "commands1_output.txt");

View File

@ -78,6 +78,8 @@ public class CardGame {
return "lose"; return "lose";
} }
} else { } else {
// remove item used to escape
items.remove(items.size() - 1);
if (roll >= minimumDiceRoll) { if (roll >= minimumDiceRoll) {
return "win"; return "win";
} else { } else {
@ -106,11 +108,10 @@ public class CardGame {
assert(resources.removeLastOccurrence(resource)); // TODO: remove assert assert(resources.removeLastOccurrence(resource)); // TODO: remove assert
} }
items.add(item); items.add(item);
// TODO: building to flee if (item.equals(STEAMBOAT) || item.equals(BALLOON)) {
if (items.equals(STEAMBOAT) || items.equals(BALLOON)) {
// player won // player won
reset(); reset();
} else if (items.equals(SAILING_RAFT) || items.equals(HANG_GLIDER)) { } else if (item.equals(SAILING_RAFT) || item.equals(HANG_GLIDER)) {
// need at least a 4/d6 // need at least a 4/d6
fightingAnimal = false; fightingAnimal = false;
awaitedDiceSize = 6; awaitedDiceSize = 6;

View File

@ -29,13 +29,4 @@ public class ListResources extends Command {
throw new InvalidInputException("invalid list-resources argument: none expected"); throw new InvalidInputException("invalid list-resources argument: none expected");
} }
} }
/*
Im Erfolgsfall werden alle aktuell im Besitz befindlichen Ressourcen zeilenweise ausgegeben. Die
Ausgabe ist geordnet absteigend nach dem Aufnahmezeitpunkt der Ressourcen. Folglich sind die
obersten fünf Ressourcen die, die in der Hütte gesichert werden. Besitzt der Spieler keine Ressourcen,wird
EMPTY
ausgegeben.Im Fehlerfall (z.B. bei einem fehlerhaften Eingabeformat) wird eine aussagekräftige Fehlermeldung
beginnend mitError, ausgegeben
*/
} }

View File

@ -1,5 +1,6 @@
package edu.kit.informatik.ui.command; package edu.kit.informatik.ui.command;
import edu.kit.informatik.Terminal;
import edu.kit.informatik.model.CardGame; import edu.kit.informatik.model.CardGame;
import edu.kit.informatik.ui.InvalidInputException; import edu.kit.informatik.ui.InvalidInputException;
@ -17,7 +18,7 @@ public class RollDice extends Command {
@Override @Override
public void apply(CardGame game) throws InvalidInputException { public void apply(CardGame game) throws InvalidInputException {
Terminal.printLine(game.rollDice(size, rolledNumber));
} }
@Override @Override