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

📄 tank.java

📁 手机上一个坦克游戏
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                if (temp > tank_y) {
                    tank_x = tank_x + dir * TANK_HSCALE / 2;
                    //System.out.println("yes below , tank_x = " + tank_x);
                }
                else {
                    tank_x = tank_x + dir;
                    //System.out.println("no overhead, tank_x++ = " + tank_x);
                }

                if (tank_x < TANK_HSCALE / 2) {
                    tank_x = TANK_HSCALE / 2;
                    //System.out.println("tank_y = " + tank_y);
                }
                else {
                    if (tank_x >
                        Main.displayable.MAP_WIDTH - 1 - TANK_HSCALE / 2) {
                        tank_x = Main.displayable.MAP_WIDTH - 1 -
                            TANK_HSCALE / 2;
                    }
                    else {
                        if (temp > tank_y) {
                            tank_y = Main.displayable.map.getDownNotNull(tank_x,
                                tank_y) - TANK_VSCALE / 2;
                            Main.displayable.content[0] = "tank_y down = " +
                                tank_y;
                        }
                        else {
                            tank_y = temp;
                        }
                    }
                }

                //System.out.println("b add x = " + tank_x +
                //                   ", y = " +
                //                   tank_y);
                Main.displayable.route.addElement(new Integer(tank_x));
                Main.displayable.route.addElement(new Integer(tank_y));
                if (tank_y >
                    Main.displayable.screen_h * 3 / 4 -
                    Main.displayable.SCREEN_Y &&
                    -Main.displayable.SCREEN_Y <=
                    Main.displayable.MAP_HEIGHT - Main.displayable.screen_h) {
                    Main.displayable.setTranslateY( (short) ( -Math.min(temp -
                        tank_y,
                        Main.displayable.MAP_HEIGHT - Main.displayable.SCREEN_Y)));
                }

                if (dir == 1) {
                    if (tank_x >
                        Main.displayable.screen_w * 3 / 4 -
                        Main.displayable.SCREEN_X &&
                        -Main.displayable.SCREEN_X <=
                        Main.displayable.MAP_WIDTH - Main.displayable.screen_w
                        ) {
                        Main.displayable.setTranslateX( -1);
                    }
                }
                if (dir == -1) {
                    if (tank_x <
                        -Main.displayable.SCREEN_X +
                        Main.displayable.screen_w / 4 &&
                        Main.displayable.SCREEN_X < 0
                        ) {
                        Main.displayable.setTranslateX(1);
                    }
                }
                move--;
                Main.displayable.repaint();

            }
        }
        //System.out.println("after moveTank x = " + tank_x + " y = " + tank_y);

    }

//是否对导弹的速度加速
    public void accelerate() {
        if (speed < 70) {
            speed++;
        }
        //Main.displayable.repaint(4, 4, 80, 40);
    }

//这个函数用来判断时候与导弹碰撞
    public boolean isCollision(Missile e1) {
        //计算导弹的位置
        if (e1.m_x > tank_x - 8 && e1.m_x < tank_x + 8 &&
            e1.m_y > tank_y - 8 &&
            e1.m_y < tank_y + 8) { // 击中坦克
            return true;
        }
        else {
            return false;
        }
    }

    public void addProperties(String property) {
        //properties.insertElementAt(property, 0);
        if (properties.size() < 4) {
            properties.addElement(property);
        }
    }

    public String getProperty(int index, int token) {
        int maxToken = -1;
        int mode = Integer.parseInt(getStringBetween(index, 0));
        if (mode == 0) {
            maxToken = 6;
        }
        if (mode == 1) {
            maxToken = 5;
        }
        if (index < properties.size() && index >= 0 && 0 <= token &&
            token <= maxToken) {
            return getStringBetween(index, token);
        }
        //以后可能还会有其他的物品
        return "";
    }

    /*
         public int getPropertyID(int index) {
        //携带的物品:导弹 0$物品的Id$物品的名字$攻击力$导弹个数$攻击范围$
        //物品:1$物品的Id$物品的名字$血$移动力$
        //System.out.println("index = " + index + "properties.size() " + properties.size());
        if (index < properties.size() && index >= 0) {
            String id = getStringBetween(index, 1);
            //System.out.println("get Prop id: " + id);
            return Integer.parseInt(id);
        }
        else {
            return -1;
        }
         }

         public String getPropertyName(int index) {
        if (index < properties.size() && index >= 0) {
            String id = getStringBetween(index, 2);
            return id;
        }
        else {
            return null;
        }
         }

         public int getAttackDemage(int index) {
        if (index < properties.size() && index >= 0) {
            String id = getStringBetween(index, 3);
            return Integer.parseInt(id);
        }
        else {
            return 0;
        }
         }

         public int getMissilesNum(int index) {
        if (index < properties.size() && index >= 0) {
            String id = getStringBetween(index, 4);
            return Integer.parseInt(id);
        }
        else {
            return 0;
        }
         }

         public int getAttackArea(int index) {
        if (index < properties.size() && index >= 0) {
            String id = getStringBetween(index, 5);
            return Integer.parseInt(id);
        }
        else {
            return 0;
        }
         }

         public int getBlood(int index) {
        if (index < properties.size() && index >= 0) {
            String id = getStringBetween(index, 3);
            return Integer.parseInt(id);
        }
        else {
            return 0;
        }
         }

         public int getMove(int index) {
        if (index < properties.size() && index >= 0) {
            String id = getStringBetween(index, 4);
            return Integer.parseInt(id);
        }
        else {
            return 0;
        }
         }
     */
    public String getStringBetween(int index, int start) {
        //携带的物品:导弹 0$物品的Id$物品的名字$攻击力$导弹个数$攻击范围$
        //物品 1$物品的Id$物品的名字$血$移动力$
        int temp = -1;
        String s = (String) properties.elementAt(index);
        for (int n = 1; n <= start; n++) {
            temp = s.indexOf("$", temp + 1);
        }
        String result = s.substring(temp + 1, s.indexOf("$", temp + 1));
        return result;
    }

    /*public boolean isMissile(int index) {
        String s = (String) properties.elementAt(index);
        return Integer.parseInt(s.substring(0, 1)) == 0;
         }*/

    public int getInitLife() {
        return INIT_LIFE;
    }

}

⌨️ 快捷键说明

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