📄 torinocanvas.java
字号:
// we're only going to store animation data for a few gates
// we'll pad it a bit to take into account the fact that the
// skier still moves while the gates animate.
//#ifdef _HIRES_GRAPHICS
////#define HURDLE_XOFF 12
////#define HURDLE_HEIGHT 31 // in pixels
////#define SHOOTINGREF_HEIGHT 54
////#define PIXEL_PER_M 24
////#define M_PER_PIXEL 2731
//#else
//#endif
//#define MAX_PLAYERS 4
//#ifndef _MAX_HUMAN_PLAYERS
//#endif
// Virtual key codes
// COLORS (RGB)
//#ifdef _LOW_DETAIL
//#else
////#define COLOR_SKY 0xc1ccf5
//#endif
//#ifdef _MULTI_LANG
////#define LANG_COUNT 5
//#else
//#endif
//#ifndef _LIMITED_EVENTS
//
////#define EVENT_SKI_JUMP 1
////#define EVENT_BIATHLON 2
////#define EVENT_SKIING 3
////#define EVENT_COUNT 4
////#define EVENT_COMPETITION 4
//
//#else
//#endif
//#ifdef _IS_NokiaS40
//// #define SOUND_COUNT 5
//#elif defined(_IS_NokiaS60) && !defined(_MMAPI)
//// #define SOUND_CROWD 5
//// #define SOUND_CRASH 6
//// #define SOUND_COUNT 7
//#elif defined(_LIMITED_SOUNDS)
//// #define SOUND_CRASH 5
//// #define SOUND_COUNT 6
//#else
//#endif
//#endif
//#ifdef _DEBUG
// public static String m_sDebug = new String();
//#endif
//*****************************************************************************
public final static int STATE_INIT = 0;
public final static int STATE_NORMAL = 1;
public final static int STATE_EXITING = 2;
public final static int WINDOW_NONE = -1;
public final static int WINDOW_MENU = 0;
public final static int WINDOW_SPLASH = 1;
public final static int WINDOW_EVENT = 2;
//#ifndef _NO_MEDAL_CEREMONY
// public final static int WINDOW_MEDALCEREMONY = 3;
//#endif
//#ifdef _OPENING_CEREMONY
// public final static int WINDOW_OPENINGCEREMONY = 4;
//#endif
private final static int KEY_EVENT_QUEUE_SIZE = 32;
private final static int aiBase[] = { 400, 600, 800 };
//*****************************************************************************
private final Display m_display;
public final Torino m_midlet;
public static int m_iScreenHeight;
public static int m_iScreenWidth;
private Window m_currentWindow;
private int m_iCurrentWindowID = WINDOW_NONE;
public GameData m_gameData;
// fonts
public Font m_menuFont;
public Font m_largeFont;
private Random m_randGen = new Random();
//#ifndef _FULL_CANVAS
// private Command m_cmdSelect;
// private Command m_cmdBack;
//#endif
//#if defined(_USE_THREAD) || defined(_USE_KEY_QUEUE)
// private int m_aiKeyEvents[];
// private int m_iKeyEventStart = 0;
// private int m_iKeyEventCount = 0;
//#endif
private static byte[] m_abyStringData;
public int m_iGameState = STATE_INIT;
//#ifdef _USE_THREAD
// public static Object s_paintLock = new Object();
// private boolean m_bPaintLock = false;
//#endif
private boolean m_bPaused = false;
public boolean m_bNeedPaint = true;
public boolean m_bPaintScheduled = false;
boolean m_bExiting = false;
// this does not need to be stored
// the menu ID we need to return to
// from the event menu in competition (-1 for event)
public int m_iPauseReturn;
//#ifdef _SPRINT_MRC
// public boolean m_bIsLicensed = false;
//#endif
//*****************************************************************************
public TorinoCanvas( Torino midlet, Display display )
{
m_display = display;
m_midlet = midlet;
m_iScreenWidth = getWidth();
m_iScreenHeight = getHeight();
//#ifndef _FULL_CANVAS
// setCommandListener(this);
//#endif
try
{
//#if defined(_USE_THREAD) || defined(_USE_KEY_QUEUE)
// m_aiKeyEvents = new int[KEY_EVENT_QUEUE_SIZE];
// m_iKeyEventCount = 0;
// m_iKeyEventStart = 0;
//#endif
m_gameData = new GameData();
m_menuFont = Font.getFont( Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL );
m_largeFont = Font.getFont( Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_LARGE );
m_gameData.iGameMode = 0/*@GAMEMODE_NONE*/;
m_gameData.iEvent = (-1)/*@EVENT_NONE*/;
m_gameData.bInitialized = false;
//#ifndef _NO_GHOST
// m_gameData.bGhostOnlineNameSearch = false;
// m_gameData.bGhostScoreSearch = false;
//#endif
resetRecords();
for (int i=0; i<4/*@MAX_TOTAL_PLAYERS*/; i++)
{
m_gameData.asName[i] = Integer.toString( i+1 ) + "UP";
}
//#ifndef _NO_ONLINE
//#ifndef _IS_SPRINT
// m_gameData.sOnlineName = "";
// m_gameData.bOnlineNameSet = false;
//#endif
//#endif
//#ifdef _MULTI_LANG
// m_gameData.bLanguageSet = false;
// m_gameData.iLang = 0;
//
// try
// {
// // default to current handset language if available
// String s = System.getProperty("microedition.locale");
// if (s.startsWith("es"))
// m_gameData.iLang = 1;
// else if (s.startsWith("fr"))
// m_gameData.iLang = 2;
// else if (s.startsWith("de"))
// m_gameData.iLang = 3;
// else if (s.startsWith("it"))
// m_gameData.iLang = 4;
// }
// catch (Exception e)
// {
// }
//
//#endif
m_gameData.bDisableSound = true;
m_gameData.bDisableTips = false;
m_gameData.iDifficulty = 1/*@DIFFICULTY_NORMAL*/;
//#ifdef _MULTI_LANG
// if (!loadData())
// saveData(true);
// loadDictionary(m_gameData.iLang);
//#else
loadDictionary();
//#endif
//#ifdef _FULL_CANVAS
createKeyLabels();
//#endif
//#if defined(_IS_SPRINT) && !defined(_NO_SOUND)
// com.sprintpcs.media.Player.addPlayerListener(this);
//#endif
//#ifndef _NO_ONLINE
//#ifdef _IS_SPRINT
// // get Game Lobby name
// createOnlineService();
// m_bLoginError = false;
// m_bLoggingIn = true;
// m_jci.getName();
//#endif
//#endif
// open splash window here
//#ifdef _BUFFER_IO
//#ifdef _KEEP_FILE_DATA
// // preload files
// getFile( RESFILE_SKATING );
//#ifdef _OPENING_CEREMONY
// //getFile( RESFILE_OPENING );
//#endif
// getFile( RESFILE_SKIING );
//#ifndef _LIMITED_EVENTS
// getFile( RESFILE_SKIJUMP );
//#endif
// getFile( RESFILE_RAMP );
// getFile( RESFILE_COUNTRY );
//#ifndef _NO_MEDAL_CEREMONY
// getFile( RESFILE_AWARDS );
//#endif
// getFile( RESFILE_AUDIO );
// getFile( RESFILE_BIATHLON );
// getFile( RESFILE_MENU );
// getFile( RESFILE_TARGETS );
// getFile( RESFILE_COMMON );
//#endif
//#endif
//#ifdef _IS_NokiaS60
// // preload the images we will use
// Image image = loadPackedImage( RESFILE_COMMON, 0/*@RES_SIGN1*/ );
// image = loadPackedImage( RESFILE_COMMON, RES_SIGN2 );
// image = loadPackedImage( RESFILE_COMMON, RES_SKY );
// image = loadPackedImage( RESFILE_COMMON, 1/*@RES_TREE*/ );
// image = loadPackedImage( RESFILE_COMMON, RES_TREESHADOW );
// image = loadPackedImage( RESFILE_COMMON, 2/*@RES_TREESFAR*/ );
// image = loadPackedImage( RESFILE_COMMON, RES_CROWD );
// image = loadPackedImage( RESFILE_COMMON, 4/*@RES_DOWNHILL*/ );
// image = loadPackedImage( RESFILE_SKIING, RES_SLALOM_TRACK_R );
// image = loadPackedImage( RESFILE_SKIING, RES_SLALOM_TRACK_L );
// image = loadPackedImage( RESFILE_SKIING, RES_SLALOM_TRACK_S );
// image = loadPackedImage( RESFILE_SKIING, 18/*@RES_FLAG_RED*/ );
// image = loadPackedImage( RESFILE_SKIING, 19/*@RES_FLAG_BLUE*/ );
// image = loadPackedImage( RESFILE_SKIING, 20/*@RES_SIGN_VERT*/ );
// image = loadPackedImage( RESFILE_SKIING, 21/*@RES_COMPASS*/ );
// image = loadPackedImage( RESFILE_RAMP, RES_RAMP );
// image = loadPackedImage( RESFILE_RAMP, RES_RAMPEND1 );
// image = loadPackedImage( RESFILE_RAMP, RES_RAMPEND2 );
// image = loadPackedImage( RESFILE_RAMP, RES_RAMPEND3 );
// image = loadPackedImage( RESFILE_RAMP, RES_RAMPEND4 );
// image = loadPackedImage( RESFILE_RAMP, RES_RAMPEND5 );
// image = loadPackedImage( RESFILE_RAMP, RES_RAMPEND6 );
// image = loadPackedImage( RESFILE_RAMP, RES_RAMPEND7 );
// image = loadPackedImage( RESFILE_RAMP, RES_ARROWD );
// image = loadPackedImage( RESFILE_RAMP, RES_ARROWU );
// image = loadPackedImage( RESFILE_RAMP, RES_ARROWL );
// image = loadPackedImage( RESFILE_RAMP, RES_ARROWR );
// image = loadPackedImage( RESFILE_RAMP, RES_ARROWWRONG );
// image = loadPackedImage( RESFILE_RAMP, RES_BARBK );
// image = loadPackedImage( RESFILE_RAMP, RES_BARFR );
// image = loadPackedImage( RESFILE_TARGETS, 28/*@RES_GUNSIGHT*/ );
// image = loadPackedImage( RESFILE_TARGETS, 29/*@RES_RICHOCHET*/ );
// image = loadPackedImage( RESFILE_TARGETS, 31/*@RES_TARGETFAR*/ );
// image = loadPackedImage( RESFILE_TARGETS, 32/*@RES_TARGETSTAND*/ );
// image = loadPackedImage( RESFILE_TARGETS, 33/*@RES_TARGETFILL*/ );
// image = loadPackedImage( RESFILE_TARGETS, RES_SNOWBANK );
// image = loadPackedImage( RESFILE_TARGETS, 5/*@RES_UPHILL*/ );
// image = loadPackedImage( RESFILE_TARGETS, 34/*@RES_HEART*/ );
// image = loadPackedImage( RESFILE_AWARDS, RES_AWARDSTAND );
// image = loadPackedImage( RESFILE_OPENING, RES_INTRO_STAIRS );
// image = loadPackedImage( RESFILE_OPENING, RES_INTRO_FIREPLACE );
// image = null;
//#endif
openWindow( WINDOW_SPLASH );
}
catch( IOException e )
{
// DUMP_EXCEPTION(e);
}
}
public void hideNotify()
{
// DEBUG_MSG( "hideNotify" );
pause();
}
public void showNotify()
{
// DEBUG_MSG( "showNotify" );
unpause();
}
public void pause()
{
// DEBUG_MSG( "pause" );
if (!m_bPaused)
{
m_bPaused = true;
if (m_currentWindow != null && m_iCurrentWindowID==WINDOW_EVENT)
{
((EventWindow) m_currentWindow).pause();
}
pauseSound();
}
}
public void unpause()
{
// DEBUG_MSG( "unpause" );
m_bPaused = false;
m_bNeedPaint = true;
//#ifdef _FULL_CANVAS
m_bKeyLabelsDirty = true;
//#endif
resumeSound();
}
//#ifdef _DISPLAY_MEM_ERROR
// public final void displayErrorAlert()
// {
// Alert alert = new Alert( "Memory Error" );
// alert.setTimeout(5000);
// alert.setString( "You must recycle the power on your phone before continuing to play this game. Please turn the power off, then on, then restart the game." );
// alert.setType( AlertType.ERROR );
// m_display.setCurrent( alert );
// try { Thread.currentThread().sleep(5000); } catch (InterruptedException e) {}
// }
//#endif
//#ifdef _DEBUG
// public final void debug_alert( String s )
// {
// Alert alert = new Alert( "Debug", s, null, AlertType.INFO );
// alert.setTimeout(3000);
// m_display.setCurrent( alert, this );
// try { Thread.currentThread().sleep(3000); } catch (InterruptedException e) {}
// }
//#endif
public int getRand( int i )
{
if (i>0)
return (Math.abs(m_randGen.nextInt()) % i);
else
return 0;
}
public final int getCanvasHeight()
{
//#ifdef _FULL_CANVAS
if ( m_keyLabels != null )
return getHeight() - m_keyLabels.m_iHeight;
else
return getHeight();
//#else
// return getHeight();
//#endif
}
public final static int getCurrentTime()
{
return (int) System.currentTimeMillis();
}
//#ifdef _CLOSE_STREAMS
// public final static void closeInputStream( InputStream is )
// {
// try
// {
// if (is != null)
// is.close();
// }
// catch (IOException e)
// {
// }
// }
//
// public final static void closeOutputStream( OutputStream os )
// {
// try
// {
// if (os != null)
// os.close();
// }
// catch (IOException e)
// {
// }
// }
//#endif
public void resetRecords()
{
for (int i=0; i<10/*@NUM_LOCAL_RECORDS*/; i++)
{
for (int j=0; j<=3/*@EVENT_COMPETITION*/; j++)
{
m_gameData.asRecordNames[j][i] = "---";//"" + (char)(0x41 + i);
m_gameData.aiRecordScores[j][i] = 0;//i;
m_gameData.abRecordNew[j][i] = false;
}
}
}
public void startGame() throws IOException
{
//#ifndef _MULTI_LANG
if (!loadData())
saveData(true);
//#endif
//#if defined(_BUFFER_IO) && defined(_KEEP_FILE_DATA)
// // Free up the read buffer. It is no longer needed after preload
// m_readBuffer = null;
//#endif
// check the game data to see what the start state should be
if (m_gameData.bInitialized || m_gameData.bCompetitionInitialized)
openMenu( MenuWindow.MENU_RESUMEGAME );
//#ifdef _MULTI_LANG
// else if (!m_gameData.bLanguageSet)
// openMenu( MenuWindow.MENU_SELECTLANGUAGE );
//#endif
else
{
openMenu( MenuWindow.MENU_MAIN );
}
}
public void openWindow( int iWindowID ) throws IOException
{
if (m_currentWindow!=null)
{
m_currentWindow.unloadResources();
m_currentWindow = null;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -