Skip to content

Commit

Permalink
Merge pull request #18 from orionsbelt-battlegrounds/name-movements
Browse files Browse the repository at this point in the history
Name movements
  • Loading branch information
Nuno Silva committed Mar 10, 2014
2 parents 8a581e5 + 6f7b5d8 commit 9fc9072
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 61 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name" : "obb-battle-engine",
"version" : "0.0.3",
"version" : "0.0.4",
"main" : "./obb.js",
"private" : false,
"scripts" : {
Expand Down
2 changes: 2 additions & 0 deletions src/moves/movement/allMovement.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(function allMovement(module) {

module.name = "allMovement";

module.isValid = function(src,dst,position) {
if( dst.x <= src.x + 1 && dst.x >= src.x - 1 ) {
if( dst.y <= src.y + 1 && dst.y >= src.y - 1 ) {
Expand Down
2 changes: 2 additions & 0 deletions src/moves/movement/diagonalMovement.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(function diagonalMovement(module) {

module.name = "diagonalMovement";

module.isValid = function(src,dst,position) {
if( dst.x == src.x + 1 && dst.y == src.y + 1 ||
dst.x == src.x - 1 && dst.y == src.y - 1 ||
Expand Down
2 changes: 2 additions & 0 deletions src/moves/movement/frontMovement.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
E : { x : 1, y: 0 }
};

module.name = "frontMovement";

module.isValid = function(src,dst,position) {
var value = frontValues[position];
if( value != null ) {
Expand Down
2 changes: 2 additions & 0 deletions src/moves/movement/normalMovement.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(function normalMovement(module) {

module.name = 'normalMovement';

module.isValid = function(src,dst,position) {
if( dst.x <= src.x + 1 && dst.x >= src.x - 1 && src.y == dst.y ) {
return true;
Expand Down
4 changes: 4 additions & 0 deletions test/moves/movement/allMovement.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ describe('allMovement', function(){
expect(allMovement.isValid).to.be.ok();
});

it('should respond to name', function() {
expect(allMovement.name).to.be("allMovement");
});

it('should be valid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(3,6);
Expand Down
56 changes: 30 additions & 26 deletions test/moves/movement/diagonalMovement.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,58 +10,62 @@ describe('diagonalMovement', function(){
expect(diagonalMovement.isValid).to.be.ok();
});

it('should respond to name', function() {
expect(diagonalMovement.name).to.be("diagonalMovement");
});

it('should be valid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(2,6);
expect(diagonalMovement.isValid(src,dst,"N")).to.be.ok();
var src = new Coordinate(3,7);
var dst = new Coordinate(2,6);
expect(diagonalMovement.isValid(src,dst,"N")).to.be.ok();
});

it('should be valid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(4,6);
expect(diagonalMovement.isValid(src,dst,"N")).to.be.ok();
var src = new Coordinate(3,7);
var dst = new Coordinate(4,6);
expect(diagonalMovement.isValid(src,dst,"N")).to.be.ok();
});

it('should be valid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(2,8);
expect(diagonalMovement.isValid(src,dst,"N")).to.be.ok();
var src = new Coordinate(3,7);
var dst = new Coordinate(2,8);
expect(diagonalMovement.isValid(src,dst,"N")).to.be.ok();
});

it('should be valid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(4,8);
expect(diagonalMovement.isValid(src,dst,"N")).to.be.ok();
var src = new Coordinate(3,7);
var dst = new Coordinate(4,8);
expect(diagonalMovement.isValid(src,dst,"N")).to.be.ok();
});

it('should be invalid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(3,6);
expect(!diagonalMovement.isValid(src,dst,"N")).to.be.ok();
var src = new Coordinate(3,7);
var dst = new Coordinate(3,6);
expect(!diagonalMovement.isValid(src,dst,"N")).to.be.ok();
});

it('should be invalid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(3,8);
expect(!diagonalMovement.isValid(src,dst,"N")).to.be.ok();
var src = new Coordinate(3,7);
var dst = new Coordinate(3,8);
expect(!diagonalMovement.isValid(src,dst,"N")).to.be.ok();
});

it('should be invalid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(2,7);
expect(!diagonalMovement.isValid(src,dst,"N")).to.be.ok();
var src = new Coordinate(3,7);
var dst = new Coordinate(2,7);
expect(!diagonalMovement.isValid(src,dst,"N")).to.be.ok();
});

it('should be invalid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(4,7);
expect(!diagonalMovement.isValid(src,dst,"N")).to.be.ok();
var src = new Coordinate(3,7);
var dst = new Coordinate(4,7);
expect(!diagonalMovement.isValid(src,dst,"N")).to.be.ok();
});

it('should be invalid', function() {
it('should be invalid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(8,8);
expect(!diagonalMovement.isValid(src,dst,"N")).to.be.ok();
expect(!diagonalMovement.isValid(src,dst,"N")).to.be.ok();
});
});
});
38 changes: 21 additions & 17 deletions test/moves/movement/frontMovement.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,59 @@ describe('frontMovement', function(){
it('should be valid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(3,6);
expect(frontMovement.isValid(src,dst,"N")).to.be.ok();
expect(frontMovement.isValid(src,dst,"N")).to.be.ok();
});

it('should respond to name', function() {
expect(frontMovement.name).to.be("frontMovement");
});

it('should be invalid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(3,8);
expect(!frontMovement.isValid(src,dst,"N")).to.be.ok();
expect(!frontMovement.isValid(src,dst,"N")).to.be.ok();
});

it('should be invalid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(2,7);
expect(!frontMovement.isValid(src,dst,"N")).to.be.ok();
expect(!frontMovement.isValid(src,dst,"N")).to.be.ok();
});

it('should be invalid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(4,7);
expect(!frontMovement.isValid(src,dst,"N")).to.be.ok();
expect(!frontMovement.isValid(src,dst,"N")).to.be.ok();
});

it('should be invalid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(2,6);
expect(!frontMovement.isValid(src,dst,"N")).to.be.ok();
var src = new Coordinate(3,7);
var dst = new Coordinate(2,6);
expect(!frontMovement.isValid(src,dst,"N")).to.be.ok();
});

it('should be invalid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(4,6);
expect(!frontMovement.isValid(src,dst,"N")).to.be.ok();
var src = new Coordinate(3,7);
var dst = new Coordinate(4,6);
expect(!frontMovement.isValid(src,dst,"N")).to.be.ok();
});

it('should be invalid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(2,8);
expect(!frontMovement.isValid(src,dst,"N")).to.be.ok();
var src = new Coordinate(3,7);
var dst = new Coordinate(2,8);
expect(!frontMovement.isValid(src,dst,"N")).to.be.ok();
});

it('should be invalid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(4,8);
expect(!frontMovement.isValid(src,dst,"N")).to.be.ok();
var src = new Coordinate(3,7);
var dst = new Coordinate(4,8);
expect(!frontMovement.isValid(src,dst,"N")).to.be.ok();
});

it('should be ininvalid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(8,8);
expect(!frontMovement.isValid(src,dst,"N")).to.be.ok();
expect(!frontMovement.isValid(src,dst,"N")).to.be.ok();
});

});
Expand Down
38 changes: 21 additions & 17 deletions test/moves/movement/normalMovement.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,58 +10,62 @@ describe('normalMovement', function(){
expect(normalMovement.isValid).to.be.ok();
});

it('should respond to name', function() {
expect(normalMovement.name).to.be("normalMovement");
});

it('should be valid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(3,6);
expect(normalMovement.isValid(src,dst,"N")).to.be.ok();
expect(normalMovement.isValid(src,dst,"N")).to.be.ok();
});

it('should be valid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(3,8);
expect(normalMovement.isValid(src,dst,"N")).to.be.ok();
expect(normalMovement.isValid(src,dst,"N")).to.be.ok();
});

it('should be valid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(2,7);
expect(normalMovement.isValid(src,dst,"N")).to.be.ok();
expect(normalMovement.isValid(src,dst,"N")).to.be.ok();
});

it('should be valid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(4,7);
expect(normalMovement.isValid(src,dst,"N")).to.be.ok();
expect(normalMovement.isValid(src,dst,"N")).to.be.ok();
});

it('should be invalid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(2,6);
expect(!normalMovement.isValid(src,dst,"N")).to.be.ok();
var src = new Coordinate(3,7);
var dst = new Coordinate(2,6);
expect(!normalMovement.isValid(src,dst,"N")).to.be.ok();
});

it('should be invalid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(4,6);
expect(!normalMovement.isValid(src,dst,"N")).to.be.ok();
var src = new Coordinate(3,7);
var dst = new Coordinate(4,6);
expect(!normalMovement.isValid(src,dst,"N")).to.be.ok();
});

it('should be invalid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(2,8);
expect(!normalMovement.isValid(src,dst,"N")).to.be.ok();
var src = new Coordinate(3,7);
var dst = new Coordinate(2,8);
expect(!normalMovement.isValid(src,dst,"N")).to.be.ok();
});

it('should be invalid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(4,8);
expect(!normalMovement.isValid(src,dst,"N")).to.be.ok();
var src = new Coordinate(3,7);
var dst = new Coordinate(4,8);
expect(!normalMovement.isValid(src,dst,"N")).to.be.ok();
});

it('should be invalid', function() {
var src = new Coordinate(3,7);
var dst = new Coordinate(8,8);
expect(!normalMovement.isValid(src,dst,"N")).to.be.ok();
expect(!normalMovement.isValid(src,dst,"N")).to.be.ok();
});

});
Expand Down

0 comments on commit 9fc9072

Please sign in to comment.