Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Using Netbeans / java script Here is Poddapp.java /* * This class represents a visual application for the pod chase game. */ package project6; /**
Using Netbeans / java script
Here is Poddapp.java
/* * This class represents a visual application for the "pod chase" game. */ package project6; /** * * @author jrsullins */ import javax.swing.*; import java.awt.*; import java.awt.event.*; public class PodApp extends JFrame implements ActionListener { // Member variables for visual objects. private JLabel[][] board; // 2D array of labels. Displays either # for player, // * for pod, or empty space private JButton northButton, // player presses to move up southButton, // player presses to move down eastButton, // player presses to move right westButton; // player presses to move left // Current width and height of board private int width = 15; private int height = 9; // Current location of player private int playerX = 7; private int playerY = 4; // PodList object private PodList pods; public PodApp() { // Construct a panel to put the board on and another for the buttons JPanel boardPanel = new JPanel(new GridLayout(height, width)); JPanel buttonPanel = new JPanel(new GridLayout(1, 4)); // Use a loop to construct the array of labels, adding each to the // board panel as it is constructed. Note that we create this in // "row major" fashion by making the y-coordinate the major // coordinate. We also make sure that increasing y means going "up" // by building the rows in revers order. board = new JLabel[height][width]; for (int y = height-1; y >= 0; y--) { for (int x = 0; x 0) { playerY--; } if (e.getSource() == northButton && playerY 0) { playerX--; } // Notify the pod list about player location pods.playerAt(playerX, playerY); // Possibly generate another pod pods.generate(); // Redraw the board drawBoard(); } /** * @param args the command line arguments */ public static void main(String[] args) { PodApp a = new PodApp(); } }Introduction This assignment is meant to introduce you to generalized container classes in Java. In this assignment you will re-implement the "pod chase" game from Assignment 2, adding a PodList class that stores a list of Pod object, as well as rewriting the Pod class to better take advantage of container methods. Game Structure and User Interface Class The basic structure of the game and visual application is mostly the same as in Project 1, in which the player (marked "if") moves around a 2D map (currently 15x9) to collect "pods" (marked The game provides buttons ("N", "S "E", and "W") that moves the player one square in the direction north, south, east, or west respectively The pods themselves are always in motion, moving is a diagonal direction (either NE, NW, SE, or Sw). When one reaches the edge of the board, it "bounces" off of the wall, changing its direction. When the player reaches the current location of a pod, then that pod is considered "caught" and will no longer be displayed. The main way that the game has changed is that every move there is a chance that a new pod will be generated. More specifically: Each turn, a new pod will be generated with a 10% chance. This probability may be change in future versions ofthe game, so you will need to make it easy to change. When a new pod is generated, it is placed at a random location on the board, and will be moving in a random direction (either NE, NW, SE, or SW) I have provided on the course web page a user interface class called PodApp. While you will not be changing any of the code in this class, I do encourage you to take a look at the code in order to better understand the requirements for the classes that you will be creating
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