import java.awt.*;
import hsa.Console;
public class Game{
static Console c;
public static void Wait (int time){
try{
Thread.sleep (time);
}
catch (InterruptedException e){
}
}
public static class Tile{
public int x,y,stack;
public Tile(){
x = 0;
y = 0;
stack = 0;
}
public Tile(int xco, int yco, int stacknum){
x = xco;
y = yco;
stack = stacknum;
}
public void draw(Tile tile){ //To draw the tile
if(stack>0){
c.setColor(Color.red);
c.fillRect(x*78+1+x,y*78+1+y,78,78); //Calculate coordinates
}
else{
c.setColor(Color.blue);
c.fillRect(x*78+1+x,y*78+1+y,78,78);
}
}
}
public static void main (String[] args){
c = new Console ();
for(int i=0;i<640;i+=79) c.drawLine(i,0,i,474);
for(int i=0;i<500;i+=79) c.drawLine(0,i,632,i);
//8x6 tiling
Tile[][] tile = new Tile[8][6];
for(int i=0;i<8;i++){
for(int j=0;j<6;j++){
tile[i][j] = new Tile();
tile[i][j].x = i;
tile[i][j].y = j; //Set x and y coordinates
tile[i][j].stack = 5;
}
}
Tile.draw(tile[0][0]);
}
}
在这里,我有一个使用多维数组的 8x6 方块。我认为坐标将对应于正确的数字,但由于某种原因,坐标似乎复制了之前创建的坐标。有人可以告诉我为什么会发生这种情况以及应该如何更正代码吗?顺便说一句,我开始使用 java,所以我不完全习惯于面向对象编程:P