got previous commit to working condition
This commit is contained in:
parent
f308fb1a40
commit
a233a5542e
@ -10,7 +10,7 @@ vertical = 0
|
||||
playersInGame = []
|
||||
# Testing 1 Player for now
|
||||
maxPlayers = 2
|
||||
timeLeft = 11.0
|
||||
initialTime = 0
|
||||
|
||||
# Renders client
|
||||
@app.route("/")
|
||||
@ -53,13 +53,14 @@ def update_game():
|
||||
|
||||
@app.route('/pregame', methods=['GET','POST','EXIT'])
|
||||
def update_players():
|
||||
global timeLeft
|
||||
global initialTime
|
||||
global maxPlayers
|
||||
|
||||
if request.method == 'GET':
|
||||
before = time.clock()
|
||||
time.sleep(0.99)
|
||||
after = time.clock()
|
||||
timeTaken = after - before
|
||||
timeLeft -= timeTaken
|
||||
after = time.time()
|
||||
timeSince = after - initialTime
|
||||
timeLeft = 10 - timeSince
|
||||
print timeLeft
|
||||
|
||||
toReturn = {}
|
||||
toReturn["timeLeft"] = int(timeLeft)
|
||||
@ -67,18 +68,28 @@ def update_players():
|
||||
|
||||
if request.method == 'POST':
|
||||
#Define the data given by client.
|
||||
uuid4 = request.get_json(force=True)
|
||||
username = request.get_json(force=True)
|
||||
print username
|
||||
|
||||
# If this client has not already registered with the server, register.
|
||||
if not uuid4 in playersInGame:
|
||||
playersInGame.append(uuid4)
|
||||
if not username["username"] in playersInGame:
|
||||
playersInGame.append(username["username"])
|
||||
|
||||
numberofplayers = len(playersInGame)
|
||||
if numberofplayers == maxPlayers:
|
||||
initialTime = time.time()
|
||||
|
||||
print numberofplayers
|
||||
|
||||
toReturn = {}
|
||||
toReturn["playersInGame"] = len(playersInGame)
|
||||
toReturn["playersInGame"] = numberofplayers
|
||||
|
||||
return jsonify(toReturn)
|
||||
|
||||
if request.method == 'EXIT':
|
||||
#Define the data given by client.
|
||||
uuid4 = request.get_json(force=True)
|
||||
playersInGame.remove(uuid4)
|
||||
# if request.method == 'EXIT':
|
||||
# #Define the data given by client.
|
||||
# uuid4 = request.get_json(force=True)
|
||||
# playersInGame.remove(uuid4)
|
||||
|
||||
# Eventual more than one game can be played on website
|
||||
|
||||
@ -92,4 +103,4 @@ def update_players():
|
||||
# return jsonify(games[game_id])
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True)
|
||||
app.run(host='0.0.0.0')
|
||||
|
||||
@ -11,6 +11,7 @@ var spectatorChoose = 1;
|
||||
var spectatedUser;
|
||||
var numberOfPlayers;
|
||||
var canMove = false;
|
||||
var serverurl = "http://68.56.19.11:5000"
|
||||
|
||||
// Colors
|
||||
var playerColors = {
|
||||
@ -49,9 +50,8 @@ document.getElementsByClassName('play')[0].onclick = function startGame() {
|
||||
|
||||
function getInitial() {
|
||||
$.ajax({
|
||||
url: 'http://localhost:5000/game',
|
||||
url: serverurl + '/game',
|
||||
type: 'GET',
|
||||
async: false,
|
||||
// data: '',
|
||||
success: function(data) {
|
||||
//called when successful
|
||||
@ -73,11 +73,10 @@ function serverTransfer(coordinate,team,turn,username) {
|
||||
username: username
|
||||
};
|
||||
// Sending Data
|
||||
$.ajax('http://localhost:5000/game', {
|
||||
$.ajax(serverurl + '/game', {
|
||||
method: 'POST',
|
||||
type : "POST",
|
||||
data: JSON.stringify(move, null, '\t'),
|
||||
async: false,
|
||||
dataType: "json",
|
||||
contentType: 'application/json;charset=UTF-8'
|
||||
})
|
||||
@ -110,25 +109,28 @@ function serverTransfer(coordinate,team,turn,username) {
|
||||
);
|
||||
}
|
||||
|
||||
function waitForPlayers(uuid4) {
|
||||
function waitForPlayers(username) {
|
||||
timer = setTimeout(function() {
|
||||
// Sending "I'm here."
|
||||
$.ajax('http://localhost:5000/pregame', {
|
||||
var sending = {
|
||||
username: username
|
||||
};
|
||||
|
||||
$.ajax(serverurl + '/pregame', {
|
||||
method: 'POST',
|
||||
type : "POST",
|
||||
data: JSON.stringify(uuid4, null, '\t'),
|
||||
async: false,
|
||||
data: JSON.stringify(sending, null, '\t'),
|
||||
dataType: "json",
|
||||
contentType: 'application/json;charset=UTF-8'
|
||||
})
|
||||
.then(
|
||||
function success(data) {
|
||||
numberOfPlayers = data.playersInGame;
|
||||
if (numberOfPlayers == 1) {
|
||||
if (numberOfPlayers == 2) {
|
||||
countdown();
|
||||
// try catch delete table for visuals later.
|
||||
} else {
|
||||
waitForPlayers();
|
||||
waitForPlayers(username);
|
||||
}
|
||||
},
|
||||
function error(e) {
|
||||
@ -143,9 +145,8 @@ function waitForPlayers(uuid4) {
|
||||
function countdown() {
|
||||
timer = setTimeout(function() {
|
||||
$.ajax({
|
||||
url: 'http://localhost:5000/pregame',
|
||||
url: serverurl + '/pregame',
|
||||
type: 'GET',
|
||||
async: false,
|
||||
success: function(data) {
|
||||
timeLeft = data.timeLeft;
|
||||
console.log(data);
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="chrome=1">
|
||||
<title>Coexistence</title>
|
||||
<link rel="icon" href="{{ url_for('static', filename='favicon.png')}}">
|
||||
<link rel="icon" href="{{ url_for('static', filename='resources/ico/favicon.png')}}">
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='main.css') }}">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
||||
</head>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user