1
0
mirror of https://github.com/exane/not-gwent-online synced 2024-12-23 21:03:14 +00:00
This commit is contained in:
exane 2015-06-18 15:31:36 +02:00
parent 6667db814c
commit cc7c988144
5 changed files with 29 additions and 22 deletions

View File

@ -444,6 +444,11 @@ var User = Backbone.Model.extend({
self.set("passing", passing);
})
app.receive("foe:left", function() {
console.log("your foe left the room");
$(".container").prepend('<div class="alert alert-danger">Your foe left the battle!</div>')
})
app.on("createRoom", this.createRoom, this);
app.on("joinRoom", this.joinRoom, this);

View File

@ -75,11 +75,8 @@ var Battle = (function(){
r.switchTurn = function(side, __flag){
__flag = typeof __flag == "undefined" ? 0 : 1;
//var side = this.turn++ % 2 ? this.p1 : this.p2;
/*if(__flag instanceof Battleside) {
side = __flag;
}*/
if(!(side instanceof Battleside)){
console.trace("side is not a battleside!");
return
@ -198,12 +195,10 @@ var Battle = (function(){
delete this.events[event];
}
r.checkIfIsOver = function(){
return !(this.p1.getRubies() && this.p2.getRubies());
}
r.checkRubies = function(){
var scoreP1 = this.p1.getScore();
var scoreP2 = this.p2.getScore();
@ -223,6 +218,12 @@ var Battle = (function(){
return Math.random() > 0.5 ? this.p1 : this.p2;
}
r.userLeft = function(sideName) {
var side = this[sideName];
side.foe.send("foe:left", null, true);
}
return Battle;
})();

View File

@ -15,14 +15,6 @@ var Room = (function(){
this._users = [];
this._ready = {};
this.socket = scServer.global;
/*
this._channel = this.socket.subscribe(this._id);*/
/*this._channel.watch(function(data) {
*//*self._users.forEach(function(user) {
})*//*
});*/
};
var r = Room.prototype;
@ -46,7 +38,6 @@ var Room = (function(){
if(this._users.length >= 2) return;
this._users.push(user);
user.addRoom(this);
/*user.joinRoom(this.getID());*/
if(!this.isOpen()){
this.initBattle();
@ -62,8 +53,6 @@ var Room = (function(){
}
r.initBattle = function(){
var self = this;
var side = 0;
this._battle = Battle(this._id, this._users[0], this._users[1], this.socket);
this._users[0].send("init:battle", {side: "p1"});
this._users[1].send("init:battle", {side: "p2"});
@ -81,7 +70,15 @@ var Room = (function(){
r.bothReady = function(){
return !!this._ready[this._users[0].getID()] && !!this._ready[this._users[1].getID()];
}
r.leave = function(user) {
var p = "p2";
if(user.getID() === this._users[0].getID()) {
p = "p1";
}
this._battle.userLeft(p);
}
return Room;
})();

View File

@ -63,18 +63,24 @@ var User = (function(){
console.log("user name changed from %s to %s", this._name, name);
this._name = name;
}
r.getName = function() {
return this._name;
}
r.getRoom = function() {
return this._rooms[0];
}
r.addRoom = function(room) {
this._rooms.push(room);
}
r.disconnect = function() {
var self = this;
this._rooms.forEach(function(room) {
room.leave(self);
})
}

View File

@ -23,8 +23,6 @@ module.exports.run = function(worker){
var connections = Connections();
var roomCollection = {};
scServer.on('connection', function(socket){
var user = User(socket);
connections.add(user);
@ -61,7 +59,7 @@ module.exports.run = function(worker){
console.log("user %s joined room %s", user.getName(), room.getID());
user.send("response:joinRoom", room.getID());
}
}, 1000);
}, 500);
})
socket.on("request:roomData", function(){