{"size": 1619, "ext": "js", "max_stars_repo_path": "src/js/game.js", "max_stars_repo_name": "wangjiezhe/Majiang", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/js/game.js", "max_issues_repo_name": "wangjiezhe/Majiang", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/js/game.js", "max_forks_repo_name": "wangjiezhe/Majiang", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.9076923077, "max_line_length": 73, "alphanum_fraction": 0.5015441631}
/*!
 *
 *  game.js
 *
 *  Copyright(C) 2017 Satoshi Kobayashi
 *  Released under the MIT license
 *  https://github.com/kobalab/Majiang/blob/master/LICENSE
 */

"use strict";

let ua = navigator.userAgent;
if (ua.match(/\bMSIE\b/) || ua.match(/\bTrident\b/)) {
    Majiang.Player = require('./majiang/dev/player0202');
}

let loaded;

$(function(){
    let game, paipu;

    function start() {
        $('#game > .player').hide();
        $('body').attr('class','game');
        game = new Majiang.Game();
        new Majiang.View.GameCtl($('#game'), game);
        game._player = [
            new Majiang.View.Player(0, $('#game')),
            new Majiang.Player(1),
            new Majiang.Player(2),
            new Majiang.Player(3),
        ];
        game._callback = end;
        game.kaiju();
    }

    function end() {
        $('body').attr('class','file').hide().fadeIn();
        $('#game > .player').show();
        if (game) {
            paipu._paipu.add(game._paipu);
        }
        while (paipu._paipu.length() > 10) {
            paipu._paipu.del(0);
        }
        paipu.redraw();
    }

    $('.version').text('ver. ' + Majiang.VERSION);

    paipu = new Majiang.View.PaipuFile($('#file .file'), 'Majiang.game');
    $('#file .next').on('click', start);

    $(window).on('load', function(){
        $('#title .loading').hide();
        $('#title .start').on('click', function(){
            if (paipu._paipu.length()) end();
            else                       start();
        }).show();
    });
    if (loaded) $(window).trigger('load');
});

$(window).on('load', ()=>loaded = true);
