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

📄 battlefield.java

📁 手机上一个坦克游戏
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
package demo;

import java.util.*;
import javax.microedition.lcdui.*;

import com.nokia.mid.sound.*;
import com.nokia.mid.ui.*;
import net.jscience.util.*;
import java.io.*;

public class BattleField
    extends FullCanvas
    implements CommandListener, Runnable, ItemStateListener {


    /** 游戏状态常量 */
    private static final int GAME_INIT = 0;
    public static final int GAME_WAIT = 2;
    private static final int GAME_OVER = 5;
    public static final int GAME_OTHERS = 6;
    public static final int GAME_VIEW = 7;
    public static final int GAME_MOVE = 8;
    private static final int GAME_PROPERTY = 9;

    /** 变量 */
    private static boolean needGet = false;
    private boolean playSound = true;

    public int screen_w = getWidth();
    public int screen_h = getHeight();


    public int propIndex = 0;
    public int game_page = -1;
    public static int map_page = -1;

    private int keyControl = -1;
    private int key;
    public boolean hasRepeat = false;
    public boolean release = false;

    private RepeatTask repeatTask = null;

    public int gameStatus;
    private Image view = null;
    private Image move = null;
    private Image prop = null;
    private Image curUsed = null;
    private Image[] item_pics = new Image[4];
    private Image comImage = null;
    private Image teamAImage = null;
    private Image teamBImage = null;
    private Image compass = null;
    public MHttpConnection mHttpConnection = null;

    private Thread thread;
    public boolean sentMissile = false; //是否已经发射过导弹,为true则不能再发
    private Display display;

    private Vector m_vGameDetails = null;

    //天空掉落物品列表
    public Vector items = null;
    public Missile missiles = null;

    //public Vector crash = null;
    public Image crash = null;
    public Vector route = null;

    public int MAP_WIDTH = 0;
    public int MAP_HEIGHT = 0;

    // mapInfo;
    public static final int BOX_SIZE = 15;
    public static int SCREEN_X = 0;
    public static int SCREEN_Y = 0;

    public Forground map;
    public Tank now;
    public int count_time = 20;
    public boolean isMe = false;
    private int current = 0;
    private int cur_mapid = 0;
    private String cur_mapname = null;
    public String win;

    //战场中要显示的信息
    public String[] content = new String[3];
    public Tank[] runs;

    //战场发送的消息

    private int[] moreMapID;
    private int[] mapColor = {
        0x00407F,
        0xB1CCFB,
        0x00407F,
        0x9EBDD1
    };
    private int[] mapID = {
        1, 2, 3, 4};
    private String[] mapName = {
        "The blizzard land",
        "The wolf tooth",
        "The Music Land",
        "The Ice Land"
    };

    //声音文件
    byte[] soundData = {
        (byte) 0x02, (byte) 0x4a, (byte) 0x3a, (byte) 0x40,
        (byte) 0x04, (byte) 0x00, (byte) 0x0b, (byte) 0x20,
        (byte) 0x82, (byte) 0xb0, (byte) 0x33, (byte) 0x03,
        (byte) 0x88, (byte) 0x00
    };

    public boolean getNewLives = false;
    private boolean isHost = false;
    public Image arrow = null;

    //控制發射導彈個數
    public static int missileIndex = 0;

    //当前窗口的之前窗口,用于出错控制或者超时时候能正确回去
    private Displayable preDisplayable;
    public static BattleField instance;

    //当前使用的物品ID
    public int curUsingItemMode = -1;
    public int curUsingItemID = -1;

    //当前更换坦克列表
    public Vector m_vTank = null;

    //当前购买导弹列表
    public Vector m_vMissile = null;

    //当前买或卖物品列表
    public Vector m_vGoods = null;

    //我當前的物品列表
    public Vector m_vMy = null;

    /** Command */
    private static Command joinCommand = new Command("Join", Command.OK, 1);
    private static Command regCommand = new Command("Resigter", Command.OK, 2);
    private static Command sendCommand = new Command("Send", 4, 1);
    private static Command searchCommand = new Command("Search", 4, 1);
    private static Command loginCommand = new Command("Login", Command.OK, 1);
    private static Command backCommand = new Command("Back", 2, 0);
    private static Command okCommand = new Command("OK", Command.OK, 0);
    private static Command createCommand = new Command("Create", 4, 1);
    private static Command buyCommand = new Command("buy", 4, 1);
    private static Command detailCommand = new Command("Detail", 4, 1);
    private static Command refreshCommand = new Command("Refresh", 4, 1);

    //剔出用户
    private static Command banCommand = new Command("Ban", 4, 1);

    //聊天
    private static Command chatCommand = new Command("Chat", 4, 1);
    private static Command changeCommand = new Command("Change", 4, 1);

    /** member variable */
    public static String userName = "";
    private String pwd = "";

    //may be retrived from RMS
    private String tankName = "";

    //最后收到的一条信息
    private String lastMessage = "";

    //聊天时候发送的消息
    private String needSendMsg = "";

    //接受消息的用户
    private String sendToUser = "";

    private List startList = null;

    private List mainList = null;
    private List itemList = null;

    private List moreMapList = null;
    private List tankList = null;
    private List missileList = null;
    private List goodsList = null;

    private List msgList = null;

    //设置
    private List settingList = null;

    //公共聊天窗口
    private List chatList = null;

    //当前游戏列表
    private List onlineGames = null;
    public List game = null;

    private ChoiceGroup mapCG;

    /** Form */
    private Form loadingForm = null;
    private Form searchForm = null;
    private Form loginForm = null;
    private Form regForm = null;
    //private Form shopForm = null;
    private Form createGameForm = null;

    private List soundList = null;
    private Form battleMsgForm = null;

    //消息发送窗口
    private Form msgForm = null;

    //创建游戏的详细信息
    private Form gameDetailForm;

    /** Constructor */
    public BattleField(Display display) {

        instance = this;
        this.display = display;
        try {
            Main.a("/demo/res/resource1.pak");
            byte abyte0[] = Main.b("view.png");
            view = Image.createImage(abyte0, 0, abyte0.length);
            //abyte0 = null;
            abyte0 = Main.b("move.png");
            move = Image.createImage(abyte0, 0, abyte0.length);
            abyte0 = Main.b("prop.png");
            prop = Image.createImage(abyte0, 0, abyte0.length);

            abyte0 = Main.b("arrow0.png");
            teamAImage = Image.createImage(abyte0, 0, abyte0.length);
            abyte0 = Main.b("bullet.png");
            teamBImage = Image.createImage(abyte0, 0, abyte0.length);

            abyte0 = Main.b("com.png");
            comImage = Image.createImage(abyte0, 0, abyte0.length);
            abyte0 = Main.b("compass.png");
            compass = Image.createImage(abyte0, 0, abyte0.length);
            abyte0 = null;
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        OperateRMS userRMS = new OperateRMS("User");
        userRMS.openRSAnyway();
        int num = userRMS.recordNum();
        startList = new List("Login", 3);
        String userInfo = "";
        for (int i = 0; i < num; i++) {
            userInfo = userRMS.UIManagerIn(i + 1);
            userInfo = userInfo.substring(0, userInfo.indexOf("$"));
            startList.append(userInfo, null);
        }
        userRMS.closeRSAnyway();
        startList.append("Other users", null);
        startList.append("Register", null);
        startList.addCommand(okCommand);
        startList.setCommandListener(this);

        loadingForm = new Form("Loading...");
        loadingForm.append("即将进行gprs连接,请您稍等后在连接列表中选择cmnet连接。选择后请等待,屏幕左上角出现G,即为正在连接,出现一个带G的四方框则表示gprs已经连接、可以继续操作.");
        Ticker ticker = new Ticker("Loading...");
        loadingForm.setTicker(ticker);
        //loadingForm.addCommand(new Command("Cancel", Command.EXIT, 0));
        //loadingForm.setCommandListener(this);

        msgForm = new Form("Message");
        msgForm.addCommand(sendCommand);
        msgForm.addCommand(backCommand);
        TextField sendToUserTF = new TextField("SendToUser", sendToUser, 12, 0);
        TextField msgTF = new TextField("Message", needSendMsg, 12, 0);
        msgForm.append(sendToUserTF);
        msgForm.append(msgTF);
        msgForm.setCommandListener(this);

        gameStatus = GAME_INIT;
        thread = new Thread(this);
        thread.start();

    }

    //当前加入或者创建游戏的列表
    private void createGameList(String players[], int foreNum) {
        int i;
        game = null;
        if (game == null) {
            game = new List("Game", 3);
        }
        else {
            for (; game.size() > 0; game.delete(0)) {
                ;
            }
        }

        for (i = 0; i < foreNum; i++) {
            game.append(players[i], teamAImage);
        }
        for (i = foreNum; i < players.length; i++) {
            game.append(players[i], teamBImage);
        }
        if (isHost) {
            game.addCommand(okCommand);
            game.addCommand(banCommand);
            game.addCommand(changeCommand);
        }
        game.addCommand(chatCommand);
        game.addCommand(backCommand);
        game.setCommandListener(this);

⌨️ 快捷键说明

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