Do not allow reset if game not started once

This commit is contained in:
Arne Keller 2020-03-07 10:24:41 +01:00
parent 0c9ea4e0ba
commit 6cfc8c0a89
3 changed files with 18 additions and 4 deletions

View File

@ -4,7 +4,7 @@ Error, can not get buildings: game not started
Error, can not get resources: game not started
Error, invalid list-buildings argument: none expected
Error, invalid list-resources argument: none expected
OK
Error, can not reset a game that is not started!
Error, invalid reset argument: none expected
Error, not expecting dice roll
Error, invalid start argument value(s)

View File

@ -3,6 +3,18 @@ package edu.kit.informatik;
import edu.kit.informatik.ui.CommandLine;
public final class Main {
/**
* Utility class -> private constructor.
*/
private Main() {
}
/**
* Program entry point.
*
* @param args command-line arguments
*/
public static void main(String[] args) {
CommandLine.startInteractive();
}

View File

@ -203,11 +203,13 @@ public class CardGame {
}
public void reset() {
if (cardStack != null) {
if (cardStack == null) {
throw new InvalidInputException("can not reset a game that is not started!");
} else {
this.currentCardStack = new ArrayDeque<>(cardStack);
}
this.resources = new ArrayDeque<>();
this.items = new ArrayList<>();
this.resources.clear();
this.items.clear();
this.fightingAnimal = false;
this.awaitedDiceSize = null;
this.minimumDiceRoll = null;