Maven refactor
This commit is contained in:
1 parent
87bc6b38e3
commit
18440d677e
45 files changed
+491
No files matched your search
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project-shared-configuration>
|
||||
<!--
|
||||
This file contains additional configuration written by modules in the NetBeans IDE.
|
||||
The configuration is intended to be shared among all the users of project and
|
||||
therefore it is assumed to be part of version control checkout.
|
||||
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
|
||||
-->
|
||||
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
|
||||
<!--
|
||||
Properties that influence various parts of the IDE, especially code formatting and the like.
|
||||
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
|
||||
That way multiple projects can share the same settings (useful for formatting rules for example).
|
||||
Any value defined here will override the pom.xml file value but is only applicable to the current project.
|
||||
-->
|
||||
<netbeans.hint.jdkPlatform>JDK_17</netbeans.hint.jdkPlatform>
|
||||
</properties>
|
||||
</project-shared-configuration>
|
||||
@@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<actions>
|
||||
<action>
|
||||
<actionName>run</actionName>
|
||||
<packagings>
|
||||
<packaging>jar</packaging>
|
||||
</packagings>
|
||||
<goals>
|
||||
<goal>process-classes</goal>
|
||||
<goal>org.codehaus.mojo:exec-maven-plugin:3.5.1:exec</goal>
|
||||
</goals>
|
||||
<properties>
|
||||
<exec.vmArgs></exec.vmArgs>
|
||||
<exec.args>${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}</exec.args>
|
||||
<exec.appArgs></exec.appArgs>
|
||||
<exec.mainClass>com.mycompany.fuck.you.netbeans.BallControl</exec.mainClass>
|
||||
<exec.executable>java</exec.executable>
|
||||
</properties>
|
||||
</action>
|
||||
<action>
|
||||
<actionName>debug</actionName>
|
||||
<packagings>
|
||||
<packaging>jar</packaging>
|
||||
</packagings>
|
||||
<goals>
|
||||
<goal>process-classes</goal>
|
||||
<goal>org.codehaus.mojo:exec-maven-plugin:3.5.1:exec</goal>
|
||||
</goals>
|
||||
<properties>
|
||||
<exec.vmArgs>-agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address}</exec.vmArgs>
|
||||
<exec.args>${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}</exec.args>
|
||||
<exec.appArgs></exec.appArgs>
|
||||
<exec.mainClass>com.mycompany.fuck.you.netbeans.BallControl</exec.mainClass>
|
||||
<exec.executable>java</exec.executable>
|
||||
<jpda.listen>true</jpda.listen>
|
||||
</properties>
|
||||
</action>
|
||||
<action>
|
||||
<actionName>profile</actionName>
|
||||
<packagings>
|
||||
<packaging>jar</packaging>
|
||||
</packagings>
|
||||
<goals>
|
||||
<goal>process-classes</goal>
|
||||
<goal>org.codehaus.mojo:exec-maven-plugin:3.5.1:exec</goal>
|
||||
</goals>
|
||||
<properties>
|
||||
<exec.vmArgs></exec.vmArgs>
|
||||
<exec.args>${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}</exec.args>
|
||||
<exec.mainClass>com.mycompany.fuck.you.netbeans.BallControl</exec.mainClass>
|
||||
<exec.executable>java</exec.executable>
|
||||
<exec.appArgs></exec.appArgs>
|
||||
</properties>
|
||||
</action>
|
||||
</actions>
|
||||
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.chloefontenot</groupId>
|
||||
<artifactId>TennisGame</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-maven-plugin</artifactId>
|
||||
<version>${javafx.maven.plugin.version}</version>
|
||||
<configuration>
|
||||
<mainClass>org.chloefontenot.BallControl</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-controls</artifactId>
|
||||
<version>${javafx.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-media</artifactId>
|
||||
<version>${javafx.version}</version>
|
||||
<classifier>linux</classifier>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<javafx.version>17</javafx.version>
|
||||
<javafx.maven.plugin.version>0.0.8</javafx.maven.plugin.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.release>8</maven.compiler.release>
|
||||
<exec.mainClass>org.chloefontenot.BallControl</exec.mainClass>
|
||||
</properties>
|
||||
</project>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package org.chloefontenot;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class BallControl extends Application {
|
||||
|
||||
private boolean mouseFocus = false;
|
||||
private int racketPosition = 0;
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception
|
||||
{
|
||||
|
||||
BouncingBall bouncingBall = new BouncingBall();
|
||||
// Create a scene and place it in the stage
|
||||
Scene scene = new Scene(bouncingBall, 800, 600);
|
||||
primaryStage.setTitle("Bouncing Ball Control");
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
bouncingBall.requestFocus();
|
||||
bouncingBall.showInfoLabel();
|
||||
|
||||
bouncingBall.setOnMouseEntered(e
|
||||
-> {
|
||||
mouseFocus = true;
|
||||
bouncingBall.hideInfoLabel();
|
||||
bouncingBall.play();
|
||||
});
|
||||
|
||||
bouncingBall.setOnMouseExited(e -> {
|
||||
mouseFocus = false;
|
||||
});
|
||||
bouncingBall.setOnMouseMoved(new EventHandler<MouseEvent>() {
|
||||
@Override
|
||||
public void handle(MouseEvent event)
|
||||
{
|
||||
double mouseX = event.getSceneX() - (bouncingBall.RACKET_LENGTH / 2); // set relative to center of racket
|
||||
bouncingBall.moveRacket(mouseX);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Increase and decrease animation
|
||||
bouncingBall.setOnKeyPressed(e
|
||||
-> {
|
||||
if (e.getCode() == KeyCode.LEFT && mouseFocus == false) {
|
||||
bouncingBall.hideInfoLabel();
|
||||
if (racketPosition > 0) {
|
||||
racketPosition = racketPosition - 30;
|
||||
}
|
||||
bouncingBall.moveRacket(racketPosition);
|
||||
}
|
||||
if (e.getCode() == KeyCode.RIGHT && mouseFocus == false) {
|
||||
bouncingBall.hideInfoLabel();
|
||||
if (racketPosition < bouncingBall.getWidth()) {
|
||||
racketPosition = racketPosition + 30;
|
||||
}
|
||||
bouncingBall.moveRacket(racketPosition);
|
||||
}
|
||||
if (e.getCode() == KeyCode.UP) {
|
||||
bouncingBall.increaseSpeed();
|
||||
} else if (e.getCode() == KeyCode.DOWN) {
|
||||
bouncingBall.decreaseSpeed();
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
launch(args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package org.chloefontenot;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javafx.animation.KeyFrame;
|
||||
import javafx.animation.Timeline;
|
||||
import javafx.beans.property.DoubleProperty;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.media.Media;
|
||||
import javafx.scene.media.MediaPlayer;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Circle;
|
||||
import javafx.scene.shape.Rectangle;
|
||||
import javafx.util.Duration;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class BouncingBall extends Pane {
|
||||
|
||||
private List<MediaPlayer> mediaPlayers = new ArrayList<>();
|
||||
GridPane textPane = new GridPane();
|
||||
private String currentlyPlaying;
|
||||
private final int COLLISION_COOLDOWN = 20;
|
||||
private long timeSinceLastCollisionEvent = 0;
|
||||
final double RACKET_LENGTH = 100;
|
||||
final double radius = 20;
|
||||
private double x = radius, y = radius;
|
||||
private double dx = 1, dy = 1;
|
||||
private Circle circle = new Circle(x, y, radius);
|
||||
private Rectangle racket = new Rectangle(RACKET_LENGTH, 20);
|
||||
private Label infoLabel = new Label("Your mouse cursor must be inside the bounds of the window to play!");
|
||||
private Label racketTime = new Label();
|
||||
private Label ballCords = new Label();
|
||||
private Label playerScoreLabel = new Label("Player Score: 0");
|
||||
private Label computerScoreLabel = new Label("Computer Score: 0");
|
||||
private Label nowPlaying = new Label();
|
||||
private Button restartBgm = new Button("Restart BGM");
|
||||
|
||||
private Timeline animation;
|
||||
|
||||
private int computerScore, playerScore = 0;
|
||||
|
||||
public BouncingBall() {
|
||||
restartBgm.setOnMouseClicked(e -> {
|
||||
playSound("bgm");
|
||||
});
|
||||
circle.setFill(Color.RED); // Set ball color
|
||||
racket.setFill(Color.BLUE);
|
||||
textPane.add(racketTime, 0, 0);
|
||||
textPane.add(ballCords, 0, 1);
|
||||
textPane.add(playerScoreLabel, 0, 2);
|
||||
textPane.add(computerScoreLabel, 0, 3);
|
||||
textPane.add(nowPlaying, 0, 4);
|
||||
textPane.add(restartBgm, 0, 5);
|
||||
getChildren().addAll(circle, racket, textPane); // Place a ball into this pane
|
||||
racket.relocate(0, 580);
|
||||
playSound("bgm");
|
||||
// Create an animation for moving the ball
|
||||
animation = new Timeline(new KeyFrame(Duration.millis(1), new EventHandler<ActionEvent>() {
|
||||
@Override
|
||||
public void handle(ActionEvent t) {
|
||||
|
||||
timeSinceLastCollisionEvent++;
|
||||
racketTime.setText("Frames since last collision: " + timeSinceLastCollisionEvent);
|
||||
moveBall();
|
||||
// Process collisions
|
||||
if (y >= (getHeight() - 20) && (timeSinceLastCollisionEvent > COLLISION_COOLDOWN)) {
|
||||
timeSinceLastCollisionEvent = 0;
|
||||
playSound("collision");
|
||||
incrementComputerScore();
|
||||
}
|
||||
if ((x <= 20 && (timeSinceLastCollisionEvent > COLLISION_COOLDOWN)) || ((x >= getWidth() - 20) && (timeSinceLastCollisionEvent > COLLISION_COOLDOWN))) {
|
||||
timeSinceLastCollisionEvent = 0;
|
||||
playSound("collision");
|
||||
}
|
||||
if (y <= 20 && (timeSinceLastCollisionEvent > COLLISION_COOLDOWN)) {
|
||||
timeSinceLastCollisionEvent = 0;
|
||||
playSound("collision");
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
animation.setRate(animation.getRate() * .5);
|
||||
animation.setCycleCount(Timeline.INDEFINITE);
|
||||
|
||||
}
|
||||
|
||||
private boolean processRacketCollision() {
|
||||
boolean racketCollision = racket.getBoundsInParent().intersects(circle.getBoundsInParent());
|
||||
|
||||
if (racketCollision && (timeSinceLastCollisionEvent > COLLISION_COOLDOWN)) { // This is second condition is a cooldown. It prevents odd behavior happening with the ball and the racket if the racket hits the ball at certain angles.
|
||||
System.out.println("Racket collision detected!");
|
||||
timeSinceLastCollisionEvent = 0;
|
||||
incrementPlayerScore();
|
||||
playSound("racket");
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void moveBall() {
|
||||
|
||||
// Check boundaries
|
||||
if (x < radius || x > getWidth() - radius) {
|
||||
dx *= -1; // Change ball move direction
|
||||
}
|
||||
if (y < radius || y > getHeight() - radius || processRacketCollision()) {
|
||||
dy *= -1; // Change ball move direction
|
||||
}
|
||||
|
||||
// Adjust ball position by 1 or -1
|
||||
x += dx;
|
||||
y += dy;
|
||||
circle.setCenterX(x);
|
||||
circle.setCenterY(y);
|
||||
ballCoordsToLabel();
|
||||
}
|
||||
|
||||
public void play() {
|
||||
animation.play();
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
animation.pause();
|
||||
}
|
||||
|
||||
public void increaseSpeed() {
|
||||
animation.setRate(animation.getRate() * 1.5);
|
||||
System.out.println(animation.getRate());
|
||||
}
|
||||
|
||||
public void decreaseSpeed() {
|
||||
animation.setRate(animation.getRate() * 1.5 > 0 ? animation.getRate() / 1.5 : 0);
|
||||
System.out.println(animation.getRate());
|
||||
}
|
||||
|
||||
public DoubleProperty rateProperty() {
|
||||
return animation.rateProperty();
|
||||
}
|
||||
|
||||
public void moveRacket(double x) {
|
||||
racket.relocate(x, 580);
|
||||
}
|
||||
|
||||
public void showInfoLabel() {
|
||||
double paneHeight = getHeight();
|
||||
double paneWidth = getWidth();
|
||||
getChildren().add(infoLabel);
|
||||
// Center Text
|
||||
infoLabel.relocate(paneWidth / 4.0, paneHeight / 2.0);
|
||||
}
|
||||
|
||||
public void hideInfoLabel() {
|
||||
getChildren().remove(infoLabel);
|
||||
}
|
||||
|
||||
private void incrementPlayerScore() {
|
||||
playerScoreLabel.setText("Player score: " + ++playerScore);
|
||||
}
|
||||
|
||||
private void incrementComputerScore() {
|
||||
computerScoreLabel.setText("Computer score: " + ++computerScore);
|
||||
|
||||
}
|
||||
|
||||
private void ballCoordsToLabel() {
|
||||
ballCords.setText("Ball coords: " + x + ", " + y);
|
||||
}
|
||||
|
||||
private void playSound(String sampleType) {
|
||||
boolean isSfx = true;
|
||||
String sample = "sound/sfx/Sample_00";
|
||||
int randInt = (int) (Math.random() * 2);
|
||||
switch (sampleType) {
|
||||
case "collision":
|
||||
randInt = (int) (Math.random() * 2);
|
||||
isSfx = true;
|
||||
switch (randInt) {
|
||||
case 0:
|
||||
sample += "05";
|
||||
break;
|
||||
case 1:
|
||||
sample += "07";
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "racket":
|
||||
randInt = (int) (Math.random() * 2);
|
||||
isSfx = true;
|
||||
switch (randInt) {
|
||||
case 0:
|
||||
sample += "10";
|
||||
break;
|
||||
case 1:
|
||||
sample += "12";
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "bgm":
|
||||
sample = "sound/bgm/";
|
||||
randInt = (int) (Math.random() * 3);
|
||||
isSfx = false;
|
||||
switch (randInt) {
|
||||
case 0:
|
||||
currentlyPlaying = "Chloe Fontenot - Blips";
|
||||
nowPlaying.setText("Now playing: " + currentlyPlaying);
|
||||
break;
|
||||
case 1:
|
||||
currentlyPlaying = "Chloe Fontenot - DEAL WITH IT";
|
||||
nowPlaying.setText("Now playing: " + currentlyPlaying);
|
||||
break;
|
||||
case 2:
|
||||
currentlyPlaying = "Chloe Fontenot - Tomodachi Moment";
|
||||
nowPlaying.setText("Now playing: " + currentlyPlaying);
|
||||
break;
|
||||
}
|
||||
sample += currentlyPlaying;
|
||||
break;
|
||||
}
|
||||
Media sound = new Media(new File(sample + ".wav").toURI().toString());
|
||||
MediaPlayer mediaPlayer = new MediaPlayer(sound);
|
||||
mediaPlayer.setStartTime(Duration.ZERO);
|
||||
mediaPlayer.setAutoPlay(true);
|
||||
// If we're playing BGM, lower the volume a little
|
||||
if (!isSfx) {
|
||||
mediaPlayer.setVolume(0.6);
|
||||
mediaPlayer.setCycleCount(MediaPlayer.INDEFINITE);
|
||||
}
|
||||
mediaPlayer.play();
|
||||
mediaPlayers.add(mediaPlayer); // Prevent the JVM's GC from deleting our media player if there's already one running
|
||||
// Free the media player when it has finished playing a sound.
|
||||
mediaPlayer.setOnEndOfMedia(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
//System.out.println("I'm done playing sound! Please take me to the ether, Java GC!");
|
||||
mediaPlayer.stop();
|
||||
mediaPlayer.dispose();
|
||||
mediaPlayers.remove(mediaPlayer);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package org.chloefontenot;
|
||||
|
||||
import javafx.scene.media.MediaPlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class MediaType {
|
||||
private MediaPlayer mediaPlayer;
|
||||
private boolean isBgm;
|
||||
|
||||
public MediaType(MediaPlayer mediaPlayer, boolean isBgm) {
|
||||
this.mediaPlayer = mediaPlayer;
|
||||
this.isBgm = isBgm;
|
||||
}
|
||||
|
||||
public boolean isIsBgm() {
|
||||
return isBgm;
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,6 @@
|
||||
org/chloefontenot/MediaType.class
|
||||
org/chloefontenot/BallControl.class
|
||||
org/chloefontenot/BallControl$1.class
|
||||
org/chloefontenot/BouncingBall.class
|
||||
org/chloefontenot/BouncingBall$1.class
|
||||
org/chloefontenot/BouncingBall$2.class
|
||||
@@ -0,0 +1,3 @@
|
||||
/home/chloe/NetBeansProjects/fuck-you-netbeans/src/main/java/org/chloefontenot/BallControl.java
|
||||
/home/chloe/NetBeansProjects/fuck-you-netbeans/src/main/java/org/chloefontenot/BouncingBall.java
|
||||
/home/chloe/NetBeansProjects/fuck-you-netbeans/src/main/java/org/chloefontenot/MediaType.java
|
||||
Reference in new issue
Block a user