• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to upgrade this applet

 
salem salman
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i am trying to update this program in order to write an applet to play the "Cat and mouse" game. In this game, the user is a "mouse" who has to find their way safely to a mousehole drawn in the middle of the top of the applet pane. Several cats appear at random positions in the pane and will try to catch the mouse by chasing after it. You lose the game if the cat gets too close to your mouse. You win if you get to the hole before they get near you.
here is mainpart of the program
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class CatMouseChase extends Applet implements ActionListener
{
private Cat myCat;
private Mouse myMouse;
private Statue myStatue;
private Position myOldCatPosition;
private boolean chaseIsOver = false;
private int timeElapsed = 0;
private final int TIME_LIMIT = 30;
private Button nextStep;
private String statusString = "Not yet started.";
private final int BORDER = 50; // margin for buttons and status strings
private static int ourWindowWidth, ourWindowHeight;
private int myXCenter, myYCenter, myUnit;
private final int WAIT_TIME = 500; //milliseconds
public void init ( )
{super.init ( );
nextStep = new Button ("Move once");
add (nextStep);
nextStep.addActionListener (this);
ourWindowWidth = getIntegerParam ("width");
ourWindowHeight = getIntegerParam ("height");
myXCenter = ourWindowWidth/2;
myYCenter = ourWindowHeight/2;
int smallestDimension = ourWindowWidth < ourWindowHeight? ourWindowWidth: ourWindowHeight;
double statueRadius = getDoubleParam("statueradius");
double mouseAngle = getDoubleParam("mouseangle");
double catRadius = getDoubleParam("catradius");
double catAngle = getDoubleParam("catangle");
myStatue = new Statue(statueRadius);
myUnit = (smallestDimension/2 - BORDER)/((int) (catRadius+myStatue.getRadius()));
myCat = new Cat (new Position (catRadius, catAngle));
myOldCatPosition = myCat.getPosition();
myMouse = new Mouse (new Position (myStatue.getRadius(), mouseAngle));
statusString = "Chase is in progress.";
}
private int getIntegerParam (String name)
{String value = this.getParameter (name);
if (value == "")
{return 0;
}
try
{return Integer.parseInt(value);
} catch (Exception e)
{return 0;
}
}
private double getDoubleParam (String name)
{String value = this.getParameter (name);
if (value == "")
{return 0.0;
}
try
{return Double.valueOf (value).doubleValue ( );
} catch (Exception e)
{return 0.0;
}
}
public void actionPerformed (ActionEvent event)
{//students complete rest of method
repaint();
}
public void paint (Graphics g)
{// The magic numbers used here should really depend on the height of the
// type face used to display the window annotations.
// We'll fix that for next semester.
g.drawOval (myXCenter+5-myUnit, myYCenter+5-myUnit, 2*myUnit-10, 2*myUnit-10);
g.drawString ("CO", myOldCatPosition.xCoord (myXCenter, myUnit)-5,
myOldCatPosition.yCoord (myYCenter, myUnit)+5 );
g.drawString ("C", myCat.getPosition ( ).xCoord (myXCenter, myUnit)-5,
myCat.getPosition ( ).yCoord (myYCenter, myUnit)+5 );
g.drawString ("M", myMouse.getPosition ( ).xCoord (myXCenter, myUnit)-5,
myMouse.getPosition ( ).yCoord (myYCenter, myUnit)+5 );
g.drawString ("Mouse at " + myMouse.getPosition ( )
+ "; cat at " + myCat.getPosition ( ), 50, ourWindowHeight-30);
g.drawString (statusString, 50, ourWindowHeight-15);
}
public void pause()
{try
{Thread.sleep(WAIT_TIME);
}
catch(Exception e)
{}
}
}
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So why don't you tell us the problem you are having so that we can help.
 
salem salman
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx for replying,
Basically i am trying to write an applet to play the "Cat and mouse" game. In this game, the user is a "mouse" who has to find their way safely to a mousehole drawn in the middle of the top of the applet pane. Several cats appear at random positions in the pane and will try to catch the mouse by chasing after it. You lose the game if the cat gets too close to your mouse. You win if you get to the hole before they get near you.
i would appreciate any one help.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I realize WHAT you are trying to do. But what I asked is what problems are you having. You said you needed help, but you don't tell us with what part. We aren't going to just write your game applet for you.
Are you getting any errors?
If so, what exact error messages are you getting?
Are you having a design problem?
Also, this may do better in the Applet forum since you are writing an applet and not an application.
So if someone wants to move this thread there....
Either way, you need to tell us what specific help you need. Not just a description of what you are wanting to do. This way, we can help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!