package com.example.jmastermind.Game;

import android.media.MediaPlayer;
import android.widget.Button;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import com.example.jmastermind.Events.PopupEvent;
import com.example.jmastermind.R;

public class Popup extends AlertDialog.Builder {
    private MediaPlayer mp;
    private AppCompatActivity context;

    /**
     * Affiche la popup de fin de jeu
     * @param context Le context
     * @param options La liste des options (rejouer, ...)
     * @param tentative Le nombre de tentatives
     * */
    public Popup(AppCompatActivity context, String[] options, int... tentative) {
        super(context);
        this.context = context;

        if(tentative[0] > 0) {
            this.mp = MediaPlayer.create(this.context, R.raw.winningsong);
            this.mp.setLooping(true);
            this.mp.start();

            this.setTitle("Félicitation ! Vous avez gagner en : " + tentative[0] + " coup(s).");
        }  else {
            this.mp = MediaPlayer.create(this.context, R.raw.loosegamesong);
            this.mp.setLooping(true);
            this.mp.start();

            this.setTitle("Perdu !");
        }

        this.setItems(options, new PopupEvent(this.context, tentative[0], this.mp));
    }
}
