<commit_before>'use strict';

var game = new Phaser.Game(1366, 768, Phaser.AUTO, '', null, false, false);

var MainState = function() {};
MainState.prototype = {
    worldLength: 20,
    tileSize: 64,
    xOffset: 43,
    yPosition: (768 / 2) - 32,
    tileScale: undefined,

    startTime: undefined,
    gameover: false,

    timeText: undefined,
    mineText: undefined,

    blopp2SFX: undefined,

    mineCount: 5,
    flagCount: 5,
    tiles: [],
    buttons: [],
    hoveredTile: undefined,
    faceSprite: undefined,

    preload: function() {
        // allow the player to right click without the menu popping up
        game.canvas.oncontextmenu = function (e) { e.preventDefault(); }

        this.startTime = Date.now();

        this.tileScale = this.tileSize / 16;
        game.load.image('bg',       'assets/sprites/bg.png');

        // unclicked
        game.load.image('flag',     'assets/sprites/flag.png');
        game.load.image('question', 'assets/sprites/question.png');

        // clicked
        game.load.image('one',      'assets/sprites/one.png');
        game.load.image('two',      'assets/sprites/two.png');
        game.load.image('empty',    'assets/sprites/empty.png');
        game.load.image('mine',     'assets/sprites/mine.png');
        game.load.image('mine_red', 'assets/sprites/mine_red.png');

        game.load.spritesheet('face',        'assets/sprites/face.png',        16, 16, 4);
        game.load.spritesheet('tile_button', 'assets/sprites/tile_button.png', 16, 16, 3);

        game.load.audio('blopp2',    'assets/sfx/blopp2.wav');
        game.load.audio('explosion', 'assets/sfx/explosion.wav');

	    game.load.script('utilScript',          '../js/util.js');
	    game.load.script('directionEnumScript', '../js/direction.enum.js');
	    game.load.script('keycodesScript',      '../js/keycodes.js');

        // necessary to preload the font lol
        game.add.text(0, 0, "", {font: '56px pixelbug', fill: '#ffffff'});
    },
    create: function() {
        game.add.sprite(0, 0, 'bg');
        game.stage.backgroundColor = "#FFFFFF";
        game.scale.pageAlignHorizontally = true;
        game.scale.pageAlignVertically = true;

        this.blopp2SFX = game.add.audio('blopp2');
        this.explosionSFX = game.add.audio('explosion');

        this.faceSprite = game.add.sprite(0 * this.tileSize + this.xOffset, this.yPosition, 'face');
        this.faceSprite.scale.set(this.tileScale, this.tileScale);

        for(var i = 0; i < this.worldLength; ++i) {
            this.tiles.push(undefined); 
            this.buttons.push(undefined);
        }

        // so firstly, we want to work out where all the mines should be placed: 5 of them between position 1 and 39 (0 is the face)
        var minePositions = [];
        for(var i = 0; i < this.mineCount; ++i) {
            var newPos = util.randomInt(1, this.worldLength);
            while(minePositions.indexOf(newPos) != -1) {
                newPos = util.randomInt(1, this.worldLength);
            }
            minePositions.push(newPos);

            // add a mine sprite at this position
            var sprite = game.add.sprite(newPos * this.tileSize + this.xOffset, this.yPosition, 'mine');
            sprite.scale.set(this.tileScale, this.tileScale);

            this.tiles[newPos] = 'M';
            /* debug
            this.tiles[1] = 'M';
            this.tiles[2] = 'M';
            this.tiles[3] = 'M';
            this.tiles[4] = 'M';
            this.tiles[5] = 'M';
            */
        }

        // secondly, check what number the other positions should have
        for(var i = 1; i < this.worldLength; ++i) {
            if(this.tiles[i] == undefined) {
                var count = 0;
                var hej = 0;
                var hoj = 0;

                if(i != 1)
                    hej = this.tiles[i - 1] === 'M' ? 1 : 0;

                if(i != 19)
                    hoj = this.tiles[i + 1] === 'M' ? 1 : 0;

                count += hej;
                count += hoj;

                var texture;
                if(count == 0) {
                    texture = "empty";
                    this.tiles[i] = 0;
                }
                else if(count == 1) {
                    texture = "one";
                    this.tiles[i] = 1;
                }
                else if(count == 2) {
                    texture = "two";
                    this.tiles[i] = 2;
                }

                var sprite = game.add.sprite(i * this.tileSize + this.xOffset, this.yPosition, texture);
                sprite.scale.set(this.tileScale, this.tileScale);
            }
        }

        // lastly, cover over all of them with clickable buttons
        for(var i = 1; i < this.worldLength; ++i) {
            var button = game.add.button(i * this.tileSize + this.xOffset, this.yPosition, 'tile_button', this.checkClickButton, this, 0, 1, 2);
            button.scale.set(this.tileScale, this.tileScale);
            this.buttons[i] = button;
        }

        this.mineText = game.add.text(this.xOffset, 0, this.flagCount, {font: '56px pixelbug', fill: '#ffffff'});
        this.timeText = game.add.text(1366 - this.xOffset, 0, "0", {font: '56px pixelbug', fill: '#ffffff'});
    },
    update: function() {
        if(!this.gameover) {
            this.mineText.text = this.flagCount;
            var secondsElapsed = (Date.now() - this.startTime) / 1000;
            this.timeText.text = Math.floor(secondsElapsed);
            util.rightAlignText(this.timeText, 1366 - this.xOffset);
            
            this.checkMouseInput();

            if(this.checkWin()) {
                this.win();
            }
        }
    },
    checkMouseInput: function() {
        if(game.input.activePointer.leftButton.isDown) {
            this.faceSprite.frame = 1; // :o
        }
        else if(game.input.activePointer.leftButton.isUp) {
            this.faceSprite.frame = 0; // :)
        }

        if(game.input.activePointer.rightButton.isDown) {
        }
        else if(game.input.activePointer.rightButton.isUp) {<commit_msg>Right click doesn't click on buttons<commit_after>'use strict';

var game = new Phaser.Game(1366, 768, Phaser.AUTO, '', null, false, false);

var MainState = function() {};
MainState.prototype = {
    worldLength: 20,
    tileSize: 64,
    xOffset: 43,
    yPosition: (768 / 2) - 32,
    tileScale: undefined,

    startTime: undefined,
    gameover: false,

    timeText: undefined,
    mineText: undefined,

    blopp2SFX: undefined,

    mineCount: 5,
    flagCount: 5,
    tiles: [],
    buttons: [],
    flags: [],
    hoveredTile: undefined,
    faceSprite: undefined,

    preload: function() {
        // allow the player to right click without the menu popping up
        game.canvas.oncontextmenu = function (e) { e.preventDefault(); }

        this.startTime = Date.now();

        this.tileScale = this.tileSize / 16;
        game.load.image('bg',       'assets/sprites/bg.png');

        // unclicked
        game.load.image('flag',     'assets/sprites/flag.png');
        game.load.image('question', 'assets/sprites/question.png');

        // clicked
        game.load.image('one',      'assets/sprites/one.png');
        game.load.image('two',      'assets/sprites/two.png');
        game.load.image('empty',    'assets/sprites/empty.png');
        game.load.image('mine',     'assets/sprites/mine.png');
        game.load.image('mine_red', 'assets/sprites/mine_red.png');

        game.load.spritesheet('face',        'assets/sprites/face.png',        16, 16, 4);
        game.load.spritesheet('tile_button', 'assets/sprites/tile_button.png', 16, 16, 3);

        game.load.audio('blopp2',    'assets/sfx/blopp2.wav');
        game.load.audio('explosion', 'assets/sfx/explosion.wav');

	    game.load.script('utilScript',          '../js/util.js');
	    game.load.script('directionEnumScript', '../js/direction.enum.js');
	    game.load.script('keycodesScript',      '../js/keycodes.js');

        // necessary to preload the font lol
        game.add.text(0, 0, "", {font: '56px pixelbug', fill: '#ffffff'});
    },
    create: function() {
        game.add.sprite(0, 0, 'bg');
        game.stage.backgroundColor = "#FFFFFF";
        game.scale.pageAlignHorizontally = true;
        game.scale.pageAlignVertically = true;

        this.blopp2SFX = game.add.audio('blopp2');
        this.explosionSFX = game.add.audio('explosion');

        this.faceSprite = game.add.sprite(0 * this.tileSize + this.xOffset, this.yPosition, 'face');
        this.faceSprite.scale.set(this.tileScale, this.tileScale);

        for(var i = 0; i < this.worldLength; ++i) {
            this.tiles.push(undefined); 
            this.buttons.push(undefined);
        }

        // so firstly, we want to work out where all the mines should be placed: 5 of them between position 1 and 39 (0 is the face)
        var minePositions = [];
        for(var i = 0; i < this.mineCount; ++i) {
            var newPos = util.randomInt(1, this.worldLength);
            while(minePositions.indexOf(newPos) != -1) {
                newPos = util.randomInt(1, this.worldLength);
            }
            minePositions.push(newPos);

            // add a mine sprite at this position
            var sprite = game.add.sprite(newPos * this.tileSize + this.xOffset, this.yPosition, 'mine');
            sprite.scale.set(this.tileScale, this.tileScale);

            this.tiles[newPos] = 'M';
            /* debug
            this.tiles[1] = 'M';
            this.tiles[2] = 'M';
            this.tiles[3] = 'M';
            this.tiles[4] = 'M';
            this.tiles[5] = 'M';
            */
        }

        // secondly, check what number the other positions should have
        for(var i = 1; i < this.worldLength; ++i) {
            if(this.tiles[i] == undefined) {
                var count = 0;
                var hej = 0;
                var hoj = 0;

                if(i != 1)
                    hej = this.tiles[i - 1] === 'M' ? 1 : 0;

                if(i != 19)
                    hoj = this.tiles[i + 1] === 'M' ? 1 : 0;

                count += hej;
                count += hoj;

                var texture;
                if(count == 0) {
                    texture = "empty";
                    this.tiles[i] = 0;
                }
                else if(count == 1) {
                    texture = "one";
                    this.tiles[i] = 1;
                }
                else if(count == 2) {
                    texture = "two";
                    this.tiles[i] = 2;
                }

                var sprite = game.add.sprite(i * this.tileSize + this.xOffset, this.yPosition, texture);
                sprite.scale.set(this.tileScale, this.tileScale);
            }
        }

        // lastly, cover over all of them with clickable buttons
        for(var i = 1; i < this.worldLength; ++i) {
            var button = game.add.button(i * this.tileSize + this.xOffset, this.yPosition, 'tile_button', this.checkClickButton, this, 0, 1, 2);
            button.scale.set(this.tileScale, this.tileScale);
            this.buttons[i] = button;
        }

        this.mineText = game.add.text(this.xOffset, 0, this.flagCount, {font: '56px pixelbug', fill: '#ffffff'});
        this.timeText = game.add.text(1366 - this.xOffset, 0, "0", {font: '56px pixelbug', fill: '#ffffff'});
    },
    update: function() {
        if(!this.gameover) {
            this.mineText.text = this.flagCount;
            var secondsElapsed = (Date.now() - this.startTime) / 1000;
            this.timeText.text = Math.floor(secondsElapsed);
            util.rightAlignText(this.timeText, 1366 - this.xOffset);
            
            this.checkMouseInput();

            if(this.checkWin()) {
                this.win();
            }
        }
    },
    checkMouseInput: function() {
        if(game.input.activePointer.leftButton.isDown) {
            this.faceSprite.frame = 1; // :o
        }
        else if(game.input.activePointer.leftButton.isUp) {
            this.faceSprite.frame = 0; // :)
        }

        if(game.input.activePointer.rightButton.isDown) {
            // hack to disable button right click
            for(let button of this.buttons) {
                if(button != undefined) {
                    button.inputEnabled = false;
                }
            }
        }
        else if(game.input.activePointer.rightButton.isUp) {
            // hack to disable button right click
            for(let button of this.buttons) {
                if(button != undefined) {
                    button.inputEnabled = true;
                }
            }
{'fraction_non_alphanumeric': 0.14231648663565402, 'fraction_numerical': 0.01639990538516124, 'mean_word_length': 1.7242268041237114, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4012004', 'n_tokens_mistral': 4119, 'n_tokens_neox': 3837, 'n_words': 798}