package core;
import icon.BaseIcon;
import icon.HouseIcon;
import icon.ScvIcon;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.DirectColorModel;
import java.awt.image.MemoryImageSource;
import java.awt.image.PixelGrabber;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.ImageIcon;
import tile.Barrack;
import tile.Headquarter;
import tile.House;
import tile.Marine;
import tile.Mine;
import tile.Scv;
import tile.Sprite;
import tile.Supply;
import tile.Tank;
import tile.Tile;
import tile.Sprite.Animation;
public class ResourceManager {
private GridMap gridMap;
public static ResourceManager resourceManager;
private static Map<String,Image> IMAGE_CACHE = new HashMap<String, Image>();
public static Image loadImage(String fileName) {
if(!IMAGE_CACHE.containsKey(fileName)){
IMAGE_CACHE.put(fileName, new ImageIcon(ResourceManager.class.getResource("/images/"+fileName)).getImage());
}
return IMAGE_CACHE.get(fileName);
}
public static GridMapRender load(int type,List<Integer> types){
resourceManager = new ResourceManager(type,types);
return resourceManager.gridMap.getTileMapRender();
}
public GridMap getGridMap() {
return gridMap;
}
/**
* 鍒濆鍖栫缉鐣ュ浘
* @return
*/
private Image initMapBg(){
BufferedImage buffer = new BufferedImage(128,128,BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = (Graphics2D) buffer.getGraphics();
for (int y = 0; y < gridMap.getHeight(); ++y) {
for (int x = 0; x < gridMap.getWidth(); ++x) {
AffineTransform affineTransform = new AffineTransform();
affineTransform.setToTranslation(x*10, y*5);
affineTransform.scale(0.2, 0.2);
g2.drawImage(Constant.IMAGE_BG, affineTransform, null);
}
}
return buffer;
}
private ResourceManager(int type,List<Integer> types) {
Constant.load();
gridMap = loadMap(type,types);
Constant.IMAGE_MAP_BG = initMapBg();
Constant.progress = Constant.TOTAL;
}
private GridMap loadMap(int type,List<Integer> types) {
List<String> list = new ArrayList<String>();
int width = readMap(list, "startmap1.map");
GridMap map = new GridMap(width, list.size());
GridMapRender mapRender = new GridMapRender(map);
mapRender.type = type;
map.setTileMapRender(mapRender);
map.setIconMap(Constant.ICON_MAP);
for (int y = 0; y < list.size(); ++y) {
// 璇诲彇姣忎竴琛�
String s = list.get(y);
for (int x = 0; x < s.length(); ++x) {
int code = (int)s.charAt(x)-40;
if(code<0||code>Constant.TILE_TABLE.length)
continue;
if(code<80&&!types.contains((code/20)))
continue;
Tile tile = Constant.TILE_TABLE[code].clone(x, y,map);
tile.setHealth(1.0f);
map.add(tile);
//纭畾褰撳墠瑙嗚鑼冨洿
if(tile.getType()==type&&tile instanceof Headquarter){
//鑾峰彇褰撳墠鍩哄湴鍧愭爣
int hqX = GridMapRender.tileXToPx(tile.getTileX());
int hqY = GridMapRender.tileYToPx(tile.getTileY());
Point size = tile.getSize();
//鑾峰彇灞忓箷涓績鍧愭爣
int centerX = (800-GridMapRender.tileXToPx(size.x))/2;
int centerY = (600-GridMapRender.tileYToPx(size.y))/2;
mapRender.setOffset(Math.max(hqX-centerX, 0),Math.max(hqY-centerY, 0));
}
}
}
return map;
}
private static int readMap(List list, String fileName) {
BufferedReader br = null;
int width = 0;
try {
br = new BufferedReader(new InputStreamReader(ResourceManager.class.getResourceAsStream("/map/" + fileName)));
String line = null;
while ((line = br.readLine()) != null) {
if (line.startsWith("#"))
continue;
list.add(line);
width = Math.max(width, line.length());
}
return width;
} catch (Exception e) {
e.printStackTrace();
return -1;
} finally {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static class Constant {
public static String IP;
public static Color GREEN;
public static Color RED=Color.red;
//鑳屾櫙
public static Image IMAGE_BG;
//鎺у埗鍙�
public static Image IMAGE_CONTROL;
//鍏夌収鏁堟灉
public static Image SCV_SPARK;
//鐭夸骇
public static Image ICON_MINE;
//浜哄彛
public static Image ICON_MAN;
//鐭夸骇閿欒淇℃伅
public static String MINE_ERROR="娌¤祫婧愬挴锛岃繕鏄鍘婚噰鐐圭熆鍚�";
//浜哄彛閿欒淇℃伅
public static String MAN_ERROR="澶尋鍟︼紝蹇�鐐规埧瀛愬嚭鏉ュ惂";
public static String BUILD_ERROR="鍦板熀涓嶇ǔ锛屼笉鑳戒慨鍦ㄨ繖閲�";
public static Image IMAGE_MAP_BG;
//ICONS
public static final BaseIcon[][] SCV_ICONS = new BaseIcon[2][3];
public static final BaseIcon[][] HQ_ICONS = new BaseIcon[2][3];
public static final BaseIcon[][] BACK_ICONS = new BaseIcon[2][3];
//ICON璧勬簮琛�
public static final Map<Integer,BaseIcon[][]> ICON_TABLE = new HashMap<Integer, BaseIcon[][]>();
//Tile璧勬簮琛�
public static final Tile[] TILE_TABLE = new Tile[82];
private static final int TYPE = 4;
public static final int TYPE_SIZE = 20;
//杩涘害鎺у埗
private static float progress;
private static final float TOTAL=19;
static void load(){
IMAGE_BG = loadImage("bg1.gif");
IMAGE_CONTROL = loadImage("panel/main.gif");
SCV_SPARK = loadImage("unit/0_scv_spark.gif");
ICON_MINE = loadImage("panel/mine.gif");
ICON_MAN = loadImage("panel/man.gif");
GREEN = new Color(16, 252, 24);
initTile();
}
private static final Map<String, BaseIcon> ICON_MAP = new HashMap<String, BaseIcon>();
private static int count = 0;
private static BaseIcon createIcon(BaseIcon icon){
ICON_MAP.put("icon"+(++count), icon);
return icon;
}
private static void initTile(){
//鍔犺浇鍥剧墖
Image scv = loadImage("unit/0_scv_red.gif");
Image marine = loadImage("unit/0_marine_red.gif");
Image marineFight = loadImage("unit/0_fight_marine_red.png");
Image tank = loadImage("unit/0_tank.gif");
Image supply = loadImage("build/0_supply_red.gif");
Image barrack = loadImage("build/0_barrack_red.gif");
Image base = loadImage("build/0_hq_red.gif");
Image mine = loadImage("block/mine.gif");
//杞崲鎴恇uffer
BufferedImage scv_buffer=imageToBuffer(scv);
BufferedImage marine_buffer=imageToBuffer(marine);
BufferedImage marineFight_buffer=imageToBuffer(marineFight);
BufferedImage supply_buffer=imageToBuffer(supply);
BufferedImage barrack_buffer=imageToBuffer(barrack);
BufferedImage base_buffer=imageToBuffer(base);
BufferedImage tank_buffer=imageToBuffer(tank);
//鍒濆鍖栫熆浜ц祫婧�
TILE_TABLE[80] = new Mine(mine,80);
//ICON
HQ_ICONS[0][0] = createIcon(new HouseIcon(loadImage("ico/0_scv.gif")));
SCV_ICONS[0][0] = createIcon(new ScvIcon(loadImage("ico/0_supply.gif")));
SCV_ICONS[0][1] = createIcon(new ScvIcon(loadImage("ico/0_barrack.gif")));
BACK_ICONS[0][0] = createIcon(new HouseIcon(loadImage("ico/0_marine.gif")));
//BACK_ICONS[0][1] = new HouseIcon(loadImage("ico/0_tanke.gif"));
//鍒濆鍖栨瘮杈冨鏉傜殑Tile
for(int i=0;i<TYPE;++i){
//鍐滄皯
没有合适的资源?快使用搜索试试~ 我知道了~
JAVA版Swing星际争霸游戏源代码.7z
共415个文件
class:144个
gif:140个
java:90个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 187 浏览量
2022-07-06
10:26:25
上传
评论
收藏 709KB 7Z 举报
温馨提示
JAVA版Swing星际争霸游戏源代码.7z
资源推荐
资源详情
资源评论
收起资源包目录
JAVA版Swing星际争霸游戏源代码.7z (415个子文件)
startmap1.map.bak 13KB
startmap1.map.bak 13KB
ResourceManager$Constant.class 11KB
Sprite.class 11KB
AStarSearch.class 9KB
Scv.class 9KB
GridMapRender.class 9KB
Server.class 7KB
MutilPlayerPanel$2.class 6KB
ResourceManager.class 6KB
FocusManager.class 6KB
GridMap.class 6KB
NewGamePanel$LeftPanel.class 5KB
Control.class 5KB
House.class 5KB
DefaultNetWorkManager.class 4KB
Client.class 4KB
ScreenManager.class 4KB
ServerProcessor.class 4KB
MutilPlayerPanel$LeftPanel.class 4KB
FullGameCore.class 4KB
ClientGUI.class 4KB
GameCore.class 3KB
GamePanel.class 3KB
PathSearch.class 3KB
WorkPanel.class 3KB
MapPanel.class 3KB
Player.class 3KB
GameGUI.class 3KB
MockNetWorkManager.class 3KB
PlayerInfo.class 3KB
Mine.class 3KB
PSExplosion.class 3KB
MutilPlayerPanel.class 3KB
AStarNode.class 3KB
Receiver.class 2KB
Detector.class 2KB
MainMenuPanel$MenuItem.class 2KB
SingleGamePanel$LeftPanel.class 2KB
StarScrollBarUI.class 2KB
PlayerContext.class 2KB
NewGamePanel.class 2KB
NewGamePanel$RightPanel.class 2KB
Marine.class 2KB
MutilPlayerPanel$RightPanel.class 2KB
SingleGamePanel$RightPanel.class 2KB
Control$ControlDragListener.class 2KB
Abstractpanel.class 2KB
MutilPlayerPanel$LeftPanel$2.class 2KB
StarComboBoxUI.class 2KB
MainMenuPanel$MenuItem$1.class 2KB
SingleGamePanel.class 2KB
MutilPlayerPanel$LeftPanel$1.class 2KB
TileList.class 2KB
MoveInfo.class 2KB
Sprite$Animation.class 2KB
Vector.class 2KB
NewGamePanel$RightPanel$2.class 2KB
StarNode.class 2KB
AbstractTile.class 2KB
NewGamePanel$RightPanel$1.class 2KB
StarComboBoxUI.class 2KB
Tank.class 2KB
MutilPlayerPanel$RightPanel$1.class 2KB
Stack.class 2KB
Particle.class 2KB
NewGamePanel$LeftPanel$4.class 2KB
NewGamePanel$LeftPanel$5.class 2KB
GamePanel$1.class 2KB
NewGamePanel$LeftPanel$3.class 2KB
StarListCellRender.class 2KB
GamePanel$5.class 2KB
ClientEvent.class 2KB
SingleGamePanel$RightPanel$1.class 2KB
SingleGamePanel$LeftPanel$2.class 2KB
SingleGamePanel$LeftPanel$1.class 2KB
NewGamePanel$TextPanel.class 2KB
BaseIcon.class 2KB
Control$ControlMoveListener.class 1KB
NewGamePanel$LeftPanel$1.class 1KB
TestGameCore.class 1KB
ConsolePanel.class 1KB
IconInfo.class 1KB
Elastic.class 1KB
RoundBorder.class 1KB
Broadcaster.class 1KB
RoundBorder.class 1KB
ImageManager.class 1KB
NetworkPanel$MenuItem.class 1KB
RoundBorder.class 1KB
RandomSequence.class 1KB
Headquarter.class 1KB
Control$ControlKeyListener.class 1KB
MainMenuPanel.class 1KB
MapPanel$MouseListener.class 1KB
NewGamePanel$LeftPanel$GameItemListener.class 1KB
NetworkPanel.class 1KB
StarComboBoxRender.class 1KB
Barrack.class 1KB
Supply.class 1KB
共 415 条
- 1
- 2
- 3
- 4
- 5
资源评论
- 007你好2022-07-25总算找到了自己想要的资源,对自己的启发很大,感谢分享~
BryanDing
- 粉丝: 297
- 资源: 5587
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功