Skip to content

Commit

Permalink
(#17) Versus game
Browse files Browse the repository at this point in the history
  • Loading branch information
EnoF committed Feb 21, 2014
1 parent 76c5223 commit c2ad732
Show file tree
Hide file tree
Showing 22 changed files with 280 additions and 43 deletions.
3 changes: 3 additions & 0 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
.when('/tutorial', {
templateUrl: 'pages/tutorial.html'
})
.when('/versus', {
templateUrl: 'pages/versus.html'
})
.otherwise({
redirectTo: '/'
});
Expand Down
20 changes: 13 additions & 7 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,27 @@

<script src="scripts/templates.js"></script>

<script src="models/Scene.js" type="text/javascript"></script>
<script src="models/FirstAttackScene.js" type="text/javascript"></script>
<script src="models/GameObject.js" type="text/javascript"></script>
<script src="models/Player.js" type="text/javascript"></script>
<script src="models/scenes/Scene.js" type="text/javascript"></script>
<script src="models/scenes/FirstAttackScene.js" type="text/javascript"></script>
<script src="models/scenes/VersusScene.js" type="text/javascript"></script>

<script src="models/characters/Character.js" type="text/javascript"></script>
<script src="models/characters/Saber.js" type="text/javascript"></script>
<script src="models/characters/SwordSoldier.js" type="text/javascript"></script>
<script src="models/GameSquare.js" type="text/javascript"></script>

<script src="models/skills/Skill.js" type="text/javascript"></script>
<script src="models/skills/CleanCut.js" type="text/javascript"></script>
<script src="models/skills/Excalibur.js" type="text/javascript"></script>

<script src="models/GameObject.js" type="text/javascript"></script>
<script src="models/Player.js" type="text/javascript"></script>
<script src="models/GameSquare.js" type="text/javascript"></script>

<script src="widgets/gameSquare/gameSquare.js" type="text/javascript"></script>
<script src="widgets/firstAttackScene/firstAttackScene.js" type="text/javascript"></script>
<script src="widgets/character/Character.js" type="text/javascript"></script>
<script src="widgets/gameBoard/gameBoard.js" type="text/javascript"></script>
<script src="widgets/character/character.js" type="text/javascript"></script>
<script src="widgets/tutorial/tutorial.js" type="text/javascript"></script>
<script src="widgets/versus/versus.js" type="text/javascript"></script>
<!--end DEV imports-->

<!--start PROD imports
Expand Down
File renamed without changes.
11 changes: 10 additions & 1 deletion app/models/Scene.js → app/models/scenes/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

var app = angular.module('jsWars');

app.factory('Scene', function SceneFactory(GameSquare) {
app.factory('Scene', function SceneFactory(GameSquare, Player) {
return clazz(function Scene() {

this.private = {
Expand Down Expand Up @@ -44,6 +44,9 @@
character.setHasAttacked(true);
this.public.closeActionPanel();
},
addUnits: function addUnits() {
throw new Error('Exception not implemented');
},
endTurn: function endTurn(player) {
var units = player.getUnits();
for (var unit = units.getFirst(); unit; unit = unit.getNext()) {
Expand All @@ -63,6 +66,12 @@
this.private.initializeMapCollumn(column, height);
}
},
initializePlayers: function initializePlayers() {
this.private.players.add(0, new Player('Player 1'));
this.private.players.add(1, new Player('Player 2'));
this.private.currentPlayerNode = this.private.players.getFirst();
this.protected.addUnits();
},
validatePositions: function validatePositions(newX, newY) {
var currentPosition = this.private.activeGameSquare;
var newPosition = this.public.getPosition(newX, newY);
Expand Down
76 changes: 76 additions & 0 deletions app/models/scenes/VersusScene.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (c) 2014.
*
* @author Andy Tang
*/
(function VersusSceneModel(angular, clazz) {
'use strict';

var app = angular.module('jsWars');

app.factory('VersusScene', ['Saber', 'SwordSoldier', 'Scene',
function VersusSceneFactory(Saber, SwordSoldier) {
return clazz(function VersusScene() {
this.extend = 'Scene';

this.private = {
createNewUnits: function createNewUnits(list) {
list.add(0, new Saber());
for (var i = 1; i < 5; i++) {
list.add(i, new SwordSoldier());
}
},
calculatPositions: function calculatePositions(unitsAdded, x, y) {
var position = {
x: x,
y: y
};
var positionCalculator = unitsAdded % 5;

if (positionCalculator === 1) {
position.x = x + 1;
} else if (positionCalculator === 2) {
position.y = y - 1;
} else if (positionCalculator === 3) {
position.x = x - 1;
} else if (positionCalculator === 4) {
position.y = y + 1;
}

return position;
},
positionUnits: function positionUnits(list, x, y) {
var unitNode = list.getFirst();
var unit;
var unitsAdded = 0;
var position;
do {
position = this.private.calculatPositions(unitsAdded, x, y);
unit = unitNode.getValue();
this.public.getPosition(position.x, position.y).setGameObject(unit);
unitsAdded++;
} while ((unitNode = unitNode.getNext()) !== null);
}
};

this.protected = {
addUnits: function addUnits() {
var playerList = this.public.getPlayers();
var playerOne = playerList.getFirst();
var playerTwo = playerList.getLast();
var unitsOne = playerOne.getValue().getUnits();
var unitsTwo = playerTwo.getValue().getUnits();
this.private.createNewUnits(unitsOne);
this.private.positionUnits(unitsOne, 2, 5);
this.private.createNewUnits(unitsTwo);
this.private.positionUnits(unitsTwo, 17, 5);
}
};

this.constructor = function constructor() {
this.super.constructor(20, 10);
this.protected.initializePlayers();
};
});
}]);
}(window.angular, window.clazz, window.LinkedHashMap));
2 changes: 1 addition & 1 deletion app/pages/tutorial.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
~ @author Andy Tang
-->
<h1>Tutorial</h1>
<section data-first-attack-scene=""></section>
<section data-tutorial=""></section>
7 changes: 7 additions & 0 deletions app/pages/versus.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!--
~ Copyright (c) 2014.
~
~ @author Andy Tang
-->
<h1>Versus</h1>
<section data-versus=""></section>
9 changes: 9 additions & 0 deletions app/styles/game.less
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ nav {
background: rgba(150, 150, 150, 0.5);
padding: 20px;
margin: 30px 30px;

.view-port {
width: 100%;
overflow: auto;

.view-content {
width: 200%;
}
}
}

.game-square {
Expand Down
22 changes: 0 additions & 22 deletions app/widgets/firstAttackScene/firstAttackScene.html

This file was deleted.

30 changes: 30 additions & 0 deletions app/widgets/gameBoard/gameBoard.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!--
~ Copyright (c) 2014.
~
~ @author Andy Tang
-->
<section>
<div class="game-board"
data-ng-class="{ 'move-mode': isInMoveMode(), 'attack-mode': isInAttackMode()}">
<h2>{{ getCurrentPlayer().getName() }}</h2>

<div class="view-port">
<div class="view-content">
<div class="column"
data-ng-repeat="column in map">
<div data-ng-repeat="square in column">
<div data-ng-class="{
'move-allowed': isInMoveRange($parent.$index, $index),
'attack-allowed': isInAttackRange($parent.$index, $index)
}"
data-game-square="square"
data-ng-click="action($parent.$index, $index)"/>
</div>
</div>
</div>
</div>
</div>
<div class="button"
data-ng-click="endTurn()">End Turn
</div>
</section>
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
*
* @author Andy Tang
*/
(function firstAttackSceneWidget(angular) {
(function gameBoardWidget(angular) {
'use strict';

var app = angular.module('jsWars');

app.controller('firstAttackSceneViewModel',
function firstAttackSceneViewModel($scope, FirstAttackScene) {
var scene = new FirstAttackScene(3, 2, 5, 2);
app.controller('gameBoardViewModel',
function gameBoardViewModel($scope) {
var scene = $scope.scene;

$scope.getCurrentPlayer = scene.getCurrentPlayer;

Expand All @@ -27,13 +27,14 @@
$scope.endTurn = scene.endTurn;
});

app.directive('firstAttackScene', function firstAttackSceneDirective() {
app.directive('gameBoard', function gameBoardDirective() {
return {
restrict: 'A',
templateUrl: 'firstAttackScene',
templateUrl: 'gameBoard',
scope: {
scene: '=gameBoard'
},
controller: 'firstAttackSceneViewModel'
controller: 'gameBoardViewModel'
};
});

Expand Down
6 changes: 6 additions & 0 deletions app/widgets/tutorial/tutorial.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!--
~ Copyright (c) 2014.
~
~ @author Andy Tang
-->
<div data-game-board="scene"/>
25 changes: 25 additions & 0 deletions app/widgets/tutorial/tutorial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2014.
*
* @author Andy Tang
*/
(function tutorialWidget(angular) {
'use strict';

var app = angular.module('jsWars');

app.controller('tutorialViewModel',
function tutorialViewModel($scope, FirstAttackScene) {
$scope.scene = new FirstAttackScene(3, 2, 5, 2);
});

app.directive('tutorial', function tutorialDirective() {
return {
restrict: 'A',
templateUrl: 'tutorial',
scope: {
},
controller: 'tutorialViewModel'
};
});
}(window.angular));
6 changes: 6 additions & 0 deletions app/widgets/versus/versus.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!--
~ Copyright (c) 2014.
~
~ @author Andy Tang
-->
<div data-game-board="scene"/>
25 changes: 25 additions & 0 deletions app/widgets/versus/versus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2014.
*
* @author Andy Tang
*/
(function versusWidget(angular) {
'use strict';

var app = angular.module('jsWars');

app.controller('versusViewModel',
function versusViewModel($scope, VersusScene) {
$scope.scene = new VersusScene();
});

app.directive('versus', function versusDirective() {
return {
restrict: 'A',
templateUrl: 'versus',
scope: {
},
controller: 'versusViewModel'
};
});
}(window.angular));
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "JSWars",
"version": "0.2.0",
"version": "0.2.1",
"description": "Turn based strategy game",
"author": "EnoF",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/FirstAttackScene.js → test/e2e/tutorial.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @author Andy Tang
*/
(function FirstAttackSceneScenarios(whereIt) {

'use strict';
describe('First Attack Scene Scenarios', function FirstAttackScene() {

beforeEach(function () {
Expand Down
27 changes: 27 additions & 0 deletions test/e2e/versus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2014.
*
* @author Andy Tang
*/
(function VersusScene() {
'use strict';

describe('Versus Scene Scenarios', function VersusScene() {

beforeEach(function navigateTo() {
browser().navigateTo('/#/versus');
});

it('should have 20 x 10 game squares', function gameSquares() {
expect(element('.game-square').count()).toEqual(20 * 10);
});

it('should spawn two sabers', function spawnTwoSabers() {
expect(element('.saber').count()).toEqual(2);
});

it('should spawn 10 sword soldiers', function swordSoldiers() {
expect(element('.sword-soldier').count()).toEqual(8);
});
});
}());
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit c2ad732

Please sign in to comment.