📄 cmap.java
字号:
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
/*
* 地图类
* 要求地图信息文件第一、二个数据表示此地图的总行数、总列数
*/
public class CMap
{
private byte m_btMapData[][]; //记录地图块信息
private byte m_rowNum = 0; //记录该地图的地图块行数
private byte m_colNum = 0; //记录该地图的地图块列数
//---------------------------
// 构造函数
// 将含有地图信息的文件读入
//---------------------------
public CMap(String filepath)
{
InputStream is = this.getClass().getResourceAsStream(filepath);
DataInputStream dis = new DataInputStream(is);
try
{
m_rowNum = dis.readByte(); //读取地图文件中的该地图的总行数
m_colNum = dis.readByte(); //读取地图文件中的该地图的总列数
} catch (IOException ex)
{
ex.printStackTrace();
}
m_btMapData = new byte[m_rowNum][m_colNum];
try
{
for (int row = 0; row < m_rowNum; row++)
{
for (int col = 0; col < m_colNum; col++)
{
m_btMapData[row][col] = dis.readByte();
}
}
} catch (IOException ex)
{
ex.printStackTrace();
}
}
//---------------------------
// 返回得到地图块序号
//---------------------------
public int GetMapData(int row, int col)
{
return m_btMapData[row][col];
}
public byte getColNum()
{
return m_colNum;
}
public byte getRowNum()
{
return m_rowNum;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -