function Game(stage,xocolor,doc,datastore,activity){ this.margin = 0; //These must be even this.gridwidth = 10; this.gridheight = 6; this.circleswidth = 0; this.circlesheight = 0; this.radius = 0; console.log(xocolor); this.verticalline = null; this.horizontalline = null; this.mode = null; this.dotsarr = []; this.buddy = ["#FFFFFF","#000000",xocolor.fill,xocolor.stroke]; this.rainbow = ['#FFFFFF','#000000','#FF0000','#FF8000','#FFFF00','#00FF00','#00FFFF','#0000FF','#FF00FF']; this.colours = this.buddy; this.robot = false; this.gameOver = false; //0 = horizontal, 1 = vertical, 2 = bilateral //Helper functions this.radiusFromX = function(){ this.margin = 1/50*stage.canvas.width; var diameter = (stage.canvas.width-(this.margin*(this.gridwidth+1)))/this.gridwidth; var radius = diameter/2; return radius; } this.radiusFromY = function(){ this.margin = 1/50*stage.canvas.height; var diameter = (stage.canvas.height-(this.margin*(this.gridheight+1)))/this.gridheight; var radius = diameter/2; return radius; } this.canDoFromX = function(){ var rad = this.radiusFromX(); this.margin = 1/50*stage.canvas.width; if ((((rad*2)*this.gridheight)+(this.margin*(this.gridheight+1)))<=stage.canvas.height){ return rad; } else { return false; } } this.removeLines = function(){ if (this.verticalline!=null){ stage.removeChild(this.verticalline); this.verticalline = null; } if (this.horizontalline!=null){ stage.removeChild(this.horizontalline); this.horizontalline = null; } } this.addVerticalLine = function(){ this.verticalline = new createjs.Shape(); this.verticalline.graphics.beginFill("#000000").drawRect(0,0,this.margin/3,this.circlesheight-this.margin); this.verticalline.x = stage.canvas.width/2-this.margin/6; this.verticalline.y = this.margin/2; stage.addChild(this.verticalline); } this.addHorizontalLine = function(){ this.horizontalline = new createjs.Shape(); this.horizontalline.graphics.beginFill("#000000").drawRect(0,0,this.circleswidth-this.margin,this.margin/3); this.horizontalline.x = (stage.canvas.width-this.circleswidth)/2+this.margin/2; this.horizontalline.y = this.circlesheight/2-this.margin/6; stage.addChild(this.horizontalline); } //Game Inits this.initHorizontalGame = function(colours){ if (colours === undefined) colours=false; this.gameOver = false; this.removeLines(); this.addVerticalLine(); this.mode = 0; if (colours==false){ this.initDots(); } else { this.initDotsFromSave(colours); } } this.initVerticalGame = function(colours){ if (colours === undefined) colours=false; this.gameOver = false; this.removeLines(); this.addHorizontalLine(); this.mode = 1; if (colours==false){ this.initDots(); } else { this.initDotsFromSave(colours); } } this.initBilateralGame = function(colours){ if (colours === undefined) colours=false; this.gameOver = false; this.removeLines(); this.addHorizontalLine(); this.addVerticalLine(); this.mode = 2; if (colours==false){ this.initDots(); } else { this.initDotsFromSave(colours); } } this.setBuddyStyle = function(){ var buddyicon = doc.getElementById("buddy-button"); buddyicon.style.backgroundColor = "#808080"; var rainbowicon = doc.getElementById("rainbow-button"); rainbowicon.removeAttribute("style"); } this.initBuddy = function(){ this.setBuddyStyle(); this.colours = this.buddy; switch(this.mode) { case 0: this.initHorizontalGame(); break; case 1: this.initVerticalGame(); break; case 2: this.initBilateralGame(); break; } } this.setRainbowStyle = function(){ var buddyicon = doc.getElementById("buddy-button"); buddyicon.removeAttribute("style"); var rainbowicon = doc.getElementById("rainbow-button"); rainbowicon.style.backgroundColor = "#808080"; } this.initRainbow = function(){ this.setRainbowStyle(); this.colours = this.rainbow; switch(this.mode) { case 0: this.initHorizontalGame(); break; case 1: this.initVerticalGame(); break; case 2: this.initBilateralGame(); break; } } this.initDots = function(){ this.dotsarr = []; var temparr = []; var incr = (this.radius*2+this.margin); var xp = (stage.canvas.width-this.circleswidth)/2+this.margin; var yp = this.margin; for (var x = 0; x