/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gamegraphics;


import gamegraphics.misc.Option;
import gamegraphics.misc.WinnerStatistic;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.text.html.HTMLEditorKit;

/**
 *
 * @author Ani
 */
public class EndOfGamePanel extends JPanel{
    private JTextPane winnerText;
    private JButton ok;
    private boolean okclicked;
    private WinnerStatistic ws;


    public EndOfGamePanel() {
        okclicked = false;
        init();
    }

    private void init(){
        initSettings();
        initWinnerText();
        initSettings();
        initOkButton();
    }

    private void initSettings(){
        setSize(800, 500);
        setBackground(new Color(30, 180, 30));
        setLayout(null);
    }

    private void initWinnerText(){
        createTextPane();
        add(winnerText);
    }

    private void createTextPane(){
        winnerText = new JTextPane();
        winnerText.setBounds(100, 100, 600, 200);
        winnerText.setBackground(getBackground());
        winnerText.setEditorKit(new HTMLEditorKit());
        winnerText.setEditable(false);
    }  

    private void initOkButton(){
        ok = new JButton("Ok");
        ok.setBounds(350, 350, 100, 40);
        ok.addActionListener(new OkButtonClicked());
        add(ok);
    }

    public boolean isOkclicked() {
        return okclicked;
    }

    public void setOkclicked(boolean okclicked) {
        this.okclicked = okclicked;

    }

    public WinnerStatistic getWs() {
        return ws;
    }

    public void setWs(WinnerStatistic ws) {
        this.ws = ws;
        setTextPaneText();
    }


    private void setTextPaneText(){
        String text="<body align=\"center\">";
        text += "<h1>";
        if (ws.isDrawn()){
            text+="Döntetlen</h1>";
        }
        else if (ws.isWinner()==Option.COMPUTER){
            text+="A számítógép nyert!</h1>";
        }
        else if (ws.isWinner()==Option.HUMAN){
            text+="Gratulálok!<br>Te nyertél!</h1>";
        }

        text+="<table><tr><td  width=\"200\"><h2 align=\"center\">Játékos</h2></td>" +
                "<td width=\"200\"><h2 align=\"center\">Számítógép</h2></td></tr><tr>";

        if (ws.isWinner()==Option.COMPUTER){
            text += "<td><h2 align=\"center\">" + ws.getPointsOfLooser() + "</h2></td>" +
                    "<td><h2 align=\"center\">" + ws.getPointsOfWinner() + "</h2></td>";
        }
        else{
            text += "<td><h2 align=\"center\">" + ws.getPointsOfWinner() + "</h2></td>" +
                    "<td><h2 align=\"center\">" + ws.getPointsOfLooser() + "</h2></td>";
        }

        text+="</tr></table></body>";

        winnerText.setText(text);
        repaint();
    }

    class OkButtonClicked implements ActionListener{

        public void actionPerformed(ActionEvent e) {
            okclicked = true;
        }

    }


}
