commit 4dd6fa8c36ab4f5b6fb3f1d29a84af8dd89c268c Author: Juraj Michalek Date: Tue Dec 23 21:36:31 2014 +0000 initial commit diff --git a/css/pexeso.css b/css/pexeso.css new file mode 100644 index 0000000..c76274d --- /dev/null +++ b/css/pexeso.css @@ -0,0 +1,58 @@ +#mainContent { + font-family: Arial, Helvetica, sans-serif; + font-size: xx-large; + font-weight: bold; + background-color: #E3F0FB; + border-radius: 4px; + padding: 10px; + text-align: center; +} +.buttonStyle { + border-radius: 4px; + border: thin solid #F0E020; + padding: 5px; + background-color: #F8F094; + font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; + font-weight: bold; + color: #663300; + width: 75px; +} + +.buttonStyle:hover { + border: thin solid #FFCC00; + background-color: #FCF9D6; + color: #996633; + cursor: pointer; +} +.buttonStyle:active { + border: thin solid #99CC00; + background-color: #F5FFD2; + color: #669900; + cursor: pointer; +} + +.card { + width: 10em; + height: 10em; +} + +.solved { + background: green; +} + +.selected1 { + background: yellow; +} + +.selected2 { + background: orange; +} + +.selected3 { + background: white; +} + +.mystery { + background: blue; + color: blue; +} \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..35964ff --- /dev/null +++ b/index.html @@ -0,0 +1,21 @@ + + + + + +PF2015 + + + + + + +
+
{{card.cardId}}
+ + + diff --git a/js/pexeso-controller.js b/js/pexeso-controller.js new file mode 100644 index 0000000..c1fba5e --- /dev/null +++ b/js/pexeso-controller.js @@ -0,0 +1,202 @@ +angular.module('app', []) +.controller('PexesoController', ['$scope', function($scope) { + $scope.languages = { + 'cs-CZ': { + title: 'Čeština' + }, + 'en-US': { + title: 'English' + }, + 'sk-SK': { + title: 'Slovenčina' + } + }; + + $scope.basicCards = { + 'printer' : { + 'cs-CZ': 'tiskárna', + 'en-US': 'house', + 'sk-SK': 'tlačiareň' + }, + 'toner' : { + 'cs-CZ': 'toner', + 'en-US': 'toner', + 'sk-SK': 'toner' + }, + 'finisher': { + 'cs-CZ': 'finisher', + 'en-US': 'finisher', + 'sk-SK': 'finisher' + }, + 'paper': { + 'cs-CZ': 'papír', + 'en-US': 'paper', + 'sk-SK': 'papier' + }, + 'black': { + 'cs-CZ': 'černá', + 'en-US': 'black', + 'sk-SK': 'čierna' + }, + 'white': { + 'cs-CZ': 'bílá', + 'en-US': 'white', + 'sk-SK': 'biela' + }, + 'color': { + 'cs-CZ': 'barva', + 'en-US': 'color', + 'sk-SK': 'farba' + }, + 'duplexPrint': { + 'cs-CZ': 'oboustranný tisk', + 'en-US': 'duplex print', + 'sk-SK': 'obostranná tlač' + }, + 'stapler': { + 'cs-CZ': 'sešívačka', + 'en-US': 'stapler', + 'sk-SK': 'zošívačka' + } + }; + + + $scope.cards = $scope.basicCards; + $scope.maxSelected = 2; + + $scope.board = [ + { + cardId:'house', + index:1, + state: 'solved' + }, { + cardId: 'dog', + index:1, + state: 'mystery' + }, { + cardId:'house', + index:2, + state: 'solved' + }, { + cardId:'printer', + index:1, + state: 'mystery' + }, { + cardId: 'dog', + index:2, + state: 'mystery' + },{ + cardId:'printer', + index:2, + state: 'mystery' + } + ]; + + /** + * Generate playing card object. + */ + $scope.getCard = function(card, cardId, index) { + return { + cardId: cardId, + card: card, + index: index, + state: 'mystery' + }; + }; + + /** + * Generate playing board. + */ + $scope.generateBoard = function(totalCount) { + $scope.board = []; + var stack = []; + angular.forEach($scope.basicCards, function(card, cardId) { + stack.push($scope.getCard(card, cardId, 1)); + stack.push($scope.getCard(card, cardId, 2)); + }); + + for (var index = 0; index < totalCount; index++) { + var coordinate = Math.floor((Math.random()* stack.length)); + $scope.board.push(stack[coordinate]); + stack.splice(coordinate, 1); + } + }; + + + $scope.selectionCounter = 0; + + $scope.selectedCards = []; + + /** + * Set state of all selected cards to defined state. + */ + $scope.setSelectionState = function(state) { + $scope.selectionCounter = 0; + angular.forEach($scope.selectedCards, function(card) { + card.state = state; + }); + $scope.selectedCards = []; + }; + + /** + * Check whether all cards were selected. + */ + $scope.areAllSelectedSame = function() { + var previous = null; + + // At least two cards must match + if ($scope.selectedCards.length < 2) { + return false; + } + + for (var index=0; index<$scope.selectedCards.length; index++) { + + var card = $scope.selectedCards[index]; + if (previous === null) { + previous = card; + } else { + if (previous.cardId != card.cardId) { + return false; + } + } + } + return true; + }; + + /** + * Click handler to select card. + */ + $scope.selectCard = function(card) { + // only mystery cards are processed + if (card.state != 'mystery') { + return; + } + + $scope.selectionCounter += 1; + + if ($scope.selectionCounter == $scope.maxSelected + 1) { + $scope.setSelectionState('mystery'); + return; + } else { + $scope.selectedCards.push(card); + } + + if (card.state == 'mystery') { + card.state = 'selected' + $scope.selectionCounter; + } + + if ($scope.areAllSelectedSame()) { + $scope.setSelectionState('solved'); + } + + }; + + + /** + * Initialize game. + */ + $scope.init = function() { + $scope.generateBoard(4*4); + }; + +}]); \ No newline at end of file