This file contains hidden or 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
| angular.module('kahootCloneApp') | |
| .controller('MainCtrl', function ($scope, $location, _, fbutil) { | |
| $scope.newGame = function() { | |
| $scope.creatingGame = true; | |
| // Generate random 6 digit pincode for the game | |
| var PIN = _.random(100000,999999), | |
| // Connect to Firebase |
This file contains hidden or 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
| yo angularfire:route Host | |
| yo angularfire:service Host |
This file contains hidden or 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
| // we store data about games as nodes of the /games node | |
| { | |
| "games" : { | |
| "123456" : { // Game identifiers will be 6 digit PIN codes | |
| // Gamestate, key-value pairs | |
| }, | |
| "234567" : { | |
| // ... | |
| } | |
| } |
This file contains hidden or 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
| angular.module('kahootCloneApp') | |
| .controller('HostCtrl', function ($scope, Host, $routeParams,fbutil) { | |
| Host.init($routeParams.PIN) | |
| .then(function() { | |
| Host.syncObject.$bindTo($scope, 'game'); | |
| }); | |
| $scope.startGame = function() { | |
| $scope.game.data.state = 'preQuestion' |
This file contains hidden or 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
| <div class="row" ng-if="game.data.state == 'waitingForPlayers'"> | |
| <div class="jumbotron"> | |
| <h1>Join our game!</h1> | |
| <h2>Go to http://someaddress.com on your smartphone</h2> | |
| <h2>Our PIN code is {{game.$id}}</h2> | |
| <p><button class="btn btn-success" ng-click="startGame()">Let's begin!</button></p> | |
| </div> | |
| <div class="col-md-12"> | |
| <div class="well"> | |
| <h3>Who's here:</h3> |
This file contains hidden or 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
| yo angularfire:route Player | |
| yo angularfire:service Player |
This file contains hidden or 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
| angular.module('kahootCloneApp') | |
| .service('Host', function (fbutil) { | |
| var self = this; | |
| self.init = function(PIN) { | |
| self.syncObject = fbutil.syncObject('games/' + PIN); | |
| return self.syncObject.$loaded(); | |
| }; | |
| }); |
This file contains hidden or 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
| <div class="row" ng-if="game.data.state=='joinGame'"> | |
| <div class="col-md-6 col-md-offset-3"> | |
| <form> | |
| <div class="form-group"> | |
| <label for="PIN">Game PIN #</label> | |
| <input ng-model="$parent.PIN" type="text" class="form-control" id="PIN" placeholder="Enter 6 digit number availible on main screen"> | |
| </div> | |
| <div class="form-group"> | |
| <label for="screenName">Your name</label> | |
| <input ng-model="$parent.screenName" type="text" class="form-control" id="screenName" placeholder="Choose a screen name"> |
This file contains hidden or 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
| angular.module('kahootCloneApp') | |
| .controller('PlayerCtrl', function ($scope, Player, $location,$routeParams) { | |
| if(! $routeParams.hasOwnProperty('PIN')) { | |
| $scope.game = { | |
| data : { | |
| state: 'joinGame' | |
| } | |
| } | |
| } else { |
This file contains hidden or 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
| angular.module('kahootCloneApp') | |
| .service('Player', function (fbutil, _, $cookieStore) { | |
| // AngularJS will instantiate a singleton by calling "new" on this function | |
| var self = this, _so; | |
| self.getUniqId = function() { | |
| // generate a unique idenftifier for the player and save it in a cookie to allow refreshes | |
| if($cookieStore.get('playerId')) { | |
| return self._id = $cookieStore.get('playerId'); | |
| } else { |