?? stage.java
字號:
package com.cpiz.poptang;
import java.io.DataInputStream;
import java.io.IOException;
/**
* 關卡數據類,用以關卡數據的持久化保存
* @author caipiz
*/
public class Stage
{
public int stageIndex = -1;
public int imgIndex = 1;
public int midIndex = 1;
public byte[][][] mapData = new byte[3][7][8];
public byte[] heroPosition = new byte[2];//英雄出生位置,英雄所在的行和列
public byte[] enemyPosition = new byte[10];// 敵人出生位置
/**
* 獲取指定關卡地圖數據
* @param stageIndex 關卡號
* @return 關卡數據對象
* @throws IOException 未找到對應關卡數據文件則拋出異常
*/
public static Stage loadStage(int stageIndex) throws IOException
{
Stage stageData = new Stage();
stageData.stageIndex = stageIndex;
DataInputStream dis = new DataInputStream(Stage.class.getResourceAsStream("/stage/" + stageIndex));
// 讀取地圖貼圖文件索引
stageData.imgIndex = dis.readInt();
// 讀取地圖貼圖文件索引
stageData.midIndex = dis.readInt();
// 讀取地圖數據
byte[] map = new byte[3*7*8];
dis.read(map);// 一次性將整個地圖讀入一維數組中
int index = 0;
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 7; j++)
{
for(int k = 0; k < 8; k++)
{
stageData.mapData[i][j][k] = map[index++];
}
}
}
// 讀取英雄出生點
dis.read(stageData.heroPosition);
// 讀取敵人出生點并獲得敵人數目
dis.read(stageData.enemyPosition);
return stageData;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -