Browse files

incorporating controller

  • Loading branch information...
1 parent e94c558 commit fc5c229abb86286ceefb5d81a843840d9419504d Rebecca Murphey committed Feb 25, 2010
Showing with 27 additions and 26 deletions.
  1. +4 −6 index.html
  2. +6 −0 js/Transformers/Bot.js
  3. +1 −1 js/Transformers/Controller.js
  4. +15 −4 js/Transformers/_Weapon.js
  5. +1 −15 js/Transformers/_base.js
View
10 index.html
@@ -7,14 +7,12 @@
<body>
<div id="controller">
</div>
- <script>
- var djConfig = {
- isDebug : true
- };
- </script>
+
+ <input type="button" id="setup" value="Setup Game" />
+ <input type="button" id="play" value="Play Turn" />
<script src="/js/dojo/dojo.js"></script>
- <!-- <script src="/js/release/game/dojo/dojo.js"></script> -->
+ <!-- <script src="/js/release/transformers/dojo/dojo.js"></script> -->
<script>
dojo.require('Transformers._base');
</script>
View
6 js/Transformers/Bot.js
@@ -21,14 +21,20 @@ dojo.require('Transformers.Gun');
new Transformers.Gun(this);
}
+ d.subscribe('/startTurn', this, 'attack');
d.subscribe('/firing', this, '_defend');
+
d.subscribe('/' + this.config.team + '/join', this, '_addTeammate');
d.publish('/' + this.config.team + '/join');
},
attack : function() {
d.publish('/' + this.config.team + '/attack', [ this ]);
+
+ setTimeout(function() {
+ d.publish('/endTurn');
+ }, this.turnLength);
},
_defend : function(attack) {
View
2 js/Transformers/Controller.js
@@ -34,7 +34,7 @@ dojo.require('Transformers.Bot');
},
_play : function() {
-
+ d.publish('/play');
}
});
})(dojo);
View
19 js/Transformers/_Weapon.js
@@ -5,27 +5,38 @@ dojo.provide('Transformers._Weapon');
constructor : function(bot) {
this.bot = bot;
this.disabled = false;
+ this.attacking = false;
d.subscribe('/' + bot.config.team + '/attack', this, '_fire');
+ d.subscribe('/endTurn', this, '_endTurn');
},
_fire : function() {
- console.log('attempting to fire');
- if (this.disabled) { return; }
+ this.attacking = true;
+
+ if (!this.rounds || this.disabled || !this.attacking) { return; }
this.disabled = true;
d.publish('/firing', [ {
bot : this.bot,
maxDamage : this.damage
} ]);
- this.rounds--;
+ // fire an arbitrary # of rounds
+ this.rounds = this.rounds - Math.floor(Math.random() * this.rounds);
if (this.rounds) {
- setTimeout(d.hitch(this, function() {
+ this.timeout = setTimeout(d.hitch(this, function() {
this.disabled = false;
+ this._fire();
}), this.reload);
}
+ },
+
+ _endTurn : function() {
+ this.attacking = false;
+ this.disabled = false;
+ this.timeout && clearTimeout(this.timeout);
}
});
})(dojo);
View
16 js/Transformers/_base.js
@@ -1,17 +1,3 @@
dojo.provide('Transformers._base');
-dojo.require('Transformers.Bot');
-
-var autobot = new Transformers.Bot({
- team : 'autobot',
- evil : false,
- missiles : 1,
- guns : 5
-});
-
-var decepticon = new Transformers.Bot({
- team : 'decepticons',
- evil : true,
- missiles : 3,
- guns : 1
-});
+dojo.require('Transformers.Controller');

0 comments on commit fc5c229

Please sign in to comment.