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

📄 resourcemanager.java

📁 goldminer游戏
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.hbwhzdg.goldminer.gamecore;

import com.hbwhzdg.goldminer.gamecore.sprites.Claw;
import com.hbwhzdg.goldminer.gamecore.util.LoadImages;
import com.hbwhzdg.goldminer.graphics.Animation;
import com.hbwhzdg.goldminer.gamecore.sprites.*;
import java.util.Properties;
import java.io.*;
import java.util.Enumeration;
import java.awt.Image;
import com.hbwhzdg.goldminer.graphics.Sprite;
import java.util.HashMap;
import java.util.LinkedList;

/**
 * <p>Title: 游戏资源管理器</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 *
 * @author rocken.zeng@gmail.com
 * @version 1.0
 */
public class ResourceManager {
    private GameMap map = new GameMap();
    private ScreenManager sm = ScreenManager.getInstance();
    private int nMap = 0; //第多少个矿区
    private int nLevel = 0; //关卡
    //初始参数
    private int passTime = 50; //每关的时间,以秒为单位。
    private double clawLength = 22; //爪子摆动时的半径长度
    private double putOutSpeed = 0.5; //爪子放出的速度,以毫秒为单位
    private double takeBackSpeed = 0.5; //爪子爪空收回的速度,以毫秒为单位
    private double stopTime = 2; //将物品爪回后,停多少毫秒后再摆动
    private double angleSpeed = 0.08; //爪子每毫秒转动的角度数
    private double minAngle = 15; //爪子偏转的最小角度
    //爪子起点
    private double startOrgX = sm.getWidth() / 2;
    private double startOrgY = 82;
    //角色
    private Sprite bigGoldOre = null;
    private Sprite bigStone = null;
    private Sprite clothWrappers = null;
    private Sprite diamond = null;
    private Sprite diamondPig = null;
    private Sprite middleGoldOre = null;
    private Sprite middleStone = null;
    private Sprite pig = null;
    private Sprite smallGoldOre = null;
    private Sprite smallStone = null;
    //奖品显示的位置
    private int prizeX = 0;
    private int prizeY = 0;
    private HashMap allSpeed = new HashMap();
    private LinkedList helps = new LinkedList();

    public ResourceManager() {
    }

    public void init() {
        loadGameProp();
        loadHelps();
        initBigGoldOre();
        initBigStone();
        initClothWrappers();
        initDiamond();
        initDiamondPig();
        initMiddleGoldOre();
        initMiddleStone();
        initPig();
        initSmallGoldOre();
        initSmallStone();
    }

    public void loadNextMap() {
        loadDiggings(); //载入矿区
        loadClaw(); //载入爪子
        loadMiner();
        nMap++;
        nLevel++;
        loadMap();
    }

    private void loadClaw() {
        Animation anim = new Animation();
        anim.addFrame(LoadImages.getImage("zhua.png"), 0);
        Claw claw = new Claw(anim);
        claw.init(startOrgX, startOrgY, clawLength, minAngle, angleSpeed,
                  putOutSpeed, takeBackSpeed, stopTime);
        claw.setAllSpeed(allSpeed);
        map.setClaw(claw);
    }

    public GameMap getMap() {
        return map;
    }

    private void loadDiggings() {
        if (map.getDiggings() == null) {
            Animation anim = new Animation();
            anim.addFrame(LoadImages.getImage("bg.png"), 0);
            anim.addFrame(LoadImages.getImage("bg1.png"), 0);
            anim.addFrame(LoadImages.getImage("bg2.png"), 0);
            anim.addFrame(LoadImages.getImage("bg3.png"), 0);
            anim.addFrame(LoadImages.getImage("bg4.png"), 0);
            anim.addFrame(LoadImages.getImage("bg5.png"), 0);
            map.setDiggings(new Diggings(anim));
        } else {
            if (nMap > map.getDiggings().getFramesSize()) {
                nMap = 1;
            }
            map.getDiggings().setCurrFrameIndex(nMap - 1);
        }
    }

    private void loadMiner() {
        Animation anim = new Animation();
        anim.addFrame(LoadImages.getImage("laoren1.png"), 250);
        anim.addFrame(LoadImages.getImage("laoren2.png"), 350);
        Miner miner = new Miner(anim);
        miner.setX(475);
        miner.setY(14);
        map.setMiner(miner);
    }

    private void loadHelps() {
        String fileName = "conf" + File.separator + "help.txt";
        BufferedReader in;
        try {
            in = new BufferedReader(new FileReader(fileName));
            String line;
            try {
                while ((line = in.readLine()) != null) {
                    line = line.trim();
                    helps.add(line);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    /**
     * 导入游戏的配置文件。
     */
    private void loadGameProp() {
        Properties prop = new Properties();
        try {
            prop.load(new FileInputStream("conf" + File.separator +
                                          "game.properties"));
            Enumeration enu = prop.propertyNames();
            String key = "";
            while (enu.hasMoreElements()) {
                key = (String) enu.nextElement();
                if (key.equals("passTime")) {
                    this.passTime = Integer.parseInt(prop.getProperty(
                            "passTime"));
                } else if (key.equals("clawLength")) {
                    this.clawLength = Double.parseDouble(prop.getProperty(
                            "clawLength"));
                } else if (key.equals("putOutSpeed")) {
                    this.putOutSpeed = Double.parseDouble(prop.getProperty(
                            "putOutSpeed"));
                } else if (key.equals("takeBackSpeed")) {
                    this.takeBackSpeed = Double.parseDouble(prop.getProperty(
                            "takeBackSpeed"));
                } else if (key.equals("A1s")) {
                    allSpeed.put("bigGoldOre", prop.getProperty("A1s"));
                } else if (key.equals("A2s")) {
                    allSpeed.put("middleGoldOre", prop.getProperty("A2s"));
                } else if (key.equals("A3s")) {
                    allSpeed.put("smallGoldOre", prop.getProperty("A3s"));
                } else if (key.equals("A4s")) {
                    allSpeed.put("diamond", prop.getProperty("A4s"));
                } else if (key.equals("A5s")) {
                    allSpeed.put("pig", prop.getProperty("A5s"));
                } else if (key.equals("A6s")) {
                    allSpeed.put("diamondPig", prop.getProperty("A6s"));
                } else if (key.equals("A7s")) {
                    allSpeed.put("smallStone", prop.getProperty("A7s"));
                } else if (key.equals("A8s")) {
                    allSpeed.put("middleStone", prop.getProperty("A8s"));
                } else if (key.equals("A9s")) {
                    allSpeed.put("bigStone", prop.getProperty("A9s"));
                } else if (key.equals("stopTime")) {
                    this.stopTime = Double.parseDouble(prop.getProperty(
                            "stopTime"));
                } else if (key.equals("angleSpeed")) {
                    this.angleSpeed = Double.parseDouble(prop.getProperty(
                            "angleSpeed"));
                } else if (key.equals("minAngle")) {
                    this.minAngle = Double.parseDouble(prop.getProperty(
                            "minAngle"));
                } else if (key.equals("prizeX")) {
                    this.prizeX = Integer.parseInt(prop.getProperty(
                            "prizeX"));
                } else if (key.equals("prizeY")) {
                    this.prizeY = Integer.parseInt(prop.getProperty(
                            "prizeY"));
                }
            }
        } catch (IOException ex) {
        }
    }

    private Image getPrizeImage(String name) {
        String prizeName = null;
        if (name.equals("B1")) {
            prizeName = "prize1.png";

⌨️ 快捷键说明

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