/** J.G. mein erstes APPLET April 1997 */

import java.applet.*;
import java.awt.*;
import java.util.*;

public class W52 extends Applet {

StringBuffer buffer;
StringBuffer buffer1;
Random r;

int n;
int n1;
Date d;
Wuerfel w;
boolean first;
AudioClip clip;
String clipname;	

//-------------------------
public void init() {
	
	buffer = new StringBuffer();
	d = new Date();
	r = new Random(d.getTime());
	n1=0;

	Font f = new Font("Helvetica", Font.PLAIN, 14);
	setFont(f);

	w = new Wuerfel();
	w.initialize(0,0,0,0,1,0,0,0,0);
	first = true;
	
	buffer1 = new StringBuffer(getParameter("Farbe"));

	repaint();
	
	clipname = getParameter("Ton");
	clip = getAudioClip(getDocumentBase(),clipname);
	
	}


//-------------------------
public boolean mouseDown(Event event, int x, int y) {
              	
	n =  r.nextInt( ) % 6; 
	n = Math.abs(n);
	n = n +1;
	buffer = new StringBuffer("das war eine " +n); 

	if (n == 6) {Font f = new Font("Helvetica", Font.BOLD, 14);   setFont(f);}
	else {Font f = new Font("Helvetica", Font.PLAIN, 14);   setFont(f);}
	
	first = false;
	
    return true;
	}

	
//-------------------------
public void paint(Graphics g) {

	g.setColor(Color.white);
	g.fillRect(0, 0, size().width - 1, size().height-1);

	g.setColor(Color.black);
 	g.drawRect(0, 0, size().width - 1, size().height - 31);
	g.drawRect(1, 1, size().width - 3, size().height - 33);


	if (buffer1.toString().equals("Zufall")) 
		{if (n==1) g.setColor(Color.black);
		if (n==2) g.setColor(Color.pink);
		if (n==3) g.setColor(Color.cyan);
		if (n==4) g.setColor(Color.green);
		if (n==5) g.setColor(Color.blue);
		if (n==6) g.setColor(Color.red);} else

	{if (buffer1.toString().equals("red")) g.setColor(Color.red);
	if (buffer1.toString().equals("green")) g.setColor(Color.green);
	if (buffer1.toString().equals("blue")) g.setColor(Color.blue);
	}
	
	if (n==6) clip.play();

 	g.drawString(buffer.toString(), 5, size().height-5);
	g.setColor(Color.black);
	
	w = new Wuerfel();
	

	if (first==true) {w.initialize(1,0,0,0,1,0,0,0,1); w.draw(g);}
       
	if (n==1)
		w.initialize(0,0,0,0,1,0,0,0,0);			
		
	if (n==2) {
		if (n1==2)
			w.initialize(1,0,0,0,0,0,0,0,1);
		else
			w.initialize(0,0,1,0,0,0,1,0,0);
		}

	if (n==3) {
		if (n1==3)
			w.initialize(1,0,0,0,1,0,0,0,1);
		else
			w.initialize(0,0,1,0,1,0,1,0,0);
		}

	if (n==4)
			w.initialize(1,0,1,0,0,0,1,0,1);
	
	if (n==5)
			w.initialize(1,0,1,0,1,0,1,0,1);
	
	if (n==6) {
		if (n1==6)
			w.initialize(1,1,1,0,0,0,1,1,1);
		else
			w.initialize(1,0,1,1,0,1,1,0,1);										
		}
			
		w.draw(g);
		n1=n;
	}
}
//==========================================
class Wuerfel {

	int w1,w2,w3,w4,w5,w6,w7,w8,w9;
	static final int Radius=10;
	int a = 27;
	
void draw(Graphics g) {

	if (this.w1==1) g.fillOval(1*a-Radius,1*a-Radius,2*Radius,2*Radius); 
	if (this.w2==1) g.fillOval(2*a-Radius,1*a-Radius,2*Radius,2*Radius);
	if (this.w3==1) g.fillOval(3*a-Radius,1*a-Radius,2*Radius,2*Radius);
	if (this.w4==1) g.fillOval(1*a-Radius,2*a-Radius,2*Radius,2*Radius);
	if (this.w5==1) g.fillOval(2*a-Radius,2*a-Radius,2*Radius,2*Radius);
	if (this.w6==1) g.fillOval(3*a-Radius,2*a-Radius,2*Radius,2*Radius);
	if (this.w7==1) g.fillOval(1*a-Radius,3*a-Radius,2*Radius,2*Radius);
	if (this.w8==1) g.fillOval(2*a-Radius,3*a-Radius,2*Radius,2*Radius);
	if (this.w9==1) g.fillOval(3*a-Radius,3*a-Radius,2*Radius,2*Radius);
	}
	
void initialize(int w1,int w2,int w3,int w4,int w5,int w6,int w7,int w8,int w9) {
	this.w1 = w1;
	this.w2 = w2;
	this.w3 = w3;
	this.w4 = w4;
	this.w5 = w5;
	this.w6 = w6;
	this.w7 = w7;
	this.w8 = w8;
	this.w9 = w9;
	}

}

