<commit_before>package de.tu_darmstadt.gdi1.gorillas.ui.states;

import de.matthiasmann.twl.Alignment;
import de.matthiasmann.twl.Button;
import de.matthiasmann.twl.slick.BasicTWLGameState;
import de.matthiasmann.twl.slick.RootPane;
import de.tu_darmstadt.gdi1.gorillas.assets.Assets;
import de.tu_darmstadt.gdi1.gorillas.entities.*;
import de.tu_darmstadt.gdi1.gorillas.main.Gorillas;
import de.tu_darmstadt.gdi1.gorillas.main.Game;
import de.tu_darmstadt.gdi1.gorillas.main.Player;
import de.tu_darmstadt.gdi1.gorillas.ui.widgets.valueadjuster.AdvancedValueAdjusterInt;
import de.tu_darmstadt.gdi1.gorillas.utils.SqlGorillas;
import eea.engine.entity.Entity;
import eea.engine.entity.StateBasedEntityManager;
import org.newdawn.slick.*;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.geom.Circle;
import org.newdawn.slick.geom.Vector2f;
import org.newdawn.slick.state.StateBasedGame;
import sun.util.resources.cldr.mk.TimeZoneNames_mk;

import java.util.ArrayList;
import java.util.List;

import static org.lwjgl.opengl.GL11.*;

public class GamePlayState extends BasicTWLGameState {

    // Key Handling
    private float keyPressDelay = 0;
    private final float keyPressWaitTime = 0.1f; // wait 100 ms TODO: experiment with these

    // DEBUG
    private String throwNumber = null;
    private String roundWinMessage = null;
    List<Circle> debugCollisions = new ArrayList<>(32);

    // UI
    private RootPane rp;
    private AdvancedValueAdjusterInt if_speed; // We are using the advanced with the edit callback for tests
    private AdvancedValueAdjusterInt if_angle; // We are using the advanced with the edit callback for tests
    private Button btnThrow;

    // GameState
    private STATES  state;
    private int     windSpeed;
    private Image   background;
    private Image   arrow;
    private Sound   explosionSound;
    private float   gravity = 9.80665f;
    private String comment = "";
    private String score = "Score: 0:0";
    private float slowmoScale;

    // Entities
    private StateBasedEntityManager entityManager;
    private Banana  banana;
    private Skyline skyline;
    private Gorilla gorilla;
    private Gorilla gorillb;
    private Sun     sun;
    private Cloud   cloud;

    // Counter
    private static int totalRoundCounter = 0;
    private Image buffer;

    public Player getActivePlayer() { return Game.getInstance().getActivePlayer(); }
    public void setActivePlayer(Player activePlayer) {
        Game.getInstance().setActivePlayer(activePlayer);
    }

    /** Die FSM für das spiel ist eigentlich recht simple:
     *      Im INPUT state werden die Eingaben des aktiven Spieles verarbeitet. Wenn einen
     *  Banane geworfen wird, wechseln wir nach THROW. Hier wird die Banane nach den Physikalichen
     *  vorgaben bewegt und am auf Kollisionen geprüft. Beim Auftreten der Kollision wird nach
     *  DMAMGE gewechselt, der schaden berechnet, auf Sieg geprüft und  zu INPUT oder VICTORY
     *  gewechselt.
     */
    private static enum STATES{ INPUT, THROW, DAMAGE, ROUNDVICTORY, VICTORY }

    @Override
    public int getID() {
        return de.tu_darmstadt.gdi1.gorillas.main.Game.GAMEPLAYSTATE;
    }

    public Skyline getSkyline(){
        return skyline;
    }

    public Gorilla getGorilla(int num){
        return num == 0 ? gorilla : gorillb;
    }

    public Sun getSun(){
        return sun;
    }

    public GamePlayState() { entityManager = StateBasedEntityManager.getInstance(); }

    @Override
    public void init(GameContainer gc, StateBasedGame game) throws SlickException {
        // Load All Static Content or Ressources (Background Images, Sounds etc)
        // Lazy Load the UI, this is better for the TestGameContainer
        if (!Game.getInstance().isTestMode()) { // Don't load anything in TestMode
            background = Assets.loadImage(Assets.Images.GAMEPLAY_BACKGROUND);
            arrow = Assets.loadImage(Assets.Images.ARROW);
            explosionSound = Assets.loadSound(Assets.Sounds.EXPLOSION);
            buffer = new Image(1024, 1024);
        }
    }

    @Override
    public void enter(GameContainer container, StateBasedGame game) throws SlickException {
        super.enter(container, game);
        if(game.getLastStateID() != Game.INGAMEPAUSE && game.getLastStateID() != Game.HELPSTATE && game.getLastStateID() != Game.OPTIONSTATE)
            startGame();
    }

    public void startGame() {
        entityManager.clearEntitiesFromState(getID());
        debugCollisions.clear();
        skyline = new Skyline(6);

        int x1 = (int)(Math.random() * 3 + 0);
        int x2 = (int)(Math.random() * 3 + 3);

        int xx = x1 * (skyline.BUILD_WIDTH) + (skyline.BUILD_WIDTH / 2);
        int yy = x2 * (skyline.BUILD_WIDTH) + (skyline.BUILD_WIDTH / 2);
<commit_msg>One comment<commit_after>package de.tu_darmstadt.gdi1.gorillas.ui.states;

import de.matthiasmann.twl.Alignment;
import de.matthiasmann.twl.Button;
import de.matthiasmann.twl.slick.BasicTWLGameState;
import de.matthiasmann.twl.slick.RootPane;
import de.tu_darmstadt.gdi1.gorillas.assets.Assets;
import de.tu_darmstadt.gdi1.gorillas.entities.*;
import de.tu_darmstadt.gdi1.gorillas.main.Gorillas;
import de.tu_darmstadt.gdi1.gorillas.main.Game;
import de.tu_darmstadt.gdi1.gorillas.main.Player;
import de.tu_darmstadt.gdi1.gorillas.ui.widgets.valueadjuster.AdvancedValueAdjusterInt;
import de.tu_darmstadt.gdi1.gorillas.utils.SqlGorillas;
import eea.engine.entity.Entity;
import eea.engine.entity.StateBasedEntityManager;
import org.newdawn.slick.*;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.geom.Circle;
import org.newdawn.slick.geom.Vector2f;
import org.newdawn.slick.state.StateBasedGame;
import sun.util.resources.cldr.mk.TimeZoneNames_mk;

import java.util.ArrayList;
import java.util.List;

import static org.lwjgl.opengl.GL11.*;

public class GamePlayState extends BasicTWLGameState {

    // Key Handling
    private float keyPressDelay = 0;
    private final float keyPressWaitTime = 0.1f; // wait 100 ms TODO: experiment with these

    // DEBUG
    private String throwNumber = null;
    private String roundWinMessage = null;
    List<Circle> debugCollisions = new ArrayList<>(32);

    // UI
    private RootPane rp;
    private AdvancedValueAdjusterInt if_speed; // We are using the advanced with the edit callback for tests
    private AdvancedValueAdjusterInt if_angle; // We are using the advanced with the edit callback for tests
    private Button btnThrow;

    // GameState
    private STATES  state;
    private int     windSpeed;
    private Image   background;
    private Image   arrow;
    private Sound   explosionSound;
    private float   gravity = 9.80665f;
    private String comment = "";
    private String score = "Score: 0:0";
    private float slowmoScale;

    // Entities
    private StateBasedEntityManager entityManager;
    private Banana  banana;
    private Skyline skyline;
    private Gorilla gorilla;
    private Gorilla gorillb;
    private Sun     sun;
    private Cloud   cloud;

    // Counter
    private static int totalRoundCounter = 0;
    private Image buffer;

    public Player getActivePlayer() { return Game.getInstance().getActivePlayer(); }
    public void setActivePlayer(Player activePlayer) {
        Game.getInstance().setActivePlayer(activePlayer);
    }

    /** Die FSM für das spiel ist eigentlich recht simple:
     *      Im INPUT state werden die Eingaben des aktiven Spieles verarbeitet. Wenn einen
     *  Banane geworfen wird, wechseln wir nach THROW. Hier wird die Banane nach den Physikalichen
     *  vorgaben bewegt und am auf Kollisionen geprüft. Beim Auftreten der Kollision wird nach
     *  DMAMGE gewechselt, der schaden berechnet, auf Sieg geprüft und  zu INPUT oder VICTORY
     *  gewechselt.
     */
    private static enum STATES{ INPUT, THROW, DAMAGE, ROUNDVICTORY, VICTORY }

    @Override
    public int getID() {
        return de.tu_darmstadt.gdi1.gorillas.main.Game.GAMEPLAYSTATE;
    }

    public Skyline getSkyline(){
        return skyline;
    }

    public Gorilla getGorilla(int num){
        return num == 0 ? gorilla : gorillb;
    }

    public Sun getSun(){
        return sun;
    }

    public GamePlayState() { entityManager = StateBasedEntityManager.getInstance(); }

    @Override
    public void init(GameContainer gc, StateBasedGame game) throws SlickException {
        // Load All Static Content or Ressources (Background Images, Sounds etc)
        // Lazy Load the UI, this is better for the TestGameContainer
        if (!Game.getInstance().isTestMode()) { // Don't load anything in TestMode
            background = Assets.loadImage(Assets.Images.GAMEPLAY_BACKGROUND);
            arrow = Assets.loadImage(Assets.Images.ARROW);
            explosionSound = Assets.loadSound(Assets.Sounds.EXPLOSION);
            buffer = new Image(1024, 1024);
        }
    }

    @Override
    public void enter(GameContainer container, StateBasedGame game) throws SlickException {
        super.enter(container, game);
        // Do not restart game after Support-States
        if(game.getLastStateID() != Game.INGAMEPAUSE && game.getLastStateID() != Game.HELPSTATE && game.getLastStateID() != Game.OPTIONSTATE)
            startGame();
    }

    public void startGame() {
        entityManager.clearEntitiesFromState(getID());
        debugCollisions.clear();
        skyline = new Skyline(6);

        int x1 = (int)(Math.random() * 3 + 0);
        int x2 = (int)(Math.random() * 3 + 3);

        int xx = x1 * (skyline.BUILD_WIDTH) + (skyline.BUILD_WIDTH / 2);
        int yy = x2 * (skyline.BUILD_WIDTH) + (skyline.BUILD_WIDTH / 2);

{'fraction_non_alphanumeric': 0.08989795918367346, 'fraction_numerical': 0.01, 'mean_word_length': 3.2576020851433536, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1371451', 'n_tokens_mistral': 3131, 'n_tokens_neox': 3032, 'n_words': 783}