import java.util.*; import java.awt.*; public class General { public Image image; int teller=0; int pos=0; int object=0; // which object are we working for? boolean walk=false; boolean stopit=false; // player stop on ice public Global global; boolean ready=false; // Used by ice .. if all objects have been moved ... int icepos; int below=0; int current1=74; int current2=0; int current3=0; int current=74; // what is the next ice position int ICE=100; int iceplaces[]=new int[ICE]; boolean pushice=false; int state=0; boolean debug=false; int x; int y; public void init(Global glbl){ } public General(Global glbl, int o){ global=glbl; object=o; icepos=0; } public int getImageBehind(){ int o1=0; if(global.dir==global.STEPP) o1=global.grid.getxy(global.player.getX()+global.STEPP*2,global.player.getY()); if(global.dir==-global.STEPP) o1=global.grid.getxy(global.player.getX()-global.STEPP*2, global.player.getY()); if(global.dir==global.STEPP*global.WIDTH) o1=global.grid.getxy(global.player.getX(),global.player.getY()+(2*global.STEPP)); if(global.dir==-global.STEPP*global.WIDTH) o1=global.grid.getxy(global.player.getX(),global.player.getY()-(2*global.STEPP)); return o1; } public int getBehind(){ int o1=getImageBehind(); o1=global.grid.getNr(o1); return o1; } public String toString(){ return "General"; } public void action1(){ if(debug)System.out.println("Action1 ==> move stone!!!"); // state=1; } public void resetice(){ pushice=true; icepos=0; stopit=false; global.boardrow=-1; global.boardcol=-1; global.doboard=true; global.PLAYERSTATE=1; current1=74; current2=0; current3=0; below=0; ready=false; } // // Pushed to ice // // Move the object to the end of the ice/first blocking object // // ice = object 74 // public int ice(int stat){ int state=stat; global.PLAYERSTATE=1; global.freeze=true; // Stone pushing!! int P=global.STEPP; int x=0; int y=0; int OLD=1; // make all empty places ice again (after push some are 1) for(int i=0;i global.STEPP-2){ pos=0; if(ready ){ state=state+1; ready=false; pushice=false; global.freeze=false; icepos=0; stopit=false; global.boardrow=-1; global.boardcol=-1; global.doboard=true; global.State=global.WALK; global.PLAYERSTATE=0; current1=74; current2=0; current3=0; below=0; ready=false; return state; } global.stap=global.STEPP; teller=0; } // what is the posistion of the player? x=global.player.getX(); y=global.player.getY(); int cx=0; // Current position of object int cy=0; int px=0; // Previous Position of object int py=0; OLD=74; below=0; // Left if(global.dir == -global.STEPP){ current1=global.grid.getxy(x-icepos-(2*P),y); if(current1!=74 && pushice) stopit=true;else stopit=false; if(!stopit) if(object==74)global.player.set(x-P,y); else{ if(icepos < global.STEPP)global.grid.setxy(x-global.STEPP,y,1); global.grid.setxy(x-P-icepos, y, OLD); global.grid.setxy(x-(icepos)-P-P, y,object); } below=global.grid.getxy(x-P-P,y); current=global.grid.getxy(x-(icepos)-P-P,y); cx=x-(icepos)-P-P-P-P; cy=y; px=cx+P; py=cy; current2=global.grid.getxy(cx,cy); } // Right if(global.dir == global.STEPP){ current1=global.grid.getxy(x+icepos+(2*P), y); if(current1!=74 && pushice)stopit=true;else stopit=false; if(!stopit) if(object==74) global.player.set(x+P,y); else{ global.grid.setxy(x+P+(icepos), y, OLD); if(icepos < global.STEPP)global.grid.setxy(x+global.STEPP,y,1); global.grid.setxy(x+(icepos)+P+P, y, object); } below=global.grid.getxy(x+P+P,y); current=global.grid.getxy(x+(icepos)+P,y); cx=x+(icepos)+P+P+P+P; cy=y; px=cx-P; py=cy; current2=global.grid.getxy(cx,cy); } // down if(global.dir == global.STEPP*global.WIDTH){ current1=global.grid.getxy(x, y+icepos+(2*P)); if(current1!=74 && pushice)stopit=true;else stopit=false; if(!stopit) if(object==74) global.player.set(x, y+P); else{ if(icepos < global.STEPP)global.grid.setxy(x,y+global.STEPP,1); global.grid.setxy(x, y+P+(icepos), OLD); global.grid.setxy(x,y+(icepos)+P+P,object); } below=global.grid.getxy(x,y+P+P); current=global.grid.getxy(x,y+(icepos)+P); cy=y+(icepos)+P+P+P+P; cx=x; py=cy-P; px=cx; current2=global.grid.getxy(cx,cy); } // up if(global.dir == -global.STEPP*global.WIDTH){ // pushing object ahead look current1=global.grid.getxy(x, y-icepos-(2*P)); if(current1!=74 && pushice)stopit=true; if(!stopit) if(object==74) global.player.set(x, y-P); else{ if(icepos < global.STEPP)global.grid.setxy(x,y-global.STEPP,1); global.grid.setxy(x,y-P-(icepos),OLD); global.grid.setxy(x,y-(icepos)-P-P,object); } below=global.grid.getxy(x,y-P-P); current=global.grid.getxy(x,y-(icepos)-P); cy=y-(icepos)-P-P-P-P; cx=x; current2=global.grid.getxy(cx,cy); py=cy+P; px=cx; } //System.out.println( "Below: "+below+" current2: "+ current2+" current3: "+current3+" object: "+object+" currnt1: "+current1); if((current3 == 1 || current3 == -1 ) && object != 74){ ready=true; pos=global.STEPP+2; stopit=false; } if( ((below !=1 && below != 74) || below == -1 )&& object == 74){ ready=true;pos=global.STEPP+2;stopit=false; } // // ???? Are we going to do 'wak' // // You fall in hole if(below == 76 ){ if(object==74){ ready=true; pos=global.STEPP+2; stopit=true; state=state+1; global.setInfo("You fall in the ice"); global.doreload=true; } } // object glides in hole if(current2 == 76 && object != 74){ // object disapears in hole global.grid.setxy(px,py,74); } // ---- current3=current2; // // when object was stuck and we pushed it away // make sure that the background object is replaced by 74 (ice) // for(int i=0;i global.STEPP-2){ pos=0; if(ready ){ state=state+1; ready=false; pushice=false; global.freeze=false; icepos=0; stopit=false; global.boardrow=-1; global.boardcol=-1; global.doboard=true; global.State=global.WALK; global.PLAYERSTATE=0; current1=74; current2=0; current3=0; below=0; ready=false; return state; } global.stap=global.STEPP; teller=0; } // what is the posistion of the player? x=global.player.getX(); y=global.player.getY(); int cx=0; // Current position of object int cy=0; int px=0; // Previous Position of object int py=0; OLD=74; below=0; System.out.println("P = "+P); // Left if(global.dir == -global.STEPP){ if(icepos > 0){ current1=global.grid.getxy(x-icepos-(3*P),y); System.out.println("current1 : "+current1); } if(current1!=74 && pushice) stopit=true; if(!stopit) if(object==74)global.player.set(x-P,y); else{ if(icepos < global.STEPP)global.grid.setxy(x-global.STEPP,y,1); global.grid.setxy(x-P-P-icepos, y, OLD); global.grid.setxy(x-(icepos)-P-P-P, y,object); } below=global.grid.getxy(x-P-P,y); current=global.grid.getxy(x-(icepos)-P-P,y); cx=x-(icepos)-P-P-P-P; cy=y; px=cx+P; py=cy; current2=global.grid.getxy(cx,cy); } // Right if(global.dir == global.STEPP){ // if(icepos > 0) current1=global.grid.getxy(x+icepos+(2*P), y); System.out.println("current1 : "+current1); System.out.println( global.grid.getxy(x+icepos, y)); System.out.println("What is ahead: "+ global.grid.getxy(x+icepos+(2*P), y)); System.out.println( global.grid.getxy(x+icepos+(3*P), y)); System.out.println( global.grid.getxy(x+icepos+(4*P), y)); System.out.println( global.grid.getxy(x+icepos+(5*P), y)); System.out.println( global.grid.getxy(x+icepos+(6*P), y)); if(current1!=74 && pushice)stopit=true;else stopit=false; if(!stopit) if(object==74) global.player.set(x+P,y); else{ global.grid.setxy(x+P+P+(icepos), y, OLD); if(icepos < global.STEPP)global.grid.setxy(x+global.STEPP,y,1); // Was (before object 13 went wrong) // global.grid.setxy(x+(icepos)+P+P+P, y, object); global.grid.setxy(x+(icepos)+P+P, y, object); } below=global.grid.getxy(x+P+P,y); current=global.grid.getxy(x+(icepos)+P,y); cx=x+(icepos)+P+P+P+P; cy=y; px=cx-P; py=cy; current2=global.grid.getxy(cx,cy); } // down if(global.dir == global.STEPP*global.WIDTH){ if(icepos > 0) current1=global.grid.getxy(x, y+icepos+(3*P)); System.out.println("current1 : "+current1); if(current1!=74 && pushice)stopit=true; if(!stopit) if(object==74) global.player.set(x, y+P); else{ if(icepos < global.STEPP)global.grid.setxy(x,y+global.STEPP,1); global.grid.setxy(x, y+P+P+(icepos), OLD); global.grid.setxy(x,y+(icepos)+P+P+P,object); } below=global.grid.getxy(x,y+P+P); current=global.grid.getxy(x,y+(icepos)+P); cy=y+(icepos)+P+P+P+P; cx=x; py=cy-P; px=cx; current2=global.grid.getxy(cx,cy); } // up if(global.dir == -global.STEPP*global.WIDTH){ // pushing object ahead look if(icepos > 0) current1=global.grid.getxy(x, y-icepos-(3*P)); System.out.println("current1 : "+current1); if(current1!=74 && pushice)stopit=true; if(!stopit) if(object==74) global.player.set(x, y-P); else{ if(icepos < global.STEPP)global.grid.setxy(x,y-global.STEPP,1); global.grid.setxy(x,y-P-P-(icepos),OLD); global.grid.setxy(x,y-(icepos)-P-P-P,object); } below=global.grid.getxy(x,y-P-P); current=global.grid.getxy(x,y-(icepos)-P); cy=y-(icepos)-P-P-P-P; cx=x; current2=global.grid.getxy(cx,cy); py=cy+P; px=cx; } System.out.println( "Below: "+below+" current2: "+ current2+" current3: "+current3+" object: "+object+" currnt1: "+current1); if((current3 == 1 || current3 == -1 ) && object != 74){ ready=true; pos=global.STEPP+2; stopit=false; } /* if( (current2 != 74 && current2 != object && current2 != 1 && current2 != OLD) && object != 74 || stopit) { ready=true; pos=global.STEPP+2; stopit=false; } */ if( ((below !=1 && below != 74) || below == -1 )&& object == 74){ ready=true;pos=global.STEPP+2;stopit=false; } /* if( (below == 1 )&& object == 74){ stopit=true; } */ // // ???? Are we going to do 'wak' // // You fall in hole if(below == 76 ){ if(object==74){ ready=true; pos=global.STEPP+2; stopit=true; state=state+1; global.setInfo("You fall in the ice"); global.doreload=true; } } // object glides in hole if(current2 == 76 && object != 74){ // object disapears in hole global.grid.setxy(px,py,74); } // ---- current3=current2; // // when object was stuck and we pushed it away // make sure that the background object is replaced by 74 (ice) // for(int i=0;i global.STEPP-2){ pos=0; //System.out.println("General-Push -> returning state + 1 (41?)"); state=state+1; global.stap=global.STEPP; teller=0; } // Move image of player if(global.stap > 0)global.stap--;else global.stap=global.STEPP; // what is the posistion of the player? x=global.player.getX(); y=global.player.getY(); if(debug)System.out.println("Event1 on General player: "+x+","+y+" "+" STEPP % X"+(x%global.STEPP)+" Y%STEPP "+(y%global.STEPP)); // Left if(global.dir == -global.STEPP){ global.grid.setxy(x-(global.STEPP)-P, y,object); global.grid.setxy(x-global.STEPP, y,1); global.player.set(x-P,y); } // Right if(global.dir == global.STEPP){ global.grid.setxy(x+(global.STEPP)+P, y, object); global.grid.setxy(x+global.STEPP, y, 1); global.player.set(x+P,y); } // down if(global.dir == global.STEPP*global.WIDTH){ global.grid.setxy(x,y+(global.STEPP)+P,object); global.grid.setxy(x,y+(global.STEPP),1); global.player.set(x, y+P); } // up if(global.dir == -global.STEPP*global.WIDTH){ global.grid.setxy(x,y-(global.STEPP)-P,object); global.grid.setxy(x,y-(global.STEPP),1); global.player.set(x, y-P); } // Commented due to strange menu - display (level display) when you are pushing global.State=global.WALK; return state; } public void event1(){} public void action3(){ System.out.println("GENERAL - Action3 ... CAN WE REMOVE!"); } public void action4(){ System.out.println("GENERAL - Action4 ... CAN WE REMOVE!"); // state=40; } public void event40(){ System.out.println("GENERAL - Action4 ... CAN WE REMOVE!"); } public void event30(){ } 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 void event(){ // put everything here like a 'run' method switch(state){ case 1: event1(); break; case 2: event2();break; case 40: event40(); break; case 41: event41(); break; case 30: event30(); break; case 31: event31(); break; } // draw image } public void event2(){ System.out.println("GENERAL - event2 ... CAN WE REMOVE!"); } // After hole -> Leave empty! public void event41(){ System.out.println("GENERAL - event41 ... CAN WE REMOVE!"); } // After water -> stone in water public void event31(){ System.out.println("Event31 - General .. can we remove? "); } // public void resetevent(){ System.out.println("RESET ON GENERAL .."); } }