From 0ff386fe2813d87974b798c4beee65fadbf34d2a Mon Sep 17 00:00:00 2001 From: arzynik Date: Thu, 21 Nov 2013 18:55:32 -0800 Subject: [PATCH] added minigame funcitonality written in angular. --- .../default/crunchbutton/frontend/cafe.phtml | 0 .../views/default/seven/frontend/about.phtml | 2 +- .../views/default/seven/frontend/cafe.phtml | 31 ++ www/assets/css/seven.css | 35 ++- www/assets/js/app.js | 5 + www/assets/js/controllers.js | 269 ++++++++++++++++++ www/assets/js/util.js | 11 + 7 files changed, 347 insertions(+), 6 deletions(-) create mode 100644 include/views/default/crunchbutton/frontend/cafe.phtml create mode 100644 include/views/default/seven/frontend/cafe.phtml diff --git a/include/views/default/crunchbutton/frontend/cafe.phtml b/include/views/default/crunchbutton/frontend/cafe.phtml new file mode 100644 index 000000000..e69de29bb diff --git a/include/views/default/seven/frontend/about.phtml b/include/views/default/seven/frontend/about.phtml index 637703c09..5982082e5 100644 --- a/include/views/default/seven/frontend/about.phtml +++ b/include/views/default/seven/frontend/about.phtml @@ -86,7 +86,7 @@
Favorite beer: Stella Artois

- Hes in Brazil. + Hes in Brazil. I hear he also likes to play games.

diff --git a/include/views/default/seven/frontend/cafe.phtml b/include/views/default/seven/frontend/cafe.phtml new file mode 100644 index 000000000..a238eb818 --- /dev/null +++ b/include/views/default/seven/frontend/cafe.phtml @@ -0,0 +1,31 @@ +
+ + +
+ + +

+ +
+
+ +
+
+ +
+
+ +
+

{{requested.name}}

+
+
+ {{stats.level.name}}
+ Time: {{stats.timer}} / {{stats.level.time/1000}}:00 seconds
+ Errors: {{stats.errors}}
+ Success: {{stats.success}}
+ Required: {{stats.level.required}}
+
+


+ +
+
diff --git a/www/assets/css/seven.css b/www/assets/css/seven.css index ae3f86209..00b4d34de 100644 --- a/www/assets/css/seven.css +++ b/www/assets/css/seven.css @@ -273,14 +273,20 @@ html { .pushabutton { background: url(../images/micro/push-a-button.svg) no-repeat; background-position: center center; - width: 14em; - height: 14em; background-size: 100%; margin: 0 auto; - margin-bottom: 1em; padding-top: 50px; -webkit-transition: all 0.2s; } +.snap-drawer .pushabutton { + width: 14em; + height: 14em; + margin-bottom: 1em; +} +.home-top .pushabutton { + width: 16em; + height: 16em; +} @media (min-width: 321px) and (max-height: 350px) { .pushabutton { display: none; @@ -875,7 +881,6 @@ p { display:block; border-bottom:1px solid rgba(0,0,0,0.1); padding:8px 0 2px 0; - font-weight:bold; text-decoration:none; color:#fff; text-indent:20px; @@ -905,7 +910,6 @@ p { line-height: 1.6em; margin-bottom: 20px; font-size: 14px; - font-weight: 200; } } @@ -2794,4 +2798,25 @@ sup { @media screen and (min-width: 769px) { +} + +.cafe-button { + border: 0; + background: #fe9872; + color: #fff; + font-size: 1.5em; + cursor: pointer; + border-radius: 4px; + padding: 1em 0 1em 0; + width: 9em; + height: 5em; + margin: .5em; + float: left; +} +.cafe-message { + height: 3.1em; + margin-bottom: 1em; +} +.cafe-request { + height: 2.1em; } \ No newline at end of file diff --git a/www/assets/js/app.js b/www/assets/js/app.js index c70136dff..6fe98bed6 100644 --- a/www/assets/js/app.js +++ b/www/assets/js/app.js @@ -223,6 +223,11 @@ NGApp.config(['$routeProvider', '$locationProvider', function($routeProvider, $l controller: 'HomeCtrl', templateUrl: 'assets/view/home.html' }) + .when('/cafe', { + action: 'cafe', + controller: 'CafeCtrl', + templateUrl: 'assets/view/cafe.html' + }) .otherwise({ action: 'home', controller: 'DefaultCtrl', diff --git a/www/assets/js/controllers.js b/www/assets/js/controllers.js index 59c43f9f1..914356ad9 100644 --- a/www/assets/js/controllers.js +++ b/www/assets/js/controllers.js @@ -982,4 +982,273 @@ NGApp.controller( 'NoInternetCtrl', function ( $scope ) { // Just store the cookie, it will be used later $.cookie( 'referral', $routeParams.id ); $location.path( '/' ); +}); + + +/** + * mini game controller + */ +NGApp.controller('CafeCtrl', function ($scope, $http) { + var + gameStart = null, + timer = null, + messageTimeout = null, + enabled = false, + level = 0, + startTimer = null; + + var getItem = function(key) { + for (var x in items) { + if (items[x].id == key) { + return items[x]; + } + } + return null; + }; + + $scope.buttonPress = function(id) { + if (!$scope.requested || !enabled) { + return; + } + + var clicked = getItem(id); + + if ($scope.requested.id == clicked.id) { + $scope.stats.success++; + if ($scope.stats.success >= rounds[level].required) { + win(); + return; + } + showMessage('Yay. Keep going!','good'); + requestPress(); + } else { + enabled = false; + $scope.stats.errors++; + showMessage('You suck! Wait 2 seconds!','error'); + setTimeout(function() { + enabled = true; + },2000); + } + }; + + var showMessage = function(message, type) { + clearTimeout(messageTimeout); + $scope.message = {}; + $scope.message[type] = message; + + messageTimeout = setTimeout(function() { + $scope.$apply(function() { + $scope.message = null; + }); + },2000); + }; + + var requestPress = function() { + var cloned = $scope.items.slice(0); + + if (!$scope.requested) { + var newrequest = $.pluck(cloned,1); + newrequest = newrequest[0]; + } else { + var previous = newrequest = $scope.requested; + while (newrequest.id == previous.id) { + newrequest = $.pluck(cloned,1); + newrequest = newrequest[0]; + } + } + + if ($scope.$$phase) { + $scope.requested = newrequest; + } else { + $scope.$apply(function($scope) { + $scope.requested = newrequest; + }); + } + }; + + var loose = function() { + $scope.stop(); + + if ($scope.$$phase) { + $scope.message = {error: 'You loose.'}; + + } else { + $scope.$apply(function($scope) { + $scope.message = {error: 'You loose.'}; + }); + } + }; + + var win = function() { + $scope.stop(); + level++; + + if ($scope.$$phase) { + $scope.message = {good: 'You win! Try the next level!'}; + + } else { + $scope.$apply(function($scope) { + $scope.message = {good: 'You win! Try the next level!'}; + }); + } + }; + + var updateTimer = function() { + var now = new Date; + var diffMs = now.getTime() - gameStart.getTime(); + var diff = Math.round(diffMs / 10).pad(4); + + if (diffMs >= rounds[level].time) { + loose(); + return; + } + + diff = (diff + ' ').slice(0,2) + ':' + (diff + ' ').slice(2,4); + + if ($scope.$$phase) { + $scope.stats.timer = diff; + } else { + $scope.$apply(function($scope) { + $scope.stats.timer = diff; + }); + } + }; + + var rounds = [ + { + name: 'Trial Level ', + time: 20000, + required: 3 + }, + { + name: 'Level 1', + time: 20000, + required: 10 + }, + { + name: 'Level 2', + time: 20000, + required: 20 + }, + { + name: 'Level 3', + time: 20000, + required: 30 + }, + { + name: 'Level 4', + time: 20000, + required: 40 + } + ]; + + var items = [ + { + name: 'Wenzel', + id: 'wenzel' + }, + { + name: 'Spicy With', + id: 'spicywith' + }, + { + name: 'All Meat Pizza', + id: 'allmeatpizza' + }, + { + name: 'Mega Burger', + id: 'megaburger' + }, + { + name: 'Curry Rice', + id: 'curryrice' + }, + { + name: 'Steak Sandwich', + id: 'steaksandwich' + }, + { + name: 'Spicy Tuna Roll', + id: 'spicytunaroll' + }, + { + name: 'Nachos', + id: 'nachos' + }, + { + name: 'Shrimp Tacos', + id: 'shrimptacos' + }, + { + name: 'Orange Chicken', + id: 'orangechicken' + }, + { + name: 'Chicken Parm Sandwich', + id: 'chickenparmsandwich' + }, + { + name: 'Virgin Mojito', + id: 'virginmojito' + }, + { + name: 'Chicken Tikka Masala', + id: 'chickentikkamasala' + }, + { + name: 'Bucket of Waffles', + id: 'bucketofwaffles' + }, + { + name: 'Boring Salad', + id: 'boringsalad' + } + ]; + + $scope.stop = function() { + clearTimeout(startTimer); + clearTimeout(messageTimeout); + clearInterval(timer); + gameStart = null; + + $scope.message = null; + $scope.requested = null; + enabled = false; + $scope.running = false; + $scope.items = []; + }; + + $scope.start = function() { + $scope.items = $.pluck(items,6); + $scope.message = {good: 'Starting in 3 seconds!'}; + $scope.stats = { + timer: '00:00', + level: rounds[level], + errors: 0, + success: 0 + }; + + startTimer = setTimeout(function() { + gameStart = new Date(); + timer = setInterval(function() { + updateTimer(); + },10); + + if ($scope.$$phase) { + $scope.message = null; + } else { + $scope.$apply(function($scope) { + $scope.message = null; + }); + } + + requestPress(); + enabled = true; + },3000); + $scope.running = true; + }; + + $scope.timer = '00:00'; + + }); \ No newline at end of file diff --git a/www/assets/js/util.js b/www/assets/js/util.js index 72e149bfd..757e9184c 100644 --- a/www/assets/js/util.js +++ b/www/assets/js/util.js @@ -129,3 +129,14 @@ Number.prototype.pad = String.prototype.pad = function(width, z) { var n = this + ''; return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n; } + + +$.pluck = function(ar, len) { + for (var i = ar.length - 1; i > 0; i--) { + var j = Math.floor(Math.random() * (i + 1)); + var temp = ar[i]; + ar[i] = ar[j]; + ar[j] = temp; + } + return ar.slice(0, len || len.length); +}; \ No newline at end of file