import java.applet.*; import java.awt.*; public class Nu extends Applet{ int a,b,c,kount,n; int vali[]; Image pic[]; public void init(){ n=0; vali=new int[9]; pic=new Image[3]; for(int t=0;t<=2;t++){ pic[t]=getImage(getDocumentBase(),""+t+".jpg"); } for (int q=0;q<=8;q++){ vali[q]=0; } } public void paint(Graphics g){ g.drawLine(0,100,300,100); g.drawLine(0,200,300,200); g.drawLine(100,0,100,300); g.drawLine(200,0,200,300); for(int u=0;u<=8;u++){ g.drawImage(pic[vali[u]],(u-3*(int)((u)/3))*100+2,((int)(u/3))*100+2,this); } } public boolean mouseDown(Event e,int x,int y){ a=(int)(x/100); b=(int)(y/100); c=b*3+a; if(vali[c]==0){ vali[c]=1; n=n+1; repaint(); konec(); while(vali[c]!=0){ c=(int)(9*Math.random()); } vali[c]=2; repaint(); n=n+1; konec(); } return true; } public void konec(){ kount=0; for(int q=1;q<=2;q++){ if(vali[0]==q&vali[1]==q&vali[2]==q){kount=q;} if(vali[0]==q&vali[4]==q&vali[8]==q){kount=q;} if(vali[0]==q&vali[3]==q&vali[6]==q){kount=q;} if(vali[1]==q&vali[4]==q&vali[7]==q){kount=q;} if(vali[2]==q&vali[5]==q&vali[8]==q){kount=q;} if(vali[3]==q&vali[4]==q&vali[5]==q){kount=q;} if(vali[2]==q&vali[4]==q&vali[6]==q){kount=q;} if(vali[6]==q&vali[7]==q&vali[8]==q){kount=q;} if(q==1){ if(kount==1){showStatus("You won last game!");q=5;} else{kount=0;}} if(kount==2){showStatus("I won last game!");} } if(kount!=0){ for(int r=0;r<=8;r++){vali[r]=0;n=0;} } if((kount==0)&(n==9)){showStatus("A draw"); for(int r=0;r<=8;r++){vali[r]=0;n=0;} } } }