Question
Mouse-trap game: For this assignment, you are to write a GUI program that plays a sick game. 1. Creates a GUI with a playing/drawing area.
Mouse-trap game: For this assignment, you are to write a GUI program that plays a sick game.
1. Creates a GUI with a playing/drawing area. The size of the area should be 500 by 500 pixels.
2. Your program should randomly determine a position where the mouse trap is hiding. To do this, you would generate a random number for the x position and the y position. That point (x,y) is the mouse trap. However, it isnt just the point, but any point plus or minus 10 pixels (both in the x and y coordinates). For example, if your random point was (123,345), then the trap is considered when the x position is from 103-133 AND the y position is from 335-355. (More on where the x,y position is to follow.
3. Produce a color picker (see chapter 13) to allow the user to pick a mouse droppings color.
You should default to a dark brown.
4. The game begins when the mouse pointer is over your game area. The player tries to move the mouse around the board. As the mouse moves, you should capture the events (see chapter 14) and draw the mouse droppings in the desired color (see 3) on the screen. [Edit: You should make the droppings 10x10 or an oval shape of similar size so that they show appropriately on the screen.]
5. Hint: You will not be able to see old droppings if your paint or paintComponent method invokes the super class (which you need to do). There are two ways to fix this:
a. You can save each mouse position in an ArrayList. Then after you invoke the super class in the paint/paintComponent, you re-draw each of the mouse positions by processing your ArrayList. Since youve already learned about ArrayList objects, this is perhaps the easier method.
b. Alternatively, you can use a bufferedImage object. You make your mouse markings (e.g. fillRect() in your bufferedImaage object, and then after invoking the super() method in paint/paintComponent, cause the bufferedImage to be drawn on the screen.
6. The player continues to move the mouse, trying to color the board. But, as each mouse dropping is produced, you are to determine if the mouse has sprung the trap, i.e. has entered the trap area.
7. When the mouse enters the trap, you are to put up a message box with the total number of mouse droppings.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started