import java.io.*; import java.awt.event.*; import java.util.*; import java.awt.*; import java.applet.Applet; public class trull extends Applet implements MouseListener{ int x,y,xm,ym,a; int[][] ristid = new int[3][3]; boolean on=true; boolean tais=true; int olek=0; String tulemus; public trull(){ addMouseListener(this); a=0; } public void paint (Graphics g){ g.drawLine(150,50,150,200); g.drawLine(200,50,200,200); g.drawLine(100,100,250,100); g.drawLine(100,150,250,150); if (olek==0){ tais=true; for (int f=0; f<3; f++){ for (int h=0; h<3; h++){ if (ristid[h][f]==1){ g.drawLine(h*50+102,f*50+52,(h*50+100)+48,(f*50+50)+48); g.drawLine(h*50+148,f*50+52,h*50+102,f*50+50+48); } if (ristid[h][f]==2){ g.drawOval(h*50+102,f*50+52,46,46); } if(ristid[h][f]==0){ tais=false; } } } } if (olek==1){ g.drawString(tulemus,160,250); try{ Thread.sleep(4000); }catch(Exception c){} System.exit(0); } } public void mousePressed(MouseEvent e){ int x=((int)(e.getX()/50))-2; int y=((int)(e.getY()/50))-1; if (!tais&&x>=0&&x<=2&&y>=0&&y<=2&&ristid[x][y]!=1&&ristid[x][y]!=2){ a++; ristid[x][y]=1; while(on){ xm=(int)(Math.random()*3); ym=(int)(Math.random()*3); if (ristid[xm][ym]!=1&&ristid[xm][ym]!=2||a>4)on=false; } if(a<5)ristid[xm][ym]=2; paint(getGraphics()); on=true; } boolean risttaish=true; boolean ringtaish=true; boolean risttaisv=true; boolean ringtaisv=true; boolean ringd=false; boolean ristd=false; for (int f=0; f<3; f++){ for (int h=0; h<3; h++){ if (ristid[h][f]!=1)risttaish=false; if (ristid[h][f]!=2)ringtaish=false; if (ristid[f][h]!=1)risttaisv=false; if (ristid[f][h]!=2)ringtaisv=false; } if (risttaish){ olek=1; tulemus="RISTID VÕITSID"; } if (risttaisv){ olek=1; tulemus="RISTID VÕITSID"; } if (ringtaish){ olek=1; tulemus="SÕÕRID VÕITSID"; } if (ringtaisv){ olek=1; tulemus="SÕÕRID VÕITSID"; } if(ristid[0][0]==1&&ristid[1][1]==1&&ristid[2][2]==1||ristid[2][0]==1&&ristid[1][1]==1&&ristid[0][2]==1){ olek=1; ristd=true; tulemus="RISTID VÕITSID"; } if(ristid[0][0]==2&&ristid[1][1]==2&&ristid[2][2]==2||ristid[2][0]==2&&ristid[1][1]==2&&ristid[0][2]==2){ olek=1; ringd=true; tulemus="SÕÕRID VÕITSID"; } if (tais&&!risttaish&&!risttaisv&&!ringtaish&&!ringtaisv&&!ringd&&!ristd){ olek=1; tulemus="VIIK"; //tais=true; } risttaish=true; risttaisv=true; ringtaish=true; ringtaisv=true; } paint(getGraphics()); } 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("Trips-traps-trull against the machine"); f.setSize(50*3+200,50*3+150); f.setResizable(false); f.add(new trull()); f.setVisible(true); f.addWindowListener(new akenkinni()); } } class akenkinni extends WindowAdapter{ public void windowClosing(WindowEvent e){ System.exit(0); } }