Question
I'm so very confused on how to do this project! Here is what I have so far, but I don't think it's correct! The prompt
I'm so very confused on how to do this project! Here is what I have so far, but I don't think it's correct! The prompt is at the bottom but basically its supposed to be a game where a large shape goes around and pics up other smaller shapes as food, as it pics up the food the shape grows larger until all the food is gone and the game ends! Any help would be greatly appreciated! thank you!!
import java.awt.Color;
import java.util.ArrayList;
import edu.princeton.cs.introcs.*;
import edu.princeton.cs.introcs.DrawListener;
public class RoamingGame implements DrawListener {
public RoamingGame() {
draw = new Draw();
draw.setCanvasSize(500, 500);
draw.setXscale(0, 500);
draw.setYscale(0, 500);
draw.addListener(this);
}
private double player1, playerPosition, playerSize;
private Color color;
private Draw draw;
private ArrayList food = new ArrayList();
public void draw()
{
draw.clear();
for (Food f : food) {
}
draw.setPenColor(StdDraw.RED);
draw.filledCircle(player1, playerPosition, playerSize);
}
@Override
public void mousePressed(double x, double y) {
// TODO Auto-generated method stub
}
@Override
public void mouseDragged(double x, double y) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(double x, double y) {
Color color = new Color(
(int)(Math.random()*255),
(int) (Math.random()*255),
(int) (Math.random()*255));
draw.setPenColor(color);
draw.filledCircle(x, y, 10);
}
@Override
public void keyTyped(char c) {
if (c == 'q') {
System.out.println("'q' pressed, quitting program...");
System.exit(0);
}
}
@Override
public void keyPressed(int keycode) {
if(keycode == 65) {
}
else if(keycode == 68) {
}
else if(keycode == 83) {
}
else if(keycode == 87) {
}
}
@Override
public void keyReleased(int keycode) {
// TODO Auto-generated method stub
}
public class Food {
private double x, y;
}
void drawFood(){
for (int x= 0; x
for(int y = 0; y
StdDraw.setPenColor(StdDraw.RED);
food.add(not sure what goes here);
}
}
}
}
In this project you'll create a simple interactive game, as demonstrated in class.
Roaming Game
The game involves moving the player around a canvas using the 'w', 'a', 's' and 'd' keys. The canvas is sprinkled with food (circles). When the player(larger circle) moves to a position with food, the player consumes the food, resulting in the player growing in size, and the food disappearing.
The game should also respond to mouse presses. If the user clicks the mouse outside the image of the player, then the player should disappear then reappear in a random, new location. If the mouse is clicked inside of the image of the player, then the player should change its color to a new, random color.
Draw / DrawListener
In this project, we will use event-driven programming, which means that we will no longer be using an StdDraw animation loop. Instead, we will use Draw and DrawListener.
Implementation
Create two classes, one called RoamingGameDriver and one called RoamingGame. RoamingGameDriver's job is only to instantiate a RoamingGame object and call its draw() method.
The RoamingGame class should have instance variables to store the position, size, and color of the player (circle). It should also have an instance variable to store the food in an arrayList and a Draw object for the canvas. RoamingGame should implement DrawListener, so it must have a definition for each of the methods in that interface. However, since we are only responding to keys typed and mouse releases, you only need to implement those two methods from the interface. (The remaining methods from DrawListener can be blank.) RoamingGame should naturally have a draw() method, which refreshes the image of the player and the food on the canvas. It should be called whenever the canvas contents change (that is, when the player has moved or changed color, or when a Food has been eaten).
RoamingGame should also have an inner class called Food used to store a food object. The version of Food just has an x-position and y-position since the food should be a fixed, small size. You have to figure out what methods the Food class must minimally have.
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