@Test public void testHealExecute() { testPlayer.addHealth(-5); commandHeal.execute(""); assertEquals(testPlayer.getMaxHealth(), testPlayer.getCurrentHealth()); }
@Override String execute(Object[] arguments) { player = World.getInstance().getFirstPlayer(); switch (this.commandType) { case HEAL: int healAmount = player.getMaxHealth() - player.getHealth(); player.addHealth(healAmount); return "Healed: "+healAmount; case HEALTH: int newHealth; try { newHealth = Integer.parseInt((String) arguments[0]); } catch (NumberFormatException e) { return "Positive integer only."; } if (newHealth > 0) { player.setMaxHealth(newHealth); player.addHealth(player.getMaxHealth() - player.getHealth()); return "Max Health Now: " + newHealth; } else { return "Positive integer only."; } } return null; }
HealthCommands extends Command { @Override String execute(Object[] arguments) { player = World.getInstance().getFirstPlayer(); switch (this.commandType) { case HEAL: int healAmount = player.getMaxHealth() - player.getHealth(); player.addHealth(healAmount); return "Healed: "+healAmount; case HEALTH: int newHealth; try { newHealth = Integer.parseInt((String) arguments[0]); } catch (NumberFormatException e) { return "Positive integer only."; } if (newHealth > 0) { player.setMaxHealth(newHealth); player.addHealth(player.getMaxHealth() - player.getHealth()); return "Max Health Now: " + newHealth; } else { return "Positive integer only."; } } return null; } }
HealthCommands extends Command { @Override String execute(Object[] arguments) { player = World.getInstance().getFirstPlayer(); switch (this.commandType) { case HEAL: int healAmount = player.getMaxHealth() - player.getHealth(); player.addHealth(healAmount); return "Healed: "+healAmount; case HEALTH: int newHealth; try { newHealth = Integer.parseInt((String) arguments[0]); } catch (NumberFormatException e) { return "Positive integer only."; } if (newHealth > 0) { player.setMaxHealth(newHealth); player.addHealth(player.getMaxHealth() - player.getHealth()); return "Max Health Now: " + newHealth; } else { return "Positive integer only."; } } return null; } HealthCommands(CommandType command); }
HealthCommands extends Command { @Override String execute(Object[] arguments) { player = World.getInstance().getFirstPlayer(); switch (this.commandType) { case HEAL: int healAmount = player.getMaxHealth() - player.getHealth(); player.addHealth(healAmount); return "Healed: "+healAmount; case HEALTH: int newHealth; try { newHealth = Integer.parseInt((String) arguments[0]); } catch (NumberFormatException e) { return "Positive integer only."; } if (newHealth > 0) { player.setMaxHealth(newHealth); player.addHealth(player.getMaxHealth() - player.getHealth()); return "Max Health Now: " + newHealth; } else { return "Positive integer only."; } } return null; } HealthCommands(CommandType command);  }
HealthCommands extends Command { @Override String execute(Object[] arguments) { player = World.getInstance().getFirstPlayer(); switch (this.commandType) { case HEAL: int healAmount = player.getMaxHealth() - player.getHealth(); player.addHealth(healAmount); return "Healed: "+healAmount; case HEALTH: int newHealth; try { newHealth = Integer.parseInt((String) arguments[0]); } catch (NumberFormatException e) { return "Positive integer only."; } if (newHealth > 0) { player.setMaxHealth(newHealth); player.addHealth(player.getMaxHealth() - player.getHealth()); return "Max Health Now: " + newHealth; } else { return "Positive integer only."; } } return null; } HealthCommands(CommandType command);   }