//取出不可用的数据;
public int[] getUsedTilesByCoor(int x, int y){
return used[x][y];
}
//计算单元格中不可用的数据;
public int[] calculateUsedTiles(int x, int y){
int [] c = new int[9];
//计算Y轴方向不可用数据;
for(int i = 0; i < 9; i ++){
if( i == y ){
continue;
}
int t = getTile(x,i);
if(t!=0){
c[t-1]=t;
}
}
//计算X轴方向不可用数据:
for(int i = 0; i < 9 ; i++){
if(i == x){
continue;
}
int t = getTile(i,y);
if(t != 0){
c[t-1] = t;
}
}
//计算小九宫格不可用数据;
int startx = (x / 3) * 3;
int starty = (y / 3) * 3;
for(int i = startx; i < startx + 3; i++){
for(int j = starty; j < starty + 3; j++){
if(i == x && j == y){
continue;
}
int t = getTile(i,j);
if(t != 0 ){
c[t-1] = t;
}
}
}
int nused = 0;
for(int t : c){
if(t != 0){
nused ++;
}
}
int [] c1 = new int[nused];
nused = 0 ;
for(int t : c){
if(t != 0){
c1[nused++] = t;
}
}
return c1;
}
//获取屏幕点击的焦点
@Override
public boolean onTouchEvent(MotionEvent event) {
if(event.getAction() != MotionEvent.ACTION_DOWN){
return super.onTouchEvent(event);
}
int selectedX = (int)(event.getX()/width);
int selectedY = (int)(event.getY()/height);
int used[] = game.getUsedTilesByCoor(selectedX, selectedY);
for(int i = 0 ; i < used.length ; i++){
System.out.println(used[i]);
}
return true;
}