import java.awt.*; import java.applet.*; public class nim extends Applet{ String str="Youe move"; Choice os = new Choice(); Button bu1= new Button("Start"); Button bu2=new Button("Next move"); Choice tf1=new Choice(); TextField tf2=new TextField("?"); Choice os2=new Choice(); Choice os3=new Choice(); TextField tf3=new TextField("Processing"); boolean nacal,toplay=false,konec=false; int n,m,r,p; String level; char plr; public void init(){ setLayout(null); os.addItem("Loser"); os.addItem("Novice"); os.addItem("Master"); os.addItem("Crook"); tf1.addItem("Total number"); tf1.addItem(""+25); tf1.addItem(""+32); tf1.addItem(""+36); tf1.addItem(""+43); tf1.addItem(""+48); os2.addItem("Max possible"); for(int t=5;t<11;t++){ os2.addItem(""+t);} os3.addItem("Computer"); os3.addItem("Human"); add(os); add(tf1); add(os2); add(os3); add(bu1); add(tf2); add(bu2); add(tf3); os.reshape(0,0,60,10); tf1.reshape(60,0,100,10); os2.reshape(160,0,100,10); os3.reshape(260,0,90,10); bu1.reshape(180,30,90,42); tf2.reshape(180,80,40,20); bu2.reshape(230,80,60,20); tf3.reshape(180,110,160,20); Graphics g=this.getGraphics(); g.setColor(Color.pink); g.fillRect(0,0,400,300); } public void start(){ Graphics g=this.getGraphics(); g.setColor(Color.pink); g.fillRect(0,0,400,300); } public boolean action(Event e,Object o) { Graphics g=this.getGraphics(); g.setColor(Color.pink); g.fillRect(0,0,350,250); g.setColor(Color.blue); if (nacal){ if (toplay){ r=Integer.parseInt(tf2.getText().trim()); if (r<=0){r=1;} if (r>m){r=m;} if (r>n){r=n;} n=n-r; g.setColor(Color.pink); g.fillRect(0,0,350,250); g.setColor(Color.blue); p=0; for(int k=1;k<7;k++){ for(int l=1;l<9;l++){ p=p+1; if(p>n){break;} g.drawOval(20*l,30*k+40,13,13); g.fillOval(20*l,30*k+40,13,13);}} if (n==0){ tf3.setText("You won !"); konec=true; } } if(n>0){ if (level.equals("Loser")){ if (m=n){r=n;} else{ for (int k=1;k<=Math.min(m,n);k++){ for (int i=0;i<11;i++){ if (i*m==n-k-1){r=k;break;} } } } } if (level.equals("Crook")){ if (n<=m+2){r=n;} else {r=(int)(m*Math.random())+1;} } n=n-r; toplay=true; g.setColor(Color.pink); g.fillRect(0,0,350,250); g.setColor(Color.blue); p=0; for(int k=1;k<7;k++){ for(int l=1;l<9;l++){ p=p+1; if(p>n){break;} g.drawOval(20*l,30*k+40,13,13); g.fillOval(20*l,30*k+40,13,13);}} if (n==0){tf3.setText("I won !");konec=true;} } } else{ if (o.equals("Start")){ level=os.getSelectedItem(); if((os2.getSelectedItem()).equals("Max possible")){m=10;}else {m=Integer.parseInt(os2.getSelectedItem().trim());} if((tf1.getSelectedItem()).equals("Total number")){n=48;}else {n=Integer.parseInt(tf1.getSelectedItem().trim());} if((os3.getSelectedItem()).equals("Computer")){toplay=false;} tf3.setText("Processing"); p=0; g.setColor(Color.blue); for(int k=1;k<7;k++){ for(int l=1;l<9;l++){ p=p+1; if(p>n){break;} g.drawOval(20*l,30*k+40,13,13); g.fillOval(20*l,30*k+40,13,13);}} nacal=true; konec=false; } } if (konec){nacal=false;} return false; } }