From 4c67291aee90d1e42c51400d544882bcda8e1a18 Mon Sep 17 00:00:00 2001 From: Tyler Ferrari Date: Tue, 9 May 2023 12:30:00 +0000 Subject: Move files --- Driver.java | 21 ------- NoteField.java | 34 ----------- NoteInfo.java | 22 ------- Score.java | 51 ---------------- SongPlayer.java | 142 ------------------------------------------- Timer.java | 15 ----- src/fallTest/Driver.java | 21 +++++++ src/fallTest/NoteField.java | 34 +++++++++++ src/fallTest/NoteInfo.java | 22 +++++++ src/fallTest/Score.java | 51 ++++++++++++++++ src/fallTest/SongPlayer.java | 142 +++++++++++++++++++++++++++++++++++++++++++ src/fallTest/Timer.java | 15 +++++ 12 files changed, 285 insertions(+), 285 deletions(-) delete mode 100644 Driver.java delete mode 100644 NoteField.java delete mode 100644 NoteInfo.java delete mode 100644 Score.java delete mode 100644 SongPlayer.java delete mode 100644 Timer.java create mode 100644 src/fallTest/Driver.java create mode 100644 src/fallTest/NoteField.java create mode 100644 src/fallTest/NoteInfo.java create mode 100644 src/fallTest/Score.java create mode 100644 src/fallTest/SongPlayer.java create mode 100644 src/fallTest/Timer.java diff --git a/Driver.java b/Driver.java deleted file mode 100644 index 721fb80..0000000 --- a/Driver.java +++ /dev/null @@ -1,21 +0,0 @@ -/*Name: - *Date: - *Period: - *Teacher: - *Description: - */ -package cs; - - -public class Driver -{ - - public static void main(String[] args) - { - // TODO Auto-generated method stub - SongPlayer g = new SongPlayer(); - g.queueTest(); - g.createAndShowGui(); - } - -} diff --git a/NoteField.java b/NoteField.java deleted file mode 100644 index b54e33a..0000000 --- a/NoteField.java +++ /dev/null @@ -1,34 +0,0 @@ -/*Name: Guitar Hero Project - *Description: Contains the information for a single note on the field - */ -package cs; - -public class NoteField -{ - private boolean failed = false; - private final int NOTESPEED = 5; - private int yPos = SongPlayer.HEIGHT; - - public void gameTick() { - if (!failed) { - if (yPos > 0) { - yPos -= NOTESPEED; - } - else { - failed = true; - } - } - } - - public int goalDistance() { - return (yPos-((SongPlayer.HEIGHT)/6)); - } - - public boolean getFailed() { - return failed; - } - - public int getY() { - return yPos; - } -} diff --git a/NoteInfo.java b/NoteInfo.java deleted file mode 100644 index 538b31b..0000000 --- a/NoteInfo.java +++ /dev/null @@ -1,22 +0,0 @@ -/*Name: Guitar Hero Project - *Description: Contains the info for when to send a note - */ -package cs; - - -public class NoteInfo -{ - private int sendTime; - - public NoteInfo(int t) { - sendTime = t; - } - - public int getTime() { - return sendTime; - } - - public int compareTo(NoteInfo other) { - return sendTime - other.sendTime; - } -} diff --git a/Score.java b/Score.java deleted file mode 100644 index 97f2393..0000000 --- a/Score.java +++ /dev/null @@ -1,51 +0,0 @@ -/*Name: Guitar Hero Project - *Description: Handles all the scoring for playing songs - */ -package cs; - - -public class Score -{ - private int combo=0; - private int comboMultiplier=1; - private int score=0; - - public void perfect() { - score += 5*comboMultiplier; - System.out.println("perfect"); - } - - public void close() { - score += comboMultiplier; - System.out.println("close"); - } - - public void miss() { - combo = 0; - comboMultiplier = 1; - System.out.println("miss"); - } - public void combo() { - combo++; - - if (combo == 2) { - comboMultiplier = 2; - } - - if (combo == 4) { - comboMultiplier = 4; - } - - if (combo == 8) { - comboMultiplier = 8; - } - } - - public int getScore() { - return score; - } - - public int getCombo() { - return combo; - } -} diff --git a/SongPlayer.java b/SongPlayer.java deleted file mode 100644 index da58b08..0000000 --- a/SongPlayer.java +++ /dev/null @@ -1,142 +0,0 @@ -/*Name: Guitar Hero Project - *Description: Contains the main game loop for gameplay - */ -package cs; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import java.util.*; - -public class SongPlayer -{ - Timer time = new Timer(); - - public static final int HEIGHT = 650; - public static final int LENGTH = 400; - - private final int BLENGTH = LENGTH/6; - private final int BHEIGHT = HEIGHT/20; - - JFrame frame = new JFrame("Guitar Hero"); //creates the frame - JButton d = new JButton("D"); //creates the four button lanes - - Queue sends = new LinkedList(); //Queue that dictates when to send the notes - ArrayList lanes = new ArrayList(); //Array list containing all the notes currently on the field - ArrayList vis = new ArrayList(); //Array list containing the visual representations of the notes in lanes - - Score score = new Score(); - - public void queueTest() { - sends.add(new NoteInfo(1000)); - sends.add(new NoteInfo(2000)); - sends.add(new NoteInfo(3000)); - sends.add(new NoteInfo(4000)); - sends.add(new NoteInfo(5000)); - sends.add(new NoteInfo(6000)); - sends.add(new NoteInfo(7000)); - sends.add(new NoteInfo(8000)); - sends.add(new NoteInfo(9000)); - } - - - /** - * Creates the Gui used to play the game - */ - public void createAndShowGui() { - - d.setBounds(1*BLENGTH, (5*HEIGHT)/6, BLENGTH, BHEIGHT); //makes the button bounds for each button - - frame.add(d); //adds the buttons to the frame - - frame.setSize(LENGTH, HEIGHT); //sets the size of the frame - frame.setLayout(null); - frame.setVisible(true); //makes the frame visible - - - while (true) { //TRY TO FIND A BETTER SOLUTION FOR THIS?? maybe something like sends.size() > 0 || lanes.size() > 0 - - if (!sends.isEmpty() && sends.peek().getTime()-time.time()<3) { //checks if any notes in the queue need to be sent at this time - lanes.add(new NoteField()); //adds that note's information to the lane list - - vis.add(new JButton()); //creates a visual representation of that note in the visualizer list - frame.add(vis.get(vis.size()-1)); - - sends.remove(); //removes the note just sent from the sending queue - } - - if (lanes.size() > 0) { //if there are any notes in the lanes, tests for a button press - d.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke('d'), "dPress"); //Input map and Action map setting - d.getActionMap().put("dPress", new AbstractAction() { //Defines what happens when the proper button is pressed - public void actionPerformed(ActionEvent e) - { - int i = getClosestNote(); - int dist = (int)Math.abs(lanes.get(i).goalDistance()); - - lanes.remove(i); //removes the notes and visual representation from the playing field when the button is pressed - frame.remove(vis.get(i)); - vis.remove(i); - - if (dist > 2*BHEIGHT) { //Determines what to add to the score depending on the proximity of the note - score.miss(); - } - else if (dist > BHEIGHT) { - score.combo(); - score.close(); - } - else { - score.combo(); - score.perfect(); - } - - System.out.println(score.getScore() + " Combo: " + score.getCombo()); - } - }); - d.setFocusable(false); //makes it so you can't focus on the button - } - - for (int i=0; i 0 && lanes.get(i).getFailed()) { //if the note has passed into the fail boundary, removes the note from the field - score.miss(); - System.out.println(score.getScore() + " Combo: " + score.getCombo()); - - - lanes.remove(i); - frame.remove(vis.get(i)); - vis.remove(i); - - i--; - } - } - - frame.repaint(); //updates the visuals every frame - - try { - Thread.sleep(10); - } catch (InterruptedException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - - /** - * Finds the note closest to the goal - * @return the location in the array list of the closest note - */ - private int getClosestNote() { - int pos = 0; - - for (int i=0; i 0) { + yPos -= NOTESPEED; + } + else { + failed = true; + } + } + } + + public int goalDistance() { + return (yPos-((SongPlayer.HEIGHT)/6)); + } + + public boolean getFailed() { + return failed; + } + + public int getY() { + return yPos; + } +} diff --git a/src/fallTest/NoteInfo.java b/src/fallTest/NoteInfo.java new file mode 100644 index 0000000..77b9a20 --- /dev/null +++ b/src/fallTest/NoteInfo.java @@ -0,0 +1,22 @@ +/*Name: Guitar Hero Project + *Description: Contains the info for when to send a note + */ +package fallTest; + + +public class NoteInfo +{ + private int sendTime; + + public NoteInfo(int t) { + sendTime = t; + } + + public int getTime() { + return sendTime; + } + + public int compareTo(NoteInfo other) { + return sendTime - other.sendTime; + } +} diff --git a/src/fallTest/Score.java b/src/fallTest/Score.java new file mode 100644 index 0000000..f2840a3 --- /dev/null +++ b/src/fallTest/Score.java @@ -0,0 +1,51 @@ +/*Name: Guitar Hero Project + *Description: Handles all the scoring for playing songs + */ +package fallTest; + + +public class Score +{ + private int combo=0; + private int comboMultiplier=1; + private int score=0; + + public void perfect() { + score += 5*comboMultiplier; + System.out.println("perfect"); + } + + public void close() { + score += comboMultiplier; + System.out.println("close"); + } + + public void miss() { + combo = 0; + comboMultiplier = 1; + System.out.println("miss"); + } + public void combo() { + combo++; + + if (combo == 2) { + comboMultiplier = 2; + } + + if (combo == 4) { + comboMultiplier = 4; + } + + if (combo == 8) { + comboMultiplier = 8; + } + } + + public int getScore() { + return score; + } + + public int getCombo() { + return combo; + } +} diff --git a/src/fallTest/SongPlayer.java b/src/fallTest/SongPlayer.java new file mode 100644 index 0000000..ad3e4e2 --- /dev/null +++ b/src/fallTest/SongPlayer.java @@ -0,0 +1,142 @@ +/*Name: Guitar Hero Project + *Description: Contains the main game loop for gameplay + */ +package fallTest; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import java.util.*; + +public class SongPlayer +{ + Timer time = new Timer(); + + public static final int HEIGHT = 650; + public static final int LENGTH = 400; + + private final int BLENGTH = LENGTH/6; + private final int BHEIGHT = HEIGHT/20; + + JFrame frame = new JFrame("Guitar Hero"); //creates the frame + JButton d = new JButton("D"); //creates the four button lanes + + Queue sends = new LinkedList(); //Queue that dictates when to send the notes + ArrayList lanes = new ArrayList(); //Array list containing all the notes currently on the field + ArrayList vis = new ArrayList(); //Array list containing the visual representations of the notes in lanes + + Score score = new Score(); + + public void queueTest() { + sends.add(new NoteInfo(1000)); + sends.add(new NoteInfo(2000)); + sends.add(new NoteInfo(3000)); + sends.add(new NoteInfo(4000)); + sends.add(new NoteInfo(5000)); + sends.add(new NoteInfo(6000)); + sends.add(new NoteInfo(7000)); + sends.add(new NoteInfo(8000)); + sends.add(new NoteInfo(9000)); + } + + + /** + * Creates the Gui used to play the game + */ + public void createAndShowGui() { + + d.setBounds(1*BLENGTH, (5*HEIGHT)/6, BLENGTH, BHEIGHT); //makes the button bounds for each button + + frame.add(d); //adds the buttons to the frame + + frame.setSize(LENGTH, HEIGHT); //sets the size of the frame + frame.setLayout(null); + frame.setVisible(true); //makes the frame visible + + + while (true) { //TRY TO FIND A BETTER SOLUTION FOR THIS?? maybe something like sends.size() > 0 || lanes.size() > 0 + + if (!sends.isEmpty() && sends.peek().getTime()-time.time()<3) { //checks if any notes in the queue need to be sent at this time + lanes.add(new NoteField()); //adds that note's information to the lane list + + vis.add(new JButton()); //creates a visual representation of that note in the visualizer list + frame.add(vis.get(vis.size()-1)); + + sends.remove(); //removes the note just sent from the sending queue + } + + if (lanes.size() > 0) { //if there are any notes in the lanes, tests for a button press + d.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke('d'), "dPress"); //Input map and Action map setting + d.getActionMap().put("dPress", new AbstractAction() { //Defines what happens when the proper button is pressed + public void actionPerformed(ActionEvent e) + { + int i = getClosestNote(); + int dist = (int)Math.abs(lanes.get(i).goalDistance()); + + lanes.remove(i); //removes the notes and visual representation from the playing field when the button is pressed + frame.remove(vis.get(i)); + vis.remove(i); + + if (dist > 2*BHEIGHT) { //Determines what to add to the score depending on the proximity of the note + score.miss(); + } + else if (dist > BHEIGHT) { + score.combo(); + score.close(); + } + else { + score.combo(); + score.perfect(); + } + + System.out.println(score.getScore() + " Combo: " + score.getCombo()); + } + }); + d.setFocusable(false); //makes it so you can't focus on the button + } + + for (int i=0; i 0 && lanes.get(i).getFailed()) { //if the note has passed into the fail boundary, removes the note from the field + score.miss(); + System.out.println(score.getScore() + " Combo: " + score.getCombo()); + + + lanes.remove(i); + frame.remove(vis.get(i)); + vis.remove(i); + + i--; + } + } + + frame.repaint(); //updates the visuals every frame + + try { + Thread.sleep(10); + } catch (InterruptedException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + /** + * Finds the note closest to the goal + * @return the location in the array list of the closest note + */ + private int getClosestNote() { + int pos = 0; + + for (int i=0; i