Last active
December 30, 2015 14:09
-
-
Save Gwash3189/7840067 to your computer and use it in GitHub Desktop.
D&D initiative & health tracker in Angular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.min.js"></script> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script> | |
<script src="script.js"></script> | |
</head> | |
<body ng-app="init"> | |
<h1>Working</h1> | |
<div ng-controller="CharacterController"> | |
<ul ng-repeat="character in characters"> | |
<li><b>Name: </b>{{character.name}}</li> | |
<li><b>Health: </b>{{character.name}}</li> | |
<li><b>Initiative: </b>{{character.initiative}}</li> | |
</ul> | |
<br /> | |
<input type="text" ng-model="character.name" /> | |
<br /> | |
<input type="number" ng-model="character.health" /> | |
<br /> | |
<input type="number" ng-model="character.initiative" /> | |
<br /> | |
<button ng-click="addCharacter(character)">Add</button> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var init = angular.module("init", []); | |
init.controller("CharacterController",function($scope){ | |
$scope.characters = []; | |
$scope.character = {}; | |
$scope.addCharacter = function(character){ | |
if(character.hasOwnProperty("id") === false){ | |
var length = $scope.characters.length; | |
if(length === 0){ | |
$scope.character.id = 0; | |
} | |
else { | |
$scope.character.id = $scope.characters.length; | |
} | |
} | |
$scope.characters.push($scope.character); | |
$scope.characters.sort(function(a,b){ | |
return a.initiative - b.initiative; | |
}).reverse(); | |
$scope.character = {}; | |
} | |
$scope.removeCharacter = function(id){ | |
for(var i =0; i < $scope.characters.length; i++){ | |
if($scope.characters[i].id === id){ | |
$scope.characters[i].splice(i,1); | |
i--; | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment