1
0
mirror of https://github.com/exane/not-gwent-online synced 2024-10-31 10:36:53 +00:00
not-gwent-online/server/Battle.js

59 lines
1.1 KiB
JavaScript
Raw Normal View History

2015-06-10 16:12:52 +00:00
var Battleside = require("./Battleside");
2015-06-13 19:36:02 +00:00
var io = global.io;
2015-06-10 16:12:52 +00:00
var Battle = (function(){
2015-06-13 22:33:20 +00:00
var Battle = function(id, p1, p2){
2015-06-10 16:12:52 +00:00
if(!(this instanceof Battle)){
2015-06-13 22:33:20 +00:00
return (new Battle(id, p1, p2));
2015-06-10 16:12:52 +00:00
}
/**
* constructor here
*/
2015-06-13 19:36:02 +00:00
this._id = id;
2015-06-13 22:33:20 +00:00
this._user1 = p1;
this._user2 = p2;
2015-06-10 16:12:52 +00:00
};
var r = Battle.prototype;
/**
* methods && properties here
* r.property = null;
* r.getProperty = function() {...}
*/
2015-06-13 19:36:02 +00:00
r.p1 = null;
r.p2 = null;
2015-06-13 22:33:20 +00:00
r._user1 = null;
r._user2 = null;
2015-06-13 19:36:02 +00:00
r.turn = 0;
2015-06-10 16:12:52 +00:00
2015-06-13 19:36:02 +00:00
r._id = null;
2015-06-10 16:12:52 +00:00
2015-06-13 19:36:02 +00:00
r.init = function(){
2015-06-13 22:33:20 +00:00
this.p1 = Battleside(this._user1.getName(), 0, this);
this.p2 = Battleside(this._user2.getName(), 1, this);
2015-06-13 19:36:02 +00:00
this.p1.foe = this.p2;
this.p2.foe = this.p1;
2015-06-13 22:33:20 +00:00
this.p1.send("update:info", {info: this.p1.getInfo()});
this.p2.send("update:info", {info: this.p2.getInfo()});
2015-06-13 19:36:02 +00:00
this.start();
2015-06-10 16:12:52 +00:00
}
2015-06-13 19:36:02 +00:00
r.start = function() {
this.p1.draw(10);
this.p2.draw(10);
2015-06-13 22:33:20 +00:00
//this.p2.wait();
2015-06-10 16:12:52 +00:00
}
2015-06-13 19:36:02 +00:00
r.send = function(event, data) {
io.to(this._id).emit(event, data);
}
2015-06-10 16:12:52 +00:00
return Battle;
})();
module.exports = Battle;