Question
Programming language is Java. I just need help from exercise 2. I don't understand how to store the RasterImage, Graphics2Dobjects, Alien array, and Hero objects
Programming language is Java.
I just need help from exercise 2. I don't understand how to store the RasterImage, Graphics2Dobjects, Alien array, and Hero objects as class variables. Also do not understand the steps, just need some clarification. Here is the explanation:
Exercise02(modify your BattleField class):In this task, you will modify your BattleFieldclass so that it now stores the RasterImage, Graphics2Dobjects, Alien array, and Hero objects as class variables(i.e. fields of the class). You should also store the size of the RasterImageas class variables.Now complete the following:
1.Create a default constructor for the BattleFieldclass that creates a RasterImageby acceptingthesize of the RasterImage(i.e. width and height) as arguments, and creates the same setup of aliens as given in the project file for lab 4.
2.Test your program with a main method that instantiates the BattleFieldusing the default constructor
3.Create a method called draw that will draw the objects in the BattleFielda.Note: it is a good idea to clear the RasterImageor Graphics2Dobject so that the image in the window is blank, then make a series of calls to re-draw the Battlefieldobjects (i.e. traverse the array and draw all the aliens, then draw the Hero)
This is the main method:
int ROWS = 3;
int COLS = 10;
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
RasterImage gameBoard = new RasterImage(640,480);
gameBoard.show(); gameBoard.setTitle("BattleField");
Graphics2D g = gameBoard.getGraphics2D();
Alien[][] aliens = new Alien[ROWS][COLS]; // 2D array of Aliens
int max = 10;
int min = 3;
int range = max-min - 1 ;
for (int col=0; col_COLS; col++) {
for (int row=0; row_ROWS; row++) {
// create and initialize position of Aliens
Point2D.Double pos = new Point2D.Double(col*60.0, row*60.0);
aliens[row][col] = new Alien(pos);
aliens[row][col].drawAlien(g); }
}
Hero shooter = new Hero(200,350);
shooter.draw(g);
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