From 923703da42256d3249efb04c076b724d4356bc7c Mon Sep 17 00:00:00 2001 From: "Valeriano A.R" Date: Sun, 13 Sep 2015 10:40:32 +0200 Subject: [PATCH] Scoreboard --- code/CandyFucker.js | 18 ++++++++++++------ index.html | 13 +++++++++++-- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/code/CandyFucker.js b/code/CandyFucker.js index 5118970..4c3be53 100644 --- a/code/CandyFucker.js +++ b/code/CandyFucker.js @@ -39,19 +39,21 @@ CandyEntity.prototype = { // // CandyFucker // -var CandyFucker = function(idScreen){ +var CandyFucker = function(idScreen, idInfoDisplay){ var self = this; this.GameScreen = new GameScreen(idScreen, this.Init.bind(this), this.Proc.bind(this), this.End.bind(this) ); + this.InfoDisplay = document.getElementById(idInfoDisplay); this.Grid = null; this.GridOffset = {X: 0, Y: 0}; this.CandyTypes = ["Red", "Blue", "Cyan", "Green", "Yellow"]; this.Locked = false; this.Falling = false; this.Changed = false; + this.Score = 0; window.Images.LoadImages( [ @@ -70,21 +72,19 @@ var CandyFucker = function(idScreen){ CandyFucker.prototype = { Init: function(gameScreen){ this.BuildGrid(15, 15); + this.UpdateInfoDisplay(); }, Proc: function(gameScreen){ if(this.Locked){ if(this.Falling){ if(!this.CandyFall()){ this.Falling = false; - console.log("Stoped"); } }else{ if(this.ApplyRules()){ this.Falling = true; - console.log("Falling"); }else{ this.Locked = false; - console.log("Stoped"); } } }else{ @@ -92,13 +92,15 @@ CandyFucker.prototype = { if(this.ApplyRules()){ this.Locked = true; this.Falling = true; - console.log("Falling"); } } } this.Changed = false; }, End: function(gameScreen){ }, + UpdateInfoDisplay: function(){ + this.InfoDisplay.innerHTML = "Score: " + this.Score; + }, GetCandy: function(x, y){ return this.Grid[y][x]; }, @@ -260,7 +262,11 @@ CandyFucker.prototype = { var verticalRuns = this.ScanVerticalRuns(); var runs = horizontalRuns.concat(verticalRuns); var points = this.RemoveRuns(runs); - console.log(points) + if(points>0){ + this.Score += points; + this.UpdateInfoDisplay(); + console.log("Score: +" + points); + } return (runs.length>0); }, CandyFall: function(){ diff --git a/index.html b/index.html index b141d7a..f562952 100644 --- a/index.html +++ b/index.html @@ -18,11 +18,19 @@ text-align: center; height: 100%; } + #infoDisplay{ + display:block; + height:20px; + width: 100%; + line-height: 20px; + font-size: 15px; + color: rgb(220,220,220); + } #screenContainer { display: block; position: relative; width: 100%; - height: 100%; + height: calc(100% - 20px); overflow: hidden; } #screen { @@ -37,13 +45,14 @@ +