fixed memory leak, and corrected countdown
This commit is contained in:
parent
ac4492e9a9
commit
230124e9af
@ -10,7 +10,7 @@ vertical = 0
|
|||||||
playersInGame = []
|
playersInGame = []
|
||||||
# Testing 1 Player for now
|
# Testing 1 Player for now
|
||||||
maxPlayers = 1
|
maxPlayers = 1
|
||||||
timeLeft = 11
|
timeLeft = 11.0
|
||||||
|
|
||||||
# Renders client
|
# Renders client
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
@ -53,11 +53,16 @@ def update_game():
|
|||||||
|
|
||||||
@app.route('/pregame', methods=['GET','POST','EXIT'])
|
@app.route('/pregame', methods=['GET','POST','EXIT'])
|
||||||
def update_players():
|
def update_players():
|
||||||
|
global timeLeft
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
countdown()
|
before = time.clock()
|
||||||
|
time.sleep(0.99)
|
||||||
|
after = time.clock()
|
||||||
|
timeTaken = after - before
|
||||||
|
timeLeft -= timeTaken
|
||||||
|
|
||||||
toReturn = {}
|
toReturn = {}
|
||||||
toReturn["timeLeft"] = timeLeft
|
toReturn["timeLeft"] = int(timeLeft)
|
||||||
return jsonify(toReturn)
|
return jsonify(toReturn)
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
@ -75,15 +80,6 @@ def update_players():
|
|||||||
uuid4 = request.get_json(force=True)
|
uuid4 = request.get_json(force=True)
|
||||||
playersInGame.remove(uuid4)
|
playersInGame.remove(uuid4)
|
||||||
|
|
||||||
def countdown():
|
|
||||||
timeLeft = 11
|
|
||||||
timeLeft = timeLeft - 1
|
|
||||||
time.sleep(1)
|
|
||||||
if len(playersInGame) != maxPlayers:
|
|
||||||
timeLeft = 11
|
|
||||||
else:
|
|
||||||
countdown()
|
|
||||||
|
|
||||||
# Eventual more than one game can be played on website
|
# Eventual more than one game can be played on website
|
||||||
|
|
||||||
# @app.route('/game/<int:game_id>', methods=['GET', 'POST'])
|
# @app.route('/game/<int:game_id>', methods=['GET', 'POST'])
|
||||||
|
|||||||
@ -50,7 +50,7 @@ document.getElementsByClassName('play')[0].onclick = function startGame() {
|
|||||||
|
|
||||||
function getInitial() {
|
function getInitial() {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'http://127.0.0.1:5000/pregame',
|
url: 'http://localhost:5000/game',
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
async: false,
|
async: false,
|
||||||
// data: '',
|
// data: '',
|
||||||
@ -74,7 +74,7 @@ function serverTransfer(coordinate,team,turn,username) {
|
|||||||
username: username
|
username: username
|
||||||
};
|
};
|
||||||
// Sending Data
|
// Sending Data
|
||||||
$.ajax('http://127.0.0.1:5000/game', {
|
$.ajax('http://localhost:5000/game', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
type : "POST",
|
type : "POST",
|
||||||
data: JSON.stringify(move, null, '\t'),
|
data: JSON.stringify(move, null, '\t'),
|
||||||
@ -112,56 +112,53 @@ function serverTransfer(coordinate,team,turn,username) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function waitForPlayers(uuid4) {
|
function waitForPlayers(uuid4) {
|
||||||
repeat = true;
|
timer = setTimeout(function() {
|
||||||
while (repeat == true) {
|
// Sending "I'm here."
|
||||||
timer = setTimeout(function() {
|
$.ajax('http://localhost:5000/pregame', {
|
||||||
// Sending "I'm here."
|
method: 'POST',
|
||||||
$.ajax('http://127.0.0.1:5000/pregame', {
|
type : "POST",
|
||||||
method: 'POST',
|
data: JSON.stringify(uuid4, null, '\t'),
|
||||||
type : "POST",
|
async: false,
|
||||||
data: JSON.stringify(uuid4, null, '\t'),
|
dataType: "json",
|
||||||
async: false,
|
contentType: 'application/json;charset=UTF-8',
|
||||||
dataType: "json",
|
})
|
||||||
contentType: 'application/json;charset=UTF-8',
|
.then(
|
||||||
|
function success(data) {
|
||||||
success: function(data) {
|
numberOfPlayers = data["playersInGame"];
|
||||||
numberOfPlayers = data["playersInGame"];
|
if (numberOfPlayers == 1) {
|
||||||
if (numberOfPlayers == 1) {
|
countdown();
|
||||||
countdown();
|
// try catch delete table for visuals later.
|
||||||
repeat = false
|
} else {
|
||||||
// try catch delete table for visuals later.
|
waitForPlayers();
|
||||||
}
|
|
||||||
},
|
|
||||||
error: function(e) {
|
|
||||||
//called when there is an error
|
|
||||||
//(e.message);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(
|
|
||||||
// Repeat this function until 10 players are here.
|
|
||||||
function success (data) {
|
|
||||||
repeat = true
|
|
||||||
}
|
}
|
||||||
);
|
},
|
||||||
}, 3000);
|
function error(e) {
|
||||||
}
|
//called when there is an error
|
||||||
|
//(e.message);
|
||||||
|
}
|
||||||
|
// Repeat this function until 10 players are here.
|
||||||
|
);
|
||||||
|
}, 3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function countdown() {
|
function countdown() {
|
||||||
timer = setTimeout(function() {
|
timer = setTimeout(function() {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'http://127.0.0.1:5000/pregame',
|
url: 'http://localhost:5000/pregame',
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
async: false,
|
async: false,
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
timeLeft = data["timeLeft"];
|
timeLeft = data["timeLeft"];
|
||||||
|
console.log(data)
|
||||||
//MAKE VISUAL STUFF HERE
|
//MAKE VISUAL STUFF HERE
|
||||||
if(timeLeft == 0) {
|
if(timeLeft == 0) {
|
||||||
|
canMove = true;
|
||||||
createPlayer();
|
createPlayer();
|
||||||
autoScroll('start');
|
autoScroll('start');
|
||||||
document.onkeydown = movePlayer;
|
document.onkeydown = movePlayer;
|
||||||
}
|
} else {
|
||||||
countdown();
|
countdown();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
error: function(e) {
|
error: function(e) {
|
||||||
//called when there is an error
|
//called when there is an error
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user