import java.util.*; import java.awt.*; // // End point of 13-match // // public class object96 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 public object96(){ objnumber=96; methods[0]="hit"; methods[1]="resetevent"; methods[2]="event"; } public void init(Global glbl){ global=glbl; //System.out.println("object 96 init!"); if(image == null){ image=global.loadImage(global.Server, global.Directory+"96"+global.Extention, global.show); oldimage=image; } sound=global.loadSound(global.Server, global.Directory+"99.au"); Date d=new Date(); oldtime=(long)d.getTime(); 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(){ int nr; boolean found=false; for(int i=0; i < 13 && !found; i++){ nr=global.grid.next(0,0,(118+i)); if(nr > -1)found=true; } if(!found){ if(global.playsound)sound.play(); nr=global.grid.next(0,0,96); global.grid.set(nr, 1); global.doboard=true; }else{ global.setInfo("Not all boxes are gone!"); } } public void event(){ } public void resetevent(){ System.out.println("Resetevent on object96"); husle(); } // Display public void display(){ global.boardrow=-1; global.boardcol=-1; global.doboard=true; } // random change cards public void husle(){ System.out.println("husle!"); // Set the item global.cards=new Hashtable(); //System.out.println("Make hidden images"); for(int x=2; x < global.WIDTH-2; x++){ for(int y=2; y < global.HEIGHT-3; y+=2){ //System.out.println(":x: "+x+" y : "+y); boolean ok=false; //System.out.println("card get : "+x+", "+y); Integer check=new Integer(0); try{ check=(Integer)global.cards.get((String)(""+x*global.STEPP+","+y*global.STEPP)); if(check==null)ok=false; if(check.intValue() > 0) ok=true; }catch(Exception g){ } while(!ok){ Integer I=new Integer(rnd(12)); //System.out.println("object random: "+I); // Used to do a perfect match on every object .. now you can have more of the same .. it works faster this way int i=I.intValue(); int t=13-i; global.cards.put((String)(""+x*global.STEPP+","+y*global.STEPP), new Integer(I.toString())); // search next available object boolean found=false; 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-3 && Y.intValue()%2 == 0){ Integer C=new Integer(0); try{ C=(Integer)global.cards.get( (String) (""+(X.intValue()*global.STEPP)+","+(Y.intValue()*global.STEPP))); if(C==null) C=new Integer(0); }catch(Exception gg){C=new Integer(0);} if(C.intValue() == 0){ found=true; global.cards.put((String)(""+(X.intValue()*global.STEPP)+","+(Y.intValue()*global.STEPP)), new Integer(I.toString())); global.grid.setxy(X.intValue()*global.STEPP,Y.intValue()*global.STEPP, (117+t)); ok=true; } } } // while !found global.grid.setxy(x*global.STEPP,y*global.STEPP, (117+I.intValue())); } // while //System.out.println("going for next y y="+y); } // for y } // for x 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; } }