/*beads.java Sieuwert van Otterloo smotterl@cs.uu.nl go.to/sieuwert March 2000 A mind game where the user must move colored disks around until all are in their own position.*/ import java.awt.*; class bead{ Color c,opposite;//it's color int rad;//painted size int num;//the number it has int x, y;//it's position bead(int i,float tot){ rad=17-(int)tot/3; num=i; c=Color.getHSBColor((float)(i/tot),1,1); if(c.getRed()+2*c.getGreen()+c.getBlue()>512) opposite=Color.black; else opposite=Color.white; } void set(int a,int b) /*move this bead to given position*/ {x=a;y=b;} void paint(Graphics g){ //paint this bead g.setColor(c); circle(g,x,y,rad); g.setColor(opposite); g.drawString(""+num,x-5,y+5); } static void circle(Graphics g,int i,int j,int rd) //draw a filled circle {g.fillOval(i-rd,j-rd,2*rd,2*rd);} } public class beads extends java.applet.Applet{ int B;/*total number of beads*/ int[] posx;/*horizontal position of beads*/ int[] posy;/*vertical position of beads*/ bead[] b;/*the beads*/ Color[] backcolor;/*colors of the large circles*/ boolean restart; Font font=new Font("Arial",Font.BOLD,14); int movecounter;/*the number of moves done*/ long timer;/*number of seconds user is buzy*/ int[] letterx,lettery; public void init(){ setBackground(Color.white); shuffle(5); /*the puzzle starts with 5 beads. If solved, it becomes harder.*/ } void shuffle(int total){ /*sets up a new game. total becomes the new number of beads.*/ B=total; if(B>17) B=17; //13 is maximum value backcolor=new Color[B]; for(int i=0;i