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

📄 gameshell.java

📁 CreatLog luke 俄罗斯方块
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    boolean GASaveNVData(GameSaveable gameData) {	RecordStore store;	byte[] data;	ByteArrayOutputStream bos;	DataOutputStream dos;	boolean createNew = false;	try{	    store = RecordStore.openRecordStore(getGameName(),true);	    if(store == null) return false;	    bos = new ByteArrayOutputStream();	    dos = new DataOutputStream(bos);	    gameData.serialize(dos);	    dos.flush();	    bos.flush();	    data = bos.toByteArray();	    dos.close();	    bos.close();	    try{		store.setRecord(1,data,0,data.length);	    }	    catch( InvalidRecordIDException rse ) {		store.addRecord(data,0,data.length);	    }	}	catch( Exception exc ) {	    exc.printStackTrace();	    return false; // exc could be RecordStoreExc or IOExc	}	return true;    }    /** Returns an object containing the menu settings      * with fields that control which menus should be      * displayed as well as which menus have been selected.      *      * @param gameID <i>Obsolete</i>. Was typedef unsigned int MenuItemId_t      */    GAMenuSelectObject_t GAGetMenuSetting() {	return mso;    }    /**      * Get the current date. Not Y10k safe.      *      * @param currentDate A pointer to string in where the date will be placed,       *    the date is on the form YYYY:MM:DD      *      * @returns TRUE if everything went OK      *     If it went wrong the parameter CurrentDate is set to 2000:01:01      *      *      */    boolean GAGetCurrentDate(StringBuffer currentDate)    {	Calendar rightNow = Calendar.getInstance();	int year = rightNow.get(Calendar.YEAR);	int month = rightNow.get(Calendar.MONTH);	int day = rightNow.get(Calendar.DAY_OF_MONTH);	currentDate.delete( 0, currentDate.length() );	currentDate.append(Integer.toString(year)+":");	if(month<10) currentDate.append("0");	currentDate.append(Integer.toString(month)+":");	if(day<10) currentDate.append("0");	currentDate.append(Integer.toString(day));	return true;    }    /*      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                                           Gapisound      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    */    /**      * Create a single tone in the speaker. Sound is not available in MIDP 1.0.      * <p>      * <i>Dummy method. This means it does nothing yet, or is at best partially implemented.</i>      *      * @param Freq The frequence of the tone. It is a discrete scale       *       from G, A, H, C, D, E, F with half tones up and down      *       this is from 396 Hz up to 1991 Hz. All params were uint16 in C.      * @param Duration The time in milliseconds, in span 100 -> 1000 in steps of 100      * @param Pitch The level of the tone, valid values are 0 -> 10. If this is 0       *           then use the predefined setting used by the user. 10 is reserved do not use it.      *      *      */    void GASound(int Freq, int Duration, int Pitch) {}    /**      * This method will play a predefined sound effect. Sound is not available in MIDP 1.0.      * <p>      * <i>Dummy method. This means it does nothing yet, or is at best partially implemented.</i>      *      * @param soundEffect the sound effect to play      *		The method will search for files with the name 'game_SoundEffect'. This was const char * in C.      *      * @returns TRUE if the requested sound will be played      *      */    boolean GASoundEffectPlay(String soundEffect) {	return true;    }    /*      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                                           Gapisfx      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    */    /**      * Getting the image id from a file name placed in the games directory      * <p>      * <i>Probably not implementable in MIDP. (obsolete)</i>      *      * @param menuId The menu id of the game. <i>Obsolete</i>. (Was MenuItemId_t in c: typedef unsigned int MenuItemId_t)      * @param filename The filename for the operational (was const char *)      *      * @returns 0 if something went wrong, for example the file does not exist      * Otherwise the return value is the image edit used by GACharOut. was uint16.      *      * @see GAfopen      */    int GAGetImageId(String fileName) {	return 0;    }    /*      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                                           Gapihighscore      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    */    // This is from the enum GAPI_HighscoreMenuState_e    static final byte ViewHighscoreEntry = 0;    static final byte InputHighscoreEntry = 1;    static final byte DoneHighScoreList = 2;    static final byte ClearHighScoreList = 3;    static final byte SendHighScoreList = 4;    static final int GAPI_HIGHSCORE_NUMBER_OF_ENTRYS = 3;    static final int GAPI_HIGHSCORE_USE_SCORE = 7;    static final int GAPI_HIGHSCORE_USE_NAME = 3;    static final char GAPI_HIGHSCORE_UNSET_CHAR = '?';    static final int GAPI_high_back_width = 101;    static final int GAPI_high_back_height = 16;    static final int GAPI_high_highmask_width = 101;    static final int GAPI_high_highmask_height = 16;    static final int GAPI_high_highorig_width = 101;    static final int GAPI_high_highorig_height = 16;    static final int GAMES_HIGHSCORE_ICON_ID = 256; // Unicode of first icon    static final int GAMES_HIGHSCORE_ICON_COUNT = 19; // The number of different icons    static final int GAPI_HIGHSCORE_UNINIT_DIFF = 65000;    static int HighscoreIconId; // This allows games to use different patterns.    byte GASendHighscore = DoneHighScoreList;    static final int GAPI_HIGHSCORE_INPUT_STEP_BACKWARD1   = KeyLeft;    static final int GAPI_HIGHSCORE_INPUT_STEP_BACKWARD2   = KeyLeftUp;    static final int GAPI_HIGHSCORE_INPUT_STEP_FORWARD1    = KeyRight;    static final int GAPI_HIGHSCORE_INPUT_STEP_FORWARD2    = KeyRightDown;    /**      * Button used to step backward when inputing a name      *      */    static final int  GAPI_HIGHSCORE_INPUT_CLEAR  = KeyClear;    static final int  GAPI_HIGHSCORE_INPUT_ACCEPT  = KeyYes;    static final int  GAPI_HIGHSCORE_INPUT_NOT_ACCEPT  = KeyNo;    static final int GAPI_HSANIM_BACKGR = 5;    static final int GAPI_HSANIM_FOREGR = 0;    Image hsForegroundImage;    Image hsBackgroundImage;    static final int GAPI_HIGHSCORE_SHOW_CURSOR_SPEED = 1;    static final int GAPI_HIGHSCORE_SHOW_ANIM_STEP = 3;    class GAPI_HighscoreEntry_t implements GameSaveable{	char[][] Name = new char[GAPI_HIGHSCORE_NUMBER_OF_ENTRYS][GAPI_HIGHSCORE_USE_NAME];	int[] Difficult = new int[GAPI_HIGHSCORE_NUMBER_OF_ENTRYS]; /*uint16*/ 	char[][] Score = new char[GAPI_HIGHSCORE_NUMBER_OF_ENTRYS][GAPI_HIGHSCORE_USE_SCORE];	boolean HighscoreListHasEntries; 	public void serialize( DataOutputStream dos ) throws IOException {	    for(int i = 0; i<GAPI_HIGHSCORE_NUMBER_OF_ENTRYS; i++)		for(int j = 0; j<GAPI_HIGHSCORE_USE_NAME; j++)		    dos.writeChar(Name[i][j]);	    for(int i = 0; i<GAPI_HIGHSCORE_NUMBER_OF_ENTRYS; i++)		dos.writeInt(Difficult[i]);	    for(int i = 0; i<GAPI_HIGHSCORE_NUMBER_OF_ENTRYS; i++)		for(int j = 0; j<GAPI_HIGHSCORE_USE_SCORE; j++)		    dos.writeChar(Score[i][j]);	    dos.writeBoolean(HighscoreListHasEntries);	}	public void unSerialize( DataInputStream dis ) throws IOException {	    for(int i = 0; i<GAPI_HIGHSCORE_NUMBER_OF_ENTRYS; i++)		for(int j = 0; j<GAPI_HIGHSCORE_USE_NAME; j++)		    Name[i][j] = dis.readChar();	    for(int i = 0; i<GAPI_HIGHSCORE_NUMBER_OF_ENTRYS; i++)		Difficult[i] = dis.readInt();	    for(int i = 0; i<GAPI_HIGHSCORE_NUMBER_OF_ENTRYS; i++)		for(int j = 0; j<GAPI_HIGHSCORE_USE_SCORE; j++)		    Score[i][j] = dis.readChar();	    HighscoreListHasEntries = dis.readBoolean();	}    }    class GAPI_HighscoreList_t{	int CurrentTopLine; /*uint8*/ 	int CursorLine; /*sint16*/ 	int CursorPosition; /*sint16*/	int CursorBlinkRate; /*sint16*/	char CursorChar; 	boolean CursorBlink; 	int AnimationRate; /*sint16*/	int AnimationCnt; /*sint16*/	int AnimationX; /*sint16*/	int CursorX; /*sint16*/	int CursorY; /*sint16*/	byte MenuState; /*uint8*/	boolean ShowName;	boolean ShowDifficult;	boolean ShowScore;	boolean ShowMenu;	boolean ShowPlace; 	int ShowNrOfEntries; /*uint8*/	boolean DifficultType;    }    /**      * This method assume that Score in the highscore list is a number, this number is checked against Score      * If Score is higher than in the highscore list then it is inserted in the list and if entries is switched      * on then the highscore list is prepared for name input.      *      * @param highList The highscore list. C: was GAPI_HighscoreList_t *       * @param highEntry The entries coming from EEPROM. C: was GAPI_HighscoreEntry_t *       * @param score the Score to compare the highscore list entries. was uint32 = typedef unsigned long!.      * @param difficulty The difficulty level. was uint16.      *      * @return TRUE if the score have been added to the highscore list      */    boolean GAHighScoreAddNum(GAPI_HighscoreList_t HighList, GAPI_HighscoreEntry_t Entries, int Score, int Difficulty) {	boolean               Result = false;	int                   i;	int                   k;	int                   Hit = -1;	int                   StoredScore;	int                   factor;	for (i = 0; i < GAPI_HIGHSCORE_NUMBER_OF_ENTRYS; i++)	    {		StoredScore = 0;		factor = 1;				for(int j = GAPI_HIGHSCORE_USE_SCORE-1; j >= 0; j--) {		    StoredScore += factor * (int)(Entries.Score[i][j]-'0');		    factor *= 10;		}		//System.out.println("---> SCORE = "+Score+" STOREDSCORE = "+StoredScore);		if (Score > StoredScore)		    {			Hit = i;			i = GAPI_HIGHSCORE_NUMBER_OF_ENTRYS;			// Register that a highscore has been added to the list			Entries.HighscoreListHasEntries = true;			//			// Move down in the list			//		    }	    }	if (Hit >= 0)	    {		for (k = (GAPI_HIGHSCORE_NUMBER_OF_ENTRYS - 1); k > Hit; k--)		    {			for(int j = 0; j<GAPI_HIGHSCORE_USE_SCORE; j++)			    Entries.Score[k][j] = Entries.Score[k-1][j];			for(int j = 0; j<GAPI_HIGHSCORE_USE_NAME; j++)			    Entries.Name[k][j] = Entries.Name[k-1][j];			Entries.Difficult[k] = Entries.Difficult[k - 1];		    }		GAHighScoreSetScore(Entries, Hit, Score);		for(int j = 0; j<GAPI_HIGHSCORE_USE_NAME; j++)		    Entries.Name[Hit][j] = GAPI_HIGHSCORE_UNSET_CHAR;		Entries.Difficult[Hit] = Difficulty;		HighList.CursorLine = Hit;		HighList.CursorPosition = 0;		Result = true;	    }	return (Result);    }    /**      * This method initilize a highscore list.      * This method should be called first of all.      * <p>      * <i>Dummy method. This means it does nothing yet, or is at best partially implemented.</i>      *      * @param highList The highscore list. C: was GAPI_HighscoreList_t *       * @param highEntry The entries coming from EEPROM. C: was GAPI_HighscoreEntry_t *       */    void GAHighScoreListInit(GAPI_HighscoreList_t HighList, GAPI_HighscoreEntry_t Entries) {	int                    i;	int                    t;	HighList.ShowName = false;	HighList.ShowDifficult = false;	HighList.ShowScore = false;	HighList.ShowMenu = true;	HighList.ShowPlace = true;	HighList.ShowNrOfEntries = GAPI_HIGHSCORE_NUMBER_OF_ENTRYS;	HighList.CursorLine = -1;	HighList.CurrentTopLine = 0;	HighList.CursorPosition = 0;	HighList.CursorBlinkRate = 1;	HighList.CursorChar = 'A';	HighList.MenuState = DoneHighScoreList;	HighList.AnimationX = (DISPLAY_WIDTH - GAPI_high_back_width) / 2;	HighList.AnimationCnt = 0;	for (i = 0; i < GAPI_HIGHSCORE_NUMBER_OF_ENTRYS; i++)	    {		GAHighScoreSetScore(Entries, i, 0);		HighList.ShowScore = true;		Entries.Difficult[i] = '-';		HighList.ShowDifficult = true;		HighList.DifficultType = true;		for (t = 0; t < GAPI_HIGHSCORE_USE_NAME; t++)		    {			Entries.Name[i][t] = GAPI_HIGHSCORE_UNSET_CHAR;		    }		HighList.ShowName = true;	    }	HighscoreIconId = GAMES_HIGHSCORE_ICON_ID + (GARand() % GAMES_HIGHSCORE_ICON_COUNT);	//System.out.println("Setting HighscoreIconId to "+HighscoreIconId);    }    /**      * This method re-initilize a highscore list      * (clears all previous entries)      * <p>      * <i>Dummy method. This means it does nothing yet, or is at best partially implemented.</i>      *      * @param highList The highscore list. C: was GAPI_HighscoreList_t *       * @param highEntry The entries coming from EEPROM. C: was GAPI_HighscoreEntry_t *       *      */    void GAHighScoreListClear(GAPI_HighscoreList_t HighList, GAPI_HighscoreEntry_t Entries) {	  int                   i;	  int                   t;	  for (i = 0; i < GAPI_HIGHSCORE_NUMBER_OF_ENTRYS; i++)	      {

⌨️ 快捷键说明

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