-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
217 lines (165 loc) · 4.32 KB
/
Copy pathindex.html
File metadata and controls
217 lines (165 loc) · 4.32 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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<!DOCTYPE html>
<html>
<head>
<title>
</title>
<link rel="stylesheet" href="styles.css">
<script src="main.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.js"
integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
</head>
<body>
<div id='mainScreen'>
<div id ='logIn'>
<table id ='table2'>
<tr>
<td class='utable'>
User Name:
</td>
<td class='utable'>
<input type="text" id='userName'><br>
</td>
</tr>
<tr>
<td class='utable'>
Password:
</td>
<td class='utable'>
<input type="password" id='passWord'><br>
</td>
</tr>
</table>
<button id ='log'>Log In</button>
</div>
<div id='table'>
<table id='table1'>
<tr>
<td class='cell' id='1'>a</td>
<td class='cell' id='2'>a</td>
<td class='cell' id='3'>a</td>
<td class='cell' id='4'>a</td>
<td class='cell' id='5'>a</td>
</tr>
<tr>
<td class='cell' id='6'>a</td>
<td class='cell' id='7'>a</td>
<td class='cell' id='8'>a</td>
<td class='cell' id='9'>a</td>
<td class='cell' id='10'>a</td>
</tr>
<tr>
<td class='cell' id='11'>a</td>
<td class='cell' id='12'>a</td>
<td class='cell' id='13'>a</td>
<td class='cell' id='14'>a</td>
<td class='cell' id='15'>a</td>
</tr>
<tr>
<td class='cell' id='16'>a</td>
<td class='cell' id='17'>a</td>
<td class='cell' id='18'>a</td>
<td class='cell' id='19'>a</td>
<td class='cell' id='20'>a</td>
</tr>
</table>
</div>
<div id='won'>
</div>
<div id='error'>Your user name or password is wrong</div>
<div id='button'>
<button id='start'>START</button>
<button id='show'>HINT</button>
<button id='reset'>Reset</button>
<button id='logOut'>LogOut</button>
<button id='score'>Score</button>
</div>
<div id='divScore'>
</div>
</div>
<script>
//here we start the code
var cells=document.querySelectorAll('.cell'); //save all the classes of the cells in the table inside the cells variable
$(document).ready(function(){
//hide divs exept log in div
$('#error').hide();
$('#table').hide();
$('#won').hide();
$('#button').hide();
$('#show').hide();
$('#reset').hide();
$('#logOut').hide();
//give the cells some attributs
$('.cell').css('border', 'solid black 1px');
$('.cell').css('width','60px')
$('.cell').css('height','60px')
//when we click on the log in button
$('#log').click(function(){
$('#show').hide();
$('#reset').hide();
$('#start').show();
//save the userName and Password in variabels
var $userName=$('#userName').val();
var $passWord=$('#passWord').val();
//chick if the userName and pass is correct
for(var i=0;i<users.length;i++){
if(users[i].name===$userName&&users[i].pass===$passWord){
//make a new variable called id to store the id of the user
id=users[i].id;
$('#error').hide();
$('#logIn').slideUp(1000);
$('#button').show();
break;
}else{
$('#error').show();
}
}
})
//when we click on start button call the startgame()
$('#start').click(function(){
startGame();
});
//when click on the hint button it will show all the numbers to the user for 1.5 sec
$('#show').click(function(){
console.log(correctNum)
for(var i=1 ; i<=20 ; i++){
$('#'+i).html(allNumberArray[i-1]);
cells[i-1].removeEventListener('click',showCell);
}
setTimeout(function(){
for(var i=1 ; i<=20 ; i++){
if(!correctNum.includes(i.toString())){
$('#'+i).html('');
cells[i-1].addEventListener('click',showCell);
}
}
},1500)
})
//start the game from the begging
$('#reset').click(function(){
cellId=[];
checkClick=0;
correctNum=[];
$('#divScore').slideUp(500);
startGame();
})
//go back to the first page
$('#logOut').click(function(){
cellId=[];
checkClick=0;
correctNum=[];
id=0;
$('#logIn').slideDown(1000);
$('#divScore').slideUp(500);
$('#button').slideUp(1000);
$('#table').slideUp(1000);
$('#won').slideUp(1000);
})
//display the score of the player
$("#score").click(function(){
$('#divScore').slideDown(500);
$('#divScore').html(users[id-1].name +' you win '+users[id-1].numberOfWoningGame +' Games <br>' + ' your high score in all games: <br>'+users[id-1].highScore )
})
});
</script>
</body>
</html>