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

📄 gamescreen.java

📁 是男人就下一百层
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
               					else{
               						iX -= iSpeed;
               					}
                			}
	                		if (iSpeed > 0){
		                		if (iAction == 0){
			                		if (counter < 2){
			                			iStatus = 1;
			                		}
			                		if (counter < 4){
			                			iStatus = 2;
			                		}
			                		else{
			                			iStatus = 3;
			                		}
			                	}
		                		if (iAction == 1 || iAction == 2){
		                			if (counter % 2 == 0){
			                			iStatus = 9;
			                		}
			                		else{
			                			iStatus = 10;
			                		}
		                		}
	                		}
	                		else{
	                			if (iAction == 0){
		                			if (counter < 2){
			                			iStatus = 4;
			                		}
			                		if (counter < 4){
			                			iStatus = 5;
			                		}
			                		else{
			                			iStatus = 6;
			                		}
			                	}
		                		if (iAction == 1 || iAction == 2){
		                			if (counter % 2 == 0){
			                			iStatus = 11;
			                		}
			                		else{
			                			iStatus = 12;
			                		}
		                		}
	                		}
	                	}
	                	if (getKeyStates() == 32){
	                		if (iX + iSpeed > 2 + (iPlayer[iStatus].width >> 1) && iX + iSpeed <  ScreenWidth - (iPlayer[iStatus].width >> 1) - 2){
               					if (iAction == 2){
               						if (iSpeed > 0){
               							iX += 2;
               						}
               						else{
               							iX -= 2;
               						}
               					}
               					else{
               						iX += iSpeed;
               					}
                			}
	                		if (iSpeed > 0){
		                		if (iAction == 0){
		                			if (counter < 2){
			                			iStatus = 4;
			                		}
			                		if (counter < 4){
			                			iStatus = 5;
			                		}
			                		else{
			                			iStatus = 6;
			                		}
			                	}
		                		if (iAction == 1 || iAction == 2){
		                			if (counter % 2 == 0){
			                			iStatus = 11;
			                		}
			                		else{
			                			iStatus = 12;
			                		}
		                		}
	                		}
	                		else{
	                			if (iAction == 0){
			                		if (counter < 2){
			                			iStatus = 1;
			                		}
			                		if (counter < 4){
			                			iStatus = 2;
			                		}
			                		else{
			                			iStatus = 3;
			                		}
			                	}
		                		if (iAction == 1 || iAction == 2){
		                			if (counter % 2 == 0){
			                			iStatus = 9;
			                		}
			                		else{
			                			iStatus = 10;
			                		}
		                		}
	                		}
	                	}
	                	if (getKeyStates() == 0){
	                		if (iAction == 0){
	                			iStatus = 0;
	                		}
	                		else{
	                			if (counter < 3){
	                				iStatus = 7;
	                			}
	                			else{
	                				iStatus = 8;
	                			}
	                		}
	                	}
	                	int iY = getPlayerY();
	                	if (iY < minHeight + iPlayer[iStatus].height){
	                		iLife --;
	                		iAtLevel ++;
	                	}
	                	if (iLife == 0 || iY > ScreenHeight){
	                		gameStatus = 3;
	                		if(scores[getmin()] < (level >> 2) + 1){
	                			scores[getmin()] = (level >> 2) + 1;
	                			scores = BubbleSort(scores);
	                			for(int i = 0; i < 8; i ++){
									mangame.record.setVal("score" + i,"" + scores[i]);
								}
	                			mangame.record.save();
	                		}
							
	                		counter = 0;
	                		iLife = 0;
	                		iStatus = 13;
	                	}
	                	for (int i = 0; i < 7; i ++){
	                		if (boards[i].active || boards[i].typeid == 2){
	                			boards[i].status ++;
	                			if (boards[i].status == 6){
	                				boards[i].status = 0;
	                				if (boards[i].typeid != 2 && boards[i].typeid != 1 ){
	                					boards[i].active = false;
	                				}
	                			}
	                		}
	                		if (boards[i].haveBonus){
	                			bonusX = boards[i].x;
	                			bonusY = boards[i].level * levelHeight - scroll + minHeight;
	    	                	if (bonusX != -1 && bonusY != -1){
	    	                		if (Math.abs(bonusY - iY) < bonusImage[bonusTypeid].height && Math.abs(bonusX - iX) < ((bonusImage[bonusTypeid].width + iPlayer[iStatus].width) >> 1)){
	    	                			if(bonusTypeid == 0){
	    	                				iSpeed = - iSpeed;
	    	                				ConditionCount = 0;
	    	                			}
	    	                			if(bonusTypeid == 1){
	    	                				iSpeed = 2 * iSpeed;
	    	                				ConditionCount = 0;
	    	                			}
	    	                			if(bonusTypeid == 2){
	    	                				iLife += 3;
	    	                				if(iLife > 6){
	    	                					iLife = 6;
	    	                				}
	    	                			}
	    	                			boards[i].haveBonus = false;
	    	                		}
	    	                	}
	    	                }
	                	}
                	}
                	if (gameStatus == 3){
                		counter ++;
                		if (counter > 40){
	        	    		playGame = false;
	        	    		runMenu = true;
	        	    		iMenu = 0;
	        	    		counter = 0;
	        	    		stopSound();
	        	    		needRepaint = true;
                		}
        	    	}
                	repaint();
	                Thread.sleep(delay);
                }
            }
            }
        }
        catch(Exception exception)
        {
            System.out.println("Exception caught:" + exception);
        }
        runGame = false;
    }
    
	public void keyPressed (int keycode){
		if (runMenu){
			if (iMenu == 99){
				iMenu = 1;
				needRepaint = true;
				return;
			}
			if (bDrawLogo){
				if (counter < 30){
					counter = 30;
				}
				else{
					counter = 0;
					xhLogo = null;
        			bDrawLogo = false;
        			System.gc();
				}
			}
			else{
				if (!this.bDrawLoad){
					if ((keycode == LEFT|| keycode == KEY_NUM4 )) {
						iMenu --;
						if (iMenu == -1){
							iMenu = 5;
						}
						needRepaint = true;
					}
					else if ((keycode ==RIGHT || keycode == KEY_NUM6 )) {
						iMenu ++;
						if (iMenu == 6){
							iMenu = 0;
						}
						needRepaint = true;
					}
					else if (keycode ==KEY_NUM1 || keycode == KEY_NUM3 ) {
						switch (iMenu){
							case 0://新游戏
								bDrawLoad = true;
								needRepaint = true;
								break;
							case 1://排行榜
								iMenu = 99;
								needRepaint = true;
								break;
							case 2://设置
								list.setSelectedIndex(mangame.record.getIntVal("bg"), true);
								mangame.display.setCurrent(list);
								break;
							case 3://帮助
								Form form1 = new Form("帮助");
								String string1 = new String("【描述】:\n玩家需要在游戏中扮演一名矿工形象的主角,以该形象从最高层不停的向下移动。\n" + 
										"【规则】:玩家需利用走,跳等各种动作,到达象征胜利的底层。移动过程中,可以供玩家进行踏脚的会有几种板块,根据板块的类型不同板块的作用也不尽相同。\n" +
										"【控制】:\n按4或左软键左移,按6或右软键右移。游戏中按右键暂停,左键继续,右键返回主菜单。\n" +
										"【客服】\n电话:021-65870761\nE-mail:xym@xieheng.com.cn"
										);
								form1.append(string1);
								form1.addCommand(back);
								form1.setCommandListener(this);
								mangame.display.setCurrent(form1);
								break;
							case 4://关于
								Form form2 = new Form("关于");
								String string2 = new String("【男人挺到底】V1.0版\n" +
										"上海协亨通讯设备有限公司\n" +
										"电话:021-65870761\nE-mail:xym@xieheng.com.cn");
								form2.append(string2);
								form2.addCommand(back);
								form2.setCommandListener(this);
								mangame.display.setCurrent(form2);
								break;
							case 5://退出
								runGame = false;
								mangame.quit();
								break;
						}
					}
				}
			}
		}
		if (playGame){
			if (gameStatus == 0){
	    		gameStatus = 1;
	    	}
			if(gameStatus == 1){
//				System.out.println(keycode);
				if(keycode == KEY_NUM1 || keycode ==KEY_NUM2 ){
					gameStatus = 2;
					return;
				}
			}
			if (gameStatus == 2){
				if(keycode == KEY_NUM1){
					gameStatus = 1;
				}
				if (keycode == KEY_NUM2){
					gameStatus = 3;
				}
			}
	    	if (gameStatus == 3){
	    		playGame = false;
	    		runMenu = true;
	    		iMenu = 0;
	    		counter = 0;
	    		stopSound();
	    		needRepaint = true;
	    	}
		}
	}
	
	public int randomBoardType(int i){
		int ran;
		while (true){
			ran = Math.abs(new Random().nextInt()) % 5;
			if (ran != boards[i].typeid){
				break;
			}
		}
		return ran;
	}
	
	public int randomX(int i){
		int ran;
		while (true){
			ran = Math.abs(new Random().nextInt()) % ScreenWidth;
			if (ran != boards[i].x){
				break;
			}
		}
		if (ran < 15 + (boardWidth >> 1)){
			ran = 15 + (boardWidth >> 1);
		}
		if (ran > ScreenWidth - 15 - (boardWidth >> 1)){
			ran = ScreenWidth - 15 - (boardWidth >> 1);
		}
		return ran;
	}

	public Image2 getBoard(Board bd){
		switch (bd.typeid){
		case 2:
			if (bd.status < 2){
				return(board[2]);
			}
			if (bd.status < 4){
				if (bd.active){
					return(board[3]);
				}
				else{
					return(board[4]);
				}
			}
			else{
				if (bd.active){
					return(board[4]);
				}
				else{
					return(board[3]);
				}
			}
		case 3:
			if (bd.status < 2){
				return(board[5]);
			}
			if (bd.status < 4){
				return(board[6]);
			}
			else{
				return(board[7]);
			}
		case 4:
			if (bd.status < 2){
				return(board[8]);
			}
			if (bd.status < 4){
				return(board[9]);
			}
			else{
				return(board[10]);
			}
		default:
			return(board[bd.typeid]);
		}
	}
	
	public int onBoard(){
		for (int i = 0;i < 7;i ++){
			if (boards[i].level == iAtLevel){
				if (Math.abs(iX - boards[i].x) < (iPlayer[iStatus].width + boardWidth) >> 1){
					if (boards[i].typeid != 4 || (boards[i].typeid == 4 && boards[i].status != 5)){
						return i;
					}
				}
			}
		}
		return -1;
	}
	
	public int getPlayerY(){
		if (iAction != 1){
			return (iAtLevel * levelHeight + levelHeight / 7 * actionStep - boardHeight + minHeight - scroll);
		}
		else{
			return (iAtLevel * levelHeight - (levelHeight >> 2) * (3 - Math.abs(actionStep - 3)) - boardHeight + minHeight - scroll);
		}
	}
	
	public void drawLevel(Graphics g){
		g.setColor(255, 255, 255);
		int l = (level >> 2) + 1;
		int i = 0;
		while (l > 0){
			g.drawString("" + (l % 10), 90 - 6 * i, 0, 0);
			i ++;
			l /= 10;
		}
	}
	
	public void setSound(){
		try {
			if (mangame.record.getIntVal("bg") == 0 && bgplayer.getState() != Player.STARTED){
				bgplayer.start();
			}
			if (mangame.record.getIntVal("bg") == 1 && bgplayer.getState() == Player.STARTED){
				bgplayer.stop();
			}
		}
		catch ( Exception e ) {
			e.printStackTrace();
		}
	}
	  
	public void stopSound(){
		try {
			if (bgplayer.getState() == Player.STARTED){
				bgplayer.stop();
			}
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}

	public int getmin(){
		int min = 0;
		int minval = scores[0];
		for (int i = 1;i < 8;i ++){
			if (scores[i] < minval){
				minval = scores[i];
				min = i;
			}
		}
		return min;
	}
	
	public int[] BubbleSort(int[] R){
		int i,j;
	    boolean exchange;
	    for(i = 0; i< R.length; i ++){
	       exchange = false;
	       for(j = R.length - 1; j > i; j--)
	        if(R[j] > R[j-1]){
	        	int temp = R[j];
	        	R[j] = R[j-1];
	        	R[j-1] = temp;
	        	exchange = true;
	         }
	       if(!exchange){
	             return R;
	       }
	    }
	    return R;
	}

}

⌨️ 快捷键说明

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