Skip to content

Commit

Permalink
Merge pull request #20 from orionsbelt-battlegrounds/Convert-To-Players
Browse files Browse the repository at this point in the history
Convert to players
  • Loading branch information
tiagomrsousa committed Mar 13, 2014
2 parents 3f44ba0 + 0799d5f commit 07e6357
Show file tree
Hide file tree
Showing 7 changed files with 728 additions and 6 deletions.
5 changes: 4 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ var positionType = require("./src/engine/positionConverters/positionType.js");
var coordinate = require("./src/engine/coordinate.js");
var assert = require('assert');
var expect = require("expect.js");
var convertToPlayer2 = require("./src/engine/positionConverters/convertToPlayer2.js");

new positionType();

var converter = new convertToPlayer2(2);
var coor = new coordinate(6,0);
var aaa = converter.convertCoordinateToBase(coor);
converter.resolveUltimateCoordinate(coordinate1);
19 changes: 17 additions & 2 deletions src/engine/positionConverters/basePositionConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function basePositionConverter(players) {
this.coordinate9 = new coordinate(9,9);
this.coordinate19 = new coordinate(1, 9);
new positionType();
}
}

basePositionConverter.prototype.resolveUltimateCoordinate = function(coord){
if( this.numberOfPlayers == 2 ) {
Expand All @@ -28,12 +28,27 @@ basePositionConverter.prototype.resolveUltimateCoordinate = function(coord){
return null;
};

basePositionConverter.prototype.convertPositionToBase = function (position){
if(positionType.position[position] === undefined){
return null;
}
return position;
};

basePositionConverter.prototype.convertPositionToSpecific = function (position){
if(positionType.position[position] === undefined){
return null;
}
return position;
};
};

basePositionConverter.prototype.convertCoordinateToBase = function (coord){
return coord;
};

basePositionConverter.prototype.convertCoordinateToSpecific = function (coord){
return coord;
};

basePositionConverter.prototype.maxCoordinateValue = function (){
if( this.numberOfPlayers == 2) {
Expand Down
31 changes: 31 additions & 0 deletions src/engine/positionConverters/convertToPlayer1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
var basePositionConverter = require("./basePositionConverter.js");

function convertToPlayer1(players) {
this.base = new basePositionConverter(players);
}

convertToPlayer1.prototype.resolveUltimateCoordinate = function(coord){
return this.base.resolveUltimateCoordinate(coord);
};

convertToPlayer1.prototype.convertPositionToSpecific = function(position){
return this.base.convertPositionToSpecific(position);
};

convertToPlayer1.prototype.convertPositionToBase = function(position){
return this.base.convertPositionToBase(position);
};

convertToPlayer1.prototype.maxCoordinateValue = function(){
return this.base.maxCoordinateValue();
};

convertToPlayer1.prototype.convertCoordinateToBase = function (coord){
return this.base.convertCoordinateToBase(coord);
};

convertToPlayer1.prototype.convertCoordinateToSpecific = function (coord){
return this.base.convertCoordinateToSpecific(coord);
};

module.exports = convertToPlayer1;
57 changes: 57 additions & 0 deletions src/engine/positionConverters/convertToPlayer2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
var basePositionConverter = require("./basePositionConverter.js");
var positionType = require("./positionType.js");
var coordinate = require("./../coordinate.js");

new positionType();
var positionConversion = [];
positionConversion[positionType.position["N"]] = positionType.position["S"];
positionConversion[positionType.position["S"]] = positionType.position["N"];
positionConversion[positionType.position["W"]] = positionType.position["E"];
positionConversion[positionType.position["E"]] = positionType.position["W"];

function convertToPlayer2(players) {
this.base = new basePositionConverter(players);
}


convertToPlayer2.prototype.convertPositionToBase = function(position){
return GetPostion(position);
};


convertToPlayer2.prototype.convertPositionToSpecific = function(position){
return GetPostion(position);
};

convertToPlayer2.prototype.convertCoordinateToBase = function (coord){
var ultimate = this.resolveUltimateCoordinate(coord);
if( ultimate != null ) {
return ultimate;
}
var x = this.maxCoordinateValue() - coord.x;
var y = this.maxCoordinateValue() - coord.y;

return new coordinate(x,y);
};

convertToPlayer2.prototype.convertCoordinateToSpecific = function (coord){
return this.convertCoordinateToBase(coord);
};


convertToPlayer2.prototype.resolveUltimateCoordinate = function(coord){
return this.base.resolveUltimateCoordinate(coord);
};

convertToPlayer2.prototype.maxCoordinateValue = function(){
return this.base.maxCoordinateValue();
};

function GetPostion(position){
if(positionConversion[position] === undefined){
return null;
}
return positionConversion[position];
}

module.exports = convertToPlayer2;
68 changes: 68 additions & 0 deletions src/engine/positionConverters/convertToPlayer3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
var basePositionConverter = require("./basePositionConverter.js");
var positionType = require("./positionType.js");
var coordinate = require("./../coordinate.js");

new positionType();
var positionConversion = [];
positionConversion[positionType.position["N"]] = positionType.position["E"];
positionConversion[positionType.position["S"]] = positionType.position["W"];
positionConversion[positionType.position["W"]] = positionType.position["N"];
positionConversion[positionType.position["E"]] = positionType.position["S"];

var positionConversionToSpecific = [];
positionConversionToSpecific[positionType.position["N"]] = positionType.position["W"];
positionConversionToSpecific[positionType.position["S"]] = positionType.position["E"];
positionConversionToSpecific[positionType.position["W"]] = positionType.position["S"];
positionConversionToSpecific[positionType.position["E"]] = positionType.position["N"];

function convertToPlayer3(players) {
this.base = new basePositionConverter(players);
}


convertToPlayer3.prototype.convertPositionToBase = function(position){
if(positionConversion[position] === undefined){
return null;
}
return positionConversion[position];
};


convertToPlayer3.prototype.convertPositionToSpecific = function(position){
if(positionConversionToSpecific[position] === undefined){
return null;
}
return positionConversionToSpecific[position];

};

convertToPlayer3.prototype.convertCoordinateToBase = function (coord){
//var x = coord.y;
//var y = this.maxCoordinateValue() - coord.x;

var y = coord.x;
var x = this.maxCoordinateValue() - coord.y;

return new coordinate(x,y);
};

convertToPlayer3.prototype.convertCoordinateToSpecific = function (coord){
//var x = this.maxCoordinateValue() - coord.y;
//var y = coord.x;

var y = this.maxCoordinateValue() - coord.x;
var x = coord.y;

return new coordinate(x,y);
};


convertToPlayer3.prototype.resolveUltimateCoordinate = function(coord){
return this.base.resolveUltimateCoordinate(coord);
};

convertToPlayer3.prototype.maxCoordinateValue = function(){
return this.base.maxCoordinateValue();
};

module.exports = convertToPlayer3;
68 changes: 68 additions & 0 deletions src/engine/positionConverters/convertToPlayer4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
var basePositionConverter = require("./basePositionConverter.js");
var positionType = require("./positionType.js");
var coordinate = require("./../coordinate.js");

new positionType();
var positionConversion = [];
positionConversion[positionType.position["N"]] = positionType.position["W"];
positionConversion[positionType.position["S"]] = positionType.position["E"];
positionConversion[positionType.position["W"]] = positionType.position["S"];
positionConversion[positionType.position["E"]] = positionType.position["N"];

var positionConversionToSpecific = [];
positionConversionToSpecific[positionType.position["N"]] = positionType.position["E"];
positionConversionToSpecific[positionType.position["S"]] = positionType.position["W"];
positionConversionToSpecific[positionType.position["W"]] = positionType.position["N"];
positionConversionToSpecific[positionType.position["E"]] = positionType.position["S"];

function convertToPlayer4(players) {
this.base = new basePositionConverter(players);
}


convertToPlayer4.prototype.convertPositionToBase = function(position){
if(positionConversion[position] === undefined){
return null;
}
return positionConversion[position];
};


convertToPlayer4.prototype.convertPositionToSpecific = function(position){
if(positionConversionToSpecific[position] === undefined){
return null;
}
return positionConversionToSpecific[position];

};

convertToPlayer4.prototype.convertCoordinateToBase = function (coord){
//var y = coord.x;
//var x = this.maxCoordinateValue() - coord.y;

var x = coord.y;
var y = this.maxCoordinateValue() - coord.x;

return new coordinate(x,y);
};

convertToPlayer4.prototype.convertCoordinateToSpecific = function (coord){
//var y = this.maxCoordinateValue() - coord.x;
//var x = coord.y;

var x = this.maxCoordinateValue() - coord.y;
var y = coord.x;

return new coordinate(x,y);
};


convertToPlayer4.prototype.resolveUltimateCoordinate = function(coord){
return this.base.resolveUltimateCoordinate(coord);
};

convertToPlayer4.prototype.maxCoordinateValue = function(){
return this.base.maxCoordinateValue();
};

module.exports = convertToPlayer4;
Loading

0 comments on commit 07e6357

Please sign in to comment.