forked from johannes-riesterer/Schrottchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
257 lines (209 loc) · 8.53 KB
/
index.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
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>-C-rapcpoin</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<style>
#role {
display: inline-block;
width: 150px;
hight: 150px;
}
#solve {
display: inline-block;
width: 150px;
height: auto;
}
.row {
width: 100%;
height: auto;
}
.number {
display: inline-block;
width: 100px;
height: 110px;
background-image: url("assets/number.png");
background-size: cover;
text-align: center;
vertical-align: middle;
line-height: 114px;
font-size: 60px;
color: white;
}
.question {
display: inline-block;
width: 120px;
height: 130px;
background-image: url("assets/question.png");
background-size: cover;
text-align: center;
vertical-align: middle;
line-height: 134px;
font-size: 60px;
color: white;
}
.chainNumber {
display: inline-block;
width: 100px;
height: 110px;
background-image: url("assets/question.png");
background-size: cover;
text-align: center;
vertical-align: middle;
line-height: 114px;
font-size: 60px;
color: white;
}
.pairs {
display: inline-block;
width: 100px;
height: 110px;
background-image: url("assets/pairs.png");
background-size: cover;
text-align: center;
vertical-align: middle;
line-height: 114px;
font-size: 40px;
color: black;
}
#rules {
font-size: 15px;
}
#rules h1{
font-size: 30px;
}
#k{
display: inline-block;
}
#n{
display: inline-block;
}
</style>
</head>
<body>
<div id="rules"><h1>Rules: </h1>
1) Solve the problem by selecting <div id="k">4</div> out of <div id="n">6</div> given numbers, such that they sum up to the given number in the big black circle. The Leftmost number in the small black circle must allways be included. <br>
2) The Person who solves the problem first can pull from bag. If he already owns an item, he can swap it with any other or give it away as present.
</div>
<div class="row">
<img src="assets/shitcoin.png" id="role">
<img src="assets/trash.png" id="solve">
<div id="params">
<div>Numbers<input type="number" id="param_n" value="5"></div>
<div>Choices<input type="number" id="param_k" value="3"></div>
<div>Min<input type="number" id="param_min" value="1"></div>
<div>Max<input type="number" id="param_max" value="10"></div>
</div>
</div>
<div class="row">
<div class="question">
<div id="sum"> </div>
</div>
</div>
<div class="row" id="numbers">
</div>
<div class="row" id="answers">
</div>
<div class="row">
<div id="solution"></div>
</div>
<script>
var randomNumbers = [0, 0, 0, 0, 0];
var randomIndices = [0, 0, 0]
var sum;
var lastSum = 0;
var min = 1;
var max = 10;
var solved = false;
document.getElementById("role").onclick = function() {
roleTheDice();
};
document.getElementById("solve").onclick = function() {
var answer = 0;
all_answers = document.getElementById("answers").children
for (var i = 0; i < randomIndices.length; i++) {
answer = answer + parseInt(all_answers[i].value);
}
console.log(answer)
if (answer == sum && solved == false) {
solved = true;
lastSum = lastSum + sum;
all_numbers = document.getElementById("numbers").children
markedNodes = [];
for (var i = 0; i < randomIndices.length; i++) {
marked = false;
for (var j = 0; j < randomNumbers.length; j++) {
if (parseInt(all_answers[i].value) == randomNumbers[j]) {
if (marked == false) {
if (markedNodes.includes(j) == false) {
all_numbers[j + 1].style.background = "green"
marked = true;
markedNodes.push(j);
}
}
}
}
}
}
else {
for (var i = 0; i < randomIndices.length; i++) {
all_answers[i].value = "";
}
}
};
function roleTheDice() {
solved = false;
document.getElementById("numbers").innerHTML = "";
document.getElementById("answers").innerHTML = "";
randomNumbers = new Array(parseInt(document.getElementById("param_n").value));
randomIndices = new Array(parseInt(document.getElementById("param_k").value));
document.getElementById("n").innerHTML = randomNumbers.length+1;
document.getElementById("k").innerHTML = randomIndices.length+1;
min = parseInt(document.getElementById("param_min").value)
max = parseInt(document.getElementById("param_max").value)
var lastSumElement = document.createElement("div");
lastSumElement.setAttribute("class", "chainNumber");
lastSumElement.innerHTML = lastSum;
document.getElementById("numbers").appendChild(lastSumElement);
for (var i = 0; i < randomNumbers.length; i++) {
randomNumbers[i] = Math.floor(Math.random() * max) + min;
var number = document.createElement("div");
number.setAttribute("class", "number");
number.innerHTML = randomNumbers[i];
document.getElementById("numbers").appendChild(number);
}
for (var i = 0; i < randomIndices.length; i++) {
var answer = document.createElement("input");
answer.setAttribute("class", "answer");
document.getElementById("answers").appendChild(answer);
}
console.log(randomNumbers);
for (var i = 0; i < randomIndices.length; i++) {
var chosen = true;
var index = 0;
while (chosen) {
index = Math.floor(Math.random() * randomNumbers.length - 1) + 1;
chosen = false;
for (var j = 0; j < i; j++) {
if (randomIndices[j] == index) {
chosen = true;
}
}
}
randomIndices[i] = index;
}
sum = 0;
for (var i = 0; i < randomIndices.length; i++) {
sum = sum + randomNumbers[randomIndices[i]];
}
document.getElementById("sum").innerHTML = sum + lastSum;
}
</script>
</body>
</html>