<commit_before>package master;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.*;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * GamePlay Class
 * Created by muhd7rosli on 8/5/2014.
 */
public class GamePlay extends Application {

    private void move(ImageView car, String direction, double orientation){
        double currentX = car.getX(), currentY = car.getY();
        double currentOrientation = car.getRotate();

        double newOrientation = Math.toRadians(currentOrientation + orientation);

        double newX, newY;
        if(direction.equals("FORWARD")) {
            newX = currentX - currentOrientation * Math.cos(newOrientation);
            newY = currentY - currentOrientation * Math.sin(newOrientation);
        }
        else {
            newX = currentX + currentOrientation * Math.cos(newOrientation);
            newY = currentY + currentOrientation * Math.sin(newOrientation);
        }

        car.setX(newX);
        car.setY(newY);
    }

    /**
     * This class
     * @param stage
     */
    public void start(Stage stage){
        // create whole container
        VBox container = new VBox();
        container.setSpacing(10.0);

        // create canvas
        double canvasWidth = 800, canvasHeight = 600;

        Pane canvas = new BorderPane();
        canvas.setPrefSize(canvasWidth, canvasHeight); // set the size

        // create textfield to display car position
        Label displayPositionLabel = new Label("Position");
        final TextField displayPosition = new TextField();
        displayPosition.setDisable(true);
        displayPosition.setPrefWidth(100);
        // create textfield to display car orientation
        Label displayOrientationLabel = new Label("Orientation");
        final TextField displayOrientation = new TextField();
        displayOrientation.setDisable(true);
        displayOrientation.setPrefWidth(100);
        // create textfield to display current speed
        Label displaySpeedLabel = new Label("Speed");
        final TextField displaySpeed = new TextField();
        displaySpeed.setDisable(true);
        displaySpeed.setPrefWidth(100);

        HBox infoBar = new HBox();
        infoBar.setSpacing(10);
        infoBar.getChildren().addAll(displayPositionLabel, displayPosition,
                displayOrientationLabel, displayOrientation, displaySpeedLabel, displaySpeed);

        // add all elements
        container.getChildren().addAll(infoBar, canvas);

        Scene scene = new Scene(container);

        Image carSourceImage = new Image("car_small.png");
        final ImageView car = new ImageView(carSourceImage);
        canvas.getChildren().add(car);
        car.setX(canvasWidth/2.0 - car.getFitWidth());
        car.setY(canvasHeight/2.0 - car.getFitHeight());
        car.setRotate(90.0);

        final DoubleProperty movementUnit = new SimpleDoubleProperty(10.0);
        final StringProperty coordinate = new SimpleStringProperty();

        // binding
        displayPosition.textProperty().bind(coordinate);
        displayOrientation.textProperty().bind(car.rotateProperty().asString());
        displaySpeed.textProperty().bind(movementUnit.asString());

        final MultiplePressedKeysEventHandler keyHandler =
                new MultiplePressedKeysEventHandler(new MultiplePressedKeysEventHandler.MultiKeyEventHandler() {
                    @Override
                    public void handle(MultiplePressedKeysEventHandler.MultiKeyEvent ke) {

                        // check if both LEFT and A keys are pressed
                        if (ke.isPressed(KeyCode.LEFT)  && ke.isPressed(KeyCode.A)) {
                            System.out.println("LEFT and A");
                        }
                        // check if only LEFT is pressed
                        else if(ke.isPressed(KeyCode.LEFT) && !ke.isPressed(KeyCode.A)){
                            System.out.println("LEFT");
                        }
                        // check if only A is pressed
                        else if(!ke.isPressed(KeyCode.LEFT) && ke.isPressed(KeyCode.A)){
                            System.out.println("A");
                        }

                        // check if both RIGHT and D keys are pressed
                        if (ke.isPressed(KeyCode.RIGHT) && ke.isPressed(KeyCode.D)) {
                            System.out.println("RIGHT and D");
                        }
                        // check if only RIGHT is pressed
                        else if(ke.isPressed(KeyCode.RIGHT) && !ke.isPressed(KeyCode.D)){
                            System.out.println("RIGHT");
                        }
                        // check if only D is pressed
                        else if(!ke.isPressed(KeyCode.RIGHT) && ke.isPressed(KeyCode.D)){
                            System.out.println("D");
                        }

                        // check if both UP and M keys are pressed
                        if (ke.isPressed(KeyCode.UP) && ke.isPressed(KeyCode.W)) {
                            System.out.println("UP and W");
                        }
                        // check if only UP is pressed
                        else if(ke.isPressed(KeyCode.UP) && !ke.isPressed(KeyCode.W)){
                            System.out.println("UP");
                            move(car, "FORWARD", 0.0);
                        }
                        // check if only W is pressed
                        else if(!ke.isPressed(KeyCode.UP) && ke.isPressed(KeyCode.W)){
                            System.out.println("W");
                        }

                        // check if both DOWN and S keys are pressed
                        if (ke.isPressed(KeyCode.DOWN) && ke.isPressed(KeyCode.S)) {
                            System.out.println("DOWN and S");
                        }
                        // check if only DOWN is pressed
                        else if(ke.isPressed(KeyCode.DOWN) && !ke.isPressed(KeyCode.S)){
                            System.out.println("DOWN");
                            move(car, "BACKWARD", 0.0);
                        }
                        // check if only S is pressed
                        else if(!ke.isPressed(KeyCode.DOWN) && ke.isPressed(KeyCode.S)){
                            System.out.println("S");
                        }
                    }
                });

        scene.setOnKeyPressed(keyHandler);
        scene.setOnKeyReleased(keyHandler);

        // give title to window
        stage.setTitle("Tracking");
        stage.setScene(scene);
        stage.show();
    }

    /**
     * Main application access
     * @param args
     */
    public static void main(String[] args){
        launch(args);<commit_msg>Change directional button.  Include instructional label.<commit_after>package master;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.*;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;

/**
 * GamePlay Class
 * Created by muhd7rosli on 8/5/2014.
 */
public class GamePlay extends Application {

    private void move(ImageView car, String direction){
        double currentX = car.getX(), currentY = car.getY();
        double currentOrientation = car.getRotate();

        double newOrientation = Math.toRadians(currentOrientation);

        double newX, newY;
        if(direction.equals("FORWARD")) {
            newX = currentX - 1.0 * Math.cos(newOrientation);
            newY = currentY - 1.0 * Math.sin(newOrientation);
        }
        else {
            newX = currentX + 1.0 * Math.cos(newOrientation);
            newY = currentY + 1.0 * Math.sin(newOrientation);
        }

        car.setX(newX);
        car.setY(newY);
    }

    /**
     *
     * @param car
     * @param direction
     */
    private void move(ImageView car, String direction, double speed){
        double currentX = car.getX(), currentY = car.getY();
        double currentOrientation = car.getRotate();

        double newOrientation = Math.toRadians(currentOrientation);

        double newX, newY;
        if(direction.equals("FORWARD")) {
            newX = currentX - speed * Math.cos(newOrientation);
            newY = currentY - speed * Math.sin(newOrientation);
        }
        else {
            newX = currentX + speed * Math.cos(newOrientation);
            newY = currentY + speed * Math.sin(newOrientation);
        }

        car.setX(newX);
        car.setY(newY);
    }

    /**
     *
     * @param car
     * @param direction
     * @param orientation
     */
    private void move(final ImageView car, String direction, double speed, double orientation){
        double currentX = car.getX(), currentY = car.getY();
        double currentOrientation = car.getRotate();

        double newOrientation = currentOrientation + orientation;
        final double newOrientationRad = Math.toRadians(newOrientation);

        final double newX, newY;
        if(direction.equals("FORWARD")) {
            newX = currentX - speed * Math.cos(newOrientationRad);
            newY = currentY - speed * Math.sin(newOrientationRad);
        }
        else {
            newX = currentX + speed * Math.cos(newOrientationRad);
            newY = currentY + speed * Math.sin(newOrientationRad);
        }

        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                car.setRotate(Math.toDegrees(newOrientationRad));
                car.setX(newX);
                car.setY(newY);
            }
        });

    }

    private String displayNumber(double number){

        BigDecimal bd = new BigDecimal(number);
        bd.setScale(3, BigDecimal.ROUND_FLOOR);
        DecimalFormat df = new DecimalFormat("##.###");
        return df.format(number);
    }

    /**
     * This class
     * @param stage
     */
    public void start(Stage stage){
        // create whole container
        VBox container = new VBox();
        container.setSpacing(10.0);

        // create canvas
        double canvasWidth = 800, canvasHeight = 600;

        Pane canvas = new BorderPane();
        canvas.setPrefSize(canvasWidth, canvasHeight); // set the size

        // create textfield to display car position
        Label displayPositionLabel = new Label("Position");
        final TextField displayPosition = new TextField();
        displayPosition.setDisable(true);
        displayPosition.setPrefWidth(100);
        // create textfield to display car orientation
        Label displayOrientationLabel = new Label("Orientation");
        final TextField displayOrientation = new TextField();
        displayOrientation.setDisable(true);
        displayOrientation.setPrefWidth(100);
        // create textfield to display current speed
        Label displaySpeedLabel = new Label("Speed");
        final TextField displaySpeed = new TextField();
        displaySpeed.setDisable(true);
        displaySpeed.setPrefWidth(100);

        Label instructionLbl = new Label("Pressed UP key to move forward, " +
                "Pressed DOWN key to move backward, " + "\n" +
                "Pressed LEFT key to move left, " + "\n" +
                "Pressed RIGHT key to move right, " + "\n" +
                "Pressed W key to accelerate, " + "\n" +
                "Pressed S key to decelerate.");
        instructionLbl.setPrefWidth(canvasWidth);

        HBox infoBar = new HBox();
        infoBar.setSpacing(10);
        infoBar.getChildren().addAll(displayPositionLabel, displayPosition,
                displayOrientationLabel, displayOrientation, displaySpeedLabel, displaySpeed);

        // add all elements
        container.getChildren().addAll(infoBar, instructionLbl, canvas);

        Scene scene = new Scene(container);

        Image carSourceImage = new Image("car_small.png");
        final ImageView car = new ImageView(carSourceImage);
        canvas.getChildren().add(car);
        car.setX(canvasWidth/2.0 - car.getFitWidth());
        car.setY(canvasHeight/2.0 - car.getFitHeight());
        car.setRotate(90.0);

        final DoubleProperty movementUnit = new SimpleDoubleProperty(0.0);
        final StringProperty coordinate = new SimpleStringProperty();
        final StringProperty rotation = new SimpleStringProperty(String.valueOf(car.getRotate()));

        // binding
        displayPosition.textProperty().bind(coordinate);
        displayOrientation.textProperty().bind(rotation);
        displaySpeed.textProperty().bind(movementUnit.asString());

        final MultiplePressedKeysEventHandler keyHandler =
                new MultiplePressedKeysEventHandler(new MultiplePressedKeysEventHandler.MultiKeyEventHandler() {
                    @Override
                    public void handle(MultiplePressedKeysEventHandler.MultiKeyEvent ke) {

                        // check if both UP and LEFT keys are pressed
                        if (ke.isPressed(KeyCode.UP)  && ke.isPressed(KeyCode.LEFT)) {
                            System.out.println("UP and LEFT");
                            move(car, "FORWARD", movementUnit.getValue(), -10.0);

                        }
                        // check if only UP and RIGHT keys are pressed
                        else if(ke.isPressed(KeyCode.UP) && ke.isPressed(KeyCode.RIGHT)){
                            System.out.println("UP AND RIGHT");
                            move(car, "FORWARD", movementUnit.getValue(), +10.0);
                        }
                        else if(ke.isPressed(KeyCode.DOWN) && ke.isPressed(KeyCode.LEFT)){
                            System.out.println("DOWN AND LEFT");
                            move(car, "BACKWARD", movementUnit.getValue(), -10.0);
                        }
                        else if(ke.isPressed(KeyCode.DOWN) && ke.isPressed(KeyCode.RIGHT)){
                            System.out.println("DOWN AND RIGHT");
                            move(car, "BACKWARD", movementUnit.getValue(), +10.0);
                        }
                        // check if only UP is pressed
                        else if(ke.isPressed(KeyCode.UP)){
                            move(car, "FORWARD", movementUnit.getValue());
                        }
                        // check if only DOWN is pressed
                        else if(ke.isPressed(KeyCode.DOWN)){
                            move(car, "BACKWARD", movementUnit.getValue());
                        }
                        // check if only LEFT is pressed
                        else if(ke.isPressed(KeyCode.LEFT)){
                            move(car, "FORWARD", 0.0, -10.0);
                        }
                        // check if only RIGHT is pressed
                        else if(ke.isPressed(KeyCode.RIGHT)){
                            move(car, "FORWARD", 0.0, +10.0);
                        }
                        // check if only W is pressed
                        else if(ke.isPressed(KeyCode.W)){
                            movementUnit.setValue(movementUnit.getValue() + 10.0);
                        }
                        // check if only S is pressed
                        else if(ke.isPressed(KeyCode.S)){
                            movementUnit.setValue(movementUnit.getValue() - 10.0);
                        }

                        coordinate.setValue(displayNumber(car.getX()) + ", " + displayNumber(car.getY()));
                        rotation.setValue(displayNumber(car.getRotate()));
                    }
                });

        scene.setOnKeyPressed(keyHandler);
        scene.setOnKeyReleased(keyHandler);

        // give title to window
        stage.setTitle("Tracking");
        stage.setScene(scene);
        stage.show();
    }

    /**
     * Main application access
     * @param args
     */
    public static void main(String[] args){
        launch(args);
{'fraction_non_alphanumeric': 0.1024741081703107, 'fraction_numerical': 0.006559263521288838, 'mean_word_length': 1.8238830219333875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2939818', 'n_tokens_mistral': 4644, 'n_tokens_neox': 4349, 'n_words': 986}