-
Notifications
You must be signed in to change notification settings - Fork 0
/
PanelPlay.java
827 lines (699 loc) · 27.2 KB
/
PanelPlay.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
import javax.sound.sampled.*;
import javax.swing.*;
import javax.swing.border.LineBorder;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
@SuppressWarnings("serial")
// kill VSCode errors (does nothing in jGRASP)
/**
* This class can be externally called from a static function and can run in a separate thread
*/
class RunAudio implements Runnable {
/**
* The object containing the audio stream within the RunAudio class.
*/
private Clip music;
/**
* Creates a RunAudio object, takes a Clip object and puts it in a class variable.
*/
public RunAudio(Clip music) {
this.music = music;
}
/**
* Starts the audio stream (music) if it is not already running.
*/
public void run() {
if (!music.isRunning())
music.start();
}
}
/**
* The panel for the actual gameplay of JMania.
*/
public class PanelPlay extends JPanel implements ActionListener {
/**
* The array size of the arrow coordinate arrays.
* Consequently, this is the max number of arrows which can be in a song.
*/
private int arraySize = 1000;
/**
* The dimensions of the panel as integers.
*/
private int width, height;
/**
* The x-coordinates (horizontal position) for the arrows.
*/
private int[] x = new int[arraySize];
/**
* The y-coordinates (vertical position) for the arrows.
*/
private int[] y = new int[arraySize];
/**
* The number of pixels the y-coordinate changes per tick (each time the timer runs)
*/
private int velY = 1;
/**
* The owner of the JFrame.
*/
private Window owner;
/**
* The path where sprites are located.
*/
private String arrowPath = Driver.projectPath + "/assets/images/";
/**
* The main timer that updates gameplay information such as graphics, timing, judgement, etc.
*/
private Timer tm = new Timer(1, this);
/**
* The thread that plays the audio stream (music).
*/
private Thread audioThread;
/**
* A list of scores separated by each individual arrow.
* Stored as integers, such that 3 is perfect, 2 is great, 1 is good, and 0 is a miss.
*/
public List<Integer> scores = new ArrayList<Integer>();
/**
* A constant specifying a left arrow in a simfile.
*/
private final String left = "1000";
/**
* A constant specifying a downwards arrow in a simfile.
*/
private final String down = "0100";
/**
* A constant specifying an upwards arrow in a simfile.
*/
private final String up = "0010";
/**
* A constant specifying a right arrow in a simfile.
*/
private final String right = "0001";
/**
* A constant specifying no arrows pressed in a simfile.
*/
private final String notPressed = "0000";
/**
* A string containing the filename for the image of an inactive left arrow.
*/
private String leftDefault = "inactiveLeft.png";
/**
* A string containing the filename for the image of an inactive right arrow.
*/
private String rightDefault = "inactiveRight.png";
/**
* A string containing the filename for the image of an inactive downwards arrow.
*/
private String downDefault = "inactiveDown.png";
/**
* A string containing the filename for the image of an inactive upwards arrow.
*/
private String upDefault = "inactiveUp.png";
/**
* A long value used to store the current time on the computer, to keep track of when to draw a frame.
* Used in conjunction with temptime to be updated when there is an adequate difference between the two.
*/
private long milltime = System.currentTimeMillis();
/**
* A long value used to store the current time on the computer, to keep track of when to draw a frame.
* Used in conjunction with milltime to be updated until there is an adequate difference between the two.
*/
private long temptime;
/**
* An integer used to count milliseconds until the progress bar should be updated.
*/
private int progressBarUpdate = 0;
/**
* Used to check if the song has started, and should only turn on once.
*/
private boolean songstarted = false;
/**
* The topmost arrow to be destroyed (as an integer, based on note index).
*/
private int nextArrow;
/**
* A counter determining when to initialize a new arrow.
*/
private int timeCount;
/**
* An integer used as a multiplier for the time to initialize a new arrow.
*/
private int newArrowTime = 225;
/**
* A string set to the value of the arrow key that is pressed, used to check which arrow should be destroyed.
*/
private String pressed = notPressed;
/**
* The default arrow sprite objects.
*/
private ImageIcon inactiveLeft, inactiveDown, inactiveUp, inactiveRight;
/**
* A list of all the arrows as sprites.
*/
private ImageIcon active[] = new ImageIcon[arraySize];
/**
* The default arrow sprite objects.
*/
public Simfile smf;
/**
* List of times when each note should appear, based on Simfile.NotesTime().
*/
List<List<String>> timestamp;
/**
* The current note which is to appear, based on order of time.
*/
public int noteindex = 0;
/**
* The object used to store the audio file being used.
*/
public File file;
/**
* The audio stream as a Clip object which can be directly played and accessed.
*/
public Clip music;
/**
* The current position of the song in microseconds, updated within the main timer
*/
private double micro;
/**
* The label that displays perfects, greats, goods, and misses.
*/
private JLabel judgeLabel = new JLabel();
/**
* The progress bar which displays how far you are in the song.
*/
private JProgressBar progressBar = new JProgressBar(0, 100);
/**
* The length of the audio stream (music) in microseconds.
*/
private long currentSongLength;
/**
* The actual value determining how far you are in the song.
*/
private int songProgress;
/**
* The panel containing the accuracy and score labels.
*/
private JPanel statsPanel = new JPanel();
/**
* The label which displays how accurately you pressed the arrows, as a percentage.
*/
private JLabel accuracyLabel = new JLabel();
/**
* The label which displays a score based on how accurately and how well you pressed the arrows.
*/
private JLabel scoreLabel = new JLabel();
public static Color colorPerfect = new Color(56, 142, 60);
public static Color colorGreat = new Color(245, 124, 0);
public static Color colorGood = new Color(251, 192, 45);
public static Color colorMiss = new Color(211, 47, 47);
/**
* A function that adds to the note index variable, in case variables must be static within a function.
*/
public int addnoteindex() {
noteindex++;
return 1;
}
/**
* Creates a PanelPlay object to display the actual game.
*/
public PanelPlay(Window owner, int width, int height, Simfile simfile) {
initTopLayout();
initStatsLayout();
initProgressBar();
// Catch all other exceptions
try {
this.file = new File(simfile.AudioFile());
if (file.exists()) {
AudioInputStream stream = AudioSystem.getAudioInputStream(file);
this.music = AudioSystem.getClip();
music.open(stream);
adjustSongVolume();
currentSongLength = music.getMicrosecondLength();
}
}
/******************************************
* These are all defined in the Simfile class
******************************************/ catch (IOException e) {
throw new RuntimeException("There was an I/O error reading the audio file.");
} catch (LineUnavailableException e) {
throw new RuntimeException("We messed up, no line is available for the sound.");
} catch (UnsupportedAudioFileException e) {
throw new RuntimeException(
"This type of audio file is unsupported. Only uncompressed formats are supported.");
}
// Catch the error thrown by PanelPlay
try {
smf = simfile;
timestamp = smf.NotesTime();
} catch (Exception f) {
f.printStackTrace();
}
this.owner = owner;
this.width = width;
this.height = height;
y[noteindex] = 800; // starts first arrow at y-coordinate 800 (80 pixels below bottom of screen)
// key bindings
int arrowMap = JComponent.WHEN_IN_FOCUSED_WINDOW;
InputMap imap = this.getInputMap(arrowMap);
KeyStroke leftKey = KeyStroke.getKeyStroke("LEFT");
KeyStroke rightKey = KeyStroke.getKeyStroke("RIGHT");
KeyStroke upKey = KeyStroke.getKeyStroke("UP");
KeyStroke downKey = KeyStroke.getKeyStroke("DOWN");
KeyStroke releaseLeft = KeyStroke.getKeyStroke("released LEFT");
KeyStroke releaseRight = KeyStroke.getKeyStroke("released RIGHT");
KeyStroke releaseUp = KeyStroke.getKeyStroke("released UP");
KeyStroke releaseDown = KeyStroke.getKeyStroke("released DOWN");
imap.put(leftKey, "loadLeft");
imap.put(rightKey, "loadRight");
imap.put(downKey, "loadDown");
imap.put(upKey, "loadUp");
imap.put(releaseLeft, "releaseLeft");
imap.put(releaseRight, "releaseRight");
imap.put(releaseUp, "releaseUp");
imap.put(releaseDown, "releaseDown");
ActionMap amap = this.getActionMap();
amap.put("loadLeft", new ArrowAction(left));
amap.put("loadRight", new ArrowAction(right));
amap.put("loadDown", new ArrowAction(down));
amap.put("loadUp", new ArrowAction(up));
amap.put("releaseLeft", new ReleaseAction(left));
amap.put("releaseRight", new ReleaseAction(right));
amap.put("releaseUp", new ReleaseAction(up));
amap.put("releaseDown", new ReleaseAction(down));
owner.requestFocus();
}
/**
* Changes the song's volume (loudness) based on user-defined settings
*/
private void adjustSongVolume() throws IOException {
Properties gameProps = new Properties();
gameProps.load(new FileInputStream(Driver.projectPath + "/app.properties"));
float songVolume = Float.parseFloat(gameProps.getProperty("songVolume"));
FloatControl gainControl = (FloatControl) music.getControl(FloatControl.Type.MASTER_GAIN);
float clipRange = gainControl.getMaximum() - gainControl.getMinimum();
clipRange = (float) (clipRange - (clipRange*0.05)); // Prevents volume from being too low
float clipVolStep = clipRange / 100;
float finalVolume = gainControl.getMinimum() + (clipVolStep * songVolume);
gainControl.setValue(finalVolume);
}
/**
* Stops the game by ending the reading of the simfile and not reading the audio
*/
private void endRound() {
// Stops reading the simfile
tm.stop();
audioThread.interrupt();
// Stops playing the song
songstarted = false;
music.stop();
music.flush();
// Sets the window to show PanelSelect
}
/**
* Initializes the back button and judgement labels.
*/
private void initTopLayout() {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
setBackground(Driver.bgColor);
// Add back button to panel
PanelBack topLayout = new PanelBack();
topLayout.removeAll();
topLayout.setLayout(new BoxLayout(topLayout, BoxLayout.X_AXIS));
topLayout.setBackground(new Color(0, 0, 0, 0)); // make transparent
topLayout.add(Box.createRigidArea(new Dimension(20, 60)));
topLayout.add(topLayout.backButton);
topLayout.backButton.addActionListener(event -> {
endRound();
// SwingUtilities.invokeLater(() -> owner.showView(new PanelSelect(owner, Driver.width, Driver.height)));
SwingUtilities.invokeLater(() -> owner.showView(new PanelEnd(owner, Driver.width, Driver.height, this.calcAccuracy(), this.scores)));
});
topLayout.backButton.setText(" Exit");
topLayout.add(Box.createHorizontalGlue());
judgeLabel.setFont(Driver.fontBold.deriveFont(28f));
topLayout.add(judgeLabel);
topLayout.add(Box.createRigidArea(new Dimension(20, 60)));
topLayout.setVisible(true);
add(topLayout);
}
/**
* Initializes the layout for the accuracy and score labels
*/
private void initStatsLayout() {
add(Box.createRigidArea(new Dimension(0, 50)));
statsPanel.setLayout(new BoxLayout(statsPanel, BoxLayout.Y_AXIS));
statsPanel.setBackground(new Color(0, 0, 0, 0));
Dimension statDimension = new Dimension(Driver.width, 100);
JPanel accuracyPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 30, 10));
accuracyPanel.setBackground(Driver.bgColor);
accuracyPanel.setMaximumSize(statDimension);
accuracyPanel.setBackground(new Color(0, 0, 0, 0));
accuracyLabel.setText("Accuracy: ");
accuracyLabel.setFont(Driver.fontRegular.deriveFont(24f));
accuracyPanel.add(accuracyLabel);
JPanel scorePanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 30, 0));
scorePanel.setBackground(Driver.bgColor);
scorePanel.setMaximumSize(statDimension);
scorePanel.setBackground(new Color(0, 0, 0, 0));
scoreLabel.setText("Score: ");
scoreLabel.setFont(Driver.fontRegular.deriveFont(24f));
scorePanel.add(scoreLabel);
statsPanel.add(accuracyPanel);
statsPanel.add(scorePanel);
add(statsPanel);
}
/**
* Initializes the progress bar on the bottom of the screen, determining how far you have gotten in the song.
*/
private void initProgressBar() {
add(Box.createVerticalGlue());
progressBar.setPreferredSize(new Dimension(this.getWidth(), 20));
progressBar.setForeground(new Color(243, 66, 53));
progressBar.setBorder(new LineBorder(Color.BLUE));
progressBar.setValue(0);
progressBar.setStringPainted(true);
progressBar.setFont(Driver.standardFont);
add(progressBar);
}
/**
* A class to handle keypresses and compare to arrows
*/
private class ArrowAction extends AbstractAction {
/**
* A string indicating what arrow key is being pressed
*/
private String direction;
/**
* Creates an ArrowAction object and puts the arrow key direction into a class variable
*/
public ArrowAction(String direction) {
this.direction = direction;
}
/**
* Displays what arrow is being pressed (by adding brightness to the judgement arrows) based on direction
*/
public void actionPerformed(ActionEvent e) {
switch (direction) {
case left:
leftDefault = "pressedLeft.png";
break;
case right:
rightDefault = "pressedRight.png";
break;
case down:
downDefault = "pressedDown.png";
break;
case up:
upDefault = "pressedUp.png";
break;
}
pressed = direction;
}
}
/**
* A class to handle releasing of keypresses and compare to arrows
*/
private class ReleaseAction extends AbstractAction {
/**
* A string indicating what arrow key is being pressed
*/
private String direction;
/**
* Creates an ReleaseAction object and puts the arrow key direction into a class variable
*/
public ReleaseAction(String direction) {
this.direction = direction;
}
/**
* Displays what arrow is being pressed (by adding brightness to the judgement arrows) based on direction
*/
public void actionPerformed(ActionEvent e) {
switch (direction) {
case left:
leftDefault = "inactiveLeft.png";
break;
case right:
rightDefault = "inactiveRight.png";
break;
case down:
downDefault = "inactiveDown.png";
break;
case up:
upDefault = "inactiveup.png";
break;
}
}
}
/**
* The function that runs based on the timer.
* Graphics and music are mostly handled within this function.
*/
public void actionPerformed(ActionEvent e) {
timeCount++;
//Ends game if music finishes playing
if (!music.isRunning() && music.getMicrosecondPosition() > 0) {
endRound();
SwingUtilities.invokeLater(() -> owner.showView(new PanelEnd(owner, Driver.width, Driver.height, this.calcAccuracy(), this.scores)));
}
// animate all existing arrows
for (int start = noteindex; start > 0; start--) {
y[start] -= velY;
if (y[start] <= -80 && active[start] != null) {
int judge = this.Judgement(smf, nextArrow, y[nextArrow]);
updateResults(judge);
this.addNote(judge);
active[start] = null;
nextArrow++;
}
}
for (int start = 1; start < noteindex; start++) {
if (active[start] != null) {
nextArrow = start;
break;
}
}
// if an arrow key is pressed and the topmost arrow is the corresponding arrow,
// destroy it.
if (y[nextArrow] < 720 && active[nextArrow] != null) {
switch (pressed) {
case left:
if (active[nextArrow].getDescription() == "left") {
int judge = this.Judgement(smf, nextArrow, y[nextArrow]);
updateResults(judge);
if (judge > 0) {
active[nextArrow] = null;
this.addNote(judge);
nextArrow++;
}
}
break;
case down:
if (active[nextArrow].getDescription() == "down") {
int judge = this.Judgement(smf, nextArrow, y[nextArrow]);
updateResults(judge);
if (judge > 0) {
active[nextArrow] = null;
this.addNote(judge);
nextArrow++;
}
}
break;
case up:
if (active[nextArrow].getDescription() == "up") {
int judge = this.Judgement(smf, nextArrow, y[nextArrow]);
updateResults(judge);
if (judge > 0) {
active[nextArrow] = null;
this.addNote(judge);
nextArrow++;
}
}
break;
case right:
if (active[nextArrow].getDescription() == "right") {
int judge = this.Judgement(smf, nextArrow, y[nextArrow]);
updateResults(judge);
if (judge > 0) {
active[nextArrow] = null;
this.addNote(judge);
nextArrow++;
}
}
break;
case notPressed:
break;
}
pressed = notPressed;
}
temptime = System.currentTimeMillis();
if (temptime - milltime >= 16) {
if (progressBarUpdate >= 32) { // Runs every ~0.5 seconds
// Updates the progress bar
songProgress = (int) (micro / this.currentSongLength * 100);
progressBar.setValue(songProgress);
progressBarUpdate = 0;
} else {
progressBarUpdate++;
}
repaint();
milltime = temptime;
}
// Redraw the canvas
if (!songstarted) {
audioThread = new Thread(new RunAudio(music));
audioThread.start();
songstarted = true;
}
micro = (double) music.getMicrosecondPosition();
double second = micro / 1000000;
if (noteindex < smf.NoteCount()) { // So that the game doesn't run out of notes
if (second > Double.parseDouble(timestamp.get(noteindex).get(0)) - 1.0) {
loadArrow(timestamp.get(noteindex).get(1));
y[noteindex] = 800;
addnoteindex();
// System.out.println(Double.toString(second));
// System.out.println(timestamp.get(noteindex).get(0));
}
}
}
/**
* The function that handles drawing the graphics on to the screen.
*/
public void paintComponent(Graphics g) {
// background
super.paintComponent(g);
g.setColor(Driver.bgColor);
g.fillRect(0, 0, width, height);
loadStaticSprites(g); // draw default arrows
// redraw every arrow with their updated y-coord values (the real animation)
if (noteindex >= 1) {
for (int start = noteindex; start > 0; start--) {
if (active[start] != null) {
g.drawImage(active[start].getImage(), x[start], y[start], null, null);
}
}
}
tm.start(); // start animation
}
/**
* Loads images of arrows into ImageIcon variables and draws them on the screen.
*/
private void loadStaticSprites(Graphics g) {
inactiveDown = new ImageIcon(arrowPath + downDefault);
inactiveLeft = new ImageIcon(arrowPath + leftDefault);
inactiveUp = new ImageIcon(arrowPath + upDefault);
inactiveRight = new ImageIcon(arrowPath + rightDefault);
g.drawImage(inactiveLeft.getImage(), 425, 100, null, null);
g.drawImage(inactiveDown.getImage(), 525, 100, null, null);
g.drawImage(inactiveUp.getImage(), 625, 100, null, null);
g.drawImage(inactiveRight.getImage(), 725, 100, null, null);
}
/**
* Loads new arrows on the screen based on the direction that it should be in (which is passed into it).
*/
private void loadArrow(String direction) {
switch (direction) {
case left:
active[noteindex] = new ImageIcon(arrowPath + "activeLeft.png");
active[noteindex].setDescription("left");
x[noteindex] = 425;
break;
case down:
active[noteindex] = new ImageIcon(arrowPath + "activeDown.png");
active[noteindex].setDescription("down");
x[noteindex] = 525;
break;
case up:
active[noteindex] = new ImageIcon(arrowPath + "activeUp.png");
active[noteindex].setDescription("up");
x[noteindex] = 625;
break;
case right:
active[noteindex] = new ImageIcon(arrowPath + "activeRight.png");
active[noteindex].setDescription("right");
x[noteindex] = 725;
break;
case notPressed:
break;
}
}
/**
* Determines how accurate the pressed arrow is compared to when it should be pressed (through y-coordinates of arrows).
* Returns 3 for perfect, 2 for great, 1 for good, and 0 for a miss.
*/
public int Judgement(Simfile sim, int notenum, int y) {
int diff = Math.abs(y - 80); // get difference between the y-coordinate positions when pressed and the actual arrow on screen
if (diff <= 30) // perfect
{
return 3;
} else if (diff <= 60) // great
{
return 2;
} else if (diff <= 90) // good
{
return 1;
} else // miss
{
return 0;
}
}
/**
* Calculates the score by finding the sum of the Judgement scores.
*/
public int calcScore() {
int totalscore = 0;
for (Integer s : scores)
totalscore += s;
return totalscore;
}
/**
* Calculates the accuracy by dividing calcScore() by the maximum possible score (the amount of arrows multiplied by 3, as 3 is perfect).
* Returns a double which is a percentage.
*/
public double calcAccuracy() {
int totalscore = calcScore();
return (double) totalscore / ((double) this.scores.size() * 3.0);
}
/**
* Adds an arrow's score to the total list of scores.
*/
public void addNote(int score) {
scores.add(score);
}
/**
* Updates the judgement text, displaying whether the player got a perfect, great, good, or miss on the most recently pressed arrow.
*/
public void updateResults(int judge) {
switch (judge) {
case 3:
judgeLabel.setText("PERFECT");
judgeLabel.setForeground(colorPerfect);
break;
case 2:
judgeLabel.setText("GREAT");
judgeLabel.setForeground(colorGreat);
break;
case 1:
judgeLabel.setText("GOOD");
judgeLabel.setForeground(colorGood);
break;
case 0:
judgeLabel.setText("MISS");
judgeLabel.setForeground(colorMiss);
break;
}
double roundedAccuracy = Math.round(this.calcAccuracy() * 10000.0) / 100.0;
accuracyLabel.setText("Accuracy: " + roundedAccuracy + "%");
scoreLabel.setText("Score: " + this.calcScore());
}
}