-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.js
81 lines (80 loc) · 2.52 KB
/
common.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
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
var numberOfFaces = 2;
var leftSide = document.getElementById('leftSide');
var rightSide = document.getElementById('rightSide');
var body = document.getElementById('mainDiv');
var start = document.getElementById('start');
var startGame = document.getElementById('startGame');
var shortGame = document.getElementById('shortGame');
var longGame = document.getElementById('longGame');
var exit = document.getElementById('exit');
var gameOver = document.getElementById('gameOver');
var f = document.getElementById('f');
var tryAgain = document.getElementById('tryAgain');
var countOfRightChoise = 0;
var checkTypeOfGame;
var myGame = function() {
for(i=0; i<numberOfFaces; i++) {
var img = document.createElement('img');
img.src = 'http://home.cse.ust.hk/~rossiter/mooc/matching_game/smile.png';
img.style.left = Math.floor(Math.random()*401) + 'px';
img.style.top = Math.floor(Math.random()*401) + 'px';
leftSide.appendChild(img);
}
leftSideImgs = leftSide.cloneNode(true);
leftSideImgs.removeChild(leftSideImgs.lastChild);
rightSide.appendChild(leftSideImgs);
leftSide.lastChild.onclick = function nextLevel(event) {
while(leftSide.firstChild) {
leftSide.removeChild(leftSide.firstChild);
}
rightSide.removeChild(rightSide.lastChild);
event.stopPropagation();
ChooseTypeOfGame(numberOfFacesAddition, checkTypeOfGame);
countOfRightChoise += 1;
myGame();
};
leftSide.onclick = function() {
gameOver.style.display = 'block';
body.onclick = null;
leftSide.lastChild.onclick = null;
exit.style.display = 'none';
f.innerHTML = countOfRightChoise;
};
startGame.onclick = function() {
startGame.style.display = 'none';
shortGame.style.display = 'block';
longGame.style.display = 'block';
};
shortGame.onclick = function() {
start.style.display = 'none';
exit.style.display = 'block';
checkTypeOfGame = 5;
};
longGame.onclick = function() {
start.style.display = 'none';
exit.style.display = 'block';
checkTypeOfGame = 2;
};
var numberOfFacesAddition = function(number) {
numberOfFaces += number;
};
function ChooseTypeOfGame(fn, num) {
if(checkTypeOfGame === 5) {
if(fn(num)) {
num = checkTypeOfGame;
return num;
}
} else if(checkTypeOfGame === 2) {
if(fn(num)) {
num = checkTypeOfGame;
return num;
}
}
}
exit.onclick = function() {
window.location.reload();
}
tryAgain.onclick = function() {
window.location.reload();
};
};