Scoreboard

This commit is contained in:
2015-09-13 10:40:32 +02:00
parent dd80e50aee
commit 923703da42
2 changed files with 23 additions and 8 deletions

View File

@@ -39,19 +39,21 @@ CandyEntity.prototype = {
// //
// CandyFucker // CandyFucker
// //
var CandyFucker = function(idScreen){ var CandyFucker = function(idScreen, idInfoDisplay){
var self = this; var self = this;
this.GameScreen = new GameScreen(idScreen, this.GameScreen = new GameScreen(idScreen,
this.Init.bind(this), this.Init.bind(this),
this.Proc.bind(this), this.Proc.bind(this),
this.End.bind(this) this.End.bind(this)
); );
this.InfoDisplay = document.getElementById(idInfoDisplay);
this.Grid = null; this.Grid = null;
this.GridOffset = {X: 0, Y: 0}; this.GridOffset = {X: 0, Y: 0};
this.CandyTypes = ["Red", "Blue", "Cyan", "Green", "Yellow"]; this.CandyTypes = ["Red", "Blue", "Cyan", "Green", "Yellow"];
this.Locked = false; this.Locked = false;
this.Falling = false; this.Falling = false;
this.Changed = false; this.Changed = false;
this.Score = 0;
window.Images.LoadImages( window.Images.LoadImages(
[ [
@@ -70,21 +72,19 @@ var CandyFucker = function(idScreen){
CandyFucker.prototype = { CandyFucker.prototype = {
Init: function(gameScreen){ Init: function(gameScreen){
this.BuildGrid(15, 15); this.BuildGrid(15, 15);
this.UpdateInfoDisplay();
}, },
Proc: function(gameScreen){ Proc: function(gameScreen){
if(this.Locked){ if(this.Locked){
if(this.Falling){ if(this.Falling){
if(!this.CandyFall()){ if(!this.CandyFall()){
this.Falling = false; this.Falling = false;
console.log("Stoped");
} }
}else{ }else{
if(this.ApplyRules()){ if(this.ApplyRules()){
this.Falling = true; this.Falling = true;
console.log("Falling");
}else{ }else{
this.Locked = false; this.Locked = false;
console.log("Stoped");
} }
} }
}else{ }else{
@@ -92,13 +92,15 @@ CandyFucker.prototype = {
if(this.ApplyRules()){ if(this.ApplyRules()){
this.Locked = true; this.Locked = true;
this.Falling = true; this.Falling = true;
console.log("Falling");
} }
} }
} }
this.Changed = false; this.Changed = false;
}, },
End: function(gameScreen){ }, End: function(gameScreen){ },
UpdateInfoDisplay: function(){
this.InfoDisplay.innerHTML = "Score: " + this.Score;
},
GetCandy: function(x, y){ GetCandy: function(x, y){
return this.Grid[y][x]; return this.Grid[y][x];
}, },
@@ -260,7 +262,11 @@ CandyFucker.prototype = {
var verticalRuns = this.ScanVerticalRuns(); var verticalRuns = this.ScanVerticalRuns();
var runs = horizontalRuns.concat(verticalRuns); var runs = horizontalRuns.concat(verticalRuns);
var points = this.RemoveRuns(runs); var points = this.RemoveRuns(runs);
console.log(points) if(points>0){
this.Score += points;
this.UpdateInfoDisplay();
console.log("Score: +" + points);
}
return (runs.length>0); return (runs.length>0);
}, },
CandyFall: function(){ CandyFall: function(){

View File

@@ -18,11 +18,19 @@
text-align: center; text-align: center;
height: 100%; height: 100%;
} }
#infoDisplay{
display:block;
height:20px;
width: 100%;
line-height: 20px;
font-size: 15px;
color: rgb(220,220,220);
}
#screenContainer { #screenContainer {
display: block; display: block;
position: relative; position: relative;
width: 100%; width: 100%;
height: 100%; height: calc(100% - 20px);
overflow: hidden; overflow: hidden;
} }
#screen { #screen {
@@ -37,13 +45,14 @@
</style> </style>
</head> </head>
<body> <body>
<div id="infoDisplay"></div>
<div id="screenContainer"> <div id="screenContainer">
<canvas id="screen" width="512" height="512" /> <canvas id="screen" width="512" height="512" />
</div> </div>
<script src="code/GameLib.js"></script> <script src="code/GameLib.js"></script>
<script src="code/CandyFucker.js"></script> <script src="code/CandyFucker.js"></script>
<script> <script>
new CandyFucker("screen"); new CandyFucker("screen", "infoDisplay");
</script> </script>
</body> </body>
</html> </html>