/** elleFuit.java une applet (cf. elleFuit.html, ElleFuit.class, sons/*.au) */ import java.awt.Graphics; import java.awt.Rectangle; import java.lang.Math; public class ElleFuit extends java.applet.Applet { int xxf,yyf; // taille de la fenêtre int xb, yb; // position de la boîte int touche; public void init() { touche = 0; resize(200, 200); } public void paint(Graphics g) { // xxf=this.getWidth(); yyf=this.getHeight(); Rectangle r=this.getBounds(); xxf=r.width; yyf=r.height; g.drawRect(0, 0, xxf-1 , yyf-1 ); g.drawRect(1, 1, xxf-3, yyf-3); xb = (int)(Math.random()*1000) % (xxf - xxf/10); yb = (int)(Math.random()*1000) % (yyf - yyf/10); g.drawRect(xb, yb, xxf/10 - 1, yyf/10 - 1); } /* * Mouse methods */ public boolean mouseDown(java.awt.Event evt, int x, int y) { requestFocus(); // xxf=this.getWidth(); yyf=this.getHeight(); Rectangle r=this.getBounds(); xxf=r.width; yyf=r.height; if((xb<x && x<xb+xxf/10-1) && (yb<y && y<yb+yyf/10-1)) { if(touche > 0) { switch(touche%4) { case 0: play(getCodeBase(), "sons/tiptoe.thru.the.tulips.au"); break; case 1: play(getCodeBase(), "sons/danger,danger...!.au"); break; case 2: play(getCodeBase(), "sons/adapt-or-die.au"); break; case 3: play(getCodeBase(), "sons/cannot.be.completed.au"); break; } touche++; if(touche > 5) getAppletContext().showStatus( "!!! SPECTACULAIRE !!! score:"+touche); else getAppletContext().showStatus( "UN de PLUS !!! Touché ! score:" + touche); } else { getAppletContext().showStatus("BRAVO ! Continue !!!"); play(getCodeBase(), "sons/that.hurts.au"); touche = 1; } } else { getAppletContext().showStatus( "Pas de boîte en (" + x + ", " + y + ") !!!"); play(getCodeBase(), "sons/thin.bell.au"); touche = 0; } repaint(); return true; } public boolean mouseMove(java.awt.Event evt, int x, int y) { if((x % 3 == 0) && (y % 3 == 0)) repaint(); return true; } public void mouseEnter() { repaint(); } public void mouseExit() { touche = 0; repaint(); } /** * Focus methods */ public void keyDown(int key) { requestFocus(); touche = 0; play(getCodeBase(), "sons/ip.au"); } } // fin class ElleFuit