<commit_before>/*
 * GameWindow.java
 *
 * Created on 10.03.2011, 21:06:52
 */
package info.hska.erstiduell.view;

import info.hska.erstiduell.Game;
import info.hska.erstiduell.Team;
import info.hska.erstiduell.questions.Answer;
import info.hska.erstiduell.questions.Question;
import java.awt.Color;
import java.util.Observable;
import java.util.Observer;
import javax.swing.JLabel;

/**
 *
 * @author timroes
 */
public class GameWindow extends javax.swing.JFrame implements Observer {

    private Game game;
    private JLabel[] points;
    private JLabel[] teams;
    private String myAsterisk;

    /**
     * Creates new GameWindow
     *
     * @param game
     */
    public GameWindow(Game game) {
        this.game = game;
        initComponents();
        //this.setSize(1366, 768);
        //this.setSize(1024, 768);
        this.game.getDevice().setFullScreenWindow(this);
        this.points = new JLabel[]{points1, points2, points3, points4};
        this.teams = new JLabel[]{teamName1, teamName2, teamName3, teamName4};
    }

    public void update(Observable Game, Object o) {
        this.game = (Game) o;
        redraw();
    }

    public Game getGame() {
        return game;
    }

    public void setBGColor(Color color) {
        getContentPane().setBackground(color);
        points1.setForeground(color);
        points2.setForeground(color);
        if (points3 != null) {
            points3.setForeground(color);
            teamName3.setForeground(color);
        }
        if (points4 != null) {
            points4.setForeground(color);
            teamName4.setForeground(color);
        }
        content.setBackground(color);
        timer.setForeground(color);
    }

    public void setFGColor(Color color) {
        setForeground(color);
        winnerLabel.setForeground(color);
        content.setForeground(color);
        jPanel1.setBackground(color);
        timerPanel.setBackground(color);
    }

    public void showBuzzer(int team) {
        if (team > 0) {
            timer.setText("<html><center>" + game.getTeams().get(team - 1).getName()
                    + "</center></html>");
        }
        timerPanel.setVisible(true);
    }

    public void showTimer(String text) {
        timer.setText("<html><center>"
                + text
                + "</center></html>");
        timerPanel.setVisible(true);
    }

    public void redraw() {
        timerPanel.setVisible(false);
        timer.setText("");
        refreshPoints();
        drawPlayerNames();

        if (game.isFinished()) {
            drawWinner();
        } else {
            drawContent();
        }

    }

    private void drawPlayerNames() {
        int numAnswers = (game.getCurrentQuestion() == null)
                ? 10 : game.getCurrentQuestion().getAnswers().size();
        for (int i = 0; i < game.getNumberOfPlayers(); i++) {
            if (game.getTeams().get(i).getPenalty() >= numAnswers) {
                myAsterisk = "<p>";
                for (int j = 0; j < game.getTeams().get(i).getName().length(); j++) {
                    myAsterisk = myAsterisk + "*";
                }
                myAsterisk = myAsterisk + "</p>";
                teams[i].setText("<html><font color='red'>"
                        + myAsterisk
                        + game.getTeams().get(i).getName()
                        + myAsterisk
                        + "</font></html>");
            } else {
                teams[i].setText(game.getTeams().get(i).getName());
            }
        }
    }

    private void refreshPoints() {
        for (int i = 0; i < 4; i++) {
            if (points[i] != null) {
                points[i].setText(String.valueOf(game.getTeams().get(i).getPoints()));
            }
        }
    }

    private void drawContent() {
        StringBuilder c = new StringBuilder("<html>");
        Question cur;
        if ((cur = game.getCurrentQuestion()) != null) {<commit_msg>now showing number of tries left<commit_after>/*
 * GameWindow.java
 *
 * Created on 10.03.2011, 21:06:52
 */
package info.hska.erstiduell.view;

import info.hska.erstiduell.Game;
import info.hska.erstiduell.Team;
import info.hska.erstiduell.questions.Answer;
import info.hska.erstiduell.questions.Question;
import java.awt.Color;
import java.util.Observable;
import java.util.Observer;
import javax.swing.JLabel;

/**
 *
 * @author timroes
 */
public class GameWindow extends javax.swing.JFrame implements Observer {

    private Game game;
    private JLabel[] points;
    private JLabel[] teams;
    private String myAsterisk;

    /**
     * Creates new GameWindow
     *
     * @param game
     */
    public GameWindow(Game game) {
        this.game = game;
        initComponents();
        //this.setSize(1366, 768);
        //this.setSize(1024, 768);
        this.game.getDevice().setFullScreenWindow(this);
        this.points = new JLabel[]{points1, points2, points3, points4};
        this.teams = new JLabel[]{teamName1, teamName2, teamName3, teamName4};
    }

    public void update(Observable Game, Object o) {
        this.game = (Game) o;
        redraw();
    }

    public Game getGame() {
        return game;
    }

    public void setBGColor(Color color) {
        getContentPane().setBackground(color);
        points1.setForeground(color);
        points2.setForeground(color);
        if (points3 != null) {
            points3.setForeground(color);
            teamName3.setForeground(color);
        }
        if (points4 != null) {
            points4.setForeground(color);
            teamName4.setForeground(color);
        }
        content.setBackground(color);
        timer.setForeground(color);
    }

    public void setFGColor(Color color) {
        setForeground(color);
        winnerLabel.setForeground(color);
        content.setForeground(color);
        jPanel1.setBackground(color);
        timerPanel.setBackground(color);
    }

    public void showBuzzer(int team) {
        if (team > 0) {
            timer.setText("<html><center>" + game.getTeams().get(team - 1).getName()
                    + "</center></html>");
        }
        timerPanel.setVisible(true);
    }

    public void showTimer(String text) {
        timer.setText("<html><center>"
                + text
                + "</center></html>");
        timerPanel.setVisible(true);
    }

    public void redraw() {
        timerPanel.setVisible(false);
        timer.setText("");
        refreshPoints();
        drawPlayerNames();

        if (game.isFinished()) {
            drawWinner();
        } else {
            drawContent();
        }
    }

    private void drawPlayerNames() {

        int numAnswers = (game.getCurrentQuestion() == null)
                ? 10 : game.getCurrentQuestion().getAnswers().size();
        String color;
        int triesLeft;
        for (int team = 0; team < game.getNumberOfPlayers(); team++) {
            if (game.getCurrentQuestion() != null) {
                myAsterisk = "<p>";
                triesLeft = game.getCurrentQuestion().getAnswers().size()
                        - game.getTeams().get(team).getPenalty();
                for (int j = 0; j < triesLeft; j++) {
                    myAsterisk = myAsterisk + "*";
                }
                myAsterisk += "</p>";
            } else {
                myAsterisk = "";
                triesLeft = -1;
            }
            switch (triesLeft) {
                case 0:
                    color = "red";
                    break;
                case 1:
                    color = "orange";
                    break;
                case 2:
                    color = "yellow";
                    break;
                default:
                    color = "black";
            }
            myAsterisk = myAsterisk + "</p>";
            teams[team].setText("<html><font color='" + color + "'>"
                    + myAsterisk
                    + game.getTeams().get(team).getName()
                    + myAsterisk
                    + "</font></html>");
        }
    }

    private void refreshPoints() {
        for (int i = 0; i < 4; i++) {
            if (points[i] != null) {
                points[i].setText(String.valueOf(game.getTeams().get(i).getPoints()));
            }
        }
    }

    private void drawContent() {
        StringBuilder c = new StringBuilder("<html>");
        Question cur;
        if ((cur = game.getCurrentQuestion()) != null) {
{'fraction_non_alphanumeric': 0.1321981790232943, 'fraction_numerical': 0.013006976469197115, 'mean_word_length': 1.7694826457105435, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 37, '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': '1451307', 'n_tokens_mistral': 2532, 'n_tokens_neox': 2405, 'n_words': 469}