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

📄 torinocanvas.java

📁 国外人写的操作感挺好的一款滑雪游戏.结构也比较清楚
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
					
				return s;
			}
//#ifndef _LIMITED_EVENTS
//		}
//		else
//		{
//			// distance events
//			if (iResult == 0)
//			{
//				return "---";
//			}
//			else
//			{
//				int a = FP.toInt(iResult);
//				int b = FP.toInt(FP.fracPart(iResult)*10);
//				String s = new String();
//				s = a + "." + b;
//				return s;
//			}
//		}
//#endif
	}	

//#ifndef _LIMITED_EVENTS
//	public final static int m_aiAITable[][] = 
//	{
//		{ // USA (32)
//			10, 8, 6, 8
//		},		
//		{ // Canada (26)
//			6, 5, 6, 9
//		},
//		{ // China (22)
//			5, 5, 8, 4
//		},
//		{ // France (22)
//			5, 4, 6, 7
//		},
//		{ // Germany (26)
//			7, 5, 10, 4
//		},
//		{ // Italy (18)
//			2, 3, 3, 10
//		},
//		{ // Japan (26)
//			8, 6, 6, 6
//		},
//		{ // Korea (18)
//			9, 2, 2, 3
//		},
//		{ // Spain (18)
//			4, 7, 3, 4
//		},
//		{ // UK (22)
//			3, 10, 5, 4
//		},
//		{ // Epyx (32)
//			8, 10, 7, 7
//		}
//		
//	};
//#else
	public final static int m_aiAITable[][] = 
	{
		{ // USA (32)
			10, 6, 8
		},		
		{ // Canada (26)
			6, 6, 9
		},
		{ // China (22)
			5, 8, 4
		},
		{ // France (22)
			5, 6, 7
		},
		{ // Germany (26)
			7, 10, 4
		},
		{ // Italy (18)
			2, 3, 10
		},
		{ // Japan (26)
			8, 6, 6
		},
		{ // Korea (18)
			9, 2, 3
		},
		{ // Spain (18)
			4, 3, 4
		},
		{ // UK (22)
			3, 5, 4
		},
		{ // Epyx (32)
			8, 7, 7
		}
		
	};
//#endif

//*****************************************************************************
	public int						m_iLoadStatus = 100;
	private Label					m_loadingLabel;
	
	public void initLoader( Runnable r )
	{
		// create a new thread to load the window
		m_iLoadStatus = 0;
		m_loadingLabel = new Label( m_menuFont,0,0,0,0xFFFFFF/*@COLOR_WHITE*/,
			0x000000/*@COLOR_BLACK*/,0);
		m_loadingLabel.setText( getString( STRING_LOADING ) );
		m_loadingLabel.setPosition( (getWidth()-m_loadingLabel.m_iWidth)>>1,
			(getCanvasHeight()>>1) - m_loadingLabel.m_iHeight - 1);
 
		Thread t = new Thread(r);
		t.start();
		m_bNeedPaint = true;
	}
	
	public void updateLoadStatus( int iComplete )
	{		
		m_iLoadStatus = iComplete;
		m_bNeedPaint = true;
		if ( m_iLoadStatus >= 100 )
			m_loadingLabel = null;
	}
	
	
	public void paintLoadScreen( Graphics g )
	{
		g.setColor( 0x000000/*@COLOR_BLACK*/ );
		g.fillRect( 0, 0, getWidth(), getCanvasHeight() );
		
		// draw the label
		if (m_loadingLabel != null)
		{
			m_loadingLabel.paint( g );
		}
		
		// draw the status bar
		int iX, iY, iDX, iDY;
		iX = (getWidth()-52/*@LOADBAR_WIDTH*/)>>1;
		iY = (getCanvasHeight()>>1) + 1;
		iDX = 52/*@LOADBAR_WIDTH*/-1;
		iDY = 8/*@LOADBAR_HEIGHT*/-1;

		g.setColor( 0x9499ae/*@COLOR_GAME_METERBORDER*/ );
		g.drawRect( iX, iY, iDX, iDY );

		iX++;
		iY++;
		iDY--;
		iDX = m_iLoadStatus>>1;
		if (iDX > 0)
		{
			g.setColor( 0xEE9D00/*@COLOR_GAME_METERFILL*/ );
			g.fillRect( iX, iY, iDX, iDY );
		}				

		iX += iDX;
		iDX = 50/*@LOADBAR_MAX*/-iDX;
		if (iDX > 0)
		{
			g.setColor( 0x565656/*@COLOR_GAME_METERBACK*/ );
			g.fillRect( iX, iY, iDX, iDY );
		}				
		
	}
	

//*****************************************************************************
	public void startMainLoop()
	{
		m_iGameState = STATE_NORMAL;
//#ifdef _USE_THREAD
		new Thread(this).start();
//#else
//		m_display.callSerially( this );
//#endif
	}

        public void sleep(int time)
        {
                try
		{
                    Thread.sleep(time);
                }
                catch(Exception E){}
        }
        
	public void run()
	{
//#ifdef _USE_THREAD
                Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
		while (true)
		{
		
	/*	while( m_bPaused )
		{
			try {
				Thread.currentThread().sleep(10);
			} catch (InterruptedException e) {}
		}
*/
		//synchronized (s_paintLock)
		{
//#endif

		try
		{
                    sleep(10);
//#ifdef _DEBUG
//			int iTime = getCurrentTime();
//#endif
			if (!m_bPaused && isShown())
			{
//#if defined(_USE_THREAD) || defined(_USE_KEY_QUEUE)
//				publishKeyEvents();
//#endif
				if (m_currentWindow != null)
					m_currentWindow.onIdle();
			}
			
//#ifdef _DEBUG
//			m_iRunTime = getCurrentTime() - iTime;
//#endif

			if ( m_iGameState < STATE_EXITING)
			{
				if (!m_bPaused && isShown() && m_bNeedPaint)
				{
//#ifdef _USE_THREAD
					//m_bPaintLock = true;
                                        sleep(5);;
					m_bPaintScheduled = true;
					repaint();
					//s_paintLock.notify();
					//s_paintLock.wait();
					//Thread.yield();
					serviceRepaints();
				}				
//#else
//				    Thread.currentThread().sleep(15/*@_LOOP_DELAY*/);
//					m_bPaintScheduled = true;
//					repaint();
//					serviceRepaints();
//				}				
//				m_display.callSerially( this );
//#endif

//#if defined(_USE_THREAD) && defined(_LOOP_DELAY)
//				// force at least one extra delay just to give the system time to think
//				try 
//				{
//					
//				} catch (InterruptedException e) {}
//#endif

			}
			else
			{
				m_midlet.exitRequested();
//#ifdef _USE_THREAD
				break;
//#endif
			}
		}
		catch ( Exception e )
		{
//			DUMP_EXCEPTION_MSG(e, "*** Error during run ***");
			//e.printStackTrace();
			
//#ifdef _DISPLAY_MEM_ERROR
//			m_midlet.m_bCriticalError = true;
//#endif
			m_midlet.exitRequested();
		}
		catch ( OutOfMemoryError e )
		{
//			DEBUG_MSG( "*** OutOfMemoryError ***");
//#ifdef _DISPLAY_MEM_ERROR
//			m_midlet.m_bCriticalError = true;
//#endif
                       // e.printStackTrace();
			m_midlet.exitRequested();
		}
//#ifdef _USE_THREAD
		} // synchronized
		} // while (true)
//#endif
	}

//#ifndef _FULL_CANVAS
//	public void setKeyLabels( int iOK, int iBack )
//	{
//		String sOK;
//		String sBack;
//		// phones have different behaviors for how they treat "empty"
//		// command buttons, so we have to tailor our method to each phone.
//#if !defined(_IS_SamsungA600) && !defined(_IS_Sanyo5300) && !defined(_IS_NOKIA)
//		if ( iOK == (-1)/*@NULL_STRING*/ )
//			sOK = " ";
//		else
//			sOK = getString( iOK );
//		if ( iBack == (-1)/*@NULL_STRING*/ )
//			sBack = " ";
//		else
//			sBack = getString( iBack );
//#else
//		if ( iOK == (-1)/*@NULL_STRING*/ )
//			sOK = null;
//		else
//			sOK = getString( iOK );
//		if ( iBack == (-1)/*@NULL_STRING*/ )
//			sBack = null;
//		else
//			sBack = getString( iBack );
//#endif
//
//		// check if these labels match current ones
//		if (	
//			(	
//				(
//					m_cmdSelect == null && sOK == null
//				)
//				|| 
//				(
//					m_cmdSelect != null && sOK != null && sOK.equals( m_cmdSelect.getLabel() )
//				)
//			)
//			&& 
//			(
//				(
//					m_cmdBack == null && sBack == null
//				)
//				|| 
//				(
//					m_cmdBack != null && sBack != null && sBack.equals( m_cmdBack.getLabel() )
//				)
//			)
//			)
//		{
//			return;
//		}
//			
//		// remove commands
//		if (m_cmdBack != null)
//		{
//			removeCommand( m_cmdBack );
//			m_cmdBack = null;
//		}
//		
//		if (m_cmdSelect != null)
//		{
//			removeCommand( m_cmdSelect );
//			m_cmdSelect = null;
//		}		
//
//		// add new commands		
//		if (sOK != null)
//		{
//			m_cmdSelect = new Command( sOK, Command.OK, 1 );
//   			addCommand( m_cmdSelect );
//		}
//		if (sBack != null)
//		{
//			m_cmdBack = new Command( sBack, Command.BACK, 2 );
//   			addCommand( m_cmdBack );
//		}
//	}
//	
//	public void commandAction( Command c, Displayable d )
//	{
//#if defined(_USE_THREAD) || defined(_USE_KEY_QUEUE)
//		synchronized (m_aiKeyEvents)
//		{
//			if (m_iKeyEventCount < KEY_EVENT_QUEUE_SIZE-1)
//			{
//#endif
//				int iKey;
//				switch ( c.getCommandType() )
//				{
//				case Command.BACK:
//			    	iKey = 0x400000/*@VKEY_BACK*/;
//					break;
//				case Command.OK:
//			    	iKey = 0x200000/*@VKEY_SELECT*/;
//					break;
//				default:
//					iKey = 0;
//					break;
//				}
//#if !defined(_USE_THREAD) && !defined(_USE_KEY_QUEUE)
//				if ( iKey != 0 )
//				{
//					try
//					{
//						handleKeyPressed( iKey );
//						handleKeyReleased( iKey );
//					}
//					catch ( Exception e )
//					{
////						DUMP_EXCEPTION_MSG(e, "*** Error during commandAction ***");
//#ifdef _DISPLAY_MEM_ERROR
//						m_midlet.m_bCriticalError = true;
//#endif
//						m_midlet.exitRequested();
//					}					
//				}
//				
//#else
//				if ( iKey != 0 )
//				{
//				    addKeyEvent( iKey );
//				    addKeyEvent( iKey | 0x1000000/*@VKEY_RELEASED*/ );
//				}				
//			}
//		}
//#endif
//	}
//#else
	private Label	m_OKLabel;
	private Label	m_BackLabel;
	private Window	m_keyLabels;
	private boolean	m_bKeyLabelsDirty = true;
	public void createKeyLabels()
	{
		m_keyLabels = new Window( this );
		m_keyLabels.m_iPaintFlags = Window.PAINT_FILL;
		m_keyLabels.m_iFillColor = 0xFFFFFF/*@COLOR_WHITE*/;
		m_OKLabel = new Label(m_menuFont,0,0,0,0x000000/*@COLOR_BLACK*/,0,0);
		m_OKLabel.setAlignment( Drawable.ALIGNH_LEFT | Drawable.ALIGNV_MIDDLE );
		m_OKLabel.setText( null );
		m_keyLabels.addToFront( m_OKLabel );
		m_BackLabel = new Label(m_menuFont,0,0,0,0x000000/*@COLOR_BLACK*/,0,0);
		m_BackLabel.setAlignment( Drawable.ALIGNH_RIGHT | Drawable.ALIGNV_MIDDLE );
		m_BackLabel.setText( null );
		m_keyLabels.addToFront( m_BackLabel );
		m_keyLabels.setDimensions( getWidth(), m_OKLabel.m_iHeight );
		m_keyLabels.setPosition( 0, getHeight() - m_keyLabels.m_iHeight );
	}	

	public void setKeyLabels( int iOK, int iBack )
	{
		m_bKeyLabelsDirty = true;
		m_OKLabel.setText( iOK );
		m_BackLabel.setText( iBack );
	}
//#endif // _FULL_CANVAS

//#if defined(_USE_THREAD) || defined(_USE_KEY_QUEUE)
//	private void addKeyEvent( int iEvent )
//	{
//		synchronized (m_aiKeyEvents)
//		{
//			if (m_iKeyEventCount < KEY_EVENT_QUEUE_SIZE)
//			{
//				m_aiKeyEvents[(m_iKeyEventStart + m_iKeyEventCount)%KEY_EVENT_QUEUE_SIZE] = iEvent;
//				m_iKeyEventCount++;
//			}
//		}		
//	}	
//
//	public void clearKeyEvents()
//	{
//		synchronized (m_aiKeyEvents)
//		{
//			m_iKeyEventCount = 0;
//		}		
//	}	
//
//	private int getKeyEvent()
//	{
//		synchronized (m_aiKeyEvents)
//		{
//			int iEvent = 0;
//			if (m_iKeyEventCount > 0)
//			{
//				iEvent = m_aiKeyEvents[m_iKeyEventStart];
//				m_iKeyEventCount--;
//				m_iKeyEventStart++;
//				if (m_iKeyEventStart == KEY_EVENT_QUEUE_SIZE )
//					m_iKeyEventStart = 0;
//			}
//			return iEvent;
//		}		
//	}	
//
//	private void publishKeyEvents() throws IOException
//	{

⌨️ 快捷键说明

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