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
Place your order today and enjoy professional academic writing services—From simple class assignments to dissertations. Give us a chance to impress you.
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:
Save your time - order a paper!
Get your paper written from scratch within the tight deadline. Our service is a reliable solution to all your troubles. Place an order on any task and we will take care of it. You won’t have to worry about the quality and deadlines
Order Paper NowDevelop 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
