class GameOverReason
{
    static WATER = 0;
    static FOOD = 1;
    static CRIME = 2;
}

class GameOverUI
{
    constructor( sparrowUI )
    {
        this.ui = sparrowUI;
        
        this.lbl_bg = this.ui.add( new Sparrow.UI.Label( "" , { position: "center" , verticalPosition: "center" , width: 400 , height: 240 , background: "background" , backgroundColor: "#ccaa88" , borderWidth: 1 , borderColor: "#554433" } ) );
        this.lbl_bg.addChild( new Sparrow.UI.Label( "Game Over" , { position: "center" , y: 20 , width: 380 , height: 40 , textAlign: "center" , textSize: 40 } ) );
        this.lbl_reason = this.lbl_bg.addChild( new Sparrow.UI.Label( "Game Over" , { position: "center" , y: 80 , width: 380 , textAlign: "center" , textSize: 30 } ) );
        this.lbl_time = this.lbl_bg.addChild( new Sparrow.UI.Label( "" , { position: "center" , y: 120 , width: 380 , textAlign: "center" , textSize: 30 } ) );
        this.btn_playAgain = this.lbl_bg.addChild( new Sparrow.UI.Button( "Play Again" , { position: "center" , verticalPosition: "bottom" , y: 10 , width: 200 , height: 50 , backgroundColor: "#554433" , textColor: "#ffffff" , hover: { backgroundColor: "#776655" } } ) );
        this.btn_playAgain.onclick = () => {
            game.restart();
            ui.updateGameUI();
            ui.intro.show();
            this.lbl_bg.b_visible = false;
        };
        this.lbl_bg.b_visible = false;
    }

    show( reason )
    {
        if ( reason === GameOverReason.WATER )
        {
            this.lbl_reason.setStr( "We ran out of water." );
            sound_gameover_water.play();
        }
        else if ( reason === GameOverReason.FOOD )
        {
            this.lbl_reason.setStr( "We ran out of food." );
            sound_gameover_food.play();
        }
        else if ( reason === GameOverReason.CRIME )
        {
            this.lbl_reason.setStr( "Too much crime." );
            sound_gameover_crime.play();
        }
        var time = parseInt( game.gameTime );
        this.lbl_time.setStr( "You lasted "+time+" seconds." );
        this.lbl_bg.b_visible = true;
    }
}