use of de.kimminich.kata.tcg.Action in project kata-tcg by bkimminich.
the class ConsoleInputStrategy method nextMove.
@Override
public Move nextMove(int availableMana, int currentHealth, List<Card> availableCards) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in, Charset.defaultCharset()));
Integer card = -1;
Action action = Action.DAMAGE;
while (card < 0 || card > 8 || card > availableMana || !availableCards.contains(new Card(card))) {
try {
String input = br.readLine();
if (input.endsWith("h")) {
action = Action.HEALING;
input = input.replace("h", "");
}
card = Integer.decode(input);
} catch (NumberFormatException e) {
logger.warning("Invalid input: " + e.getMessage());
}
}
return new Move(Optional.of(new Card(card)), action);
} catch (IOException e) {
logger.severe("Could not read console input: " + e.getMessage());
e.printStackTrace();
}
return new Move(Optional.empty(), null);
}
Aggregations