?? sprite.java
字號:
// 程序:2D迷宮角色類別
// 范例文件:Sprite.java
class Sprite {
int LcX, LcY;
int SizeW, SizeH;
int maze[][];
int indexI = 1, indexJ = 1;
public Sprite(int x, int y, int w, int h, int[][] m)
{
LcX = x;
LcY = y;
SizeW = w;
SizeH = h;
maze = m;
}
public void moveUp()
{
if(isPassed(indexI, indexJ,'U'))
{
LcY -= SizeW;
indexI--;
}
}
public void moveDown()
{
if(isPassed(indexI, indexJ,'D'))
{
LcY += SizeW;
indexI++;
}
}
public void moveRight()
{
if(isPassed(indexI, indexJ,'R'))
{
LcX += SizeW;
indexJ++;
}
}
public void moveLeft()
{
if(isPassed(indexI, indexJ,'L'))
{
LcX -= SizeW;
indexJ--;
}
}
private boolean isPassed(int i, int j, char d)
{
boolean pass = false;
switch (d)
{
case 'U':
if(maze[i-1][j] == 0)
pass = true;
break;
case 'D':
if(maze[i+1][j] == 0)
pass = true;
break;
case 'L':
if(maze[i][j-1] == 0)
pass = true;
break;
case 'R':
if(maze[i][j+1] == 0)
pass = true;
break;
}
return pass;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -