/
Simple_Simon.html
156 lines (111 loc) · 3.32 KB
/
Simple_Simon.html
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Simple Simon</title>
<link rel="stylesheet" href="simple_simon_css.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<div id="simonGame">
<div id="clickBMO">
<h1 id="title">BMO Says</h1>
<p>Start New Game</p>
<h2 id="level">Level : 0</h2>
</div>
<div id="1" class="princess bubblegum"></div>
<div id="2" class="princess flame"></div>
<div id="3" class="princess lumpyspace"></div>
<div id="4" class="princess marceline"></div>
</div>
<script src="jquery.js"></script>
<script>
var pattern = [];
var level = 0;
var lastSequence = [];
var sequenceCheck = false;
function randomNum(min, max) {
return Math.round(Math.random() * (max - min)) + min;
}
function addToPattern() {
var value = randomNum(1, 4);
pattern.push(value);
}
function animateSquare() {
var tile = pattern.pop();
sequenceCheck = true;
$('#' + tile).animate({
opacity: 0.2
}, 200).animate({
opacity: 1
}, 100);
lastSequence.push(tile);
}
function playPattern() {
for (var i = 0; i < pattern.length; i++) {
var delayTime = i * 500;
setTimeout(animateSquare, delayTime);
}
}
createClickEvent();
function createClickEvent() {
console.log($('.princess'));
$('.princess').click(function () {
console.log(lastSequence);
var tile = lastSequence.shift();
var tileId = $(this).attr('id');
$(this).animate({opacity: .2}, 200).animate({opacity: 1}, 100)
if (tile == tileId) {
pattern.push(tile);
if (lastSequence.length <= 0) {
level++;
$('#level').html('Level: ' + level);
addToPattern();
setTimeout(playPattern, 600);
}
} else {
sequenceCheck = false;
failSound();
$('h1').html('Game Over').css({});
$('p').html('Click to Restart');
pattern = [];
lastSequence = [];
}
if (level % 5 == 0) {
rewardSound();
}
});
}
function startGame() {
resetGame();
addToPattern();
playPattern();
}
function resetGame() {
level = 0;
$('#level').html('Level: ' + level);
$('h1').html('BMO Says').css({});
$('p').html('Click to Start Game');
}
$('#clickBMO').click(function () {
if (sequenceCheck === false) {
startGame();
startSound();
}
});
function failSound() {
var audio = new Audio('images/unacceptable.mp3');
audio.play();
}
function rewardSound() {
var audio = new Audio('images/oh_my_glob.mp3');
audio.play();
}
function startSound() {
var audio = new Audio('images/BMO_jam.mp3');
audio.play();
}
</script>
</body>
</html>