码迷,mamicode.com
首页 > 其他好文 > 详细

项目总结

时间:2017-05-31 00:19:23      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:wrap   win   param   button   ttext   imp   ati   拼图   integer   

通过了几个月坚持不懈的努力,我们组也终于完成了最终成果。关于趣拼图,我们从最初的界面设计到现在的完成,其中也经历了许多,也遇到了很多问题,但我们也都解决了,也从中了解到完成一个项目有多不容易,也从中体会到了团体合作的重要性,下面就先展示一下关于中等的拼图的代码经,这是经过修改最多的一个部分。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/game2_bg" >

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="100dp" >

<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/game2_zd_over" />

<TableLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:shrinkColumns="0"
android:stretchColumns="1" >
<TableRow>
<TextView
android:textSize="35sp"
android:text="@string/znpt_time"
android:textColor="#BFEFFF" />
<Chronometer
android:id="@+id/myTimer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="35sp"
android:textColor="#BFEFFF"
android:gravity="center" />
</TableRow>
<TableRow>
<TextView
android:textSize="35sp"
android:text="@string/bushu"
android:textColor="#BFEFFF" />
<TextView
android:id="@+id/znpt_zd_step"
android:textSize="35sp"
android:text="@string/num_init"
android:gravity="center"
android:textColor="#BFEFFF" />
</TableRow>
</TableLayout>
</LinearLayout>
<TextView
android:id="@+id/game2_zd_Over"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="30sp"
android:gravity="center"
android:text="" />
<TextView
android:id="@+id/game2_zd_time_step"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="30sp"
android:gravity="center"
android:text="" />

<GridLayout
android:id="@+id/game2_ZD"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:columnCount="4"
android:rowCount="4" >

<Button
android:id="@+id/game2_ZD_num1"
style="@style/gameZnptZhongDeng"
android:background="#D1EEEE" />
<Button
android:id="@+id/game2_ZD_num2"
style="@style/gameZnptZhongDeng"
android:background="#D1EEEE" />
<Button
android:id="@+id/game2_ZD_num3"
style="@style/gameZnptZhongDeng"
android:background="#D1EEEE" />
<Button
android:id="@+id/game2_ZD_num4"
style="@style/gameZnptZhongDeng"
android:background="#D1EEEE" />
<Button
android:id="@+id/game2_ZD_num5"
style="@style/gameZnptZhongDeng"
android:background="#D1EEEE" />
<Button
android:id="@+id/game2_ZD_num6"
style="@style/gameZnptZhongDeng"
android:background="#D1EEEE" />
<Button
android:id="@+id/game2_ZD_num7"
style="@style/gameZnptZhongDeng"
android:background="#D1EEEE" />
<Button
android:id="@+id/game2_ZD_num8"
style="@style/gameZnptZhongDeng"
android:background="#D1EEEE" />
<Button
android:id="@+id/game2_ZD_num9"
style="@style/gameZnptZhongDeng"
android:background="#D1EEEE" />
<Button
android:id="@+id/game2_ZD_num10"
style="@style/gameZnptZhongDeng"
android:background="#D1EEEE" />
<Button
android:id="@+id/game2_ZD_num11"
style="@style/gameZnptZhongDeng"
android:background="#D1EEEE" />
<Button
android:id="@+id/game2_ZD_num12"
style="@style/gameZnptZhongDeng"
android:background="#D1EEEE" />
<Button
android:id="@+id/game2_ZD_num13"
style="@style/gameZnptZhongDeng"
android:background="#D1EEEE" />
<Button
android:id="@+id/game2_ZD_num14"
style="@style/gameZnptZhongDeng"
android:background="#D1EEEE" />
<Button
android:id="@+id/game2_ZD_num15"
style="@style/gameZnptZhongDeng"
android:background="#D1EEEE" />
<Button
android:id="@+id/game2_ZD_num16"
style="@style/gameZnptZhongDeng"
android:background="#AAAAAA"
android:text="@string/num_tool"
android:textColor="#AAAAAA" />
</GridLayout>

</LinearLayout>
以及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");
}
}
}
}
}
}
}
这就是最后修改好的中等程度代码,改完了的是没有问题的。

项目总结

标签:wrap   win   param   button   ttext   imp   ati   拼图   integer   

原文地址:http://www.cnblogs.com/1502720106-HZH/p/6921814.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!