import java.util.*; import java.awt.*; // // End point of memory // // public class object224 extends object{ // calculate the random cards private static Random random = new Random(); int state=0; long oldtime=0; Image oldimage; // When card is turned it should be put back int anim[]=new int[10]; public object224(){ anim[0]=43; anim[1]=44; anim[2]=179; anim[3]=199; objnumber=224; methods[0]="hit"; methods[1]="resetevent"; methods[2]="event"; } public void init(Global glbl){ global=glbl; //System.out.println("object 224 init!"); if(image == null){ image=global.loadImage(global.Server, global.Directory+"224"+global.Extention, global.show); oldimage=image; } sound=global.loadSound(global.Server, global.Directory+"224.au"); Date d=new Date(); oldtime=(long)d.getTime(); //System.out.println("husle 224"); husle(); } public void execute(){ if(method.compareTo("event")==0) event(); if(method.compareTo("resetevent")==0) resetevent(); if(method.compareTo("hit")==0){ hit(); return; } } // Hit the crate/wood public void hit(){ } public void event(){ //System.out.println("object224.event"); } public void resetevent(){ System.out.println("Resetevent on object224"); husle(); } // Display public void display(){ global.boardrow=-1; global.boardcol=-1; global.doboard=true; } // random change cards public void husle(){ //System.out.println("224 husle!"); // Set the item int animal=0; int bewaar[][]=new int[global.WIDTH][global.HEIGHT]; // global.cards=new Hashtable(); for(int x1=0; x1 < global.WIDTH-1; x1++) for(int y1=0; y1 < global.HEIGHT-1; y1++) bewaar[x1][y1]=0; //System.out.println("Grid making"); for(int x=2; x < global.WIDTH-2; x++){ for(int y=2; y < global.HEIGHT-2; y+=2){ //System.out.println("Checking: "+x+","+y); boolean ok=false; Integer check=new Integer(0); try{ // check=(Integer)global.cards.get((String)(""+x*global.STEPP+","+y*global.STEPP)); if(bewaar[x][y] != 0){ //System.out.println("Found a bewaar objec"); ok=true; } // if(check.intValue() > 0) ok=true; }catch(Exception g){ } while(!ok){ Integer I=new Integer(rnd(4)); animal=anim[I.intValue()-1]; int i=I.intValue(); // global.cards.put((String)(""+x*global.STEPP+","+y*global.STEPP), ""+animal); // first available free receives the animal bewaar[x][y]=animal; //System.out.println("------"); //System.out.println("Animal: "+animal+"x:"+x+"y:"+y); global.grid.setxy(x*global.STEPP,y*global.STEPP, animal); // search next available place on the board boolean found=false; int counter=0; while(!found ){ Integer X=new Integer(rnd(global.WIDTH)); Integer Y=new Integer(rnd(global.HEIGHT)); if(X.intValue() > 1 && X.intValue() < global.WIDTH-2 && Y.intValue() > 1 && Y.intValue() < global.HEIGHT-2 && Y.intValue()%2 == 0){ if(bewaar[X.intValue()][Y.intValue()] == 0){ // Additional three animals! if(counter++ > 1){found=true;ok=true;} // global.cards.put((String)(""+(X.intValue()*global.STEPP)+","+(Y.intValue()*global.STEPP)), ""+animal); bewaar[X.intValue()][Y.intValue()]=animal; global.grid.setxy(X.intValue()*global.STEPP,Y.intValue()*global.STEPP, animal); //System.out.println("animal set: "+animal+"X:"+X+"Y:"+Y); //ok=true; } // bewaar } // X, Y in range? } // while !found //System.out.println("====="); } // while } // for y } // for x int twelve=global.grid.next(0,0,224); global.grid.set(twelve, 225); state=1; global.selected=0; display(); } public int rnd(int rr){ return rand(rr); } public int rand(int seed){ int retval=random.nextInt(seed)+1; return retval; } }