-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBlackJack_EN.htm
659 lines (508 loc) · 15 KB
/
BlackJack_EN.htm
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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Black Jack</title>
<meta name="author" content="Rainer Wess" />
<meta name="description" content="Black Jack Game made with JavaScript HTML5 and CSS" />
<meta name="keywords" content="game,card game,Black Jack,Touch,Handy App,mobile phone,open source,GPL, freeware, HTML,CSS,JavaScript" />
<meta name="HandheldFriendly" content="true" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=yes, minimal-ui" />
<style>
/*
I have reduced the margin-height
of some elements to look nicer on
the Sololearn mobile App. To play
it standlone you may stretch it a
little bit in Y-direction.
New:
Optimised the layout with flexbox.
*/
body {
width: 360px;
margin: auto;
color: white;
font-family: Arial;
font-size: 16px;
font-weight: bold;
background-color: darkgreen;
/* disabling content selection */
-webkit-user-select:none;
-khtml-user-select:none;
-moz-user-select:none;
-ms-user-select:none;
user-select:none;
}
hr {
margin-top: 20px;
margin-bottom: 20px;
}
a {
color: Gold;
}
.game_page {
position: absolute;
overflow: hidden;
top: 0px;
left: 0px;
width: 320px;
margin: 20px;
color: white;
background-color: darkgreen;
}
.overlay_page {
z-index: 5;
position: absolute;
top: 0px;
left: 0px;
width: 320px;
margin: 20px;
color: white;
background-color: darkgreen;
}
.hidden_page {
z-index: 5;
display: none;
}
.game_title {
font: 32px Arial;
font-weight: bold;
color: red;
line-height: 1.2;
text-align: left;
text-shadow: -1px 0 white, 0 1px white, 1px 0 white, 0 -1px white;
}
.MenuBtn {
font: 22px Arial;
font-weight: bold;
color: DeepSkyBlue;
font-weight: bold;
float: right;
width: 35px;
height: 35px;
border: 1px solid;
border-color: white;
border-radius: 5px;
background-color: darkgreen;
}
.players {
font: 20px Arial;
font-weight: bold;
color: white;
margin-top: 35px;
}
#info, #busted {
text-align: left;
margin-left: 50px;
}
#points_cpu, #points_usr {
float: right;
text-align: right;
}
.tables {
display: flex;
flex-direction: row;
justify-content: space-between;
margin-top: 20px;
margin-bottom: 40px;
}
.places {
height: 82px;
width: 58px;
}
#controls {
display: flex;
flex-direction: row;
justify-content: space-between;
margin-top: 50px;
margin-bottom: 3px;
margin-right: 3px;
}
.btn {
font-size: 16px;
color: white;
font-weight: bold;
border-color: white;
border: 1px solid;
border-radius: 5px;
-webkit-box-shadow: 3px 3px #303030;
-moz-box-shadow: 3px 3px #303030;
box-shadow: 3px 3px #303030;
height: 35px;
}
#takeBtn {
background-color: green;
}
#standBtn {
background-color: red;
}
#newBtn {
background-color: black;
}
#menu {
overflow: hidden;
height: 100%;
}
#mBtn {
visibility:visible;
}
.redBtn {
background-color: red;
}
.menu_info {
margin-top: 15px;
width: 100%;
}
h3 {
font: 20px Arial;
font-weight: bold;
}
.content {
font: 16px Arial;
font-weight: bold;
margin-top: 30px;
margin-bottom: 10px;
height: 100%;
}
</style>
<script>
/*
Black Jack - (17+4)
Copyright Rainer Wess 2018
Made in Germany 🇩🇪
Open Source / Freeware
Released under GNU GPL 3.0
You can download it from
github, search RainerWessOS
New in version 1.0:
Nice deck of cards created by
nicubunu from openclipart.org
*/
globals: {
var points_usr;
var points_cpu;
var sum_usr;
var sum_cpu;
var place_usr;
var place_cpu;
var running;
var i;
var ani;
var intA;
var intTC = [];
var deck = [];
var card = [];
var card_value = [];
var revcard;
var nocard;
}
for (i = 0; i <= 51; i++) {
card[i] = new Image();
card[i].src = "cards/card" + i + ".png";
}
revcard = new Image();
revcard.src = "cards/reverse.png";
nocard = new Image();
nocard.src = "cards/nocard.png";
card_value = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10];
function id(id) {
return document.getElementById(id);
}
function setImg(pn, num) {
id("place" + pn).src = card[num].src;
}
function setText(sid, txt) {
id(sid).innerHTML = txt;
}
function setColor(sid, color) {
id(sid).style.color = color;
}
function aniWin() {
ani = (ani) ? false : true;
if (ani) setColor("info", "darkgreen");
else setColor("info","gold");
}
function showMenu() {
id("menu").className="overlay_page";
id("guide").className="hidden_page";
id("about").className="hidden_page";
}
function showGuide() {
id("guide").className="overlay_page";
id("menu").className="hidden_page";
}
function showAbout() {
id("about").className="overlay_page";
id("menu").className="hidden_page";
}
function showGame() {
id("game").className="game_page";
id("menu").className="hidden_page";
}
function enableButtons() {
id("takeBtn").disabled = false;
id("standBtn").disabled = false;
}
function disableButtons() {
id("takeBtn").disabled = true;
id("standBtn").disabled = true;
id("newBtn").disabled = true;
}
function init() {
points_usr = 0;
setText("points_usr", points_usr);
points_cpu = 0;
setText("points_cpu", points_cpu);
newGame();
}
function createDeck() {
var arr = [];
for (var i = 0; i < 52; i++) {
arr[i] = i;
}
return arr;
}
function shuffle(arr) {
var i, j, tmp;
// Fisher-Yates Shuffling Algorithm
for(i=arr.length-1; i>0; i--) {
j = Math.floor(Math.random() * (i + 1));
tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
return arr;
}
function takeCard() {
var tc;
if(deck.length == 0) {
deck = createDeck();
deck = shuffle(deck);
}
tc = deck.pop();
return tc;
}
function newGame() {
sum_usr = 0;
sum_cpu = 0;
place_usr = 0;
place_cpu = 5;
ani = false;
running = true;
id("newBtn").blur();
disableButtons();
if (intA) clearInterval(intA);
setText("busted", " ");
setText("info", " ");
setText("cpu", "0");
setText("you", "0");
setColor("info", "white");
for (i = 0; i <= 9; i++) {
id("place" + i).src = nocard.src;
}
setTimeout(showReversedCard, 500);
setTimeout(cpuTakeCard, 1000);
setTimeout(usrTakeCard, 1500);
setTimeout(enableButtons, 1600);
}
function showReversedCard() {
id("place6").src = revcard.src;
}
function usrTakeCard() {
var cNum;
id("takeBtn").blur();
if (running) {
if (sum_usr <= 21) {
setText("info", " ");
cNum = takeCard();
setImg(place_usr, cNum);
place_usr++;
sum_usr += card_value[cNum % 13];
setText("you", sum_usr);
}
if (sum_usr > 20) {
disableButtons();
whoWins();
}
// in rare cases five cards are not enough
// ToDo: shift the drawn cards in the places, if more cards needed then places available, but for now we reuse the last place
if (place_usr > 4) place_usr--;
}
}
function cpuTakeCard() {
var cNum;
if (running) {
if ((sum_cpu < 19 && sum_cpu < sum_usr) || (sum_cpu < 16 && sum_cpu == sum_usr)) {
cNum = takeCard();
setImg(place_cpu, cNum);
place_cpu++;
sum_cpu += card_value[cNum % 13];
setText("cpu", sum_cpu);
if (place_cpu > 9) {
// in rare cases five cards are not enough then the last place is reused
place_cpu--;
intTC[0] = setTimeout(cpuTakeCard, 1000);
}
}
else whoWins();
}
}
function stand() {
// computers turn
var wait = 0;
id("standBtn").blur();
if (sum_usr > 9) {
disableButtons();
if (sum_cpu > sum_usr) whoWins();
for (i = 0; i < 4; i++) {
if (sum_usr > sum_cpu && sum_cpu < 19 || sum_usr == sum_cpu && sum_cpu < 16) {
intTC[i] = setTimeout(cpuTakeCard, wait);
wait += 1000;
}
}
} // Little Britain joke
else setText("info", "💻 says NO!");
}
function youWin() {
setColor("info", "gold");
setText("info", "You Win!");
intA = setInterval(aniWin, 700);
}
function youLose() {
setText("info", "You Lose.");
}
function whoWins() {
if (running) {
if (sum_usr > 21 || (sum_cpu <= 21 && sum_cpu > sum_usr && sum_usr > 0)) {
running = false;
if (sum_usr > 21) {
setText("info", "Busted");
setTimeout(youLose, 800);
}
else youLose();
points_cpu += 1;
setText("points_cpu", points_cpu);
}
else if (sum_cpu > 21 || sum_usr == 21 || (sum_usr <= 21 && sum_usr > sum_cpu)) {
running = false;
if (sum_cpu > 21) {
setText("busted", "* Busted *");
setTimeout(youWin, 500);
}
else if (sum_usr == 21) {
setTimeout(youWin, 500);
}
else youWin();
points_usr += 1;
setText("points_usr", points_usr);
}
else if (sum_cpu > 0 && sum_usr == sum_cpu) {
running = false;
setColor("info", "white")
setText("info", "It's a tie!");
}
if (!running) {
id("newBtn").disabled = false;
for (i = 0; i < intTC.length; i++) {
if (intTC[i]) clearTimeout(intTC[i]);
}
}
}
}
// END
</script>
</head>
<body onload="init()">
<div id="menu" class="hidden_page">
<div class="header"><span class="game_title">Black Jack</span><button id="mBtn" class="MenuBtn" onclick="showGame()">✕</button></div>
<hr>
<div>
<button class="btn redBtn" onclick="showGuide()">How to play</button>
</div>
<div class="menu_info">
The rules of this simplyfied Black Jack card game.
<p>
</div>
<hr>
<div>
<button class="btn redBtn" onclick="showAbout()">About the game</button>
</div>
<div class="menu_info">
Information about author, licence and copyright for this game.
</div>
<hr>
<div>
<button class="btn redBtn" onclick="showGame()">Back to game</button>
</div>
<div class="menu_info">
The menu button in the top right corner will you also bring back to the game.
</div>
</div>
<div id="guide" class="hidden_page">
<div class="header"><span class="game_title">Black Jack</span><button class="MenuBtn" onclick="showMenu()">☰</button></div>
<div class="content">
<h3> How to play </h3>The purpose of the game is to win. 😀<br> You play here against a real pro, the Gina. <P>The goal of the game is to come closer to 21 points than your opponent, ideally to get exactly 21 points. But do not overdo it, because if a player passes 21 points, it is too much and he has lost. <p>Because the Gina plays so damn good, she has to turn a card over so that you can see it and estimate, if you already have enough points, or risk taking another card. <p>
If you get exactly 21 points, you win immediately, which is of course the best, because then the Gina does not come into play. <P>
Have fun playing!<p>
</div>
</div>
<div id="about" class="hidden_page">
<div class="header"><span class="game_title">Black Jack</span><button class="MenuBtn" onclick="showMenu()">☰</button>
</div>
<div class="content">
<h3>About the Game</h3>
Game-Development / Programming:<br> 2018 ©️ Rainer Wess, Osnabrück
<p>
Made in Germany 🇩🇪
<p>
This game is open source / freeware. You can do with it whatever you want as long as this copyright and license disclaimer stays intact.
<p>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
<p>
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
<p>
You should have received a copy of the GNU General Public License along with this program.
<p>
If not, see <a href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>
<p>
You can download the latest version of this game from github.com:<br>
<a href="https://github.com/RainerWessOS/Black-Jack">https://github.com/RainerWessOS/Black-Jack</a>
<p>
The grafics for the nice deck of cards were created by nicubunu and are realeased under Creative Commons Zero 1.0 Public Domain License. I have them from openclipart.org
<p>
</div>
</div>
<div id="game" class="game_page">
<div class="header"><span class="game_title">Black Jack</span><button class="MenuBtn" onclick="showMenu()">☰</button>
</div>
<div class="players">GINA : <span id="cpu">0</span> <span id="busted"> </span><span id="points_cpu">0</span>
</div>
<div class="tables">
<div class="places"><img id="place6" src="cards/nocard.png" alt=""></div>
<div class="places"><img id="place5" src="cards/nocard.png" alt=""></div>
<div class="places"><img id="place7" src="cards/nocard.png" alt=""></div>
<div class="places"><img id="place8" src="cards/nocard.png" alt=""></div>
<div class="places"><img id="place9" src="cards/nocard.png" alt=""></div>
</div>
<div class="players">YOU : <span id="you">0</span> <span id="info"> </span><span id="points_usr">0</span></div>
<div class="tables">
<div class="places"><img id="place0" src="cards/nocard.png" alt=""></div>
<div class="places"><img id="place1" src="cards/nocard.png" alt=""></div>
<div class="places"><img id="place2" src="cards/nocard.png" alt=""></div>
<div class="places"><img id="place3" src="cards/nocard.png" alt=""></div>
<div class="places"><img id="place4" src="cards/nocard.png" alt=""></div>
</div>
<div id="controls">
<div>
<button id="takeBtn" class="btn" onclick="usrTakeCard()">TAKE CARD</button>
</div>
<div>
<button id="standBtn" class="btn" onclick="stand()">STAND</button>
</div>
<div>
<button id="newBtn" class="btn" onclick="newGame()">NEW GAME</button>
</div>
</div>
</div>
</body>
</html>