visual fixes

This commit is contained in:
yamanq 2016-01-17 20:46:58 -05:00
parent 230124e9af
commit f308fb1a40
2 changed files with 277 additions and 278 deletions

View File

@ -9,7 +9,7 @@ color = 0
vertical = 0 vertical = 0
playersInGame = [] playersInGame = []
# Testing 1 Player for now # Testing 1 Player for now
maxPlayers = 1 maxPlayers = 2
timeLeft = 11.0 timeLeft = 11.0
# Renders client # Renders client

View File

@ -4,7 +4,6 @@ var username;
var playerTeam; var playerTeam;
var timer; var timer;
var type; var type;
var username;
var playerColor; var playerColor;
var claimColor; var claimColor;
var turn = 0; var turn = 0;
@ -12,6 +11,7 @@ var spectatorChoose = 1;
var spectatedUser; var spectatedUser;
var numberOfPlayers; var numberOfPlayers;
var canMove = false; var canMove = false;
// Colors // Colors
var playerColors = { var playerColors = {
"red": "#E62E2E", "red": "#E62E2E",
@ -20,7 +20,7 @@ var playerColors = {
var claimedColors = { var claimedColors = {
"red": "#FF9999", "red": "#FF9999",
"blue": "#9999FF" "blue": "#9999FF"
} };
document.getElementsByClassName('play')[0].onclick = function startGame() { document.getElementsByClassName('play')[0].onclick = function startGame() {
uuid4 = function() { uuid4 = function() {
@ -45,8 +45,7 @@ document.getElementsByClassName('play')[0].onclick = function startGame() {
// Update score before creating player so scoreboard starts at 0 // Update score before creating player so scoreboard starts at 0
updateScore(); updateScore();
waitForPlayers(username); waitForPlayers(username);
};
}
function getInitial() { function getInitial() {
$.ajax({ $.ajax({
@ -56,8 +55,8 @@ function getInitial() {
// data: '', // data: '',
success: function(data) { success: function(data) {
//called when successful //called when successful
playerCoordinate = data["coordinate"]; playerCoordinate = data.coordinate;
playerTeam = data["team"]; playerTeam = data.team;
}, },
error: function(e) { error: function(e) {
//called when there is an error //called when there is an error
@ -86,13 +85,13 @@ function serverTransfer(coordinate,team,turn,username) {
.then( .then(
function success(data) { function success(data) {
for (var user in data) { for (var user in data) {
if (data.hasOwnProperty(user) if (data.hasOwnProperty(user) &&
&& (user != username) (user != username) &&
&& (data[user].length > turn) (data[user].length > turn) &&
&& (data[user][turn][2] != "spectator") (data[user][turn][2] != "spectator")
) { ) {
if ((data[user].length > data[spectatedUser].length) if ((data[user].length > data[spectatedUser].length) &&
&& data[spectatedUser][turn][2] === "spectator") { data[spectatedUser][turn][2] === "spectator") {
spectatedUser = user; spectatedUser = user;
} }
var theMove = data[user][turn]; var theMove = data[user][turn];
@ -120,11 +119,11 @@ function waitForPlayers(uuid4) {
data: JSON.stringify(uuid4, null, '\t'), data: JSON.stringify(uuid4, null, '\t'),
async: false, async: false,
dataType: "json", dataType: "json",
contentType: 'application/json;charset=UTF-8', contentType: 'application/json;charset=UTF-8'
}) })
.then( .then(
function success(data) { function success(data) {
numberOfPlayers = data["playersInGame"]; numberOfPlayers = data.playersInGame;
if (numberOfPlayers == 1) { if (numberOfPlayers == 1) {
countdown(); countdown();
// try catch delete table for visuals later. // try catch delete table for visuals later.
@ -148,10 +147,10 @@ function countdown() {
type: 'GET', type: 'GET',
async: false, async: false,
success: function(data) { success: function(data) {
timeLeft = data["timeLeft"]; timeLeft = data.timeLeft;
console.log(data) console.log(data);
//MAKE VISUAL STUFF HERE //MAKE VISUAL STUFF HERE
if(timeLeft == 0) { if(timeLeft === 0) {
canMove = true; canMove = true;
createPlayer(); createPlayer();
autoScroll('start'); autoScroll('start');
@ -164,7 +163,7 @@ function countdown() {
//called when there is an error //called when there is an error
//(e.message); //(e.message);
} }
}) });
}, 750); //Prevent too many requests }, 750); //Prevent too many requests
} }
@ -173,7 +172,7 @@ function countdown() {
// Creation of Table // Creation of Table
function createTable() { function createTable() {
var body = document.body var body = document.body;
var tbl = document.createElement('table'); var tbl = document.createElement('table');
tbl.style.border = "1px solid black"; tbl.style.border = "1px solid black";
for(var i = 0; i < 20; i++) { for(var i = 0; i < 20; i++) {
@ -228,7 +227,7 @@ function updateOldTable(coordinate, team) {
otherPlayer = table.rows[coordinate[0]].cells[coordinate[1]]; otherPlayer = table.rows[coordinate[0]].cells[coordinate[1]];
otherPlayer.style.backgroundColor = claimedColors[team]; otherPlayer.style.backgroundColor = claimedColors[team];
otherPlayer.className = otherPlayer.className.replace("player ", ""); otherPlayer.className = otherPlayer.className.replace("player ", "");
otherPlayer.id = "" otherPlayer.id = "";
} }
function updateScore() { function updateScore() {
@ -256,10 +255,10 @@ function movement(x,y) {
timer = timer =
setTimeout(function() { setTimeout(function() {
try { try {
if (nextSquare == undefined if (nextSquare === undefined ||
|| nextSquare.className.includes('player') nextSquare.className.includes('player') ||
|| playerTeam === "spectator" playerTeam === "spectator" ||
|| nextSquare.className.includes(playerTeam)) { nextSquare.className.includes(playerTeam)) {
killPlayer(playerCoordinate, playerTeam); killPlayer(playerCoordinate, playerTeam);
} }
else { else {
@ -301,11 +300,11 @@ function movePlayer(e) {
clearTimeout(timer); clearTimeout(timer);
movement(0,1); movement(0,1);
} else if (e.keyCode === 37 && type != "left") { } else if (e.keyCode === 37 && type != "left") {
type = "left" type = "left";
clearTimeout(timer); clearTimeout(timer);
movement(-1,0); movement(-1,0);
} else if (e.keyCode === 39 && type != "right") { } else if (e.keyCode === 39 && type != "right") {
type = "right" type = "right";
clearTimeout(timer); clearTimeout(timer);
movement(1,0); movement(1,0);
} }
@ -340,7 +339,7 @@ function spectatorMode() {
spectatorType = 'spectatorFull'; spectatorType = 'spectatorFull';
spectatorFull(); spectatorFull();
} }
} };
} }
function spectatorFull() { function spectatorFull() {
@ -360,7 +359,7 @@ function autoScroll(type) {
} else if (type == "spectator") { } else if (type == "spectator") {
$('body').scrollTo(document.getElementById(spectatedUser), 100, {offset: {top: center[0] , left: center[1]} }); $('body').scrollTo(document.getElementById(spectatedUser), 100, {offset: {top: center[0] , left: center[1]} });
} else { } else {
alert("Broken?") alert("Broken?");
// $('body').scrollTo(document.getElementById(username), 100, {offset: {top: center[0] , left: center[1]} }); // $('body').scrollTo(document.getElementById(username), 100, {offset: {top: center[0] , left: center[1]} });
} }
} }