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

📄 mygamewithtiledlayercanvas.jad

📁 一个类似泡泡堂的战车游戏。 两人玩的对战游戏
💻 JAD
字号:
// Decompiled by DJ v2.9.9.60 Copyright 2000 Atanas Neshkov  Date: 2004-6-1 16:58:41
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   MyGameWithTiledLayerCanvas.java

import java.io.OutputStream;
import java.io.PrintStream;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.*;

public class MyGameWithTiledLayerCanvas extends GameCanvas
    implements Runnable
{

    public MyGameWithTiledLayerCanvas(int x1, OutputStream os1)
    {
        super(true);
        RIGHT = 3;
        LEFT = 0;
        UP = 1;
        DOWN = 2;
        WALL = 0;
        state = 0;
        state1 = 0;
        conti = true;
        rate = 150;
        flag = x1;
        if(flag == 1)
        {
            x = 0;
            y = 0;
            ex = 160;
            ey = 153;
            tank = 0;
        } else
        {
            x = 160;
            y = 153;
            ex = 0;
            ey = 0;
            tank = 109;
        }
        os = os1;
        sender = new Sender(os);
        lm = new LayerManager();
        b1 = createBackGround();
        c1 = createTank("/pic/tank2.png");
        c2 = createTank("/pic/tank2.png");
        lm.append(c1);
        lm.append(c2);
        lm.append(b1);
    }

    private Sprite createTank(String pic)
    {
        Image img = null;
        try
        {
            img = Image.createImage(pic);
        }
        catch(Exception exp)
        {
            System.out.println(exp);
        }
        return new Sprite(img, 16, 16);
    }

    public TiledLayer createBackGround()
    {
        Image img = null;
        try
        {
            img = Image.createImage("/pic/border.png");
        }
        catch(Exception exp)
        {
            System.out.println(exp);
        }
        TiledLayer tiledLayer = new TiledLayer(11, 10, img, 16, 17);
        tiledLayer.createAnimatedTile(5);
        for(int i = 0; i < map.length; i++)
        {
            int column = i % 11;
            int row = (i - column) / 11;
            tiledLayer.setCell(column, row, map[i]);
        }

        return tiledLayer;
    }

    public void run()
    {
        long st = 0L;
        long et = 0L;
        g = getGraphics();
        do
        {
            if(!conti)
                break;
            st = System.currentTimeMillis();
            input();
            rotate();
            tank1 = ex / 16 + (ey / 17) * 11;
            render(g);
            et = System.currentTimeMillis();
            if(et - st < (long)rate)
                try
                {
                    Thread.sleep((long)rate - (et - st));
                }
                catch(Exception exp) { }
        } while(true);
    }

    public void input()
    {
        int keystate = getKeyStates();
        if((keystate & 2) != 0)
        {
            tank = tank - 11;
            if(tank >= 0 && (map[tank] | WALL) != 2 && (map[tank] | WALL) != 18 && (map[tank] | WALL) != 3)
            {
                state = 3;
                y = y - 17;
                if(y <= 0)
                    y = 0;
                sendto(x, y, -1, state);
            } else
            {
                tank = tank + 11;
            }
        }
        if((keystate & 0x40) != 0)
        {
            tank = tank + 11;
            if(tank <= 109 && (map[tank] | WALL) != 2 && (map[tank] | WALL) != 18 && (map[tank] | WALL) != 3)
            {
                state = 1;
                y = y + 17;
                if(y >= 153)
                    y = 153;
                sendto(x, y, -1, state);
            } else
            {
                tank = tank - 11;
            }
        }
        if((keystate & 4) != 0)
        {
            tank = tank - 1;
            if(tank >= 0 && (map[tank] | WALL) != 2 && (map[tank] | WALL) != 18 && (map[tank] | WALL) != 3)
            {
                state = 2;
                x = x - 16;
                if(x < 0)
                {
                    x = 0;
                    tank = tank + 1;
                }
                sendto(x, y, -1, state);
            } else
            {
                tank = tank + 1;
            }
        }
        if((keystate & 0x20) != 0)
        {
            tank = tank + 1;
            if(tank <= 109 && (map[tank] | WALL) != 2 && (map[tank] | WALL) != 18 && (map[tank] | WALL) != 3)
            {
                state = 0;
                x = x + 16;
                if(x >= 176)
                {
                    x = 160;
                    tank = tank - 1;
                }
                sendto(x, y, -1, state);
            } else
            {
                tank = tank - 1;
            }
        }
        if((keystate & 0x100) != 0)
        {
            bomb = new Bomb(tank, this);
            bomb.start();
            sendto(x, y, tank, state);
        }
    }

    public void updatetile1(int x, int y, int z)
    {
        int x1 = x;
        int y1 = y;
        int z1 = z;
        int z2 = x1 + y1 * 11;
        map[z2] = 18;
        if(z1 == 11)
            map[z2] = 11;
        b1.setCell(x1, y1, z1);
    }

    public void updatetile(int x, int y, int z)
    {
        int x1 = x;
        int y1 = y;
        int z1 = z;
        int z2 = x1 + y1 * 11;
        if(z2 <= 109 && z2 >= 0 && x1 >= 0 && x1 <= 10 && y1 >= 0 && y1 <= 9 && map[z2] != 2)
            b1.setCell(x1, y1, z1);
        if(z2 == tank)
            if(flag == 2)
                flag = 3;
            else
            if(flag == 0)
                flag = 1;
        if(z2 == tank1)
            if(flag == 1)
                flag = 3;
            else
            if(flag == 0)
                flag = 2;
        if(z2 <= 109 && z2 >= 0 && map[z2] == 3)
            map[z2] = 11;
    }

    public void rotate()
    {
        setTankDirection(state);
        setTankDirection1(state1);
    }

    public void setTankDirection(int state)
    {
        switch(state)
        {
        case 0: // '\0'
            c1.setFrame(0);
            Sprite _tmp = c1;
            c1.setTransform(5);
            break;

        case 1: // '\001'
            c1.setFrame(0);
            Sprite _tmp1 = c1;
            c1.setTransform(3);
            break;

        case 2: // '\002'
            c1.setFrame(0);
            Sprite _tmp2 = c1;
            c1.setTransform(6);
            break;

        case 3: // '\003'
            c1.setFrame(0);
            Sprite _tmp3 = c1;
            c1.setTransform(0);
            break;
        }
    }

    public void setTankDirection1(int state1)
    {
        switch(state1)
        {
        case 0: // '\0'
            c2.setFrame(0);
            Sprite _tmp = c2;
            c2.setTransform(5);
            break;

        case 1: // '\001'
            c2.setFrame(0);
            Sprite _tmp1 = c2;
            c2.setTransform(3);
            break;

        case 2: // '\002'
            c2.setFrame(0);
            Sprite _tmp2 = c2;
            c2.setTransform(6);
            break;

        case 3: // '\003'
            c2.setFrame(0);
            Sprite _tmp3 = c2;
            c2.setTransform(0);
            break;
        }
    }

    public void render(Graphics g)
    {
        c1.defineReferencePixel(16, 16);
        c2.defineReferencePixel(16, 16);
        c1.setPosition(x, y);
        c2.setPosition(ex, ey);
        lm.setViewWindow(0, 0, 180, 177);
        lm.paint(g, 0, 0);
        flushGraphics();
    }

    public void sendto(int x1, int y1, int z1, int w1)
    {
        int x2 = x1;
        int y2 = y1;
        int z2 = z1;
        int w2 = w1;
        String s3 = "";
        s3 = s3 + x2;
        s3 = s3 + ":";
        s3 = s3 + y2;
        s3 = s3 + ";";
        s3 = s3 + z2;
        s3 = s3 + ",";
        s3 = s3 + w2;
        sender.send(s3);
    }

    public void die1()
    {
        g.setColor(0xff0000);
        g.drawString("YOU   LOST", 70, 80, 0);
        flushGraphics();
        conti = false;
    }

    public void die2()
    {
        g.setColor(0xff0000);
        g.drawString("YOU   WIN", 70, 80, 0);
        flushGraphics();
        conti = false;
    }

    public void die3()
    {
        g.setColor(0xff0000);
        g.drawString("   DOGFALL   ", 70, 80, 0);
        flushGraphics();
        conti = false;
    }

    public void start()
    {
        Thread t = new Thread(this);
        t.start();
    }

    public void exit()
    {
        conti = false;
    }

    Graphics g;
    LayerManager lm;
    TiledLayer b1;
    Sprite c1;
    Sprite c2;
    Bomb bomb;
    int tank;
    int tank1;
    int RIGHT;
    int LEFT;
    int UP;
    int DOWN;
    int WALL;
    int x;
    int y;
    int state;
    int state1;
    int ex;
    int ey;
    int flag;
    int flag1;
    OutputStream os;
    Sender sender;
    int map[] = {
        11, 11, 3, 11, 11, 3, 11, 11, 11, 11, 
        11, 11, 11, 2, 11, 3, 11, 3, 2, 3, 
        11, 3, 11, 11, 3, 2, 11, 11, 2, 11, 
        11, 3, 11, 3, 2, 3, 11, 2, 11, 11, 
        11, 3, 11, 3, 11, 11, 2, 11, 3, 11, 
        2, 11, 11, 3, 11, 11, 2, 3, 11, 11, 
        3, 11, 11, 11, 11, 11, 3, 11, 3, 11, 
        3, 11, 11, 2, 11, 11, 11, 11, 2, 3, 
        11, 11, 11, 3, 11, 3, 2, 3, 3, 11, 
        11, 11, 11, 11, 11, 3, 11, 11, 11, 11, 
        11, 11, 11, 11, 2, 3, 11, 11, 11, 11
    };
    boolean conti;
    int rate;
}

⌨️ 快捷键说明

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