1 package de.jos.game.aspect.plugins; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 6 import org.apache.commons.lang.StringUtils; 7 8 import de.jos.game.logic.AbstractGameBoard; 9 import de.jos.game.objects.screen.AbstractGameObject; 10 import de.jos.game.objects.screen.TheGame; 11 12 public class ScorePlugin implements DebugPlugin { 13 14 private static final String CMD_SCORE = "SCORE"; 15 private static final String CMD_S = "S"; 16 17 public void executeCommand(AbstractGameObject gameObject, String command) { 18 if (gameObject instanceof TheGame) { 19 AbstractGameBoard board = ((TheGame) gameObject).getGameLogic().getBoard(); 20 if (command.startsWith(CMD_S)) { 21 try { 22 Integer score = Integer.valueOf(command.substring(1).trim()); 23 int oldScore = board.getActionContainer().getActionStatistics().getScore(); 24 board.getActionContainer().getActionStatistics().updateScore(score - oldScore); 25 } catch (Exception e) { 26 e.printStackTrace(); 27 } 28 } 29 } 30 } 31 32 public List<String> getPluginHelp() { 33 List<String> helpStringList = new ArrayList<String>(); 34 helpStringList.add(CMD_S +" <NEW SCORE>"); 35 return helpStringList; 36 } 37 38 public String getPluginHelpCommand() { 39 return CMD_SCORE; 40 } 41 42 public String getPluginName() { 43 return StringUtils.upperCase(CMD_SCORE + " - change the current score"); 44 } 45 46 public boolean possibleCommandMatch(String command) { 47 boolean match = false; 48 if (command.startsWith(CMD_S)) { 49 match = true; 50 } 51 return match; 52 } 53 54 }