Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Created on Oct 24, 2010
- */
- package engine.rts;
- public class BindingTest
- {
- public static void main(String[] args)
- {
- Unit unit = new Unit();
- Tree tree = new Tree();
- tree.health = 88;
- unit.startChopping(tree);
- while (true)
- {
- unit.tick();
- tree.tick();
- if (unit.choppingTree == null)
- break;
- }
- }
- public static class Unit
- {
- Tree choppingTree;
- public void startChopping(Tree tree)
- {
- tree.binding.listen("chopped", this);
- this.choppingTree = tree;
- }
- public void tick()
- {
- if (this.choppingTree != null)
- {
- System.out.println("chop!");
- this.choppingTree.health -= 10;
- }
- }
- private void onTreeChopped(Tree tree)
- {
- System.out.println("tree was chopped!");
- this.choppingTree = null;
- }
- }
- public static class Tree
- {
- private final Binding binding = new Binding(this);
- public int health = 55;
- public void tick()
- {
- if (this.health <= 0)
- {
- this.binding.fire("chopped");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement