import java.awt.*; import java.awt.image.*; import java.util.*; import java.net.*; import java.awt.event.*; 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=10000; // Seconds to sleep*1000 boolean first=false; int WIDTH=16; int HEIGHT=13; String INFO=""; int runspeed=0; int runningspeed=0; boolean showprogressionbar=false; boolean busynetwork=false; Hashtable imagehash=new Hashtable(); Hashtable soundhash=new Hashtable(); Sound randomsounds[]; int MAXSOUNDS=8; private static final Runtime s_runtime = Runtime.getRuntime (); String showtext=""; int storedobject155=0; // Used in object 155/156 int storedobject157=0; // Used in object 157/158 String playbackkeys=""; // store keys String playback; // actual playback boolean PLAYBACK=false; int playbacknr=0; int BEFOREPAY=25; // When do we have to pay? boolean buy=false; // Did we buy the program boolean BUYSTATE=false; boolean PLAYERIMAGE=false; // Is there a playerimage? // put it here public String OBJECTSTATE; int drawer=0; // Tell Show/Board routine that we have moved. When no objects are displayed it will otherwise not draw the character /* int STEPP=8; int MAXSTEPP=8; int SIZER=5; */ int STEPP=5; int MAXSTEPP=5; int SIZER=8; boolean nonwindows=false; int KEYWAIT=0; // based on sleeper => show int steptaken=0; int backup_steptaken=0; int all=4; // number of All players in room int PLAYERSTATE=0; static final int WALKING=0; static final int PUSHING=1; static final int INWATER=2; static final int PLAYERNOTHING=5; boolean onice=false; // Are we stuck on ice int interest=0; // Show interesting debugging value long resettime=0; // Reset the board if we are stuck in testrun (multiplay) long playtime=0; // Time it takes to complete a level int score=0; // Score of the user // boolean playsound=false; // Good point on javagaming.org: don't scare of players@work boolean playsound=true; // Well .. it seems that others don't like the lack of sound boolean nicewalk=false; // Can we draw walk or do we need to 'jump' private boolean debug=false; volatile boolean freezekeyboard=false; volatile boolean perform=false; // perform the action? volatile boolean aftermoves=false; // Key sets this volatile boolean finished=false; // resetevent checks it volatile boolean resetevent=false; volatile boolean waitforme=false; volatile int object=0; volatile boolean iskey=false; boolean iskeyboard=false; // Keyboard or mouse-only int mouseX=0; int mouseY=0; int mouseposx=0; int mouseposy=0; int introstate=1; // Help screen/objects information (object135) /* int UP=38; int DOWN=40; int RIGHT=39; int LEFT=37; int ESC=27; int BS=8; // Backspace */ int UP=KeyEvent.VK_UP; int DOWN=KeyEvent.VK_DOWN; int RIGHT=KeyEvent.VK_RIGHT; int LEFT=KeyEvent.VK_LEFT; int ESC=KeyEvent.VK_ESCAPE; int BS=KeyEvent.VK_BACK_SPACE; int ENTER=KeyEvent.VK_ENTER; int teammove=0; int teammovex=0; int teammovey=0; int teamkey=0; /* 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 onturn=0; // The network calculated which room is on boolean teamplay=false; // Do we play in a team? int turn=-320; // Do we have the turn? Turn==1 yes! boolean isturn=false; // Are we turn based or time based? int nroflevels=199; // Maximum nr of levels int usernr=10000; // Usernumber int team=usernr; // teamnumber -> Teamplay int State=0; // Game state int RState=0; // Run / Test state for multiplay arrow movement int testlevel=0; int testoldx=2330; // Used DURING test run int testoldy=2330; 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 dorefreshpos=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 mousepressed=false; // if level==1000 and we don't move the mouse extra 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= System.getProperty("java.version") ; ; String osname=new String("Windows"); String osarch=new String("Sparc"); int CHATSIZE=9; // Calculated in Show .. based on OS int TEXTSIZE=12; // Calculated in Show .. based on OS int CHATLINESIZE=24; Font textfont=new Font("Terminal",Font.BOLD,TEXTSIZE); Font chatfont=new Font("Terminal",Font.BOLD,CHATSIZE); Font scorefont=new Font("SansSerif",Font.BOLD, 4); Font infofont=new Font("SansSerif",Font.BOLD, 8); 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; volatile boolean eventsdone=true; // 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*10][WIDTH*10]; int mp[][]=new int[HEIGHT*9][WIDTH*9]; int backup_mp[][]=new int[HEIGHT*9][WIDTH*9]; volatile Player player; // all player moves / sets Loader loader; Object dynamic; int PlayerPos=0; int oldPlayerPos=32; int pushed=0; // pushed position volatile int dir=1; // Initialize the direction of movement String extra=""; // extra information about user (selection sound and/or speed) boolean dark=false; Image background; // Background image Sound backgroundmusic; // Sound backgroundsound; // Sound backgroundsoundbase; boolean parametered=false; // Did we send parameters to the applet? // network communication // FIFO ReadStack; // communication TeamPlay FIFO WriteStack; FIFO ChatStack; // 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=System.getProperty("java.version").indexOf("1.1")==0?".gif":".png"; // 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; static final int TEST=12; static final int DONOTHING=13; static final int AUTOMATEDRUN=200; String username=""; String roomname[]=new String[5]; // Gamestate_Menu // Menu states int menus=11; // 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 static final int MENU_BUY=104; static final int MENU5=105; static final int MENU6=106; static final int MENU7=107; static final int MENU_LEVELS=108; static final int MENU_SCORES=109; // Last Menu state static final int MENU_WAIT_OK=999; static final int MENU_OK = 1000; // internal variables // debug retrieve/sent int retrieved=0; int sent=0; int sbacky=0; int rbacky=0; // Memory game Image memory_img[]=new Image[32]; Hashtable cards; int selected=0; int selectedx; int selectedy; int selectedimage; // // METHODS // // Constructor // public Global(Show shw){ show=shw; String S_room; String S_usernr; String S_score; String S_extra; String S_level; String S_team; String S_buy; try{ S_room=show.applet.getParameter("room"); S_usernr=show.applet.getParameter("usernr"); S_level=show.applet.getParameter("level"); S_score=show.applet.getParameter("score"); if(S_score.indexOf("!") > -1){ S_extra=S_score.substring(S_score.indexOf("!")+1); extra=S_extra; S_score=S_score.substring(0,S_score.indexOf("!")); }else{S_extra="";} S_team=show.applet.getParameter("team"); S_buy=show.applet.getParameter("buy"); System.out.println("PARAMETERS: "+S_room+", "+S_usernr+", "+S_score); }catch(Exception egege){ System.out.println("Error with getParameter"); S_room="0"; S_usernr="0"; S_level="0"; S_score="0"; S_team="0"; S_buy="0"; } try{ room=Integer.parseInt(S_room); }catch(Exception egeg){ room=0; } try{ usernr=Integer.parseInt(S_usernr); }catch(Exception egega){ usernr=0; } try{ level=Integer.parseInt(S_level); }catch(Exception egaga){ level=0; } try{ score=Integer.parseInt(S_score); }catch(Exception egegege){ score=0; } try{ if(Integer.parseInt(S_team)==1){ introstate=100; teamplay=true; } }catch(Exception egege){ } if(usernr > 0){ parametered=true; if(show!=null) Server=show.applet.getCodeBase().toString(); String result=execute("history.php?usernr="+usernr+"&javaversion="+javaversion); }else{ room=1; usernr=10000; level=1; score=0; } try{ if(Integer.parseInt(S_buy)==1){ standalone=true; teamplay=false; buy=true; } }catch(Exception egege){ } OBJECTSTATE=""; for(int i=0; i default directory if(show.image[1]==null){ Directory="/maze/"; } // grid.load("level"+level); // System.out.println("In Global.init() .. check the load of the screen"); grid.load(); //using global.level :) for(int h=0; h 0){ //System.out.println("Before load/check: "+w+", "+h+"object: "+k); show.applet.repaint(); oo o=(oo)loader.getObject(k); checkaction(o,k); //System.out.println("after load/check"); slider++; } } } // draw the board == > tell Show to launch it ;-) doboard=true; } // // Key action public boolean key(int d){ boolean result=true; int o1=0; int kk=0; //replay if(State > MENU1-1 || State == LOADING || State==RELOADING || State == CHANGE){ System.out.println("Key method in global. menu1 State s greater"); return false; } // if we are busy in the processing of events if(freeze)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()); kk=1; } if(d ==-STEPP){ o1=grid.getxy(player.getX()-STEPP,player.getY()); kk=2; } if(d == -STEPP*WIDTH){ o1=grid.getxy(player.getX(),player.getY()-STEPP); kk=3; } if(d == STEPP*WIDTH){ o1=grid.getxy(player.getX(),player.getY()+STEPP); kk=4; } }catch(Exception eg){ o1=-1; } drawer++; if(o1==-1){ // System.out.println("You hit a border!"); }else{ if(o1 > 0){ steptaken++; try{ object=o1; oo o=(oo)loader.getObject(o1); o.setMethod("hit"); playbackkeys+=""+kk; 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; } /* -- USE BAGRESET // --- OBJECTSTATE // States used in objects to communicate between objects // Suppose you have an object that sets a state of another object remotely. // Most used for different states or if the state is of temporary effect // Used for instance by the monkey when it receives bananas // When 'eating' the bananas the monkey will not get the player during a specific time public void setObjectState(int nr, String value){ try{ //System.out.println("set objectstate:"+nr+"to value: "+value); String t=OBJECTSTATE.substring(0,nr-1)+value+OBJECTSTATE.substring(nr-1,MAXOBJECT-1); OBJECTSTATE=t; }catch(Exception eg){ //System.out.println("global.setObjectState error: "+eg.toString()); } } public String getObjectState(int nr){ String retval=""; try{ retval=OBJECTSTATE.substring(nr-1,nr); }catch(Exception egeg){ retval=""; } return retval; } */ // // Initialize all the objects public void inits(){ int t; int r; int s; String obj; int l; doboard=false; dorotate=false; Date date=new Date(); playtime=date.getTime(); for(int iii=0;iii<4;iii++)roomname[iii]=""; // clear global.mp multiplayer arrows try{ l=Array.getLength(dynamic); for(s=1; s< l; s++){ slider++; // for load screen //System.out.println("init "+s); if(loader.isLoaded(s)){ oo o=(oo)loader.getObject(s); o.init(this); } } }catch(Exception e){ System.out.println("INITS error: "+e.toString()); } } // // Display the info // public void setInfo(String text){ show.info.add(text); // show.info.select(show.info.getItemCount()-1); show.info.select(show.info.getItemCount()-2); showtext=text; show.info.repaint(); } // // makeBackground(int objnumber, Image object) // // Change the background into the object so that pushing displays nicer in SLOW mode // public void makeBackground(int objnumber, Image obj){ int nr=grid.next(0,0,objnumber); while(nr > -1){ int x=nr%(WIDTH*STEPP); int y=nr==0?0:nr/(WIDTH*STEPP); int s=((y+STEPP)*WIDTH)+x; show.applet.repaint(); // change background if(obj==null) System.out.println("image is null!"); show.changeBackground(obj,s); show.repaint(); nr=grid.next(x+1,y,objnumber); } } // // 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]); o.setMethod("aftermove"); o.execute(); } }catch(Exception e){ System.out.println("Aftermove error : object "+all_aftermoves[i]+" Eror: "+e.toString()); } } } // // 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{ //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; // First search for the Server+filename in the stack retval=(Sound)soundhash.get(Server+filename); if(retval==null){ // if not found in stack -> read from network retval=readSound(Server, filename); if(retval!=null) soundhash.put(Server+filename, (Sound)retval); } return retval; } private Sound readSound(String Server, String filename){ Sound retval=null; show.applet.repaint(); 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){ Image retval=null; // First search for the Server+filename in the stack retval=(Image)imagehash.get(Server+filename); if(retval==null){ // if not found in stack -> read from network retval=readImage(Server, filename, comp); if(retval!=null) imagehash.put(Server+filename, (Image)retval); } return retval; } private Image readImage(String Server, String filename, Component comp){ MediaTracker mt; Image img=null; Date d=new Date(); URL url; //System.out.println( "file:"+filename); boolean no_error=true; show.applet.repaint(); 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; else{ // If there is a 404 page -> not an image! if(inputLine.toUpperCase().indexOf("HTTP") > -1) no_error=false; else no_error=true; } in.close(); if(no_error){ try{ img=Toolkit.getDefaultToolkit().getImage(url); }catch(Exception eggegeg){img=null;no_error=false;} if(img!=null && no_error){ mt = new MediaTracker(show); mt.addImage( img, 0 ); mt.waitForAll(); }else no_error=false; } } // if error URL IS NULL } catch (Exception ef) { System.out.println("error oading image: "+ef.toString()); no_error=false; } // test size if(img != null && no_error){ 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); if(!no_error)img=null; return img; } } // // EOF //