import java.util.*; import java.awt.*; // // Candy // // Grow - grow - grow -- snake // // public class object170 extends object{ int state=0; boolean debug=false; Image image1; Image image2; Image img; Sound sound2; int o1=0; // behind int i1=0; // imagebehind int x; int y; public General general; public Sound throwing; boolean filled=false; int length=0; public object170(){ objnumber=170; methods[0]="hit"; methods[1]="action1"; methods[2]="resetevent"; methods[3]="event"; methods[4]="aftermove"; } public void init(Global glbl){ global=glbl; if(image == null){ image1=global.loadImage(global.Server, global.Directory+"170"+global.Extention, global.show); } throwing=global.loadSound(global.Server, global.Directory+"170.au"); sound2=global.loadSound(global.Server, global.Directory+"171.au"); general=new General(global,getNr()); filled=false; image=image1; } public void execute(){ if(method.compareTo("action1")==0) action1(); if(method.compareTo("event")==0) event(); if(method.compareTo("resetevent")==0) resetevent(); if(method.compareTo("aftermove")==0) aftermove(); if(method.compareTo("hit")==0){ hit(); return; } } // Hit the crate/wood public void hit(){ if(global.countBag(153)==5) { if(global.playsound){ sound2.play(); } int nr=global.grid.next(0,0,170); global.grid.set(nr,1); global.boardrow=-1;global.boardcol=-1; global.doboard=true; } // removes when there are no more } // Action 1 -> background behind the crate/wood public void action1(){ state=1; } public void event(){ switch(state){ case 1: event1(); break; case 2: event2();break; case 3: break; } // draw image } // Action methods public void event1(){ if(general != null) state=general.push(state); else System.out.println("General is null"); } public void event2(){ global.freeze=false; global.aftermoves=true; global.resetevent=true; global.waitforme=false; state=3; } public void event40(){ state=general.push(state); // state + 1 is returned -> event41 } // After hole -> Leave empty! public void event41(){ x=global.player.getX(); 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+1)*global.WIDTH)+x; global.freeze=false; state=43; // do nothing global.doboard=true; global.resetevent=true; // Reset the event global.waitforme=false; // Ready with pushing global.aftermoves=true; // We can execute the aftermoves } public void aftermove(){ // make sure that the length of the snake is correct int x=global.player.getX(); int y=global.player.getY(); if(global.dir == global.STEPP){ x-=global.STEPP; } if(global.dir == -global.STEPP){ x+=global.STEPP; } if(global.dir == global.STEPP*global.WIDTH){ y-=global.STEPP; } if(global.dir == -global.STEPP*global.WIDTH){ y+=global.STEPP; } // make old pos int nr=global.countBag(153); int n,n0,n1,n2,n3=0; if(nr > 0){ int o=global.grid.getxy(x,y); //System.out.println("object on place of old player:"+o); if(o==1){ Date d=new Date(); if(global.playsound && d.getTime()%1000 < 50 )sound2.play(); switch(nr){ case 1: n=global.grid.next(0,0,171); if(n > 0) global.grid.set(n,1); break; case 2: n=global.grid.next(0,0,172); global.grid.set(n,1); n=global.grid.next(0,0,171); global.grid.set(n,172); break; case 3: n1=global.grid.next(0,0,173); n2=global.grid.next(0,0,172); n3=global.grid.next(0,0,171); global.grid.set(n1,1); global.grid.set(n2,173); global.grid.set(n3,172); break; case 4: n0=global.grid.next(0,0,202); n1=global.grid.next(0,0,173); n2=global.grid.next(0,0,172); n3=global.grid.next(0,0,171); global.grid.set(n0,1); global.grid.set(n1,202); global.grid.set(n2,173); global.grid.set(n3,172); break; case 5: n=global.grid.next(0,0,203); n0=global.grid.next(0,0,202); n1=global.grid.next(0,0,173); n2=global.grid.next(0,0,172); n3=global.grid.next(0,0,171); global.grid.set(n,1); global.grid.set(n0,203); global.grid.set(n1,202); global.grid.set(n2,173); global.grid.set(n3,172); break; } global.grid.setxy(x,y,171); global.boardrow=-1;global.boardcol=-1;global.doboard=true; } } // object171 is a snake-part // object172 is finish } // public void resetevent(){ if(global.object==getNr() && global.perform) if(global.STEPP==1) state=0; else state=1; } }