📄 gameboy.java
字号:
package bin;
import java.util.ArrayList;
class Gameboy implements Runnable
{
public int GameboyX,GameboyY,GameW,GameH,Xaxes,Yaxes,x,y,a,b,game,col;
int [][] plat;
int i = 22;
int j = 0;
static int goal;
static int gold;
ArrayList list = new ArrayList();;
Thread left;
Thread right;
public Gameboy(int GameboyX, int GameboyY, int GameW, int GameH, int [][] plat)
{
this.GameboyX = GameboyX;
this.GameboyY = GameboyY;
this.GameH = GameH;
this.GameW = GameW;
this.goal = 0;
this.gold = 22;
this.plat = plat; //构造对象属性及2x数组
}
public void workup()
{
if(plat[i-1][j] == 3)
{
//System.out.println (plat[i][j]);
GameboyY -= GameH;
i--;
/*人物向上移动
*考虑人物站立的位置是在砖块等物体之上
*所以当前的数组元素应该在人物的脚下
*人物在游戏里显示出来的位置是人物所在数组的上一数组元素
*/
if (plat[i][j] == 1)
{
Gold();
}
if (plat[i-1][j] == 6)
{
second();
}
}
}
public void workdown()
{
if (plat[i][j] == 3)
{
//System.out.println (plat[i][j]);
GameboyY += GameH;
i++; //处理人物向上移动
if (plat[i][j] == 0) //判断向下是否踩空
{
while (plat[i][j] == 0 || plat[i][j] == 6) //对踩空后进行处理
{
GameboyY += GameH;
i++;
}
}
else if (plat[i][j] == 1 ) //判断是否是金B
{
Gold();
while (plat[i][j] == 0) //判断得到金B后是否层继续会踩空
{
GameboyY += GameH;
i++;
}
}
if (plat[i-1][j] == 6)
{
second();
}
}
}
public void workleft()
{
// System.out.println ("I:" + i + " J:" + j);
// System.out.println ("GameboyX:" + GameboyX + " GameboyY:" + GameboyY);
try
{
if (plat[i-1][j-1] != 2 && plat[i-1][j-1] != 4)
{
if (GameboyX >= 0)
{
GameboyX -= GameW;
if (GameboyX == 0)
{
GameboyX = 0;
j = 0; //处理人物向右移动
}
else
{
j--;
}
}
if (plat[i][j] == 0) //判断是否踩空
{
Gravity(); //踩空后调用重力方法
if (plat[i][j] == 1)
{
Gold();
Gravity();
}
}
else if (plat[i][j] == 1 ) //判断是否为金B
{
Gold();
Gravity(); //调用重力方法
}
else if (plat[i-1][j] == 1 || plat[i][j] == 1)
{
plat[i-1][j] = 0; //获得金B
goal += 100;
gold--;
}
if (plat[i-1][j] == 6)
{
second();
}
}
}
catch (ArrayIndexOutOfBoundsException excption){ }
}
public void workright()
{
// System.out.println ("I:" + i + " J:" + j);
// System.out.println ("GameboyX:" + GameboyX + " GameboyY:" + GameboyY);
try
{
if (plat[i-1][j+1] != 2 && plat[i-1][j+1] != 4)//人物显示的地方没有砖或铁则可以移动
{
//System.out.println (plat[i][j]);
if (GameboyX <= 580)
{
GameboyX += GameW;
if (GameboyX == 580)
{
GameboyX = 580;
j = 29; //处理人物向右移动
}
else
{
j++;
}
}
//处理人物向右移动
if (plat[i][j] == 0) //判断是否踩空
{
Gravity();
if (plat[i][j] == 1)
{
Gold();
Gravity();
}
}
else if (plat[i][j] == 1) //判断是否为金B
{
Gold();
Gravity(); //调用重力方法
}
else if (plat[i-1][j] == 1 || plat[i][j] == 1)
{
plat[i-1][j] = 0;
goal += 100;
gold--;
}
if (plat[i-1][j] == 6)
{
second();
}
}
}
catch (ArrayIndexOutOfBoundsException excption){ }
}
public void Gravity()
{
while (plat[i][j] == 0) //判断当前位置是否为空,如果为空则循环
{
GameboyY += GameH; //由于向心力的原因人物以自由垂直方式落下
i++; //数组元素i递增,在游戏中显示为行,直到当前行当前列不为空则退出循环
}
}
public void Gold()
{
plat[i][j] = 0;
goal += 100;
gold--;
}
public void second()
{
Second se = new Second();
}
public void workdiglift()
{
if (plat[i][j-1] == 2 && plat[i-1][j-1] == 0)
{
plat[i][j-1] = 0;
Xaxes = i;
Yaxes = j-1;
list.add(new Coordinate(Xaxes,Yaxes));
left = new Thread(this);
left.start();
}
}
public void workdigright()
{
if (plat[i][j-1] == 2 && plat[i-1][j+1] == 0)
{
plat[i][j+1] = 0;
Xaxes = i;
Yaxes = j+1;
list.add(new Coordinate(Xaxes,Yaxes));
right = new Thread(this);
right.start();
}
}
public void run()
{
try
{
for (int size = 0; size < list.size(); size++)
{
try
{
left.sleep(5000);
}
catch(Exception e)
{
e.printStackTrace();
}
Coordinate cd = (Coordinate)(list.get(0));
// System.out.println (list.size());
x = cd.getJ();
y = cd.getI();
plat[y][x] = 2;
list.remove(0);
list.trimToSize();
// System.out.println (list.size());
a = x*20;
b = y*24;
if (a == GameboyX && b == GameboyY)
{
game = 1;
GameboyX = 0;
GameboyY = 504;
}
}
StatePanel.setLabScoreValue();
OrderPane.setScore();
}
catch (Exception e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -