mirror of
https://github.com/ysoftdevs/pf2015.git
synced 2026-04-18 22:59:54 +02:00
automaticaly compute size of board
This commit is contained in:
@@ -68,9 +68,13 @@ flippy.fancy {
|
|||||||
position: relative;
|
position: relative;
|
||||||
font-size: .8em;
|
font-size: .8em;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
width: 150px;
|
|
||||||
height: 150px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flippy.fancy {
|
||||||
|
width: 60px;
|
||||||
|
height: 60px;
|
||||||
|
}
|
||||||
|
|
||||||
flippy.fancy img {
|
flippy.fancy img {
|
||||||
width:auto;
|
width:auto;
|
||||||
max-width:100%;
|
max-width:100%;
|
||||||
|
|||||||
@@ -2,9 +2,7 @@
|
|||||||
font-family: Arial, Helvetica, sans-serif;
|
font-family: Arial, Helvetica, sans-serif;
|
||||||
font-size: xx-large;
|
font-size: xx-large;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
background-color: #E3F0FB;
|
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
padding: 10px;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
.buttonStyle {
|
.buttonStyle {
|
||||||
@@ -36,7 +34,6 @@
|
|||||||
width: 5em;
|
width: 5em;
|
||||||
height: 5em;
|
height: 5em;
|
||||||
margin: 0.2em;
|
margin: 0.2em;
|
||||||
float: left;
|
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,14 +40,13 @@
|
|||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="mainContent" ng-controller="PexesoController" ng-show="isLevelVisible" ng-style="containerStyle">
|
||||||
<div id="mainContent" ng-controller="PexesoController" ng-show="isLevelVisible">
|
|
||||||
|
|
||||||
<flippy ng-repeat="card in board"
|
<flippy ng-repeat="card in board"
|
||||||
class="fancy"
|
class="fancy"
|
||||||
ng-class="card.flipState"
|
ng-class="card.flipState"
|
||||||
ng-click="selectCard(card)"
|
ng-click="selectCard(card)"
|
||||||
|
ng-style="cardStyle"
|
||||||
flip-duration="800"
|
flip-duration="800"
|
||||||
timing-function="ease-in-out">
|
timing-function="ease-in-out">
|
||||||
|
|
||||||
@@ -59,6 +58,7 @@
|
|||||||
<span class="cardHelper"></span><img ng-src="img/cards/{{card.cardId}}.png" ng-show="card.cardType == 'picture'"></span>
|
<span class="cardHelper"></span><img ng-src="img/cards/{{card.cardId}}.png" ng-show="card.cardType == 'picture'"></span>
|
||||||
<div ng-hide="card.cardType == 'picture'">{{card.card['en-US']}}</div>
|
<div ng-hide="card.cardType == 'picture'">{{card.card['en-US']}}</div>
|
||||||
</flippy-back>
|
</flippy-back>
|
||||||
|
|
||||||
|
|
||||||
</flippy>
|
</flippy>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -8,9 +8,20 @@ angular.module('app', ['angular-flippy', 'level-selector', 'level-complete'])
|
|||||||
// How many cards must be found as the same.
|
// How many cards must be found as the same.
|
||||||
$scope.chainLength = 2;
|
$scope.chainLength = 2;
|
||||||
|
|
||||||
// Whic card types are active
|
// Which card types are active
|
||||||
$scope.currentCardTypes = [ 'picture', 'picture' ];
|
$scope.currentCardTypes = [ 'picture', 'picture' ];
|
||||||
|
|
||||||
|
// Fit defined number of items on screen
|
||||||
|
$scope.containerStyle = {
|
||||||
|
"max-width": "280px"
|
||||||
|
};
|
||||||
|
|
||||||
|
// Card style - define dimensions
|
||||||
|
$scope.cardStyle = {
|
||||||
|
width: "60px",
|
||||||
|
height: "60px"
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Level descriptor:
|
* Level descriptor:
|
||||||
*
|
*
|
||||||
@@ -25,35 +36,54 @@ angular.module('app', ['angular-flippy', 'level-selector', 'level-complete'])
|
|||||||
$scope.levels = [
|
$scope.levels = [
|
||||||
{
|
{
|
||||||
totalCards: 2*2,
|
totalCards: 2*2,
|
||||||
|
cardsPerRow: 2,
|
||||||
chainLength: 2,
|
chainLength: 2,
|
||||||
cardTypes: ['picture', 'picture']
|
cardTypes: ['picture', 'picture']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
totalCards: 4*4,
|
totalCards: 3*3,
|
||||||
|
cardsPerRow: 3,
|
||||||
|
chainLength: 3,
|
||||||
|
cardTypes: ['picture', 'picture', 'picture']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
totalCards: 4*4,
|
||||||
|
cardsPerRow: 4,
|
||||||
|
chainLength: 4,
|
||||||
|
cardTypes: ['picture', 'picture', 'picture', 'picture']
|
||||||
|
}, {
|
||||||
|
totalCards: 4*4,
|
||||||
|
cardsPerRow: 4,
|
||||||
chainLength: 2,
|
chainLength: 2,
|
||||||
cardTypes: ['picture', 'picture']
|
cardTypes: ['picture', 'picture']
|
||||||
}, {
|
}, {
|
||||||
totalCards: 4*4,
|
totalCards: 4*4,
|
||||||
|
cardsPerRow: 4,
|
||||||
chainLength: 2,
|
chainLength: 2,
|
||||||
cardTypes: ['picture', 'en-US']
|
cardTypes: ['picture', 'en-US']
|
||||||
}, {
|
}, {
|
||||||
totalCards: 4*4,
|
totalCards: 4*4,
|
||||||
|
cardsPerRow: 4,
|
||||||
chainLength: 2,
|
chainLength: 2,
|
||||||
cardTypes: ['picture', 'oneLanguage']
|
cardTypes: ['picture', 'oneLanguage']
|
||||||
}, {
|
}, {
|
||||||
totalCards: 4*4,
|
totalCards: 4*4,
|
||||||
|
cardsPerRow: 4,
|
||||||
chainLength: 2,
|
chainLength: 2,
|
||||||
cardTypes: ['picture', 'randomLanguage']
|
cardTypes: ['picture', 'randomLanguage']
|
||||||
}, {
|
}, {
|
||||||
totalCards: 3*3,
|
totalCards: 3*3,
|
||||||
|
cardsPerRow: 3,
|
||||||
chainLength: 3,
|
chainLength: 3,
|
||||||
cardTypes: ['picture', 'picture', 'picture']
|
cardTypes: ['picture', 'picture', 'picture']
|
||||||
}, {
|
}, {
|
||||||
totalCards: 3*3,
|
totalCards: 3*3,
|
||||||
|
cardsPerRow: 3,
|
||||||
chainLength: 3,
|
chainLength: 3,
|
||||||
cardTypes: ['picture', 'randomLanguage', 'randomLanguage']
|
cardTypes: ['picture', 'randomLanguage', 'randomLanguage']
|
||||||
}, {
|
}, {
|
||||||
totalCards: 4*4,
|
totalCards: 4*4,
|
||||||
|
cardsPerRow: 4,
|
||||||
chainLength: 4,
|
chainLength: 4,
|
||||||
cardTypes: ['picture', 'randomLanguage', 'randomLanguage', 'randomLanguage']
|
cardTypes: ['picture', 'randomLanguage', 'randomLanguage', 'randomLanguage']
|
||||||
}
|
}
|
||||||
@@ -128,7 +158,6 @@ angular.module('app', ['angular-flippy', 'level-selector', 'level-complete'])
|
|||||||
|
|
||||||
|
|
||||||
$scope.cards = $scope.basicCards;
|
$scope.cards = $scope.basicCards;
|
||||||
$scope.maxSelected = 2;
|
|
||||||
|
|
||||||
$scope.board = [];
|
$scope.board = [];
|
||||||
|
|
||||||
@@ -202,8 +231,8 @@ angular.module('app', ['angular-flippy', 'level-selector', 'level-complete'])
|
|||||||
$scope.areAllSelectedSame = function() {
|
$scope.areAllSelectedSame = function() {
|
||||||
var previous = null;
|
var previous = null;
|
||||||
|
|
||||||
// At least two cards must match
|
// At least n-cards must match
|
||||||
if ($scope.selectedCards.length < 2) {
|
if ($scope.selectedCards.length < $scope.chainLength) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,7 +282,7 @@ angular.module('app', ['angular-flippy', 'level-selector', 'level-complete'])
|
|||||||
$scope.selectionCounter += 1;
|
$scope.selectionCounter += 1;
|
||||||
|
|
||||||
|
|
||||||
if ($scope.selectionCounter == $scope.maxSelected + 1) {
|
if ($scope.selectionCounter == $scope.chainLength + 1) {
|
||||||
$scope.resetSelection();
|
$scope.resetSelection();
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@@ -270,13 +299,41 @@ angular.module('app', ['angular-flippy', 'level-selector', 'level-complete'])
|
|||||||
if ($scope.isLevelComplete()) {
|
if ($scope.isLevelComplete()) {
|
||||||
$timeout($scope.completeLevel, 1000);
|
$timeout($scope.completeLevel, 1000);
|
||||||
}
|
}
|
||||||
} else if ($scope.selectionCounter == $scope.maxSelected) {
|
} else if ($scope.selectionCounter == $scope.chainLength) {
|
||||||
$timeout($scope.resetSelection, 1000);
|
$timeout($scope.resetSelection, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adjust size of card
|
||||||
|
*/
|
||||||
|
$scope.computeCardSize = function(cardsPerRow) {
|
||||||
|
var cardSize = Math.floor(Math.min(window.innerWidth, window.innerHeight) / cardsPerRow) - 20;
|
||||||
|
$scope.cardStyle = {
|
||||||
|
width: cardSize + "px",
|
||||||
|
height: cardSize + "px"
|
||||||
|
};
|
||||||
|
|
||||||
|
var paddingLeft = Math.floor((window.innerWidth - (cardSize + 10) * cardsPerRow) / 2);
|
||||||
|
var paddingTop = Math.floor((window.innerHeight - (cardSize + 10) * cardsPerRow) / 2);
|
||||||
|
|
||||||
|
if (paddingLeft < 0) {
|
||||||
|
paddingLeft = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (paddingTop < 0) {
|
||||||
|
paddingTop = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$scope.containerStyle = {
|
||||||
|
"max-width": (cardSize + 20) * cardsPerRow + "px",
|
||||||
|
"padding-left": paddingLeft + "px",
|
||||||
|
"padding-top": paddingTop + "px"
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start Level
|
* Start Level
|
||||||
*/
|
*/
|
||||||
@@ -284,6 +341,8 @@ angular.module('app', ['angular-flippy', 'level-selector', 'level-complete'])
|
|||||||
$scope.levelIndex = args.levelIndex;
|
$scope.levelIndex = args.levelIndex;
|
||||||
$scope.currentLevel = $scope.levels[$scope.levelIndex];
|
$scope.currentLevel = $scope.levels[$scope.levelIndex];
|
||||||
$scope.currentCardTypes = $scope.currentLevel.cardTypes;
|
$scope.currentCardTypes = $scope.currentLevel.cardTypes;
|
||||||
|
$scope.computeCardSize($scope.currentLevel.cardsPerRow);
|
||||||
|
$scope.chainLength = $scope.currentLevel.chainLength;
|
||||||
$scope.generateBoard($scope.currentLevel.totalCards);
|
$scope.generateBoard($scope.currentLevel.totalCards);
|
||||||
$scope.isLevelVisible = true;
|
$scope.isLevelVisible = true;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user