Skip to content

Commit cc4998b

Browse files
wiwi
authored andcommitted
Final Day :(
1 parent 09c6232 commit cc4998b

5 files changed

Lines changed: 18 additions & 9 deletions

File tree

src/day5/1281923869157.jpg

38.8 KB
Loading
102 KB
Binary file not shown.

src/day5/Scary maze.jpg

25.9 KB
Loading

src/day5/ScaryMaze.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,24 @@
1212
import javax.imageio.ImageIO;
1313
import javax.swing.JApplet;
1414
import javax.swing.JFrame;
15+
import javax.swing.JOptionPane;
1516
import javax.swing.JPanel;
1617
import javax.swing.SwingUtilities;
1718

1819
public class ScaryMaze extends JPanel implements Runnable, MouseMotionListener {
1920

2021
BufferedImage maze;
21-
final int frameWidth = 600;
22-
final int frameHeight = 400;
22+
final int frameWidth = 800;
23+
final int frameHeight = 600;
2324

2425
ScaryMaze() throws Exception {
2526
//1. Use this online tool to make a maze image and drop it into your day5 package: http://pixlr.com/editor/
26-
maze = ImageIO.read(getClass().getResource("maze.png"));
27+
maze = ImageIO.read(getClass().getResource("Scary maze.jpg"));
2728
//2. set the mouse pointer to the start of your maze using:
28-
//new Robot().mouseMove(xPosition, yPosition)
29+
new Robot().mouseMove(17,303);
2930

3031
//3. add a mouse motion listener using:
31-
//addMouseMotionListener(this)
32+
addMouseMotionListener(this);
3233

3334
}
3435

@@ -38,27 +39,35 @@ public void mouseMoved(MouseEvent e) {
3839
int mouseY = e.getY();
3940
int mouseColor = maze.getRGB(mouseX, mouseY);
4041
//4. print the mouseColor variable to see what color the mouse is touching
42+
System.out.println(mouseColor);
4143

4244
//5. make a variable to hold the background color.
45+
int backgroundColor = -1230536;
46+
int finishColor = -16711699;
4347

4448
//6. if the mouse falls off the path (if it is on the background)
45-
49+
if(mouseColor==backgroundColor){
50+
scare();
51+
}
4652
// call the scare method
4753

4854
//10. if the mouse is on the end color
49-
55+
if(mouseColor==finishColor){
56+
JOptionPane.showMessageDialog(null, "congrats. you finished the SCARY MAZE!");
57+
}
5058
// pop up a message to tell them they won
5159

5260
}
5361

5462
private void scare() {
5563
System.out.println("BOO!");
5664
//7. find a scary sound and put it in the day5 package where you put your maze picture. You can find a sound on freesound.org. Log in as leagueofamazing/code4life.
57-
//AudioClip sound = JApplet.newAudioClip(getClass().getResource("scream.wav"));
65+
AudioClip sound = JApplet.newAudioClip(getClass().getResource("scare.wav"));
5866

5967
//8. play the scary sound. Hint: type "sound" and then a period.
60-
68+
sound.play();
6169
//9. drop an image into your day5 package, and use the showScaryImage method to scare your victim!
70+
showScaryImage("1281923869157.jpg");
6271

6372
}
6473

src/day5/scare.wav

84.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)