Skip to content
Browse files

sort of working: Identify. Was refactoring board. GameCtrl is pretty …

…broken
  • Loading branch information...
1 parent fdc0386 commit 6b415542b859aa2f240d8cbfac9d80b4a26091a7 @seanhess committed Nov 10, 2012
View
2 Makefile
@@ -0,0 +1,2 @@
+all:
+ tsc --module amd public/app.ts
View
17 modules.js
@@ -0,0 +1,17 @@
+var Henry;
+(function (Henry) {
+ Henry.woot = "hello";
+})(Henry || (Henry = {}));
+
+console.log("INSIDE!");
+var Blah;
+(function (Blah) {
+ Blah.woot = "henry";
+})(Blah || (Blah = {}));
+
+
+
+
+
+
+
View
1 public/controllers/Identify.js
@@ -8,7 +8,6 @@ define(["require", "exports"], function(require, exports) {
$scope.intro = "show";
});
}, 1200);
- console.log("WAHOO");
$scope.version = AppVersion;
$scope.player = CurrentPlayer.loadPreferences();
$scope.gameId = $scope.player.gameId || "global";
View
2 public/controllers/Identify.ts
@@ -36,8 +36,6 @@ export class Controller {
})
}, 1200)
- console.log("WAHOO")
-
$scope.version = AppVersion
// see if they have a preferred name and gameId
View
200 public/services/Board.js
@@ -1,103 +1,97 @@
-define(function(require) {
- var app = require('app')
- app.main
-
-.factory('Board', function($rootScope) {
-
- var map = {
- width: 800,
- height: 600,
- unit: 50
- }
-
- map.grid = {
- x: map.width / map.unit,
- y: map.height / map.unit
- }
-
- console.log(map, map.grid)
-
- // Directions
- var LEFT = "left"
- var RIGHT = "right"
- var UP = "up"
- var DOWN = "down"
-
- function getPosition(direction) {
- var position = {}
-
- if(direction === UP) {
- position.axis = 'y'
- position.distance = -1;
- }
-
- else if(direction === RIGHT) {
- position.axis = 'x'
- position.distance = 1
- }
-
- else if(direction === DOWN) {
- position.axis = 'y'
- position.distance = 1
- }
-
- else if(direction === LEFT) {
- position.axis = 'x'
- position.distance = -1
- }
-
- else {
- console.log("BAD DIRECTION", direction)
- return false
- }
-
- return position;
- }
-
- function move(object, position) {
- var axis = position.axis
- var distance = position.distance
- var potential = object[axis] + distance;
- var direction;
- if (axis == 'x' && distance > 0) direction = RIGHT
- else if (axis == 'x' && distance < 0) direction = LEFT
- else if (axis == 'y' && distance > 0) direction = DOWN
- else if (axis == 'y' && distance < 0) direction = UP
- else console.log("BAD MOVE", axis, distance)
-
- if (map.grid[axis] <= potential || potential < 0) {
- return false
- }
-
- return {
- axis: axis,
- location: potential,
- facing: direction
- }
- }
-
- function isHit(one, two) {
- return (one.x == two.x && one.y == two.y)
- }
-
- function makeRandomN(max) {
- return function() {
- return Math.floor(Math.random() * max)
- }
- }
-
- return {
- move: move,
- getPosition: getPosition,
- unit: map.unit,
- isHit: isHit,
- randomX: makeRandomN(map.grid.x),
- randomY: makeRandomN(map.grid.y),
- LEFT: LEFT,
- RIGHT: RIGHT,
- UP: UP,
- DOWN: DOWN,
- }
-})
-
-})
+define(["require", "exports", "../app"], function(require, exports, __app__) {
+ var app = __app__;
+
+ var MAP;
+ (function (MAP) {
+ MAP.width = 800;
+ MAP.height = 600;
+ MAP.unit = 50;
+ MAP.grid = {
+ x: MAP.width / MAP.unit,
+ y: MAP.width / MAP.unit
+ };
+ })(MAP || (MAP = {}));
+
+ exports.LEFT = "left";
+ exports.RIGHT = "right";
+ exports.UP = "up";
+ exports.DOWN = "down";
+ app.main.factory('Board', function ($rootScope) {
+ return {
+ move: move,
+ getPosition: getPosition,
+ isHit: isHit,
+ randomX: makeRandomN(MAP.grid.x),
+ randomY: makeRandomN(MAP.grid.y)
+ };
+ function getPosition(direction) {
+ if(direction === exports.UP) {
+ return {
+ axis: 'y',
+ distance: -1
+ };
+ }
+ if(direction === exports.RIGHT) {
+ return {
+ axis: 'x',
+ distance: 1
+ };
+ }
+ if(direction === exports.DOWN) {
+ return {
+ axis: 'y',
+ distance: 1
+ };
+ }
+ if(direction === exports.LEFT) {
+ return {
+ axis: 'x',
+ distance: -1
+ };
+ } else {
+ console.log("BAD DIRECTION", direction);
+ return null;
+ }
+ }
+ function move(object, position) {
+ var axis = position.axis;
+ var distance = position.distance;
+ var potential = object[axis] + distance;
+ var direction;
+ if(axis == 'x' && distance > 0) {
+ direction = exports.RIGHT;
+ } else {
+ if(axis == 'x' && distance < 0) {
+ direction = exports.LEFT;
+ } else {
+ if(axis == 'y' && distance > 0) {
+ direction = exports.DOWN;
+ } else {
+ if(axis == 'y' && distance < 0) {
+ direction = exports.UP;
+ } else {
+ console.log("BAD MOVE", axis, distance);
+ }
+ }
+ }
+ }
+ if(MAP.grid[axis] <= potential || potential < 0) {
+ return null;
+ }
+ return {
+ axis: axis,
+ location: potential,
+ facing: direction
+ };
+ }
+ function isHit(one, two) {
+ return (one.x == two.x && one.y == two.y);
+ }
+ function makeRandomN(max) {
+ return function () {
+ return Math.floor(Math.random() * max);
+ }
+ }
+ });
+})
+
View
113 public/services/Board.ts
@@ -0,0 +1,113 @@
+// I could just use reference
+
+
+import app = module("../app")
+
+module MAP {
+ export var width = 800
+ export var height = 600
+ export var unit = 50
+
+ export var grid = {
+ x:width / unit,
+ y:width / unit,
+ }
+}
+
+// Directions
+export var LEFT = "left"
+export var RIGHT = "right"
+export var UP = "up"
+export var DOWN = "down"
+
+export interface IPosition {
+ axis:string;
+ distance:number;
+}
+
+export interface IPoint {
+ x:number;
+ y:number;
+}
+
+export interface IBoard {
+ getPosition(direction:string):IPosition;
+ move(object:IPoint, position:IPosition);
+ isHit(one:IPoint, two:IPoint):bool;
+ randomX():number;
+ randomY():number;
+}
+
+// these are the worst variable names of all time
+export interface IMove {
+ axis: string;
+ location: number;
+ facing: string;
+}
+
+app.main.factory('Board', function($rootScope:ng.IRootScopeService):IBoard {
+
+ return {
+ move: move,
+ getPosition: getPosition,
+ isHit: isHit,
+ randomX: makeRandomN(MAP.grid.x),
+ randomY: makeRandomN(MAP.grid.y),
+ }
+
+ function getPosition(direction:string):IPosition {
+
+ if(direction === UP) {
+ return {axis: 'y', distance: -1}
+ }
+
+ if(direction === RIGHT) {
+ return {axis: 'x', distance: 1}
+ }
+
+ if(direction === DOWN) {
+ return {axis: 'y', distance: 1}
+ }
+
+ if(direction === LEFT) {
+ return {axis: 'x', distance: -1}
+ }
+
+ else {
+ console.log("BAD DIRECTION", direction)
+ return null
+ }
+ }
+
+ function move(object:IPoint, position:IPosition) {
+ var axis = position.axis
+ var distance = position.distance
+ var potential = object[axis] + distance;
+ var direction;
+ if (axis == 'x' && distance > 0) direction = RIGHT
+ else if (axis == 'x' && distance < 0) direction = LEFT
+ else if (axis == 'y' && distance > 0) direction = DOWN
+ else if (axis == 'y' && distance < 0) direction = UP
+ else console.log("BAD MOVE", axis, distance)
+
+ if (MAP.grid[axis] <= potential || potential < 0) {
+ return null
+ }
+
+ return {
+ axis: axis,
+ location: potential,
+ facing: direction
+ }
+ }
+
+ function isHit(one:IPoint, two:IPoint):bool {
+ return (one.x == two.x && one.y == two.y)
+ }
+
+ function makeRandomN(max:number) {
+ return function():number {
+ return Math.floor(Math.random() * max)
+ }
+ }
+})
View
1 public/services/Players.js
@@ -3,6 +3,7 @@ define(["require", "exports", "../app"], function(require, exports, __app__) {
+
app.main.factory('Players', function ($rootScope, FB, Board, AppVersion) {
return {
isAlive: isAlive,
View
3 public/services/Players.ts
@@ -12,6 +12,7 @@
import app = module("../app")
import fb = module("./FB")
import av = module("./AppVersion")
+import b = module("./Board")
export interface IPlayer {
x:number;
@@ -55,7 +56,7 @@ export interface IPlayerService {
move(state:IPlayerState, player:IPlayer);
}
-app.main.factory('Players', function($rootScope:ng.IScope, FB:fb.FB, Board, AppVersion:av.IAppVersion):IPlayerService {
+app.main.factory('Players', function($rootScope:ng.IScope, FB:fb.FB, Board:b.IBoard, AppVersion:av.IAppVersion):IPlayerService {
// the big cheese. Does the deed
// you can make fancy bindings here, no?

0 comments on commit 6b41554

Please sign in to comment.
Something went wrong with that request. Please try again.