Gitlab CSE Unil

games.html 22.7 KB
Newer Older
M. Chardon's avatar
M. Chardon committed
1
2
3
4
5
6
7
8
<!DOCTYPE html>
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>@lea</title>
        <meta name="author" content="Marion CHARDON for ESC/RISET - University of Lausanne" />
        <meta name="description" content="Free Web tool for guess data" />
        <meta name="keywords" content="Cipher, Bigdata, Guess" />
        <meta charset="UTF-8" />
M. Chardon's avatar
M. Chardon committed
9
10
11
12
        <link rel="stylesheet" href="../node_modules/bootstrap3/dist/css/bootstrap.min.css" /> 
        <link rel="stylesheet" href="css/dashboard.css" />
        <link rel="stylesheet" href="../node_modules/font-awesome/css/font-awesome.min.css" />
        <link rel="stylesheet" href="../css/logo_unil.css" />
M. Chardon's avatar
M. Chardon committed
13
        <link rel="stylesheet" href="../css/main.css" />
M. Chardon's avatar
M. Chardon committed
14
15
        <script src="../node_modules/jquery/dist/jquery.min.js"></script>
        <script src="../node_modules/bootstrap3/dist/js/bootstrap.min.js"></script>
M. Chardon's avatar
M. Chardon committed
16
17
18
19
20
21
22
23
24
25
        <script src="js/crypto/asmcrypto.js"></script>
        <script src="js/controleur.js"></script>
        <script src="js/entities/global.js"></script>
        <script src="js/entities/modeleTwo.js"></script>
        <script src="js/entities/modeleThree.js"></script>
        <script src="js/entities/modeleFour.js"></script>
        <script src="js/entities/modeleMaskEight.js"></script>
        <script src="js/entities/resultat.js"></script>
        <script src="js/graph/d3.v4.min.js"></script>
        <script src="js/graph/gauge.js"></script>
M. Chardon's avatar
M. Chardon committed
26
27
28
29
30
31
32
33
34
        <script src="js/graph.js"></script>        
        <script src="../js/jquery.i18n/libs/CLDRPluralRuleParser/src/CLDRPluralRuleParser.js"></script>
        <script src="../js/jquery.i18n/jquery.i18n/src/jquery.i18n.js"></script>
        <script src="../js/jquery.i18n/jquery.i18n/src/jquery.i18n.messagestore.js"></script>
        <script src="../js/jquery.i18n/jquery.i18n/src/jquery.i18n.fallbacks.js"></script>
        <script src="../js/jquery.i18n/jquery.i18n/src/jquery.i18n.parser.js"></script>
        <script src="../js/jquery.i18n/jquery.i18n/src/jquery.i18n.emitter.js"></script>
        <script src="../js/jquery.i18n/jquery.i18n/src/jquery.i18n.language.js"></script>
        <script src="js/languages.js"></script>
M. Chardon's avatar
M. Chardon committed
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
    </head>
    <body>
        <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
            <div class="container">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="../index.html"><img src="../img/g3761.png" alt="" style="height:28px;display: inline;"/>Cryptex - @lea</a>
                </div>
                <div id="navbar" class="navbar-collapse collapse">
                    <ul class="nav navbar-nav navbar-right">
M. Chardon's avatar
M. Chardon committed
50
51
                        <li><a onclick="initLang('en');"><img style="background: white; height:25px;" alt="English" src="../img/flags/english.png"/></a></li>
                        <li><a onclick="initLang('fr');"><img style="background: white;height:25px;" alt="Français" src="../img/flags/french.png"/></a></li>
M. Chardon's avatar
M. Chardon committed
52
                        <li><a href="help.html"><span class="i18n" data-lang="help"></span></a></li>
M. Chardon's avatar
M. Chardon committed
53
54
55
56
57
58
59
60
                    </ul>
                </div>
            </div>
        </nav>    
        <div class="container" style="margin-bottom: 70px; margin-top: 20px;">
            <div class="row">
                <div class="col-sm-3">
                    <ul class="nav nav-pills nav-stacked">
M. Chardon's avatar
M. Chardon committed
61
62
63
64
                        <li><a href="index.html"><span class="i18n" data-lang="step1"></span></a></li>
                        <li><a href="pasapas.html"><span class="i18n" data-lang="step2"></span></a></li>
                        <li><a href="understand.html"><span class="i18n" data-lang="step3"></span></a></li>
                        <li class="active"><a href="games.html"><span class="i18n" data-lang="step4"></span></a></li>
M. Chardon's avatar
M. Chardon committed
65
66
67
68
69
70
71
72
73
                    </ul>
                </div>
                <div class="col-sm-9" style="padding-left: 20px;">

                    <div class="row">
                        <div class="col-sm-12">
                            <div class="alert alert-info alert-dismissable">
                                <strong>Info!</strong>
                                <p>
M. Chardon's avatar
M. Chardon committed
74
                                    <span class="i18n" data-lang="game_info"></span>
M. Chardon's avatar
M. Chardon committed
75
76
77
78
                                </p>
                            </div>

                            <div class="panel panel-default" id='playerdiv'>
M. Chardon's avatar
M. Chardon committed
79
                                <div class="panel-heading"><span class="i18n" data-lang="game_config"></span></div>
M. Chardon's avatar
M. Chardon committed
80
81
82
                                <div class="panel-body">
                                    <div class="row" >
                                        <div class="col-sm-4">
M. Chardon's avatar
M. Chardon committed
83
84
85
                                            <b><span class="i18n" data-lang="game_play_against"></span>:</b><br/>
                                            <input class='vs' type="radio" name="vs" value="computer" checked='checked' /> <span class="i18n" data-lang="game_play_against_computeur"></span><br/>
                                            <input class='vs' type="radio" name="vs" value="player"/> <span class="i18n" data-lang="game_play_against_other_player"></span>   
M. Chardon's avatar
M. Chardon committed
86
87
                                        </div>
                                        <div class="col-sm-4">
M. Chardon's avatar
M. Chardon committed
88
                                            <b><span class="i18n" data-lang="game_play_against_other_player_name"></span>:</b><br/>
M. Chardon's avatar
M. Chardon committed
89
90
91
92
                                            <input type="text" id="nameplayerA" placeholder="Player A" class='form-control' />
                                            <input type="text" id="nameplayerB" placeholder="Player B" class='form-control' style='display: none;'/>
                                        </div>
                                        <div class="col-sm-offset-1 col-sm-3">
M. Chardon's avatar
M. Chardon committed
93
                                            <button class="btn btn-default" onclick="startGame();"><i class="fa fa-play" aria-hidden="true"></i> <span class="i18n" data-lang="game_play_ok"></span>!</button>
M. Chardon's avatar
M. Chardon committed
94
95
96
97
98
99
100
101
102
103
104
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="row" id='gamediv' style='display: none;'>
                        <div class="row">

                            <div class="col-sm-offset-9 col-sm-1">
M. Chardon's avatar
M. Chardon committed
105
                                <button class="btn btn-default" onclick="reset();"><span class="i18n" data-lang="game_restart"></span></button>
M. Chardon's avatar
M. Chardon committed
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
                            </div>
                        </div>
                        <div class="row" style='margin-top: 10px;'>

                            <div class="col-sm-6">

                                <div class="panel panel-warning">
                                    <div class="panel-heading">Player A</div>
                                    <div class="panel-body">
                                        <div class="row" style="padding-bottom: 10px;padding-top: 10px;">
                                            <div class="col-sm-10">
                                                <button class="btn btn-info btn-lg btnbre" onclick="insertVal(0, 'A');">0 [s]</button>
                                                <button class="btn btn-primary btn-lg btnbre" onclick="insertVal(1, 'A');">1 [d]</button>
                                            </div>
                                        </div>
                                        <div class="row" style="padding: 10px;">
                                            <div class="col-sm-12">
                                                <textarea class="form-control" readonly="readonly" id="userinputA" style="font-size: large;height: 150px;background-color: papayawhip;"></textarea>
                                                <div id="userinputdivA" style="display: none;"></div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div style="text-align: center;">
                                    <span id="playerAGaugeContainer"></span>
                                </div>
                                <div class="row" id='propositionPanelA' style="display:none;">
                                    <div class="col-sm-12">
                                        <div class="panel panel-primary">
M. Chardon's avatar
M. Chardon committed
135
                                            <div class="panel-heading"><span class="i18n" data-lang="perc_correct"></span></div>
M. Chardon's avatar
M. Chardon committed
136
137
138
                                            <div class="panel-body">
                                                <div class="row">
                                                    <ul>
M. Chardon's avatar
M. Chardon committed
139
140
                                                        <li><span style="color:orange;"><span class="i18n" data-lang="orange_wrong"></span></span></li>
                                                        <li><span style="color:blue;"><span class="i18n" data-lang="blue_right"></span></span></li>
M. Chardon's avatar
M. Chardon committed
141
142
                                                    </ul>
                                                    <div class="col-sm-6">
M. Chardon's avatar
M. Chardon committed
143
                                                        <span class="i18n" data-lang="tot_right"></span>:
M. Chardon's avatar
M. Chardon committed
144
145
146
                                                        <input class="form-control" readonly="readonly" id="guessValueCorrectA" />
                                                    </div>
                                                    <div class="col-sm-6">
M. Chardon's avatar
M. Chardon committed
147
                                                        <span class="i18n" data-lang="10_res"></span>:
M. Chardon's avatar
M. Chardon committed
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
                                                        <input class="form-control" readonly="readonly" id="guessValueCorrect10A" />
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                            </div>

                            <div class="col-sm-6">

                                <div class="panel panel-success">
                                    <div class="panel-heading">Player B</div>
                                    <div class="panel-body">
                                        <div class="row" style="padding-bottom: 10px;padding-top: 10px;">
                                            <div class="col-sm-10">
                                                <button class="btn btn-info btn-lg btnbre" onclick="insertVal(0, 'B');">0 [k]</button>
                                                <button class="btn btn-primary btn-lg btnbre" onclick="insertVal(1, 'B');">1 [l]</button>
                                            </div>
                                        </div>
                                        <div class="row" style="padding-bottom: 42px;display: none;" id="computerplayer"></div>
                                        <div class="row" style="padding: 10px;">
                                            <div class="col-sm-12">
                                                <textarea class="form-control" readonly="readonly" id="userinputB" style="font-size: large;height: 150px;background-color: mintcream;"></textarea>
                                                <div id="userinputdivB" style="display: none;"></div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div style="text-align: center;">
                                    <span id="playerBGaugeContainer"></span>
                                </div>
                                <div class="row" id='propositionPanelB' style="display:none;">
                                    <div class="col-sm-12">
                                        <div class="panel panel-primary">
M. Chardon's avatar
M. Chardon committed
184
                                            <div class="panel-heading"><span class="i18n" data-lang="perc_correct"></span></div>
M. Chardon's avatar
M. Chardon committed
185
186
187
                                            <div class="panel-body">
                                                <div class="row">
                                                    <ul>
M. Chardon's avatar
M. Chardon committed
188
189
                                                        <li><span style="color:orange;"><span class="i18n" data-lang="orange_wrong"></span></span></li>
                                                        <li><span style="color:blue;"><span class="i18n" data-lang="blue_right"></span></span></li>
M. Chardon's avatar
M. Chardon committed
190
191
                                                    </ul>
                                                    <div class="col-sm-6">
M. Chardon's avatar
M. Chardon committed
192
                                                        <span class="i18n" data-lang="tot_right"></span>:
M. Chardon's avatar
M. Chardon committed
193
194
195
                                                        <input class="form-control" readonly="readonly" id="guessValueCorrectB" />
                                                    </div>
                                                    <div class="col-sm-6">
M. Chardon's avatar
M. Chardon committed
196
                                                        <span class="i18n" data-lang="10_res"></span>:
M. Chardon's avatar
M. Chardon committed
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
                                                        <input class="form-control" readonly="readonly" id="guessValueCorrect10B" />
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                            </div>
                        </div>
                    </div>
                </div>

                <!--div class="col-sm-6">
                    <svg id="graphic" width="960" height="500"></svg>
                </div-->
            </div>
        </div>


        <div id="contacts" class="modal fade" role="dialog"></div>
        <div id="credits" class="modal fade" role="dialog"></div>
        <div id="legalInformation" class="modal fade" role="dialog"></div>
        <footer class="footer"></footer>

        <script>

            var controleurA = new Controleur("game");
            var controleurB = new Controleur("game");
            var limitGame = 200;

            var gauges = [];

            function createGauge(name, label, min, max)
            {
                var config =
                        {
                            size: 180,
                            label: label,
                            min: undefined !== min ? min : 0,
                            max: undefined !== max ? max : 100,
                            minorTicks: 5
                        };

                var range = config.max - config.min;
                config.yellowZones = [{from: config.min + range * 0.70, to: config.min + range * 0.9}];
                config.redZones = [{from: config.min + range * 0.9, to: config.max}];

                gauges[name] = new Gauge(name + "GaugeContainer", config);
                gauges[name].render();
            }

            function createGauges()
            {
                createGauge("playerA", "Divination");
                createGauge("playerB", "Divination");
                //createGauge("test", "Test", -50, 50 );
            }

            function updateGaugesVal(key, value)
            {
                gauges[key].redraw(value);
            }

            function initialize()
            {
                createGauges();
                updateGaugesVal('playerA', 0);
                updateGaugesVal('playerB', 0);
                //setInterval(updateGauges, 5000);
            }


            $(document).ready(function () {
                $("input[name='vs']").on('change', function () {
                    var vs = $('input[name=vs]:checked').val();
                    if (vs === "computer") {
                        $("#nameplayerB").hide();
                    } else {
                        $("#nameplayerB").show();
                    }
                });
                initialize();
            });

            function trigKeyDownInit(event) {
                //event.preventDefault();
                if (event.which === 83) {
                    insertVal(0, 'A');
                } else if (event.which === 68) {
                    insertVal(1, 'A');
                }
                var vs = $('input[name=vs]:checked').val();
                if (vs !== "computer") {
                    if (event.which === 75) {
                        insertVal(0, 'B');
                    } else if (event.which === 76) {
                        insertVal(1, 'B');
                    }
                }
            }

            function insertVal(val, player) {
                var nbreSaisis = -1;
                if (player === "A") {
                    nbreSaisis = controleurA.suite.length;
                } else {
                    nbreSaisis = controleurB.suite.length;
                }
                if (nbreSaisis < limitGame) {
                    $("#userinput" + player).val($("#userinput" + player).val() + val);
                    nbreSaisis++;
                    var res = null;
                    if (player === "A") {
                        controleurA.registerVal(val);
                        res = controleurA.guestNextValue();
                    } else {
                        controleurB.registerVal(val);
                        res = controleurB.guestNextValue();
                    }
                    if (res) {
                        $("#guessValue" + player).val(res.valeur);
                        var controlelastValue = null;
                        if (player === "A") {
                            controlelastValue = controleurA.getControlelastValue();
                        } else {
                            controlelastValue = controleurB.getControlelastValue();
                        }
                        if (controlelastValue !== null) {
                            if (controlelastValue > 0)
                                $('#userinputdiv' + player).append('<span style="color:blue;">' + val + '</span> ');
                            else
                                $('#userinputdiv' + player).append('<span style="color:orange;">' + val + '</span> ');
                        } else {
                            $('#userinputdiv' + player).append(val + ' ');
                        }
                    } else {
                        $('#userinputdiv' + player).append(val + ' ');
                    }
                    if (player === "A") {
                        controleurA.majIndices('A');
                        if (res && controleurA.global.reponses.length > 0) {
                            updateGaugesVal('playerA', getNbreBonnesReponses(controleurA.global.reponses) * 100 / (controleurA.global.reponses.length));
                        }
                    } else {
                        controleurB.majIndices('B');
                        if (res && controleurB.global.reponses.length > 0) {
                            updateGaugesVal('playerB', getNbreBonnesReponses(controleurB.global.reponses) * 100 / (controleurB.global.reponses.length));
                        }
                    }
                    if (nbreSaisis === limitGame) {
                        $("#propositionPanel" + player).show();
                        $(".btnbre").hide();
                        $("#userinput" + player).hide();
                        $('#userinputdiv' + player).show();
                        $("#computerplayer").hide();
                        //$('body').off('keydown');
                    }

                    if (player === "A" && playerB === "computer") {
                        insertVal(getCharAleatoire(), 'B');
                    }
                }
            }

            function reset() {
                controleurA.resetApi();
                controleurB.resetApi();
                $("input[name!=vs]").each(function () {
                    $(this).val("");
                });
                $("textarea").each(function () {
                    $(this).val("");
                });
                $("#propositionPanelA").hide();
                $("#propositionPanelB").hide();
                $(".btnbre").show();
                $("#userinputA").show();
                $("#userinputdivA").html("");
                $("#userinputdivA").hide();
                $("#userinputB").show();
                $("#userinputdivB").html("");
                $("#userinputdivB").hide();

                $('body').off('keydown');
                //$('body').on('keydown', trigKeyDownInit);

                $("#gamediv").hide();
                $("#playerdiv").show();
                $("#nameplayerB").hide();
                $("input[name=vs][value=computer]").prop('checked', true);
                $("#computerplayer").hide();

                updateGaugesVal('playerA', 0);
                updateGaugesVal('playerB', 0);
            }

            function startGame() {
                if ($("#nameplayerA").val() && $("#nameplayerA").val().length > 0) {
                    $(".panel-warning > .panel-heading").html($("#nameplayerA").val());
                } else
                    $(".panel-warning > .panel-heading").html("Player A");
                var vs = $('input[name=vs]:checked').val();
                if (vs === "computer") {
M. Chardon's avatar
M. Chardon committed
401
                    $(".panel-success > .panel-heading").html($.i18n("game_computeur"));
M. Chardon's avatar
M. Chardon committed
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
                    $(".panel-success button").hide();
                    playerB = "computer";
                    $("#computerplayer").show();
                } else {
                    playerB = "player";
                    if ($("#nameplayerB").val() && $("#nameplayerB").val().length > 0) {
                        $(".panel-success > .panel-heading").html($("#nameplayerB").val());
                    } else {
                        $(".panel-success > .panel-heading").html("Player B");
                    }
                    $(".panel-success button").show();
                    $("#computerplayer").hide();
                }

                $("#gamediv").show();
                $("#playerdiv").hide();
                $('body').on('keydown', trigKeyDownInit);
            }
        </script>

        <script src="../js/main.js"></script>

    </body>
</html>