-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflag.js
More file actions
82 lines (78 loc) · 3.11 KB
/
flag.js
File metadata and controls
82 lines (78 loc) · 3.11 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// flag class, for création of each flag in the game, just add a line with the options and to the array
var count;
var flag = function (pCountry, pNumberOfColor, color1, color2, color3, pDirection) {
var country = pCountry;
var optimalClics;
var colors = new Array(pNumberOfColor);
colors[0] = color1;
colors[1] = color2;
var direction = pDirection;
if (pNumberOfColor >= 3) {
colors[2] = color3;
}
var id = count++;
return {
getCountry: function () {
return country;
},
getColor: function (value) {
return colors[value];
},
getId: function () {
return id;
},
getColors: function () {
return colors;
},
getOptmimalClics: function () {
return optimalClics;
},
getDirection: function () {
return direction;
},
setOptimalClic: function (value) {
optimalClics = value;
}
}
}
//creation of basic flag for the game, more can be add later based on row3, column3, row2 and row2triangle pattern
var flagFrance = flag("france", 3, "blue", "white", "red", "row3");
var flagBelgique = flag("belgique", 3, "black", "yellow", "red", "row3");
var flagAllemagne = flag("allemagne", 3, "black", "red", "yellow", "column3");
var flagHollande = flag("hollande", 3, "red", "white", "blue", "column3");
var flagPologne = flag("pologne", 2, "white", "red", null, "row2");
var flagTcheque = flag("tcheque", 4, "white", "red", "blue", "row2triangle");
var flagAutriche = flag("autriche", 3, "red", "white", "red", "row3");
// array of all flag
var allFlag = [flagFrance, flagBelgique, flagAllemagne, flagHollande, flagPologne, flagTcheque, flagAutriche];
// create a new flag, with the div etc..
function createFlag(flag) {
var flagDiv = $(".drapeau");
var numberOfDiv;
flagDiv.attr("id", flag.getDirection());
flagDiv.append("<h1>" + flag.getCountry().charAt(0).toUpperCase() + flag.getCountry().slice(1) + "</h1>");
numberOfDiv = flag.getColors().length;
flagDiv.append("<div>");
for (let i = 0; i < numberOfDiv; i++) {
flagDiv.children().last().append("<div></div>");
}
var colorAtual = new Array();
flagDiv.children().filter("div").children().each(function () {
$(this).addClass(allColorSwitch[Math.floor(Math.random() * 5)]);
colorAtual.push($(this).attr("class"))
});
var colorSoluce = flag.getColors();
var totalOptimalClic = 0;
for (let i = 0; i < colorSoluce.length; i++) {
var numberOfClicForOneColor = allColorSwitch.indexOf(colorSoluce[i]) - allColorSwitch.indexOf(colorAtual[i])
if (numberOfClicForOneColor < 0) {
numberOfClicForOneColor = allColorSwitch.length - allColorSwitch.indexOf(colorAtual[i]) + allColorSwitch.indexOf(colorSoluce[i])
}
totalOptimalClic += numberOfClicForOneColor;
}
flag.setOptimalClic(totalOptimalClic);
if (flag.getDirection().indexOf("triangle") >= 0) {
flagDiv.children().filter("div").children().eq(2).attr('id', 'triangle');
}
switchColor(flag.getDirection());
}