Skip to content

Commit 292abd6

Browse files
committed
Quick corrections
Added printing methods to music --> also music now toggles Signed-off-by: Mohamed Omar <REDACTED-PRIVATE>
1 parent 25cbc41 commit 292abd6

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/com/redomar/game/HelpMenu.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,14 @@
77
import javax.swing.*;
88

99
/**
10-
* Created with IntelliJ IDEA.
11-
* User: Gagandeep Bali
12-
* Date: 7/1/14
13-
* Time: 9:44 AM
14-
* To change this template use File | Settings | File Templates.
10+
* Credit to Gagandeep Bali @ stackoverflow
1511
*/
1612
public class HelpMenu {
1713

1814
private MyPanel contentPane;
1915

2016
private void displayGUI() {
21-
JFrame frame = new JFrame("Image Example");
17+
JFrame frame = new JFrame("Help Menu");
2218
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
2319

2420
contentPane = new MyPanel();
@@ -34,7 +30,7 @@ private class MyPanel extends JPanel {
3430

3531
private BufferedImage image;
3632

37-
public MyPanel() {
33+
private MyPanel() {
3834
try {
3935
image = ImageIO.read(MyPanel.class.getResource("/controls/controls.png"));
4036
} catch (IOException ioe) {
@@ -55,12 +51,7 @@ protected void paintComponent(Graphics g) {
5551
}
5652

5753
public static void run() {
58-
Runnable runnable = new Runnable() {
59-
@Override
60-
public void run() {
61-
new HelpMenu().displayGUI();
62-
}
63-
};
54+
Runnable runnable = () -> new HelpMenu().displayGUI();
6455
EventQueue.invokeLater(runnable);
6556
}
6657
}

src/com/redomar/game/InputHandler.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class InputHandler implements KeyListener {
1919
private Printing print = new Printing();
2020
private int map;
2121
private boolean ignoreInput = false;
22+
private boolean toggleMusic = false;
2223
private PopUp popup = new PopUp();
2324

2425
public InputHandler(Game game) {
@@ -70,11 +71,18 @@ private void toggleKey(int keyCode, boolean isPressed) {
7071
}
7172

7273
if (keyCode == KeyEvent.VK_M) {
73-
Game.getBackgroundMusic().play();
74+
if(!toggleMusic){
75+
Game.getBackgroundMusic().play();
76+
print.print("Playing Music", PrintTypes.MUSIC);
77+
toggleMusic = true;
78+
}
7479
}
7580

7681
if (keyCode == KeyEvent.VK_COMMA) {
7782
Game.getBackgroundMusic().stop();
83+
if(toggleMusic)
84+
print.print("Stopping Music", PrintTypes.MUSIC);
85+
toggleMusic = false;
7886
}
7987

8088

0 commit comments

Comments
 (0)