Skip to content

Commit

Permalink
Added jsHint for assessment
Browse files Browse the repository at this point in the history
  • Loading branch information
acareaga committed Feb 17, 2016
1 parent 66c06e7 commit e54b31a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 35 deletions.
10 changes: 5 additions & 5 deletions lib/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@ Block.prototype.draw = function(context) {
Block.prototype.move = function (xOffset, yOffset) {
this.x += xOffset;
this.y += yOffset;
return this
return this;
};

Block.prototype.onBottom = function ( xOffset, yOffset){
if (this.board.findBlockOnBoard(this.x + xOffset, this.y + yOffset)) { return true }
if (this.board.findBlockOnBoard(this.x + xOffset, this.y + yOffset)) { return true; }
};

Block.prototype.inactive = function() {
return this.active = false;
};

Block.prototype.canMove = function(blockIsAt, isThereA){
if (this.inactive) { return this.active = false }
if (this.inactive) { return this.active = false; }
// check conditionals below to confirm falling block moves correctly
if (this.blockisAt) { return this.inactive }
if (this.isThereA) { return false }
if (this.blockisAt) { return this.inactive; }
if (this.isThereA) { return false; }
};

module.exports = Block;
36 changes: 18 additions & 18 deletions lib/board.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
var util = require('util');
var EventEmitter = require('events');
var Block = require('./block');
// var Block = require('./block');
util.inherits(Board, EventEmitter);
var _ = require('lodash');

var iShape = require('./shapes/iShape')
var jShape = require('./shapes/jShape')
var lShape = require('./shapes/lShape')
var oShape = require('./shapes/oShape')
var sShape = require('./shapes/sShape')
var tShape = require('./shapes/tShape')
var zShape = require('./shapes/zShape')
var Shape = require('./shape')
var iShape = require('./shapes/iShape');
var jShape = require('./shapes/jShape');
var lShape = require('./shapes/lShape');
var oShape = require('./shapes/oShape');
var sShape = require('./shapes/sShape');
var tShape = require('./shapes/tShape');
var zShape = require('./shapes/zShape');
var Shape = require('./shape');

var shapes = [iShape, jShape, lShape, oShape, sShape, tShape, zShape]
var shapes = [iShape, jShape, lShape, oShape, sShape, tShape, zShape];

function Board(columns = 10, rows = 20) {
this.columns = columns;
Expand All @@ -28,12 +28,12 @@ function Board(columns = 10, rows = 20) {
16: 0, 17: 0, 18: 0,
19: 0, 20: 0
};
};
}

Board.prototype.draw = function (context) {
_.each(this.pieces, function(piece){
piece.draw(context);
})
});
};

Board.prototype.generateShape = function() {
Expand All @@ -57,15 +57,15 @@ Board.prototype.addBlockToBoard = function(shape) {

Board.prototype.findBlockOnBoard = function(x, y) {
for (let block of this.blocks) {
if (block.x === x && block.y === y) { return block }
};
if (block.x === x && block.y === y) { return block; }
}
};

Board.prototype.rowChecker = function() {
for (let block of this.blocks) {
this.rowBlockCount[block.y] += 1;
if (this.rowBlockCount[block.y] === 10) {this.clearRow(block.y) }
};
if (this.rowBlockCount[block.y] === 10) { this.clearRow(block.y); }
}
};

Board.prototype.clearRow = function(rowNumber) {
Expand All @@ -78,8 +78,8 @@ Board.prototype.clearRow = function(rowNumber) {

Board.prototype.moveBlocksAboveDown = function(rowNumber) {
for (let block of this.blocks) {
if (block.y < rowNumber) { block.moveDown() }
};
if (block.y < rowNumber) { block.moveDown(); }
}
};

module.exports = Board;
22 changes: 10 additions & 12 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ let context = canvas.getContext('2d');
let $ = require('jQuery');

let Board = require('./board');
let Block = require('./block');
let Shape = require('./shape');

let board = new Board;
let currentShape = board.pieces[0]
let board = new Board();
let currentShape = board.pieces[0];

$(document).ready(function(){
drawBoard();
Expand All @@ -33,31 +31,31 @@ function drawBoard() {

// NEED TO ADD A FUNCTION TO CHECK IF EACH BLOCK IN THE SHAPE CAN MOVE DOWN ON -IF-
// move shape down if blocks are above bottom row height
if ( currentShape.piece.shape[4].y < board.rows ) {
if ( currentShape.piece.shape[1].y < board.rows ) {
currentShape.moveShapeDown();
} else {

// change the shape status to false
currentShape.active = false
currentShape.active = false;
// change the shape status to false
_.every(currentShape.piece.shape, function(block) {
block.active = false;
})
});
// drop a new shape after the status is changed to inactive
// currentShape = board.generateShape();
currentShape = board.generateShape();
}
};
}

// 1. get piece to fall
// 2. get rando piece to drop when blocks inactive
// 3. get piece to stack
// 4. create game loop with key inputs (left, right, down, rotate)
// 5. Add screens (start, pause, end screen)

requestAnimationFrame(gameLoop)
// setTimeout(function() { requestAnimationFrame(gameLoop) }, 200 )
// requestAnimationFrame(gameLoop);
setTimeout(function() { requestAnimationFrame(gameLoop) }, 200 );
});
};
}

// $(document).keydown(function(event){
// if (event.keyCode === 32 ) { // space
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"babel-loader": "^5.3.2",
"chai": "^3.2.0",
"css-loader": "^0.15.5",
"jshint": "2.9.1",
"mocha": "^2.2.5",
"mocha-loader": "^0.7.1",
"node-libs-browser": "^0.5.2",
Expand Down

0 comments on commit e54b31a

Please sign in to comment.