我正在尝试制作扫雷游戏。但我有点困惑如何为游戏中的每个单元格获取 x 和 y 坐标以便为每个单元格绘制图像。此代码仅绘制具有位置 (0,0) 的第一个单元格。我怎样才能获得对其他单元格的引用?这是我的代码:
public class Cell {
private int row, col;
private int ulx, uly, w, h;
private boolean marked, covered, mined;
private int adjcount;
private Cell(int r, int c) {
marked=false;
covered=true;
mined=false;
row=r;
col=c;
w=h=16;
adjcount=0;
}
public int getX(){
return ulx;
}
public int getY(){
return uly;
}
public boolean getMarked() {
return marked;
}
public void setMarked(boolean value) {
marked=value;
}
public boolean getCovered() {
return covered;
}
public void setCovered(boolean value) {
covered=value;
}
public boolean getMined() {
return mined;
}
public void setMined(boolean value) {
mined=value;
}
public void setAdjCount(int count) {
adjcount = count;
}
public int getAdjCount() {
return adjcount;
}
这是我在游戏中绘制每个单元格的地方
if (getCovered() == true && getMarked () == false) { // gray rectangle
g.drawImage(gRec,getX(),getY(),w,h,null);
}