forked from Vishnupriya1507/ACMW-Apogee-2k19
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.html
385 lines (365 loc) · 9.72 KB
/
db.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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
{% extends "base.html" %}
{% load staticfiles %}
{% block content %}
<style type="text/css">
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
/* Modal Content */
.modal-content {
background-color: #fefefe;
margin: auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}
/* The Close Button */
.close {
color: #aaaaaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
.board{
width:343px;
background: #ab9c8e;
display: block;
}
.box {
width:70px;
height: 70px;
margin-left: 10px;
margin-top:10px;
margin-bottom:0px;
display: inline-block;
background: #e9ded1;
margin-right: 0px;
padding-right: 0px;
}
.box-2{
background: #eee4da;
}
.box-4{
background:#ede0c8;
}
.box-8{
background: #f2b179;
}
.box-16{
background: #f59563;
}
.box-32{
background:#f67c5f;
}
.box-64{
background: #f65e3b;
}
.box-128{
background: #edcf72;
}
.box-256{
background: #edcc61;
}
.box-512{
background: #edc850;
}
.box-1024{
background: #edc53f;
}
.box-2048{
background: #edc22e;
box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.55556), inset 0 0 0 1px rgba(255, 255, 255, 0.33333);
}
.edge {
margin-right: 10px;
}
.last {
margin-bottom: 10px;
}
.capture {
background: transparent;
border: none;
height: 90px;
width: 90px;
text-align: center;
font-size: 20px;
}
</style>
<div class="container">
<p id = "demo"></p>
<button type="button" onclick="myfunction()">Click Me!</button>
<h2>2048</h2>
<span id="user-username">{{ request.user.username }}</span>
<div>SCORE:</div>
<span id = "scoredisp"></span>
<h2>Modal Example</h2>
<!-- Trigger/Open The Modal -->
<button id="myBtn">Open Modal</button>
<!-- The Modal -->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<p>First Name: <input type="text" id="myText" value="Mickey"></p>
<p id = "check">Hello</p>
<button id = "bt" onclick = "sendans()">Submit</button>
</div>
</div>
<div ng-app="GameApp" ng-controller="GameCtrl" >
<div class="row">
<div class="col-md-offset-8 col-md-2">
<!-- <button ng-click="renew()" class="btn btn-primary"><span class="glyphicon glyphicon glyphicon glyphicon-repeat" aria-hidden="true"></span>
New</button> -->
</div>
</div>
<br/>
<div id="board" class="board" ng-keyup="key($event)" tabindex="1">
<div class="box" ng-class="getClass(0)">
<input ng-value="print(0)" disabled class="capture">
</div>
<div class="box" ng-class="getClass(1)">
<input ng-value="print(1)" disabled class="capture">
</div>
<div class="box" ng-class="getClass(2)">
<input ng-value="print(2)" disabled class="capture">
</div>
<div class="box edge" ng-class="getClass(3)">
<input ng-value="print(3)" disabled class="capture">
</div>
<div class="box" ng-class="getClass(4)">
<input ng-value="print(4)" disabled class="capture">
</div>
<div class="box" ng-class="getClass(5)">
<input ng-value="print(5)" disabled class="capture">
</div>
<div class="box" ng-class="getClass(6)">
<input ng-value="print(6)" disabled class="capture">
</div>
<div class="box edge" ng-class="getClass(7)">
<input ng-value="print(7)" disabled class="capture">
</div>
<div class="box" ng-class="getClass(8)">
<input ng-value="print(8)" disabled class="capture">
</div>
<div class="box" ng-class="getClass(9)">
<input ng-value="print(9)" disabled class="capture">
</div>
<div class="box" ng-class="getClass(10)">
<input ng-value="print(10)" disabled class="capture">
</div>
<div class="box edge" ng-class="getClass(11)">
<input ng-value="print(11)" disabled class="capture">
</div>
<div class="box last" ng-class="getClass(12)">
<input ng-value="print(12)" disabled class="capture">
</div>
<div class="box last" ng-class="getClass(13)">
<input ng-value="print(13)" disabled class="capture">
</div>
<div class="box last" ng-class="getClass(14)">
<input ng-value="print(14)" disabled class="capture">
</div>
<div class="box edge last" ng-class="getClass(15)">
<input ng-value="print(15)" disabled class="capture">
</div>
</div>
</div>
</div>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
<script src="//code.angularjs.org/1.5.8/angular-resource.min.js"></script>
<script src="{% static 'hammer.min.js'%}"></script>
<script>
var yes = 1;
function display(str){
document.getElementById('check').innerHTML =str;
modal.style.display = "block";
console.log(str);
console.log("done");
}
const getAns = () => {
console.log(document.getElementById('myText').value);
return document.getElementById('myText').value;
};
const makeRequest = (url,data,method) =>{
var csrf_token = document.cookie.split('=')[1];
console.log(data);
let request = new XMLHttpRequest();
request.open(method,url,true);
request.setRequestHeader("Content-type","application/json");
request.setRequestHeader("X-CSRFToken",csrf_token);
request.onreadystatechange = () => {
if(request.readyState === 4 && request.status === 200){
//suuccessfully recieved response
let dataRetrieved = JSON.parse(request.responseText);
//processData(dataRetrieved);
}
else if(request.readyState === 4 && request.status !== 200){
console.log('Error in fetching data...');
}
};
request.send(JSON.stringify(data));
};
const sendans = () => {
let ans = getAns();
let obj = {'answer':ans, 'board_state': 2, 'user_': document.getElementById('user-username').innerHTML };
modal.style.display = "none";
let url = '/do/';
makeRequest(url,obj,"POST");
};
// Get the modal
var modal = document.getElementById('myModal');
// Get the button that opens the modal
var btn = document.getElementById("myBtn");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
function myfunction(){document.getElementById('demo').innerHTML = "DONE";}
var app = angular.module('GameApp', ["ngResource"]);
app.factory('Game', ['$resource',
function($resource) {
return $resource('/do', {}, {
renew: {
method: 'GET',
isArray: true
},
process: {
method: 'POST'
}
});
}
]);
app.config(['$httpProvider',function($httpProvider) {
$httpProvider.defaults.xsrfCookieName = 'csrftoken';
$httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';
}]);
app.controller("GameCtrl",function($scope,Game){
$scope.board = [];
var UP=0;
var DOWN=1;
var LEFT=2;
var RIGHT=3;
var GAME_OVER=false;
for(var i = 0;i<16;i++){
$scope.board[i] = 0;
}
var hammertime = new Hammer(document.body);
hammertime.get('swipe').set({ direction: Hammer.DIRECTION_ALL });
hammertime.on('swipeleft', function(ev) {
$scope.process(LEFT);
});
hammertime.on('swiperight', function(ev) {
$scope.process(RIGHT);
});
hammertime.on('swipeup', function(ev) {
$scope.process(UP);
});
hammertime.on('swipedown', function(ev) {
$scope.process(DOWN);
});
$scope.key =function(event) {
console.log(event.keyCode);
var direction=-1;
switch(event.keyCode){
case 38:
direction = UP;
break;
case 40:
direction =DOWN;
break;
case 37:
direction = LEFT;
break;
case 39:
direction = RIGHT;
break;
}
if(direction != -1) {
$scope.process(direction);
}
}
$scope.process = function(direction){
if(GAME_OVER){
alert("Game over");
return;
}
Game.process({
board:$scope.board,
direction: direction,
board_state: yes
}).$promise.then(showBoard);
}
var showBoard = function(response) {
console.log(response);
console.log("start");
//console.log(response.revealQues_dict.curr_ques_Ques);
//display(response.revealQues_dict.curr_ques_Ques);
console.log("end");
if(!response.continue) {
alert("Game over");
GAME_OVER=true;
}else{
if(response.board_state == 2){
yes = 3;
display(response.curr_ques_Ques);
}
else if(response.board_state == 1){$scope.board = response.board;
$scope.score = response.score;}
}
console.log("yyyyyayyyy");
console.log(response.board[0]);
console.log($scope.score);
document.getElementById('scoredisp').innerHTML = 0;
}
$scope.renew = function() {
$scope.board = Game.renew();
GAME_OVER=false;
document.getElementById('board').focus();
}
$scope.print = function(n){
var bh;
var arr = ["A","B","C","D","E","F","G"];
if($scope.board[n] == 512){alert("GAME END");
window.location = "/";}
bh = arr[Math.log2($scope.board[n])];
document.getElementById('scoredisp').innerHTML = $scope.score;
return $scope.board[n]==0?"":bh;
//document.getElementById('scoredisp').innerHTML = $scope.score;
}
//
$scope.getClass = function(n) {
return $scope.board[n]==0?"":"box-"+$scope.board[n];
}
$scope.renew();
});
alert
</script>
{% endblock %}