Rotation slowdown #51
@ -19,6 +19,7 @@ class Game {
|
||||
this.winnerIndex = 0;
|
||||
this.round = 0;
|
||||
this.hunter = new Hunter();
|
||||
this.playerNames = [];
|
||||
}
|
||||
|
||||
finish_turn() {
|
||||
@ -88,6 +89,18 @@ class Game {
|
||||
this.winnerIndex = index;
|
||||
}
|
||||
}
|
||||
|
||||
getPlayerNames(){
|
||||
return this.playerNames;
|
||||
}
|
||||
|
||||
addPlayerName(playerName){
|
||||
this.playerNames.push(playerName);
|
||||
}
|
||||
|
||||
removePlayerName(playerName){
|
||||
this.playerNames.splice(this.playerNames.indexOf(playerName), 1)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Game;
|
@ -50,10 +50,12 @@ io.on('connection', socket => {
|
||||
|
||||
if (game[socket.room].add_player(socket.username)) {
|
||||
|
||||
game[socket.room].addPlayerName(data.username);
|
||||
addedUser = true;
|
||||
|
||||
socket.emit('login');
|
||||
socket.join(socket.room);
|
||||
io.in(socket.room).emit('updatePlayerNames', game[socket.room].getPlayerNames());
|
||||
|
||||
if (game[socket.room].players.length === 1) io.to(socket.id).emit('first player');
|
||||
|
||||
@ -61,7 +63,7 @@ io.on('connection', socket => {
|
||||
|
||||
generate_log_message(socket.room, socket.username, "JOINED", "");
|
||||
} else {
|
||||
io.to(socket.id).emit('error', 'Game started already or room has two many members');
|
||||
io.to(socket.id).emit('error', 'Game started already or room has too many members');
|
||||
}
|
||||
});
|
||||
|
||||
@ -78,6 +80,10 @@ io.on('connection', socket => {
|
||||
|
||||
socket.on('disconnect', function () {
|
||||
if (game[socket.room] !== undefined && addedUser) {
|
||||
|
||||
game[socket.room].removePlayerName(socket.username);
|
||||
io.in(socket.room).emit('updatePlayerNames', game[socket.room].getPlayerNames());
|
||||
|
||||
socket.broadcast.to(socket.room).emit('user left', socket.username);
|
||||
game[socket.room].remove_player(socket.username);
|
||||
|
||||
|
@ -22,6 +22,8 @@ let game_board_size = 2000;
|
||||
let max_size = calculate_size();
|
||||
let sprite_size = Math.floor(game_board_size / 11);
|
||||
|
||||
let playerNames = [];
|
||||
|
||||
// fields
|
||||
let sprites = [
|
||||
new Sprite(1, 9, false), // lower left
|
||||
@ -162,28 +164,33 @@ function start_game() {
|
||||
score_button_text.x = sprite_size * 3 + 25 - sprite_size * 0.2;
|
||||
score_button_text.y = sprite_size * 7 + 25 - sprite_size * 0.2 + sprite_size * 0.5;
|
||||
|
||||
score_button = new PIXI.Graphics();
|
||||
score_button.lineStyle(4, 0x000000, 1);
|
||||
score_button.beginFill(0x7d7d7d);
|
||||
score_button.drawRect(sprite_size * 3 - sprite_size * 0.2, sprite_size * 7 - sprite_size * 0.2 + sprite_size * 0.5, score_button_text.width + 50, score_button_text.height + 50);
|
||||
score_button.endFill();
|
||||
score_button.interactive = true;
|
||||
score_button.buttonMode = true;
|
||||
score_button.defaultCursor = 'pointer';
|
||||
score_button.on('pointerdown', function () {
|
||||
card = new Card(game_board_size, "",
|
||||
{ "text": "Spieler 1: " + positions[0], "status": false },
|
||||
{ "text": "Spieler 2: " + positions[1], "status": false },
|
||||
{ "text": "Spieler 3: " + positions[2], "status": false },
|
||||
{ "text": "Spieler 4: " + positions[3], "status": false }, 0, false);
|
||||
card.showCard();
|
||||
show_card = true;
|
||||
socket.on('updatePlayerNames', function (playerNames) {
|
||||
|
||||
this.playerNames = playerNames;
|
||||
|
||||
score_button = new PIXI.Graphics();
|
||||
score_button.lineStyle(4, 0x000000, 1);
|
||||
score_button.beginFill(0x7d7d7d);
|
||||
score_button.drawRect(sprite_size * 3 - sprite_size * 0.2, sprite_size * 7 - sprite_size * 0.2 + sprite_size * 0.5, score_button_text.width + 50, score_button_text.height + 50);
|
||||
score_button.endFill();
|
||||
score_button.interactive = true;
|
||||
score_button.buttonMode = true;
|
||||
score_button.defaultCursor = 'pointer';
|
||||
score_button.on('pointerdown', function () {
|
||||
card = new Card(game_board_size, "",
|
||||
{ "text": playerNames[0] + ": " + positions[0], "status": false },
|
||||
{ "text": playerNames[1] + ": " + positions[1], "status": false },
|
||||
{ "text": playerNames[2] + ": " + positions[2], "status": false },
|
||||
{ "text": playerNames[3] + ": " + positions[3], "status": false }, 0, false);
|
||||
card.showCard();
|
||||
show_card = true;
|
||||
});
|
||||
|
||||
app.stage.addChild(score_button);
|
||||
score_button.addChild(score_button_text);
|
||||
});
|
||||
|
||||
|
||||
app.stage.addChild(score_button);
|
||||
score_button.addChild(score_button_text);
|
||||
|
||||
socket.on('first player', function () {
|
||||
my_turn.text = "Your Turn";
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user