<commit_before>function GameGrid(canvas) {
    console.log("Grid: Rezzing");
    this.canvas = canvas;
    this.context = this.canvas.getContext('2d');
    this.init();
}

GameGrid.prototype.init = function() {
    this.player = new Player(this, new Vector([this.canvas.width / 2, this.canvas.height / 2]));
    // This will be managed by Waves
    this.enemies = [
        new Warrior(this, new Vector([ Math.random() * (this.canvas.width - config.unitSize) + config.unitSize, Math.random() * (this.canvas.height - config.unitSize) + config.unitSize ])),
        new Warrior(this, new Vector([ Math.random() * (this.canvas.width - config.unitSize) + config.unitSize, Math.random() * (this.canvas.height - config.unitSize) + config.unitSize ])),
        new Bulldog(this, new Vector([ Math.random() * (this.canvas.width - config.unitSize) + config.unitSize, Math.random() * (this.canvas.height - config.unitSize) + config.unitSize ]))
    ];
}

GameGrid.prototype.Draw = function() {
    this.DrawBackground();
    if (this.player) { this.player.Draw() };
    for (var i = 0; i < this.enemies.length; i++) {
        this.enemies[i].Draw();
    }
}

GameGrid.prototype.DrawBackground = function() {
    this.context.fillStyle = config.gridColor;
    this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
}

GameGrid.prototype.Update = function() {
    if (! this.player) { return; }
    
    // Check for hits/deaths by player
    if (this.player.disc.status == 'deadly') {
        for (var i = 0; i < this.enemies.length; i++) {
            if (this.player.disc.Collided(this.enemies[i])) {
                this.enemies[i].Hit();
                console.log(this.enemies[i].name + ' hit. ' + (this.enemies[i].maxHits - this.enemies[i].hits) + ' left');

                // Check to see if they died
                if (this.enemies[i].hits == this.enemies[i].maxHits) {
                    console.log(this.enemies[i].name + ' derezzed');
                    if (this.enemies[i].regenerateTimer) {
                        window.clearTimeout(this.enemies[i].regenerateTimer);
                    }
                    this.enemies.splice(i, 1);
                }
                
                // Return disc to player
                this.player.disc.Return();
            }
        }
    }
    // Check for player hits/death
    for (var i = 0; i < this.enemies.length; i++) {
        if (this.enemies[i].disc && this.enemies[i].disc.status == 'deadly' && this.enemies[i].disc.Collided(this.player)) {
            this.player.Hit();
            console.log(this.player.name + ' hit. ' + (this.player.maxHits - this.player.hits) + ' left');
            
            if (this.player.hits == this.player.maxHits) {
                console.log(this.player.name + ' derezzed');
                console.log('Game Over');
                this.player = null;
            }
            
            // Return disc to enemy
            this.enemies[i].disc.Return();
        }
    }
    
    // Movement
    if (this.player) { this.player.Update(); }
    for (var i = 0; i < this.enemies.length; i++) {
        this.enemies[i].Update();
    }
}<commit_msg>Bugfix: Game properly ends when players hits are all used up.<commit_after>function GameGrid(canvas) {
    console.log("Grid: Rezzing");
    this.canvas = canvas;
    this.context = this.canvas.getContext('2d');
    this.init();
}

GameGrid.prototype.init = function() {
    this.player = new Player(this, new Vector([this.canvas.width / 2, this.canvas.height / 2]));
    // This will be managed by Waves
    this.enemies = [
        new Warrior(this, new Vector([ Math.random() * (this.canvas.width - config.unitSize) + config.unitSize, Math.random() * (this.canvas.height - config.unitSize) + config.unitSize ])),
        new Warrior(this, new Vector([ Math.random() * (this.canvas.width - config.unitSize) + config.unitSize, Math.random() * (this.canvas.height - config.unitSize) + config.unitSize ])),
        new Bulldog(this, new Vector([ Math.random() * (this.canvas.width - config.unitSize) + config.unitSize, Math.random() * (this.canvas.height - config.unitSize) + config.unitSize ]))
    ];
}

GameGrid.prototype.Draw = function() {
    this.DrawBackground();
    if (this.player) { this.player.Draw() };
    for (var i = 0; i < this.enemies.length; i++) {
        this.enemies[i].Draw();
    }
}

GameGrid.prototype.DrawBackground = function() {
    this.context.fillStyle = config.gridColor;
    this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
}

GameGrid.prototype.Update = function() {
    if (! this.player) { return; }

    // Check for hits/deaths by player
    if (this.player.disc.status == 'deadly') {
        for (var i = 0; i < this.enemies.length; i++) {
            if (this.player.disc.Collided(this.enemies[i])) {
                this.enemies[i].Hit();
                console.log(this.enemies[i].name + ' hit. ' + (this.enemies[i].maxHits - this.enemies[i].hits) + ' left');

                // Check to see if they died
                if (this.enemies[i].hits == this.enemies[i].maxHits) {
                    console.log(this.enemies[i].name + ' derezzed');
                    if (this.enemies[i].regenerateTimer) {
                        window.clearTimeout(this.enemies[i].regenerateTimer);
                    }
                    this.enemies.splice(i, 1);
                }

                // Return disc to player
                this.player.disc.Return();
            }
        }
    }
    // Check for player hits/death
    for (var i = 0; i < this.enemies.length; i++) {
        if (this.enemies[i].disc && this.enemies[i].disc.status == 'deadly' && this.enemies[i].disc.Collided(this.player)) {
            this.player.Hit();
            console.log(this.player.name + ' hit. ' + (this.player.maxHits - this.player.hits) + ' left');

            if (this.player.hits == this.player.maxHits) {
                console.log(this.player.name + ' derezzed');
                console.log('Game Over');
                this.player = null;
                break;
            }

            // Return disc to enemy
            this.enemies[i].disc.Return();
        }
    }

    // Movement
    if (this.player) {
        this.player.Update();

        for (var i = 0; i < this.enemies.length; i++) {
            this.enemies[i].Update();
        }
    }
}
{'fraction_non_alphanumeric': 0.15887703889585947, 'fraction_numerical': 0.003136762860727729, 'mean_word_length': 2.025142314990512, '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': '1014161', 'n_tokens_mistral': 2099, 'n_tokens_neox': 1973, 'n_words': 373}