⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.java

📁 之前有人传过`不过是没有资源只有代码的` 我在重新传一遍有资源的`是一个滑雪的游戏`类似flash的打企鹅`
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    void drawMessage(String message)    {		v = prepareText(message,s_w - 8);		k = v.size();		y = (s_h - k * 16) >> 1;		for (j = 0; j < k; j++, y += 16)		{			str = ((String)v.elementAt(j)).trim();			drawString(str,(s_w - getStringWidth(str)) >> 1,y);		}    }    void updateSnow()    {    	for (j = 0; j < snow.length; j++)    	{			x = (snow[j] >> 24) & 0xFF;			y = (snow[j] >> 16) & 0xFF;			k = (snow[j] >> 8)  & 0xFF;			h = snow[j] & 0xFF;			y += 4;			x += 1 - k - k;			if (y > h)			{				h = y + 10 + rnd(20) * 2;				k = 1 - k;			}			if (y > s_h)			{				x = rnd(s_w);				y = 0;				k = rnd(1);				h = rnd(20) * 2 + 10;			}		   	snow[j] =  (x & 0xFF) << 24;		   	snow[j] |= (y & 0xFF) << 16;    		snow[j] |= (k & 0xFF) << 8;		   	snow[j] |= h & 0xFF;		}    }    void drawGhostName(int x,int y, int color)    {		if (m_ghost != null)		{			setClip(0,0,s_w,s_h);			setColor(0x202020);			drawString(m_ghost,x,y,Graphics.BOTTOM | Graphics.HCENTER);			setColor(color);			drawString(m_ghost,x,y + 1,Graphics.BOTTOM | Graphics.HCENTER);		}    }    int pb_cur = 0, pb_max = 0;    void drawLogo(boolean needRast)    {		setColor(needRast ? 0x000000 : 0xEFF5FB);		fillRect(0,0,s_w,s_h);		if ((img[logo0_index] != null) && (img[logo1_index] != null))		{			x1 = getImageWidth(logo0_index);			x2 = getImageWidth(logo1_index);			h2 = getImageHeight(logo1_index);			y1 = 0;//#if Size_0			y2 = 1;			logoTop = h2 + y2 + 4;//#endif//#if Motorola && C650			y1 = h2 - 20;			y2 = 0;			logoTop = h2 + 8;//#elif Size_1			y1 = h2 - 8;			y2 = 0;			logoTop = h2 + 8;//#endif			boolean needLogo = true;//#if Size_2			y2 = 5;			logoTop = h2 + y2 + 6;//#endif			if (!needRast)			{//#if Size_1				drawImage(logo1_index,(s_w - x2) >> 1,bgTop + y2);				drawImage(logo0_index,(s_w - x1) >> 1,bgTop + y1);//#else				drawImage(logo0_index,(s_w - x1) >> 1,bgTop + y1);				drawImage(logo1_index,(s_w - x2) >> 1,bgTop + y2);//#endif			}			else//#if Size_0			if (menuLevel == 0)//#endif			if (needLogo) drawImage(logo1_index,(s_w - x2) >> 1,bgTop + y2);		}    }    void drawRast()    {    	if (gd != null)    	{    		setClip(0,0,s_w,s_h);	    	if (img[rast_index] != null)    		for (i = 0; i < s_w; i += 16)		    	for (j = 0; j < s_h; j += 16)		    		drawImage(rast_index,i,j);		}    }    void drawBgm()    {		setClip(0,0,s_w,s_h);		setColor(0x000000);		fillRect(0,0,s_w,s_h);	}	public void run()	{        t = Thread.currentThread();       	if (mainThread != null); // dummy code 		while (t == mainThread)		{			try{ t.sleep(3); } catch(Exception iex){}			tcur = System.currentTimeMillis() - tstart;			runFlag = true;			if (running)			{				needRepaint = false;				for (task_i = 0; task_i < tasks.length; task_i++)				while (runFlag && tasks[task_i] < tcur)//				if (tcur > 65)				{//					tstart = System.currentTimeMillis();        			tasks[task_i] += taskTimes[task_i];					if (task_i == 0)					{						try						{	    					switch(state)    						{							case STATE_SKIJUMP_RUN_SCORES:								if (--state_delay <= 0)								{									storeTime(G_SKIJUMP,total_points,total_points);								}								break;    						case STATE_SKIJUMP_RUN:    							update_skijump();    							break;    						case STATE_BIATHLON_RUN:    							if (go_delay > 0) go_delay--;    							if (go_index >= 2) update_biathlon(); // GO message shown    							else	    						{    								if (go_delay <= 0)    								{    									go_delay = 20;    									if (++go_index >= 2)    									{	    									ghost_time = ghost_time_w = 0;    										man.period = total_points = 0;											time_finish = 0;    										time_start = System.currentTimeMillis();     									}    									else    									{    									}		    						}	    						}    							break;							case STATE_BIATHLON_RUN_SCORES:								if (--state_delay <= 0)								{									m_v1 = (int)(time_total / 10);									m_v2 = man.missed;									storeTime(G_BIATHLON,total_points,m_v1);								}								break;							case STATE_SKATER_RUN:	    						if (go_delay > 0) go_delay--;    						   								if (go_index >= 2) update_skater_run(); // GO message shown    							else    							{    								if (go_delay <= 0)	    							{    									go_delay = 20;    									if (++go_index >= 2)    									{    										ghost_time = ghost_time_w = 0;    										man.period = total_points = 0;											time_finish = 0;											frames_passed = 0;    										time_start = System.currentTimeMillis(); 	    								}	    								else 	    								{	    								}	    							}    							}    			       									break;							case STATE_SKATER_RUN_FINISH:								update_skater_run();								if (--state_delay <= 0)								{									go_delay = 0;									state = STATE_SKATER_RUN_SCORES;									state_delay = 40;								}								break;							case STATE_SKATER_RUN_SCORES:								update_skater_run();								if (--state_delay <= 0)								{									m_v1 = (int)(time_total / 10);									m_v2 = 0;									storeTime(G_SKATER,total_points,m_v1);								}								break;	   						case STATE_MENU:    							updateMenu();    							break;	    					case STATE_EDITOR_FINISH:	    						if (--state_delay <= 0) editOk(new String(editText));	    						break;	    					case STATE_EDITOR:    							updateEditor();    							break;    						case STATE_INTRO:    							if (--state_delay <= 0 || (isKeyPressed))	    						{                                    img[logo0_index] = null;                                    loadLogo();    								loadImages(true);    								state = STATE_LOGO;    								state_delay = 40;    							}    							break;							case STATE_PLACE:								if (--state_delay <= 0 || (isKeyPressed))								{									menuLevel = 9;									returnMenu();									action = key_action = NO_ACTION;    								runFlag = false;								}								break;	    					case STATE_LOGO:    							if (--state_delay <= 0 || (logoTop != -1 && isKeyPressed))    							{    								action = key_action = NO_ACTION;		   			           		menuLevel = 0;		   			           		returnMenu();    								runFlag = false;    							}	    					}            	    	}            		    catch (Exception e)						{//		   	           		e.printStackTrace();	                	}						if (!isKeyPressed) action = key_action = NO_ACTION;						needRepaint = true;					}	        	}    	    	if (needRepaint)				{					doRepaint();				}        	}		}	}	void doRepaint()	{//#if Siemens && (!SX1)		paint(getGraphics());		flushGraphics();//#else    	repaint(); 		serviceRepaints();//#endif	}    synchronized public void start()     {        if (mainThread == null)         {            mainThread = new Thread(this);            mainThread.start();        }    }        synchronized public void stop()     {        mainThread = null;        try        {        	rs.closeRecordStore();        }        catch(Exception ex){}    }    ////////////////////////////////////////////////////////    	// header fields	static byte cipherAddition = 0;	static byte cipherValue = 0;	//	// file table fields	static byte[] filename = null;	static int pk_size[];	static int pk_index[];	static String sFileName = null;	byte[] buffer = null;	//	// internal function which reads one coded byte and decodes it	byte readCByte() throws IOException	{		int r = in.read();		r = (cipherAddition == 1 ? ((r - cipherValue) & (0xFF)) : ((r + cipherValue) & 0xFF));		return (byte)r;	}	private int readCInt() throws IOException	{		int r = (byte)readCByte() & 0x00FF;		r |= ((byte)readCByte() & 0x00FF) << 8;		r |= ((byte)readCByte() & 0x00FF) << 16;		r |= ((byte)readCByte() & 0x00FF) << 24;		return r;	}	private int readCBytes(byte[]b, int l) throws IOException	{		boolean noZero = true;		int i, n = 0;		for (i = 0; i < l; i++)		{			b[i] = readCByte();			if (b[i] != 0)			{				if (noZero) n++;			}			else noZero = false;		}		return n;	}	int _readInt() throws Exception	{		int r = (byte)in.read() & 0x000000FF;		r |= ((byte)in.read() & 0x000000FF) << 8;		r |= ((byte)in.read() & 0x000000FF) << 16;		r |= ((byte)in.read() & 0x000000FF) << 24;		return r;	}	void loadFromStream(int loadMode) throws Exception	{		int i, i2, j, k;		pk_size = new int[img.length];		pk_index = new int[img.length];		filename = new byte[10];		int dx = 0;		in.read(filename,0,6);		if (!(new String(filename,0,6).equals("DEEPAK"))) return;		_readInt();		int w2 = _readInt();		cipherAddition = (byte)in.read();		cipherValue = (byte)in.read();		in.read(filename,0,10);		_readInt();		dx += 30;		if (w2 > img.length) w2 = img.length;		// search for entry name		// reading file table		int idx = 0;		for (i = 0; i < w2 ; i++, dx += 22)		{			doRepaint();			k = readCBytes(filename,filename.length);			// searching max size of image			pk_size[i] = readCInt();			readCInt(); // dummy 4 bytes			pk_index[i] = -1;			readCInt();			sFileName = new String(filename,0,k).toLowerCase();			i2 = sFileName.indexOf(".");			if (i2 != 1) sFileName = sFileName.substring(0,i2);				for (j = 0; j < img_names.length; j++)				{					if (img_names[j] != null && (j != logo0_index) && (j != logo1_index)) 					{						if (img_names[j].equals(sFileName))						{							pk_index[i] = j;							if (pk_size[i] > idx) idx = pk_size[i];			   	//							System.out.println("Enqueued " + img_names[j]);							img_names[j] = null;							break;						}					}				}		}		sFileName = null;		System.gc();		if (idx > 0)		{			buffer = new byte[idx];			// reading resources			for (i = 0; i < w2; i++)			{				doRepaint();				if (pk_index[i] != -1)				{					readCBytes(buffer,pk_size[i]);					if (loadMode == 0)					{						img[pk_index[i]] = Image.createImage(buffer,0,pk_size[i]);					}				}				else				{					in.skip(pk_size[i]);				}			}			buffer = null;		}		in.close();		in = null;		pk_size = null;		pk_index = null;		filename = null;		System.gc();	}	void loadResource(int index) 	{		try		{			if (img_names[index] != null)			{//#if GX10				if (index == logo0_index) img[index] = img_cache[0];				if (index == logo1_index) img[index] = img_cache[1];				if (index == rast_index) img[index] = img_cache[2];//#else				createImage(index, "/Res/" + img_names[index] + ".png");//#endif				img_names[index] = null;			}		}		catch(Exception ex)		{//			ex.printStackTrace();		}	}	public boolean loadImages(boolean onlyLogo)	{		// reading the header					loadResource(logo0_index);		loadResource(logo1_index);		loadResource(rast_index);		if (onlyLogo) return true;		int n;		for (n = 0; n < 4; n++)		try		{			in = midlet.getClass().getResourceAsStream("/Res/" + n + ".pak");			loadFromStream(0);		}		catch(Exception ex){}		return true;	}	//////////////////////////////////////////////////////////////////////////////////////////    static Vector parse(String str)    {    	str2 = "";    	h = str.length() - 1;    	v2 = new Vector();    	for (int i = 0; i <= h; i++)    	{    		ch = str.charAt(i);    		if (i == h) str2 += ch;    		if ((ch == ',') || (i == h))    		{    			try    			{    				v2.addElement(new Integer(Integer.parseInt(str2)));    			}    			catch(Exception ex){}    			str2 = "";    		}    		else str2 += ch;    	}    	str2 = null;    	return v2;    }    ///////////////////////////////////////////////////////////////////////////////////    static String gp(String name)    {    	if (hp == null)    	{    	    hp = new Hashtable();            try            {	    	    in = midlet.getClass().getResourceAsStream("/Res/wg.c");    			int i,mode = 0;    			String key = "",value = "";    			while((i = in.read()) != -1)    			{    				ch = (char)i;    				if (ch == '\n')    				{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -