Commit 146fa934 authored by Monika's avatar Monika
Browse files

edges playground - racket

parent 25eed86c
......@@ -27,6 +27,13 @@ module.exports = function() {
console.log(player.getTeam());
},
getIds: function() {
var id = [];
Object.keys(_players).forEach(function(key) {
id.push(_players[key].getId());
});
return id;
},
getPlayerById: function(id){
return _players[id];
},
......
......@@ -67,7 +67,6 @@ $(function () {
racket.setAxis(event.pageX - $playground.offset().left,event.pageY - $playground.offset().top);
drawRacket(d);
socket.emit('move racket', d);
......@@ -77,17 +76,20 @@ $(function () {
};
});
var $rackets = $(".rackets");
// Whenever the server emits 'login', log the login message
socket.on('login', function (data) {
log.add("Joined: " + data.numUsers);
log.add("Your name: " + data.username);
console.log(data);
if(!connected){
user.setId(data.id);
if(data.id == 1){
user.setIsTurn(true);
}
for (var i=0; i < data.allIds.length; i++){// if we need later to send all players whe can directly from them take ids
$rackets.append("<div class='racket racket" + data.allIds[i] + "'></div>")
}
racket.setEl($('div.racket' + data.id));
connected = true;
}
......
......@@ -43,13 +43,6 @@
<div id="playground">
<div id="table"></div>
<div class="rackets">
<div class="racket racket0"></div>
<div class="racket racket1"></div>
<div class="racket racket2"></div>
<div class="racket racket3"></div>
<div class="racket racket4"></div>
<div class="racket racket5"></div>
<div class="racket racket6"></div>
</div>
<div class="score"><span class="team0">0</span>:<span class="team1">0</span></div>
<div id="ball"></div>
......
......@@ -69,7 +69,8 @@ io.on('connection', function (socket) {
socket.emit('login', {
numUsers: PlayersCollection.getCount(),
username: newPlayer.getName(),
id: newPlayer.getId()
id: newPlayer.getId(),
allIds: PlayersCollection.getIds()
});
//// echo globally (all clients) that a person has connected
socket.broadcast.emit('user joined', {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment