Skip to content

Commit

Permalink
replace Direction with Tank.Direction
Browse files Browse the repository at this point in the history
  • Loading branch information
newagebegins committed Jun 5, 2012
1 parent 9f31ef9 commit ef1c860
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
/nbproject/
/NOTES.txt
1 change: 0 additions & 1 deletion SpecRunner.html
Expand Up @@ -19,7 +19,6 @@

<!-- source files -->
<script type="text/javascript" src="src/Utils.js"></script>
<script type="text/javascript" src="src/Direction.js"></script>
<script type="text/javascript" src="src/Point.js"></script>
<script type="text/javascript" src="src/Rect.js"></script>
<script type="text/javascript" src="src/Sprite.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion spec/CollisionDetectorSpec.js
Expand Up @@ -6,7 +6,7 @@ describe("CollisionDetector", function () {
var tank = new Tank(eventManager);
tank.setRect(new Rect(0, 0, 1, 1));
tank.setSpeed(1);
tank.setDirection(Direction.RIGHT);
tank.setDirection(Tank.Direction.RIGHT);

var wall = new Wall();
wall.setRect(new Rect(1, 0, 1, 1));
Expand Down
8 changes: 4 additions & 4 deletions spec/TankControllerSpec.js
@@ -1,19 +1,19 @@
describe("TankController", function () {
describe("KEY_DOWN", function () {
it("LEFT", function () {
checkKey(Direction.RIGHT, Keyboard.Key.LEFT, Direction.LEFT);
checkKey(Tank.Direction.RIGHT, Keyboard.Key.LEFT, Tank.Direction.LEFT);
});

it("RIGHT", function () {
checkKey(Direction.LEFT, Keyboard.Key.RIGHT, Direction.RIGHT);
checkKey(Tank.Direction.LEFT, Keyboard.Key.RIGHT, Tank.Direction.RIGHT);
});

it("UP", function () {
checkKey(Direction.LEFT, Keyboard.Key.UP, Direction.UP);
checkKey(Tank.Direction.LEFT, Keyboard.Key.UP, Tank.Direction.UP);
});

it("DOWN", function () {
checkKey(Direction.LEFT, Keyboard.Key.DOWN, Direction.DOWN);
checkKey(Tank.Direction.LEFT, Keyboard.Key.DOWN, Tank.Direction.DOWN);
});

function checkKey(initialDirection, pressedKey, expectedDirection) {
Expand Down
12 changes: 6 additions & 6 deletions spec/TankSpec.js
Expand Up @@ -16,7 +16,7 @@ describe("Tank", function () {
});

it("direction should be Right", function () {
expect(tank.getDirection()).toEqual(Direction.RIGHT);
expect(tank.getDirection()).toEqual(Tank.Direction.RIGHT);
});
});

Expand All @@ -27,7 +27,7 @@ describe("Tank", function () {
});

it("#setDirection", function () {
var DIRECTION = Direction.LEFT;
var DIRECTION = Tank.Direction.LEFT;
tank.setDirection(DIRECTION);
expect(tank.getDirection()).toEqual(DIRECTION);
});
Expand All @@ -36,19 +36,19 @@ describe("Tank", function () {
var INIT_X = 0, INIT_Y = 0, SPEED = 1;

it("right", function () {
checkDirection(Direction.RIGHT, new Point(INIT_X + SPEED, INIT_Y))
checkDirection(Tank.Direction.RIGHT, new Point(INIT_X + SPEED, INIT_Y))
});

it("left", function () {
checkDirection(Direction.LEFT, new Point(INIT_X - SPEED, INIT_Y))
checkDirection(Tank.Direction.LEFT, new Point(INIT_X - SPEED, INIT_Y))
});

it("up", function () {
checkDirection(Direction.UP, new Point(INIT_X, INIT_Y - SPEED))
checkDirection(Tank.Direction.UP, new Point(INIT_X, INIT_Y - SPEED))
});

it("down", function () {
checkDirection(Direction.DOWN, new Point(INIT_X, INIT_Y + SPEED))
checkDirection(Tank.Direction.DOWN, new Point(INIT_X, INIT_Y + SPEED))
});

function checkDirection(direction, finalPosition) {
Expand Down
6 changes: 0 additions & 6 deletions src/Direction.js

This file was deleted.

17 changes: 12 additions & 5 deletions src/Tank.js
Expand Up @@ -3,13 +3,20 @@ function Tank(eventManager) {

this._eventManager = eventManager;
this._speed = 0;
this._direction = Direction.RIGHT;
this._direction = Tank.Direction.RIGHT;
}

Tank.subclass(Sprite);

Tank.SPEED = 4;

Tank.Direction = {
RIGHT: 'RIGHT',
LEFT: 'LEFT',
UP: 'UP',
DOWN: 'DOWN',
};

Tank.prototype.getSpeed = function () {
return this._speed;
};
Expand All @@ -35,10 +42,10 @@ Tank.prototype.move = function () {
Tank.prototype._getNewX = function () {
var result = this._x;

if (this._direction == Direction.RIGHT) {
if (this._direction == Tank.Direction.RIGHT) {
result += this._speed;
}
else if (this._direction == Direction.LEFT) {
else if (this._direction == Tank.Direction.LEFT) {
result -= this._speed;
}

Expand All @@ -48,10 +55,10 @@ Tank.prototype._getNewX = function () {
Tank.prototype._getNewY = function () {
var result = this._y;

if (this._direction == Direction.UP) {
if (this._direction == Tank.Direction.UP) {
result -= this._speed;
}
else if (this._direction == Direction.DOWN) {
else if (this._direction == Tank.Direction.DOWN) {
result += this._speed;
}

Expand Down
8 changes: 4 additions & 4 deletions src/TankController.js
Expand Up @@ -15,16 +15,16 @@ TankController.prototype._keyDown = function (key) {
this._tank.setSpeed(Tank.SPEED);

if (key == Keyboard.Key.LEFT) {
this._tank.setDirection(Direction.LEFT);
this._tank.setDirection(Tank.Direction.LEFT);
}
else if (key == Keyboard.Key.RIGHT) {
this._tank.setDirection(Direction.RIGHT);
this._tank.setDirection(Tank.Direction.RIGHT);
}
else if (key == Keyboard.Key.UP) {
this._tank.setDirection(Direction.UP);
this._tank.setDirection(Tank.Direction.UP);
}
else if (key == Keyboard.Key.DOWN) {
this._tank.setDirection(Direction.DOWN);
this._tank.setDirection(Tank.Direction.DOWN);
}
};

Expand Down

0 comments on commit ef1c860

Please sign in to comment.