Skip to content

Commit

Permalink
Fix mushroom count calculations when mushrooms are destroyed.
Browse files Browse the repository at this point in the history
  • Loading branch information
RandolphBurt committed Jul 26, 2013
1 parent b2f189f commit 28342b3
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions App/js/services/GameBoard.js
Expand Up @@ -24,11 +24,7 @@ gameApp.factory("GameBoard", function(GlobalSettings, Utils, GraphicsEngine) {

createMushroom: function (x, y) {
if (!this.map[y][x]) {
if (inPlayerArea(y, this.height)) {
this.mushroomsInPlayerArea++;
}

this.mushroomsOnScreen++;
this.incrementMushroomCount(y);
}

this.map[y][x] = 4;
Expand All @@ -41,9 +37,26 @@ gameApp.factory("GameBoard", function(GlobalSettings, Utils, GraphicsEngine) {
},

destroyMushroom: function(x, y) {
this.decrementMushroomCount(y);
this.map[y][x] = 0;
},

incrementMushroomCount: function(y) {
if (inPlayerArea(y, this.height)) {
this.mushroomsInPlayerArea++;
}

this.mushroomsOnScreen++;
},

decrementMushroomCount: function(y) {
if (inPlayerArea(y, this.height)) {
this.mushroomsInPlayerArea--;
}

this.mushroomsOnScreen--;
},

playerAllowedToMove: function(currentX, currentY, direction) {
var x = currentX;
var y = currentY;
Expand Down Expand Up @@ -79,6 +92,9 @@ gameApp.factory("GameBoard", function(GlobalSettings, Utils, GraphicsEngine) {
} else if (mushroomSpace > 0) {
this.map[y][x]--;
}
if (mushroomSpace !== 0 && this.map[y][x] === 0) {
this.decrementMushroomCount(y);
}
}

if (mushroomSpace > 0) {
Expand Down

0 comments on commit 28342b3

Please sign in to comment.