maingame.java

来自「j2me 连连看源代码」· Java 代码 · 共 2,475 行 · 第 1/5 页

JAVA
2,475
字号
				{
                    //#ifdef S40
	            	//# loadTitleImage();
	            	//#endif
					if(bSound)
		        	{
		        		m_pEffect.StopSound() ;
		        		m_pEffect.PlaySound("/title.mid",true);
		        	}
				}
				
				//#ifdef COMMAND
				//# AddCommand(STAGE_TITLE);
				//#endif
				
				game_stage = STAGE_TITLE;
			}
		}
		m_iKey = KEY_NONE;
	}
	
	/**
	 * when enter the about stage , the keypressed event is processed here
	 */
	private final void flow_about()
	{
		
			keyMovement(m_iKey);
			        
			if(m_iKey == KEY_L)
			{
				about_ui = null;
				CreateTitleWindow();
				
                //#ifdef COMMAND
				//# AddCommand(STAGE_TITLE);
				//#endif
				game_stage = STAGE_TITLE;
			}
			m_iKey = KEY_NONE;
	}
	
	/**
	 * create the title window
	 */
	private static void CreateTitleWindow()
	{
		deleteWindow();
		menu_y = (short)(MENU_Y + view_y);
		menu_width = 80;
		//#ifdef K500
		//# menu_height = Common.FONT_LINE_H * 2;
		//#else
		menu_height = Common.FONT_LINE_H * 3;
		//#endif
		myWin = new Window(-1,menu_y,menu_width,menu_height,menu_ui);
	}
	
	/**
	 * 
	 *create system menu window
	 */
	private void createSystemWindow()
	{
		deleteWindow();
		menu_width = 80;
		menu_height = Common.FONT_LINE_H * 4 ;
		menu_y = (short)((screen_height - menu_height)>>1);
		if(bSound)
		{
			Text.system [1] = Text.on_off[0];
		}
		else
			Text.system [1] = Text.on_off [1];
		
		myWin = new Window(-1,menu_y,menu_width,menu_height,Text.system);
	}
	
	/**
	 * delete window
 	 */
	private static void deleteWindow()
	{
		if(myWin != null)
			myWin = null;
		System.gc();
	}
	
	private final void flow_setting(){
		if(m_iKey == KEY_L || m_iKey == KEY_FIRE){
			bSound = true;
			m_pEffect.StopSound();
			m_pEffect.PlaySound("/title.mid",true);
			//#ifdef COMMAND
			//# AddCommand(old_game_stage);
			//#endif
			game_stage = old_game_stage;
		}else if(m_iKey == KEY_R){
			bSound = false;
			m_pEffect.StopSound();
			//#ifdef COMMAND
			//# AddCommand(old_game_stage);
			//#endif
			game_stage = old_game_stage;
		}
		m_iKey = KEY_NONE;
	}
	
	/**
	 * call when load image from the resource.
	 * according to a progress ,you can know the condition of loading images
	 */
	private final void flow_loading()
	{
		if(image_loaded >= MAX_IMAGE)
		{   
            //#ifdef COMMAND
			//# AddCommand(STAGE_SETTING);
			//#endif
			
			//get some information (width and time) from the image
			timebar_width = m_pImage[TIME_BAR].getWidth() ;
			timebar_height = m_pImage[TIME_BAR].getHeight();
			congratulation_height = m_pImage[CONGRATULATION].getHeight();
			arrow_height = m_pImage[LEFTARROW].getHeight();
			combochar_width = m_pImage[COMBOCHAR].getWidth()/10 ;
			combochar_height = m_pImage[COMBOCHAR].getHeight() ;
			combo_width = m_pImage[COMBO].getWidth();
			back_width = m_pImage[BK].getWidth() ;
			back_height = m_pImage[BK].getHeight();
			menu_ui = Text.menu_item;
			bSound = readSound();
			if(bSound)
			{
				menu_ui[2] = Text.on_off[0];
			}
			else
				menu_ui[2] = Text.on_off [1];
			CreateTitleWindow();
			
			menu_option = 0;
			old_game_stage = STAGE_TITLE;
			game_stage = STAGE_SETTING;
			m_iKey = KEY_NONE;
			
		}
		else
		{
			if(image_loaded >=33 && image_loaded <= 38)
			{
				image_loaded++;
				return;
			}
			m_pImage[image_loaded] = loadImage(image_loaded++);
		}
	}
	
	private void setGameLevel(int _level)
	{
		game_level = _level;
		str_level = null;
		str_level = ""+game_level;
	}
	
	private void flow_title()
	{
		animation_counter++;
		animation_counter = (animation_counter&15);
		if (m_iKey != KEY_NONE){
			//Up button pressed
			if (m_iKey == KEY_UP)  {
				if(menuSelector>0){
					menuSelector--;
				}else{
					menuSelector = maxMenuItem - 1;
				}
				
				//#ifdef A760 || POINTER_PRESSED
				//# if(hasPointerEvents())
				//# {
					//# old_pointer--;
					//# if(myWin.selectedChoice == 5)
						//# old_pointer = 2;
					//# else 
					//# {
						//# if(old_pointer < 0)
							//# old_pointer = 0;
					//# }
				//# }
				//#endif
			}  
			//Down button pressed
			else if (m_iKey == KEY_DOWN){
				if(menuSelector<maxMenuItem-1){
					menuSelector++;
				}else{
					menuSelector = 0;
				}
				
				//#ifdef A760 || POINTER_PRESSED
				//# if(hasPointerEvents())
				//# {
					//# old_pointer++;
					//# if(myWin.selectedChoice == 0)
						//# old_pointer = 0;
					//# else 
					//# {
						//# if(old_pointer > 2)
							//# old_pointer = 2;
					//# }
				//# }
				//#endif
			}
			
			//  Confirm button pressed       
			//  Switch to corresponding stage 
			
			if (m_iKey == KEY_L || m_iKey == KEY_FIRE){
				menu_option =(byte)menuSelector;
				
				if (menu_option == 0)
				{   
					
					//#if !NO_PAY && PAY_001
					//#ifdef COMMAND
					//# AddCommand(STAGE_PAY);
					//#endif
					final int PAY_TIME = 4;
					final int ONE_TIME_MONEY = 1;					
					int wantTime = Rms.getPayRecord(MsgPay.PM_ONCE,PAY_TIME);
					if(wantTime>0){
						payType = MsgPay.PM_ONCE;
						payTime = PAY_TIME;
						money = ONE_TIME_MONEY;
						nowTime = (byte)(payTime - wantTime);
						Vector v = getSubsection("亲爱的玩家,谢谢支持正版游戏,初次进入游戏,你需连续发送"+
								wantTime+"条短信("+money+"元/条,不含通信费),就可永久免费使用该游戏,要发送吗?", screen_width - 20, "");
						payMsg = new String[v.size()];
						v.copyInto(payMsg);
						tmpState = (byte)game_stage;
						game_stage = STAGE_PAY;	
						return;
					}				
					//#endif
							
					//#if !NO_PAY && PAY_002
					//#ifdef COMMAND
					//# AddCommand(STAGE_PAY);
					//#endif
					//# int temp = Rms.getPayRecord(MsgPay.PM_THING_SKILL, 2);
					//# if(temp==1){
						//# final int PAY_TIME = 4;
						//# final int ONE_TIME_MONEY = 1;					
						//# int wantTime = Rms.getPayRecord(MsgPay.PM_PERLEVEL,PAY_TIME);
						//# if(wantTime>0){
							//# payType = MsgPay.PM_PERLEVEL;
							//# payTime = PAY_TIME;
							//# money = ONE_TIME_MONEY;
							//# nowTime = (byte)(payTime - wantTime);
							//# Vector v = getSubsection("亲爱的玩家,谢谢支持正版游戏,继续游戏,你需连续发送"+
					//# wantTime+"条短信("+money+"元/条,不含通信费),就可永久免费使用该游戏,要发送吗?", screen_width - 20, "");
							//# payMsg = new String[v.size()];
							//# v.copyInto(payMsg);
							//# tmpState = (byte)game_stage;
							//# game_stage = STAGE_PAY;	
							//# return;
						//# }
					//# }
					//#endif
										
                    //#ifdef COMMAND
					//# AddCommand(STAGE_GAME);
					//#endif
					
					m_pImage[TITLE] = null;
					m_pImage[MENU_ITEM] = null;
					m_pImage[XIN_XIN] = null;
					System.gc();
					
					// start the game
					//stop the music
					m_pEffect.StopSound();
					deleteWindow();
					setGameLevel((byte)1);
					game_score = 0;
					newgame();
					game_stage = STAGE_GAME;
				} 
				//ranking
				else if (menu_option == 2)  
				{
                    //#ifdef COMMAND
					//# AddCommand(STAGE_RANKING);
					//#endif
					
					//set 
					page_pointer = 0;
					if(MAX_RANK <= LINE_A_PAGE)
					{
						hasArrow = false;
					}
					else
					{
						hasUpArrow = false;
						hasDownArrow = true;
						hasArrow = true;
					}
					readRanking();
					deleteWindow();
					last_stage = STAGE_TITLE;
					game_stage = STAGE_RANKING;
				}
                //sound
				else if (menu_option == 1)  
				{   
					//#ifdef COMMAND
					//# AddCommand(STAGE_SETTING);
					//#endif
					old_game_stage = STAGE_TITLE;
					game_stage = STAGE_SETTING;
				}
				//help
				else if (menu_option == 3)
				{
                    //#ifdef COMMAND
					//# AddCommand(STAGE_HELP);
					//#endif
					
					if(help_ui != null)
						help_ui = null;
					help_ui = Common.splitString(Text.rule_string,font,screen_width - 30 );
					initWindow(help_ui,SHOW_NUM);
					deleteWindow();
					help_pointer = 0;
					last_stage = STAGE_TITLE;
	    			game_stage = STAGE_HELP;
				}
				//about
				else if (menu_option == 4)  
				{   
                    //#ifdef COMMAND
					//# AddCommand(STAGE_ABOUT);
					//#endif

					if(about_ui != null)
						about_ui = null;
					about_ui = Common.splitString(Text.about_string,font,screen_width - 30 );
					initWindow(about_ui,SHOW_NUM);
					deleteWindow();
	    			game_stage = STAGE_ABOUT;				
				}  
				//exit
				else if (menu_option == 5)  
				{
					game_stage = STAGE_EXIT;
				}
			}
			
			if(m_iKey == KEY_R)	game_stage = STAGE_EXIT;
			m_iKey = KEY_NONE;
		}
	}	
	
	/**
	 * start the game 
	 */
	private void newgame()
	{    
        tile_left = 0;
		
		//load the data to the map array 
		// the data compose a shape
		loadGameLevelMap();
		
		//create some randoms and store them into the map
		randMap();
		
		//init tile object
		initTileObject();
		
		//center the arrow
		hand_x = ((line_count - 2)>>1);
		hand_y = ((row_count - 2)>>1);
		
		//calculate the time of a level
		level_time = MAX_LEVEL_TIME - game_level*MINUTE;
		if(level_time <= MIN_LEVEL_TIME)
			level_time = MIN_LEVEL_TIME;
		max_time = level_time;
		
		timebar_x = (screen_width - timebar_width)>>1; 
		
		str_score = null;
		str_score = ""+game_score;
		//initialzie
		hint_time = 0;
		combo_time = MAX_COMBO_TIME;
		level_score = 0;
		combo_score = 0;
		combo_counter = 0;
		stunt_counter = 0;
		stunt_time_counter = 0;
		temp_combo_score = 0;
		
		m_iKey = KEY_NONE;
		tempKey = KEY_NONE;
		isKeyReleased = true;
		hasTremble = false;
		hasStuntFlashing = false;
		hasStuntTime = false;
		canOver = true;
		canSelect = true;
		hasCombo = false;
		hasHint = false;
		hitWrongPair = false;
		isGameOver = false;
		isFirstSelect = false;
		hasMusic = false;
		bCanDraw = false;
		m_CntMapsCount = 0;
		wrong_counter = 0;
		hasMotion = false;
		hasStunt = false;
	}
	
	private void flow_init()
	{
			
	}
	
	//init the tile object
	private void initTileObject()
	{
        //clear the hashtable
		if(ht.size() > 0)
		{
			ht.clear();
			System.gc();
		}
		//create the tile object
		
		for(int i = 1; i < row_count -1; i++)
			for(int j = 1; j < line_count - 1; j++)
			{
				byte temp_value = map[i][j];
				if(temp_value != EMPTY)
				{
					Tile kitty_tile;            // the object store the kitty
					kitty_tile = new Tile();
					kitty_tile.tile_type = TILE_INIT;
					kitty_tile.tile_frame = (short)(temp_value-1);
					kitty_tile.tile_y = (i-1)*tile_height + tile_heightC;
					kitty_tile.tile_x = (j-1)*tile_width + tile_widthC;
					ht.put( new Integer(((i-1)*(line_count-2) + j - 1)),kitty_tile);
     			}
			}
	}
	
	//reshuffle the left tiles
	private void reShuffle()
	{
		int m,n,k;
		for( int i=1; i<=(row_count-2); i++ )
			for( int j=1; j<=(line_count-2); j++ )
			{
				if(map[i][j]!=0)
				{
					do
					{
						m = rand(row_count-2);
						n = rand(line_count-2);
					}
					while( 0==map[m][n] );
					k=map[i][j];
					map[i][j]=map[m][n];
					map[m][n]=(byte)k;
				}
			}
	}
	
	private final void flow_game()
	{
		//left soft key pressed
		if(response_key == KEY_L)
		{
			m_iKey = KEY_NONE;
			createSystemWindow();
			if(bSound)
        	{
        		m_pEffect.StopSound() ;
        		m_pEffect.PlaySound("/title.mid",true);
        	}
			
			//#ifdef COMMAND
			//# AddCommand(STAGE_SYSTEM);

⌨️ 快捷键说明

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