Skip to content

Commit 1f7e9c9

Browse files
committed
first commit
1 parent 833135d commit 1f7e9c9

14 files changed

+300
-0
lines changed

app/configuration.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export default function configuration ($routeProvider) {
2+
3+
$routeProvider
4+
5+
.when('/', {
6+
templateUrl: 'views/home.html',
7+
controller: 'HomeController',
8+
controllerAs: 'ctrl'
9+
})
10+
11+
.when('/play/:id', {
12+
templateUrl: 'views/play.html',
13+
controller: 'PlayStepController',
14+
controllerAs: 'ctrl'
15+
})
16+
17+
.otherwise({
18+
redirectTo: '/'
19+
})
20+
21+
}

app/controllers/HomeController.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default function HomeController (StepService) {
2+
3+
StepService.getSteps()
4+
.then(function (steps) {
5+
this.steps = steps
6+
}.bind(this))
7+
8+
}

app/controllers/PlayStepController.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default function StepController ($routeParams, StepService, UserService) {
2+
3+
StepService.getStep($routeParams.id)
4+
.then(function (step) {
5+
this.step = step
6+
}.bind(this))
7+
8+
this.user = UserService
9+
10+
this.selectAction = function (action) {
11+
StepService.action(action, this.user)
12+
}
13+
14+
}

app/index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>DTAdventure</title>
6+
</head>
7+
<body ng-app="DTAdventure">
8+
9+
<header ng-include="'views/header.html'"></header>
10+
11+
<div ng-view></div>
12+
13+
<script src="bundle.js"></script>
14+
</body>
15+
</html>

app/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import angular from 'angular'
2+
import ngRoute from 'angular-route'
3+
4+
import configuration from './configuration'
5+
import HomeController from './controllers/HomeController'
6+
import PlayStepController from './controllers/PlayStepController'
7+
//import EditStepController from './controllers/EditStepController'
8+
import StepService from './services/StepService'
9+
import ActionService from './services/ActionService'
10+
import UserService from './services/UserService'
11+
12+
angular.module('DTAdventure', [ngRoute])
13+
14+
// configuration
15+
.config(configuration)
16+
17+
// controllers
18+
.controller('HomeController', HomeController)
19+
.controller('PlayStepController', PlayStepController)
20+
//.controller('EditStepController', EditStepController)
21+
22+
23+
// filters
24+
25+
// services
26+
.factory('StepService', StepService)
27+
.factory('ActionService', ActionService)
28+
.factory('UserService', UserService)

app/services/ActionService.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export default function ActionService ($location) {
2+
3+
return {
4+
go: function(user, params) {
5+
$location.path('/play/' + params.step)
6+
return true
7+
},
8+
9+
fight: function(user, params) {
10+
user.gold += params.gold
11+
user.life += params.life
12+
return user.life > 0
13+
},
14+
15+
chest: function(user, params) {
16+
user.gold += params.gold
17+
user.life += params.life
18+
return user.life > 0
19+
}
20+
}
21+
}

app/services/StepService.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export default function StepService ($http, ActionService) {
2+
3+
function handleResponse(response) {
4+
return response.data
5+
}
6+
7+
return {
8+
getSteps: function () {
9+
return $http.get('http://localhost:3000/steps')
10+
.then(handleResponse)
11+
},
12+
13+
// createStep: function (step) {
14+
// return $http.post('http://localhost:3000/steps', step)
15+
// .then(handleResponse)
16+
// },
17+
18+
getStep: function (id) {
19+
return $http.get('http://localhost:3000/steps/' + id)
20+
.then(handleResponse)
21+
},
22+
23+
action: function (action, user) {
24+
return ActionService[action.type](user, action.params)
25+
}
26+
}
27+
}

app/services/UserService.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default function StepService ($http, ActionService) {
2+
return {
3+
life: 100,
4+
gold: 0
5+
}
6+
}

app/views/header.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<h2>DTAdventure !!!!</h2>
2+
<a href="#/">Home</a>

app/views/home.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<table>
2+
<thead>
3+
<tr>
4+
<th>Nom</th>
5+
<th></th>
6+
</tr>
7+
</thead>
8+
<tbody>
9+
<tr ng-repeat="step in ctrl.steps track by $index">
10+
<td>{{ step.name }}</td>
11+
<td>
12+
<a ng-href="">Edit</a>
13+
<a ng-href="#/play/{{ step.id }}">Start !</a>
14+
</td>
15+
</tr>
16+
</tbody>
17+
</table>

0 commit comments

Comments
 (0)