players start at same time, visuals for timer and lobby
This commit is contained in:
parent
a233a5542e
commit
6c39a38429
@ -33,7 +33,8 @@ def update_game():
|
|||||||
vertical = vertical + 1
|
vertical = vertical + 1
|
||||||
answer = {
|
answer = {
|
||||||
"team": team,
|
"team": team,
|
||||||
"coordinate": [vertical, horizontal]
|
"coordinate": [vertical, horizontal],
|
||||||
|
"max": maxPlayers
|
||||||
}
|
}
|
||||||
|
|
||||||
return jsonify(answer)
|
return jsonify(answer)
|
||||||
|
|||||||
@ -42,7 +42,7 @@ td {
|
|||||||
margin-left:5%;
|
margin-left:5%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.scoreboard, .spectator {
|
.scoreboard, .spectator, .info {
|
||||||
font-family: Lato;
|
font-family: Lato;
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
@ -66,6 +66,13 @@ td {
|
|||||||
margin-top: 45%;
|
margin-top: 45%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.info {
|
||||||
|
padding: 10px 15px 10px 15px;
|
||||||
|
font-size: 30px;
|
||||||
|
margin-left: 40%;
|
||||||
|
bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
#redscore {
|
#redscore {
|
||||||
color: #E62E2E;
|
color: #E62E2E;
|
||||||
background-color: #E62E2E;
|
background-color: #E62E2E;
|
||||||
|
|||||||
@ -9,9 +9,10 @@ var claimColor;
|
|||||||
var turn = 0;
|
var turn = 0;
|
||||||
var spectatorChoose = 1;
|
var spectatorChoose = 1;
|
||||||
var spectatedUser;
|
var spectatedUser;
|
||||||
var numberOfPlayers;
|
var numberOfPlayers = 1;
|
||||||
var canMove = false;
|
var canMove = false;
|
||||||
var serverurl = "http://68.56.19.11:5000"
|
var serverurl = "http://activate.adobe.com:5000"
|
||||||
|
var maxPlayers;
|
||||||
|
|
||||||
// Colors
|
// Colors
|
||||||
var playerColors = {
|
var playerColors = {
|
||||||
@ -29,7 +30,8 @@ document.getElementsByClassName('play')[0].onclick = function startGame() {
|
|||||||
};
|
};
|
||||||
//// OPTIMIZATION - cache callback
|
//// OPTIMIZATION - cache callback
|
||||||
_uuid4 = function(cc) {
|
_uuid4 = function(cc) {
|
||||||
var rr = Math.random() * 16 | 0; return (cc === 'x' ? rr : (rr & 0x3 | 0x8)).toString(16);
|
var rr = Math.random() * 16 | 0;
|
||||||
|
return (cc === 'x' ? rr : (rr & 0x3 | 0x8)).toString(16);
|
||||||
};
|
};
|
||||||
|
|
||||||
username = uuid4();
|
username = uuid4();
|
||||||
@ -42,6 +44,7 @@ document.getElementsByClassName('play')[0].onclick = function startGame() {
|
|||||||
login.parentNode.removeChild(login);
|
login.parentNode.removeChild(login);
|
||||||
// Create scoreboard before table to prevent css glitching
|
// Create scoreboard before table to prevent css glitching
|
||||||
createScoreboard();
|
createScoreboard();
|
||||||
|
createInfo();
|
||||||
createTable();
|
createTable();
|
||||||
// Update score before creating player so scoreboard starts at 0
|
// Update score before creating player so scoreboard starts at 0
|
||||||
updateScore();
|
updateScore();
|
||||||
@ -57,6 +60,7 @@ function getInitial() {
|
|||||||
//called when successful
|
//called when successful
|
||||||
playerCoordinate = data.coordinate;
|
playerCoordinate = data.coordinate;
|
||||||
playerTeam = data.team;
|
playerTeam = data.team;
|
||||||
|
maxPlayers = data.max;
|
||||||
},
|
},
|
||||||
error: function(e) {
|
error: function(e) {
|
||||||
//called when there is an error
|
//called when there is an error
|
||||||
@ -126,9 +130,9 @@ function waitForPlayers(username) {
|
|||||||
.then(
|
.then(
|
||||||
function success(data) {
|
function success(data) {
|
||||||
numberOfPlayers = data.playersInGame;
|
numberOfPlayers = data.playersInGame;
|
||||||
if (numberOfPlayers == 2) {
|
updateInfo();
|
||||||
|
if (numberOfPlayers == maxPlayers) {
|
||||||
countdown();
|
countdown();
|
||||||
// try catch delete table for visuals later.
|
|
||||||
} else {
|
} else {
|
||||||
waitForPlayers(username);
|
waitForPlayers(username);
|
||||||
}
|
}
|
||||||
@ -137,7 +141,6 @@ function waitForPlayers(username) {
|
|||||||
//called when there is an error
|
//called when there is an error
|
||||||
//(e.message);
|
//(e.message);
|
||||||
}
|
}
|
||||||
// Repeat this function until 10 players are here.
|
|
||||||
);
|
);
|
||||||
}, 3000);
|
}, 3000);
|
||||||
}
|
}
|
||||||
@ -150,12 +153,20 @@ function countdown() {
|
|||||||
success: function(data) {
|
success: function(data) {
|
||||||
timeLeft = data.timeLeft;
|
timeLeft = data.timeLeft;
|
||||||
console.log(data);
|
console.log(data);
|
||||||
//MAKE VISUAL STUFF HERE
|
updateTimer(timeLeft);
|
||||||
if (timeLeft === 0) {
|
if (timeLeft === 0) {
|
||||||
canMove = true;
|
canMove = true;
|
||||||
createPlayer();
|
createPlayer();
|
||||||
autoScroll('start');
|
autoScroll('start');
|
||||||
document.onkeydown = movePlayer;
|
document.onkeydown = movePlayer;
|
||||||
|
remove = document.getElementsByClassName("info")[0];
|
||||||
|
remove.parentNode.removeChild(remove);
|
||||||
|
|
||||||
|
if (playerCoordinate[1] == 10) {
|
||||||
|
movement(-1,0);
|
||||||
|
} else {
|
||||||
|
movement(1,0);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
countdown();
|
countdown();
|
||||||
}
|
}
|
||||||
@ -165,7 +176,7 @@ function countdown() {
|
|||||||
//(e.message);
|
//(e.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, 750); //Prevent too many requests
|
}, 250); //Prevent too many requests
|
||||||
}
|
}
|
||||||
|
|
||||||
// CREATION
|
// CREATION
|
||||||
@ -215,6 +226,14 @@ function createPlayer() {
|
|||||||
startSquare.id = username;
|
startSquare.id = username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Creation of Information box
|
||||||
|
|
||||||
|
function createInfo() {
|
||||||
|
var table = document.getElementsByTagName('body')[0].appendChild(document.createElement("DIV"));
|
||||||
|
table.className = 'info';
|
||||||
|
table.appendChild(document.createTextNode("Players in lobby: " + numberOfPlayers));
|
||||||
|
}
|
||||||
|
|
||||||
// UPDATING
|
// UPDATING
|
||||||
|
|
||||||
function updateTable(username, coordinate, team) {
|
function updateTable(username, coordinate, team) {
|
||||||
@ -240,6 +259,14 @@ function updateScore() {
|
|||||||
document.getElementById('bluenumber').childNodes[0].nodeValue = " : " + score[1];
|
document.getElementById('bluenumber').childNodes[0].nodeValue = " : " + score[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateInfo() {
|
||||||
|
document.getElementsByClassName("info")[0].childNodes[0].nodeValue = "Players in lobby: " + numberOfPlayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateTimer(timeLeft) {
|
||||||
|
document.getElementsByClassName("info")[0].childNodes[0].nodeValue = "Countdown: " + timeLeft;
|
||||||
|
}
|
||||||
|
|
||||||
// PLAYER HANDLING
|
// PLAYER HANDLING
|
||||||
|
|
||||||
function movement(x,y) {
|
function movement(x,y) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user