Introduction: In this project, you will be creating a basic video game using the knowledge of Graphical User Interfaces (GUI) and Object-Oriented programming you have learned so far. You will be giv

Swamped with your writing assignments? We'll take the academic weight off your shoulders. We complete all our papers from scratch. You can get a plagiarism report upon request just to confirm.


Order a Similar Paper Order a Different Paper

Introduction:

In this project, you will be creating a basic video game using the knowledge of Graphical User Interfaces (GUI) and Object-Oriented programming you have learned so far. You will be given starter code to assist in collision detection as well as a basic framework for the video game. Your goal is to design and fill out the remaining pieces to make the game functional. Furthermore, there will be extra credit assigned based on creativity. That is, if you put in the additional time and effort to create a unique game, you can earn an additional 30 points of extra credit. This will give you an opportunity to improve your projects category grade if you wish to do it. The uniqueness can come from special rules, graphics, etc.

Video Game:

Develop a GUI to contain the video game painting and allow the user to play the game. A minimal version of this is displayed below. There are two types of enemies, SmallEnemy and BigEnemy, as well as a Missile to hit the enemies. A JLabel keeps track of the score at the top left of the JFrame. Next, a JButton at the bottom of the JFrame allows us to shoot a Missile. Finally, a Turret is painted at the bottom center of the JFrame to act as the vessel to shoot a Missile.

More details are in the attached document.

/////////////////////////////////////////////////////////////////////////////////////////////////

here’s the starter code:

Tester.java:

import java.awt.BorderLayout;

import java.awt.GraphicsEnvironment;

import java.awt.Point;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

/**

* The driver class for Project 4.

*

*/

@SuppressWarnings(“serial”)

public class Tester extends JFrame {

private static final int WINDOW_WIDTH = 700;

private static final int WINDOW_HEIGHT = 500;

private int score;

private int timer;

private int missilesFired = 0;

private JLabel scoreLabel;

private JButton fireButton;

private GamePanel panel;

/**

* Default constructor to control the game.

*/

public Tester() {

// Setup the initial JFrame elements

setTitle(“Ball Destruction!”);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setSize(WINDOW_WIDTH,WINDOW_HEIGHT);

setLayout(new BorderLayout());

panel = new GamePanel();

add(panel, BorderLayout.CENTER);

centerFrame(this);

setVisible(true);

setTimer();

// Add the JButton for shooting the bullet

fireButton = new JButton(“Shoot The Enemy!”);

fireButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

panel.addMissile();

missilesFired++;

}

});

add(fireButton, BorderLayout.SOUTH);

// Add the JLabel for the score

scoreLabel = new JLabel();

add(scoreLabel, BorderLayout.NORTH);

}

/**

* This method is called to start the video game which then

* calls the infinite game loop for the game.

*/

public void start() {

gameLoop();

}

/**

* Method contains the game loop to move enemies, manage score,

* and check if the game is finished.

*/

public void gameLoop() {

// Game loop

while(true) {

pauseGame();

panel.detectCollision();

score = panel.getTotalScore();

scoreLabel.setText(Integer.toString(score));

panel.move();

panel.repaint();

if(missilesFired > 10) {

if(score >= 800){

JOptionPane.showMessageDialog(null, “You Win!”, “Game Finished Message”,

JOptionPane.INFORMATION_MESSAGE);

System.exit(0);

} else {

JOptionPane.showMessageDialog(null, “You Lose!”, “Game Finished Message”,

JOptionPane.INFORMATION_MESSAGE);

System.exit(0);

}

}

if(timer == 300) {

panel.addEnemy();

setTimer();

}

timer++;

}

}

/**

* Pauses the thread for 30ms to control the

* speed of the animations.

*/

public void pauseGame() {

try {

Thread.sleep(30);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

/**

* Method centers the frame in the middle of the screen.

*

* @param frame to center with respect to the users screen dimensions.

*/

public void centerFrame(JFrame frame) {

int width = frame.getWidth();

int height = frame.getHeight();

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

Point center = ge.getCenterPoint();

int xPosition = center.x – width/2, yPosition = center.y – height/2;

frame.setBounds(xPosition, yPosition, width, height);

frame.validate();

}

/**

* Randomly assign a value to determine how soon a new Enemy should

* be created.

*/

public void setTimer() {

timer = (int)(Math.random() * 100);

}

/**

* The main method to execute the program.

*

* @param args Any inputs to the program when it starts.

*/

public static void main(String[] args) {

Tester main = new Tester();

main.start();

}

}

/////////////////////////////////////////////////////////////////////////

GamePanel.java:

import java.awt.Color;

import java.awt.Graphics;

import java.awt.Rectangle;

import java.util.ArrayList;

import javax.swing.JPanel;

/**

* This class contains the paintable objects such as the enemies,

* turret, and missile. It also keeps track of the

*

*/

public class GamePanel extends JPanel {

/**

* Paints the enemies and missiles when called and also paints

* the background of the panel White.

*/

@Override

public void paintComponent(Graphics g) {

super.paintComponent(g);

g.setColor(Color.white);

g.fillRect(0, 0, this.getWidth(), this.getHeight());

}

/**

* Method detects the collision of the missile and all the enemies. This is done by

* drawing invisible rectangles around the enemies and missiles, if they intersect, then

* they collide.

*/

public void detectCollision() {

// Create temporary rectangles for every enemy and missile on the screen currently

for(int i = 0; i < enemyList.size(); i++) {

Rectangle enemyRec = enemyList.get(i).getBounds();

for(int j = 0; j < missileList.size(); j++) {

Rectangle missileRec = missileList.get(j).getBounds();

if(missileRec.intersects(enemyRec)) {

(enemyList.get(i)).processCollision(enemyList, i);

missileList.remove(j);

if(enemyList.get(i) instanceof BigEnemy) {

totalScore += 100;

} else {

totalScore += 150;

}

}

}

}

}

}

Introduction: In this project, you will be creating a basic video game using the knowledge of Graphical User Interfaces (GUI) and Object-Oriented programming you have learned so far. You will be giv
Introduction: In this project, you will be creating a basic video game using the knowledge of Graphical User Interfaces (GUI) and Object-Oriented programming you have learned so far. You will be given starter code to assist in collision detection as well as a basic framework for the video game. Your goal is to design and fill out the remaining pieces to make the game functional. Furthermore, there will be extra credit assigned based on creativity. That is, if you put in the additional time and effort to create a unique game, you can earn an additional 30 points of extra credit. This will give you an opportunity to improve your projects category grade if you wish to do it. The uniqueness can come from special rules, graphics, etc. Video Game: Develop a GUI to contain the video game painting and allow the user to play the game. A minimal version of this is displayed below. There are two types of enemies, SmallEnemy and BigEnemy, as well as a Missile to hit the enemies. A JLabel keeps track of the score at the top left of the JFrame. Next, a JButton at the bottom of the JFrame allows us to shoot a Missile. Finally, a Turret is painted at the bottom center of the JFrame to act as the vessel to shoot a Missile. Game Rules: The minimal ruleset of the game is simple. You press the button to shoot a Missile. If you hit a BigEnemy, then you get 100 points. If you hit a SmallEnemy, then you get 150 points. You can shoot a total of 10 Missiles and then the game ends. If your score is 800 or above, you win, else you lose. Note that these are suggested rules and you may create your own ruleset. Class Files: The classes needed to complete this project are listed below. Take note of the portions of code that are provided to you as starter code. Also, for the extra credit, you are allowed to modify these. Please read the Extra Credit Hint below. Tester (PROVIDED) – This class inherits JFrame and contains all the information necessary to display the GUI and to have the game infinitely operate. a. Instance Properties: i. private static final int WINDOW_WIDTH – The width of the JFrame. ii. private static final int WINDOW_HEIGHT – The height of the JFrame. iii. private int score – The current score of the game. private int timer – The timer to assist in the game loop. private int missilesFired – The number of Missiles fired. vi. private JLabel scoreLabel – The JLabel to display the score. vii. private JButton fireButton – The JButton to fire a Missile. viii. private GamePanel panel – The custom JPanel to contain the GUI objects. b. Methods: public Tester() – (PROVIDED) The default (or empty) constructor to initialize the instance properties and setup the necessary GUI pieces such as the DefaultCloseOperation, Visibility, Layout, etc. public void start() – (PROVIDED) This method is called to start the video game. It will call the infinite gameLoop() method to execute all aspects of the game. public void gameLoop() – (PROVIDED) The game loop to infinitely run the game until it finishes. The game loop does a sequential set of activities each iteration. That is, pause the game, detect collision of Missiles and Enemies, calculate score, move the Enemies and Missiles, repaint the Enemies and Missiles, check if the game has finished, and determine if a new Enemy needs to be added (say if the timer is equal to 300). public void pauseGame() – (PROVIDED) This method pauses the game for 30ms to allow calculations to be done for each gameLoop iteration before the next frame is shown to the user. public void centerFrame(JFrame frame) – (PROVIDED) This method simply centers the JFrame to the middle of the users monitor. public void setTimer() – (PROVIDED) This method randomly sets the Enemy spawn timer. public static void main(String[] args) – (PROVIDED) The main method to execute the program. Here you make the JFrame of type Tester to start the game. GamePanel (PARTIALLY PROVIDED) – This class inherits JPanel and contains all the GUI elements for the custom JPanel to make the game function. a. Instance Properties: private int totalScore – The score to update the game by. private boolean isNextEnemyBig – A boolean to determine which enemy to generate next, either a BigEnemy or SmallEnemy. private Turret turret – A Turret object to use throughout the class. private ArrayList – A polymorphic ArrayList to hold both BigEnemy and SmallEnemy objects. private ArrayList – An ArrayList to hold Missile objects. b. Methods: public GamePanel() – The default (or empty) constructor to initialize the instance properties. It also adds a new BigEnemy and a new SmallEnemy to the Enemy ArrayList to start the game. public void paintComponent(Graphics g) – (PARTIALLY PROVIDED) Paint the JPanel white, for every Enemy and every Missile, call their respective paintComponent() methods, and paint the Turret with the Turret’s respective paintComponent() method. public void move() – For every Enemy and every Missile, calls the corresponding Enemy and Missile move() methods in their respective classes. iv. public void addMissile() – Adds a new Missile to the Missile ArrayList. public void addEnemy() – Adds a new BigEnemy or SmallEnemy to the Enemy ArrayList depending on the isNextEnemyBig boolean instance property. public int getTotalScore() – Returns the totalScore instance property. public void detectCollision()– (PROVIDED) This method detects if a Missile hits an Enemy and updates the score. The Missile that hit the enemy is removed and the Enemy is affected by calling the processCollission() method in the corresponding Enemy class. Turret – This class inherits JComponent and holds the information necessary for a Turret. a. Instance Properties: i. private Rectangle base – The rectangle that represents the base of the Turret. ii. private Rectangle turret – The rectangle that represents the turret of the Turret. iii. private Color turrentColor – The color of the Turret. b. Methods: public Turret() – The default (or empty) constructor to initialize the instance properties. The values for the Turret’s Rectangle objects, as well as the color, are for you to decide. Recall that a Rectangle has a constructor that takes in the x coordinate, y coordinate, width, and height. public void paintComponent(Graphics g) – The paintComponent() method that paints the Turret base and Turret barrel. Missile – This class inherits JComponent and holds the information necessary to a Missile. Hint: The Missile class inherits JComponent. This means that from the constructor, and the child classes, when we are working with the missileXCoord, missileYCoord, missileHeight, and missileWidth, these can be set using the super.setBounds() method. Furthermore, we can access each of these four instance properties with the super.getX() for example. Instance Properties: private int missileSpeed – The speed of the Missile. private Color missileColor – The color of the Missile. Methods: public Missile() – The default (or empty) constructor to initialize the instance properties and sets the bounds of the JComponent’s Rectangle. The values for the Missile, as well as the color, are for you to decide. public void paintComponent(Graphics g) – The paintComponent() method that paints the Missile based on the current x and y coordinates. public void move(int width, int height, ArrayList list, int missile) – Determine if the missile is off the screen and remove it from the ArrayList if it is. Also, determine the next position on the screen the Missile should appear on after being repainted. Note that the width and height parameters are the dimensions of the JFrame. Update the bounds of the JComponent’s Rectangle object to reflect the movement. Enemy – This class is abstract, inherits JComponent, and holds the information necessary to an Enemy. The children to this class are BigEnemy and SmallEnemy. Hint: The Enemy class inherits JComponent. This means that from the constructor, and the child classes, when we are working with the enemyXCoord, enemyYCoord, enemyHeight, and enemyWidth, these can be set using the super.setBounds() method. Furthermore, we can access each of these four instance properties with the super.getX() for example. Instance Properties: i. private int enemySpeed – The speed of the Enemy. ii. private Color enemyColor – The color of the Enemy. Methods: i. public Enemy(int enemyXCoord, int enemyYCoord, int enemyHeight, int enemyWidth, double enemySpeed) – A partial constructor that sets the coordinates, size, and speed of the Enemy and sets the bounds of the JComponent’s Rectangle. ii. public abstract void processCollision(ArrayList list, int enemy) – An abstract method which determines what occurs when a Missile hits an Enemy. public abstract setColor() – An abstract method which generates and sets the color of the Enemy. public abstract void move(int width, int height) – An abstract method which computes and updates the next position of the Enemy with respect to the JFrame width and height. public void paintComponent(Graphics g) – The paintComponent() method that paints the Enemy based on the current x and y coordinates. Getters and Setters for each instance property. BigEnemy – This class inherits the class Enemy and must implement the abstract methods it contains. Instance Properties: i. None. Methods: public BigEnemy() – The default (or empty) constructor to initialize the instance properties. The values for the BigEnemy, as well as the color, are for you to decide. public void setColor() – This method is the implementation of the Enemy’s abstract setColor() method. You will choose the color of the BigEnemy and set the parent’s color accordingly. public void move(int width, int height) – This method is the implementation of the Enemy’s abstract move() method. You will check if the BigEnemy has hit a wall or not, then reverse the direction if it has. Also, you will update the coordinates of the BigEnemy for the next frame. Note that the width and height parameters are the dimensions of the JFrame. Update the bounds of the JComponent’s Rectangle object to reflect the movement. public void processCollision(ArrayList list, int bigEnemy) – This method is the implementation of the Enemy’s abstract processCollision() method. If this method is called, then a Missile hit a BigEnemy. You will check to see if either the BigEnemy’s height or width is less than zero. If so, remove the BigEnemy from the ArrayList. If not, shrink the size of the BigEnemy by some amount you decide. Update the bounds of the JComponent’s Rectangle object to reflect the collision. SmallEnemy – This class inherits the class Enemy and must implement the abstract methods it contains. Instance Properties: i. None. Methods: public SmallEnemy() – The default (or empty) constructor to initialize the instance properties. The values for the SmallEnemy, as well as the color, are for you to decide. public void setColor() – This method is the implementation of the Enemy’s abstract setColor() method. You will choose the color of the SmallEnemy and set the parent’s color accordingly. public void move(int width, int height) – This method is the implementation of the Enemy’s abstract move() method. You will check if the SmallEnemy has hit a wall or not, then reverse the direction if it has. Also, you will update the coordinates of the SmallEnemy for the next frame. Finally, you will update the speed to go faster each move() call depending on the positive or negative direction the SmallEnemy is currently going in. Note that the width and height parameters are the dimensions of the JFrame. Update the bounds of the JComponent’s Rectangle object to reflect the movement. public void processCollision(ArrayList list, int smallEnemy) – This method is the implementation of the Enemy’s abstract processCollision() method. If this method is called, then a Missile hit a SmallEnemy. You will check to see if either the SmallEnemy’s height or width is less than zero. If so, remove the SmallEnemy from the ArrayList. If not, shrink the size of the SmallEnemy by some amount you decide that is less than what you did for BigEnemy’s processCollision(). Update the bounds of the JComponent’s Rectangle object to reflect the collision. Extra Credit Hint: You may want to change the rule set to make it more complicated or exciting. You can also investigate introducing image files and sound effects using a bit of additional research. Perhaps moving the entire turret could be cool. Finally, maybe introducing key clicks or mouse clicks instead of the basic button at the bottom of the JFrame could be interesting. As long as you can shoot a missile at enemies and get a game over screen, you can be as creative as you want (this includes changing classes, adding classes, etc.)! JavaDoc Style Comments: You are required to make JavaDoc comments for all classes and methods including parameters and return descriptions. Important Note: Please make sure the file names are correct and the code is well commented! The gameLoop in the Tester class makes the game function. Every iteration of the while loop, the game pauses for 30 milliseconds, which gives time to calculate if a collision occurred between a missile and enemy, it moves enemies, repaints them, updates the score, and checks the game ending condition. The JComponent class has a Rectangle object, which has an X and Y coordinate as well as a Width and Height. For most things in this project, like Enemies and Missiles, we can utilize this Rectangle object in JComponent by using setBounds(x, y, width, height). This is necessary as the provided dectectCollision() method in the GamePanel class uses the JComponent’s Rectangle object via the getBounds() method call. If you do not use setBounds(), then collision detection will not work. Submission Instructions: Submit your .java files (Tester.java, GamePanel.java, Turret.java, Missile.java, Enemy.java, BigEnemy.java, SmallEnemy.java, and any other .javas you made for this project) zipped to the corresponding Project 4 Canvas folder. Rubric: Task Grade GUI The GUI is visible and contains components that display information such as the score and any other necessary pieces of information to play the game 15 The GUI has the Title, DefaultCloseOperation, Size, and Visibility correctly set 10 Functionality The game loop is functioning as intended following the provided instructions 10 The user can interact with the GUI to fire Missiles and hit Enemies 10 When an Enemy is hit with a Missile, the score increases, and the Enemy is visually effected 7 Enemies The inheritance hierarchy with the abstract Enemy is followed 8 Both the SmallEnemy and BigEnemy are visually unique and have specific rules in their move() and processCollision() methods 8 The Enemies are painted and move on the GUI 7 Missiles The Missiles are painted and move on the GUI 7 The Missile is removed when it hits an Enemy or goes off the screen 6 Turret The Turret is painted on the GUI 6 It visually looks like the Missiles are fired from the Turret 6 JavaDoc and Intermediate Submission JavaDoc present for all classes and methods . 0 (-10) Total 100 Extra Credit Provided unique additions to the game that are reasonably past the minimal set of guidelines provided for the project 30 Total 130

Writerbay.net

We offer CUSTOM-WRITTEN, CONFIDENTIAL, ORIGINAL, and PRIVATE writing services. Kindly click on the ORDER NOW button to receive an A++ paper from our masters- and PhD writers.

Get a 10% discount on your order using the following coupon code SAVE10


Order a Similar Paper Order a Different Paper