?? sprite2.java
字號:
// 程序:2.5D迷宮角色類
// 范例文件:Sprite2.java
class Sprite2 {
int SizeW;
int maze[][];
int indexI = 1, indexJ = 0;
public Sprite2(int w, int[][] m)
{
SizeW = w;
maze = m;
}
public void moveUp()
{
if(isPassed(indexI, indexJ,'U'))
indexI--;
}
public void moveDown()
{
if(isPassed(indexI, indexJ,'D'))
indexI++;
}
public void moveRight()
{
if(isPassed(indexI, indexJ,'R'))
indexJ++;
}
public void moveLeft()
{
if(isPassed(indexI, indexJ,'L'))
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 + -