Skip to content

Commit

Permalink
Merge pull request #73 from Spindler-ICS4UC-1-1819/final-prep
Browse files Browse the repository at this point in the history
Final prep
  • Loading branch information
NicolasHawrysh authored Jan 20, 2019
2 parents 62739f9 + 6d51ff8 commit 3ad5acc
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 57 deletions.
10 changes: 0 additions & 10 deletions ICS4UC_RST/src/games/Score.java

This file was deleted.

2 changes: 1 addition & 1 deletion ICS4UC_RST/src/games/player/KeyboardPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public abstract class KeyboardPlayer<T extends KeyBinding> {
/**
* Key bindings map for the keyboard player.
*/
protected HashMap<KeyCode, T> keyBindings;
private HashMap<KeyCode, T> keyBindings;

/**
* Gets this keyboard player's key bindings.
Expand Down
22 changes: 13 additions & 9 deletions ICS4UC_RST/src/games/pong/Pong.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
* @author Kyle Anderson
* ICS4U RST
*/
@SuppressWarnings("WeakerAccess")
public class Pong {
// Default width and height for the pong game.
private static final int WIDTH = 512, HEIGHT = 256;
// How far the paddles are from the side.
private static final int PADDLE_DISTANCE = 5, PADDLE_WIDTH = 2, PADDLE_HEIGHT = 40;
private static final int PADDLE_DISTANCE = 5, PADDLE_WIDTH = 3, PADDLE_HEIGHT = 40;

/**
* Maximum ball rebound angle, in degrees.
Expand All @@ -30,9 +31,9 @@ public class Pong {
// Ratios for distances and speeds.
private static final double BALL_RADIUS = 4;
// How many units per second the paddle moves while the button is being held down.
public static final double PADDLE_MOVEMENT_RATE = 200;
private static final double PADDLE_MOVEMENT_RATE = 200;
// Velocity of the pong ball in units per second.
public static final double PONG_BALL_VELOCITY = 250;
public static final double PONG_BALL_VELOCITY = 325;
// How many milliseconds to pause after a player scores.
private static final long SCORE_PAUSE = 3000; // Set score pause to 3 seconds.
/**
Expand Down Expand Up @@ -82,7 +83,7 @@ public class Pong {
/**
* An action to be run after each tick.
*/
private ArrayList<Runnable> tickActions = new ArrayList<>();
private final ArrayList<Runnable> tickActions = new ArrayList<>();

/**
* Constructs a new pong game with the given players.
Expand Down Expand Up @@ -437,7 +438,7 @@ private boolean testBallCollision(Paddle testingPaddle, final long nanosSinceLas
ballPoint = PongBall.getX(ball.getRadius(), oldBallX, Side.RIGHT);
} else {
paddlePoint = testingPaddle.getX(Side.RIGHT);
ballPoint = oldBallX;
ballPoint = PongBall.getX(ball.getRadius(), oldBallX, Side.LEFT);
}

// If the ball was in intersect range during the last tick, we don't need to deal with it now.
Expand All @@ -446,25 +447,28 @@ private boolean testBallCollision(Paddle testingPaddle, final long nanosSinceLas

// Otherwise, we need to run more calculations.
if (didIntersect) {
final Side ballSide = testingPaddle.getSide();
// Determine how long it's been since the ball would've collided. time = distance / velocity
final double timePassedSinceCollision = (Math.abs(ball.getX() - oldBallX)) / (ball.getRunPerNanoSecond());
final double timePassedSinceCollision = (Math.abs(ball.getX(ballSide) - paddlePoint)) / (ball.getRunPerNanoSecond());
// Determine where the paddle would have been at that time. distance = velocity * time.
final double paddleTopAtTime = testingPaddle.getY(Side.TOP) - timePassedSinceCollision * testingPaddle.getVelYNanos();
// Also get the bottom position here.
final double paddleBottomAtTime = Paddle.getY(testingPaddle.getHeight(), paddleTopAtTime, Side.BOTTOM);
final double paddleTopCollisionPoint = paddleTopAtTime + ball.getRadius();
final double paddleBottomCollisionPoint = paddleBottomAtTime - ball.getRadius();
// Determine the ball's height at that time.
final double ballTopYAtTime = ball.getY(Side.TOP) - timePassedSinceCollision * (ball.getRisePerNanoSecond());
final double ballCenterAtTime = PongBall.getY(ball.getRadius(), ballTopYAtTime, Side.CENTER);
double goodBallPos;
if (ballCenterAtTime > paddleTopAtTime) {
if (ballCenterAtTime >= paddleTopCollisionPoint) {
goodBallPos = ballTopYAtTime;
} else if (ballCenterAtTime < paddleBottomAtTime) {
} else if (ballCenterAtTime <= paddleBottomCollisionPoint) {
goodBallPos = PongBall.getY(ball.getRadius(), ballTopYAtTime, Side.BOTTOM);
} else {
goodBallPos = ballCenterAtTime;
}

didIntersect = doesBallIntersect(goodBallPos, paddleTopAtTime, paddleBottomAtTime);
didIntersect = doesBallIntersect(goodBallPos, paddleTopCollisionPoint, paddleBottomCollisionPoint);

// If there was an intersection, we need to continue even more with determining the ball's new location.
if (didIntersect) {
Expand Down
1 change: 1 addition & 0 deletions ICS4UC_RST/src/games/pong/PongEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public EventType getType() {
return type;
}

@SuppressWarnings("WeakerAccess")
public void setType(EventType type) {
this.type = type;
}
Expand Down
2 changes: 2 additions & 0 deletions ICS4UC_RST/src/games/pong/network/PongNetworkMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public long timestamp() {
*
* @param timestampSent The time (in nanoseconds) at which the data was calculated (when frame was rendered).
*/
@SuppressWarnings("WeakerAccess")
public void setTimestampSent(long timestampSent) {
this.timestampSent = timestampSent;
}
Expand Down Expand Up @@ -207,6 +208,7 @@ public static PongNetworkMessage fromJsonString(String jsonString) {
* @param message The PongNetworkMessage to be converted.
* @return The json string.
*/
@SuppressWarnings("WeakerAccess")
public static String toJsonString(PongNetworkMessage message) {
return gson.toJson(message);
}
Expand Down
1 change: 1 addition & 0 deletions ICS4UC_RST/src/games/pong/pieces/Paddle.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @author Kyle Anderson
* ICS4U RST
*/
@SuppressWarnings("WeakerAccess")
public class Paddle implements PongPiece {
private double x, y;
private final double width, height;
Expand Down
9 changes: 4 additions & 5 deletions ICS4UC_RST/src/games/pong/players/PongBot.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
*
*/
package games.pong.players;

import games.pong.Pong;
Expand All @@ -12,11 +9,12 @@

/**
* @author s405751 (Nicolas Hawrysh)
*
* <p>
* ICS4U
*
* <p>
* Abstract class for pong bot
*/
@SuppressWarnings("WeakerAccess")
public abstract class PongBot implements PongPlayer {
protected static final int PADDLE_HEIGHT_DIVISOR = 10;
/**
Expand Down Expand Up @@ -103,6 +101,7 @@ public void setGame(Pong game) {

/**
* Determines if this bot has a target vertical height to reach.
*
* @return True if there is a target, false otherwise.
*/
protected boolean hasTarget() {
Expand Down
2 changes: 1 addition & 1 deletion ICS4UC_RST/src/games/pong/ui/Divider.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author s405751 (Nicolas Hawrysh)
* ICS4U RST
*/
public class Divider extends Group {
class Divider extends Group {
// Number of squares that we want.
private static final int NUMBER_OF_DASHES = 20;

Expand Down
9 changes: 4 additions & 5 deletions ICS4UC_RST/src/games/pong/ui/PongUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public class PongUI extends Pane implements Game {
We want to make it so that if the player presses the end key END_KEY_NUMBER_PRESSES times in END_KEY_MILLISECONDS
milliseconds, the game quits.
*/
private Long[] endKeyPressTimes = new Long[END_KEY_NUMBER_PRESSES];
private final Long[] endKeyPressTimes = new Long[END_KEY_NUMBER_PRESSES];
private VBox selector;

/**
Expand Down Expand Up @@ -367,7 +367,7 @@ private void updateBallLocation() {
* @param desiredSide The desired coordinate (Side.TOP, Side.CENTER, Side.BOTTOM) that needs to be calculated.
* @return The transformed value.
*/
public static double transformY(double boardHeight, PongPiece piece, Side desiredSide) {
private static double transformY(double boardHeight, PongPiece piece, Side desiredSide) {
double newY;
double topLeftY = boardHeight - piece.getY(Side.TOP);
switch (desiredSide) {
Expand Down Expand Up @@ -698,9 +698,8 @@ private static <T> void shiftAndAppend(T[] array, T... elementsToAppend) {
}
} else {
// First shift.
for (int i = elementsToAppend.length; i < array.length; i++) {
array[i - elementsToAppend.length] = array[i];
}
if (array.length - elementsToAppend.length >= 0)
System.arraycopy(array, elementsToAppend.length, array, 0, array.length - elementsToAppend.length);
// Then append.
for (int i = 0; i < elementsToAppend.length; i++) {
array[array.length - i - 1] = elementsToAppend[i];
Expand Down
6 changes: 3 additions & 3 deletions ICS4UC_RST/src/games/pong/ui/Scoreboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @author Kyle Anderson and Nicolas Hawrysh
* ICS4U RST
*/
public class Scoreboard extends Group {
class Scoreboard extends Group {
// Text objects for the scores.
private final Label leftScore;
private final Label rightScore;
Expand All @@ -25,8 +25,8 @@ public class Scoreboard extends Group {
/**
* Instantiates a new Scoreboard object.
*
* @param font
* @param foregroundColour
* @param foregroundColour The foreground colour.
* @param font The font to be used.
*/
public Scoreboard(Paint foregroundColour, Font font) {
leftScore = new Label("0");
Expand Down
2 changes: 1 addition & 1 deletion ICS4UC_RST/src/menu/ConnectTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @author Kyle Anderson
* ICS4U RST
*/
public class ConnectTask extends Task<Boolean> {
class ConnectTask extends Task<Boolean> {
private final String ip;
private final int port;

Expand Down
4 changes: 2 additions & 2 deletions ICS4UC_RST/src/menu/HostTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
* @author Kyle Anderson
* ICS4U RST
*/
public class HostTask extends Task {
final int port;
class HostTask extends Task {
private final int port;

/**
* Instantiates a host task with the given port.
Expand Down
14 changes: 7 additions & 7 deletions ICS4UC_RST/src/menu/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public class MainMenu extends Application {
}

/**
* The key to be pressed whewn the user wants to toggle fullscreen.
* The key to be pressed when the user wants to toggle fullscreen.
*/
private static final KeyCode FULLSCREEN_KEYCODE = KeyCode.F11;
private static final String MENU_HELP_TEXT = String.format("Welcome to the Arcade!\n" +
Expand All @@ -98,9 +98,9 @@ public class MainMenu extends Application {
public static final int GAP = 15;
// Font size ratios
private static final int HEADER_FONT_SIZE_RATIO = 13, INPUT_FONT_SIZE_RATIO = 40, GAME_FONT_SIZE_RATIO = 5;
private DoubleProperty headerFontSize = new SimpleDoubleProperty(HEADER_FONT_SIZE_RATIO);
private DoubleProperty inputFontSize = new SimpleDoubleProperty(INPUT_FONT_SIZE_RATIO);
private DoubleProperty gameFontSize = new SimpleDoubleProperty(GAME_FONT_SIZE_RATIO);
private final DoubleProperty headerFontSize = new SimpleDoubleProperty(HEADER_FONT_SIZE_RATIO);
private final DoubleProperty inputFontSize = new SimpleDoubleProperty(INPUT_FONT_SIZE_RATIO);
private final DoubleProperty gameFontSize = new SimpleDoubleProperty(GAME_FONT_SIZE_RATIO);
private static final Font
HEADER_FONT = Font.font("ArcadeClassic", FontWeight.BOLD, 36),
INPUT_FONT = Font.font("Book Antiqua");
Expand Down Expand Up @@ -665,7 +665,7 @@ private void onConnection() {
*
* @param receivedEvent The event of the received data.
*/
public void messageReceived(ReceivedDataEvent receivedEvent) {
private void messageReceived(ReceivedDataEvent receivedEvent) {
// Determine if some of the data should be passed to the current game.
final boolean shouldSendToGame = currentGame != null && currentGame.isNetworkGame();
if (receivedEvent == ReceivedDataEvent.RECEIVED_DATA) {
Expand Down Expand Up @@ -759,7 +759,6 @@ private void sendGameData(final String gameData) {
* @param otherPlayerName The gamer tag of the player inviting this player to play the game.
* @param game The game to which the user was invited.
* @param onInviteDecision The action to be called when the user either accepts or declines the invite.
* @return True if this user accepts playing the game, false otherwise.
*/
private void gameInvite(final String otherPlayerName, final Game game, @NotNull Consumer<Boolean> onInviteDecision) {
if (game != null) {
Expand Down Expand Up @@ -810,7 +809,7 @@ private Game findGame(final String gameClassName) {
* @param content The notification's content text.
* @param action The action to be called when the notification is clicked.
*/
public static void showNotification(Alert.AlertType type, final String title, final String content, @Nullable EventHandler<ActionEvent> action) {
private static void showNotification(Alert.AlertType type, final String title, final String content, @Nullable EventHandler<ActionEvent> action) {
Notifications notifications = Notifications.create();
notifications.title(title);
notifications.text(content);
Expand Down Expand Up @@ -872,6 +871,7 @@ public static void main(String[] args) {
*
* @param stage The stage for which the icon should be set.
*/
@SuppressWarnings("WeakerAccess")
public static void setIcon(Stage stage) {
stage.getIcons().add(WINDOW_ICON);
}
Expand Down
4 changes: 2 additions & 2 deletions ICS4UC_RST/src/menu/PartyMenuItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @author Kyle Anderson
* ICS4U RST
*/
public class PartyMenuItem extends StackPane {
class PartyMenuItem extends StackPane {
private static final Pattern IP_VALIDATOR = Pattern.compile("\\A((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\z");


Expand All @@ -31,7 +31,7 @@ public class PartyMenuItem extends StackPane {
private final String inactiveText, activeText;
private boolean active;

private Button disconnectButton;
private final Button disconnectButton;

private EventHandler<ActionEvent> actionHandler;

Expand Down
13 changes: 2 additions & 11 deletions ICS4UC_RST/src/network/party/PartyHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,6 @@ public static void host(final int port) throws IOException {
}
}

/**
* Determines if the other player is connected.
*
* @return True if the other player is connected, false otherwise.
*/
public static boolean isOtherPlayerConnected() {
return socket.isConnected();
}

/**
* Disconnects from the party.
*/
Expand Down Expand Up @@ -147,7 +138,7 @@ public static Server getServer() {
*
* @return The TCP socket object.
*/
public static TCPSocket getTCPSocket() {
private static TCPSocket getTCPSocket() {
return socket;
}

Expand Down Expand Up @@ -278,7 +269,7 @@ public static void main(String[] args) throws IOException, InterruptedException

boolean waiting;
do {
waiting = isOtherPlayerConnected();
waiting = isConnected();
if (waiting) {
AdvancedIO.print("Waiting for other user to join...");
}
Expand Down
1 change: 1 addition & 0 deletions ICS4UC_RST/src/network/party/network/NetworkMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @author Kyle Anderson
* ICS4U RST
*/
@SuppressWarnings("WeakerAccess")
public class NetworkMessage {
private String hostName;
private HostStatus hostStatus;
Expand Down

0 comments on commit 3ad5acc

Please sign in to comment.