欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Java實(shí)現(xiàn)經(jīng)典游戲飛機(jī)大戰(zhàn)-I的示例代碼

 更新時(shí)間:2022年02月09日 14:28:08   作者:小虛竹and掘金  
《飛機(jī)大戰(zhàn)-I》是一款融合了街機(jī)、競技等多種元素的經(jīng)典射擊手游。本文將利用java語言實(shí)現(xiàn)這游戲,文中采用了swing技術(shù)進(jìn)行了界面化處理,感興趣的可以了解一下

前言

《飛機(jī)大戰(zhàn)-I》是一款融合了街機(jī)、競技等多種元素的經(jīng)典射擊手游。華麗精致的游戲畫面,超炫帶感的技能特效,超火爆畫面讓你腎上腺素爆棚,給你帶來全方位震撼感受,體驗(yàn)飛行戰(zhàn)斗的無限樂趣。

游戲是用java語言實(shí)現(xiàn),采用了swing技術(shù)進(jìn)行了界面化處理,設(shè)計(jì)思路用了面向?qū)ο笏枷搿?/p>

主要需求

玩家控制一臺(tái)戰(zhàn)斗機(jī),以消滅所有的敵機(jī)為勝利,有些敵機(jī)會(huì)掉落裝備,不可錯(cuò)過哦

主要設(shè)計(jì)

1、 用Swing庫做可視化界面

2、鼠標(biāo)控制戰(zhàn)斗機(jī)移動(dòng)

3、 用線程實(shí)現(xiàn)畫面刷新。

4、用流實(shí)現(xiàn)音樂播放。

5、 創(chuàng)造一個(gè)飛機(jī), 并且放在場景下方。

6、管理場景所有的飛機(jī)、子彈、道具移動(dòng)

7、管理場景所有的子彈的發(fā)射

8、生成敵方飛機(jī)算法

9、分?jǐn)?shù)計(jì)算算法

功能截圖

游戲開始

戰(zhàn)斗效果:

代碼實(shí)現(xiàn)

啟動(dòng)類

public class Main {

    public static void main(String[] args) {
        // 創(chuàng)建窗口
        JFrame frame = new JFrame("飛機(jī)大戰(zhàn)");
        // 添加 JPanel
        Data.canvas = new Canvas(frame);
        frame.setContentPane(Data.canvas);
        // 初始化 Data
        Data.init();
        // 設(shè)置圖標(biāo)
        frame.setIconImage(Load.image("ICON.png"));
        // 設(shè)置窗口可見
        frame.setVisible(true);
        // 獲取標(biāo)題欄的高度和寬度
        Data.TITLE_BOX_HEIGHT = frame.getInsets().top;
        // 設(shè)置大小
        frame.setSize(Data.WIDTH, Data.HEIGHT + Data.TITLE_BOX_HEIGHT);
        // 窗口大小固定
        frame.setResizable(false);
        // 窗口居中顯示
        frame.setLocationRelativeTo(frame.getOwner());
        // 窗口關(guān)閉時(shí)結(jié)束程序
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        // 播放背景音樂
        Load.sound("background").loop(Clip.LOOP_CONTINUOUSLY);
    }
}

核心類

public class Game implements Scenes {
    // 玩家 BOSS
    Aircraft player, boss;
    // 敵人
    List<Aircraft> enemy;
    // 玩家子彈 敵人子彈 道具列表
    List<Bullet> bulletPlayer, bulletEnemy, bulletBuff;
    // 玩家生命 生命 < 0 時(shí)死亡
    // int life = Data.LIFE;
    // 當(dāng)前關(guān)卡 當(dāng)前分?jǐn)?shù)
    int checkpoint = 1, fraction = 0;
    // 飛機(jī)的飛行方向, 此處需要注意,監(jiān)聽按鍵來控制飛機(jī)移動(dòng)時(shí),不應(yīng)該單純的按鍵按下一次就執(zhí)行一次,因?yàn)殒I盤按下不松開,飛機(jī)應(yīng)該一直向某個(gè)方向移動(dòng),直到按鍵被放開
    boolean left = false, right = false, down = false, up = false;
    // fps, 記錄當(dāng)前幀數(shù)
    int fps = 0;
    // 提示的 x 坐標(biāo)
    int tipsX = -1000;

    public Game() {
        // 創(chuàng)造一個(gè)飛機(jī), 并且放在場景下方, 玩家的角度屬性不會(huì)使用
        player = new Aircraft(Data.playerAircraftImage, Data.playerDeathImage, Data.SPEED, 0, Data.WIDTH / 2 - 40, Data.HEIGHT - 100);
        // 設(shè)置飛機(jī)碰撞點(diǎn),因?yàn)橛螒虿捎玫木匦闻鲎矙z測,會(huì)出現(xiàn)很多誤差,所以手動(dòng)設(shè)置碰撞矩形,不采用圖片的大小, 這個(gè)碰撞的坐標(biāo)是相對(duì)于圖片位置的相對(duì)坐標(biāo)
        player.upperLeft = new Point(15, 15);
        player.lowerRight = new Point(75, 75);
        // 初始化列表
        bulletPlayer = new ArrayList<>();
        bulletEnemy = new ArrayList<>();
        bulletBuff = new ArrayList<>();
        enemy = new ArrayList<>();
    }

    public void onKeyDown(int keyCode) {
        if (keyCode == KeyEvent.VK_W || keyCode == KeyEvent.VK_UP)
            up = true;
        if (keyCode == KeyEvent.VK_S || keyCode == KeyEvent.VK_DOWN)
            down = true;
        if (keyCode == KeyEvent.VK_A || keyCode == KeyEvent.VK_LEFT)
            left = true;
        if (keyCode == KeyEvent.VK_D || keyCode == KeyEvent.VK_RIGHT)
            right = true;
    }

    public void onKeyUp(int keyCode) {
        if (keyCode == KeyEvent.VK_W || keyCode == KeyEvent.VK_UP)
            up = false;
        if (keyCode == KeyEvent.VK_S || keyCode == KeyEvent.VK_DOWN)
            down = false;
        if (keyCode == KeyEvent.VK_A || keyCode == KeyEvent.VK_LEFT)
            left = false;
        if (keyCode == KeyEvent.VK_D || keyCode == KeyEvent.VK_RIGHT)
            right = false;
    }

    public void onMouse(int x, int y, int struts) {

    }

    public void draw(Graphics g) {
        if (fps == 0) {
            left = right = up = down = false;
        }
        // 繪制一次 fps + 1
        fps++;
        // 飛機(jī)移動(dòng)
        move();
        // 子彈發(fā)射
        attack();
        // 敵方飛機(jī)生成
        generate();
        // 失效對(duì)象銷毀
        remove();
        // 繪制背景
        Data.background.show(g);
        // 繪制我方飛機(jī)
        if(player != null)
            player.draw(g);
        // 繪制BOSS
        if (boss != null) boss.draw(g);
        // 繪制敵方飛機(jī)
        for (Aircraft a : enemy)
            a.draw(g);
        // 繪制我發(fā)子彈
        for (Bullet b : bulletPlayer)
            b.draw(g);
        // 繪制敵方子彈
        for (Bullet b : bulletEnemy)
            b.draw(g);
        // 繪制道具
        for (Bullet d : bulletBuff)
            d.draw(g);

        g.drawString("分?jǐn)?shù) : " + fraction, 200, 200);
        if (boss != null) {
            g.drawImage(Data.hpBox, 10, -10, null);
            g.setColor(Color.orange);
            g.fillRect(106, -2, (int) (300 * ((boss.hp * 1.0) / 300)), 15);
        }
        // 繪制boss出現(xiàn)的圖片
        if (tipsX > -900 && tipsX < 900) {
            g.drawImage(Data.tips, tipsX, 200, null);
        }
    }

    // 管理場景所有的飛機(jī)、子彈、道具移動(dòng)
    void move() {
        if (player != null) {
            // 這里這個(gè)坐標(biāo),是為了讓敵人發(fā)射子彈時(shí)定位用的
            Data.x = player.x;
            Data.y = player.y;
            // 飛機(jī)向上移動(dòng), 這里還限制了飛機(jī)的范圍,不讓其飛出屏幕外
            if (up) player.move(0, -player.speed);
            if (player.y < 0) player.y = 0;
            // 飛機(jī)向下移動(dòng)
            if (down) player.move(0, player.speed);
            if (player.y > Data.HEIGHT - player.height) player.y = Data.HEIGHT - player.height;
            // 飛機(jī)向左移動(dòng)
            if (left) player.move(-player.speed, 0);
            if (player.x < 0) player.x = 0;
            // 飛機(jī)向右移動(dòng)
            if (right) player.move(player.speed, 0);
            if (player.x > Data.WIDTH - player.width) player.x = Data.WIDTH - player.width;
        }
        // boss 移動(dòng)
        if (boss != null) boss.move();
        // 我方子彈的移動(dòng)
        for (Bullet bullet : bulletPlayer)
            bullet.move();
        // 敵方子彈的移動(dòng)
        for (Bullet bullet : bulletEnemy)
            bullet.move();
        // 道具的移動(dòng)
        for (Bullet bullet : bulletBuff)
            bullet.move();
        // 地方飛機(jī)的移動(dòng),包括BOSS
        for (Aircraft air : enemy)
            air.move();
        // BUFF 移動(dòng)
        for (Bullet b : bulletBuff)
            b.move();
    }

    void remove() {
        Random random = new Random();
        // 子彈銷毀
        for (int i = 0; i < bulletEnemy.size(); ) {
            if (bulletEnemy.get(i).isRemove()) {
                bulletEnemy.remove(i);
            } else i++;
        }
        for (int i = 0; i < bulletPlayer.size(); ) {
            if (bulletPlayer.get(i).isRemove()) {
                bulletPlayer.remove(i);
            } else i++;
        }
        for (int i = 0; i < bulletBuff.size(); ) {
            if (bulletBuff.get(i).isRemove()) {
                bulletBuff.remove(i);
            } else i++;
        }
        // 敵人銷毀
        for (int i = 0; i < enemy.size(); ) {
            if (enemy.get(i).isRemove()) {
                // 生成道具
                if (random.nextInt(100) > 80) {
                    if (random.nextInt(100) > 60)
                        bulletBuff.add(new Buff(Buff.BUFF2, enemy.get(i).x, enemy.get(i).y));
                    else
                        bulletBuff.add(new Buff(Buff.BUFF1, enemy.get(i).x, enemy.get(i).y));
                }
                Load.playSound("死亡");
                // 擊殺一個(gè)敵人增加 1 分,不整這么多花里胡哨的
                fraction += 10;
                if (fraction / 100 == checkpoint) {
                    boss = new Boss2();
                    checkpoint += 1;
                    Load.playSound("警告");
                    new Thread(() -> {
                        tipsX = -Data.WIDTH;
                        try {
                            for (int n = 0; n < Data.WIDTH / 2; n++) {
                                tipsX += 2;
                                Thread.sleep(4);
                            }
                            Thread.sleep(2000);
                            for (int n = 0; n < Data.WIDTH / 4; n++) {
                                tipsX += 4;
                                Thread.sleep(4);
                            }
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        tipsX = -1000;
                    }).start();
                }
                enemy.remove(i);
            } else i++;
        }
        // boss銷毀
        if (boss != null) {
            // boss 死亡掉落4個(gè)buff
            if (boss.isRemove()) {
                bulletBuff.add(new Buff(Buff.BUFF2, boss.x + boss.width / 2, boss.y + boss.height / 2));
                bulletBuff.add(new Buff(Buff.BUFF1, boss.x + boss.width / 2, boss.y + boss.height / 2));
                bulletBuff.add(new Buff(Buff.BUFF2, boss.x + boss.width / 2, boss.y + boss.height / 2));
                bulletBuff.add(new Buff(Buff.BUFF1, boss.x + boss.width / 2, boss.y + boss.height / 2));
                boss = null;
            }
        }
        boolean isPlay = false;
        // 檢測我方子彈碰撞
        for (int i = 0; i < bulletPlayer.size(); i++) {
            Point point = bulletPlayer.get(i).getPoint();
            if (bulletPlayer.get(i).buffetIndex > 1) continue;
            // 檢測子彈是否擊中boss
            if (boss != null && boss.hp > 0) {
                Point rect[] = boss.getCollisionRect();
                if (Rect.isInternal(point.x, point.y, rect[0].x, rect[0].y, rect[1].x, rect[1].y)) {
                    boss.hp -= bulletPlayer.get(i).struts;
                    bulletPlayer.get(i).buffetIndex = 1;
                    bulletPlayer.get(i).speed = 5;
                    if (boss.hp <= 0) {
                        boss.imgIndex = 10;
                    }
                    if (!isPlay) {
                        isPlay = true;
                        Load.playSound("擊中");
                    }
                    continue;
                }
            }
            for (Aircraft a : enemy) {
                Point rect[] = a.getCollisionRect();
                if (a.hp < 0) continue;
                if (Rect.isInternal(point.x, point.y, rect[0].x, rect[0].y, rect[1].x, rect[1].y)) {
                    if (!isPlay) {
                        isPlay = true;
                        Load.playSound("擊中");
                    }
                    a.hp -= bulletPlayer.get(i).struts;
                    bulletPlayer.get(i).buffetIndex = 1;
                    bulletPlayer.get(i).speed = 5;
                    if (a.hp < 0) {
                        a.kill();;
                        a.speed = 1;
                    }
                    break;
                }
            }
        }
        Point rect[], point;
        // 檢測敵方子彈碰撞
        if(player != null) {
            rect = player.getCollisionRect();
            if (player != null && player.hp > 0) {
                for (Bullet b : bulletEnemy) {
                    point = b.getPoint();
                    if (Rect.isInternal(point.x, point.y, rect[0].x, rect[0].y, rect[1].x, rect[1].y)) {
                        player.hp -= b.struts;
                        player.kill();
                        death();
                    }
                }
            }
        }
        // 吃BUFF
        if (player != null && player.hp > 0) {
            rect = player.getCollisionRect();
            for (Bullet buff : bulletBuff) {
                Point p = buff.getPoint();
                if (Rect.isInternal(p.x, p.y, rect[0].x, rect[0].y, rect[1].x, rect[1].y)) {
                    buff.x = -100;
                    if (buff.struts == Buff.BUFF1)
                        player.setBuff(16, 0);
                    else
                        player.setBuff(0, 16);
                }
            }
        }
        // 飛機(jī)之間的碰撞
        if(player != null) {
            for (Aircraft air : enemy) {
                int x = air.x + air.width / 2, y = air.y + air.height / 2;

                if(Rect.isInternal(x, y, player.x, player.y, player.width, player.height)) {
                    player.kill();
                    air.kill();
                    Load.playSound("失敗");
                    death();
                }
            }
        }
    }

    // 管理場景所有的子彈的發(fā)射
    void attack() {
        // 我方飛機(jī)3幀發(fā)射一次
        if (player != null && player.hp > 0) {
            if (!player.isRemove() && fps % 3 == 0)
                bulletPlayer.addAll(Arrays.asList(player.attack()));
        }
        // 敵方飛機(jī)發(fā)射子彈
        if (fps % 5 == 0)
            for (Aircraft em : enemy)
                bulletEnemy.addAll(Arrays.asList(em.attack()));
        // boss發(fā)射子彈
        if (boss != null) bulletEnemy.addAll(Arrays.asList(boss.attack()));
    }

    // 生成敵方飛機(jī)
    void generate() {
        // BOSS 存在時(shí)不生成小飛機(jī)
        if (boss != null) return;

        if (fps % 100 != 0 && fps >= 1) return;

        Random random = new Random();
        int rn = random.nextInt(100) + 1;

        int[] hp = {(fps / 2000) + 1 * checkpoint, (fps / 2000) + 2 * checkpoint, (fps / 2000) + 5 * checkpoint, (fps / 2000) + 8 * checkpoint, (fps / 2000) + 11 * checkpoint};

        switch (rn / 10) {
            case 1: {
                enemy.add(new Enemy(Data.enemyAircraftImages[4], Data.enemyDeathImages[4], 2, 90, random.nextInt(300) + 100, -150, hp[4]));
                return;
            }
            case 2: {
                enemy.add(new Enemy(Data.enemyAircraftImages[3], Data.enemyDeathImages[3], 2, 90, 100, -150, hp[3]));
                enemy.add(new Enemy(Data.enemyAircraftImages[3], Data.enemyDeathImages[3], 2, 90, 380, -150, hp[3]));
                return;
            }
            case 3: {
                enemy.add(new Enemy(Data.enemyAircraftImages[2], Data.enemyDeathImages[2], 2, 90, 10, -150, hp[2]));
                enemy.add(new Enemy(Data.enemyAircraftImages[0], Data.enemyDeathImages[0], 2, 90, 240, -150, hp[0]));
                enemy.add(new Enemy(Data.enemyAircraftImages[2], Data.enemyDeathImages[2], 2, 90, 430 + 100, -150, hp[2]));
                return;
            }
            case 4: {
                enemy.add(new Enemy(Data.enemyAircraftImages[2], Data.enemyDeathImages[2], 2, 90, 0, -150, hp[2]));
                enemy.add(new Enemy(Data.enemyAircraftImages[3], Data.enemyDeathImages[3], 2, 90, 130, -150, hp[3]));
                enemy.add(new Enemy(Data.enemyAircraftImages[0], Data.enemyDeathImages[0], 2, 90, 300, -150, hp[0]));
                enemy.add(new Enemy(Data.enemyAircraftImages[1], Data.enemyDeathImages[1], 2, 90, 450, -150, hp[1]));
                return;
            }
            case 5: {
                enemy.add(new Enemy(Data.enemyAircraftImages[0], Data.enemyDeathImages[0], 2, 110, 400, random.nextInt(100) - 200, hp[0]));
                enemy.add(new Enemy(Data.enemyAircraftImages[1], Data.enemyDeathImages[1], 2, 110, 480, random.nextInt(100) - 200, hp[1]));
                enemy.add(new Enemy(Data.enemyAircraftImages[1], Data.enemyDeathImages[1], 2, 110, 560, random.nextInt(100) - 200, hp[1]));
                enemy.add(new Enemy(Data.enemyAircraftImages[1], Data.enemyDeathImages[1], 2, 110, 640, random.nextInt(100) - 200, hp[1]));
                enemy.add(new Enemy(Data.enemyAircraftImages[0], Data.enemyDeathImages[0], 2, 110, 720, random.nextInt(100) - 200, hp[0]));
                return;
            }
            case 6: {
                enemy.add(new Enemy(Data.enemyAircraftImages[1], Data.enemyDeathImages[1], 2, 70, -440, random.nextInt(100) - 200, hp[1]));
                enemy.add(new Enemy(Data.enemyAircraftImages[0], Data.enemyDeathImages[0], 2, 70, -320, random.nextInt(100) - 200, hp[0]));
                enemy.add(new Enemy(Data.enemyAircraftImages[0], Data.enemyDeathImages[0], 2, 70, -240, random.nextInt(100) - 200, hp[0]));
                enemy.add(new Enemy(Data.enemyAircraftImages[0], Data.enemyDeathImages[0], 2, 70, -170, random.nextInt(100) - 200, hp[0]));
                enemy.add(new Enemy(Data.enemyAircraftImages[1], Data.enemyDeathImages[1], 2, 70, -100, random.nextInt(100) - 200, hp[1]));
                return;
            }
            case 7: {
                enemy.add(new Enemy(Data.enemyAircraftImages[1], Data.enemyDeathImages[1], 2, 70, 30, random.nextInt(100) - 200, hp[1]));
                enemy.add(new Enemy(Data.enemyAircraftImages[2], Data.enemyDeathImages[2], 2, 70, 100, random.nextInt(100) - 200, hp[2]));
                enemy.add(new Enemy(Data.enemyAircraftImages[3], Data.enemyDeathImages[3], 2, 70, 200, random.nextInt(100) - 200, hp[3]));
                enemy.add(new Enemy(Data.enemyAircraftImages[2], Data.enemyDeathImages[2], 2, 70, 300, random.nextInt(100) - 200, hp[2]));
                enemy.add(new Enemy(Data.enemyAircraftImages[1], Data.enemyDeathImages[1], 2, 70, 430, random.nextInt(100) - 200, hp[1]));
                return;
            }
            case 8: {
                enemy.add(new Enemy(Data.enemyAircraftImages[1], Data.enemyDeathImages[1], 2, 30, -100, -150, hp[1]));
                enemy.add(new Enemy(Data.enemyAircraftImages[1], Data.enemyDeathImages[1], 2, 90, 240, -150, hp[1]));
                enemy.add(new Enemy(Data.enemyAircraftImages[1], Data.enemyDeathImages[1], 2, 120, 615 + 100, -150, hp[1]));
                return;
            }
            case 9: {
                enemy.add(new Enemy(Data.enemyAircraftImages[4], Data.enemyDeathImages[4], 2, 90, 100 + random.nextInt(100), -150, hp[4]));
                enemy.add(new Enemy(Data.enemyAircraftImages[4], Data.enemyDeathImages[4], 2, 90, 415 - random.nextInt(100), -150, hp[4]));
                return;
            }
            case 10: {
                enemy.add(new Enemy(Data.enemyAircraftImages[2], Data.enemyDeathImages[2], 2, 90, 120 + random.nextInt(100), -150, hp[2]));
                enemy.add(new Enemy(Data.enemyAircraftImages[2], Data.enemyDeathImages[2], 2, 90, 395 - random.nextInt(100), -150, hp[2]));
            }
        }
    }
    void death() {
        new Thread(() ->{
            try {
                player = null;
                Thread.sleep(3000);
                Data.canvas.switchScenes("Home");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
    }
}

核心算法

@SuppressWarnings("serial")
public class GameMenu extends JFrame {

	GameMenu thisMenu;
	private JPanel contentPane;
	TestWindowBuilder fatherMenu;
	boolean isCheating;
	CMusic battleBGM,questCompleteBGM;

	int pressingW;
	int pressingS;
	int pressingA;
	int pressingD;
	int pressingJ;
	int pressingK;
	
	int playingSave;
	int playingProfessionID;
	
	int g_int1;
	
	Role playingRole;
	double playerX;//0-734
	double playerY;//0-312
	int rotationSpeed=15;//旋轉(zhuǎn)速度
	int movementSpeed=3;//移動(dòng)速度
	int NormalSpeed=3;
	int attackSpeed=3;//攻擊速度
	int activeCounter;
	int attackCounter;
	int defenceCounter=0;
	int perfectDefenceTime=0;//完美格擋剩余時(shí)間(在敵人發(fā)動(dòng)攻擊前0.1秒啟動(dòng)的格擋能讓格擋所需體力消耗減少到原來的十分之一)
	int defenceCooldown=0;//格擋冷卻 這樣阻止了玩家瘋狂地啟動(dòng)/停止格擋
	int playerWidth=50;
	int playerHeight=50;
	int gamePhaseTimeCounter=0;
	int gamePhaseTimeCounter2=0;
	int endPhase=6*4;//游戲通關(guān)的階段
	/*第一關(guān) 0
	 * 第二關(guān) 6
	 * */
	int gamePhase=0;//游戲開始時(shí)的階段(正常玩家從第一關(guān)開始打,階段應(yīng)當(dāng)從0開始)
	
	String humanIconContorler;
	
	JPanel viewMap;
	
	//玩家有兩個(gè)Label 一個(gè)在boss上方 一個(gè)在boss下方
	int usingPlayerLabel=0;
	JLabel[] playerLabel=new JLabel[2];
	
	JLabel lblNewLabel_6;
	JLabel lblNewLabel_7;
	JLabel[] GiantBackGround=new JLabel[400];
	JLabel bossLabel;
	JLabel lblNewLabel_2;
	JLabel lblNewLabel_3;
	JLabel lblNewLabel_2B;
	JLabel lblNewLabel_3B;
	JLabel MobHead;
	JLabel MobName;
	JLabel MobHPBar;
	JLabel MobHPText;
	JLabel TitleLabelT;
	JLabel SubTitleLabelT;
	JLabel TitleLabel;
	JLabel SubTitleLabel;
	JPanel Titles;
	JLabel placeNameLabel;
	JLabel groundArrayLabel;
	JLabel placeChangeBlack;//換場地時(shí)的黑幕
	JLabel placeChangeBlack_1;//換場地時(shí)的黑幕(用于屬性條)

	
	int maxProCount=5000;
	JLabel[] proLabel=new JLabel[maxProCount];
	boolean[] proIsUsed=new boolean[maxProCount];
	proLink proHead=new proLink();
	int existProCount;
	
	int maxParCount=5000;
	JLabel[] parLabel=new JLabel[maxParCount];
	boolean[] parIsUsed=new boolean[maxParCount];
	parLink parHead=new parLink();
	int existParCount;
	
	int existPro=0;
	int proTeamPointer=0;//隊(duì)列指針 0-499
	
	int existPar=0;
	int parTeamPointer=0;

	JPanel panel;
	
	Mob boss;
	
	int allPhaseCount=1;
	int gameTime=0;
	
	Map map;
	
	/**
	 * Create the frame.
	 */
	public GameMenu(TestWindowBuilder fatherMenu,boolean isCheating,int professionID,int partID,int playingSave)
	{
		this.setTitle("CARROT MAN II");
		this.setIconImage(new ImageIcon("resource/down4.png").getImage());
		for(int i=0;i<proIsUsed.length;++i)
			proIsUsed[i]=false;
		for(int i=0;i<parIsUsed.length;++i)
			parIsUsed[i]=false;
		playingProfessionID=professionID;
		this.playingSave=playingSave;
		gamePhase=(partID-1)*6;
		this.fatherMenu=fatherMenu;
		this.isCheating=isCheating;
		//this.isCheating=true;//測試用
		g_int1=0;
		playerX=50;
		playerY=200;
		thisMenu=this;
		activeCounter=0;
		attackCounter=0;
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(fatherMenu.getBounds());
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		//轉(zhuǎn)場黑幕 第100層
		placeChangeBlack=new JLabel("");
		placeChangeBlack.setIcon(new ImageIcon("resource/black.png"));
		placeChangeBlack.setVisible(true);
		placeChangeBlack_1=new JLabel("");
		placeChangeBlack_1.setIcon(new ImageIcon("resource/black.png"));
		placeChangeBlack_1.setVisible(true);
		placeChangeBlack.setBounds(0, 0, 784, 362);
		placeChangeBlack_1.setBounds(0, 0, 784, 362);
		//contentPane.add(placeChangeBlack);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBounds(0, 0, 784, 50);
		contentPane.add(panel_1);
		panel_1.setLayout(null);

		panel_1.add(placeChangeBlack_1);
		
		JLabel lblNewLabel = new JLabel("");//頭像
		lblNewLabel.setBounds(0, 0, 50, 50);
		lblNewLabel.setIcon(new ImageIcon("resource/HPBarHead.png"));
		panel_1.add(lblNewLabel);
		
		lblNewLabel_2B = new JLabel("");//血量字
		lblNewLabel_2B.setForeground(Color.WHITE);
		lblNewLabel_2B.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel_2B.setBounds(50, 0, 200, 25);
		panel_1.add(lblNewLabel_2B);
		
		lblNewLabel_3B = new JLabel("");//體力字
		lblNewLabel_3B.setForeground(Color.WHITE);
		lblNewLabel_3B.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel_3B.setBounds(50, 25, 200, 25);
		panel_1.add(lblNewLabel_3B);
		
		lblNewLabel_2 = new JLabel("");//血條
		lblNewLabel_2.setBounds(50, 0, 200, 25);
		lblNewLabel_2.setIcon(new ImageIcon("resource/RedBar.png"));
		panel_1.add(lblNewLabel_2);
		
		lblNewLabel_3 = new JLabel("");//體力條
		lblNewLabel_3.setBounds(50, 25, 200, 25);
		lblNewLabel_3.setIcon(new ImageIcon("resource/GreenBar.png"));
		panel_1.add(lblNewLabel_3);
		
		JLabel lblNewLabel_1 = new JLabel("");//血條體力條背景
		lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel_1.setBounds(50, 0, 200, 50);
		lblNewLabel_1.setIcon(new ImageIcon("resource/HPBarBG.png"));
		panel_1.add(lblNewLabel_1);

		JLabel lblNewLabel_4 = new JLabel("J");
		lblNewLabel_4.setForeground(Color.GRAY);
		lblNewLabel_4.setFont(new Font("黑體", Font.BOLD, 30));
		lblNewLabel_4.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel_4.setBounds(250, 0, 50, 50);
		panel_1.add(lblNewLabel_4);
		
		JLabel lblNewLabel_5 = new JLabel("");
		lblNewLabel_5.setFont(new Font("宋體", Font.PLAIN, 20));
		lblNewLabel_5.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel_5.setBounds(250, 0, 50, 50);
		lblNewLabel_5.setIcon(new ImageIcon("resource/skillJ.png"));
		panel_1.add(lblNewLabel_5);

		JLabel skillKLabel = new JLabel("K");
		skillKLabel.setForeground(Color.GRAY);
		skillKLabel.setFont(new Font("黑體", Font.BOLD, 30));
		skillKLabel.setHorizontalAlignment(SwingConstants.CENTER);
		skillKLabel.setBounds(300, 0, 50, 50);
		panel_1.add(skillKLabel);
		
		JLabel skillKLabel2 = new JLabel("");
		skillKLabel2.setFont(new Font("宋體", Font.PLAIN, 20));
		skillKLabel2.setHorizontalAlignment(SwingConstants.CENTER);
		skillKLabel2.setBounds(300, 0, 50, 50);
		skillKLabel2.setIcon(new ImageIcon("resource/skillK.png"));
		panel_1.add(skillKLabel2);
		
		placeNameLabel = new JLabel("");
		placeNameLabel.setFont(new Font("宋體", Font.PLAIN, 30));
		placeNameLabel.setHorizontalAlignment(SwingConstants.CENTER);
		placeNameLabel.setBounds(350, 0, 200, 50);
		panel_1.add(placeNameLabel);
		
		JLabel placeNameLabel2 = new JLabel("");
		placeNameLabel2.setHorizontalAlignment(SwingConstants.CENTER);
		placeNameLabel2.setBounds(350, 0, 200, 50);
		placeNameLabel2.setIcon(new ImageIcon("resource/placeNameBackGround.png"));
		panel_1.add(placeNameLabel2);
		
		MobHead = new JLabel("");
		MobHead.setHorizontalAlignment(SwingConstants.CENTER);
		MobHead.setBounds(550, 0, 50, 50);
		MobHead.setIcon(new ImageIcon("resource/MobHead_0.png"));
		panel_1.add(MobHead);
		
		MobName = new JLabel("");
		MobName.setHorizontalAlignment(SwingConstants.CENTER);
		MobName.setBounds(600, 0, 184, 25);
		panel_1.add(MobName);
		
		MobHPText = new JLabel("");
		MobHPText.setForeground(Color.WHITE);
		MobHPText.setHorizontalAlignment(SwingConstants.CENTER);
		MobHPText.setBounds(600, 25, 184, 25);
		panel_1.add(MobHPText);
		
		MobHPBar = new JLabel("");
		MobHPBar.setHorizontalAlignment(SwingConstants.CENTER);
		MobHPBar.setBounds(600, 25, 184, 25);
		MobHPBar.setIcon(new ImageIcon("resource/RedBar.png"));
		panel_1.add(MobHPBar);
		
		JLabel MobNameBG = new JLabel("");
		MobNameBG.setHorizontalAlignment(SwingConstants.CENTER);
		MobNameBG.setBounds(600, 0, 184, 50);
		MobNameBG.setIcon(new ImageIcon("resource/MobNameBG.png"));
		panel_1.add(MobNameBG);	
		
		panel = new JPanel();
		panel.setBounds(0, 50, 784, 362);
		contentPane.add(panel);
		viewMap=panel;
		panel.setLayout(null);

		panel.add(placeChangeBlack);
		
		lblNewLabel_7 = new JLabel("");//玩家tryingFace指示器(暫時(shí)停用)
		lblNewLabel_7.setBounds((int)playerX, (int)playerY, 5, 5);
		lblNewLabel_7.setIcon(new ImageIcon("resource/moveDeraction2.png"));
		lblNewLabel_7.setVisible(false);
		panel.add(lblNewLabel_7);
		
		
		//第99層
		//標(biāo)題
		TitleLabelT = new JLabel("");
		TitleLabelT.setFont(new Font("黑體", Font.PLAIN, 45));
		TitleLabelT.setHorizontalAlignment(SwingConstants.CENTER);
		TitleLabelT.setBounds(100, 50, 584, 50);
		TitleLabelT.setVisible(true);
		panel.add(TitleLabelT);
		//副標(biāo)題
		SubTitleLabelT = new JLabel("");
		SubTitleLabelT.setFont(new Font("黑體", Font.PLAIN, 25));
		SubTitleLabelT.setHorizontalAlignment(SwingConstants.CENTER);
		SubTitleLabelT.setBounds(100, 100, 584, 50);
		SubTitleLabelT.setVisible(true);
		panel.add(SubTitleLabelT);
		
		//預(yù)先創(chuàng)建粒子效果的Label,第6層
		for(int i=0;i<maxParCount;++i)
		{
			parLabel[i]=new JLabel("");
			panel.add(parLabel[i]);
		}
		
		//boss上方的玩家,第5層
		playerLabel[1]=new JLabel("");
		playerLabel[1].setHorizontalAlignment(SwingConstants.CENTER);
		playerLabel[1].setBounds((int)playerX-playerWidth/2, (int)playerY-playerHeight/2, playerHeight, playerWidth);
		playerLabel[1].setIcon(new ImageIcon("resource/HumanRight_0.png"));
		playerLabel[1].setVisible(false);
		panel.add(playerLabel[1]);
		
		//bossLabel,第4.5層
		bossLabel = new JLabel("");
		panel.add(bossLabel);

		//boss下方的玩家,第4層
		playerLabel[0]=new JLabel("");
		playerLabel[0].setHorizontalAlignment(SwingConstants.CENTER);
		playerLabel[0].setBounds((int)playerX-playerWidth/2, (int)playerY-playerHeight/2, playerHeight, playerWidth);
		playerLabel[0].setIcon(new ImageIcon("resource/HumanRight_0.png"));
		playerLabel[0].setVisible(true);
		panel.add(playerLabel[0]);
		
		//玩家面向方向指示器,第3層
		lblNewLabel_6 = new JLabel("");
		lblNewLabel_6.setBounds((int)playerX, (int)playerY, 5, 5);
		lblNewLabel_6.setIcon(new ImageIcon("resource/moveDeraction.png"));
		panel.add(lblNewLabel_6);
		
		//預(yù)先創(chuàng)建發(fā)射物的Label,第2層
		for(int i=0;i<maxProCount;++i)
		{
			proLabel[i]=new JLabel("");
			panel.add(proLabel[i]);
		}
		
		//創(chuàng)建地面箭頭,第1.5層
		groundArrayLabel=new JLabel("");
		groundArrayLabel.setBounds(709,156, 50, 50);
		groundArrayLabel.setIcon(new ImageIcon("resource/groundArray.png"));
		groundArrayLabel.setVisible(false);
		panel.add(groundArrayLabel);
		
		//創(chuàng)建地面Label,第1層
		for(int i=0;i<400;++i)
		{
			GiantBackGround[i]=new JLabel("");
			GiantBackGround[i].setVisible(true);
			panel.add(GiantBackGround[i]);
		}	
		
		playingRole=new Role(professionID,thisMenu);
		
		KeyLininter kl=new KeyLininter(thisMenu);
        this.addKeyListener(kl);
		
		map=new Map(thisMenu);
		map.start();		
	}
	
	//發(fā)射物相關(guān)
	public int addProjectile(Projectile pro)
	{
		existProCount=proHead.getLength();
		if(existProCount<maxProCount)
		{
			proHead.insert(new proLink(pro));
			int tempFinder=0;
			for(int i=0;i<maxProCount;++i)
			{
				if(proIsUsed[i]==false)
				{
					proIsUsed[i]=true;
					tempFinder=i;
					break;
				}
			}
			return tempFinder;
		}
		return -1;
	}
	public void removeProjectile(int id)
	{
		proLabel[id].setVisible(false);
		proIsUsed[id]=false;
	}
	public void allProjectilesFly()
	{
		proLink tempNode=proHead;
		while(tempNode.next!=null)
		{
			tempNode=tempNode.next;
			tempNode.data.doFly();
		}
	}
	//發(fā)射物相關(guān)結(jié)束
	
	//粒子效果相關(guān)
	public int addParticle(particle par)
	{
		existParCount=parHead.getLength();
		if(existParCount<maxParCount)
		{
			parHead.insert(new parLink(par));
			int tempFinder=0;
			for(int i=0;i<maxParCount;++i)
			{
				if(parIsUsed[i]==false)
				{
					parIsUsed[i]=true;
					tempFinder=i;
					break;
				}
			}
			return tempFinder;
		}
		return -1;
	}
	public void removeParticle(int id)
	{
		parLabel[id].setVisible(false);
		parIsUsed[id]=false;
	}
	public void allParticlesFly()
	{
		parLink tempNode=parHead;
		while(tempNode.next!=null)
		{
			tempNode=tempNode.next;
			tempNode.data.doFly();
		}
	}
	public void checkPlayerLocation()//檢測玩家位置 如果超出地圖 則拉回地圖
	{
		if(playerX<playerWidth/2)
			playerX=playerWidth/2;
		if(playerX>784-playerWidth/2)
			playerX=784-playerWidth/2;
		if(playerY<playerHeight/2)
			playerY=playerHeight/2;
		if(playerY>362-playerHeight/2)
			playerY=362-playerHeight/2;	
	}
	
	@SuppressWarnings("unused")
	public void saveData(int part)
	{
		if(Integer.parseInt(fatherMenu.saveSelectMenu.savedData[playingSave].split(" ")[1])<part)
		{
			String[] temp= {
					fatherMenu.saveSelectMenu.savedData[playingSave].split(" ")[0],
					fatherMenu.saveSelectMenu.savedData[playingSave].split(" ")[1]
			};
			fatherMenu.saveSelectMenu.savedData[playingSave]=""+playingProfessionID+" "+part;
			fatherMenu.saveSelectMenu.saveSaves();
		}
	}
	
	@SuppressWarnings({ "deprecation" })
	public void modTick()//每秒執(zhí)行50次
	{
		if(attackCounter==0&&defenceCounter==0)
			playingRole.regenerate();
		if(playingRole.HP>0)
		{
			//刷新體力條
			lblNewLabel_3.setBounds(50, 25, (int) (200*playingRole.energy/playingRole.MaxEnergy), 25);
			lblNewLabel_3B.setText(""+(int)playingRole.energy+"/"+(int)playingRole.MaxEnergy);
			//刷新血條
			lblNewLabel_2.setBounds(50, 0, (int) (200*playingRole.HP/playingRole.MaxHP), 25);
			lblNewLabel_2B.setText(""+(int)playingRole.HP+"/"+(int)playingRole.MaxHP);			
		}
		else if(gamePhase!=-1)
		{
			boss.target=null;
			gamePhaseTimeCounter=0;
			gamePhase=-1;
			movementSpeed=0;
			TitleLabelT.setText("YOU DIED");
			TitleLabelT.setVisible(true);
			playerLabel[usingPlayerLabel].setVisible(false);
			lblNewLabel_6.setVisible(false);
			lblNewLabel_3.setBounds(50, 25, (int) (200*playingRole.energy/playingRole.MaxEnergy), 25);
			lblNewLabel_3B.setText(""+(int)playingRole.energy+"/"+(int)playingRole.MaxEnergy);
			lblNewLabel_2.setBounds(50, 0, (int) (200*playingRole.HP/playingRole.MaxHP), 25);
			lblNewLabel_2B.setText(""+(int)playingRole.HP+"/"+(int)playingRole.MaxHP);		
		}
		
		
		
		++gameTime;
		allProjectilesFly();
		allParticlesFly();
		if(gamePhase==0)
		{
			if(gamePhaseTimeCounter<50)
				gamePhaseTimeCounter=50;
			++gamePhaseTimeCounter;
			if(gamePhaseTimeCounter==51)
			{
				System.out.println("啟動(dòng)控制臺(tái)...");
				movementSpeed=0;
				placeChangeBlack.setBounds(0, 0, 784, 362);
				placeChangeBlack_1.setBounds(0, 0, 784, 362);
				placeChangeBlack.setVisible(true);
				placeChangeBlack_1.setVisible(true);
				TitleLabelT.setVisible(false);
				SubTitleLabelT.setVisible(false);
				groundArrayLabel.setVisible(false);
				for(int i=0;i<128;++i)//初始化第一關(guān)地面
				{
					String backGroundContorler="resource/ground";
					GiantBackGround[i].setBounds(50*(i%16),50*(int)(i/16), 50, 50);
					if(Math.random()<0.9)
						backGroundContorler=backGroundContorler+"1.png";
					else
						backGroundContorler=backGroundContorler+"2.png";
					GiantBackGround[i].setIcon(new ImageIcon(backGroundContorler));
				}
				playerX=50;
				playerY=200;
				placeNameLabel.setText(fatherMenu.textLib.textData[13]);
				TitleLabelT.setText(fatherMenu.textLib.textData[13]);
				TitleLabelT.setVisible(true);
				SubTitleLabelT.setText(fatherMenu.textLib.textData[37]);
				SubTitleLabelT.setVisible(true);
			}
			if(gamePhaseTimeCounter>=100&&gamePhaseTimeCounter<=150)
			{
				placeChangeBlack.setBounds((int)((gamePhaseTimeCounter-100)*0.02*784), 0, 784, 362);
				placeChangeBlack_1.setBounds((int)((gamePhaseTimeCounter-100)*0.02*784), 0, 784, 362);
			}
			if(gamePhaseTimeCounter==151)
			{
				startNewBattleBGM(1);
				placeChangeBlack.setVisible(false);
				placeChangeBlack_1.setVisible(false);
				gamePhaseTimeCounter=0;
				++gamePhase;
			}
		}
		if(gamePhase%6==1)
		{
			++gamePhaseTimeCounter;
			if(gamePhaseTimeCounter>=200)
			{
				++gamePhase;
				TitleLabelT.setVisible(false);
				SubTitleLabelT.setVisible(false);
				movementSpeed=NormalSpeed;
			}
		}
		if(gamePhase==2)
		{
			gamePhaseTimeCounter=0;
			boss=new Mob(1,bossLabel,thisMenu);
			boss.reflash();
			bossLabel.setVisible(true);
			++gamePhase;
		}
		if(gamePhase==3)
		{
			if(boss.HP>0)
				boss.reflash();
			else
			{
				bossLabel.setVisible(false);
				MobHPBar.setBounds(600, 25, 184*boss.HP/boss.MaxHP, 25);
				MobHPText.setText(""+boss.HP+"/"+boss.MaxHP);
				++gamePhase;
				gamePhaseTimeCounter=0;
				TitleLabelT.setText(fatherMenu.textLib.textData[38]);
				TitleLabelT.setVisible(true);
				SubTitleLabelT.setText(fatherMenu.textLib.textData[39]);
				SubTitleLabelT.setVisible(true);
				saveData(2);
				startQuestCompleteBGM();
				endBattleBGM();
			}
		}
		if(gamePhase%6==4)
		{
			playingRole.percentReHP(0.005);
			++gamePhaseTimeCounter;
			if(gamePhaseTimeCounter>200)
			{
				gamePhaseTimeCounter=0;
				++gamePhase;
				TitleLabelT.setText(fatherMenu.textLib.textData[40]);
				TitleLabelT.setVisible(true);
				SubTitleLabelT.setText(fatherMenu.textLib.textData[41]);
				SubTitleLabelT.setVisible(true);
				gamePhaseTimeCounter2=0;
			}
		}
		if(gamePhase%6==5)
		{
			++gamePhaseTimeCounter;
			if(gamePhaseTimeCounter2==0)
			{
				if(gamePhaseTimeCounter>50)
				{
					groundArrayLabel.setVisible(true);
					if(playerX>709&&playerX<759&&playerY>156&&playerY<206)//進(jìn)入箭頭
					{
						gamePhaseTimeCounter=0;
						gamePhaseTimeCounter2=1;
						movementSpeed=0;
						placeChangeBlack.setBounds(-784,0,784,362);
						placeChangeBlack.setVisible(true);
						placeChangeBlack_1.setBounds(-784,0,784,362);
						placeChangeBlack_1.setVisible(true);
					}
				}
			}
			if(gamePhaseTimeCounter2==1)
			{
				if(gamePhaseTimeCounter>=0&&gamePhaseTimeCounter<=50)
				{
					placeChangeBlack.setBounds((int)(gamePhaseTimeCounter*0.02*784-784), 0, 784, 362);
					placeChangeBlack_1.setBounds((int)(gamePhaseTimeCounter*0.02*784-784), 0, 784, 362);
				}
				if(gamePhaseTimeCounter==51)
				{
					++gamePhase;
					gamePhaseTimeCounter=0;
				}
			}
		}
		if(gamePhase==6)
		{
			movementSpeed=0;
			if(gamePhaseTimeCounter<50)
				gamePhaseTimeCounter=50;
			++gamePhaseTimeCounter;
			if(gamePhaseTimeCounter==51)
			{
				placeChangeBlack.setBounds(0, 0, 784, 362);
				placeChangeBlack.setVisible(true);
				placeChangeBlack_1.setBounds(0, 0, 784, 362);
				placeChangeBlack_1.setVisible(true);
				TitleLabelT.setVisible(false);
				SubTitleLabelT.setVisible(false);
				groundArrayLabel.setVisible(false);
				for(int i=0;i<325;++i)
				{
					GiantBackGround[i].setBounds(32*(i%25),32*(int)(i/25), 32, 32);
					GiantBackGround[i].setIcon(new ImageIcon("resource/ground6.png"));
				}
				playerX=50;
				playerY=200;
				placeNameLabel.setText(fatherMenu.textLib.textData[14]);
				TitleLabelT.setText(fatherMenu.textLib.textData[14]);
				TitleLabelT.setVisible(true);
				SubTitleLabelT.setText(fatherMenu.textLib.textData[42]);
				SubTitleLabelT.setVisible(true);
			}
			if(gamePhaseTimeCounter>=100&&gamePhaseTimeCounter<=150)
			{
				placeChangeBlack.setBounds((int)((gamePhaseTimeCounter-100)*0.02*784), 0, 784, 362);
				placeChangeBlack_1.setBounds((int)((gamePhaseTimeCounter-100)*0.02*784), 0, 784, 362);
			}
			if(gamePhaseTimeCounter==151)
			{
				startNewBattleBGM(2);
				placeChangeBlack.setVisible(false);
				placeChangeBlack_1.setVisible(false);
				gamePhaseTimeCounter=0;
				++gamePhase;
			}
		}
		if(gamePhase==8)
		{
			gamePhaseTimeCounter=0;
			boss=new Mob(2,bossLabel,thisMenu);
			bossLabel.setBounds(375, 175, 100, 100);
			boss.reflash();
			bossLabel.setVisible(true);
			++gamePhase;
		}
		if(gamePhase==9)
		{
			if(boss.HP>0)
				boss.reflash();
			else
			{
				bossLabel.setVisible(false);
				MobHPBar.setBounds(600, 25, 184*boss.HP/boss.MaxHP, 25);
				MobHPText.setText(""+boss.HP+"/"+boss.MaxHP);
				++gamePhase;
				gamePhaseTimeCounter=0;
				TitleLabelT.setText(fatherMenu.textLib.textData[43]);
				TitleLabelT.setVisible(true);
				SubTitleLabelT.setText(fatherMenu.textLib.textData[39]);
				SubTitleLabelT.setVisible(true);
				saveData(3);
				startQuestCompleteBGM();
				endBattleBGM();
			}
		}
		if(gamePhase==12)
		{
			movementSpeed=0;
			if(gamePhaseTimeCounter<50)
				gamePhaseTimeCounter=50;
			++gamePhaseTimeCounter;
			if(gamePhaseTimeCounter==51)
			{
				placeChangeBlack.setBounds(0, 0, 784, 362);
				placeChangeBlack.setVisible(true);
				placeChangeBlack_1.setBounds(0, 0, 784, 362);
				placeChangeBlack_1.setVisible(true);
				TitleLabelT.setVisible(false);
				SubTitleLabelT.setVisible(false);
				groundArrayLabel.setVisible(false);
				for(int i=0;i<325;++i)
				{
					GiantBackGround[i].setBounds(32*(i%25),32*(int)(i/25), 32, 32);
					GiantBackGround[i].setIcon(new ImageIcon("resource/ground7.png"));
				}
				playerX=50;
				playerY=200;
				placeNameLabel.setText(fatherMenu.textLib.textData[15]);
				TitleLabelT.setText(fatherMenu.textLib.textData[15]);
				TitleLabelT.setVisible(true);
				SubTitleLabelT.setText(fatherMenu.textLib.textData[44]);
				SubTitleLabelT.setVisible(true);
			}
			if(gamePhaseTimeCounter>=100&&gamePhaseTimeCounter<=150)
			{
				placeChangeBlack.setBounds((int)((gamePhaseTimeCounter-100)*0.02*784), 0, 784, 362);
				placeChangeBlack_1.setBounds((int)((gamePhaseTimeCounter-100)*0.02*784), 0, 784, 362);
			}
			if(gamePhaseTimeCounter==151)
			{
				startNewBattleBGM(3);
				placeChangeBlack.setVisible(false);
				placeChangeBlack_1.setVisible(false);
				gamePhaseTimeCounter=0;
				++gamePhase;
			}
		}
		if(gamePhase==14)
		{
			gamePhaseTimeCounter=0;
			boss=new Mob(3,bossLabel,thisMenu);
			bossLabel.setBounds(375, 175, 100, 100);
			boss.reflash();
			bossLabel.setVisible(true);
			++gamePhase;
		}
		if(gamePhase==15)
		{
			if(boss.HP>0)
				boss.reflash();
			else
			{
				bossLabel.setVisible(false);
				MobHPBar.setBounds(600, 25, 184*boss.HP/boss.MaxHP, 25);
				MobHPText.setText(""+boss.HP+"/"+boss.MaxHP);
				++gamePhase;
				gamePhaseTimeCounter=0;
				TitleLabelT.setText(fatherMenu.textLib.textData[45]);
				TitleLabelT.setVisible(true);
				SubTitleLabelT.setText(fatherMenu.textLib.textData[39]);
				SubTitleLabelT.setVisible(true);
				saveData(4);
				startQuestCompleteBGM();
				endBattleBGM();
			}
		}
		if(gamePhase==18)
		{
			movementSpeed=0;
			if(gamePhaseTimeCounter<50)
				gamePhaseTimeCounter=50;
			++gamePhaseTimeCounter;
			if(gamePhaseTimeCounter==51)
			{
				placeChangeBlack.setBounds(0, 0, 784, 362);
				placeChangeBlack.setVisible(true);
				placeChangeBlack_1.setBounds(0, 0, 784, 362);
				placeChangeBlack_1.setVisible(true);
				TitleLabelT.setVisible(false);
				SubTitleLabelT.setVisible(false);
				groundArrayLabel.setVisible(false);
				//需要修改開始
				for(int i=0;i<325;++i)
				{
					GiantBackGround[i].setBounds(32*(i%25),32*(int)(i/25), 32, 32);
					GiantBackGround[i].setIcon(new ImageIcon("resource/ground8.png"));
				}
				//需要修改結(jié)束
				playerX=50;
				playerY=200;
				//需要修改開始
				placeNameLabel.setText(fatherMenu.textLib.textData[70]);
				TitleLabelT.setText(fatherMenu.textLib.textData[70]);
				TitleLabelT.setForeground(Color.LIGHT_GRAY);
				TitleLabelT.setVisible(true);
				SubTitleLabelT.setText(fatherMenu.textLib.textData[71]);
				SubTitleLabelT.setForeground(Color.LIGHT_GRAY);
				//需要修改結(jié)束
				SubTitleLabelT.setVisible(true);
			}
			if(gamePhaseTimeCounter>=100&&gamePhaseTimeCounter<=150)
			{
				placeChangeBlack.setBounds((int)((gamePhaseTimeCounter-100)*0.02*784), 0, 784, 362);
				placeChangeBlack_1.setBounds((int)((gamePhaseTimeCounter-100)*0.02*784), 0, 784, 362);
			}
			if(gamePhaseTimeCounter==151)
			{
				startNewBattleBGM(4);//需要修改
				placeChangeBlack.setVisible(false);
				placeChangeBlack_1.setVisible(false);
				gamePhaseTimeCounter=0;
				++gamePhase;
			}
		}
		if(gamePhase==20)
		{
			gamePhaseTimeCounter=0;
			boss=new Mob(4,bossLabel,thisMenu);//需要修改
			bossLabel.setBounds(375, 175, 100, 100);//需要修改
			boss.reflash();
			bossLabel.setVisible(true);
			++gamePhase;
		}
		if(gamePhase==21)
		{
			if(boss.HP>0)
				boss.reflash();
			else
			{
				bossLabel.setVisible(false);
				MobHPBar.setBounds(600, 25, 184*boss.HP/boss.MaxHP, 25);
				MobHPText.setText(""+boss.HP+"/"+boss.MaxHP);
				++gamePhase;
				gamePhaseTimeCounter=0;
				//需要修改開始
				TitleLabelT.setText(fatherMenu.textLib.textData[72]);
				TitleLabelT.setForeground(Color.LIGHT_GRAY);
				TitleLabelT.setVisible(true);
				SubTitleLabelT.setText(fatherMenu.textLib.textData[39]);
				TitleLabelT.setForeground(Color.LIGHT_GRAY);
				SubTitleLabelT.setVisible(true);
				//saveData(4);
				//需要修改完成
				startQuestCompleteBGM();
				endBattleBGM();
			}
		}
		if(gamePhase==endPhase)
		{
			endBattleBGM();
			winMenu WM=new winMenu(thisMenu);
			WM.setVisible(true);
			thisMenu.setVisible(false);
			map.stop();
		}
		if(gamePhase==-1)
		{
			if(boss.HP>0)
				boss.reflash();
			++gamePhaseTimeCounter;
			if(gamePhaseTimeCounter>250)
			{
				endBattleBGM();
				loseMenu LM=new loseMenu(thisMenu);
				LM.setVisible(true);
				thisMenu.setVisible(false);
				map.stop();
			}
		}
		
		//刷新bossBar
		if(boss!=null&&gamePhase%6==3)
		{
			MobHead.setIcon(new ImageIcon("resource/MobHead_"+boss.MobId+".png"));
			MobName.setText(""+boss.Name);
			MobHPBar.setBounds(600, 25, 184*boss.HP/boss.MaxHP, 25);
			MobHPText.setText(""+boss.HP+"/"+boss.MaxHP);
		}
		
		//玩家試圖面向方向
		if(attackCounter==0&&defenceCounter==0)
		{
			if(pressingD==1&&pressingW==0&&pressingS==0)
			{
				playingRole.tryingFace=0;
			}
			else if(pressingD==1&&pressingW==1)
			{
				playingRole.tryingFace=45;
			}
			else if(pressingW==1&&pressingA==0&&pressingD==0)
			{
				playingRole.tryingFace=90;
			}
			else if(pressingW==1&&pressingA==1)
			{
				playingRole.tryingFace=135;
			}
			else if(pressingA==1&&pressingW==0&&pressingS==0)
			{
				playingRole.tryingFace=180;
			}
			else if(pressingA==1&&pressingS==1)
			{
				playingRole.tryingFace=225;
			}
			else if(pressingS==1&&pressingA==0&&pressingD==0)
			{
				playingRole.tryingFace=270;
			}
			else if(pressingS==1&&pressingD==1)
			{
				playingRole.tryingFace=315;
			}
		}
		
		playingRole.setFace();
		humanIconContorler="resource/human_"+playingRole.face;
		
		if(attackCounter==0&&defenceCounter==0&&(pressingW==1||pressingS==1||pressingA==1||pressingD==1))//進(jìn)行轉(zhuǎn)向
		{
			double d_angle=(playingRole.facingAngle-playingRole.tryingFace+360)%360;//0-180為順時(shí)針
			if(d_angle<=rotationSpeed||d_angle>=360-rotationSpeed)//旋轉(zhuǎn)功能
			{
				playingRole.facingAngle=playingRole.tryingFace;
			}
			else
			{
				if(d_angle>0&&d_angle<=180)
				{
					playingRole.facingAngle-=rotationSpeed;
				}
				else
				{
					playingRole.facingAngle+=rotationSpeed;
				}
			}
		}
		
		
		
		if(attackCounter==0&&defenceCounter==0&&(pressingW==1||pressingS==1||pressingA==1||pressingD==1))//進(jìn)行移動(dòng)
		{
			++activeCounter;
			playerX+=(int)(movementSpeed*Math.cos(playingRole.facingAngle*Math.PI/180));
			playerY-=(int)(movementSpeed*Math.sin(playingRole.facingAngle*Math.PI/180));
			checkPlayerLocation();
			if(activeCounter>=10)//10Tick一次 切換移動(dòng)圖片
			{
				activeCounter=0;
				playingRole.lastMoveActive=(playingRole.lastMoveActive+1)%4;
			}
			if(playingRole.lastMoveActive==2)
				humanIconContorler=humanIconContorler+'_'+0;
			else if(playingRole.lastMoveActive==3)
				humanIconContorler=humanIconContorler+'_'+2;
			else
				humanIconContorler=humanIconContorler+'_'+playingRole.lastMoveActive;
		}
		
		if(pressingJ==1&&attackCounter==0&&defenceCounter==0&&playingRole.HP>0)//發(fā)動(dòng)攻擊
		{
			attackCounter=1;
		}
		
		if(attackCounter>0&&attackCounter<=8*attackSpeed)//正在攻擊
		{
			++attackCounter;
			if(attackCounter>0&&attackCounter<=attackSpeed)
			{
				humanIconContorler=humanIconContorler+'_'+3;
			}
			else if(attackCounter<=2*attackSpeed)
			{
				humanIconContorler=humanIconContorler+'_'+4;
			}
			else if(attackCounter<=3*attackSpeed)
			{
				humanIconContorler=humanIconContorler+'_'+5;
			}
			else if(attackCounter<=4*attackSpeed)
			{
				humanIconContorler=humanIconContorler+'_'+6;
			}
			else if(attackCounter<=5*attackSpeed)
			{
				humanIconContorler=humanIconContorler+'_'+7;
			}
			else if(attackCounter<=6*attackSpeed)
			{
				humanIconContorler=humanIconContorler+'_'+8;
			}
			else if(attackCounter<=7*attackSpeed)
			{
				humanIconContorler=humanIconContorler+'_'+9;
			}
		}

		if(attackCounter==3*attackSpeed)//完成攻擊
		{
			playingRole.costEnergy(10);
			fatherMenu.startNewSound("sweep"+Calculator.randomInt(1,3)+".wav",false,1);
			playingRole.doAttack();
		}
		if(attackCounter>8*attackSpeed)//結(jié)束硬直
		{
			attackCounter=0;
		}
		
		
		if(defenceCooldown>0)
		{
			--defenceCooldown;
		}
		if(perfectDefenceTime>0)
		{
			--perfectDefenceTime;
		}
		if(pressingK==1&&attackCounter==0&&defenceCounter==0&&defenceCooldown==0)//發(fā)動(dòng)防御
		{
			perfectDefenceTime=5;
			defenceCounter=1;
			playingRole.defenceStance=true;
			playingRole.isBlocked=false;
		}
		if(defenceCounter==1)
		{
			if(pressingK==0)//解除格擋
			{
				defenceCounter=0;
				playingRole.defenceStance=false;
				if(playingRole.isBlocked==true)
					defenceCooldown=0;
				else
					defenceCooldown=30;
			}
			else
			{
				humanIconContorler=humanIconContorler+'_'+10;
			}
		}
		
		humanIconContorler=humanIconContorler+".png";
		if(boss!=null&&playingRole.HP>0)
		{
			if(playerY>=boss.bossY&&usingPlayerLabel==0)//玩家應(yīng)當(dāng)蓋住boss,但是卻沒蓋住
			{
				usingPlayerLabel=1;
				playerLabel[0].setBounds((int)playerX-playerWidth/2, (int)playerY-playerHeight/2, playerWidth, playerHeight);
				playerLabel[1].setBounds((int)playerX-playerWidth/2, (int)playerY-playerHeight/2, playerWidth, playerHeight);
				playerLabel[0].setVisible(false);
				playerLabel[1].setVisible(true);
			}
			if(playerY<boss.bossY&&usingPlayerLabel==1)//boss應(yīng)當(dāng)蓋住玩家,但是卻沒蓋住
			{
				usingPlayerLabel=0;
				playerLabel[0].setBounds((int)playerX-playerWidth/2, (int)playerY-playerHeight/2, playerWidth, playerHeight);
				playerLabel[1].setBounds((int)playerX-playerWidth/2, (int)playerY-playerHeight/2, playerWidth, playerHeight);
				playerLabel[0].setVisible(true);
				playerLabel[1].setVisible(false);
			}
		}
		playerLabel[usingPlayerLabel].setIcon(new ImageIcon(humanIconContorler));
		playerLabel[usingPlayerLabel].setBounds((int)playerX-playerWidth/2, (int)playerY-playerHeight/2, playerWidth, playerHeight);
		lblNewLabel_6.setBounds((int)playerX+(int)(25*Math.cos(playingRole.facingAngle*Math.PI/180))-2, (int)playerY-(int)(25*Math.sin(playingRole.facingAngle*Math.PI/180))-2, 4,4);
		lblNewLabel_7.setBounds((int)playerX+(int)(25*Math.cos(playingRole.tryingFace*Math.PI/180))-2, (int)playerY-(int)(25*Math.sin(playingRole.tryingFace*Math.PI/180))-2, 4,4);
	}
	
	public void startNewBattleBGM(int bossID)
	{
		if(fatherMenu.settingLib.settings[1].equals("1"))
		{
			if(battleBGM!=null)
				battleBGM.endMusic();
			battleBGM=new CMusic("boss"+bossID+".wav",true,1);
			battleBGM.start();
		}
	}
	
	public void endBattleBGM()
	{
		if(battleBGM!=null)
			battleBGM.endMusic();
	}
	
	public void startQuestCompleteBGM()
	{
		if(questCompleteBGM!=null)
			questCompleteBGM.endMusic();
		questCompleteBGM=new CMusic("QuestComplete.wav",false,1);
		questCompleteBGM.start();
	}
	
}

總結(jié)

通過此次的《飛機(jī)大戰(zhàn)-I》游戲?qū)崿F(xiàn),讓我對(duì)swing的相關(guān)知識(shí)有了進(jìn)一步的了解,對(duì)java這門語言也有了比以前更深刻的認(rèn)識(shí)。

java的一些基本語法,比如數(shù)據(jù)類型、運(yùn)算符、程序流程控制和數(shù)組等,理解更加透徹。java最核心的核心就是面向?qū)ο笏枷?,?duì)于這一個(gè)概念,終于悟到了一些。

以上就是Java實(shí)現(xiàn)經(jīng)典游戲飛機(jī)大戰(zhàn)-I的示例代碼的詳細(xì)內(nèi)容,更多關(guān)于Java飛機(jī)大戰(zhàn)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • spring源碼閱讀--@Transactional實(shí)現(xiàn)原理講解

    spring源碼閱讀--@Transactional實(shí)現(xiàn)原理講解

    這篇文章主要介紹了spring源碼閱讀--@Transactional實(shí)現(xiàn)原理講解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-09-09
  • Java中獲取年份月份的幾種常見方法

    Java中獲取年份月份的幾種常見方法

    這篇文章主要給大家介紹了關(guān)于Java中獲取年份月份的幾種常見方法,在開發(fā)應(yīng)用程序時(shí),經(jīng)常需要獲取當(dāng)前的年、月、日,并以特定格式進(jìn)行展示或處理,需要的朋友可以參考下
    2023-09-09
  • Java四舍五入時(shí)保留指定小數(shù)位數(shù)的五種方式

    Java四舍五入時(shí)保留指定小數(shù)位數(shù)的五種方式

    這篇文章主要介紹了Java四舍五入時(shí)保留指定小數(shù)位數(shù)的五種方式,幫助大家更好的理解和使用Java,感興趣的朋友可以了解下
    2020-09-09
  • 詳解Java中的時(shí)區(qū)類TimeZone的用法

    詳解Java中的時(shí)區(qū)類TimeZone的用法

    TimeZone可以用來獲取或者規(guī)定時(shí)區(qū),也可以用來計(jì)算時(shí)差,這里我們就來詳解Java中的時(shí)區(qū)類TimeZone的用法,特別要注意下面所提到的TimeZone相關(guān)的時(shí)間校準(zhǔn)問題.
    2016-06-06
  • Java零基礎(chǔ)入門數(shù)組

    Java零基礎(chǔ)入門數(shù)組

    數(shù)組對(duì)于每一門編程語言來說都是重要的數(shù)據(jù)結(jié)構(gòu)之一,當(dāng)然不同語言對(duì)數(shù)組的實(shí)現(xiàn)及處理也不盡相同。Java?語言中提供的數(shù)組是用來存儲(chǔ)固定大小的同類型元素
    2022-04-04
  • HashMap 和 Hashtable的區(qū)別

    HashMap 和 Hashtable的區(qū)別

    本文主要介紹HashMap 和 Hashtable的區(qū)別,這里整理了相關(guān)資料并詳細(xì)介紹了HashMap 和 Hashtable的區(qū)別及其工作原理和使用方法,有需要的朋友可以看一下
    2016-09-09
  • Java中Calendar時(shí)間操作常用方法詳解

    Java中Calendar時(shí)間操作常用方法詳解

    這篇文章主要為大家詳細(xì)介紹了Java中Calendar時(shí)間操作常用方法,calendar中set方法和靜態(tài)屬性帶來的一些坑,感興趣的小伙伴們可以參考一下
    2016-05-05
  • Spring之借助Redis設(shè)計(jì)一個(gè)簡單訪問計(jì)數(shù)器的示例

    Spring之借助Redis設(shè)計(jì)一個(gè)簡單訪問計(jì)數(shù)器的示例

    本篇文章主要介紹了Spring之借助Redis設(shè)計(jì)一個(gè)簡單訪問計(jì)數(shù)器的示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-06-06
  • 深入探討Druid動(dòng)態(tài)數(shù)據(jù)源的實(shí)現(xiàn)方式

    深入探討Druid動(dòng)態(tài)數(shù)據(jù)源的實(shí)現(xiàn)方式

    Druid是一個(gè)高性能的實(shí)時(shí)分析數(shù)據(jù)庫,它可以處理大規(guī)模數(shù)據(jù)集的快速查詢和聚合操作,在Druid中,動(dòng)態(tài)數(shù)據(jù)源是一種可以在運(yùn)行時(shí)動(dòng)態(tài)添加和刪除的數(shù)據(jù)源,使用動(dòng)態(tài)數(shù)據(jù)源,您可以在Druid中輕松地處理不斷變化的數(shù)據(jù)集,本文講給大家介紹一下Druid動(dòng)態(tài)數(shù)據(jù)源該如何實(shí)現(xiàn)
    2023-08-08
  • Java文件處理之使用XWPFDocument導(dǎo)出Word文檔

    Java文件處理之使用XWPFDocument導(dǎo)出Word文檔

    最近因項(xiàng)目開發(fā)的需要,整理了一份用JAVA導(dǎo)出WORD文檔,下面這篇文章主要給大家介紹了關(guān)于Java文件處理之使用XWPFDocument導(dǎo)出Word文檔的相關(guān)資料,需要的朋友可以參考下
    2023-12-12

最新評(píng)論