Skip to content

Commit

Permalink
Corrected tiles initialization and terminology
Browse files Browse the repository at this point in the history
  • Loading branch information
jperaltar committed Jan 25, 2016
1 parent 865a3b1 commit 2f32220
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
7 changes: 1 addition & 6 deletions Logic/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Game.prototype.nextTurn = function() {
this.tiles.popTile();
while (!canBePlaced(this.tiles.currentTile, this.board)){
console.warn ("Replacing the next tile (Couldn't be placed)");
this.tiles.queue.unshift(this.tiles.currentTile);
this.tiles.stack.unshift(this.tiles.currentTile);
this.tiles.popTile();
}
this.players.next();
Expand All @@ -48,9 +48,6 @@ Game.prototype.nextTurn = function() {
}
};




/*
* Check if a tile can be placed in a board
*/
Expand All @@ -63,5 +60,3 @@ var canBePlaced = function(tile, board){
});
return can;
}


17 changes: 10 additions & 7 deletions Logic/Tiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,24 +238,27 @@ Tile.prototype.turnTile = function(){
// TILES OBJECT //
/////////////////////////

var initTiles = function (queue) {
var initTiles = function (stack) {
var turns = 72;
var initialTileType = 19;
var startingTiles = JSON.parse(JSON.stringify(predefTiles));
while(queue.length < 72){
--startingTiles[initialTileType].total;
while(stack.length < turns-1){
var remainingTiles = startingTiles.filter(filterByTotal);
var Type = getRandomArbitrary(remainingTiles.length,0);
if(remainingTiles[Type].total !== 0){
--remainingTiles[Type].total;
var tile = new Tile(remainingTiles[Type].type, 0);
queue.push(tile);
stack.push(tile);
}else {
throw "No more units of the picked tile"
}
}
}

Tiles = function() {
this.queue = [];
initTiles(this.queue);
this.stack = [];
initTiles(this.stack);
this.currentTile = this.popTile();
}

Expand All @@ -276,8 +279,8 @@ var filterByTotal = function (obj) {
}

Tiles.prototype.popTile = function() {
if(this.queue.length > 0){
this.currentTile = this.queue.pop();
if(this.stack.length > 0){
this.currentTile = this.stack.pop();
if(this.currentTile == null){
throw "Popped null tile"
}
Expand Down

0 comments on commit 2f32220

Please sign in to comment.