通过了几个月坚持不懈的努力,我们组也终于完成了最终成果。关于趣拼图,我们从最初的界面设计到现在的完成,其中也经历了许多,也遇到了很多问题,但我们也都解决了,也从中了解到完成一个项目有多不容易,也从中体会到了团体合作的重要性,下面就先展示一下关于中等的拼图的代码经,这是经过修改最多的一个部分。
以及JAVA代码:
public class GameZnptZhongDengActivity extends Activity implements View.OnClickListener,Chronometer.OnChronometerTickListener { int bc_gezi = 4; Button [][] gezi = new Button [bc_gezi][bc_gezi]; Game2GeziYiDong yidong_zd = new Game2GeziYiDong(); TextView text_step , gameOver , overStep; Chronometer timer; int step , time = -2; int sign; int [][] Init_gz = { {8,1,15,11,14,5,2,12,3,13,10,4,9,7,6}, {15,13,11,2,8,6,9,7,14,4,12,5,3,10,1}, {8,12,11,2,9,15,7,14,3,6,1,5,4,13,10}, {4,9,2,8,6,1,12,10,13,7,14,15,5,3,11}, {7,13,6,14,12,8,9,10,5,4,11,15,1,3,2}, {13,6,14,9,3,12,2,11,7,15,8,10,5,1,4}, {15,5,1,14,6,11,2,4,13,7,12,9,3,10,8}, {10,9,1,8,13,5,11,7,3,14,4,12,6,2,15}, }; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.game2zhongdeng); gezi[0][0]=(Button)findViewById(R.id.game2_ZD_num1); gezi[0][1]=(Button)findViewById(R.id.game2_ZD_num2); gezi[0][2]=(Button)findViewById(R.id.game2_ZD_num3); gezi[0][3]=(Button)findViewById(R.id.game2_ZD_num4); gezi[1][0]=(Button)findViewById(R.id.game2_ZD_num5); gezi[1][1]=(Button)findViewById(R.id.game2_ZD_num6); gezi[1][2]=(Button)findViewById(R.id.game2_ZD_num7); gezi[1][3]=(Button)findViewById(R.id.game2_ZD_num8); gezi[2][0]=(Button)findViewById(R.id.game2_ZD_num9); gezi[2][1]=(Button)findViewById(R.id.game2_ZD_num10); gezi[2][2]=(Button)findViewById(R.id.game2_ZD_num11); gezi[2][3]=(Button)findViewById(R.id.game2_ZD_num12); gezi[3][0]=(Button)findViewById(R.id.game2_ZD_num13); gezi[3][1]=(Button)findViewById(R.id.game2_ZD_num14); gezi[3][2]=(Button)findViewById(R.id.game2_ZD_num15); gezi[3][3]=(Button)findViewById(R.id.game2_ZD_num16); text_step=(TextView)findViewById(R.id.znpt_zd_step); gameOver=(TextView)findViewById(R.id.game2_zd_Over); overStep=(TextView)findViewById(R.id.game2_zd_time_step); timer = (Chronometer)findViewById(R.id.myTimer); yidong_zd.setGezi(gezi); timer.setOnChronometerTickListener(this); int num = (int)(Math.random()*Init_gz.length); for( int i = 0 ; i < bc_gezi ; i ++ ){ for( int j = 0 ; j < bc_gezi ; j ++ ){ gezi[i][j].setOnClickListener(this); if( i == (bc_gezi-1) && j == (bc_gezi-1) ){ continue; } gezi[i][j].setText(Integer.toString(Init_gz[num][i*bc_gezi+j])); } } } public void onChronometerTick(Chronometer chronometer){ time ++; } public void onClick(View view){ for( int i = 0 ; i < bc_gezi ; i ++ ){ for( int j = 0 ; j < bc_gezi ; j ++ ){ if(view == gezi[i][j]){ if(yidong_zd.move(bc_gezi,i,j)){ step ++; text_step.setText(Integer.toString(step)); if(sign == 0){ timer.setBase(SystemClock.elapsedRealtime()); //���û�ʱ�� timer.start(); sign = 1; } if(yidong_zd.judge(bc_gezi)){ // ��Ϸ���� gameOver.setText("��Ϸ����"); overStep.setText("���ò���Ϊ"+Integer.toString(step)+"����ʱ��Ϊ"+Integer.toString(time)); gezi[bc_gezi-1][bc_gezi-1].setText("-1"); } } } } } } }
这就是最后修改好的中等程度代码,改完了的是没有问题的。