这些逻辑上的东西写起来会比较麻烦一点
1,按键监听
mark.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
flag1++;
if (flag1%2 == 1){
mark.setAlpha(0.55f);
}else {
mark.setAlpha(1.0f);
}
}
});
2,用一个数组存储标记内容
private int smallCell[][] = new int[81][9] ;
//第一个用来存储空格位置,第二个用来存储输入数字
public void setCellTitle(int n, int x, int y){
if (smallCell[x][y]!=0){
smallCell[x][y]=0;
}else
smallCell[x][y] = n;
}
3,画标记后的输入内容
if (selectX+selectY>=0) {
if (mgame.getNumber(selectX, selectY) == "") {
samllPaint.setTextAlign(Paint.Align.CENTER);
//number center
Paint.FontMetrics fMetrics1 = samllPaint.getFontMetrics();
float x1 = width / 2 / 3;
float y1 = height / 2 / 3 - (fMetrics1.ascent + fMetrics1.descent) / 2;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (!mgame.getSmallCell(selectX*9+selectY,i+j*3).equals("0")) {
canvas.drawText(mgame.getSmallCell(selectX*9+selectY,i+j*3),
width / 3 * i + x1 + 37 + selectX * width,
y1 + width / 3 * j + 37 + selectY * width, samllPaint);
//每个数字的位置都是固定的,监听到有数字输入,就把数字显示在对应位置
}
}
}
}
}