2015-06-13 19:36:02 +00:00
|
|
|
|
|
|
|
var io = global.io;
|
|
|
|
var DeckData = require("../assets/data/deck");
|
|
|
|
var Deck = require("./Deck");
|
|
|
|
var Hand = require("./Hand");
|
|
|
|
|
|
|
|
|
2015-06-10 16:12:52 +00:00
|
|
|
var Battleside = (function(){
|
2015-06-13 19:36:02 +00:00
|
|
|
var Battleside = function(name, n, battle){
|
2015-06-10 16:12:52 +00:00
|
|
|
if(!(this instanceof Battleside)){
|
2015-06-13 19:36:02 +00:00
|
|
|
return (new Battleside(name, n, battle));
|
2015-06-10 16:12:52 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* constructor here
|
|
|
|
*/
|
|
|
|
|
2015-06-13 19:36:02 +00:00
|
|
|
this.n = n ? "p2" : "p1";
|
|
|
|
this._name = name;
|
|
|
|
this.battle = battle;
|
|
|
|
this.hand = Hand();
|
|
|
|
this.deck = Deck(DeckData["test"]);
|
2015-06-10 16:12:52 +00:00
|
|
|
};
|
|
|
|
var r = Battleside.prototype;
|
|
|
|
/**
|
|
|
|
* methods && properties here
|
|
|
|
* r.property = null;
|
|
|
|
* r.getProperty = function() {...}
|
|
|
|
*/
|
2015-06-13 19:36:02 +00:00
|
|
|
r._name = null;
|
2015-06-10 16:12:52 +00:00
|
|
|
r._discard = null;
|
|
|
|
r._leader = null;
|
|
|
|
r._close = null;
|
|
|
|
r._range = null;
|
|
|
|
r._siege = null;
|
|
|
|
r._field = null;
|
2015-06-13 22:33:20 +00:00
|
|
|
r._lives = 2;
|
|
|
|
r._score = 0;
|
2015-06-10 16:12:52 +00:00
|
|
|
|
2015-06-13 19:36:02 +00:00
|
|
|
r.foe = null;
|
|
|
|
r.hand = null;
|
|
|
|
r.battle = null;
|
|
|
|
r.deck = null;
|
|
|
|
|
|
|
|
|
|
|
|
r.draw = function(times) {
|
|
|
|
while(times--) {
|
|
|
|
var card = this.deck.draw();
|
|
|
|
this.hand.add(card);
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("update:hand fired");
|
|
|
|
|
|
|
|
this.send("update:hand", {cards: JSON.stringify(this.hand.getCards())});
|
|
|
|
}
|
|
|
|
|
2015-06-13 22:33:20 +00:00
|
|
|
r.getInfo = function() {
|
|
|
|
return {
|
|
|
|
name: this.getName(),
|
|
|
|
lives: this._lives,
|
|
|
|
score: this._score,
|
|
|
|
hand: this.hand.length()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
r.getName = function() {
|
|
|
|
return this._name;
|
|
|
|
}
|
|
|
|
|
2015-06-13 19:36:02 +00:00
|
|
|
r.send = function(event, msg) {
|
|
|
|
msg = msg || {};
|
|
|
|
msg._roomSide = this.n;
|
|
|
|
this.battle.send(event, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-10 16:12:52 +00:00
|
|
|
|
|
|
|
return Battleside;
|
|
|
|
})();
|
|
|
|
|
|
|
|
module.exports = Battleside;
|