merged both get and post requests
This commit is contained in:
parent
7d58256e28
commit
2a93fa7fc0
@ -9,7 +9,7 @@ color = 0
|
|||||||
vertical = 0
|
vertical = 0
|
||||||
playersInGame = []
|
playersInGame = []
|
||||||
maxPlayers = 10
|
maxPlayers = 10
|
||||||
timeLeft = 10 + 1
|
timeLeft = 11
|
||||||
|
|
||||||
# Renders client
|
# Renders client
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
@ -50,11 +50,13 @@ def update_game():
|
|||||||
# Return the game with the information you added, in addition to everyone else
|
# Return the game with the information you added, in addition to everyone else
|
||||||
return jsonify(game)
|
return jsonify(game)
|
||||||
|
|
||||||
@app.route('/pregame', methods=['GET','POST','EXIT','COUNT'])
|
@app.route('/pregame', methods=['GET','POST','COUNT'])
|
||||||
def update_players():
|
def update_players():
|
||||||
|
|
||||||
if method.request == 'GET':
|
if method.request == 'GET':
|
||||||
return jsonify(len(playersInGame))
|
countdown()
|
||||||
|
return timeLeft
|
||||||
|
|
||||||
if method.request == 'POST':
|
if method.request == 'POST':
|
||||||
#Define the data given by client.
|
#Define the data given by client.
|
||||||
uuid4 = request.get_json(force=True)
|
uuid4 = request.get_json(force=True)
|
||||||
@ -62,15 +64,13 @@ def update_players():
|
|||||||
if uuid4 not in playersInGame:
|
if uuid4 not in playersInGame:
|
||||||
playersInGame.append(uuid4)
|
playersInGame.append(uuid4)
|
||||||
|
|
||||||
|
return jsonify(len(playersInGame))
|
||||||
|
|
||||||
if method.request == 'EXIT':
|
if method.request == 'EXIT':
|
||||||
#Define the data given by client.
|
#Define the data given by client.
|
||||||
uuid4 = request.get_json(force=True)
|
uuid4 = request.get_json(force=True)
|
||||||
playersInGame.remove(uuid4)
|
playersInGame.remove(uuid4)
|
||||||
|
|
||||||
if method.request == 'COUNT':
|
|
||||||
countdown()
|
|
||||||
return timeLeft
|
|
||||||
|
|
||||||
def countdown():
|
def countdown():
|
||||||
timeLeft = timeLeft - 1
|
timeLeft = timeLeft - 1
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|||||||
@ -45,7 +45,7 @@ document.getElementsByClassName('play')[0].onclick = function startGame() {
|
|||||||
// Update score before creating player so scoreboard starts at 0
|
// Update score before creating player so scoreboard starts at 0
|
||||||
updateScore();
|
updateScore();
|
||||||
waitForPlayers();
|
waitForPlayers();
|
||||||
document.onkeydown = movePlayer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getInitial() {
|
function getInitial() {
|
||||||
@ -114,18 +114,19 @@ function serverTransfer(coordinate,team,turn,username) {
|
|||||||
function waitForPlayers(uuid4) {
|
function waitForPlayers(uuid4) {
|
||||||
timer = setTimeout(function() {
|
timer = setTimeout(function() {
|
||||||
// Sending "I'm here."
|
// Sending "I'm here."
|
||||||
$.ajax({
|
$.ajax('http://127.0.0.1:5000/pregame', {
|
||||||
url: 'http://127.0.0.1:5000/pregame',
|
method: 'POST',
|
||||||
type: 'GET',
|
type : "POST",
|
||||||
async: false,
|
data: JSON.stringify(uuid4, null, '\t'),
|
||||||
// data: '',
|
async: false,
|
||||||
|
dataType: "json",
|
||||||
|
contentType: 'application/json;charset=UTF-8'
|
||||||
|
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
//called when successful
|
numberOfPlayers = data;
|
||||||
numberOfPlayers = data
|
|
||||||
if (numberOfPlayers == '10') {
|
if (numberOfPlayers == '10') {
|
||||||
countdown();
|
countdown();
|
||||||
// try catch delete table for visuals later.
|
// try catch delete table for visuals later.
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function(e) {
|
error: function(e) {
|
||||||
@ -134,46 +135,36 @@ function waitForPlayers(uuid4) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
function sendhere() {
|
// Repeat this function until 10 players are here.
|
||||||
$.ajax('http://127.0.0.1:5000/pregame', {
|
waitForPlayers();
|
||||||
method: 'POST',
|
);
|
||||||
type : "POST",
|
}, 3000);
|
||||||
data: JSON.stringify(uuid4, null, '\t'),
|
|
||||||
async: false,
|
|
||||||
dataType: "json",
|
|
||||||
contentType: 'application/json;charset=UTF-8'
|
|
||||||
})
|
|
||||||
.then(
|
|
||||||
waitForPlayers();
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
}, 3000)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function countdown() {
|
function countdown() {
|
||||||
$.ajax({
|
timer = setTimeout(function() {
|
||||||
url: 'http://127.0.0.1:5000/pregame',
|
$.ajax({
|
||||||
type: 'COUNT',
|
url: 'http://127.0.0.1:5000/pregame',
|
||||||
async: false,
|
type: 'GET',
|
||||||
success: function(data) {
|
async: false,
|
||||||
//called when successful
|
success: function(data) {
|
||||||
timeLeft = data;
|
timeLeft = data;
|
||||||
//MAKE VISUAL STUFF HERE
|
//MAKE VISUAL STUFF HERE
|
||||||
countdown()
|
if(timeLeft == 0) {
|
||||||
if(timeLeft == 0) {
|
createPlayer();
|
||||||
createPlayer();
|
autoScroll('start');
|
||||||
autoScroll('start');
|
document.onkeydown = movePlayer;
|
||||||
}
|
}
|
||||||
|
countdown();
|
||||||
},
|
},
|
||||||
error: function(e) {
|
error: function(e) {
|
||||||
//called when there is an error
|
//called when there is an error
|
||||||
//(e.message);
|
//(e.message);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}, 750); //Prevent too many requests
|
||||||
}
|
}
|
||||||
|
|
||||||
// CREATION
|
// CREATION
|
||||||
|
|
||||||
// Creation of Table
|
// Creation of Table
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user