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 render_template, jsonify, request
from time import sleep
import time
app = Flask(__name__)
# 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
vertical = 0
playersInGame = []
maxPlayers = 10
# Testing 1 Player for now
maxPlayers = 1
timeLeft = 11
# Renders client
@ -50,28 +51,32 @@ def update_game():
# Return the game with the information you added, in addition to everyone else
return jsonify(game)
@app.route('/pregame', methods=['GET','POST','COUNT'])
@app.route('/pregame', methods=['GET','POST','EXIT'])
def update_players():
if method.request == 'GET':
if request.method == 'GET':
countdown()
return timeLeft
toReturn = {}
toReturn["timeLeft"] = timeLeft
return jsonify(toReturn)
if method.request == 'POST':
if request.method == 'POST':
#Define the data given by client.
uuid4 = request.get_json(force=True)
# If this client has not already registered with the server, register.
if uuid4 not in playersInGame:
if not uuid4 in playersInGame:
playersInGame.append(uuid4)
return jsonify(len(playersInGame))
toReturn = {}
toReturn["playersInGame"] = len(playersInGame)
return jsonify(toReturn)
if method.request == 'EXIT':
if request.method == 'EXIT':
#Define the data given by client.
uuid4 = request.get_json(force=True)
playersInGame.remove(uuid4)
def countdown():
timeLeft = 11
timeLeft = timeLeft - 1
time.sleep(1)
if len(playersInGame) != maxPlayers:

View File

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