-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
1070 lines (900 loc) · 46.2 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
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
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html manifest="cache.manifest">
<head>
<meta charset="utf-8"/>
<meta name="description" content="Collection of simple Lua and Rust games that can be played in your browser. Includes solitaire, word games, chess, go, checkers. Supports local or websocket multiplayer."/>
<meta name="keywords" content="games, simple, board games, lua, multiplayer, solitaire, chess, go, checkers"/>
<meta name="author" content="Alex Barry"/>
<!-- setting maximum-scale=1 to prevent auto zooming in on input fields in safari mobile.
this may be bad if it introduces other side effects.
I still want to allow zooming in on some board games (e.g. 19x19 go) -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="mobile-web-app-capable" content="yes" />
<link rel="icon" type="image/png" href="img/logo.png" />
<meta property="og:image" content="img/logo.png"/>
<meta property="og:image:type" content="image/png">
<meta property="og:image:width" content="512">
<meta property="og:image:height" content="512">
<link rel="apple-touch-icon" href="img/logo.png" />
<link rel="apple-touch-startup-image" href="img/logo.png" />
<meta rel="apple-mobile-web-app-title" content="AlexGames" />
<title>AlexGames</title>
<script type="text/javascript" src="alexgames_wasm.js"></script>
<script type="text/javascript" src="js/alexgames.js"></script>
<script type="text/javascript" src="js/alexgames_colour_pref.js"></script>
<script type="text/javascript" src="js/alexgames_ws.js"></script>
<script type="text/javascript" src="js/alexgames_wasm_api.js"></script>
<script type="text/javascript" src="js/alexgames_wasm_wrapper.js"></script>
<!-- both of these aren't needed, only one is ever used at a time -->
<script type="text/javascript" src="js/alexgames_dict.js"></script>
<script type="text/javascript" src="js/alexgames_c_dict.js"></script>
<script type="text/javascript" src="js/url_args.js"></script>
<link rel="manifest" href="manifest.json">
<link rel="stylesheet" type="text/css" href="css/style_very_dark.css">
<link rel="stylesheet" type="text/css" href="css/style_dark.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<style>
html, body {
height: 97%;
}
.main {
margin:5px auto;
max-width:800px;
padding: 10px;
border-radius:15px;
/* height: 100%; */
}
.title {
margin:0;
text-align:center;
}
.subtitle {
margin: 0;
text-align:center;
}
/* should be the same size as the options button, which inherits the size of all buttons */
.logo {
width:50px;
height:50px;
position:absolute;
}
.canvas_div {
max-width:100%;
flex:0;
display:flex;
flex-direction:column;
align-self:center;
}
#game_canvas {
max-width:100%;
flex: 0 0 1;
align-self:center;
/* prevent double tapping to zoom in on iOS */
touch-action: manipulation;
}
.button_row {
width:100%;
display:flex;
}
.canvas_div_wrapper {
display:flex;
flex-direction:column;
position:relative;
}
.popup {
position:absolute;
left:0;
top:0;
right:0;
/* bottom:0; */
margin: auto;
z-index:2;
}
.close_button {
z-index:5;
margin:10px;
}
.game_popup {
padding: 20px;
overflow:auto;
width: 300px;
height:420px;
}
/*
* Meant for popups like "options" and "game_choice", but not
* popups generated by games.
* This one is almost full screen, the others are not.
*/
.meta_popup {
box-sizing: border-box;
position:fixed;
margin: auto;
max-width:700px;
top: 65px;
bottom: 20px;
z-index: 4;
}
.options_popup {
overflow-y: scroll;
z-index: 5;
}
.game_choice_popup_wrapper {
position:absolute;
top: 0;
bottom: 0;
padding-top: 20px;
padding-bottom: 20px;
overflow-y:scroll;
}
.game_popup > button {
width:100%;
margin-top:10px;
}
button.game_btn {
margin: 5px;
}
button {
height:50px;
/* prevent double tapping a button to zoom in on iOS */
touch-action: manipulation;
}
.overlay {
position:absolute;
left:0;
top:0;
right:0;
bottom:0;
z-index:1;
}
.overlay_transparent {
position:absolute;
left:0;
top:0;
right:0;
bottom:0;
}
.unset_game_instructions_cls {
display: flex;
align-items: center;
justify-content: center;
}
.fullscreen_msg {
max-width: 480px;
text-align: center;
}
.fullscreen_err_msg > p {
color:red;
}
</style>
</head>
<body>
<div class="main" style="position:relative">
<div id="header" class="header" style="position:relative">
<div style="display:block; margin:auto">
<a href="index.html"><img class="logo" src="img/logo-transparent.png" alt="AlexGames logo"/></a>
<h1 id="title" class="title" style=""><a class="no_underline" href="index.html">AlexGames</a></h1>
<h2 id="subtitle" class="subtitle">Choose a game</h2>
</div>
<button id="btn_options" style="position:absolute; top:0; right:0">Options</button>
</div>
<div class="canvas_div_wrapper">
<!-- TODO Make this shrink to fit in entire screen, up to
some max on desktop only -->
<div class="canvas_div">
<div style="display:flex">
<div id="status" class="status" style="flex:1">Initializing...</div>
<!--<span id="status_err" class="status status_error"> </span>-->
<!-- This button is only shown if the header is hidden -->
<button id="btn_status_options" style="flex:0; display:none">Options</button>
</div>
<div id="fullscreen_msg_wrapper" class="unset_game_instructions_cls overlay_transparent" style="display:none">
<div id="fullscreen_err_msg" class="fullscreen_msg fullscreen_err_msg">
</div>
</div>
<div id="unset_game_instructions" class="unset_game_instructions_cls overlay_transparent">
<div class="fullscreen_msg">
<!-- TODO show "loading, please wait" at first. Then change it to this once the game is loaded -->
<p>
Press here to select a game.
</p>
<p>
Alternatively, go to the "options" button in the top right of the screen, and select "load autosaved game" to resume any previously played games.
</p>
</div>
</div>
<canvas id="game_canvas" width="480" height="480">
Your browser doesn't support canvases.
</canvas>
<div id="game_button_row" class="button_row">
<!-- Buttons are added here from the game API -->
</div>
<div id="popup" class="popup game_popup" style="display:none">
<!-- This popup is populated and set visible by the game API -->
</div>
<div class="overlay" style="display:none"></div>
</div>
</div>
<!-- This is made visible when the user presses the "Options" button -->
<div id="options_popup" class="popup meta_popup options_popup" style="display:none">
<button id="btn_close_options" class="close_button">X</button>
<div class="popup_content_wrapper">
<h2 class="title">Options</h2>
<h3>Main</h3>
<button id="btn_game_select" class="options_button">Select a different game</button>
<button id="btn_history_browse" class="options_button">Load autosaved game</button>
<div style="display:flex; flex-direction:row">
<div style="flex:1; display:flex; align-items: center; margin-right:5px">
<label for="select_user_colour_pref" style="flex:0">Colour scheme</label>
<select id="select_user_colour_pref" class="popup_dropdown" style="flex:1">
<option value="auto">Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
<option value="very_dark">Very Dark</option>
</select>
</div>
<div style="flex:1">
<p class="small">Note: some games may require a refresh for their colour scheme to update.<span class="small">(This could be easily fixed in a future update.)</span></p>
</div>
</div>
<h3>Game options</h3>
<!-- These options are populated by the game API -->
<div id="game_options">
<div id="game_options_none_placeholder">
<p>This game has not defined any options. <span class="dev_note not_supported">(For developers: call the <code>add_game_option</code> API to add options here. This is useful for less commonly used options like starting a new game.)</span></p>
</div>
<!-- for example: -->
<!--<button class="options_button">Start new game</button>-->
</div>
<h3>Share/export state</h3>
<h4 class="options_subheading">Current state</h4>
<div id="current_state_not_supported" style="display:none">
<p class="not_supported">This game does not support sharing state via URL. <span class="dev_note not_supported">(For developers: define the <code>get_state</code> global function to return the state as a byte array. The game engine will base 64 encode it and it will show up here when the options menu is opened.)</span></p>
</div>
<div id="current_state_supported">
<p class="options_p">The below link contains the game's <strong>current state</strong>. You can send this link to another device to continue playing.</p>
<div class="url_container">
<a id="url_current_state" class="url_span" href="#"></a>
</div>
</div>
<h4 class="options_subheading">Initial state</h4>
<div id="init_state_not_supported" style="display:none">
<p class="not_supported">This game does not support sharing initial state via URL. <span class="dev_note not_supported">(For developers: define the <code>get_init_state</code> global function to return the state as a byte array. The game engine will base 64 encode it and it will show up here when the options menu is opened.)</span></p>
</div>
<div id="init_state_eq_state" style="display:none">
<p class="not_supported">This game's initial state is currently equal to its current state. Once you make some moves, this section should retain a link to the game's original state, so you can share it with a friend to play the same puzzle you did (if this game supports it). The above link will change to match the game's <strong>current state</strong>, so you can share a link to continue playing where you left off on another device.
</div>
<div id="init_state_supported">
<p class="options_p">The below link contains the game's <strong>initial state</strong>. You can send this link to a friend so they can try to solve the same puzzle that you did.</p>
<div class="url_container">
<a id="url_init_state" class="url_span" href="#"></a>
</div>
</div>
<h3>Upload Game Bundle</h3>
<p>In addition to the preloaded games already available on this page, you can create your own game (or get one from another person) and upload it to play on this page.</p>
<p>It should be a ZIP archive of Lua files, with a manifest file. Read more about the API and specifications here: <a href="game_api_doc.html" target="_blank">AlexGames Lua API reference</a></p>
<p>Here is an example game zip, feel free to download it, optionally edit its contents, and reupload using the buttons below to try out your changes: <a href="example_game_apidemo.zip" style="font-family:monospace">example_game_apidemo.zip</a></p>
<input type="file" id="input_upload_game_bundle" style="popup_input_row"/>
<button id="btn_process_uploaded_game_bundle" disabled>Process game bundle</button>
<h3>Multiplayer settings</h3>
<p>Generally, you should be able to just copy and paste the URL in your address bar (or below), and share it with a friend for multiplayer to work.</p>
<div class="url_container">
<a id="url_share_multiplayer" class="url_span" href="#"></a>
</div>
<p>The session ID is how the server knows to connect you with your friend(s). You can change the session ID or server below.</p>
<div class="popup_table">
<div class="popup_row">
<label for="session_id_input" class="label_col">Session ID</label>
<input id="session_id_input" class="input_col"></input>
</div>
<div class="popup_row">
<label for="custom_ws_server_input" class="label_col">Websocket server</label>
<input id="custom_ws_server_input" class="input_col" placeholder="example: wss://alexbarry.net:55433, or ws://192.168.1.100:5678"></input>
</div>
</div>
<button id="btn_submit_multiplayer_settings" style="width: 100%">Submit multiplayer settings</button>
<h3>Miscellaneous</h3>
<button id="btn_force_refresh" class="options_button">Force Refresh</button>
<!--
<label for="theme_select">Theme</label>
<select id="theme_select">
<option>Auto</option>
<option>Light</option>
<option>Dark</option>
</select>
<h3>Multiplayer</h3>
<label for="custom_ws_server">Custom Websocket server</label>
<input id="custom_ws_server" placeholder="e.g. wss://alexgames.example.com:55040"></input>
TODO add session ID to options, maybe show other players that are connected
-->
<p></p>
<a id="about_link_options" href="#">AlexGames was created by Alex Barry, click here for more info.</a>
</div>
</div>
<div id="game_choice_popup" class="popup game_choice_popup meta_popup" style="display:none">
<button id="btn_close_game_choice_popup" class="close_button">X</button>
<div class="game_choice_popup_wrapper">
<h2 class="title">Select a game</h2>
<div id="game_row_solitaire" class="game_row">
<div class="game_wrapper"><img class="game_icon" src="img/game_icons/solitaire.png"/></div>
<h2 class="game_title">Solitaire</h2>
<div class="description">
<p>Single player.</p>
<p>Win by putting all of the cards in order from lowest to highest, and grouped by suit. Cards can be placed on the game board from highest to lowest, with alternating suit colours.</p>
</div>
</div>
<div id="game_row_word_mastermind" class="game_row">
<div class="game_wrapper"><img class="game_icon" src="img/game_icons/word_mastermind.png"/></div>
<h2 class="game_title">Word Mastermind</h2>
<div class="description">
<p>Single player.</p>
<p>Guess words, finding out if the letter is in the word and in the right position. Guesses must be valid English words.</p>
<p>Supports entering an arbitrary 5-letter word to generate your own custom puzzle, to share with your friends either by handing them your device, or sending them a link with the state embedded in the URL.</p>
</div>
</div>
<div id="game_row_chess" class="game_row">
<h2 class="game_title">Chess</h2>
<div class="game_wrapper"><img class="game_icon" src="img/game_icons/chess.png"/></div>
<div class="description">
<p>Local or network multiplayer: 2 players.</p>
<p>Win by putting the opponent's king in checkmate.</p>
</div>
</div>
<div id="game_row_crossword_letters" class="game_row">
<div class="game_wrapper"><img class="game_icon" src="img/game_icons/crossword_letters.png"/></div>
<h2 class="game_title">Crossword Letters</h2>
<div class="description">
<p>Single player.</p>
<p>Try to figure out all the words that can be made from rearranging a few letters, using the crossword as a hint.
</div>
</div>
<div id="game_row_gem_match" class="game_row">
<h2 class="game_title">"Gem Match"</h2>
<div class="game_wrapper"><img class="game_icon" src="img/game_icons/gem_match.png"/></div>
<div class="description">
<p>Single player.</p>
<p>Swap gems to make lines of three or more.</p>
</div>
</div>
<div id="game_row_go" class="game_row">
<h2 class="game_title">Go/Weiqi/Baduk</h2>
<div class="game_wrapper"><img class="game_icon" src="img/game_icons/go.png"/></div>
<div class="description">
<p>Local or network multiplayer: 2 players.</p>
<p>Win by controlling more territory than your opponent, and capture their groups of stones by surrounding them.</p>
<p><strong>NOTE:</strong> this game does not yet support AI opponents, or even displaying territory or determining who wins.</p>
</div>
</div>
<div id="game_row_reversi" class="game_row">
<h2 class="game_title">Reversi</h2>
<div class="game_wrapper"><img class="game_icon" src="img/game_icons/reversi.png"/></div>
<div class="description">
<p>Local multiplayer.</p>
<p>You can only move when jumping one or more of your opponent's pieces, and then they all "reverse" to become yours.</p>
</div>
</div>
<div id="game_row_checkers" class="game_row">
<div class="game_wrapper"><img class="game_icon" src="img/game_icons/checkers.png"/></div>
<h2 class="game_title">Checkers/Draughts</h2>
<div class="description">
<p>Local or network multiplayer: 2 players.</p>
<p>Win by capturing all the opponent's pieces.</p>
</div>
</div>
<div id="game_row_endless_runner" class="game_row">
<div class="game_wrapper"><img class="game_icon" src="img/game_icons/endless_runner.png"/></div>
<h2 class="game_title">Endless Runner</h2>
<div class="description">
<p>Single player.</p>
<p>Tap to jump and use gravity to navigate through an endless set of obstacles.</p>
</div>
</div>
<div id="game_row_minesweeper" class="game_row">
<div class="game_wrapper"><img class="game_icon" src="img/game_icons/minesweeper.png"/></div>
<h2 class="game_title">Minesweeper</h2>
<div class="description">
<p>Single player, or network multiplayer up to 4 players.</p>
<p>Flag mines by using logic to determine where they are, knowing how many mines are adjacent to revealed squares.</p>
</div>
</div>
<div id="game_row_fluid_mix" class="game_row">
<div class="game_wrapper"><img class="game_icon" src="img/game_icons/fluid_mix.png"/></div>
<h2 class="game_title">Fluid Mix</h2>
<div class="description">
<p>Single player.</p>
<p>Sort/rearrange layers of liquids in vials, with the goal of ending up with each vial containing only a single type of liquid.</p>
</div>
</div>
<div id="game_row_backgammon" class="game_row">
<div class="game_wrapper"><img class="game_icon" src="img/game_icons/backgammon.png"/></div>
<h2 class="game_title">Backgammon</h2>
<div class="description">
<p>Local or network multiplayer: 2 players.</p>
<p>Win by bearing off all your pieces before your opponent. You can slow your opponent down by capturing their pieces, moving them to the middle, forcing them to start that piece from the beginning again.</p>
</div>
</div>
<div id="game_row_crib" class="game_row">
<div class="game_wrapper"><img class="game_icon" src="img/game_icons/crib.png"/></div>
<h2 class="game_title">Cribbage</h2>
<div class="description">
<p>Network multiplayer: 2-4 players.</p>
<p>Score points by getting cards worth 15, a run (cards in sequence), pairs, or a flush. First player to achieve 121 wins.</p>
</div>
</div>
<div id="game_row_spider_swing" class="game_row">
<div class="game_wrapper"><img class="game_icon" src="img/game_icons/spider_swing.png"/></div>
<h2 class="game_title">Spider swing</h2>
<div class="description">
<p>Single player only.</p>
<p>Swing from point to point, being careful not to lose too much height or speed.</p>
</div>
</div>
<div id="game_row_thrust" class="game_row">
<div class="game_wrapper"><img class="game_icon" src="img/game_icons/thrust.png"/></div>
<h2 class="game_title">"Thrust"</h2>
<div class="description">
<p>Single player only.</p>
<p>Race your space ship around the track, trying to control your momentum.</p>
</div>
</div>
<div id="game_row_wu" class="game_row">
<div class="game_wrapper"><img class="game_icon" src="img/game_icons/wu.png"/></div>
<h2 class="game_title">Gomoku/Wuziqi/Omok</h2>
<div class="description">
<p>Local or network multiplayer: 2 players.</p>
<p>The winner is the first player to place 5 stones in a row.</p>
</div>
</div>
<div id="game_row_31s" class="game_row">
<div class="game_wrapper"><img class="game_icon" src="img/game_icons/31s.png"/></div>
<h2 class="game_title">31's</h2>
<div class="description">
<p>Network multiplayer: 2-4 players.</p>
<p>You can hold only 3 cards at a time. On your turn you can choose to draw a new card, or draw a discarded card. Try to get as close to 31 as possible (must be the same suit), or go for three of a kind. On any turn a player may knock, which will end the game after everyone else has played. The player with the highest cards after knocking wins. If a player achieves 31, the game immediately ends and that player is the winner.</p>
</div>
</div>
<div id="game_row_hospital" class="game_row">
<div class="game_wrapper"><img class="game_icon" src="img/game_icons/hospital.png"/></div>
<h2 class="game_title">Hospital</h2>
<div class="description">
<p>Single player, or network multiplayer up to 4 players.</p>
<p>Alone or with a friend, try to help patients by providing them with the right kind of help, racing against the clock.</p>
</div>
</div>
<div id="game_row_life" class="game_row">
<div class="game_wrapper"><img class="game_icon" src="img/game_icons/life.png"/></div>
<h2 class="game_title">Conway's Game of Life</h2>
<div class="description">
<p>Single player only. (Arguably "zero player")</p>
<p>A cellular automaton. <a href="https://en.wikipedia.org/wiki/Conway's_Game_of_Life">See wikipedia for more information.</a> I threw this together and included it here more as a tech demo than an actual game.</p>
</div>
</div>
<div class="game_list_padding"></div>
</div>
</div>
<script>
let game_choice_row_infos = [
{ row_id: "game_row_chess", game_id: "chess" },
{ row_id: "game_row_go", game_id: "go" },
{ row_id: "game_row_checkers", game_id: "checkers" },
{ row_id: "game_row_solitaire", game_id: "solitaire" },
{ row_id: "game_row_gem_match", game_id: "gem_match" },
{ row_id: "game_row_reversi", game_id: "reversi" },
{ row_id: "game_row_minesweeper", game_id: "minesweeper" },
{ row_id: "game_row_endless_runner", game_id: "endless_runner" },
{ row_id: "game_row_fluid_mix", game_id: "fluid_mix" },
{ row_id: "game_row_wu", game_id: "wu" },
{ row_id: "game_row_backgammon", game_id: "backgammon" },
{ row_id: "game_row_word_mastermind", game_id: "word_mastermind" },
{ row_id: "game_row_crossword_letters", game_id: "crossword_letters" },
{ row_id: "game_row_crib", game_id: "crib" },
{ row_id: "game_row_thrust", game_id: "thrust" },
{ row_id: "game_row_31s", game_id: "31s" },
{ row_id: "game_row_life", game_id: "life" },
{ row_id: "game_row_spider_swing", game_id: "spider_swing" },
{ row_id: "game_row_hospital", game_id: "hospital" },
];
for (let game_choice_row_info of game_choice_row_infos) {
document.getElementById(game_choice_row_info.row_id).addEventListener('click', function() {
console.log("[init] User selected game via button press:", game_choice_row_info.game_id);
game_chosen(game_choice_row_info.game_id);
});
}
</script>
</div>
<div id="about_popup" class="popup meta_popup options_popup" style="display:none">
<button id="btn_close_about_popup" class="close_button">X</button>
<div class="popup_content_wrapper">
<h2 class="title">About AlexGames</h2>
<p>AlexGames is a platform for simple games written in Lua, Rust, or C/C++, currently supporting HTML (the page you are currently visiting), and experimental implementations in Android, and Windows/MacOS/Linux (using wxWidgets). The idea is that someone can throw together the "fun parts" of a game in a few hundred lines of Lua, Rust, or C++, and then the boilerplate to get it running on their platform of choice should be already taken care of. Adding support for a new platform should be relatively easy.</p>
<p>For further convenience (both for game developers and game players), you can develop and/or play your own Lua game just by uploading a bundle of Lua code to the browser client. If you want to put together a simple game, but don't want to bother building this project, you shouldn't need to: just download <a href="example_game_apidemo.zip">the example Lua game zip</a>, consult the <a href="game_api_doc.html" target="_blank">Lua API reference</a>, and then you can modify the existing example Lua code or write your own, and then zip your files. Then you can upload that zip file into the web client, or send it to a friend.</p>
<p>It also supports some helpful features like a built in English dictionary (for word puzzle games), sharing state via URL, and saving state and browsing previously saved states. Previews of saved states are generated using the same code the programmer wrote to render the game itself. The logic for handling this is included as a library to the game platform itself: very little extra code should be needed for game developers or developers of new "clients" (more on what a "client" is below).</p>
<p>One of the goals is for the API to be very convenient both for game developers, and for developers of new "platforms". In this context a "platform" is a device that the game is built for: there is a platform for browsers, developed in HTML/JS/WASM, a native Android platform, and a wxWidgets platform that allows for playing games natively on Windows, MacOS, and Linux.</p>
<p>Created by <a href="https://github.com/alexbarry">Alex Barry</a>. You are encouraged to submit comments, bug reports, feature requests, or say hi at:</p>
<ul>
<li>Github: <a class="url" href="https://github.com/alexbarry/AlexGames" target="_blank">github.com/alexbarry/AlexGames</a></li>
<li>Discord: <a class="url" href="https://discord.gg/rhy8SuHPYU" target="_blank">discord.gg/rhy8SuHPYU</a></li>
<li>Lemmy: <a class="url" href="https://lemmyverse.link/c/alexgames@lemmy.ca" target="_blank">!alexgames@lemmy.ca</a></li>
<li>Matrix: <a class="url" href="https://matrix.to/#/#alexgames:matrix.org" target="_blank">#alexgames:matrix.org</a></li>
<li>Email: <span class="url">alexbarry.dev2 [ at ] gmail.com</span></li>
</ul>
<p>Also available as an <a href="https://f-droid.org/packages/net.alexbarry.alexgames" target="_blank">Android app on F-Droid</a> for offline play.</p>
<p>This project would not be possible if it were not for these amazing projects:</p>
<ul>
<li><a href="https://lua.org"><img alt="Lua Logo" src="img/credits/Lua-Logo_128x128.png" width="48" height="48"/></a> A lightweight scripting language that integrates very nicely with C</li>
<li><a href="https://cmake.org">CMake</a>: cross platform build system</li>
<li><a href="https://emscripten.org">Emscripten</a>: compile C/C++ to WebAssembly</li>
<li><a href="https://www.rust-lang.org/">Rust (Language)</a>: a much nicer alternative to C++ which still integrates nicely with C++ and has great support for WebAssembly.</li>
</ul>
<!-- The others don't explicitly say to include their logo, so I'm not sure if I should. -->
<p>See more in the <a href="licenses.html" target="_blank">licenses page</a>.</p>
</div>
</div>
<!-- preload images -->
<div style="display:none">
<img id ="board" src="img/wooden_board.png"/>
<img id ="piece_black" src="img/black_piece.png"/>
<img id ="piece_white" src="img/white_piece.png"/>
<img id ="piece_highlight" src="img/piece_highlight.png"/>
<img id ="piece_king_icon" src="img/piece_king_icon.png"/>
<img id ="card_diamonds" src="img/cards/diamonds.png"/>
<img id ="card_hearts" src="img/cards/hearts.png"/>
<img id ="card_spades" src="img/cards/spades.png"/>
<img id ="card_clubs" src="img/cards/clubs.png"/>
<img id ="card_blank" src="img/cards/blank_card.png"/>
<img id ="card_facedown" src="img/cards/card_facedown.png"/>
<img id ="card_highlight" src="img/cards/card_highlight.png"/>
<img id ="more_info_btn" src="img/more_info_btn.png"/>
<img id ="backgammon_triangle_black" src="img/backgammon/triangle_black.png"/>
<img id ="backgammon_triangle_white" src="img/backgammon/triangle_white.png"/>
<img id ="backgammon_triangle_highlight" src="img/backgammon/triangle_highlight.png"/>
<img id="chess_rook_white" src="img/chess/rook_white.png"/>
<img id="chess_knight_white" src="img/chess/knight_white.png"/>
<img id="chess_bishop_white" src="img/chess/bishop_white.png"/>
<img id="chess_pawn_white" src="img/chess/pawn_white.png"/>
<img id="chess_queen_white" src="img/chess/queen_white.png"/>
<img id="chess_king_white" src="img/chess/king_white.png"/>
<img id="chess_rook_black" src="img/chess/rook_black.png"/>
<img id="chess_knight_black" src="img/chess/knight_black.png"/>
<img id="chess_bishop_black" src="img/chess/bishop_black.png"/>
<img id="chess_pawn_black" src="img/chess/pawn_black.png"/>
<img id="chess_queen_black" src="img/chess/queen_black.png"/>
<img id="chess_king_black" src="img/chess/king_black.png"/>
<img id="chess_rook_black_dark" src="img/chess/rook_black_dark.png"/>
<img id="chess_knight_black_dark" src="img/chess/knight_black_dark.png"/>
<img id="chess_bishop_black_dark" src="img/chess/bishop_black_dark.png"/>
<img id="chess_pawn_black_dark" src="img/chess/pawn_black_dark.png"/>
<img id="chess_queen_black_dark" src="img/chess/queen_black_dark.png"/>
<img id="chess_king_black_dark" src="img/chess/king_black_dark.png"/>
<img id ="dice1" src="img/dice/dice1.png"/>
<img id ="dice2" src="img/dice/dice2.png"/>
<img id ="dice3" src="img/dice/dice3.png"/>
<img id ="dice4" src="img/dice/dice4.png"/>
<img id ="dice5" src="img/dice/dice5.png"/>
<img id ="dice6" src="img/dice/dice6.png"/>
<img id ="arrow" src="img/arrow.png"/>
<img id ="minesweeper_mine" src="img/minesweeper/mine.png"/>
<img id ="minesweeper_box1" src="img/minesweeper/box1.png"/>
<img id ="minesweeper_box2" src="img/minesweeper/box2.png"/>
<img id ="minesweeper_box3" src="img/minesweeper/box3.png"/>
<img id ="minesweeper_box4" src="img/minesweeper/box4.png"/>
<img id ="minesweeper_box5" src="img/minesweeper/box5.png"/>
<img id ="minesweeper_box6" src="img/minesweeper/box6.png"/>
<img id ="minesweeper_box7" src="img/minesweeper/box7.png"/>
<img id ="minesweeper_box8" src="img/minesweeper/box8.png"/>
<img id ="minesweeper_box_unclicked" src="img/minesweeper/box_unclicked.png"/>
<img id ="minesweeper_box_empty" src="img/minesweeper/box_empty.png"/>
<img id ="minesweeper_box_flagged_red" src="img/minesweeper/box_flagged_red.png"/>
<img id ="minesweeper_box_flagged_blue" src="img/minesweeper/box_flagged_blue.png"/>
<img id ="hospital_floor_tile" src="img/hospital/floor_tile.png"/>
<img id ="hospital_floor_tile_bad" src="img/hospital/floor_tile_bad.png"/>
<img id ="hospital_doctor1" src="img/hospital/doctor1.png"/>
<img id ="hospital_doctor2" src="img/hospital/doctor2.png"/>
<img id ="hospital_doctor3" src="img/hospital/doctor3.png"/>
<img id ="hospital_doctor4" src="img/hospital/doctor4.png"/>
<img id ="hospital_patient_in_bed" src="img/hospital/patient_in_bed.png"/>
<img id ="hospital_patient_in_bed_flipped" src="img/hospital/patient_in_bed-flipped.png"/>
<img id ="hospital_ui_dirpad" src="img/hospital/ui/dirpad.png"/>
<img id ="hospital_ui_thumb_buttons" src="img/hospital/ui/thumb_buttons.png"/>
<img id ="hospital_bed" src="img/hospital/bed1.png"/>
<img id ="hospital_bed_flipped"src="img/hospital/bed1-flipped.png"/>
<img id ="hospital_iv_bag" src="img/hospital/iv_stand_bag1.png"/>
<img id ="hospital_defib" src="img/hospital/defibrillator_sabrina.png"/>
<img id ="hospital_ventilator" src="img/hospital/ventilator.png"/>
<img id ="hospital_xray_sheet" src="img/hospital/xray_sheet.png"/>
<img id ="hospital_xray_source" src="img/hospital/xray_source.png"/>
<img id ="hospital_ui_patient_needs_bg" src="img/hospital/patient_need_icons/bg.png"/>
<img id ="hospital_ui_patient_needs_bg_fixer" src="img/hospital/patient_need_icons/bg_fixer.png"/>
<img id ="hospital_ui_patient_needs_attention" src="img/hospital/patient_need_icons/attention.png"/>
<img id ="hospital_ui_patient_needs_low_fluids" src="img/hospital/patient_need_icons/low_fluids.png"/>
<img id ="hospital_ui_patient_needs_low_oxygen" src="img/hospital/patient_need_icons/low_oxygen.png"/>
<img id ="hospital_ui_patient_needs_no_heartbeat" src="img/hospital/patient_need_icons/no_heartbeat.png"/>
<img id ="hospital_ui_patient_needs_broken_bone" src="img/hospital/patient_need_icons/broken_bone.png"/>
<img id ="hospital_ui_green_cross" src="img/hospital/green_cross_icon.png"/>
<img id ="space_ship1" src="img/space/ship1.png"/>
<img id ="lunar_lander" src="img/space/lunar_lander.png"/>
<img id ="swarm_grass_bg1" src="img/swarm/grass_bg1.png"/>
<img id ="swarm_broccoli" src="img/swarm/broccoli.png"/>
<img id ="swarm_hammer" src="img/swarm/hammer.png"/>
<img id ="brick_wall" src="img/brick_wall.png"/>
<img id ="spider" src="img/spider.png"/>
</div>
<div class="footer_links">
<ul class="footer_links_list">
<li><a id="about_link_footer" href="#">About</a></li>
<li><a href="licenses.html" target="_blank">Licenses</a></li>
<li><a href="https://github.com/alexbarry/AlexGames" target="_blank">Source</a></li>
</div>
<script>
// TODO make this a better abstraction to allow for overriding the messaging API
// to use something other than websockets
const send_message = ws_send_message;
set_unset_game_instructions_visible(false);
const status_msg = document.getElementById("status");
if (typeof WebAssembly === 'undefined') {
let msg = 'WebAssembly is disabled or not supported. One possible cause is having "Lockdown Mode" enabled on Apple devices.';
console.error(msg);
let gfx = {
"status_msg": status_msg,
};
set_status_err(gfx, msg);
set_fullscreen_err(msg);
} else {
console.debug("WebAssembly variable is defined");
}
let wasm_init = false;
let ws_init = false;
let ws_error = false;
let ws_error_msg = null;
let html_init = false;
let dict_needed = false;
let dict_is_init = false; // TODO
// If this is set, then don't even try to connect to a websocket (e.g. don't show error messages).
// This is intended for the case where the web version is bundled inside another application
// for offline-only use.
let no_ws = (URL_args && URL_args.no_ws && URL_args.no_ws.toLowerCase() == "true");
let game_ready_without_network = () => { return wasm_init && html_init && ( !dict_needed || dict_is_init); };
let network_ready = () => { return (ws_init || ws_error); };
let allReady = () => { return game_ready_without_network() && (no_ws || network_ready()); };
// doing it this way might be too late, we could miss the event
//Module['onRuntimeInitialized'] = function() {
var Module = null;
createMyModule().then(MyModule => {
// TODO rename this to something unique
Module = MyModule;
wasm_init = true;
console.log("[init] wasm init");
partial_init();
});
let canvas = document.getElementById("game_canvas");
let graphics_map = new Map();
graphics_map.set("board", document.getElementById("board"));
graphics_map.set("piece_black", document.getElementById("piece_black"));
graphics_map.set("piece_white", document.getElementById("piece_white"));
graphics_map.set("piece_highlight", document.getElementById("piece_highlight"));
graphics_map.set("piece_king_icon", document.getElementById("piece_king_icon"));
graphics_map.set("card_blank" , document.getElementById("card_blank"));
graphics_map.set("card_facedown" , document.getElementById("card_facedown"));
graphics_map.set("card_highlight", document.getElementById("card_highlight"));
graphics_map.set("card_diamonds" , document.getElementById("card_diamonds"));
graphics_map.set("card_hearts" , document.getElementById("card_hearts" ));
graphics_map.set("card_spades" , document.getElementById("card_spades" ));
graphics_map.set("card_clubs" , document.getElementById("card_clubs" ));
graphics_map.set("more_info_btn" , document.getElementById("more_info_btn"));
graphics_map.set("backgammon_triangle_black" , document.getElementById("backgammon_triangle_black"));
graphics_map.set("backgammon_triangle_white" , document.getElementById("backgammon_triangle_white"));
graphics_map.set("backgammon_triangle_highlight" , document.getElementById("backgammon_triangle_highlight"));
graphics_map.set("chess_rook_white", document.getElementById("chess_rook_white"));
graphics_map.set("chess_knight_white", document.getElementById("chess_knight_white"));
graphics_map.set("chess_bishop_white", document.getElementById("chess_bishop_white"));
graphics_map.set("chess_pawn_white", document.getElementById("chess_pawn_white"));
graphics_map.set("chess_queen_white", document.getElementById("chess_queen_white"));
graphics_map.set("chess_king_white", document.getElementById("chess_king_white"));
graphics_map.set("chess_rook_black_dark", document.getElementById("chess_rook_black_dark"));
graphics_map.set("chess_knight_black_dark", document.getElementById("chess_knight_black_dark"));
graphics_map.set("chess_bishop_black_dark", document.getElementById("chess_bishop_black_dark"));
graphics_map.set("chess_pawn_black_dark", document.getElementById("chess_pawn_black_dark"));
graphics_map.set("chess_queen_black_dark", document.getElementById("chess_queen_black_dark"));
graphics_map.set("chess_king_black_dark", document.getElementById("chess_king_black_dark"));
graphics_map.set("chess_rook_black", document.getElementById("chess_rook_black"));
graphics_map.set("chess_knight_black", document.getElementById("chess_knight_black"));
graphics_map.set("chess_bishop_black", document.getElementById("chess_bishop_black"));
graphics_map.set("chess_pawn_black", document.getElementById("chess_pawn_black"));
graphics_map.set("chess_queen_black", document.getElementById("chess_queen_black"));
graphics_map.set("chess_king_black", document.getElementById("chess_king_black"));
graphics_map.set("dice1" , document.getElementById("dice1"));
graphics_map.set("dice2" , document.getElementById("dice2"));
graphics_map.set("dice3" , document.getElementById("dice3"));
graphics_map.set("dice4" , document.getElementById("dice4"));
graphics_map.set("dice5" , document.getElementById("dice5"));
graphics_map.set("dice6" , document.getElementById("dice6"));
graphics_map.set("arrow" , document.getElementById("arrow"));
graphics_map.set("minesweeper_mine" , document.getElementById("minesweeper_mine" ));
graphics_map.set("minesweeper_box1" , document.getElementById("minesweeper_box1" ));
graphics_map.set("minesweeper_box2" , document.getElementById("minesweeper_box2" ));
graphics_map.set("minesweeper_box3" , document.getElementById("minesweeper_box3" ));
graphics_map.set("minesweeper_box4" , document.getElementById("minesweeper_box4" ));
graphics_map.set("minesweeper_box5" , document.getElementById("minesweeper_box5" ));
graphics_map.set("minesweeper_box6" , document.getElementById("minesweeper_box6" ));
graphics_map.set("minesweeper_box7" , document.getElementById("minesweeper_box7" ));
graphics_map.set("minesweeper_box8" , document.getElementById("minesweeper_box8" ));
graphics_map.set("minesweeper_box_unclicked" , document.getElementById("minesweeper_box_unclicked" ));
graphics_map.set("minesweeper_box_empty" , document.getElementById("minesweeper_box_empty" ));
graphics_map.set("minesweeper_box_flagged_red" , document.getElementById("minesweeper_box_flagged_red" ));
graphics_map.set("minesweeper_box_flagged_blue" , document.getElementById("minesweeper_box_flagged_blue" ));
graphics_map.set("hospital_floor_tile" , document.getElementById("hospital_floor_tile" ));
graphics_map.set("hospital_floor_tile_bad" , document.getElementById("hospital_floor_tile_bad" ));
graphics_map.set("hospital_doctor1" , document.getElementById("hospital_doctor1" ));
graphics_map.set("hospital_doctor2" , document.getElementById("hospital_doctor2" ));
graphics_map.set("hospital_doctor3" , document.getElementById("hospital_doctor3" ));
graphics_map.set("hospital_doctor4" , document.getElementById("hospital_doctor4" ));
graphics_map.set("hospital_patient_in_bed" , document.getElementById("hospital_patient_in_bed" ));
graphics_map.set("hospital_patient_in_bed_flipped" , document.getElementById("hospital_patient_in_bed_flipped" ));
graphics_map.set("hospital_ui_dirpad" , document.getElementById("hospital_ui_dirpad" ));
graphics_map.set("hospital_ui_thumb_buttons" , document.getElementById("hospital_ui_thumb_buttons" ));
graphics_map.set("hospital_bed" , document.getElementById("hospital_bed" ));
graphics_map.set("hospital_bed_flipped" , document.getElementById("hospital_bed_flipped" ));
graphics_map.set("hospital_iv_bag" , document.getElementById("hospital_iv_bag" ));
graphics_map.set("hospital_defib" , document.getElementById("hospital_defib" ));
graphics_map.set("hospital_ventilator" , document.getElementById("hospital_ventilator" ));
graphics_map.set("hospital_xray_sheet" , document.getElementById("hospital_xray_sheet" ));
graphics_map.set("hospital_xray_source" , document.getElementById("hospital_xray_source" ));
graphics_map.set("hospital_ui_patient_needs_bg" , document.getElementById("hospital_ui_patient_needs_bg"));
graphics_map.set("hospital_ui_patient_needs_bg_fixer" , document.getElementById("hospital_ui_patient_needs_bg_fixer"));
graphics_map.set("hospital_ui_patient_needs_attention" , document.getElementById("hospital_ui_patient_needs_attention"));
graphics_map.set("hospital_ui_patient_needs_low_fluids" , document.getElementById("hospital_ui_patient_needs_low_fluids"));
graphics_map.set("hospital_ui_patient_needs_low_oxygen" , document.getElementById("hospital_ui_patient_needs_low_oxygen"));
graphics_map.set("hospital_ui_patient_needs_no_heartbeat" , document.getElementById("hospital_ui_patient_needs_no_heartbeat"));
graphics_map.set("hospital_ui_patient_needs_broken_bone" , document.getElementById("hospital_ui_patient_needs_broken_bone"));
graphics_map.set("hospital_ui_green_cross" , document.getElementById("hospital_ui_green_cross"));
graphics_map.set("space_ship1" , document.getElementById("space_ship1"));
graphics_map.set("lunar_lander" , document.getElementById("lunar_lander"));
graphics_map.set("swarm_grass_bg1" , document.getElementById("swarm_grass_bg1"));
graphics_map.set("swarm_broccoli" , document.getElementById("swarm_broccoli"));
graphics_map.set("swarm_hammer" , document.getElementById("swarm_hammer"));
graphics_map.set("brick_wall", document.getElementById("brick_wall"));
graphics_map.set("spider", document.getElementById("spider"));
let popup = document.getElementById("popup");
let status_err = document.getElementById("status_err");
let game_options_div = document.getElementById("game_options");
let g_session_id = null;
let g_options_visible = false;
let gfx = new_gfx(canvas, graphics_map, popup, status_msg, status_err, game_options_div);
gfx.game_options_none_placeholder = document.getElementById("game_options_none_placeholder");
gfx.game_choice_popup = document.getElementById("game_choice_popup");
if (URL_args.state) {
gfx.url_state_b64 = URL_args.state
}
const session_id_input = document.getElementById("session_id_input");
const custom_ws_server_input = document.getElementById("custom_ws_server_input");
const board_size = Math.min(canvas.height, canvas.width);
window.onload = function() {
console.log("[init] html init");
set_unset_game_instructions_visible(true);
html_init = true;
partial_init();
}
canvas.addEventListener('click', handle_canvas_clicked);
document.getElementById('unset_game_instructions').addEventListener('click', () => {
console.debug("User clicked 'unset_game_instructions' element. This should be hidden or blocked by the canvas once a game has been initialized.");
if (gfx.game_id == UNSET_GAME_ID) {
set_game_choice_popup_visible(true);
}
});
let ws = init_ws(no_ws);
if (URL_args && URL_args.id) {
g_session_id = URL_args.id;
session_id_input.value = g_session_id;
if (!no_ws) {
ws_connect_to_session(ws, g_session_id);
}
} else {
if (!no_ws) {
ws_new_session(ws);
}
}
if (URL_args && URL_args.game) {
console.log("[init] URL_args: setting gfx.game_id to ", URL_args.game);
gfx.game_id = URL_args.game;
console.log("Initializing game ", gfx.game_id);
} else {
}
//set_header_visible(true);
set_game_title(gfx.game_id);
let user_colour_pref = get_user_colour_pref();
if (user_colour_pref) {
set_html_colour_theme(user_colour_pref);
}
</script>
<script>
document.getElementById("btn_options").addEventListener('click', function () {
set_options_popup_visible(true);
});
document.getElementById("btn_status_options").addEventListener('click', function () {
set_options_popup_visible(true);
});
document.getElementById("btn_close_options").addEventListener('click', function () {
set_options_popup_visible(false);
});
document.getElementById("btn_game_select").addEventListener('click', function () {
console.log("[init] btn_game_select clicked: calling game_chosen(UNSET_GAME_ID)");
game_chosen(UNSET_GAME_ID);
});
document.getElementById("btn_history_browse").addEventListener('click', function () {
console.log("[init] btn_game_select clicked: calling game_chosen('history_browse')");
game_chosen("history_browse");
});
document.getElementById("about_link_footer").addEventListener('click', function () {
set_about_popup_visible(true);
});
document.getElementById("about_link_options").addEventListener('click', function () {
set_about_popup_visible(true);
});
document.getElementById("btn_close_about_popup").addEventListener('click', function () {
set_about_popup_visible(false);
});
document.getElementById("input_upload_game_bundle").addEventListener("change", function () {
document.getElementById("btn_process_uploaded_game_bundle").disabled = false;
});
document.getElementById("btn_process_uploaded_game_bundle").addEventListener('click', function () {
let fileReader = new FileReader();
fileReader.onload = function () {
console.debug("File onload");