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

📄 torinocanvas.java

📁 国外人写的操作感挺好的一款滑雪游戏.结构也比较清楚
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
				
		m_iCurrentWindowID = iWindowID;
		
		switch( iWindowID )
		{
			case WINDOW_MENU: m_currentWindow = new MenuWindow(this); break;
			case WINDOW_SPLASH: m_currentWindow = new SplashWindow(this); break;
			case WINDOW_EVENT: m_currentWindow = new EventWindow(this); break;
//#ifndef _NO_MEDAL_CEREMONY
//			case WINDOW_MEDALCEREMONY: m_currentWindow = new MedalCeremonyWindow(this); break;
//#endif
//#ifdef _OPENING_CEREMONY
//			case WINDOW_OPENINGCEREMONY: m_currentWindow = new OpeningCeremonyWindow(this); break;
//#endif
		}
		
	}

	public void openMenu( int iMenuID ) throws IOException
	{
		if (m_iCurrentWindowID != WINDOW_MENU)
			openWindow( WINDOW_MENU );
			
		((MenuWindow)m_currentWindow).changeMenu( iMenuID );
	}
	
//*****************************************************************************
// Competition mode functions

	public void competition_init()
	{
//#ifndef _NO_GHOST
//		if ( m_gameData.iGameMode == 2/*@GAMEMODE_COMPETITION*/ )
//#endif
			m_gameData.iMaxPlayers = 4;
//#ifndef _NO_GHOST
//		else //if ( m_gameData.iGameMode == Mode_Challenge )
//			m_gameData.iMaxPlayers = 2;		
//#endif

		if ( !m_gameData.bCompetitionInitialized )
		{
			// initialize competition data
			m_gameData.iEvent = 0;
			m_gameData.iCurrentPlayer = 0;
			for (int i=0; i<m_gameData.iMaxPlayers; i++)
			{
				for (int j=0; j<3/*@EVENT_COUNT*/; j++)
				{
//#ifdef _LIMITED_EVENTS
					m_gameData.aiResults[i][j] = 0;
//#else
//					for (int k=0; k<3/*@MAX_ATTEMPTS*/; k++)
//						m_gameData.aiResults[i][j][k] = 0;
//#endif
				}
				m_gameData.aiTotalScore[i] = 0;
				// clear the attempts for all players
				m_gameData.aiAttempt[i] = 0;
			}
		}	
	}

	public void competition_begin() throws IOException
	{	
		// make sure AI is set correctly based on number of human players
//#ifndef _NO_ONLINE
//		if (!m_gameData.bOnline)
//		{
//#endif
			for (int i=m_gameData.iNumPlayers; i<m_gameData.iMaxPlayers; i++)
			{
				boolean bRepeat;
				do
				{
					bRepeat = false;
					m_gameData.aiCountry[i] = getRand(11/*@NATION_COUNT*/);
					for (int j=0; j<i; j++)
					{
						if (m_gameData.aiCountry[i] == m_gameData.aiCountry[j])
							bRepeat = true;
					}
				} while (bRepeat);

				m_gameData.asName[i] = 
					getString( STRING_ATHLETE0+m_gameData.aiCountry[i] );
			}
//#ifndef _NO_ONLINE
//		}
//#endif
		
//#ifndef _NO_ONLINE
//		m_gameData.iLastTransmit = -1;
//#endif
		m_gameData.iCurrentPlayer = 0;
		m_gameData.bCompetitionInitialized = true;
		

//#ifdef _OPENING_CEREMONY
//		openWindow( WINDOW_OPENINGCEREMONY );
//#else
		openMenu( MenuWindow.MENU_STANDINGS );
//#endif
	//openWindow( WINDOW_MEDALCEREMONY );

	}	

	public boolean competition_finishAttempt() throws IOException
	{
		// return true if the event is complete
	
		// we need to go to the next player until there are no attempts remaining,
		// then iterate the event
		m_gameData.aiAttempt[m_gameData.iCurrentPlayer]++;
	
		if ( m_gameData.iCurrentPlayer < m_gameData.iNumPlayers-1 )
		{
			// iterate player on same event and attempt
			m_gameData.iCurrentPlayer++;
	
			// start event
			return false;
		}
		else
		{
			m_gameData.iCurrentPlayer = 0;
	
			// for ski jump there are three attempts
//#ifndef _LIMITED_EVENTS
//			if ( m_gameData.iEvent == EVENT_SKI_JUMP && 
// 				 m_gameData.aiAttempt[m_gameData.iCurrentPlayer] < 3/*@MAX_ATTEMPTS*/ )
//			{
//				// start event
//				return false;
//			}
//			else
//			{
//#endif			// show standings
				return true;
//#ifndef _LIMITED_EVENTS
//			}
//#endif
		}
	}	

	public void competition_finishEvent() throws IOException
	{
		boolean bNewRecord = false;
		if ( m_gameData.iGameMode != 3/*@GAMEMODE_CHALLENGE*/ )
		{
			competition_generateAIResults();
			m_gameData.iEvent++;
			// calculate scores
			bNewRecord = competition_calculateScores();
	
			if ( m_gameData.iEvent == 3/*@EVENT_COMPETITION*/ )
				competition_updateRecords(m_gameData.iEvent);
		}
		else
		{
//#ifndef _NO_ONLINE
//			m_gameData.iLastTransmit = -1;
//#endif
			bNewRecord = competition_updateRecords(m_gameData.iEvent);
		}
	
		// clear the attempts for all players
		for (int i=0; i<m_gameData.iMaxPlayers; i++)
			m_gameData.aiAttempt[i] = 0;
			//m_gameData.competition.aPlayers[i].iAttempt = 0;
	
		m_gameData.iCurrentPlayer = 0;
	
		// show event results
		if (bNewRecord)
		{
//#ifndef _NO_GHOST
//			m_gameData.bGhostScoreSearch = false;
//#endif
			openMenu( MenuWindow.MENU_LOCALRECORDS );
			return;
		}
		else
			openMenu( MenuWindow.MENU_EVENTRESULTS );
	}
	
	public void competition_recordScore( int iPlayer, int iEvent, int iResult )
	{
//#ifdef _LIMITED_EVENTS
		m_gameData.aiResults[iPlayer][iEvent] = iResult;
//#else
//		m_gameData.aiResults[iPlayer][iEvent][m_gameData.aiAttempt[iPlayer]] = iResult;
//#endif
	}
	
	private void competition_generateAIResults()
	{
		for( int i = m_gameData.iNumPlayers; i < m_gameData.iMaxPlayers; i++)
		{
//#ifdef _LIMITED_EVENTS
			if( m_gameData.aiResults[i][m_gameData.iEvent] == 0)
			{
				// generate an IAAF score and work backwards
				int iScore = aiBase[m_gameData.iDifficulty] +
					(m_aiAITable[m_gameData.aiCountry[i]][m_gameData.iEvent] * 40) + 
					getRand(201);
				int iResult = competition_convertScore( CONVERT_IAAFTOEVENT, m_gameData.iEvent, iScore );
				m_gameData.aiResults[i][m_gameData.iEvent] = iResult;
			}
//#else
//			if( m_gameData.aiResults[i][m_gameData.iEvent][0] == 0)
//			{
//				// generate an IAAF score and work backwards
//				int iScore = aiBase[m_gameData.iDifficulty] +
//					(m_aiAITable[m_gameData.aiCountry[i]][m_gameData.iEvent] * 40) + 
//					getRand(201);
//				int iResult = competition_convertScore( CONVERT_IAAFTOEVENT, m_gameData.iEvent, iScore );
//				m_gameData.aiResults[i][m_gameData.iEvent][0] = iResult;
//			}
//#endif
		}
	}
	
	private boolean competition_calculateScores()
	{
		for( int i = 0; i < m_gameData.iMaxPlayers; i++)
		{
			m_gameData.aiTotalScore[i] = 0;
			for( int j = 0; j < m_gameData.iEvent; j++ )
			{
				int iBestScore = 0;
//#ifndef _LIMITED_EVENTS
//				int iAttempts;
//				if( j == EVENT_SKI_JUMP)
//					iAttempts = 3/*@MAX_ATTEMPTS*/;
//				else
//					iAttempts = 1;
//				for( int k = 0; k < iAttempts; k++ )
//				{
//					if( m_gameData.aiResults[i][j][k] != 0 )
//					{
//						int iScore = competition_convertScore( CONVERT_EVENTTOIAAF, j,
//															   m_gameData.aiResults[i][j][k] );
//						if( iScore > iBestScore )
//							iBestScore = iScore;
//					}
//				}
//#else
				if( m_gameData.aiResults[i][j] != 0 )
				{
					int iScore = competition_convertScore( CONVERT_EVENTTOIAAF, j,
														   m_gameData.aiResults[i][j] );
					if( iScore > iBestScore )
						iBestScore = iScore;
				}
//#endif
				m_gameData.aiTotalScore[i] += iBestScore;
			}
		}
	
		// check event records against the scores for this player
		return competition_updateRecords( m_gameData.iEvent - 1 );
	}

	private boolean competition_updateRecords( int iEvent )
	{
		boolean bNewRecord = false;
	
		// for this event, check all human player scores against records for this event
		for (int i=0; i<m_gameData.iNumPlayers; i++)
		{
//#ifndef _LIMITED_EVENTS
//			int iAttempts;
//			if (iEvent == EVENT_SKI_JUMP)
//				iAttempts = 3/*@MAX_ATTEMPTS*/;
//			else
//				iAttempts = 1;
//			
//			for( int j = 0; j < iAttempts; j++)
//			{
//#endif
				int iScore;
				if (iEvent == 3/*@EVENT_COMPETITION*/)
				{
					iScore = m_gameData.aiTotalScore[i];
				}
				else
				{
//#ifndef _LIMITED_EVENTS
//					iScore = m_gameData.aiResults[i][iEvent][j];
//#else
					iScore = m_gameData.aiResults[i][iEvent];
//#endif
				}
	
				// is this score better than any record?
				if (iScore == 0)
					continue;
	
				int iRank;
				for( iRank = 0; iRank < 10/*@NUM_LOCAL_RECORDS*/; iRank++)
				{
					if( 
//#ifndef _LIMITED_EVENTS
//						(iEvent != EVENT_SKI_JUMP) && 
//#endif
						(iEvent != 3/*@EVENT_COMPETITION*/) )
					{
						if (m_gameData.aiRecordScores[iEvent][iRank] > iScore ||
							m_gameData.aiRecordScores[iEvent][iRank] == 0)
						{
							break;
						}
					}
					else
					{
						if (m_gameData.aiRecordScores[iEvent][iRank] < iScore ||
							m_gameData.aiRecordScores[iEvent][iRank] == 0)
						{
							break;
						}
					}
				}
	
				if (iRank < 10/*@NUM_LOCAL_RECORDS*/)
				{
					// new record - insert here
					for( int k = 10/*@NUM_LOCAL_RECORDS*/ - 1; k > iRank; k--)
					{
						m_gameData.aiRecordScores[iEvent][k] = 
							m_gameData.aiRecordScores[iEvent][k-1];
						m_gameData.abRecordNew[iEvent][k] = 
							m_gameData.abRecordNew[iEvent][k-1];
						m_gameData.asRecordNames[iEvent][k] = m_gameData.asRecordNames[iEvent][k-1];
					}
					m_gameData.aiRecordScores[iEvent][iRank] = iScore;
					m_gameData.abRecordNew[iEvent][iRank] = true;
	
//#ifndef _NO_ONLINE
//#ifndef _IS_SPRINT
//					if (m_gameData.bOnline)
//					{
//						m_gameData.asRecordNames[iEvent][iRank] = new String( m_gameData.sOnlineName );
//					}
//					else
//					{
//#endif
//#endif
						m_gameData.asRecordNames[iEvent][iRank] = new String( m_gameData.asName[i] );
//#ifndef _NO_ONLINE
//#ifndef _IS_SPRINT
//					}
//#endif
//#endif
	
					bNewRecord = true;
				}
//#ifndef _LIMITED_EVENTS
//			}
//#endif
		}
	
		return bNewRecord;
	}

	// Scoring table entries represent the range 1400 to 1
	private final static int CONVERT_IAAFTOEVENT = 0;
	private final static int CONVERT_EVENTTOIAAF = 1;

	private final static int competition_convertScore( int iType, int iEvent, int iScore)
	{
		// Scoring table entries represent the range 1400 to 1
		final int aiScoreTable[][] =
		{
			{ // 500m skating, ms
				34000, 34500, 35000, 35500, 36000,
				37000, 38000, 39000, 40000, 42000,
				44000, 46000, 48000, 50000, 63000
			},
//#ifndef _LIMITED_EVENTS
//			{ // Ski Jump, points (fixed32)
//				// 130, 125, 120, 115, 110
//				// 105, 100, 95, 90, 85
//				// 80, 75, 70, 65, 60
//				8519680, 8192000, 7864320, 7536640, 7208960,
//				6881280, 6553600, 6225920, 5898240, 5570560,
//				5242880, 4915200, 4587520, 4259840, 3932160
//			},
//#endif
			{ // Biathlon, ms
				65000, 69000, 73000, 77000, 81000,
				85000, 90000, 95000, 100000, 105000,
				110000, 120000, 140000, 160000, 180000
			},
			{ // Slalom, ms
				70000, 72000, 75000, 78000, 81000,
				84000, 88000, 92000, 97000, 101000,
				105000, 110000, 115000, 125000, 150000
			}
		};
	
		if (iType == CONVERT_IAAFTOEVENT)
		{
			iScore =  ( ( (iScore) <= (0) ) ? (0) : ( ( (iScore) >= (1400) ) ? (1400) : (iScore) ) ) ;
			int iBase = 14 - (iScore/100);
	
			int iResult;
			if (iScore <= 1)
				iResult = aiScoreTable[iEvent][14];
			else
			{
				iResult = ((iScore%100) * aiScoreTable[iEvent][iBase+1] + 
					(100 - iScore%100) * aiScoreTable[iEvent][iBase])/100;
			}
	
			return iResult;
		}
		else
		{
//#ifndef _LIMITED_EVENTS
//			if (iEvent != EVENT_SKI_JUMP)
//			{
//#endif
				if ( iScore <= aiScoreTable[iEvent][0] )
					return 1400;
				else if (iScore >= aiScoreTable[iEvent][14])
					return 1;
	
				for( int i=0; i < 14; i++ )
				{
					if (iScore > aiScoreTable[iEvent][i] && iScore <= aiScoreTable[iEvent][i+1])
					{
						int range = aiScoreTable[iEvent][i+1] - aiScoreTable[iEvent][i];
						int diff = aiScoreTable[iEvent][i+1] - iScore;
						int score = (diff*100)/range + (13-i)*100;
						return score; 
					}
				}
//#ifndef _LIMITED_EVENTS
//			}
//			else
//			{
//				if ( iScore >= aiScoreTable[iEvent][0] )
//					return 1400;
//				else if (iScore <= aiScoreTable[iEvent][14])
//					return 1;
//	
//				for( int i=0; i < 14; i++ )
//				{
//					if (iScore < aiScoreTable[iEvent][i] && iScore >= aiScoreTable[iEvent][i+1])
//					{
//						int range = aiScoreTable[iEvent][i] - aiScoreTable[iEvent][i+1];
//						int diff = iScore - aiScoreTable[iEvent][i+1];
//						int score = (diff*100)/range + (13-i)*100;
//						return score; 
//					}
//				}
//			}
//#endif
			return 0;
		}
	}

	public final static String convertResultToText( int iEvent, int iResult )
	{
		if ( iEvent == 3/*@EVENT_COMPETITION*/ )
		{
			return Integer.toString(iResult);
		}
//#ifndef _LIMITED_EVENTS
//		else if ( iEvent != EVENT_SKI_JUMP )
//		{
//#endif
			// timed events
			if (iResult == 0)
			{
				return "---";
			}
			else
			{
				int a = iResult / 60000;
				int b = (iResult / 10000)%6;
				int c = (iResult / 1000)%10;
				int d = (iResult / 100)%10;
				int e = (iResult / 10)%10;
				
				String s = new String();
				
				if (iEvent == 0/*@EVENT_SKATING*/)
					s = a + ":" + b + c + "." + d + e;
				else
					s = a + ":" + b + c + "." + d;

⌨️ 快捷键说明

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