Permalink
Browse files

reworking organization

  • Loading branch information...
Rebecca Murphey
Rebecca Murphey committed Feb 22, 2010
1 parent c0a94b3 commit f3a4ca5ba0d9babcb489ac539f91cd65f6d23e24
Showing with 56 additions and 108 deletions.
  1. +19 −0 js/Transformers/Game.js
  2. +14 −49 js/Transformers/Referee.js
  3. +13 −51 js/Transformers/Team.js
  4. +4 −5 js/Transformers/_Transformer.js
  5. +6 −3 topics.txt
View
@@ -0,0 +1,19 @@
+dojo.provide('Transformers.Game');
+
+dojo.require('dijit.Widget');
+dojo.require('Transformers.Referee');
+
+(function(d) {
+ d.declare('Transformers.Game', [ dijit._Widget ], {
+
+ constructor : function(args) {
+ this.teams = (args && args.teams) || ['autobots', 'decepticons'],
+ this.controller = new Transformers.Referee();
+
+ d.forEach(teams, function(t) { new Transformers.Team(t); });
+
+ d.publish('/game/new');
+ d.publish('/game/start');
+ }
+ });
+})(dojo);
View
@@ -1,63 +1,28 @@
-dojo.provide('Transformers.Controller');
-
-dojo.require('dijit._Widget');
-dojo.require('dijit._Templated');
-
-dojo.require('Transformers.Team');
+dojo.provide('Transformers.Referee');
(function(d) {
- d.declare('Transformers.Controller', [ dijit._Widget, dijit._Templated ], {
+ d.declare('Transformers.Referee', null, {
rate : 100, // ms
- templatePath : d.moduleUrl('Transformers', 'templates/controller.html'),
-
- constructor : function(args) {
- this.teamNames = args.teamNames || ['autobots', 'decepticons'];
- },
-
- postCreate : function() {
- this.setupTeams();
-
- this.connect(this.generateUserGame, 'click', 'userGenerated');
- this.connect(this.generateRandomGame, 'click', 'randomGenerated');
-
- d.subscribe('/game/end', this, 'displayResults');
- },
- setupTeams : function() {
- this.teams = d.map(this.teamNames, function(team) {
- return new Transformers.Team({ team : team }).placeAt(this.domNode, 'last');
- }, this);
- console.log(this.teams);
- },
+ constructor : function() {
+ d.subscribe('/team/join', this, '_registerTeam');
+ d.subscribe('/bot/ping', this, '_handleBotPing');
- generate : function(type) {
- d.forEach([ 'reset', 'new', 'start' ], function(topic) {
- d.publish('/game/' + topic, [ { type : type }]);
- }, this);
+ d.subscribe('/game/start', this, '_doTurn');
+
+ this.firstTurn = Math.random() > 0.5 ? 0 : 1;
},
- userGenerated : function(e) {
- e.preventDefault();
- this.generate('user');
- },
-
- randomGenerated : function(e) {
- e.preventDefault();
- this.generate('random');
+ _doTurn : function() {
+
},
- _randomTeamSize : function() {
- return Math.floor(Math.random() * this.maxTeamSize) + 1;
+ _registerTeam : function(team) {
+ this.teams.push(team);
},
- displayResults : function() {
- var results = [];
- d.forEach(this.teams, function(team) {
- results.push(team.getResults());
- });
-
- console.log(results);
+ _handleBotPing : function(ping) {
+ console.dir(ping);
}
});
-
})(dojo);
View
@@ -7,69 +7,31 @@ dojo.require('Transformers.Autobot');
dojo.require('Transformers.Decepticon');
(function(d) {
- d.declare('Transformers.Team', [ dijit._Widget, dijit._Templated ], {
- rate : 100,
- maxTeamSize : 5,
- creators : {
- 'autobots' : Transformers.Autobot,
- 'decepticons' : Transformers.Decepticon,
- 'default' : Transformers._Transformer
- },
- templatePath : d.moduleUrl('Transformers', 'templates/team.html'),
+ d.declare('Transformers.Team', [ dijit._Widget ], {
+ defaultTeamSize : 5,
constructor : function(args) {
this.team = args.team || 'anonymous';
- this.creator = this.creators[this.name] || this.creators.default;
-
this.score = 0;
- this.players = [];
- },
-
- postCreate : function() {
- d.subscribe('/game/new', this, '_setup');
- d.subscribe('/game/reset', this, '_reset');
- this.teamName.innerHTML = this.team;
- },
-
- getResults : function() {
- return 'TODO';
+ this._setup();
+
+ d.subscribe('/game/start', this, '_setup');
+ d.subscribe('/status/request', this, '_sendStatus');
+
+ d.publish('/game/join', [ this ]);
},
_setup : function(config) {
- this.teamSize = config.type == 'random' ? this._randomTeamSize() : this.playerCount.value || 1;
-
- if (this.teamSize > this.maxTeamSize) {
- this.teamSize = this.maxTeamSize;
- this.playerCount.value = this.maxTeamSize;
- }
-
- this.playerCount.disabled = true;
- this.playerCount.value = this.teamSize;
- this._buildTeam();
- },
-
- _buildTeam : function() {
- var size = this.teamSize;
+ var size = this.teamSize || this.defaultTeamSize;
+ this.members = [];
while (size--) {
- var t = new this.creator({ team : this.name }).placeAt(this.playerStatus, 'last')
- this.players.push(t);
+ this.members.push(new this.creator({ team : this.name }));
}
},
- _reset : function() {
- this.players = d.filter(this.players, function(player) {
- player.destroy();
- return false;
- }, this);
-
- this.playerCount.disabled = false;
- this.playerCount.value = '';
- this.playerCount.innerHTML = '0';
- },
-
- _randomTeamSize : function() {
- return Math.floor(Math.random() * this.maxTeamSize) + 1;
+ _sendStatus : function() {
+ d.publish('/team/ping', [ this ]);
}
});
})(dojo);
@@ -11,14 +11,13 @@ dojo.require('dijit._Widget');
this.health = this.startingHealth;
d.subscribe('/status/request', this, '_sendStatus');
- },
-
- postCreate : function() {
- this._updateHealth();
+ d.subscribe('/game/new', this, 'destroy');
+
+ d.publish('/bot/join', [ this ]);
},
_sendStatus : function() {
d.publish('/status', [ this ]);
- }
+ }
});
})(dojo);
View
@@ -5,15 +5,18 @@
/game/reset ends the game and destroys all bot instances
/game/pause pauses play; bots remain intact
/game/end game over
-/game/join team joins a game
/team/[a|d]/attack attack the opposing team; bigger results, bigger risk
/team/[a|d]/defend defend; can't cause much damage, but won't take much either
/team/[a|d]/transform change state; bots in docile state can't attack but are hard to damage
/team/[a|d]/retreat run; can't cause any damage, won't take much either; costs some health
+/team/join team joins a game
-/ping controller listens here for bots to send updates; do other bots listen too?
+/status/request bots and teams listen here for status requests; respond on /ping
+/ping/team controller listens here for teams to send updates
+/ping/bot controller listens here for bots to send updates
/bot/join bot joins the game
/bot/die bot leaves the game
-/bot/msg bot says something
+/bot/msg bot says something
+

0 comments on commit f3a4ca5

Please sign in to comment.