cleaned up javascript
This commit is contained in:
parent
a19a35db79
commit
2fa13fc69b
@ -15,28 +15,25 @@ var blueClaimed = "#9999FF";
|
|||||||
|
|
||||||
|
|
||||||
document.getElementsByClassName('play')[0].onclick = function startGame() {
|
document.getElementsByClassName('play')[0].onclick = function startGame() {
|
||||||
/* get this from server later */
|
|
||||||
|
//*********************
|
||||||
|
// TODO Get from server
|
||||||
|
//*********************
|
||||||
coordinate = [0,0];
|
coordinate = [0,0];
|
||||||
team = "red";
|
team = "red";
|
||||||
/* end */
|
|
||||||
if(team === "red") {
|
if (team === "red") {
|
||||||
playerColor = redPlayer;
|
playerColor = redPlayer;
|
||||||
claimColor = redClaimed;
|
claimColor = redClaimed;
|
||||||
} else {
|
} else if (team === "blue") {
|
||||||
playerColor = bluePlayer;
|
playerColor = bluePlayer;
|
||||||
claimColor = blueClaimed;
|
claimColor = blueClaimed;
|
||||||
|
} else {
|
||||||
|
playerColor = null;
|
||||||
|
claimColor = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Server Stuff, not necessary now.
|
// TODO IP Handling, most likely not necessary
|
||||||
// var ip = document.getElementsByClassName('ip')[0].value;
|
|
||||||
// console.log(ip);
|
|
||||||
// console.log(username);
|
|
||||||
// if (ip.match(/[a-z]/i) /* && list of ips */ || ip === "") {
|
|
||||||
// alert("That wasn't a valid ip, so we picked a random one for you!");
|
|
||||||
// /*
|
|
||||||
// ip = retrieveServerIPs('array')[Math.floor((Math.random() * retrieveServerIPs('amount')) + 1)];
|
|
||||||
// */
|
|
||||||
// }
|
|
||||||
|
|
||||||
var element = document.getElementById("login");
|
var element = document.getElementById("login");
|
||||||
element.parentNode.removeChild(element);
|
element.parentNode.removeChild(element);
|
||||||
@ -49,13 +46,7 @@ document.getElementsByClassName('play')[0].onclick = function startGame() {
|
|||||||
updateScore();
|
updateScore();
|
||||||
tableCreate();
|
tableCreate();
|
||||||
createPlayer();
|
createPlayer();
|
||||||
/*
|
document.onkeydown = movePlayer;
|
||||||
connectServer(ip);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
function getPlayers() {
|
|
||||||
/******* Add recursive calling for: update other players, scoreboard updating *************/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function serverTransfer(coordinate,team,turn) {
|
function serverTransfer(coordinate,team,turn) {
|
||||||
@ -64,6 +55,7 @@ function serverTransfer(coordinate,team,turn) {
|
|||||||
team: team,
|
team: team,
|
||||||
turn: turn
|
turn: turn
|
||||||
};
|
};
|
||||||
|
// For debugging
|
||||||
console.log(move);
|
console.log(move);
|
||||||
$.ajax('http://127.0.0.1:5000/game', {
|
$.ajax('http://127.0.0.1:5000/game', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@ -74,7 +66,9 @@ function serverTransfer(coordinate,team,turn) {
|
|||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
function success(data) {
|
function success(data) {
|
||||||
//Kenny Do it
|
//*******************************
|
||||||
|
// TODO Use moves given by server
|
||||||
|
//*******************************
|
||||||
console.log(data);
|
console.log(data);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -86,9 +80,8 @@ function serverTransfer(coordinate,team,turn) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*********************/
|
|
||||||
/* Creation of Table */
|
// Creation of Table
|
||||||
/*********************/
|
|
||||||
|
|
||||||
function tableCreate() {
|
function tableCreate() {
|
||||||
var body = document.body
|
var body = document.body
|
||||||
@ -105,9 +98,9 @@ function tableCreate() {
|
|||||||
table = document.getElementsByTagName('table')[0];
|
table = document.getElementsByTagName('table')[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************/
|
|
||||||
/* Creation of Player */
|
|
||||||
/**********************/
|
// Creation of Player
|
||||||
|
|
||||||
function createPlayer() {
|
function createPlayer() {
|
||||||
table.rows[coordinate[0]].cells[coordinate[1]].style.backgroundColor = playerColor;
|
table.rows[coordinate[0]].cells[coordinate[1]].style.backgroundColor = playerColor;
|
||||||
@ -115,7 +108,6 @@ function createPlayer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Put this stuff server side to prevent H4X (Arav) later */
|
|
||||||
function movement(x,y) {
|
function movement(x,y) {
|
||||||
timer =
|
timer =
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
@ -132,7 +124,7 @@ function movement(x,y) {
|
|||||||
document.getElementsByClassName('player')[0].style.backgroundColor = playerColor;
|
document.getElementsByClassName('player')[0].style.backgroundColor = playerColor;
|
||||||
table.rows[coordinate[0]].cells[coordinate[1]].style.backgroundColor = claimColor;
|
table.rows[coordinate[0]].cells[coordinate[1]].style.backgroundColor = claimColor;
|
||||||
coordinate = [coordinate[0] + y, coordinate[1] + x];
|
coordinate = [coordinate[0] + y, coordinate[1] + x];
|
||||||
updateScore(); // remove this after server updating
|
updateScore();
|
||||||
serverTransfer(coordinate,team,turn);
|
serverTransfer(coordinate,team,turn);
|
||||||
turn = turn + 1;
|
turn = turn + 1;
|
||||||
movement(x,y);
|
movement(x,y);
|
||||||
@ -142,7 +134,6 @@ function movement(x,y) {
|
|||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
document.onkeydown = movePlayer;
|
|
||||||
|
|
||||||
function movePlayer(e) {
|
function movePlayer(e) {
|
||||||
|
|
||||||
@ -170,12 +161,14 @@ function movePlayer(e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function spectatorMode() {
|
function spectatorMode() {
|
||||||
|
//***************************
|
||||||
|
// TODO Finish Spectator Mode
|
||||||
|
//***************************
|
||||||
coordinate = null;
|
coordinate = null;
|
||||||
/* once in server side add stuff about following players */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateScore() {
|
function updateScore() {
|
||||||
var score =
|
var score = [
|
||||||
[
|
|
||||||
document.getElementsByClassName('red').length,
|
document.getElementsByClassName('red').length,
|
||||||
document.getElementsByClassName('blue').length
|
document.getElementsByClassName('blue').length
|
||||||
];
|
];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user