Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need some help finshing up a java project have most of it done. The basically a

ID: 3838701 • Letter: N

Question

Need some help finshing up a java project have most of it done.

The basically a car game that i need to finsh.

Here are the remaing game requirments.

You should be able to play the game for 30 seconds. (i.e. you should survive for at least 30 seconds). Don’t worry about collision detection with the AI car.

At the end of the simulation, you should gather the person’s name, their favorite number, and their email address. You should check to make sure it is correctly formatted.

Specifics:

Gather the person’s name.

Gather the person’s favorite number – should be a number.

Collect the individual’s email – should have an @ and the ". " operator.

Should pre-emptively check all those values as well as have exception handlers where

appropriate.

Should have a countdown clock that starts at 30 and counts down to 0.

The AI car should race the player until the clock hits zero.

The player object should be able to move using the arrow keys.

Ignore collision detection.

For any exception handlers, you should write any exceptions to a log file.

My code;

Driver.java

import javax.swing.JFrame;

public class Driver {

   public static void main(String[] args) {
       JFrame myFrame = new JFrame("Problem 2");
      
       myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      
       // do something with a panel here...
       MainPanel myPanel = new MainPanel();
      
       myFrame.getContentPane().add(myPanel);
      
       myFrame.pack();
      
       myFrame.setVisible(true);

   }

}

GameObject.java

import javax.swing.ImageIcon;

public abstract class GameObject {

   protected int x;
   protected int y;
   protected String imagePath;
   protected final int HEIGHT;
   protected final int WIDTH;
   public GameObject(int x, int y, String imagePath, int HEIGHT, int WIDTH)
   {
       this.x = x;
       this.y = y;
       this.imagePath = imagePath;
       this.HEIGHT = HEIGHT;
       this.WIDTH = WIDTH;
   }
  
   public abstract ImageIcon getImageIcon();
   //{
       //ImageIcon myIcon = new ImageIcon(imagePath);
       //return myIcon;
       //return new ImageIcon(imagePath);
   //}
  
   public int getX() {
       return x;
   }

   public int getY() {
       return y;
   }
  
   public int getHEIGHT() {
       return HEIGHT;
   }

   public int getWIDTH() {
       return WIDTH;
   }
  
}

MainPanel.java


import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Random;

import javax.swing.JPanel;

public class MainPanel extends JPanel {

   Player myPlayer;
   Player myOtherPlayer;
   private int WIDTH = 1000;
   private int HEIGHT = 1000;
   private int WALLWIDTH = 100;
   private int WALLHEIGHT = 100;
   private ArrayList walls = new ArrayList();
   private int MAXITEMS = 5;
  
  
   public MainPanel()
   {
       setPreferredSize(new Dimension(WIDTH,HEIGHT));
       myPlayer = new Player(100,100, "toad.png", KeyEvent.VK_UP, KeyEvent.VK_DOWN, KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT,this, 50, 38);
       myOtherPlayer = new Player(200,200, "toad.png", KeyEvent.VK_W, KeyEvent.VK_S, KeyEvent.VK_A, KeyEvent.VK_D,this, 50, 38);

       createWalls();
   }
  
   public ArrayList getWalls() {
       return walls;
   }

   public void createWalls()
   {
       int j = 0;
       for(int i = 0; i < HEIGHT/WALLHEIGHT; i++)
       {
           for(int k = 0; k < WIDTH/WALLWIDTH; k++)
           {
               if(i == 0 || i == (HEIGHT/WALLHEIGHT-1))
               {
                   walls.add(new Wall(k*WALLWIDTH,j,"road.png", 100, 100));
               }
  
           }
           j+=WALLHEIGHT;
       }
   }
  

  
  
   public void paintComponent(Graphics page)
   {
       super.paintComponent(page);
      
       page.drawImage(myPlayer.getImageIcon().getImage(), myPlayer.getX(), myPlayer.getY(), null);
       page.drawImage(myOtherPlayer.getImageIcon().getImage(), myOtherPlayer.getX(), myOtherPlayer.getY(), null);
      
       for(int i = 0; i < walls.size(); i++)
       {
           page.drawImage(walls.get(i).getImageIcon().getImage(), walls.get(i).getX(), walls.get(i).getY(), null);
       }
      
  
       page.setFont(new Font("Arial", Font.PLAIN,32));
       page.drawString("Player 1 Score: " + myPlayer.getScore(), 100, 800);
       page.drawString("Player 2 Score: " + myOtherPlayer.getScore(), 100, 850);
      
//       //if(items.size() == 0)
//       {
//           page.drawString("GAME OVER", WIDTH/2-100, HEIGHT/2);
//              
//       }
   }
}

Movement.java


public class Movement {

  

   private int distanceLeft = 10;
   private int distanceRight = 10;
  
   public int getDistanceLeft() {
       return distanceLeft;
   }
   public int getDistanceRight() {
       return distanceRight;
   }
  
  
}

Player.java

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;

import javax.swing.ImageIcon;

public class Player extends GameObject implements KeyListener{

   //private int x;
   //private int y;
   //private ImageIcon myImage;
   private int Up;
   private int Down;
   private int Left;
   private int Right;
   //private String imagePath;
   private MainPanel myPanel;
   private Movement myMovement = new Movement();
   //private int HEIGHT = 38;
   //private int WIDTH = 50;
   private int score = 0;
  
   public Player(int x, int y, String imagePath, int Up, int Down, int Left, int Right, MainPanel myPanel, int HEIGHT, int WIDTH)
   {
       super(x,y,imagePath, HEIGHT, WIDTH);
       //this.x = x;
       //this.y = y;
       //this.imagePath = imagePath;
       //myImage = new ImageIcon(imagePath);
       this.Up = Up;
       this.Down = Down;
       this.Left = Left;
       this.Right = Right;
       this.myPanel = myPanel;
       myPanel.addKeyListener(this);
       myPanel.setFocusable(true);
  
   }

   public int getX() {
       return x;
   }

   public void setX(int x) {
       this.x = x;
   }

   public int getY() {
       return y;
   }

   public void setY(int y) {
       this.y = y;
   }

   //public ImageIcon getMyImage() {
   //   return myImage;
   //}

   public int getScore()
   {
       return score;
   }

   @Override
   public void keyPressed(KeyEvent arg0) {
       // TODO Auto-generated method stub
       int key = arg0.getKeyCode();
      
       if(key == Left)
       {
           x-=myMovement.getDistanceLeft();
           if(checkWalls())
           {
               x+=10;
           }
       }
       else if(key == Right)
       {
           x+=myMovement.getDistanceRight();
           if(checkWalls())
           {
               x-=10;
           }
       }
      
      
       myPanel.repaint();
      
   }

   public boolean checkWalls()
   {
       ArrayList walls = myPanel.getWalls();
      
       for(int i = 0 ; i < walls.size(); i++)
       {
           if(areRectsColliding(x,x+HEIGHT,y,y+WIDTH,walls.get(i).getX(), walls.get(i).getX()+ walls.get(i).getHEIGHT(),
                   walls.get(i).getY(),walls.get(i).getY()+walls.get(i).getWIDTH()))
                   {
                       return true;
                   }
       }
       return false;
      
   }

   @Override
   public void keyReleased(KeyEvent arg0) {
       // TODO Auto-generated method stub
      
   }

   @Override
   public void keyTyped(KeyEvent arg0) {
       // TODO Auto-generated method stub
      
   }
  
   private boolean areRectsColliding(int r1TopLeftX, int r1BottomRightX,
           int r1TopLeftY, int r1BottomRightY, int r2TopLeftX,
           int r2BottomRightX, int r2TopLeftY, int r2BottomRightY) {

       if (r1TopLeftX < r2BottomRightX && r1BottomRightX > r2TopLeftX
               && r1TopLeftY < r2BottomRightY && r1BottomRightY > r2TopLeftY) {
           return true;
       } else {
           return false;
       }
   }

   @Override
   public ImageIcon getImageIcon() {
       // TODO Auto-generated method stub
       return new ImageIcon(imagePath);
   }
}

Wall.java

import javax.swing.ImageIcon;

public class Wall extends GameObject{

   //private int x;
   //private int y;
   //private String imagePath;
   //private ImageIcon myImage;
   //private int HEIGHT = 100;
   //private int WIDTH = 100;
  
   public Wall(int x, int y, String imagePath, int HEIGHT, int WIDTH)
   {
       super(x,y,imagePath, HEIGHT, WIDTH);
      
       //this.x = x;
       //this.y = y;
       //this.imagePath = imagePath;
       //myImage = new ImageIcon(imagePath);
   }

   @Override
   public ImageIcon getImageIcon() {
       // TODO Auto-generated method stub
       return new ImageIcon(imagePath);
   }

   /*public int getX() {
       return x;
   }

   public int getY() {
       return y;
   }*/

   //public ImageIcon getImageIcon()
   //{
   //   return myImage;
   //}
/*
   public int getHEIGHT() {
       return HEIGHT;
   }

   public int getWIDTH() {
       return

road.png

toad.png

Explanation / Answer

bundle cargame;
import java.awt.*; import java.awt.geom.*; import java.util.*;
open conceptual class Vehicle {/Member factors ensured Point2D.Float position = new Point2D.Float(); secured Point2D.Float introduction = new Point2D.Float(); ensured Point2D.Float side = new Point2D.Float(); secured Point2D.Float speed = new Point2D.Float(); secured Point2D.Float guiding = new Point2D.Float(); secured skim mass; ensured glide maxSpeed; ensured coast maxSteering;/List of practices ensured ArrayList practices = new ArrayList(10);/Getters and setters open Point2D.Float getPosition() { return position; } open void updatePosition(Point2D.Float p) { position.x = p.x; position.y = p.y; } open void updatePosition(float x, drift y) { position.x = x; position.y = y; } open Point2D.Float getOrientation() { return introduction; } open void updateOrientation(Point2D.Float o) { orientation.x = o.x; orientation.y = o.y; } open void updateOrientation(float x, glide y) { orientation.x = x; orientation.y = y; }
open Point2D.Float getSideVector() { return side; }
open Point2D.Float getVelocity() { return speed; } open void updateVelocity(Point2D.Float v) { velocity.x = v.x; velocity.y = v.y; } open void updateVelocity(float x, skim y) { velocity.x = x; velocity.y = y; } open Point2D.Float getSteering() { return directing; } open void updateSteering(Point2D.Float s) { steering.x = s.x; steering.y = s.y; } open void updateSteering(float x, coast y) { steering.x = x; steering.y = y; }
open buoy getMass() { return mass; } open void setMass(float m) { mass = m; } open void setMaxSpeed(float m) { maxSpeed = m; } open buoy getMaxSpeed() { return maxSpeed; }
open void setMaxSteering(float f) { maxSteering = f; } open buoy getMaxSteering() { return maxSteering; } open void addBehaviour(Behaviour b) { behaviours.add(b); }
/A couple of utility techniques for working with vectors static buoy length(Point2D.Float v) { return (float)Math.sqrt((v.x * v.x) + (v.y * v.y)); }
static open void scale(Point2D.Float v, glide newLength) { skim l = length(v); v.x *= newLength/l; v.y *= newLength/l; }
/Update this vehicle open void update(float dt) { for (int i = 0; i < behaviours.size(); i++) { ((Behaviour)behaviours.get(i)).update(this, dt); }
/Truncate the length of the coveted controlling power vector Point2D.Float drive = new Point2D.Float(steering.x, steering.y); drift l = length(force); if (l > maxSteering) { force.x *= maxSteering/l; force.y *= maxSteering/l; }
/Newton's second law: controlling power = mass * accelerataion Point2D.Float acc = new Point2D.Float(force.x/mass, force.y/mass);
/Update speed vector utilizing Euler's strategy/and truncate its length to the most extreme permitted velocity.x += dt * acc.x; velocity.y += dt * acc.y; l = length(velocity); if (l > maxSpeed) { velocity.x *= maxSpeed/l; velocity.y *= maxSpeed/l; }/Update position utilizing Euler's technique position.x += dt * velocity.x; position.y += dt * velocity.y;
/Set introduction to break even with the speed vector/and set the side vector in like manner
l = length(velocity); if (l > 0.0f) { orientation.x = velocity.x/l; orientation.y = velocity.y/l; side.x = - orientation.y; side.y = orientation.x; }
/Abstract strategies for drawing and crossing point testing open unique void draw(Graphics2D g2); open theoretical boolean intersects(Vehicle v); }
Car.java bundle cargame;
import java.awt.*; import java.awt.geom.*; import java.awt.image.*; import javax.swing.*;
open class Car amplifies Vehicle executes ImageObserver { ensured Image img; secured coast w2; secured drift h2; open Car(String imageFileName) { ImageIcon iic = new ImageIcon(imageFileName); img = Transparency.makeColorTransparent(iic.getImage(), Color.black); } open void draw(Graphics2D g2) { AffineTransform saveXform = g2.getTransform();
g2.translate(position.x, position.y); g2.rotate(Math.atan2(orientation.y, orientation.x)); g2.drawImage(img, AffineTransform.getTranslateInstance(- img.getWidth(this)/2.0, - img.getHeight(this)/2.0), this); g2.setTransform(saveXform);
/* g2.setPaint(Color.yellow); g2.drawLine((int)Math.floor(position.x), (int)Math.floor(position.y), (int)Math.floor(position.x + 50.0f * side.x), (int)Math.floor(position.y + 50.0f * side.y)); g2.setPaint(Color.blue);
g2.drawLine((int)Math.floor(position.x), (int)Math.floor(position.y), (int)Math.floor(position.x + velocity.x), (int)Math.floor(position.y + velocity.y)); g2.setPaint(Color.white); g2.drawLine((int)Math.floor(position.x), (int)Math.floor(position.y), (int)Math.floor(position.x + steering.x), (int)Math.floor(position.y + steering.y)); */}
open boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int tallness) { return genuine; } open boolean intersects(Vehicle v) { if (v instanceof Car) { Car c = (Car)v; Point2D.Float d = new Point2D.Float(position.x - c.position.x, position.y - c.position.y); if (length(d) < 25.0f) {/Should likely process the sweep from the pictures... return genuine; } return false; }
GameSurface.java bundle cargame;
import java.util.*; import java.awt.*; import java.awt.event.*;
import javax.swing.*;
open class GameSurface augments JComponent actualizes MouseListener { ensured ArrayList vehicles; open GameSurface() { vehicles = new ArrayList(10); addMouseListener(this);/For asking for info center } open void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Dimension d = getSize(); g2.setPaint(new Color(91, 91, 91)); g2.fillRect(0, 0, d.width, d.height);
for (int i = 0; i < vehicles.size(); i++) { Vehicle v = (Vehicle)vehicles.get(i); v.draw(g2); }
ArrayList getVehicles() { return vehicles; }
open void mouseClicked(MouseEvent e) {/Custom segments need to ask for the/input center when they are clicked,/else they won't get console occasions requestFocusInWindow(); } open void mouseMoved(MouseEvent e) {} open void mouseExited(MouseEvent e) {} open void mouseReleased(MouseEvent e) {} open void mouseEntered(MouseEvent e) {} open void mousePressed(MouseEvent e) {} open void mouseDragged(MouseEvent e) {} }
AnimationSystem.java bundle cargame;
import java.util.*;
open class AnimationSystem executes Runnable { ensured GameSurface amusement; open AnimationSystem(GameSurface gameSurface) { diversion = gameSurface; } open void run() { long time = System.currentTimeMillis(); for (;;) { ArrayList vehicles = game.getVehicles();/Update position, speed and so forth of vehicles long t = System.currentTimeMillis(); long dt = t - time; coast secs = (float)dt/1000.0f;/Convert to seconds for (int i = 0; i < vehicles.size(); i++) { Vehicle v = (Vehicle)vehicles.get(i); v.update(secs); }
/Check for crashes for (int i = 0; i < vehicles.size(); i++) { for (int j = i + 1; j < vehicles.size(); j++) { Vehicle vi = (Vehicle)vehicles.get(i); Vehicle vj = (Vehicle)vehicles.get(j); if (vi.intersects(vj)) {
/Collision recognized! /For now, essentially reset the places of the vehicles vi.updatePosition(50, 50); vj.updatePosition(450, 450); }
time = System.currentTimeMillis(); game.repaint();/Sleep for a short measure of time to enable the framework to get up to speed. /This enhances framerate significantly and evades hiccups attempt { Thread.sleep(20); } get (InterruptedException e) { }
Behaviour.java bundle cargame;
open unique interface Behavior { open conceptual void update(Vehicle v, drift dt); }
PursuitBehaviour.java bundle cargame;
import java.awt.geom.Point2D;
open class PursuitBehaviour executes Behavior { ensured Vehicle target;
PursuitBehaviour(Vehicle v) { target = v; } open void update(Vehicle v, glide dt) {/Steer vehicle towards target
Point2D.Float p = v.getPosition(); Point2D.Float tp = target.getPosition(); Point2D.Float desired_velocity = new Point2D.Float(tp.x - p.x , tp.y - p.y); Vehicle.scale(desired_velocity, v.getMaxSpeed()); v.updateSteering(desired_velocity.x, desired_velocity.y); }
}
RoamBehaviour.java bundle cargame;
import java.awt.geom.Point2D;
open class RoamBehaviour executes Behavior { ensured long lastTargetUpdate; secured Point2D.Float target = new Point2D.Float(); secured drift width; secured skim stature; ensured glide x; secured coast y; open RoamBehaviour(float x, glide y, coast width, coast tallness) { this.x = x; this.y = y; this.width = width; this.height = stature; } open void update(Vehicle v, drift dt) {/Update target if important
long time = System.currentTimeMillis(); if (time - lastTargetUpdate > 5000) { target.x = x + (float)Math.random() * width; target.y = y + (float)Math.random() * stature; lastTargetUpdate = time; }/Steer vehicle towards target
Point2D.Float p = v.getPosition(); Point2D.Float desired_velocity = new Point2D.Float(target.x - p.x , target.y - p.y);
Vehicle.scale(desired_velocity, v.getMaxSpeed()); v.updateSteering(desired_velocity.x, desired_velocity.y); }
BounceOffWallsBehaviour.java bundle cargame;
import java.awt.geom.Point2D;
open class BounceOffWallsBehaviour executes Behavior { ensured skim x1; secured drift y1; secured coast x2;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote