import java.util.*; import java.awt.*; public class object402 extends object{ public Image img; public Sound sound; public Sound throwing; public Sound fall; public Sound splash; int o1=0; int o=-1; int MX=-1; int MY=-1; int state=0; boolean debug=false; String methods[]={ "hit", "action1", "event", "event1", "event2", "resetevent", "event40", "event41", "action406", "action931", "action4", "action3", ""}; public void init(Global glbl){ global=glbl; if(image==null){ image=global.loadImage(global.Server, global.Directory+"402"+global.Extention, global.show); img=global.loadImage(global.Server, global.Directory+"402_406"+global.Extention, global.show); sound=global.loadSound(global.Server, global.Directory+"400.au"); splash=global.loadSound(global.Server, global.Directory+"3.au"); fall=global.loadSound(global.Server, global.Directory+"400_404.au"); throwing=global.loadSound(global.Server, global.Directory+"2_5.au"); } objnumber=402; MX=-1; MY=-1; general=new General(global,getNr()); } public void execute(){ if(method.compareTo("action1")==0) action1(); if(method.compareTo("event")==0) event(); if(method.compareTo("resetevent")==0) resetevent(); if(method.compareTo("event1")==0) event1(); if(method.compareTo("event2")==0) event2(); if(method.compareTo("event40")==0) event40(); if(method.compareTo("action406")==0) action406(); if(method.compareTo("action3")==0) action3(); if(method.compareTo("action4")==0) action4(); if(method.compareTo("action205")==0) action205(); if(method.compareTo("action206")==0) action206(); if(method.compareTo("action207")==0) action207(); if(method.compareTo("action208")==0) action208(); if(method.compareTo("action209")==0) action209(); if(method.compareTo("action210")==0) action210(); if(method.compareTo("action211")==0) action211(); if(method.compareTo("action212")==0) action212(); if(method.compareTo("action213")==0) action213(); if(method.compareTo("action214")==0) action214(); if(method.compareTo("action215")==0) action215(); if(method.compareTo("action216")==0) action216(); if(method.compareTo("action217")==0) action217(); if(method.compareTo("action218")==0) action218(); if(method.compareTo("hit")==0){ hit(); return; } } public boolean is(String meth){ boolean retval=false; int m=methods.length; for(int i=0; i < m && !retval; i++){ if(methods[i].compareTo(meth) == 0) retval=true; } return retval; } public void hit(){ global.waitforme=true; if(sound!=null && global.playsound)sound.play(); o1=general.getBehind(); String l="action"+o1; if(is(l)){ setMethod(l); execute(); } } public String toString(){ return "object402"; } public void action1(){ // Wait for all ball-actions to complete! System.out.println("Start push"); o=objnumber; MX=-1; global.freeze=true; state=5; } // Move to the first - non - 1 public void event5(){ int x,y; x=global.player.getX(); y=global.player.getY(); if(MX < 0){ MX=x; MY=y; } int oldx=MX;int oldy=MY; global.grid.setxy(MX,MY,1); if(global.dir == -global.STEPP){ if(MX==x){MX-=global.STEPP;global.grid.setxy(MX,MY,1);} MX-=global.STEPP; } // Right if(global.dir == global.STEPP){ if(MX==x){MX+=global.STEPP;global.grid.setxy(MX,MY,1);} MX+=global.STEPP; } // down if(global.dir == global.STEPP*global.WIDTH){ if(MY==y){MY+=global.STEPP;global.grid.setxy(MX,MY,1);} MY+=global.STEPP; } // up if(global.dir == -global.STEPP*global.WIDTH){ if(MY==y){MY-=global.STEPP;global.grid.setxy(MX,MY,1);} MY-=global.STEPP; } int c=global.grid.getxy(MX,MY); //System.out.println( "found : "+c); if(c==1 ){ // Nothing global.grid.setxy(MX,MY,o); }else{ if(c > 399 && c < 404){ // No basket but other ball .. so go on to the next //System.out.println("Other BALL!"); if(MX==x && MY==y){ //System.out.println("Player place"); global.grid.setxy(MX,MY,1); }else{ //System.out.println("Switching balls"); global.grid.setxy(oldx,oldy,o); global.grid.setxy(MX,MY,c); } o=c; }else{ // Leave object where it should be global.grid.setxy(oldx,oldy,o); state=6; } } global.boardrow=-1; global.boardcol=-1; global.doboard=true; } public void saction1(){ //if(debug)System.out.println("Action1 ==> move stone!!!"); state=1; } // Action methods public void event1(){ if(general != null) state=general.push(state); } public void action406(){ global.PLAYERSTATE=1; if(global.playsound) if(throwing!=null) throwing.play(); state=40; } public void event40(){ state=general.throwit(state); // state + 1 is returned -> event41 global.PLAYERSTATE=1; global.freeze=false; global.aftermoves=true; state=41; } public void event41(){ // Search for 402 in grid int founder=global.grid.nextNr(0,0,402); if(founder<0){ int x=global.player.getX(); int y=global.player.getY(); if(global.dir == -global.STEPP){ x-=global.STEPP; } // Right if(global.dir == global.STEPP){ x+=global.STEPP; } // down if(global.dir == global.STEPP*global.WIDTH){ y+=global.STEPP; } // up if(global.dir == -global.STEPP*global.WIDTH){ y-=global.STEPP; } global.grid.setxy(x, y,1); int s=((y+global.STEPP)*global.WIDTH)+x; global.show.changeBackground(img, s); }else { if(global.playsound) fall.play(); } global.waitforme=false; global.aftermoves=true; global.State=global.PUSH; global.boardrow=-1; global.boardcol=-1; global.doboard=true; state=43; } public void action3(){ // do nothing } public void action4(){ // Do nothing .. since if we drop the ball in a hole it disappears -> changes state of 404 } public void action205(){action3();} public void action206(){action3();} public void action207(){action3();} public void action208(){action3();} public void action209(){action3();} public void action210(){action3();} public void action211(){action3();} public void action212(){action3();} public void action213(){action3();} public void action214(){action3();} public void action215(){action3();} public void action216(){action3();} public void action217(){action3();} public void action218(){action3();} public int getNr(){return 402;} public void event(){ // put everything here like a 'run' method switch(state){ case 1: event1(); break; case 2: event2(); break; case 5: event5(); break; case 6: event6();break; case 40: event40();break; case 41: event41();break; } // draw image } public void event2(){ global.freeze=false; global.waitforme=false; global.aftermoves=true; global.State=global.NOTHING; state=3; } public void event6(){ global.freeze=false; global.waitforme=false; global.aftermoves=true; global.State=global.NOTHING; MX=-1; MY=-1; state=3; } public void resetevent(){ if(global.object==getNr() && global.perform) if(global.STEPP==1) state=0; else state=1; } }