// 1.124 Final Project //Group: Evidence //Authors: Haiyang Liu, Qing Li import java.awt.*; import java.applet.Applet; import java.awt.image.*; import java.util.*; import java.lang.Math; import java.awt.event.*; public class pppp extends Applet implements Runnable { Image mBackgroundImage, mRoverImage; boolean mbBackgroundComplete = false, mbRoverComplete = false; boolean mbBackgroundDrawn = false,tmp; Image mOffScreenImage; Graphics mOffScreenGraphics; Rover mRover; Button mStartButton, mStopButton; Thread mRunner = null; static final int iWidth=512, iHeight=512; static final int North=0,South=1,East=2,West=3,NE=4,NW=5,SE=6,SW=7; //definition of data structure for gems and obstacles public Vector gem[]=new Vector [1000]; //each vector for one gem public Vector obstacle[]=new Vector [1000]; //each vector for one obstacle public int pickedup[]=new int [20]; //flags of pickup int gemnum=0,obsnum=0, gemFound = 0; int accvalue=0; //accumulated gems value picked up //end of definition of data structure for gems and obstacles public pppp() { setLayout(new BorderLayout()); Panel panel = new Panel(); panel.setLayout(new GridLayout(1,2)); mStartButton = new Button("Start"); panel.add(mStartButton); mStopButton = new Button("Stop"); panel.add(mStopButton); add("South", panel); } public void init() { // Get a handle on the images. mBackgroundImage = getImage(getCodeBase(), "mars.gif"); mRoverImage = getImage(getCodeBase(), "rover.gif"); // Create the rover. mRover = new Rover(this); // Create an offscreen buffer. mOffScreenImage = createImage(512, 512); mOffScreenGraphics = mOffScreenImage.getGraphics(); //Scan gems and obstacles tmp=ScanObj(); } // The update method is called by the AWT whenever we make a repaint() // request. The default implementation of update() clears the background // before calling paint(), which leads to flashing. To avoid flashing, // we provide our own implementation of update. public void update(Graphics g) { // Draw the background image into the offscreen buffer only once. // This allows us to keep a trail of where the rover has been. if (!mbBackgroundDrawn) { mOffScreenGraphics.drawImage(mBackgroundImage, 0, 0, this); if (mbBackgroundComplete) mbBackgroundDrawn = true; } // Draw the current Rover location into the offscreen buffer. mOffScreenGraphics.drawImage(mRoverImage, mRover.mX, mRover.mY, this); // Copy the contents of the offscreen buffer onto the screen. if (mbBackgroundComplete && mbRoverComplete) { g.drawImage(mOffScreenImage, 0, 0, null); } //beginning of indication of gems /* g.setColor(Color.black); for(int k=0; k