added backend team and coordinate assignment

This commit is contained in:
yamanq 2015-08-25 22:32:21 -04:00
parent 823b102139
commit 2c922fa4c1
2 changed files with 22 additions and 10 deletions

View File

@ -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)

View File

@ -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]} });
}
}