import java.applet.Applet; import java.applet.*; import java.awt.*; import java.awt.event.*; import java.awt.geom.*; public class mang_main extends Applet implements MouseListener{ int varvid[]; int kont[]; int x=0; int y=0; int i=0; int j=0; int k=0; int viimane=0; int X=0; int Y=0; int Z=0; int Z1=0; int v=0; int hiir=0; int praegune=0; public mang_main(){ varvid = new int[16]; varvid[0]=1; varvid[1]=1; varvid[2]=2; varvid[3]=2; varvid[4]=3; varvid[5]=3; varvid[6]=4; varvid[7]=4; varvid[8]=5; varvid[9]=5; varvid[10]=6; varvid[11]=6; varvid[12]=7; varvid[13]=7; varvid[14]=8; varvid[15]=8; for(int z=0; z<100; z++){ i=(int)(16*Math.random()); j=(int)(16*Math.random()); k=varvid[i]; varvid[i]=varvid[j]; varvid[j]=k; } kont = new int [16]; kont[0]=0; kont[1]=0; kont[2]=0; kont[3]=0; kont[4]=0; kont[5]=0; kont[6]=0; kont[7]=0; kont[8]=0; kont[9]=0; kont[10]=0; kont[11]=0; kont[12]=0; kont[13]=0; kont[14]=0; kont[15]=0; addMouseListener(this); } public void paint(Graphics g){ Graphics2D g2=(Graphics2D)g; BasicStroke bs1=new BasicStroke(4); g2.setColor(Color.black); g2.setStroke(bs1); g2.drawLine(10, 10, 210, 10); g2.drawLine(10, 60, 210, 60); g2.drawLine(10, 110, 210, 110); g2.drawLine(10, 160, 210, 160); g2.drawLine(10, 210, 210, 210); g2.drawLine(10, 10, 10, 210); g2.drawLine(60, 10, 60, 210); g2.drawLine(110, 10, 110, 210); g2.drawLine(160, 10, 160, 210); g2.drawLine(210, 10, 210, 210); g.setColor(Color.gray); BasicStroke bs0=new BasicStroke(1); g2.setStroke(bs0); // I rida X=12; Y=12; j=0; i=0; v=0; while(i<4){ while(j<4){ if(kont[v]==1){ if(varvid[v]==1){g.setColor(Color.red);} if(varvid[v]==2){g.setColor(Color.green);} if(varvid[v]==3){g.setColor(Color.blue);} if(varvid[v]==4){g.setColor(Color.yellow);} if(varvid[v]==5){g.setColor(Color.white);} if(varvid[v]==6){g.setColor(Color.cyan);} if(varvid[v]==7){g.setColor(Color.orange);} if(varvid[v]==8){g.setColor(Color.magenta);} } g.fillRect(X, Y, 46, 46); X=X+50; j=j+1; g.setColor(Color.gray); v=v+1; } i=i+1; X=12; Y=Y+50; j=0; } X=12; Y=12; j=0; i=0; Z=0; Z1=0; v=0; while(i<4){ while(j<4){ if(varvid[v]==1){g.setColor(Color.red);} if(varvid[v]==2){g.setColor(Color.green);} if(varvid[v]==3){g.setColor(Color.blue);} if(varvid[v]==4){g.setColor(Color.yellow);} if(varvid[v]==5){g.setColor(Color.white);} if(varvid[v]==6){g.setColor(Color.cyan);} if(varvid[v]==7){g.setColor(Color.orange);} if(varvid[v]==8){g.setColor(Color.magenta);} if(x>12+Z){if(x<62+Z){if(y>12+Z1){if(y<62+Z1){g.fillRect(X, Y, 46, 46);if(hiir==1){viimane=v;}if(hiir==2){praegune=v;}}}}} X=X+50; Z=Z+50; j=j+1; v=v+1; } Z=0; i=i+1; X=12; Y=Y+50; Z1=Z1+50; j=0; } if(hiir==2){ hiir=0; System.out.println(varvid[viimane]); System.out.println(varvid[praegune]); if(varvid[viimane]==varvid[praegune]){ kont[viimane]=1; kont[praegune]=1; } } hiir=hiir+1; } public void mousePressed(MouseEvent e){ x=e.getX(); y=e.getY(); repaint(); } public void mouseReleased(MouseEvent e){} public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public static void main(String argumendid[]){ Frame f=new Frame(); f.setSize(300, 300); f.setBackground(Color.blue); f.add(new mang_main()); f.setVisible(true); } }