坦克大战—day 42

1.设置背景音乐

package util;


import java.applet.Applet;
import java.applet.AudioClip;
import java.io.File;
import java.io.IOException;

public class MusicUtil {
    private static AudioClip start;
    private static AudioClip bomb;
    //装载音乐资源
    static {
        try {
            //引号里面的是音乐文件所在的绝对路径
            start = Applet.newAudioClip(new File("music/start.wav").toURL());//加载音频
            //bomb = Applet.newAudioClip(new File("music/bomb.wav").toURL());//加载音频
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void playStart() {
        start.play(); //播放音频
    }

    public static void playBomb() {
        bomb.play(); //播放音频
    }
}

2.游戏配置

在map包创建GameInfo:

package map;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * 游戏相关的信息的类
 */
public class GameInfo {
    //从文件中读取
    //关卡数量
    private static int levelCount;
    static {
        Properties prop =new Properties();
        try {
            prop.load(new FileInputStream("level/gameinfo"));
            levelCount = Integer.parseInt(prop.getProperty("levelCount"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static int getLevelCount() {
        return levelCount;
    }

}

3.通关判断

 /**
     * 是否是最后一关
     * @return
     */
    public static boolean isLastLevel(){
        //当前关卡和总关卡一致
        int currLevel = LevelInof.getInstance().getLevel();
        int levelCount = GameInfo.getLevelCount();
        return currLevel==levelCount;
    }

    /**
     * 判断是否过关了
     * @return
     */
    public static boolean isCrossLevel(){
        //消灭敌人的数量 和关卡的敌人的数量一致
        return  killEnemyCount == LevelInof.getInstance().getEnemyCount();
    }

判断

//坦克死亡后处理的内容
    private void die(){
        if(isEnemy){
            GameFrame.killEnemyCount ++;
            //敌人坦克被消灭了,归还对象池
            TankPool.theReturn((EnemyTank) this);
            //本关是否结束 
            if (GameFrame.isCrossLevel()){
                //判断游戏是否通关?
                if(GameFrame.isLastLevel()){
                    //是
                    GameFrame.setGameState(Constant.STATE_WIN);
                }else {
                    //进入下一关卡
                    GameFrame.startCrossLevel();
                }
            }
        }else {
            // 切换游戏状态
            delaySecondsToOver(1000);
        }
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值