1
0
mirror of https://github.com/exane/not-gwent-online synced 2024-10-31 10:36:53 +00:00
not-gwent-online/server/Battleside.js
2015-06-14 00:33:20 +02:00

80 lines
1.5 KiB
JavaScript

var io = global.io;
var DeckData = require("../assets/data/deck");
var Deck = require("./Deck");
var Hand = require("./Hand");
var Battleside = (function(){
var Battleside = function(name, n, battle){
if(!(this instanceof Battleside)){
return (new Battleside(name, n, battle));
}
/**
* constructor here
*/
this.n = n ? "p2" : "p1";
this._name = name;
this.battle = battle;
this.hand = Hand();
this.deck = Deck(DeckData["test"]);
};
var r = Battleside.prototype;
/**
* methods && properties here
* r.property = null;
* r.getProperty = function() {...}
*/
r._name = null;
r._discard = null;
r._leader = null;
r._close = null;
r._range = null;
r._siege = null;
r._field = null;
r._lives = 2;
r._score = 0;
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())});
}
r.getInfo = function() {
return {
name: this.getName(),
lives: this._lives,
score: this._score,
hand: this.hand.length()
}
}
r.getName = function() {
return this._name;
}
r.send = function(event, msg) {
msg = msg || {};
msg._roomSide = this.n;
this.battle.send(event, msg);
}
return Battleside;
})();
module.exports = Battleside;