import java.awt.*; import java.awt.image.*; import java.util.*; import java.net.*; import java.io.*; import java.lang.reflect.*; // Global variables / methods / objects // public class Global{ // 'Global' variables int MAXOBJECT=1003; // maximum of objects (object1-2000) int PLACER=5000; // add to the position to get a move int sleeper=25; // Plugin = 25 / < 1.1 55 int NETWORKSLEEP=30000; // Seconds to sleep*1000 // int WIDTH=16; // Width + Height will be calculated // int HEIGHT=12; int WIDTH=16; int HEIGHT=13; int STEPP=5; // SIZER * STEPP is SIZE int MAXSTEPP=5; // Maximum number of animationstepps int SIZER=8; // SIZER * STEPP is SIZE MAKE SURE 40 is target! int KEYWAIT=0; // based on sleeper => show int PLAYERSTATE=0; int interest=0; // Show interesting debugging value long playtime=0; // Time it takes to complete a level boolean playsound=false; private boolean debug=false; volatile boolean freezekeyboard=false; volatile boolean perform=false; // perform the action? volatile boolean aftermoves=false; // Key sets this // resetevent checks it volatile boolean resetevent=false; volatile int object=0; volatile boolean iskey=false; int UP=0; int DOWN=0; int RIGHT=0; int LEFT=0; int posxx=0; int posyy=0; int startx=-1; int starty=-1; int stap=0; // step in walk-animation int level=1; // which level int room=1; // which room (teamplay) int turn=0; // Do we have the turn? Turn==1 yes! boolean teamplay=false; // Do we play in a team? // isturn=true -> turnplay == teamplay boolean isturn=false; // Are we turn based or time based? int nroflevels=99; // Maximum nr of levels int usernr=10000; // Usernumber int team=usernr; // teamnumber -> Teamplay int State=0; // Game state boolean isnetwork=false; // network thread -> are we in multiplay? boolean standalone=false; // Used when not connected to internet (future?) boolean transparent=false; // Transparency drawing volatile boolean freeze=false; // You are HIT or catched or whatever you have to STOP! volatile boolean dontwalk=false; boolean doboard=false; // should we draw the board? boolean doreload=false; // HIT/DROWN/FALL etcc boolean dorotate=false; // Move of buckets / network play boolean keyreleased=true; volatile boolean keypressed=false; // If level==1 and we do't press a key the extra help info is showed boolean gridloaded=false; // Is the grid loaded? int boardrow=-1; // Row int boardcol=-1; // Col int boardwidth=-1; int boardheight=-1; int PARTDRAW_WIDTH=6; int PARTDRAW_HEIGHT=4; int slider=0; // Loadingslider String javaversion=new String("1.0"); String osname=new String("Windows"); String osarch=new String("Sparc"); int CHATSIZE=12; // Calculated in Show .. based on OS int CHATLINESIZE=24; Font textfont=new Font("Terminal",Font.BOLD,CHATSIZE); String Email=""; String Password=""; // object invocation ... // // After user move int all_aftermoves[]=new int[MAXOBJECT]; int all_aftermoves_nr=0; // Time events int all_events[]=new int[MAXOBJECT]; int all_events_nr=0; // Reset when clear/close/reload level int all_resets[]=new int[MAXOBJECT]; int all_resets_nr=0; // Grid object (load/change etc..) Grid grid; // global access to grid_items (faster) int grid_items[][]=new int[HEIGHT*8][WIDTH*8]; int mp[][]=new int[HEIGHT*8][WIDTH*8]; Player player; // all player moves / sets Loader loader; Object dynamic; int PlayerPos=0; int oldPlayerPos=32; int pushed=0; // pushed position int dir=1; // Initialize the direction of movement Image background; // Background image Sound backgroundmusic; Sound backgroundsound; Sound backgroundsoundbase; // network communication FIFO ReadStack; // communication TeamPlay FIFO WriteStack; FIFO AllMoves; int BAGSIZE=10; int bagpointer=0; int bag[]=new int[BAGSIZE]; int laststack=-1; int bewaar=0; // Monkey business ;-) String Server=new String(""); // Will be dynamicly fed by Show String Directory=new String("/maze/"); String Extention=new String(".gif"); // Show = display things Show show; // Handle communication to show screen // Game States static final int INITIALIZE = 1; static final int CHANGE = 2; static final int STOP = 3; static final int LOAD = 4; static final int RUN = 5; static final int LOADING=6; static final int RUNNING=7; static final int NOTHING = 8; static final int WALK = 9; static final int PUSH = 10; static final int RELOADING = 11; // Gamestate_Menu // Menu states int menus=5; // walk through menus int MENU=99; static final int MENU1 = 100; static final int MENU_FULL = 101; // If all the rooms are full static final int MENU_NOTOK = 102; static final int MENU_TEAM = 103; static final int MULTI = 103; // multiplay menu // Last Menu state static final int MENU_OK = 1000; // internal variables // debug retrieve/sent int retrieved=0; int sent=0; int sbacky=0; int rbacky=0; // // METHODS // // Constructor // public Global(Show shw){ show=shw; for(int i=0; i default directory if(show.image[1]==null){ Directory="/maze/"; } grid.load("level"+level); for(int h=0; h 0){ oo o=(oo)loader.getObject(grid_items[h*STEPP][w*STEPP]); checkaction(o,grid_items[h*STEPP][w*STEPP]); slider++; } } } // draw the board == > tell Show to launch it ;-) doboard=true; } // // Key action public boolean key(int d){ boolean result=true; int o1=0; if(State > MENU1-1 || State == LOADING || State==RELOADING || State == CHANGE){ System.out.println("Key method in global. menu1 State s greater"); return false;} if(freeze)return false; if(!resetevent)return false; int temppos=PlayerPos; int tempposx=player.getX(); int tempposy=player.getY(); if(debug)System.out.println("pos x : "+tempposx+", pos y: "+tempposy); // dir=d*STEPP; //moveplayer // ! try{ if(d == STEPP) o1=grid.getxy(player.getX()+STEPP,player.getY()); if(d ==-STEPP) o1=grid.getxy(player.getX()-STEPP,player.getY()); if(d == -STEPP*WIDTH) o1=grid.getxy(player.getX(),player.getY()-STEPP); if(d == STEPP*WIDTH) o1=grid.getxy(player.getX(),player.getY()+STEPP); //System.out.println("Payer.get("+tempposx+","+tempposy+" + direction)("+d+") =: "+o1); }catch(Exception eg){ o1=-1; } if(o1==-1){ System.out.println("You hit a border!"); }else{ if(o1 > 0){ try{ object=o1; oo o=(oo)loader.getObject(o1); o.setMethod("hit"); o.execute(); }catch(Exception e){} } // if o1 > 0 } //if(temppos!=PlayerPos)result=true; if(debug)System.out.println("pos x : "+player.getX()+", pos y: "+player.getY()); if( ( tempposx==player.getX() && tempposy==player.getY() && !doreload) || doreload ){ result=false; } else result=true; perform=result; return result; } // // Initialize all the objects public void inits(){ int t; int r; int s; String obj; int l; System.out.println("GLOBAL inits -> doboard = false"); doboard=false; dorotate=false; Date date=new Date(); playtime=date.getTime(); try{ l=Array.getLength(dynamic); for(s=1; s< l; s++){ slider++; // for load screen if(loader.isLoaded(s)){ oo o=(oo)loader.getObject(s); o.init(this); } } }catch(Exception e){ System.out.println("INITS error: "+e.toString()); } } // // ALL objects needs to be resetted (if they are in list!) // public void resets(){ int t; int r; int s; String obj; for(int i=0;i 0){ oo o=(oo)loader.getObject(all_aftermoves[i]); // if(o.is("aftermove")){ o.setMethod("aftermove"); o.execute(); // } } }catch(Exception e){ System.out.println("Aftermove error : "+i); } } } // // Check if we have an action that we should take care of // public void checkaction(oo o, int nr){ int i=0; boolean found=false; while(!found){ if(all_aftermoves[i]==nr || all_resets[i]==nr || all_events[i]==nr)found=true; if(i > MAXOBJECT-3) found=true; i=i+1; } if(i -1){ standalone=true; }else{ if(debug)System.out.println("EXECUTING Url opening: "+Url.toString()); URLConnection uc = Url.openConnection(); BufferedReader in = new BufferedReader( new InputStreamReader( uc.getInputStream() ) ); while ((inputLine = in.readLine()) != null){ // Script is executing .. no output is given! retval+=inputLine; } } // else is file --> standalone? }catch(Exception ef){ System.out.println("Error getting result from: "+php+" : "+ef.toString()); standalone=false; retval=""; } } return retval; } public Sound loadSound(String Server, String filename){ Sound retval=null; try{ retval=new Sound(show); retval.load(Server+filename); if(!retval.getOK())retval=null; }catch(Exception e){ System.out.println("Global.loadSound exc: "+e.toString()); } return retval; } // BEFORE THIS PLEASE TRY JARloadImage !!!!! // Jar // jar // JAR public Image loadImage(String Server, String filename, Component comp){ MediaTracker mt=null; Image img=null; Date d=new Date(); URL url; boolean no_error=true; try{ // Add dummy to the URL so that it won't cache! url=new URL(Server+filename); if(debug)System.out.println("Opening image: "+url.toString()); if(url != null){ InputStream ia = url.openStream(); BufferedReader in = new BufferedReader(new InputStreamReader (ia)); String inputLine; if((inputLine = in.readLine()) == null ) no_error=false; in.close(); img=Toolkit.getDefaultToolkit().getImage(url); if(img!=null && no_error){ no_error=true; mt = new MediaTracker(show); mt.addImage( img, 0 ); mt.waitForAll(); }else no_error=false; }else no_error=false; } catch (Exception ef) { System.out.println("error oading image: "+ef.toString()); img=null; no_error=false; } // test size if(img != null){ if(img.getWidth(show) < 0 || img.getHeight(show) < 0) img=null; } mt = null; // // Transparent drawing // // not necessary when using gifs! // // if(global.transparent && img != null) // img=trans(img); return img; } /* public int push(int obj, int stt){ int state=stt; freeze=true; // Stone pushing!! int P=1; int x=0; int y=0; // Do we paint or wait for our eyes to relax ;-) // if((teller++ % ANIFREEZE) != 1) return; // Last frame? if(pos++ > STEPP-2){ pos=0; state=2; stap=0; // teller=0; } // Move image of player if(stap < STEPP){ stap++; }else{ //state=2; stap=0; } // what is the posistion of the player? x=player.getX(); y=player.getY(); // Left if(dir == -STEPP){ grid.setxy(x-(STEPP)-P, y,obj); grid.setxy(x-STEPP, y,1); player.set(x-P,y); } // Right if(dir == STEPP){ grid.setxy(x+(STEPP)+P, y, obj); grid.setxy(x+STEPP, y, 1); player.set(x+P,y); } // down if(dir == STEPP*WIDTH){ grid.setxy(x,y+(STEPP)+P,obj); grid.setxy(x,y+(STEPP),1); player.set(x, y+P); } // up if(dir == -STEPP*WIDTH){ grid.setxy(x,y-(STEPP)-P,obj); grid.setxy(x,y-(STEPP),1); player.set(x, y-P); } State=WALK; return state; } */ } // // EOF //