From bdc58555f9f96a5998f76192913d4945a5c427a5 Mon Sep 17 00:00:00 2001 From: RyTai57 <64328234+RyTai57@users.noreply.github.com> Date: Mon, 18 May 2020 14:03:01 -0700 Subject: [PATCH 1/2] Add files via upload Deleted some TODO comments and remove unnecessary print statement --- RhythmGame/src/Arrow.java | 3 ++- RhythmGame/src/ArrowLane.java | 20 ++++++++------------ RhythmGame/src/ArrowListener.java | 3 +-- RhythmGame/src/MenuBar.java | 7 +------ RhythmGame/src/MusicPlayer.java | 2 -- RhythmGame/src/Recorder.java | 5 +++++ RhythmGame/src/RhythmGame.java | 9 --------- 7 files changed, 17 insertions(+), 32 deletions(-) diff --git a/RhythmGame/src/Arrow.java b/RhythmGame/src/Arrow.java index 7a2e0fa..a2e7337 100644 --- a/RhythmGame/src/Arrow.java +++ b/RhythmGame/src/Arrow.java @@ -1,4 +1,5 @@ + import java.awt.Color; import java.awt.Graphics2D; @@ -35,7 +36,7 @@ public Arrow(ArrowLane al) { /** * - * Moves the arrow by its velocity + * Moves the arrow by its velocity and removes it if its off the screen */ public void move() { yPos += YVEL; diff --git a/RhythmGame/src/ArrowLane.java b/RhythmGame/src/ArrowLane.java index 1657324..a1f5bea 100644 --- a/RhythmGame/src/ArrowLane.java +++ b/RhythmGame/src/ArrowLane.java @@ -18,15 +18,14 @@ public class ArrowLane { private final int xPos; - private static int goal;// change later + private static int goal; private LinkedList arrows; private final Direction direction; /** - * - * @param xPos the xCoordinate of all arrows in the lane + * @param xPos the xCoordinate of all arrows in the lane * @param direction the direction of all arrows in the lane */ @@ -38,7 +37,6 @@ public ArrowLane(int xPos, Direction direction, int screenSize) { } /** - * * Adds an arrow to the end/top of the arrowLane */ public void add() { @@ -67,11 +65,11 @@ public int compare() { int score = 0; if (arrow.getY() > goal - 100) { diff = Math.abs(arrow.getY() - goal); - if (diff <= 27) { // TODO define perfect - score = 3; // FYI 3 is best - } else if (diff <= 60) { // TODO define ok + if (diff <= 27) { + score = 3; + } else if (diff <= 60) { score = 2; - } else if (diff <= 100) { // TODO define bad + } else if (diff <= 100) { score = 1; } @@ -114,10 +112,8 @@ public int getX() { } // There is an error when an arrow is removed due to the size of the list - // changing so if we make an array with the copy, the error dissapears since - // the program draws according to the array. There is a cast exception error - // when the code first starts but it dissapears which probably means that it - // might not be the best way + // changing so if we make an array with the copy, the error disappears since + // the program draws according to the array. /** * * Moves all arrows in the lane by iterating through the linked list and calling diff --git a/RhythmGame/src/ArrowListener.java b/RhythmGame/src/ArrowListener.java index a7f50d1..743481d 100644 --- a/RhythmGame/src/ArrowListener.java +++ b/RhythmGame/src/ArrowListener.java @@ -32,10 +32,9 @@ public class ArrowListener extends AbstractAction implements ActionListener { public ArrowListener(RhythmGame g, String k) { game = g; key = k; - System.out.println("constructed"); } - @Override // Aparently overrides don't need javadoc, they probably just have it + @Override public void actionPerformed(ActionEvent arg0) { game.recieveInput(key); diff --git a/RhythmGame/src/MenuBar.java b/RhythmGame/src/MenuBar.java index 981a607..3037191 100644 --- a/RhythmGame/src/MenuBar.java +++ b/RhythmGame/src/MenuBar.java @@ -1,3 +1,4 @@ + import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; @@ -69,23 +70,17 @@ public MenuBar(RhythmGame g, JFrame window) { public void actionPerformed(ActionEvent e) { Object o = e.getSource(); if (selectFile == o) { - System.out.println("File Selected"); String path = System.getProperty("user.dir") + "\\music"; chooser = new JFileChooser("Select a file"); chooser.setCurrentDirectory(new File(path)); int result = chooser.showOpenDialog(game); if (result == JFileChooser.APPROVE_OPTION) { - System.out.println("Haven't tested this part yet. I hope it works"); File file = chooser.getSelectedFile(); fileName = file; } - System.out.println( - "I got the Absolute Path of the file, I have no clue " + "what to do with it, but I got it"); } else if (startGame == o && fileName != null) { - System.out.println("Game starts"); game.start(GameState.PLAY, fileName); } else if (startRecord == o && fileName != null) { - System.out.println("Record starts"); game.start(GameState.RECORD, fileName); } else if (quit == o) { diff --git a/RhythmGame/src/MusicPlayer.java b/RhythmGame/src/MusicPlayer.java index be981dd..def50bd 100644 --- a/RhythmGame/src/MusicPlayer.java +++ b/RhythmGame/src/MusicPlayer.java @@ -38,7 +38,6 @@ public boolean defineSong(String path) { if (clip != null) { clip.close(); } - // https://www.geeksforgeeks.org/play-audio-file-using-java/ try { // create AudioInputStream object audioInputStream = AudioSystem.getAudioInputStream(new File(path).getAbsoluteFile()); @@ -57,7 +56,6 @@ public boolean defineSong(String path) { System.out.println("The audio file selected is unsuported"); return false; } catch (IOException e) { - // TODO Auto-generated catch block System.out.println("error occcured in retrieving the file"); e.printStackTrace(); return false; diff --git a/RhythmGame/src/Recorder.java b/RhythmGame/src/Recorder.java index df24117..411f3f0 100644 --- a/RhythmGame/src/Recorder.java +++ b/RhythmGame/src/Recorder.java @@ -10,6 +10,11 @@ * new file * * @author Ryan Tai, David Choi + * @version May 18, 2020 + * @author Period: 1 + * @author Assignment: RhythmGame + * + * @author Sources: None * */ public class Recorder { diff --git a/RhythmGame/src/RhythmGame.java b/RhythmGame/src/RhythmGame.java index d7260cb..1b4621e 100644 --- a/RhythmGame/src/RhythmGame.java +++ b/RhythmGame/src/RhythmGame.java @@ -81,8 +81,6 @@ public RhythmGame() { for (int i = 0; i < 4; i++) { lanes[i] = new ArrowLane(100 + 200 * i, dir[i], window.getHeight()); } - - // SetWorldTime to a negative number depending on velocity } /** @@ -128,15 +126,12 @@ private void setKeyBindings() { */ public void recieveInput(String input) { - // TODO you need to define gameState as recording and playing when you create - // the menu if (gameState == gameState.IDLE) { return; } else if (gameState == GameState.RECORD) { recorder.record(input); } else if (gameState == GameState.PLAY) { int comparison = 0; - System.out.println("play"); if (input.equals("Left")) { comparison = lanes[0].compare(); } else if (input.equals("Down")) { @@ -146,7 +141,6 @@ public void recieveInput(String input) { } else if (input.equals("Right")) { comparison = lanes[3].compare(); } - System.out.println(comparison); addScore(comparison); } @@ -171,7 +165,6 @@ public void addScore(int i) { scoreColor = Color.GREEN; break; } - System.out.println('i'); g2d.fillRect(0, window.getContentPane().getHeight() - Arrow.getHalfHeight() * 3, SCREEN_WIDTH, Arrow.getHalfHeight() * 2); @@ -356,8 +349,6 @@ public static int getScreenHeight() { */ public static void main(String[] args) { RhythmGame game = new RhythmGame(); -// game.gameState = GameState.RECORD; -// game.recorder.startNewRecodring("song2"); } } From 2d1e38ef81a4871b39c578c3c3f34d067411bc1b Mon Sep 17 00:00:00 2001 From: RyTai57 <64328234+RyTai57@users.noreply.github.com> Date: Mon, 18 May 2020 14:05:58 -0700 Subject: [PATCH 2/2] Update RhythmGame.java --- RhythmGame/src/RhythmGame.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RhythmGame/src/RhythmGame.java b/RhythmGame/src/RhythmGame.java index 1b4621e..4750491 100644 --- a/RhythmGame/src/RhythmGame.java +++ b/RhythmGame/src/RhythmGame.java @@ -46,7 +46,7 @@ public class RhythmGame extends JPanel implements ActionListener { private MenuBar menuBar; private ArrowLane[] lanes; private static final int SCREEN_WIDTH = 800; - private static final int SCREEN_HEIGHT = 1000; // kinda irrelevent + private static final int SCREEN_HEIGHT = 1000; private int worldTime; private Timer timer; private String currentLine = "";