嗨,我正在研究滑动拼图,到目前为止一切都很好。我有一个工作难题,但现在我正在处理没有图像的数字。现在我想使用图像作为数字的背景。谁能帮我把图像剪下来,把它们和数字联系起来,这样谜题仍然有效吗?
这是我的数字代码,它是 9 块拼图
public Button[] findButtons() {
Button[] b = new Button[9];
b[0] = (Button) findViewById(R.id.Button00);
b[1] = (Button) findViewById(R.id.Button01);
b[2] = (Button) findViewById(R.id.Button02);
b[3] = (Button) findViewById(R.id.Button03);
b[4] = (Button) findViewById(R.id.Button04);
b[5] = (Button) findViewById(R.id.Button05);
b[6] = (Button) findViewById(R.id.Button06);
b[7] = (Button) findViewById(R.id.Button07);
b[8] = (Button) findViewById(R.id.Button08);
return b;
}
public void makeMove(final Button b) {
bad_move=true;
int b_text,b_pos,zuk_pos;
b_text=Integer.parseInt((String) b.getText());
b_pos=find_pos(b_text);
zuk_pos=find_pos(0);
switch(zuk_pos)
{
case(0):
if(b_pos==1||b_pos==3)
bad_move=false;
break;
case(1):
if(b_pos==0||b_pos==2||b_pos==4)
bad_move=false;
break;
case(2):
if(b_pos==1||b_pos==5)
bad_move=false;
break;
case(3):
if(b_pos==0||b_pos==4||b_pos==6)
bad_move=false;
break;
case(4):
if(b_pos==1||b_pos==3||b_pos==5||b_pos==7)
bad_move=false;
break;
case(5):
if(b_pos==2||b_pos==4||b_pos==8)
bad_move=false;
break;
case(6):
if(b_pos==3||b_pos==7)
bad_move=false;
break;
case(7):
if(b_pos==4||b_pos==6||b_pos==8)
bad_move=false;
break;
case(8):
if(b_pos==5||b_pos==7)
bad_move=false;
break;
}
if(bad_move==true)
{
feedbackText.setText("Ongeldige zet");
return;
}
feedbackText.setText("Geldige zet");
cells.remove(b_pos);
cells.add(b_pos, 0);
cells.remove(zuk_pos);
cells.add(zuk_pos,b_text);
fill_grid();
for(int i=0;i<9;i++)
{
if(cells.get(i)!=goal[i])
{
return;
}
}
feedbackText.setText("Voltooid");
mChronometer.stop();
long elapsedMillis = SystemClock.elapsedRealtime() - mChronometer.getBase();
tijd = (int) elapsedMillis;
mScoreDialog = new ScoreDialog(this,this, 0, convertToTimeFormat(elapsedMillis));
mScoreDialog.show();
}
public void fill_grid()
{
for(int i=0;i<9;i++)
{
int text=cells.get(i);
AbsoluteLayout.LayoutParams absParams =
(AbsoluteLayout.LayoutParams)buttons[text].getLayoutParams();
switch(i)
{case(0):
absParams.x = 5;
absParams.y = 5;
buttons[text].setLayoutParams(absParams);
break;
case(1):
absParams.x = 110;
absParams.y = 5;
buttons[text].setLayoutParams(absParams);
break;
case(2):
absParams.x = 215;
absParams.y = 5;
buttons[text].setLayoutParams(absParams);
break;
case(3):
absParams.x = 5;
absParams.y = 110;
buttons[text].setLayoutParams(absParams);
break;
case(4):
absParams.x =110;
absParams.y =110;
buttons[text].setLayoutParams(absParams);
break;
case(5):
absParams.x = 215;
absParams.y =110;
buttons[text].setLayoutParams(absParams);
break;
case(6):
absParams.x = 5;
absParams.y = 215;
buttons[text].setLayoutParams(absParams);
break;
case(7):
absParams.x = 110;
absParams.y = 215;
buttons[text].setLayoutParams(absParams);
break;
case(8):
absParams.x = 215;
absParams.y = 215;
buttons[text].setLayoutParams(absParams);
break;
}
}
}
public int find_pos(int element)
{
int i=0;
for(i=0;i<9;i++)
{
if(cells.get(i)==element)
{
break;
}
}
return i;
}
如您所见,我正在验证动作并使用图像按钮。