fixed many bugs, memory leak remains

This commit is contained in:
yamanq 2016-01-17 18:50:48 -05:00
parent 2a93fa7fc0
commit ac4492e9a9
3 changed files with 51 additions and 38 deletions

View File

@ -0,0 +1,2 @@
# Coexistence
A game coded in the script of java.

View File

@ -1,6 +1,6 @@
from flask import Flask from flask import Flask
from flask import render_template, jsonify, request from flask import render_template, jsonify, request
from time import sleep import time
app = Flask(__name__) app = Flask(__name__)
# Since only one game for now, this is the object that will hold the data for the game # Since only one game for now, this is the object that will hold the data for the game
@ -8,7 +8,8 @@ game = {}
color = 0 color = 0
vertical = 0 vertical = 0
playersInGame = [] playersInGame = []
maxPlayers = 10 # Testing 1 Player for now
maxPlayers = 1
timeLeft = 11 timeLeft = 11
# Renders client # Renders client
@ -50,28 +51,32 @@ 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','COUNT']) @app.route('/pregame', methods=['GET','POST','EXIT'])
def update_players(): def update_players():
if method.request == 'GET': if request.method == 'GET':
countdown() countdown()
return timeLeft toReturn = {}
toReturn["timeLeft"] = timeLeft
return jsonify(toReturn)
if method.request == 'POST': if request.method == '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)
# If this client has not already registered with the server, register. # If this client has not already registered with the server, register.
if uuid4 not in playersInGame: if not uuid4 in playersInGame:
playersInGame.append(uuid4) playersInGame.append(uuid4)
toReturn = {}
toReturn["playersInGame"] = len(playersInGame)
return jsonify(toReturn)
return jsonify(len(playersInGame)) if request.method == '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)
def countdown(): def countdown():
timeLeft = 11
timeLeft = timeLeft - 1 timeLeft = timeLeft - 1
time.sleep(1) time.sleep(1)
if len(playersInGame) != maxPlayers: if len(playersInGame) != maxPlayers:

View File

@ -44,7 +44,7 @@ document.getElementsByClassName('play')[0].onclick = function startGame() {
createTable(); createTable();
// Update score before creating player so scoreboard starts at 0 // Update score before creating player so scoreboard starts at 0
updateScore(); updateScore();
waitForPlayers(); waitForPlayers(username);
} }
@ -112,33 +112,39 @@ function serverTransfer(coordinate,team,turn,username) {
} }
function waitForPlayers(uuid4) { function waitForPlayers(uuid4) {
timer = setTimeout(function() { repeat = true;
// Sending "I'm here." while (repeat == true) {
$.ajax('http://127.0.0.1:5000/pregame', { timer = setTimeout(function() {
method: 'POST', // Sending "I'm here."
type : "POST", $.ajax('http://127.0.0.1:5000/pregame', {
data: JSON.stringify(uuid4, null, '\t'), method: 'POST',
async: false, type : "POST",
dataType: "json", data: JSON.stringify(uuid4, null, '\t'),
contentType: 'application/json;charset=UTF-8' async: false,
dataType: "json",
contentType: 'application/json;charset=UTF-8',
success: function(data) { success: function(data) {
numberOfPlayers = data; numberOfPlayers = data["playersInGame"];
if (numberOfPlayers == '10') { if (numberOfPlayers == 1) {
countdown(); countdown();
// try catch delete table for visuals later. repeat = false
} // try catch delete table for visuals later.
}, }
error: function(e) { },
//called when there is an error error: function(e) {
//(e.message); //called when there is an error
} //(e.message);
}) }
.then( })
// Repeat this function until 10 players are here. .then(
waitForPlayers(); // Repeat this function until 10 players are here.
); function success (data) {
}, 3000); repeat = true
}
);
}, 3000);
}
} }
function countdown() { function countdown() {
@ -148,7 +154,7 @@ function countdown() {
type: 'GET', type: 'GET',
async: false, async: false,
success: function(data) { success: function(data) {
timeLeft = data; timeLeft = data["timeLeft"];
//MAKE VISUAL STUFF HERE //MAKE VISUAL STUFF HERE
if(timeLeft == 0) { if(timeLeft == 0) {
createPlayer(); createPlayer();