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

📄 gamescreen.java

📁 手机游戏
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   GameScreen.java

package matchit2;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Timer;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.VolumeControl;

// Referenced classes of package matchit2:
//            TimerTask, GameMatrix, GameWin, FireworksCanvas, 
//            MatchIt2, MainMenu

public class GameScreen extends GameCanvas
{

    public GameScreen(MatchIt2 m, MainMenu mp, int lvl)
    {
        super(false);
        HASSOUND = false;
        HASTEST = false;
        X = 1;
        Y = 1;
        XX = -1;
        YY = -1;
        X1 = -1;
        X2 = -1;
        Y1 = -1;
        Y2 = -1;
        VStep = 1;
        HStep = 1;
        VSize = 22;
        HSize = 22;
        VCount = 14;
        HCount = 9;
        SeedCount = 35;
        ImageCount = 35;
        XMargin = 2;
        YMargin = 2;
        HintOffset = 100;
        LineSize = 2;
        LineColor = 0xffffff;
        BackColor = 0;
        RectColor = 0xff0000;
        SeleColor = 65280;
        OuterColor = 0xffffff;
        HintColor = 0x2200ff;
        TimeColor = 65280;
        SoundVolume = 100;
        CurrentRound = 1;
        ScoreColor = 0x7777ff;
        RestShuffle = 4;
        RestHint = 6;
        TimeTotal = 360;
        TimeWidth = 60;
        timertask = new TimerTask(this);
        timer = new Timer();
        Level = 0;
        Paused = true;
        Ended = false;
        setFullScreenMode(true);
        try
        {
            parent = m;
            myparent = mp;
            Level = lvl;
            HSize = HSizes[Level];
            VSize = VSizes[Level];
            HCount = HCounts[Level];
            VCount = VCounts[Level];
            XMargin = XMargins[Level];
            YMargin = YMargins[Level];
            SeedCount = SeedCounts[Level];
            jbInit();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

    private void jbInit()
        throws Exception
    {
        if(HASSOUND)
        {
            bs_error = new byte[8470];
            bs_clear = new byte[8470];
            bs_shuffle = new byte[8470];
            bs_global = new byte[20000];
            try
            {
                InputStream is = getClass().getResourceAsStream("/res/sounds/1.wav");
                is.read(bs_clear);
                is.close();
                is = getClass().getResourceAsStream("/res/sounds/3.wav");
                is.read(bs_error);
                is.close();
                is = getClass().getResourceAsStream("/res/sounds/5.wav");
                is.read(bs_shuffle);
                is.close();
                s_gameover = "/res/sounds/6.wav";
                s_win = "/res/sounds/2.wav";
            }
            catch(Exception pe)
            {
                pe.printStackTrace();
            }
        }
        ScreenHeight = getHeight();
        ScreenWidth = getWidth();
        X = 1;
        Y = 1;
        matrix = new GameMatrix(HCount, VCount, SeedCount);
        Score = 0;
        TimeLeft = TimeTotal;
        timer.schedule(timertask, 0L, 1000L);
        Paused = false;
    }

    public void TimeDown()
    {
        if(Paused)
            return;
        TimeLeft--;
        if(TimeLeft <= 0)
        {
            timer.cancel();
            GameEnd();
        }
        repaint();
    }

    private void plays(String s)
    {
        if(!HASSOUND)
            return;
        try
        {
            InputStream is = getClass().getResourceAsStream(s);
            is.read(bs_global);
            is.close();
            playbs(bs_global);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

    private void playbs(byte bs[])
    {
        if(!HASSOUND)
            return;
        if(SoundVolume == 0)
            return;
        try
        {
            if(player != null)
                player.close();
            ByteArrayInputStream bis = new ByteArrayInputStream(bs);
            player = Manager.createPlayer(bis, "audio/x-wav");
            player.realize();
            vc = (VolumeControl)player.getControl("VolumeControl");
            vc.setLevel(SoundVolume);
            player.start();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

    public void GameEnd()
    {
        timertask.cancel();
        Ended = true;
        repaint();
    }

    public void removeImages()
    {
        for(int i = 1; i <= SeedCount; i++)
            images[i - 1] = null;

    }

    public void goMain()
    {
        removeImages();
        if(fireworks != null)
            fireworks.stop();
        fireworks = null;
        if(gamewin != null)
            gamewin.stop();
        gamewin = null;
        Display.getDisplay(parent).setCurrent(myparent);
    }

    private void Success()
    {
        Paused = true;
        CurrentRound++;
        plays(s_win);
        if(CurrentRound >= 12)
        {
            removeImages();
            if(Level < 2)
            {
                timer.cancel();
                if(gamewin == null)
                    gamewin = new GameWin(this, Level);
                Display.getDisplay(parent).setCurrent(gamewin);
                gamewin.start();
            } else
            {
                if(fireworks == null)
                    fireworks = new FireworksCanvas(this);
                Display.getDisplay(parent).setCurrent(fireworks);
                fireworks.start();
            }
        }
        RestShuffle++;
        RestHint++;
        matrix.initMatrix(HCount, VCount);
        TimeLeft = TimeTotal;
        Paused = false;
    }

    private void ShowHint()
    {
        int i = matrix.find();
        if(i > 0)
        {
            X1 = (i / 1000) % HCount;
            Y1 = i / 1000 / HCount;
            X2 = i % 1000 % HCount;
            Y2 = (i % 1000) / HCount;
        }
    }

    protected void keyRepeated(int keyCode)
    {
        int j = getGameAction(keyCode);
        switch(j)
        {
        case 1: // '\001'
        case 2: // '\002'
        case 5: // '\005'
        case 6: // '\006'
            keyPressed(keyCode);
            // fall through

        case 3: // '\003'
        case 4: // '\004'
        default:
            return;
        }
    }

    public void goPause()
    {
        Paused = true;
        repaint();
    }

    public void goActive(boolean resume)
    {
        Paused = !resume;
        repaint();
    }

    protected void pointerPressed(int x, int y)
    {
        if(Ended)
        {
            goMain();
            return;
        }
        int xx = x / HSizes[Level];
        int yy = y / VSizes[Level];
        if(x > ScreenWidth - 10 && y > ScreenHeight - 10)
        {
            goMain();
            return;
        }
        if(x > 50 && y > ScreenHeight - 13 && x < 50 + TimeWidth)
            if(Paused)
            {
                goActive(true);
                return;
            } else
            {
                goPause();
                return;
            }
        if(xx < HCounts[Level] && yy < VCounts[Level])
        {
            X = xx + 1;
            Y = yy + 1;
            keyPressed(getKeyCode(8));
            return;
        }
        if(x > ScreenWidth - 67 && y > ScreenHeight - 13 && x < ScreenWidth - 54)
        {
            keyPressed(57);
            return;
        }
        if(x > ScreenWidth - 33 && y > ScreenHeight - 13 && x < ScreenWidth - 23)
        {
            keyPressed(35);
            return;
        }
        if(x > 53 + TimeWidth && y > ScreenHeight - 13 && x < 68 + TimeWidth)
        {
            keyPressed(55);
            return;
        } else
        {
            return;
        }
    }

    public void keyPressed(int keyCode)
    {
        if(Paused)
        {
            if(getGameAction(keyCode) == 8)
                goActive(true);
            return;
        }
        switch(keyCode)
        {
        default:
            break;

        case 48: // '0'
            if(HASTEST)
            {
                CurrentRound = 12;
                Success();
            }
            break;

        case 49: // '1'
            if(HASTEST)
                GameEnd();
            break;

        case 42: // '*'
            goPause();
            break;

        case 35: // '#'
            if(X1 >= 0)
                break;
            if(RestHint > 0)
            {
                ShowHint();
                RestHint--;
            }
            repaint();
            break;

        case 57: // '9'
            if(RestShuffle > 0)
            {
                do
                    matrix.shuffleMatrix();
                while(matrix.find() == 0);
                RestShuffle--;
                matrix.rearrange(CurrentRound);
                playbs(bs_shuffle);
            }
            repaint();
            break;

        case 55: // '7'
            SoundVolume = SoundVolume - 25;
            if(SoundVolume < 0)
                SoundVolume = 100;
            repaint();
            break;
        }
        keyCode = getGameAction(keyCode);
        switch(keyCode)
        {
        case 3: // '\003'
        case 4: // '\004'
        case 7: // '\007'
        default:
            break;

        case 8: // '\b'
            if(Ended)
            {
                goMain();
                return;
            }
            if(matrix.getAt(X, Y) >= 0)
            {
                int j;
                if(XX == X && YY == Y)
                {
                    XX = -1;
                    YY = -1;
                } else
                if(XX < 0 || YY < 0)
                {
                    XX = X;
                    YY = Y;
                    playbs(bs_error);
                } else

⌨️ 快捷键说明

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