Create a simple game in a Java Applet. Your game should have the following features:
Must have a graphical user interface Must have user interaction Must have a win/lose status
Upload your java code for your game here. Include a short paragraph describing how to play the game.
For your reference, the below is the example code given by our professor...Create a different game, but use this code if needed. Please don't copy codes from different websites. Please create a new one. Thanks in advance... import java.applet.*; import java.awt.*; import java.awt.image.*;
import java.awt.event.*; public class Game extends Applet implements Runnable, MouseListener, MouseMotionListener{Thread gameThread; int width = 400, height = 400, MAX = 50; int currentX[] = new int[MAX]; int currentY[] = new int[MAX]; int speed = 10; //Speed at which we will move the objects int step = 0, direction = 1, shipX = width/2-10, shipY=height-45; int mbx = -10, mby = -10, randomShoot = 0, health = 50, BNUM = 10, playing = 0; int bX[] = new int[BNUM]; int bY[] = new int[BNUM]; int ebX[] = new int[BNUM]; int ebY[] = new int[BNUM];
//these variables control the processing speed of the graphics long start = 0; long tick_end_time; long tick_duration; long sleep_duration; static final int MIN_SLEEP_TIME = 10; static final int MAX_FPS = 20; static final int MAX_MS_PER_FRAME = 1000/MAX_FPS; float fps = 0; BufferedImage bufferedImg; Graphics2D bufferedImgSurface; float dist; public void start()
{ gameThread = new Thread(this); gameThread.start(); } public void init() { int row = 10; int col = 10; int count = 0; currentX[0]=c currentY[0]=row;for(int i = 0; i <><><> 15) { if(direction == 1) {direction = 0 } else { direction = 1; } step = 0; for(int j = 0; j <><><=0) ><><><=0) ><=><>= 0) { for(int i = 0; i <>= height) { ebX[i] = currentX[randomShoot]; ebY[i] = currentY[randomShoot]; break; }//end if }//end for bullets }//end if alien is on screen
}//end for shooting alien bullets for (int j = 0; j <>= height)) { dist = (int)(Math.sqrt(Math.pow((shipX+10)-ebX[j], 2) + Math.pow((shipY+10)-ebY[j], 2))); if(dist <=><><><=><>=340) playing = 2; } //end for checking alien status if (count == MAX) playing = 3; }//if playing else{} repaint();
tick_end_time = System.currentTimeMillis(); tick_duration = tick_end_time - start; sleep_duration = MAX_MS_PER_FRAME - tick_duration; if(sleep_duration <><>
for(int j = 0; j <><>
=>=>=>=0) >=0) >