-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.js
36 lines (31 loc) · 1.21 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
app.service('Utils', function ($q) {
var makeNumber = function (multiplier) {
return Math.floor(Math.random() * (multiplier || 10));
};
this.makeCard = function () {
// found in images folder i.e. oldie-[*].jpg
var numOfImages = 10;
return {
'cardDetails': {
'population': makeNumber(1000000),
'coastline (km)': makeNumber(500),
'GDP': 1,
'area (km2)': makeNumber(30000)
},
'chosenProperty': null,
'imageUrl': 'images/country-' +
(Math.ceil(Math.random() * numOfImages)) + '.jpg'
};
};
// A draw is null
// This is going to have to be replaced if the values become more complex
// or different winning factors have to be taken into consideration.
this.calculateWinner = function (property, opponentCard, myCard) {
var didIwin = opponentCard[property] === myCard[property] ?
null :
myCard[property] > opponentCard[property], // true or false
winLoseDraw = didIwin === null ? 'draw' :
didIwin ? 'me' : 'opponent';
return $q.when(winLoseDraw);
};
})