Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Just need help with Exercise 02. Programming language: Java BattleField code: import imagePackage.RasterImage; import java.awt.Color; import java.awt.Composite; import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics2D; import java.awt.Paint;

Just need help with Exercise 02.

Programming language: Java

BattleField code:

import imagePackage.RasterImage;

import java.awt.Color;

import java.awt.Composite;

import java.awt.Dimension;

import java.awt.Font;

import java.awt.Graphics2D;

import java.awt.Paint;

import java.awt.Shape;

import java.awt.Stroke;

import java.awt.Toolkit;

import java.awt.geom.AffineTransform;

import java.awt.geom.Point2D;

import java.io.PrintStream;

public class BattleField {

    

    public static void main(String[] args) {

        /*

         * Exercise: 

         *      Create an Array of Different Aliens, positioned according to a bounding box

         * 

         * 

         */

        final int ROWS = 3;

        final 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

        

        for (int col=0; col

            for (int row=0; 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);

        

        // 

        

        



    }

}

Exercise 01 (Familiarization of Battlefield and extension of Alien Class): Goal: Building on lab 3, the goal of this lab is to create a family of Alien classes using inheritance. In the project file for lab 4, a simplified solution to lab 3 is provided: i.e. with the final version of the three classes: Alien, Hero & BattleField. Run the BattleField class (it has a main method implemented). This will generate and display an array of alien objects (that are all instantiated using default color settings, arranged in a grid pattern on the RasterImage object). In this first task, familiarize yourself with these classes, then modify the main method in BattleField.java so that a random alien from the array "aliens" is selected, and the alien is re-coloured to be color.RED. Run your program a couple of times to ensure that this is the case. Keep in mind, after you set the alien's colour property, you will need to re-draw it (see the methods provided in the Alien class for this). Exercise 02 (modify your BattleField class): In this task, you will modify your BattleField class so that it now stores the RasterImage, Graphics2D objects, Alien array, and Hero objects as class variables (i.e. fields of the class). You should also store the size of the RasterImage as class variables. Now complete the following: 1. Create a default constructor for the BattleField class that creates a RasterImage by accepting the size 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 BattleField using the default constructor 3. Create a method called "draw" that will draw the objects in the BattleField a. Note: it is a good idea to clear the RasterImage or Graphics2D object so that the image in the window is blank, then make a series of calls to re- draw the Battlefield objects (i.e. traverse the aray and draw all the aliens, then draw the Hero) Exercise 01 (Familiarization of Battlefield and extension of Alien Class): Goal: Building on lab 3, the goal of this lab is to create a family of Alien classes using inheritance. In the project file for lab 4, a simplified solution to lab 3 is provided: i.e. with the final version of the three classes: Alien, Hero & BattleField. Run the BattleField class (it has a main method implemented). This will generate and display an array of alien objects (that are all instantiated using default color settings, arranged in a grid pattern on the RasterImage object). In this first task, familiarize yourself with these classes, then modify the main method in BattleField.java so that a random alien from the array "aliens" is selected, and the alien is re-coloured to be color.RED. Run your program a couple of times to ensure that this is the case. Keep in mind, after you set the alien's colour property, you will need to re-draw it (see the methods provided in the Alien class for this). Exercise 02 (modify your BattleField class): In this task, you will modify your BattleField class so that it now stores the RasterImage, Graphics2D objects, Alien array, and Hero objects as class variables (i.e. fields of the class). You should also store the size of the RasterImage as class variables. Now complete the following: 1. Create a default constructor for the BattleField class that creates a RasterImage by accepting the size 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 BattleField using the default constructor 3. Create a method called "draw" that will draw the objects in the BattleField a. Note: it is a good idea to clear the RasterImage or Graphics2D object so that the image in the window is blank, then make a series of calls to re- draw the Battlefield objects (i.e. traverse the aray and draw all the aliens, then draw the Hero)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

BattleFiledjava import javaioFile public class BattleField ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Business Data Communications Infrastructure Networking and Security

Authors: William Stallings, Tom Case

7th edition

133023893, 978-0133023893

More Books

Students also viewed these Programming questions

Question

Explain the process of Human Resource Planning.

Answered: 1 week ago