Skip to content

Commit d73cc4c

Browse files
June ClarkeJune Clarke
authored andcommitted
adding day5 recipes to workshop template
1 parent 7f51b28 commit d73cc4c

4 files changed

Lines changed: 111 additions & 3 deletions

File tree

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,11 @@ bin/
22
*.class
33

44
*.class
5+
6+
bin/day1/robot/Spiral.class
7+
8+
bin/day1/robot/Spiral.class
9+
10+
bin/solutions/StarShowSolution.class
11+
12+
bin/solutions/TriangleShellSolution.class
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package day1.robot;
1+
package day5;
22
import org.jointheleague.graphical.robot.Robot;
33

44
/*** Teacher's note ***/
@@ -16,7 +16,7 @@ public static void main(String[] args) {
1616

1717
// *15. Make some adjustments to see what other kinds of shapes you can make.
1818

19-
// 1. Show the robot
19+
// 1. Make a new robot, and set it's pen down.
2020

2121
// 12. Set the robot speed to 10
2222

src/day5/ScaryMaze.java

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package day5;
2+
3+
import java.applet.AudioClip;
4+
import java.awt.Dimension;
5+
6+
import java.awt.Graphics;
7+
import java.awt.Robot;
8+
import java.awt.event.MouseEvent;
9+
import java.awt.event.MouseMotionListener;
10+
import java.awt.image.BufferedImage;
11+
12+
import javax.imageio.ImageIO;
13+
import javax.swing.JApplet;
14+
import javax.swing.JFrame;
15+
import javax.swing.JPanel;
16+
import javax.swing.SwingUtilities;
17+
18+
public class ScaryMaze extends JPanel implements Runnable, MouseMotionListener {
19+
20+
BufferedImage maze;
21+
final int frameWidth = 600;
22+
final int frameHeight = 400;
23+
24+
ScaryMaze() throws Exception {
25+
//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+
//2. set the mouse pointer to the start of your maze using:
28+
//new Robot().mouseMove(xPosition, yPosition)
29+
30+
//3. add a mouse motion listener using:
31+
//addMouseMotionListener(this)
32+
33+
}
34+
35+
@Override
36+
public void mouseMoved(MouseEvent e) {
37+
int mouseX = e.getX();
38+
int mouseY = e.getY();
39+
int mouseColor = maze.getRGB(mouseX, mouseY);
40+
//4. print the mouseColor variable to see what color the mouse is touching
41+
42+
//5. make a variable to hold the background color.
43+
44+
//6. if the mouse falls off the path (if it is on the background)
45+
46+
// call the scare method
47+
48+
//10. if the mouse is on the end color
49+
50+
// pop up a message to tell them they won
51+
52+
}
53+
54+
private void scare() {
55+
System.out.println("BOO!");
56+
//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"));
58+
59+
//8. play the scary sound. Hint: type "sound" and then a period.
60+
61+
//9. drop an image into your day5 package, and use the showScaryImage method to scare your victim!
62+
63+
}
64+
65+
private void showScaryImage(String imageName) {
66+
try {
67+
maze = ImageIO.read(getClass().getResource(imageName));
68+
} catch (Exception e) {
69+
System.err.println("Couldn't find this image: " + imageName);
70+
}
71+
repaint();
72+
}
73+
74+
public static void main(String[] args) throws Exception {
75+
SwingUtilities.invokeLater(new ScaryMaze());
76+
}
77+
78+
@Override
79+
public void run() {
80+
JFrame frame = new JFrame("June's Scary Maze");
81+
frame.add(this);
82+
setPreferredSize(new Dimension(frameWidth, frameHeight));
83+
frame.pack();
84+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
85+
frame.setResizable(false);
86+
frame.setVisible(true);
87+
}
88+
89+
@Override
90+
public void paintComponent(Graphics g) {
91+
g.drawImage(maze, 0, 0, null);
92+
}
93+
94+
@Override
95+
public void mouseDragged(MouseEvent e) {}
96+
97+
}
98+
99+
100+
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package day1.robot;
1+
package day5;
22

33
import org.jointheleague.graphical.robot.Robot;
44

0 commit comments

Comments
 (0)