/** * Allows player to choose his action for the turn among the possible actions. Only valid integers * are allowed as a choice. */ private void setPlayerAction() { while (true) { System.out.println("1)Attack\n2)Commander action\n0)Help"); int userChoice = getValidChoice(); if (userChoice == 0) { showActionHelp(); } else if (userChoice == 1) { firstArmy.setAction(userChoice); break; } else if (userChoice == 2) { if (firstArmy.isCommanderOnCooldown()) { System.out.printf( "%s special ability is on cooldown for another %s turns.\n", firstArmy.getName(), firstArmy.getCommanderCooldown()); } else { firstArmy.setAction(userChoice); break; } } else { System.out.println(userChoice + " is not a valid choice."); } } }
/** Uses controller to set actions for computer controlled army. */ private void setComputerAction() { secondArmy.setAction(ComputerArmyController.getAction(secondArmy)); }