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

The goal of this assignment is to develop an event-based game. You are going to

ID: 3736118 • Letter: T

Question

The goal of this assignment is to develop an event-based game. You are going to develop a Pong Game.

The game board is a rectangle with a ball bouncing around. On the right wall, you will have a rectangular paddle (1/3 of the wall height). The paddle moves with up and down arrows. Next to the game board, there will be a score board. It will show the count of goals, and count of hits to the paddle. In the beginning of the game, the paddle will be on the center of the right wall.

You can develop a two-player game, and it will count for extra 2 points bonus.

You can arrange the color and the style of the board/paddle/ball/Score Board as you prefer.

My Pong Game SCORE BOARD Goals Hits 10 25

Explanation / Answer

Please find my answer:

You need to understand that this is a very big assignment which is difficult to be completed in 2 hours (time we get to complete an assignment in Chegg).

For your reference, I am providing you a sample code for creating a Ball, one controller for Computer and one controller for a Player. You need to incrementally add changes to Game.java to construct the whole game.

CODE

======================

Ball.java

*********************

import java.awt.Color;

import java.awt.Component;

import java.awt.Graphics;

import java.awt.Image;

import javax.swing.ImageIcon;

import java.applet.*; // Don't forget this import statement!

import java.awt.*; // Or this one for the graphics!

public class Ball {

/** Creates a new instance of Ball */

private int Reduis;

public int x;

public int y;

public int vx;

public int vy;

private int BALL_TOP;

private int BALL_LEFT;

private int BALL_RIGHT;

private int BALL_DOWN;

private int PLAYER_TOP;

private int PLAYER_DOWN;

private int PLAYER_RIGHT;

private int COMP_TOP;

private int COMP_DOWN;

private int COMP_LEFT;

private int max_vx=5;

private int max_vy=5;

public Component myBase;

private Color BallColor;

private Image myImg;

public Ball(int r, int x,int y,int vx,int vy,Color BallColor,Component newBase)

{

Reduis=r;

this.x=x;

this.y=y;

this.vx=vx;

this.vy=vy;

myBase=newBase;

myImg= ((Applet) myBase).getImage (((Applet) myBase).getCodeBase(), "images/Ball.gif");

this.BallColor=BallColor;

}

public void move() {

if (vx > max_vx) vx = max_vx;

else if (vx < -max_vx) vx = -max_vx;

else if (vy > max_vy) vy = max_vy;

else if (vy < -max_vy) vy = -max_vy;

// else if (vx == 0 && !isStoped) vx = 1;

x += vx;

y += vy;

}

public int wheresBall() {

if (vy > 0) {

if (y > 280)

{

vy = -vy;

return 0;

}

} else if (vy < 0) {

if (y < 40)

{

vy = -vy;

return 0;

}

}

if(x<20)

return 1;

else if(x>375)

return 2;

return 0;

}

public void PCollision(Player PlayerStick,AudioClip hitSound) {

BALL_TOP = y - Reduis;

BALL_DOWN = y + Reduis;

BALL_LEFT = x - Reduis;

BALL_RIGHT = x + Reduis;

PLAYER_TOP = PlayerStick.y;

PLAYER_DOWN = PlayerStick.y + PlayerStick.sizey;

if ((BALL_TOP >= PLAYER_TOP - 10) && (BALL_DOWN <= PLAYER_DOWN + 10)) {

if (BALL_LEFT <= 30 ) {

hitSound.play();

vx = - vx;

if (PlayerStick.vy < 0) {

vy --;

} else if (PlayerStick.vy > 0) {

vy += PlayerStick.vy;

}

}

}

}

public void CCollision(Computer CompStick,AudioClip hitSound) {

BALL_TOP = y - Reduis;

BALL_DOWN = y + Reduis;

BALL_LEFT = x - Reduis;

BALL_RIGHT = x + Reduis;

COMP_TOP = CompStick.y;

COMP_DOWN= CompStick.y + CompStick.sizey;

if ((BALL_TOP >= COMP_TOP - 10) && (BALL_DOWN <= COMP_DOWN + 10)) {

if (BALL_RIGHT >= 370 ) {

hitSound.play();

vx = - vx;

if (CompStick.vy < 0) {

vy --;

} else if (CompStick.vy > 0) {

vy += CompStick.vy;

}

}

}

}

public void DrawBall(Graphics g) {

g.setColor(BallColor);

g.drawImage(myImg,x - Reduis, y - Reduis,myBase);

}

}

Player.java

***************************

import java.awt.Color;

import java.awt.Graphics;

import java.applet.*;

import java.awt.*;

public class Player {

public int x;

public int y;

public int sizex;

public int sizey;

public int vy;

private Color StickColor;

/** Creates a new instance of Player */

public Player(int x,int y,int sizex,int sizey,Color StickColor) {

this.x=x;

this.y=y;

vy=0;

this.sizex=sizex;

this.sizey=sizey;

this.StickColor=StickColor;

}

public void Move(int dy) {

y+=dy;

}

public void MoveByMouse(int newy)

{

y=newy;

}

public void DrawStrick(Graphics g) {

g.setColor(StickColor);

g.fillRect(x, y, sizex, sizey);

}

}

Computer.java

******************************

import java.awt.Color;

import java.awt.Graphics;

import java.applet.*;

import java.awt.*;

public class Computer {

public int x;

public int y;

public int sizex;

public int sizey;

public int vy;

private int real_y;

private Color StickColor;

/** Creates a new instance of Computer */

public Computer(int x,int y,int sizex,int sizey,Color StickColor) {

this.x=x;

this.y=y;

this.sizex=sizex;

this.sizey=sizey;

this.StickColor=StickColor;

vy = 4;

}

public void ComputerMove(Ball b) {

real_y = y + (sizey / 2);

if (b.vx < 0) {

if (real_y < 150) {

y += vy;

}

else if (real_y > 150) {

y -= vy;

}

} else if (b.vx > 0) {

if ( real_y != b.y) {

if (b.y < real_y) {

y -= vy;

}

else if (b.y > real_y) {

y += vy;

}

}

}

}

public void DrawStrick(Graphics g) {

g.setColor(StickColor);

g.fillRect(x, y, sizex, sizey);

}

}

Game.java

****************************

You need to incrementally add features to this class.

****Note: Please create one more post on Chegg to implement Game.java and I will try to answer it.

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