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

📄 gamescreen.java

📁 充气球的j2me代码,可以自由的部署在eclipse,netbeas里面.希望大家喜欢.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
// 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 
// Source File Name:   GameScreen.java

import com.nokia.mid.sound.Sound;
import com.nokia.mid.ui.FullCanvas;
import java.io.PrintStream;
import java.util.*;
import javax.microedition.lcdui.*;

public class GameScreen extends FullCanvas
{

    public static int TIMEFIRST = 2500;
    public int MAX_LEVEL = 5;
    private TwirlEmUpMIDlet parent;
    public GameThread gameThread;
    private MainMenu menu;
    private WordBuilder wordBuilder;
    private WordSet presentWordSet;
    private Sound countdownSound;
    private Sound correctSound;
    private Sound wrongSound;
    private Sound nextLevelSound;
    public static int screenWidth;
    public static int screenHeight;
    private int cursorPosition;
    private boolean blink;
    public boolean gamePaused;
    public boolean running;
    private Sprite characterSprite;
    private Sprite pumpSprite;
    private Sprite balloonSprite;
    private Sprite scoreSprite;
    private Sprite timeSprite;
    private Image xImage;
    private Sprite letterSprite[];
    private Sprite blankSprite[];
    private boolean letterFlags[];
    private int letterCounter;
    private int letterFrame[];
    private int blankFrame[];
    private int presentNumLetters;
    private int presentNumWords;
    private int presentAsc[];
    private int wordIndex[];
    private int wordX[];
    private int wordY[];
    private int wordWidth[];
    private int level;
    private String presentWords[];
    private int playerScore;
    private String playerWord;
    private int guessedWords;
    private static int scoreWord = 10;
    private static int scoreLevel = 50;
    public StringTimer timer;
    private int time;
    private boolean wordGuessed[];
    public boolean gameOver;
    private boolean isNextLevel;
    private int firstTime;
    private int balloonFrame;
    private int xFirst = 90;
    private int yFirst = 60;
    private Thread t;
    private static int last;
    private int xCharacter;
    private int yCharacter;
    private int counter;
    private boolean down;
    private boolean up;
    private Image burst;
    private boolean saved;
    private boolean not;
    private int notCounter;
    public boolean high;
    private boolean created;
    private boolean nextLevelOnce;
    private int n;
    private int m;
    private boolean notRepaint;
    public static boolean ready = true;
    private boolean done;
    boolean once;
    private boolean noWords;

    public GameScreen(TwirlEmUpMIDlet parent, MainMenu menu)
    {
        this.parent = null;
        gameThread = null;
        this.menu = null;
        wordBuilder = null;
        presentWordSet = null;
        countdownSound = null;
        correctSound = null;
        wrongSound = null;
        nextLevelSound = null;
        blink = true;
        gamePaused = false;
        running = true;
        characterSprite = null;
        pumpSprite = null;
        balloonSprite = null;
        scoreSprite = null;
        timeSprite = null;
        xImage = null;
        presentNumLetters = 0;
        presentNumWords = 0;
        level = -1;
        playerScore = 0;
        playerWord = "";
        guessedWords = 0;
        timer = null;
        time = 0;
        gameOver = false;
        isNextLevel = false;
        firstTime = 0;
        balloonFrame = 0;
        xCharacter = 0;
        yCharacter = 0;
        counter = 0;
        burst = null;
        saved = false;
        not = false;
        notCounter = 0;
        high = false;
        created = false;
        nextLevelOnce = false;
        n = 0;
        m = 0;
        notRepaint = false;
        done = false;
        once = false;
        noWords = false;
        this.parent = parent;
        this.menu = menu;
        screenWidth = getWidth();
        screenHeight = getHeight();
        letterFrame = new int[6];
        blankFrame = new int[6];
        letterSprite = new Sprite[6];
        blankSprite = new Sprite[6];
        try
        {
            countdownSound = new Sound(Resources.countdownSoundByte, 1);
            countdownSound.setGain(200);
            correctSound = new Sound(Resources.correctSoundByte, 1);
            correctSound.setGain(200);
            wrongSound = new Sound(Resources.wrongSoundByte, 1);
            wrongSound.setGain(200);
            nextLevelSound = new Sound(Resources.nextLevelSoundByte, 1);
            nextLevelSound.setGain(200);
        }
        catch(Exception e) { }
        try
        {
            burst = Image.createImage("/res/burst.png");
            xImage = Image.createImage("/res/x.png");
            xCharacter = 90;
            yCharacter = 119;
            characterSprite = new Sprite(Image.createImage("/res/character.png"), 41, 35, 3);
            characterSprite.setFrame(0);
            characterSprite.setX(xCharacter);
            characterSprite.setY(yCharacter);
            characterSprite.setVisible(true);
            pumpSprite = new Sprite(Image.createImage("/res/pump.png"), 35, 40, 2);
            pumpSprite.setFrame(0);
            pumpSprite.setX(101);
            pumpSprite.setY(145);
            pumpSprite.setVisible(true);
            balloonSprite = new Sprite(Image.createImage("/res/balloon.png"), 40, 48, 8);
            balloonSprite.setFrame(0);
            balloonSprite.setX(128);
            balloonSprite.setY(134);
            balloonSprite.setVisible(true);
            scoreSprite = new Sprite(Image.createImage("/res/button.png"), 33, 13, 3);
            scoreSprite.setFrame(0);
            scoreSprite.setX(12);
            scoreSprite.setY(190);
            scoreSprite.setVisible(true);
            timeSprite = new Sprite(Image.createImage("/res/button.png"), 33, 13, 3);
            timeSprite.setFrame(1);
            timeSprite.setX(90);
            timeSprite.setY(190);
            timeSprite.setVisible(true);
            for(int i = 0; i < 6; i++)
            {
                blankSprite[i] = new Sprite(Image.createImage("/res/letter.png"), 12, 29, 28);
                letterSprite[i] = new Sprite(Image.createImage("/res/letter.png"), 12, 29, 28);
            }

        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        initialize();
    }

    public void initialize()
    {
        try
        {
            level = -1;
            playerScore = -50;
            if(gameThread == null)
                gameThread = new GameThread(parent, this);
            try
            {
                wordBuilder = new WordBuilder(this);
                wordIndex = new int[5];
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            for(int i = 0; i < 5; i++)
                wordIndex[i] = i;

            nextLevel();
            t = new Thread(gameThread);
            running = true;
            t.start();
            ready = true;
        }
        catch(Exception e)
        {
            Alert a = new Alert("Error");
            a.setImage(null);
            a.setString(e.toString());
            a.setTimeout(3000);
            a.setType(AlertType.CONFIRMATION);
            parent.setDisplayable(a, menu);
        }
        repaint();
    }

    public void paint(Graphics g)
    {
        System.gc();
        try
        {
            g.setFont(Resources.font1);
            g.setColor(0xfff568);
            g.fillRect(0, 0, screenWidth, screenHeight);
            String scoreString = playerScore + "";
            String timeString = timer.toString();
            g.setColor(0);
            g.drawString(scoreString, 52, 190, 20);
            g.drawString(timeString, 130, 190, 20);
            if(timer.timesUp() && !wordGuessed[presentNumWords - 1])
                gameOver = true;
            else
            if(timer.timesUp() && wordGuessed[presentNumWords - 1])
                if(level + 1 >= 5)
                {
                    gameOver();
                    try
                    {
                        characterSprite.setFrame(0);
                        characterSprite.setX(90);
                        characterSprite.setY(114);
                        characterSprite.paint(g);
                        pumpSprite.paint(g);
                        g.drawImage(burst, 116, 145, 16);
                    }
                    catch(Exception e)
                    {
                        System.out.println("Error");
                        e.printStackTrace();
                    }
                    if(!once)
                    {
                        if(Resources.withSound)
                            try
                            {
                                nextLevelSound.play(1);
                            }
                            catch(Exception e)
                            {
                                e.printStackTrace();
                            }
                        GameOverCanvas goc = new GameOverCanvas(parent, this);
//                        Timer timer2 = new Timer();
//                        TimerTask tt = timer2. new TimerTask() {
//
//                            public void run()
//                            {
//                                running = false;
//                                gamePaused = false;
//                                gameOver = true;
//                                Thread _tmp = t;
//                                Thread.yield();
//                                t = null;
//                                presentWordSet = null;
//                                parent.setDisplayable(goc);
//                                timer2.cancel();
//                            }
//
//                        };
//                        timer2.schedule(tt, 5000L);
//                        once = true;
                    }
                    g.setFont(Resources.font1);
                    g.setColor(255);
                    g.drawString("score", 30, 130, 20);
                    g.drawString("level", 30, 145, 20);
                    g.setFont(Resources.font2);
                    g.setColor(0xff0000);
                    g.drawString(playerScore + "", 60, 130, 20);
                    g.drawString((level + 1) + "", 60, 145, 20);
                    g.setFont(Resources.font4);
                    g.setColor(0);
                    g.drawString(" CONGRATULATIONS!", 8, 30, 20);
                    g.drawString("You have reached", 10, 50, 20);
                    g.drawString("Maximum Level", 20, 70, 20);
                } else
                {
                    isNextLevel = true;
                }
            scoreSprite.paint(g);
            if(timer.getTimeInSeconds() <= 11 && timer.getTime() % 1000 == 0)
                m++;
            try
            {
                timeSprite.setFrame(m % 2 + 1);
            }
            catch(Exception e) { }
            timeSprite.paint(g);
            if(isNextLevel)
                paintNextLevel(g);
            else
            if(gameOver)
            {
                gameOver();
                paintGameOver(g);
                running = false;
            } else
            if(!once)
                paintGame(g);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        ready = true;
    }

    private void paintGame(Graphics g)
    {
        g.setColor(0);
        try
        {
            if(!timer.isRunning())
                timer.start();
        }
        catch(Exception e) { }

⌨️ 快捷键说明

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