From 2c922fa4c1716e51f161bb1982d906b006b0259b Mon Sep 17 00:00:00 2001 From: yamanq Date: Tue, 25 Aug 2015 22:32:21 -0400 Subject: [PATCH] added backend team and coordinate assignment --- clashingcomrades/server.py | 19 +++++++++++++++---- clashingcomrades/static/main.js | 13 +++++++------ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/clashingcomrades/server.py b/clashingcomrades/server.py index 89093e2..4c03170 100644 --- a/clashingcomrades/server.py +++ b/clashingcomrades/server.py @@ -4,7 +4,8 @@ app = Flask(__name__) # Since only one game for now, this is the object that will hold the data for the game game = {} - +color = 0 +coloumn = 0 # Renders client @app.route("/") @@ -19,19 +20,29 @@ def update_game(): # Eventually will be used for initial team and coordinate # Not currently being used anywhere if request.method == 'GET': - return jsonify(game) + global color + global coloumn + color = color + 1 + team = ["red", "blue"][color % 2] + row = 10 + color % 2 + coloumn = coloumn + 1 + answer = { + "team": team, + "coordinate": [row, coloumn] + } + + return jsonify(answer) # What to do when the Client tells the server something if request.method == 'POST': - print "asdabsb" # Define the data given by client playerStatus = request.get_json(force=True) # If the username that the player sent is already defined in game if playerStatus["username"] in game: game[playerStatus["username"]].append([playerStatus["turn"], playerStatus["coordinate"], playerStatus["team"]]) else: - print "yesolkgahjewoiagj" game[playerStatus["username"]] = [[playerStatus["turn"], playerStatus["coordinate"], playerStatus["team"]]] + # Return the game with the information you added, in addition to everyone else return jsonify(game) diff --git a/clashingcomrades/static/main.js b/clashingcomrades/static/main.js index fe8e789..67e7fec 100644 --- a/clashingcomrades/static/main.js +++ b/clashingcomrades/static/main.js @@ -33,7 +33,7 @@ document.getElementsByClassName('play')[0].onclick = function startGame() { //********************* // TODO Get from server //********************* - playerCoordinate = [19,0]; + playerCoordinate = [0,0]; playerTeam = "blue"; // TODO IP Handling, most likely not necessary @@ -106,7 +106,7 @@ function createTable() { tbl.style.border = "1px solid black"; for(var i = 0; i < 20; i++) { var tr = tbl.insertRow(); - for(var j = 0; j < 30; j++) { + for(var j = 0; j < 20; j++) { var td = tr.insertCell(); } } @@ -205,7 +205,7 @@ function movement(x,y) { serverTransfer(playerCoordinate,playerTeam,turn,username); } turn = turn + 1; - autoScroll(); + autoScroll('spectator'); movement(x,y); } catch(err) { @@ -261,11 +261,12 @@ function autoScroll(type) { window.innerHeight / -2, window.innerWidth / -2 ]; - if(type === 'start') { + if(type == 'start') { $('body').scrollTo(document.getElementById(username), 0, {offset: {top: center[0] , left: center[1]} }); - } else if (playerTeam == "spectator") { + } else if (type == "spectator") { $('body').scrollTo(document.getElementById(spectatedUser), 100, {offset: {top: center[0] , left: center[1]} }); } else { - $('body').scrollTo(document.getElementById(username), 100, {offset: {top: center[0] , left: center[1]} }); + alert("Broken?") + // $('body').scrollTo(document.getElementById(username), 100, {offset: {top: center[0] , left: center[1]} }); } } \ No newline at end of file