-
Notifications
You must be signed in to change notification settings - Fork 1
/
question.html
260 lines (228 loc) · 11.1 KB
/
question.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
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<title>Front-end Startup Template</title>
<!-- Material Design fonts -->
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:300,400,500,700">
<link rel="stylesheet" href="//fonts.googleapis.com/icon?family=Material+Icons">
<!-- Bootstrap -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<!-- Bootstrap Material Design -->
<link rel="stylesheet" href="lib/bootstrap-material-design/dist/css/bootstrap-material-design.css">
<link rel="stylesheet" href="lib/bootstrap-material-design/dist/css/ripples.min.css">
<link rel="stylesheet" href="css/style.css">
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<script src="//css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script>
<![endif]-->
<script src="https://cdn.socket.io/socket.io-1.2.0.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script src="lib/underscore/underscore.js"></script>
<script>
var socket = io();
var question;
$(function(){
socket.on('question', function(question_data){
$('.correct').removeClass('correct');
$('.wrong').removeClass('wrong');
$('.success').removeClass('success');
$('.danger').removeClass('danger');
$('#question-result-holder').hide();
question = question_data;
if(question){
$('#question-text').html(question.q_text);
//bravo be kalo!
var text = $('#question-text').text();
$('#question-text').html(text.trim());
$('#answer-1').text(question.q_options_1);
$('#answer-2').text(question.q_options_2);
$('#answer-3').text(question.q_options_3);
$('#answer-4').text(question.q_options_4);
}
else{
console.log('NO QUESTION');
}
});
socket.on('answer', function(answer_data){
console.log(answer_data);
var answer_div = $( '#answer-' + answer_data.answer ).closest('.answers__single-answer');
$('#question-result-holder').show();
if( answer_data.status ) {
$('#question-result-holder')
.removeClass('alert-warning alert-success')
.addClass('alert-success');
answer_div.addClass('correct');
$('#question-result').html(answer_data.player + ' ПОЗНА!');
}
else {
$('#question-result-holder')
.removeClass('alert-warning alert-success')
.addClass('alert-warning');
answer_div.addClass('wrong');
$( '#answer-' + question.q_correct_option ).closest('.answers__single-answer').addClass('correct');
$('#question-result').html(answer_data.player + ' ОБЪРКА!!!');
}
var leaderboard_html = "";
if( answer_data.players ){
console.log(answer_data.players);
answer_data.players = _.sortBy(answer_data.players, 'points').reverse();
var i = 0;
for( var player_id in answer_data.players ) {
var player = answer_data.players[player_id];
leaderboard_html += "<tr class='";
if(player.name == answer_data.player){
console.log("status " + answer_data.status);
if(answer_data.status){
leaderboard_html +="success";
}
else{
leaderboard_html +="danger";
}
}
leaderboard_html +="'>";
leaderboard_html += "<td>" + (i+1) + "</td>";
leaderboard_html += "<td>" + player.name + "</td>";
leaderboard_html += "<td>" + player.points + "</td>";
leaderboard_html += "</tr>";
i++;
}
$('#leaderboard').html(leaderboard_html);
}
});
socket.on('restart', function(){
window.location.reload();
});
socket.on('end game', function(player){
alert(player + ' СПЕЧЕЛИ!!! Другите сте ботове!');
setTimeout(function(){
socket.emit('new game', true);
window.location.reload();
}, 5000);
});
socket.emit('game started', true);
$('#new-game').on('click', function(){
socket.emit('new game', true);
})
});
</script>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-9">
<div class="page-header text-center">
<h1 style="font-size: 50px;" id="question-text">...?</h1>
</div>
<div id="question-result-holder" class="alert alert-warning" style="display: none;">
<p id="question-result"></p>
</div>
<div class="answers">
<div class="row">
<div class="col-md-6">
<div class="text-center answers__single-answer">
<span id="answer-1">...</span>
<div class="answers__single-answer__border color--choice1"></div>
</div>
</div>
<div class="col-md-6">
<div class="text-center answers__single-answer">
<span id="answer-2">...</span>
<div class="answers__single-answer__border color--choice2"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="text-center answers__single-answer">
<span id="answer-3">...</span>
<div class="answers__single-answer__border color--choice3"></div>
</div>
</div>
<div class="col-md-6">
<div class="text-center answers__single-answer">
<span id="answer-4">...</span>
<div class="answers__single-answer__border color--choice4"></div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-3">
<div class="well side-panel">
<div class="page-header">
<h3 id="tables">Резултат</h3>
</div>
<table class="table table-striped table-hover">
<thead>
<tr>
<th>#</th>
<th>Играч</th>
<th>Резултат</th>
</tr>
</thead>
<tbody class="text-left" id="leaderboard">
</tbody>
</table>
<button class="btn btn-warning btn-default" data-toggle="modal" data-target="#myModal">Харесай ни, майка!</button>
<button id="new-game" class="btn btn-primary btn-raised" data-toggle="modal" data-target="#myModal">Рестартирай света</button>
</div>
</div>
</div>
</div>
<!-- Това е модал, майка! -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">И ние те харесваме, майка!</h4>
</div>
<div class="modal-body">
<div id="loading" style="display: none;">Зареждаме коте ...</div>
<div id="kote-success" style="display: none;">Това е коте:</div>
<img id="kote" alt="" class="img-responsive" style="max-height: 350px;" />
<script>
$(function(){
$('#myModal').on('show.bs.modal', function(){
$('#loading').show();
$.ajax({
url: 'https://nijikokun-random-cats.p.mashape.com/random',
headers: {
"X-Mashape-Key": "rCHR14UA0imshTfNn7uYk7sMByXCp1YTB2Ijsny27oo25nA7oB",
"Accept": "application/json"
}
})
.done(function(data){
$('#loading').hide();
$('#kote-success').show();
$('#kote').attr('src', data.source);
});
})
.on('hide.bs.modal', function(){
$('#loading').show();
$('#kote-success').hide();
$('#kote').attr('src', '');
});
});
</script>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">БХ</button>
</div>
</div>
</div>
</div>
<script src="lib/jquery/dist/jquery.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="lib/bootstrap-material-design/dist/js/material.js"></script>
<script src="lib/bootstrap-material-design/dist/js/ripples.js"></script>
<script>
$(function(){
$.material.init();
});
</script>
</body>
</html>