<commit_before>package eu.theunitry.fabula.levels;


import eu.theunitry.fabula.UNGameEngine.graphics.UNGameScreen;
import eu.theunitry.fabula.UNGameEngine.graphics.UNColor;
import eu.theunitry.fabula.UNGameEngine.graphics.UNLevel;
import eu.theunitry.fabula.UNGameEngine.graphics.UNGraphicsObject;
import eu.theunitry.fabula.UNGameEngine.launcher.UNLauncher;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Objects;
import java.util.Random;

/**
 * Level 1
 * <NAME>
 */
public class Level1 extends UNLevel
{
    private Timer timer;
    private JButton button;
    private boolean winning;
    private int need, touch;
    private String lastHelp;
    public UNGraphicsObject blobby;
    public ArrayList<UNGraphicsObject> bombs;
    private ArrayList<Integer> answers;
    private ArrayList<JLabel> answerLabels;

    /**
     * Level 1
     * @param gameScreen
     * @param hudEnabled
     */
    public Level1(UNGameScreen gameScreen, boolean hudEnabled)
    {
        super(gameScreen, hudEnabled);

        gameScreen.stopAudio();

        this.need = 3 + new Random().nextInt(3);

        Random rn = new Random();
        int max = 5;
        int min = 2;
        int num1 = rn.nextInt(max - min + 1) + min;
        int num2 = rn.nextInt(max - min + 1) + min;
        int num3 = rn.nextInt(max - min + 1) + min;

        String question = "(" + String.valueOf(num1) + " + " + String.valueOf(num2) + ") x " + String.valueOf(num3);

        int correctAnswer = (num1 + num2) * num3;

        // Load questions & help texts
        this.setQuestion("De geheime formule is " + question + ". Klik op de juiste bom! Snel!");
        this.addHelp("Jammer! Je moet " + need + " appels in de mand stoppen");
        this.addHelp("Helaas! Er moeten " + need + " appels in de mand zitten");
        this.setHelp("Blobby probeert de wereld te vernietigen. We moeten haar neerhalen!");

        //  Set resources/audio
        this.setBackgroundImage(gameScreen.unResourceLoader.backgrounds.get("the-end"));
        this.blobby = new UNGraphicsObject(gameScreen.getWindow().getFrame(), 320, -50, gameScreen.getSprites().get("2:1:1:1"), false, 38 * 3, 70 * 3);

        this.addObject(blobby);

        gameScreen.getMusic().get("the-end").play(true);
        gameScreen.getMusic().get("the-end").setVolume(0.1);

        // Set variables
        this.winning = false;
        this.lastHelp = getHelp();
        bombs = new ArrayList<>();
        answerLabels = new ArrayList<>();

        answerLabels.add(new JLabel(String.valueOf(correctAnswer - 2)));
        answerLabels.add(new JLabel(String.valueOf(correctAnswer)));
        answerLabels.add(new JLabel(String.valueOf(correctAnswer + 3)));

        for (JLabel label : answerLabels)
        {
            label.setForeground(UNColor.WHITE_COLOR);
            label.setFont(new Font("Minecraftia", Font.PLAIN, 20));
        }

        bombs.add(new UNGraphicsObject(gameScreen.getWindow().getFrame(), 240, 350, gameScreen.getSprites().get("2:1:2"), false, 64, 64));
        answerLabels.get(0).setBounds(bombs.get(0).getX() + 17, bombs.get(0).getY(), 64, 64);
        this.add(answerLabels.get(0));
        bombs.add(new UNGraphicsObject(gameScreen.getWindow().getFrame(), 340, 350, gameScreen.getSprites().get("2:1:2"), false, 64, 64));
        answerLabels.get(1).setBounds(bombs.get(1).getX() + 17, bombs.get(1).getY(), 64, 64);
        this.add(answerLabels.get(1));
        bombs.add(new UNGraphicsObject(gameScreen.getWindow().getFrame(), 440, 350, gameScreen.getSprites().get("2:1:2"), false, 64, 64));
        answerLabels.get(2).setBounds(bombs.get(2).getX() + 17, bombs.get(2).getY(), 64, 64);
        this.add(answerLabels.get(2));



        for (UNGraphicsObject bomb : bombs)
        {
            this.addObject(bomb);
        }

        this.button = new JButton("Vuren!");

        // Standard styling
        this.setLayout(null);

        // Set button styling
        this.button.setBounds(618, 64, 150, 50);
        this.button.setBackground(new Color(51, 51, 51));
        this.button.setFont(new Font("Minecraftia", Font.PLAIN, 15));
        this.button.setForeground(Color.white);
        this.button.setOpaque(true);

        // Makes it look good on Mac
        this.button.setFocusPainted(false);
        this.button.setBorderPainted(false);

        // Speaks for itself
        button.addActionListener(e -> {
            if (button.getText().equals("Doorgaan"))
            {
                levelDone(5);
            }
            if (isHelperDoneTalking()) {
                if (winning) {
                    getHelper().setState(3);
                    setHelp("Goed gedaan, dat wordt smikkelen en smullen!");

                    button.setText("Door");
                } else {
                    addMistake();
                    if (getMistakes() < 3) {
                        getHelper().setState(4);
                        while(lastHelp.equals(getHelp())) {
                            setHelp(getHelpList().get(new Random().nextInt(getHelpList().size())));
                        }
                        lastHelp = getHelp();
                    } else {
                        getHelper().setState(4);
                        if (touch < need) {
                            setHelp("Jammer, er moest" + ((need - touch == 1) ? "" : "en") + " nog " + (need - touch) +
                                    " appel" + ((need - touch == 1) ? "" : "s")  + " bij. Want " + touch + " plus " +
                                    (need - touch)  + " is " + need
                            );
                        } else {
                            setHelp("Jammer, er moest" + ((touch - need == 1) ? "" : "en") + " " + (touch - need) +
                                    " appel" + ((touch - need == 1) ? "" : "s")  + " af. Want " + touch + " min " +
                                    (touch - need)  + " is " + need
                            );
                        }

                        button.setText("Door");
                    }
                }
            }
        });

        this.getPanel().add(button);

        timer = new Timer(100, new ActionListener() {
            int i = blobby.getY();
            int frame = 0;
            @Override
            public void actionPerformed(ActionEvent e) {
                if(frame < 3)
                {
                    frame++;
                } else {
                    frame = 0;
                }
                blobby.setImage(gameScreen.getSprites().get("2:1:1:" + String.valueOf(frame)));

                if(i <= 90) blobby.setY(i = i + 10);
                if(i >= 90) {
                    shakeBlobby();
                }
                touch = 0;
                winning = (touch == need);
                if(bombs.get(1).isMouseClick())
                {
                    bombs.get(1).setMouseClick(false);<commit_msg>Remove button<commit_after>package eu.theunitry.fabula.levels;


import eu.theunitry.fabula.UNGameEngine.graphics.UNGameScreen;
import eu.theunitry.fabula.UNGameEngine.graphics.UNColor;
import eu.theunitry.fabula.UNGameEngine.graphics.UNLevel;
import eu.theunitry.fabula.UNGameEngine.graphics.UNGraphicsObject;
import eu.theunitry.fabula.UNGameEngine.launcher.UNLauncher;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Objects;
import java.util.Random;

/**
 * Level 1
 * <NAME>
 */
public class Level1 extends UNLevel
{
    private Timer timer;
    private JButton button;
    private boolean winning;
    private int need, touch;
    private String lastHelp;
    public UNGraphicsObject blobby;
    public ArrayList<UNGraphicsObject> bombs;
    private ArrayList<Integer> answers;
    private ArrayList<JLabel> answerLabels;

    /**
     * Level 1
     * @param gameScreen
     * @param hudEnabled
     */
    public Level1(UNGameScreen gameScreen, boolean hudEnabled)
    {
        super(gameScreen, hudEnabled);

        gameScreen.stopAudio();

        this.need = 3 + new Random().nextInt(3);

        Random rn = new Random();
        int max = 5;
        int min = 2;
        int num1 = rn.nextInt(max - min + 1) + min;
        int num2 = rn.nextInt(max - min + 1) + min;
        int num3 = rn.nextInt(max - min + 1) + min;

        String question = "(" + String.valueOf(num1) + " + " + String.valueOf(num2) + ") x " + String.valueOf(num3);

        int correctAnswer = (num1 + num2) * num3;

        // Load questions & help texts
        this.setQuestion("De geheime formule is " + question + ". Klik op de juiste bom! Snel!");
        this.addHelp("Jammer! Je moet " + need + " appels in de mand stoppen");
        this.addHelp("Helaas! Er moeten " + need + " appels in de mand zitten");
        this.setHelp("Blobby probeert de wereld te vernietigen. We moeten haar neerhalen!");

        //  Set resources/audio
        this.setBackgroundImage(gameScreen.unResourceLoader.backgrounds.get("the-end"));
        this.blobby = new UNGraphicsObject(gameScreen.getWindow().getFrame(), 320, -50, gameScreen.getSprites().get("2:1:1:1"), false, 38 * 3, 70 * 3);

        this.addObject(blobby);

        gameScreen.getMusic().get("the-end").play(true);
        gameScreen.getMusic().get("the-end").setVolume(0.1);

        // Set variables
        this.winning = false;
        this.lastHelp = getHelp();
        bombs = new ArrayList<>();
        answerLabels = new ArrayList<>();

        answerLabels.add(new JLabel(String.valueOf(correctAnswer - 2)));
        answerLabels.add(new JLabel(String.valueOf(correctAnswer)));
        answerLabels.add(new JLabel(String.valueOf(correctAnswer + 3)));

        for (JLabel label : answerLabels)
        {
            label.setForeground(UNColor.WHITE_COLOR);
            label.setFont(new Font("Minecraftia", Font.PLAIN, 20));
        }

        bombs.add(new UNGraphicsObject(gameScreen.getWindow().getFrame(), 240, 350, gameScreen.getSprites().get("2:1:2"), false, 64, 64));
        answerLabels.get(0).setBounds(bombs.get(0).getX() + 17, bombs.get(0).getY(), 64, 64);
        this.add(answerLabels.get(0));
        bombs.add(new UNGraphicsObject(gameScreen.getWindow().getFrame(), 340, 350, gameScreen.getSprites().get("2:1:2"), false, 64, 64));
        answerLabels.get(1).setBounds(bombs.get(1).getX() + 17, bombs.get(1).getY(), 64, 64);
        this.add(answerLabels.get(1));
        bombs.add(new UNGraphicsObject(gameScreen.getWindow().getFrame(), 440, 350, gameScreen.getSprites().get("2:1:2"), false, 64, 64));
        answerLabels.get(2).setBounds(bombs.get(2).getX() + 17, bombs.get(2).getY(), 64, 64);
        this.add(answerLabels.get(2));



        for (UNGraphicsObject bomb : bombs)
        {
            this.addObject(bomb);
        }

        this.button = new JButton("Vuren!");

        // Standard styling
        this.setLayout(null);

        // Set button styling
        this.button.setBounds(618, 64, 150, 50);
        this.button.setBackground(new Color(51, 51, 51));
        this.button.setFont(new Font("Minecraftia", Font.PLAIN, 15));
        this.button.setForeground(Color.white);
        this.button.setOpaque(true);

        // Makes it look good on Mac
        this.button.setFocusPainted(false);
        this.button.setBorderPainted(false);

        // Speaks for itself
        button.addActionListener(e -> {
            if (button.getText().equals("Doorgaan"))
            {
                levelDone(5);
            }
            if (isHelperDoneTalking()) {
                if (winning) {
                    getHelper().setState(3);
                    setHelp("Goed gedaan, dat wordt smikkelen en smullen!");

                    button.setText("Door");
                } else {
                    addMistake();
                    if (getMistakes() < 3) {
                        getHelper().setState(4);
                        while(lastHelp.equals(getHelp())) {
                            setHelp(getHelpList().get(new Random().nextInt(getHelpList().size())));
                        }
                        lastHelp = getHelp();
                    } else {
                        getHelper().setState(4);
                        if (touch < need) {
                            setHelp("Jammer, er moest" + ((need - touch == 1) ? "" : "en") + " nog " + (need - touch) +
                                    " appel" + ((need - touch == 1) ? "" : "s")  + " bij. Want " + touch + " plus " +
                                    (need - touch)  + " is " + need
                            );
                        } else {
                            setHelp("Jammer, er moest" + ((touch - need == 1) ? "" : "en") + " " + (touch - need) +
                                    " appel" + ((touch - need == 1) ? "" : "s")  + " af. Want " + touch + " min " +
                                    (touch - need)  + " is " + need
                            );
                        }

                        button.setText("Door");
                    }
                }
            }
        });

        timer = new Timer(100, new ActionListener() {
            int i = blobby.getY();
            int frame = 0;
            @Override
            public void actionPerformed(ActionEvent e) {
                if(frame < 3)
                {
                    frame++;
                } else {
                    frame = 0;
                }
                blobby.setImage(gameScreen.getSprites().get("2:1:1:" + String.valueOf(frame)));

                if(i <= 90) blobby.setY(i = i + 10);
                if(i >= 90) {
                    shakeBlobby();
                }
                touch = 0;
                winning = (touch == need);
                if(bombs.get(1).isMouseClick())
                {
                    bombs.get(1).setMouseClick(false);
{'fraction_non_alphanumeric': 0.13801228045123518, 'fraction_numerical': 0.02213337141225189, 'mean_word_length': 1.770371835443038, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3219392', 'n_tokens_mistral': 4384, 'n_tokens_neox': 4028, 'n_words': 817}