-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
292 lines (265 loc) · 13.5 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
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
<!DOCTYPE html>
<html>
<head>
<meta charset = "UTF-8">
<title>What are the odds</title>
<style>
body {
font-family: 'PT Sans', sans-serif;
}
.selector {
padding-top: 30px;
display: grid;
gap: 30px;
justify-content: space-around;
align-items: start;
}
.selector-tile {
max-width: 20em;
border-radius: 20px;
padding: 5px 15px;
box-shadow: 0px 0px 10px grey;
}
.selector-tile:hover {
background-color: rgb(248, 248, 248)
}
.selector-tile > h1 {
margin-top: 0.5em;
margin-bottom: 0px;
}
.number-input {
display: grid;
justify-content: center;
gap: 30px;
}
.number-input > h1 {
margin-bottom: 0;
}
.input-div-wrapper {
display: grid;
justify-items: center;
}
.input-div {
font-size: 3em;
}
.next-button-wrapper {
display: grid;
justify-items: end;
}
input {
border-style: solid;
border-color: black;
border-width: 5px;;
font-size: 1em;
max-width: 2em;
}
button {
padding: 0.5em;
border: none;
font-size: 1.25em;
font-weight: bold;
background-color: rgb(224, 224, 224);
}
button:hover {
background-color: black;
color: rgb(224, 224, 224)
}
</style>
</head>
<body>
<div id="random-selector" class="selector">
<div id="random-yes" class="selector-tile">
<h1>Zufallszahlen</h1>
<p>Ihr gebt nur ein, wie hoch die Chancen sein sollen, der Rest erledigt der Computer.</p>
</div>
<div id="random-no" class="selector-tile">
<h1>Manuelle Eingabe</h1>
<p>Ihr gebt ein, wie hoch die Chancen sein sollen, danach kann jeder sein Zahl frei wählen, oder sich vom Computer helfen lassen.</p>
</div>
</div>
<script>
function Game (odds, newGameWhenEqualsOdds) {
this.odds = odds;
this.newGameWhenEqualsOdds = newGameWhenEqualsOdds;
this.player1 = "";
this.player2 = "";
this.newGame = false;
this.evaluate = function() {
if (this.player1 === "") {
this.player1 = Math.floor(Math.random() * odds) + 1;
}
if (this.player2 === "") {
this.player2 = Math.floor(Math.random() * odds) + 1;
}
if (this.player1 === this.player2) {
this.success = true;
} else {
this.success = false;
}
if (this.newGameWhenEqualsOdds) {
if ((this.player1 + this.player2) === this.odds) {
this.newGame = true
}
}
return [this.success, this.newGame]
}
}
function GameFlow (random, nextGameWhenEqualsOdds, odds) {
this.random = random;
this.nextGameWhenEqualsOdds = nextGameWhenEqualsOdds;
this.odds = odds;
this.showPlayer = (num) => {
return new Promise((resolve) => {
document.body.innerHTML = `
<div class="number-input">
<h1>Welche Zahl solls sein, Spieler ${num}?</h1>
<div class="input-div-wrapper"><span class="input-div"><input id="input" type="number" step="1" min="1" max="${this.game.odds}"></span></div>
<div class="next-button-wrapper"><button id="player${num}-button">Weiter</button></div>
</div>
`
document.getElementById('player' + num + '-button').addEventListener("click", () => {
let val = "";
if (document.getElementById('input').value !== "") {
val = parseInt(document.getElementById('input').value)
}
if(((val >= 1) && (val <= this.odds)) || (document.getElementById('input').value === "")) {
if (num === 1) {
this.game.player1 = val;
this.showPlayer(2).then(() => {resolve()})
} else {
this.game.player2 = val;
resolve();
}
}
})
})
}
this.start = async () => {
this.game = new Game(this.odds, this.nextGameWhenEqualsOdds);
if(!this.random) {
await this.showPlayer(1)
}
this.game.evaluate();
let resultString;
if(this.game.success && this.game.newGame) {
resultString = '😱 Oh nein, du musst die Aufgabe erledigen. Immerhin gibts noch ne Revanche.'
} else if(!this.game.success && this.game.newGame) {
resultString = '🎉 Yeah, du musst die Aufgabe nicht erledigen und es gibt eine Revanche.'
} else if(this.game.success && !this.game.newGame) {
resultString = '😱 Oh nein, du musst die Aufgabe erledigen.'
} else {
resultString = '🥳 Yeah, du musst die Aufgabe nicht erledigen.'
}
let buttonString = "";
if(this.game.newGame) {
buttonString = '<button id="revenche-button">Revanche</button>'
} else {
buttonString = '<button id="revenche-button">Neues Spiel</button>'
}
document.body.innerHTML = `
<div style="display: flex; justify-content: center;" >
<div class="result" style="display: grid; justify-content: center; max-width: 20em;">
<h1>Ergebnis</h1>
<div style="display: flex; justify-content: center;"><h3>Die Chancen standen 1:${this.game.odds}</h3></div>
<div style="display: grid; grid-template-columns: repeat(2, 1fr); justify-items: center;">
<div style="display: grid;">
<span style="font-weight: bold; color: rgb(133, 127, 143); font-size: 0.75em;">SPIELER 1</span>
<span style="font-size: 1.5em; font-weight: bold;">${this.game.player1}</span>
</div>
<div style="display: grid; justify-items: end;">
<span style="font-weight: bold; color: rgb(133, 127, 143); font-size: 0.75em;">SPIELER 2</span>
<span style="font-size: 1.5em; font-weight: bold;">${this.game.player2}</span>
</div>
</div>
<div style="display: flex; justify-content: center;"><h2 style="margin-top: 2em;">${resultString}</h2></div>
${buttonString}
</div>
</div>
`
if(this.game.newGame) {
document.getElementById('revenche-button').addEventListener('click', () => {
this.nextGame = new GameFlow(this.random, true, Math.floor(odds/2));
this.nextGame.start();
})
} else {
document.getElementById('revenche-button').addEventListener('click', () => {
document.body.innerHTML = `
<div id="random-selector" class="selector">
<div id="random-yes" class="selector-tile">
<h1>Zufallszahlen</h1>
<p>Ihr gebt nur ein, wie hoch die Chancen sein sollen, der Rest erledigt der Computer.</p>
</div>
<div id="random-no" class="selector-tile">
<h1>Manuelle Eingabe</h1>
<p>Ihr gebt ein, wie hoch die Chancen sein sollen, danach kann jeder sein Zahl frei wählen, oder sich vom Computer helfen lassen.</p>
</div>
</div>
`
document.getElementById("random-yes").addEventListener("click", () => {
let game = new GameController(true)
})
document.getElementById("random-no").addEventListener("click", () => {
let game = new GameController(false)
})
})
}
}
}
function GameController (random) {
this.random = random;
document.body.innerHTML = `
<div id="revanche-selector" class="selector">
<div id="no" class="selector-tile">
<h1>Normal</h1>
<p>Alles bleibt beim Alten.</p>
</div>
<div id="yes" class="selector-tile">
<h1>Revanche mit doppelter Wahr­schein­lich­keit</h1>
<p>Wenn beide gewählten Zahlen zusammen addiert die Chance ergeben, gibts eine Revanche mit doppelter Treffer­wahrschein­lichkeit.</p>
</div>
</div>
`
document.getElementById("no").addEventListener("click", () => {
this.newGameWhenEqualsOdds = false
document.body.innerHTML = `
<div id="odds-input" class="number-input">
<h1>Welche Chance solls sein?</h1>
<div class="input-div-wrapper"><span class="input-div"><span>1:</span><input type="number" step="1" min="2" max="100" id="input"></span></div>
<div class="next-button-wrapper"><button id="odds-button">Weiter</button></div>
</div>
`
document.getElementById('odds-button').addEventListener("click", async () => {
let num = parseInt(document.getElementById('input').value)
if((num >= 2) && (num <= 100)) {
this.game = new GameFlow(this.random, this.newGameWhenEqualsOdds, num)
this.game.start();
}
})
})
document.getElementById("yes").addEventListener("click", () => {
this.newGameWhenEqualsOdds = true
document.body.innerHTML = `
<div id="odds-input" class="number-input">
<h1>Welche Chance solls sein?</h1>
<div class="input-div-wrapper"><span class="input-div"><span>1:</span><input type="number" step="1" min="2" max="100" id="input"></span></div>
<div class="next-button-wrapper"><button id="odds-button">Weiter</button></div>
</div>
`
document.getElementById('odds-button').addEventListener("click", async () => {
let num = parseInt(document.getElementById('input').value)
if((num >= 2) && (num <= 100)) {
this.game = new GameFlow(this.random, this.newGameWhenEqualsOdds, num)
this.game.start();
}
})
})
}
document.getElementById("random-yes").addEventListener("click", () => {
let game = new GameController(true)
})
document.getElementById("random-no").addEventListener("click", () => {
let game = new GameController(false)
})
</script>
</body>
</html>