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

📄 gamescreen.java

📁 是男人就下一百层
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 


import java.io.InputStream;
import java.util.Random;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
//import com.nokia.mid.ui.FullCanvas;


class GameScreen extends GameCanvas
    implements Runnable,CommandListener
{
	/**
	 * 背景音
	 */
	public Player bgplayer;
	/**
	 * 重画标志
	 */
	public boolean needRepaint;
	/**
	 * 整体运行
	 */
	public boolean runGame;
	/**
	 * 画进度条
	 */
	public boolean bDrawLoad;
	/**
	 * 画logo
	 */
	public boolean bDrawLogo;
	/**
     * logo
     */
    public Image2 xhLogo;
	/**
	 * 菜单标识
	 */
	public int iMenu;
	/**
	 * 游戏运行
	 */
	public boolean playGame;
	/**
	 * 纪录
	 */
	public myRecord record;
	/**
	 * 菜单运行
	 */
	public boolean runMenu;
	/**
	 * midlet
	 */
	public ManGame mangame;
    private Command back = new Command( "返回", Command.BACK, 1 );
    protected Thread thread;
    public static int ScreenWidth;
    public static int ScreenHeight;
    /**
     * 刷新率
     */
    public static int delay = 50;
    /**
     * 板宽
     */
    public static int boardWidth = 28;
    /**
     * 板高
     */
    public static int boardHeight = 3;
    /**
     * 进度条
     */
    private Image2 iLoadBarImage;
    /**
     * 菜单
     */
    private Image2 barImage;
    /**
     * 菜单项
     */
    private Image2[] menuImage = new Image2[6];
    /**
     * 游戏状态
     */
    private Image2[] statusImage = new Image2[2];
    /**
     * 计数器
     */
    private int counter;
    /**
     * 板属性
     */
    public Board[] boards = new Board[7];
    /**
     * 人物位置 和 状态
     */
    public int iX, iAtLevel, iSpeed, iStatus, iAction, actionStep, ConditionCount;
    /**
     * 人物
     */
    private Image2[] iPlayer = new Image2[14];
    /**
     * 板
     */
    private Image2[] board = new Image2[11];
    /**
     * 背景
     */
    private Image2 bg;
    /**
     * 卷标
     */
    private int scroll;
    /**
     * 层高
     */
    public static int levelHeight;
    /**
     * 层数
     */
    private int level;
    /**
     * 生命值
     */
    private int iLife;
    /**
     * 生命最大值
     */
    private int iMaxLife;
    /**
     * 上端 
     */
    public static int minHeight = 20;
    /**
     * 游戏状态,0为新游戏,1为运行,2为暂停,3为结束
     */
    public int gameStatus = 0;
    /**
     * 道具
     */
    public Image2[] bonusImage = new Image2[3];
    /**
     * 楼层
     */
    public Image2 levelImage;
    /**
     * 道具类型
     */
    public int bonusTypeid;
    /**
     * 排行
     */
    private int[] scores = new int[8];
    private static List list;
    private static String[] listitem = { "背景音乐开","背景音乐关" };
        
    public GameScreen(ManGame mangame)
    {
        super(false);
        setFullScreenMode(true);
        ScreenWidth = getWidth();
        ScreenHeight = getHeight();
//        ScreenWidth = 128;
//        ScreenHeight = 128;
        this.mangame = mangame;
		iLoadBarImage = new Image2("/loadbar.png");
	    barImage = new Image2("/bar.png");
	    for (int i = 0; i < 6; i ++){
			menuImage[i] = new Image2("/m"+i+".png");
		}
	    for (int i = 0; i < 2; i++){
	    	statusImage[i] = new Image2("/f"+i+".png");
	    }
	    for (int i = 0; i < 3; i++){
	    	bonusImage[i] = new Image2("/g"+i+".png");
	    }
	    levelImage = new Image2("/l.png");
	    levelHeight = (ScreenHeight - minHeight) / 7;
	    list = new List ( null, Choice.IMPLICIT, listitem, null );
	    list.addCommand(back);
		list.setCommandListener(this);
        thread = new Thread(this);
        thread.start();
    }

	public void commandAction(Command cmd, Displayable display) {
		if (cmd == back) {
			mangame.display.setCurrent(this);
			needRepaint = true;
		}
		if(cmd == List.SELECT_COMMAND){
			int music = mangame.record.getIntVal("bg");
			if(list.getSelectedIndex() != music){
				mangame.record.setVal("bg","" + list.getSelectedIndex());
				mangame.record.save();
			}
			mangame.display.setCurrent(this);
			needRepaint = true;
		}
	}   

    public void paint(Graphics g)
    {
    	if (needRepaint){
	    	g.setColor(0, 0, 0);
	    	//g.fillRect(0, 0, ScreenWidth+200, ScreenHeight+400);
	    	g.fillRect(0,0,this.getWidth(),this.getHeight());
	        if (runMenu){
		        if(bDrawLoad)
		        {
		            g.setColor(215, 184, 13);
		            g.fillRect(((ScreenWidth - iLoadBarImage.width) >> 1) + 3, ScreenHeight * 5 / 6 + 3, counter * (iLoadBarImage.width - 6) >> 3, iLoadBarImage.height - 6);
		            iLoadBarImage.drawCenter(g, ScreenHeight * 5 / 6);
		            return;
		        }
		        if (bDrawLogo){
		        	xhLogo.draw(g,0,0);
		        	return;
		        }
		        if (iMenu < 90){
		        	menuImage[iMenu].drawCenter(g, (ScreenHeight * 3) >> 2);
		        	barImage.drawCenter(g, (ScreenHeight * 3) >> 2);
		        }
		        else{
//		        	System.out.println("HighScore");
		        	g.setColor(255,255,255);
		        	g.drawString( "排行榜", ScreenWidth >> 1, 5, Graphics.TOP | Graphics.HCENTER );
		        	for ( int i = 0; i < 8 && scores[i] > 0; i++ ) {
		    			g.drawString( "第" + (i+1) + "名 : 第 " +  scores[i] + " 层", 10,i * 12 + 25, Graphics.LEFT | Graphics.TOP );
		    		}
		        }
	        }
	        needRepaint = false;
    	}
    	if (playGame){
        	bg.draw(g, 0, 0);
        	iPlayer[iStatus].drawCenterBottom(g, iX, getPlayerY());
        	for (int i = 0;i < 7;i ++){
        		getBoard(boards[i]).drawCenterBottom(g, boards[i].x, boards[i].level * levelHeight - scroll + minHeight);
        		if (boards[i].haveBonus){
        			bonusImage[bonusTypeid].drawCenterBottom(g,boards[i].x, boards[i].level * levelHeight - scroll + minHeight - getBoard(boards[i]).height);
        		}
           	}
        	if (gameStatus == 0){
        		statusImage[0].drawCenter(g,40);
        	}
        	if (gameStatus == 3){
        		statusImage[1].drawCenter(g,40);
        	}
        	if (gameStatus == 2){
        		g.setColor(255,255,255);
	    		g.drawString("暂停", ScreenWidth >> 1, ScreenHeight >> 1, Graphics.BOTTOM | Graphics.HCENTER);
	    		g.drawString("退出", ScreenWidth , ScreenHeight, Graphics.BOTTOM | Graphics.RIGHT);
	    		g.drawString("继续", 0, ScreenHeight, Graphics.BOTTOM | Graphics.LEFT);
	    	}
        	for (int i = 0;i < 6;i ++){
        		g.setColor(255,0,0);
        		g.fillRect(3 + 6 * i,4,5,9);
        	}
        	for (int i = 0;i < iLife;i ++){
        		g.setColor(252,219,0);
        		g.fillRect(4 + 6 * i,5,3,7);
        	}
        	for (int i = iLife;i < iMaxLife;i ++){
        		g.setColor(0,0,0);
        		g.fillRect(4 + 6 * i,5,3,7);
        	}
        	levelImage.drawCenterBottom(g, 70 , 10);
        	drawLevel(g);
        	if (iSpeed < 0){
        		bonusImage[0].draw(g, 100, 0);
        	}
        	if (iSpeed > 4){
        		bonusImage[1].draw(g, 100, 0);
        	}
        }
    }

    public void run()
    {
        iMenu = 0;
        runGame = true;
        runMenu = true;
        needRepaint = true;
        bDrawLogo = true;
        for (int i = 0; i < 8; i ++){
			scores[i] = mangame.record.getIntVal("score" + i);
//			System.out.println(scores[i]);
		}
        try
        {
            while(runGame){
            	if (!mangame.isPause){
                while(runMenu){
                	if (bDrawLogo){
                		if (counter == 0){
                			xhLogo = new Image2("/xhlogo.png");
                		}
                		if (counter == 30){
                			xhLogo = new Image2("/logo.png");
                		}
                		counter ++;
                		if (counter > 60){
                			counter = 0;
                			xhLogo = null;
                			bDrawLogo = false;
                			System.gc();
                		}
                	}
                	if (bDrawLoad){
                		counter ++;
                		switch (counter){
	                		case 1:
	                			for (int i = 0;i < 14;i ++){
	                				iPlayer[i] = new Image2("/p"+i+".png");
	                			}
	                			break;
	                		case 2:
	                			for (int i = 0;i < 11;i ++){
	                				board[i] = new Image2("/b"+i+".png");
	                			}
	                			break;
		                	case 3:
		                		boards[0] = new Board(0,ScreenWidth >> 1,1);
		                		boards[1] = new Board(0,ScreenWidth >> 1,2);
		                		for (int i = 2;i < 7;i ++){
				                	boards[i] = new Board(randomBoardType(i - 1), randomX(i - 1), i + 1);
		                		}
		                		break;
		                	case 4:
		                		try{
		                			if (bgplayer == null){
		                				InputStream sound = getClass().getResourceAsStream("/0.mid");
		                				bgplayer = Manager.createPlayer(sound,"audio/midi");
		                				bgplayer.prefetch();
		                				bgplayer.setLoopCount(-1);
		                			}
		                		}
		                		catch(Exception e){
		                			e.printStackTrace();
		                		}
		                		bg = new Image2("/bg.png");
		                		break;
		                	default:
		                		break;
                		}
                		if (counter > 8){
                			bDrawLoad = false;
                			runMenu = false;
                			counter = 0;
                			level = 1;
                			scroll = 0;
                			iX = ScreenWidth >> 1;
                			iAtLevel = 2;
                			iStatus = 0;
                			iAction = 0;
                			actionStep = 0;
                			iMaxLife = 6;
                			iLife = 6;
                			iSpeed = 3;
                			playGame = true;
                			gameStatus = 0;
            				setSound();
                		}
                		needRepaint = true;
                	}
                	repaint();
                    Thread.sleep(delay);
                }
                while(playGame) 
                {
                	if (gameStatus == 1){
//                    	检查状态
                		if (iAction == 0 || actionStep == 6){
	            			if (actionStep == 6){
	            				actionStep = 0;
	            				if (iAction == 2){
	            					iAtLevel ++;
	            				}
	            			}
	            			int onLevel = onBoard();
		               		if (onLevel == -1){
		               			iAction = 2;
		               		}
		               		else{
		               			if (boards[onLevel].typeid == 0){//木板
		               				iAction = 0;
		               			}
		               			if (boards[onLevel].typeid == 1){//钉板
		               				iAction = 0;
		               				if (boards[onLevel].active == true){
		               					iLife --;
		               					boards[onLevel].active = false;
		               				}
		               			}
		               			if (boards[onLevel].typeid == 3){//弹簧板
		               				iAction = 1;
		               				boards[onLevel].active = true;
		               			}
		               			if (boards[onLevel].typeid == 4){//翻板
		               				iAction = 0;
		               				boards[onLevel].active = true;
		               			}
		               			if (boards[onLevel].typeid == 2){//滑板
		               				if (boards[onLevel].active){
		               					iX -= 2;
		               				}
		               				else{
		               					iX += 2;
		               				}
		               				iAction = 0;
		               			}
		               		}
	            		}
                		int bonusX = -1;
                		int bonusY = -1;
	                	counter = (counter + 1) % 6;
	                	scroll ++;
	                	if (iSpeed < 0 || iSpeed > 4){
	                		ConditionCount ++;
	                		if (ConditionCount == 60){
	                			iSpeed = 3;
	                		}
	                	}
	                	if (scroll >= levelHeight){
	                		level ++;
	                		iAtLevel --;
	                		scroll = scroll - levelHeight;
	                		for (int i = 0;i < 7;i ++){
	                			if (boards[i].level == 1){
	                				if (i != 0){
	                					boards[i] = new Board(randomBoardType(i - 1), randomX(i - 1),7);
	                				}
	                				else{
	                					boards[i] = new Board(randomBoardType(5), randomX(5),7);
	                				}
	                				if(level % 10 == 0){
	                					bonusTypeid = Math.abs(new Random().nextInt()) % 3;
	                					boards[i].haveBonus = true;
	                				}
	                			}
	                			else{
	                				boards[i].level --;
	                			}
	                		}
	                	}
	            		if (iAction == 1 || iAction == 2){
	            			actionStep ++;
	            		}
	                	if (getKeyStates() == 4){
	                		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;
               						}
               					}

⌨️ 快捷键说明

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