added command sample
This commit is contained in:
31
command/src/main/java/com/iluwatar/Wizard.java
Normal file
31
command/src/main/java/com/iluwatar/Wizard.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.iluwatar;
|
||||
|
||||
public class Wizard extends Target {
|
||||
|
||||
private Command previousSpell;
|
||||
|
||||
public Wizard() {
|
||||
this.setSize(Size.NORMAL);
|
||||
this.setVisibility(Visibility.VISIBLE);
|
||||
previousSpell = null;
|
||||
}
|
||||
|
||||
public void castSpell(Command command, Target target) {
|
||||
System.out.println(this + " casts " + command + " at " + target);
|
||||
command.execute(target);
|
||||
previousSpell = command;
|
||||
}
|
||||
|
||||
public void undoLastSpell() {
|
||||
if (previousSpell != null) {
|
||||
System.out.println(this + " undoes " + previousSpell);
|
||||
previousSpell.undo();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Wizard";
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user