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

📄 battlefield.java

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

                    displayable = advForm;
                    display.setCurrent(displayable);
                    break;
                case 1:
                    displayable = startList;
                    userName = "";

                    changeToAlert("Warning", httpClientHolder.ReadUTF(),
                                  displayable,
                                  AlertType.WARNING, 2000);
                    break;
                case 5: //返回创建游戏的信息
                    playSound(1);
                    //修改连接延时
                    mHttpConnection.frequency = 4000L;
                    //删除游戏用户列表
                    if (game != null) {
                        for (; game.size() > 0; game.delete(0)) {
                            ;
                        }
                    }

                    //创建者
                    StringBuffer tmp = new StringBuffer();
                    tmp.append(userName);
                    if (userName.length() < 12) {
                        for (int j = 0; j < 12 - userName.length(); j++) {
                            tmp.append(" ");
                        }
                    }
                    tmp.append("   ");
                    tmp.append(httpClientHolder.ReadInt());
                    String my[] = {
                        tmp.toString()
                    };
                    isHost = true;
                    createGameList(my, 1);
                    displayable = game;
                    display.setCurrent(displayable);
                    break;
                case 6:
                    displayable = mainList;
                    changeToAlert("warning", httpClientHolder.ReadUTF(),
                                  displayable,
                                  AlertType.WARNING, 2000);
                    break;
                case 7:
                case 13:
                    playSound(1);
                    mHttpConnection.frequency = 4000;
                    if (game != null) {
                        for (; game.size() > 0; game.delete(0)) {
                            ;
                        }
                    }

                    String gameName = httpClientHolder.ReadUTF();
                    byte gameMode = httpClientHolder.ReadByte();
                    cur_mapid = httpClientHolder.ReadShort();
                    byte foreNum = httpClientHolder.ReadByte();
                    byte playerCount = httpClientHolder.ReadByte();
                    String players[] = new String[playerCount];
                    int l;
                    String user = "";
                    int wordWidth;
                    for (l = 0; l < foreNum; l++) {
                        user = httpClientHolder.ReadUTF();
                        wordWidth = 12 - user.length();
                        if (user.length() < 12) {
                            for (int j = 0; j < wordWidth; j++) {
                                user = user + " ";
                            }
                        }
                        players[l] = user + "   " + httpClientHolder.ReadInt();
                    }
                    for (l = foreNum; l < playerCount; l++) {
                        user = httpClientHolder.ReadUTF();
                        wordWidth = 12 - user.length();
                        if (user.length() < 12) {
                            for (int j = 0; j < wordWidth; j++) {
                                user = user + " ";
                            }
                        }
                        players[l] = user + "   " + httpClientHolder.ReadInt();
                    }
                    isHost = false; //不是游戏的创建者
                    createGameList(players, foreNum);
                    displayable = game;
                    display.setCurrent(displayable);
                    break;
                case 8:
                    displayable = mainList;
                    changeToAlert("warning", "No Game Avaiable!", displayable,
                                  AlertType.WARNING, 1000);
                    break;
                case 9: //somebody joined the game
                case 15:
                    if (display.getCurrent() != loadingForm) {
                        playSound(1);
                        byte teamNum = httpClientHolder.ReadByte();
                        String joinUser = httpClientHolder.ReadUTF();
                        if (joinUser.length() < 12) {
                            int cWordWidth = 12 - joinUser.length();
                            for (int j = 0; j < cWordWidth; j++) {
                                joinUser = joinUser + " ";
                            }
                        }
                        if (teamNum == 0) {
                            game.append(joinUser + "   " +
                                        httpClientHolder.ReadInt(), teamAImage);
                        }
                        else {
                            game.append(joinUser + "   " +
                                        httpClientHolder.ReadInt(), teamBImage);
                        }
                        displayable = game;
                        display.setCurrent(displayable);
                    }
                    break;
                case 10: //开始战斗成功!
                    mHttpConnection.frequency = 3000;
                    byte foreofPlayers = httpClientHolder.ReadByte();

                    byte playerscount = httpClientHolder.ReadByte();

                    try {
                        runs = new Tank[playerscount];
                        int i;
                        for (i = 0; i < foreofPlayers; i++) {
                            runs[i] = new Tank( /*this,/**/
                                httpClientHolder.ReadUTF(),
                                httpClientHolder.ReadByte(), //tankID
                                httpClientHolder.ReadByte(), //move
                                10,
                                10, httpClientHolder.ReadShort(),
                                httpClientHolder.ReadShort(),
                                httpClientHolder.ReadShort(), false,
                                httpClientHolder.ReadByte());
                        }
                        for (i = foreofPlayers; i < playerscount; i++) {

                            runs[i] = new Tank( /*this,/**/
                                httpClientHolder.ReadUTF(),
                                httpClientHolder.ReadByte(),
                                httpClientHolder.ReadByte(),
                                10,
                                10, httpClientHolder.ReadShort(),
                                httpClientHolder.ReadShort(),
                                httpClientHolder.ReadShort(), true,
                                httpClientHolder.ReadByte());
                        }
                        now = runs[0];
                        int index = 0;
                        for (index = 0; index < runs.length; index++) {
                            if (runs[index].userName.equals(
                                userName)) {
                                break;
                            }
                        }
                        byte itemsCount = httpClientHolder.ReadByte();
                        for (int k = 0; k < itemsCount; k++) {
                            String prop = httpClientHolder.ReadUTF();
                            runs[index].addProperties(prop);
                        }

                        byte revMap = httpClientHolder.ReadByte();

                        OperateRMS mapRMS = new OperateRMS("Map");
                        mapRMS.openRSAnyway();
                        if (revMap == 0) {
                            cur_mapname = httpClientHolder.ReadUTF();
                            MAP_WIDTH = httpClientHolder.ReadShort();
                            MAP_HEIGHT = httpClientHolder.ReadShort();
                            byte t = httpClientHolder.ReadByte();
                            int size = httpClientHolder.ReadShort();
                            short[] mapInfo = new short[size];
                            for (int k = 0; k < size; k++) {
                                mapInfo[k] = httpClientHolder.ReadShort();
                            }
                            if (t == 1) { //新的地图格式
                                map = new Forground(mapInfo, cur_mapid - 1,
                                    MAP_WIDTH, MAP_HEIGHT,
                                    mapColor[ (cur_mapid - 1) % 4], size / 4, true);
                            }
                            else { //老地图格式
                                map = new Forground(mapInfo, cur_mapid - 1,
                                    MAP_WIDTH, MAP_HEIGHT,
                                    mapColor[ (cur_mapid - 1) % 4], 0, false);
                            }

                            mapRMS.addMap(mapInfo, cur_mapid, MAP_WIDTH,
                                          MAP_HEIGHT,
                                          cur_mapname, t);
                            mapInfo = null;
                        }
                        else {
                            cur_mapname = mapRMS.getMapName(1);
                            MAP_WIDTH = mapRMS.getMapWidth(1);
                            MAP_HEIGHT = mapRMS.getMapHeight(1);

                            byte t = mapRMS.getIsNew(1);
                            short[] mapInfo = mapRMS.getMap(1);
                            int size = mapInfo.length;
                            if (t == 1) { //新的地图格式
                                map = new Forground(mapInfo, cur_mapid - 1,
                                    MAP_WIDTH, MAP_HEIGHT,
                                    mapColor[ (cur_mapid - 1) % 4], size / 4, true);
                            }
                            else { //老地图格式
                                if (t == 0) {
                                    map = new Forground(mapInfo, cur_mapid - 1,
                                        MAP_WIDTH, MAP_HEIGHT,
                                        mapColor[ (cur_mapid - 1) % 4], 0, false);
                                }
                            }
                        }
                        mapRMS.closeRSAnyway();
                        mapRMS = null;
                        for (int k = 0; k < runs[index].properties.size(); k++) {
                            int id = Integer.parseInt(runs[index].getProperty(k,
                                1));
                            int mode = (Integer.parseInt(runs[index].
                                getStringBetween(k, 0)) == 0) ? 0 :
                                1;
                            String dir = null;
                            if (mode == 0) { //

                                dir = "prop_010.png";
                            }
                            else { // items
                                dir = "prop_1" + id + "0.png";
                            }
                            byte abyte[] = Main.b(dir);
                            try {
                                item_pics[k] = Image.createImage(abyte, 0,
                                    abyte.length);
                            }
                            catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                        if (route == null) {
                            route = new Vector();
                        }
                        if (items == null) {
                            items = new Vector();
                        }
                        route.addElement(new Integer(now.tank_x));
                        route.addElement(new Integer(now.tank_y));

                        byte abyte0[] = Main.b("arrow0.png");
                        arrow = Image.createImage(abyte0, 0, abyte0.length);
                        abyte0 = null;

                        setOrigin(); //初始化变量
                        this.setGameStatus();
                        if (now.tank_x > 3 * screen_w / 4) {
                            setTranslateX( -Math.min(now.tank_x -
                                screen_w / 2,
                                MAP_WIDTH - screen_w));
                        }
                        if (now.tank_y > screen_h * 3 / 4) {
                            setTranslateY( -Math.min(now.tank_y -
                                (screen_h * 3 / 4),
                                MAP_HEIGHT - screen_h));
                        }
                        playSound(1);
                        display.setCurrent(this);

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

                    break;
                case 61: //游戏开始失败
                    displayable = game;
                    changeToAlert("Error", httpClientHolder.ReadUTF(),
                                  displayable, AlertType.ERROR, 2000);
                    break;
                case 11:
                    String playerName = httpClientHolder.ReadUTF();
                    if (playerName.equals(userName)) {
                        displayable = mainList;
                        display.setCurrent(displayable);
                    }
                    else {
                        for (int i = 0; i < game.size(); i++) {
                            if ( (game.getString(i).substring(0,
                                game.getString(i).indexOf("   "))).equals(
                                playerName)) {
                                game.delete(i);
                                break;
                            }
                        }
                        displayable = game;
                        display.setCurrent(displayable);
                    }
                    break;
                case 12:
                case 21:
                case 51:
                case 52:
                    if (onlineGames != null) {
                        for (; onlineGames.size() > 0; onlineGames.delete(0)) {
                            ;
                        }
                    }
                    byte gamesCount = httpClientHolder.ReadByte();
                    if (m_vGameDetails == null) {
                        m_vGameDetails = new Vector();
                    }
                    if (m_vGameDetails != null) {

⌨️ 快捷键说明

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