I have a java game that I have been working on for a while, and now I would like to revamp my debugging system.
At this moment you press the Tilde key and then type in a range of commands: Heal, Ammo, etc. I later added a spawn command for the zombie enemy. The command is as follows. ~spawn.zombie.100(x-coord).100(y-coord). The following code runs which splits the command into parameters for spawning.
public void cheat(String code) {
String[] tokens = code.substring(1).toLowerCase().split("\\.");
switch (tokens[0]) {
case "spawn":
switch (tokens[1]) {
case "zombie":
game.cubes.add(new EnemyZombie(game, Integer
.parseInt(tokens[2]), Integer.parseInt(tokens[2])));
break;
case "health":
game.cubes.add(new PowerUpHealth(game, Integer
.parseInt(tokens[2]), Integer.parseInt(tokens[2])));
break;
}
break;
default:
break;
}
game.start();
}
How could I implement a syntax similar to that of Java? I would like to be able to type zombie.spawn().setX(100).setY(100).setHealth(1) and have those parameters passed.