Skip to content

Commit

Permalink
[Linesh][#23] Refactor: move position calculation methods to Game
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanLin-TWer committed Mar 19, 2017
1 parent d7a51a3 commit 497de9f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions js/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ export class Player extends Movable {
}
break
case 'up':
if (this.y > Game.row(0)) {
if (Game.withinTopBoundary(this.y)) {
this.move(0, -Game.CELL_HEIGHT)
}
break
case 'down':
if (this.y < Game.row(5)) {
if (Game.withinBottomBoundary(this.y)) {
this.move(0, Game.CELL_HEIGHT)
}
break
Expand Down
8 changes: 8 additions & 0 deletions js/constants/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,13 @@ export class Game {
static withinRightBoundary(x) {
return x < Game.col(Game.HORIZON_CELLS)
}

static withinTopBoundary(y) {
return y > Game.TOP_BOUNDARY
}

static withinBottomBoundary(y) {
return y < Game.row(5)
}
}

0 comments on commit 497de9f

Please sign in to comment.