import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; import games.*; public class ScaryMonsterGame { public static void main(String [] args) { Game game = new Game("Scary Monster Chase Game"); game.setPrototypeMonster(new ImageMonster("clawsfin.gif")); game.start(); try { Thread.currentThread().sleep(10000); } catch (InterruptedException e) { } game.setPrototypeMonster(new ImageMonster("bounce.gif")); } } class ImageMonster extends Monster { private ImageIcon _icon; public ImageMonster(String img) { _icon = new ImageIcon(img); } /// ImageMonsters move somewhat randomly: public boolean move(Game g) { moveTo(getX()+(int)(Math.random()*4-2), getY()+(int)(Math.random()*4-2)); return super.move(g); } /// ImageMonsters draw an image rather than a box: public void draw(Graphics g) { _icon.paintIcon(null,g,getX()-_icon.getIconWidth(), getY()-_icon.getIconHeight()); } }