找回密码
 立即注册→加入我们

QQ登录

只需一步,快速开始

搜索
热搜: 下载 VB C 实现 编写
查看: 2650|回复: 1

自己动手实现android版2048

[复制链接]

307

主题

228

回帖

7349

积分

用户组: 真·技术宅

UID
2
精华
76
威望
291 点
宅币
5599 个
贡献
253 次
宅之契约
0 份
在线时间
949 小时
注册时间
2014-1-25
发表于 2014-5-25 18:09:58 | 显示全部楼层 |阅读模式

欢迎访问技术宅的结界,请注册或者登录吧。

您需要 登录 才可以下载或查看,没有账号?立即注册→加入我们

×
由于自己写的实验室版2048收到实验室同学热烈欢迎,他们建议我写android版的,所以我就写来给大家娱乐

MainActivity.java

  1. package com.game.lab2048;
  2. import java.util.ArrayList;
  3. import android.os.Bundle;
  4. import android.os.Handler;
  5. import android.app.Activity;
  6. import android.app.AlertDialog;
  7. import android.app.AlertDialog.Builder;
  8. import android.content.DialogInterface;
  9. import android.content.DialogInterface.OnClickListener;
  10. import android.content.Intent;
  11. import android.content.SharedPreferences;
  12. import android.view.GestureDetector;
  13. import android.view.GestureDetector.OnGestureListener;
  14. import android.view.Menu;
  15. import android.view.MotionEvent;
  16. import android.view.View;
  17. import android.view.View.OnTouchListener;
  18. import android.view.animation.AlphaAnimation;
  19. import android.view.animation.Animation;
  20. import android.view.animation.TranslateAnimation;
  21. import android.widget.EditText;
  22. import android.widget.LinearLayout;
  23. import android.widget.TextView;
  24. import android.widget.Toast;
  25. public class MainActivity extends Activity implements OnGestureListener
  26. {
  27. private static final float FLIP_DISTANCE = 80;
  28. private static final int DIRECTION_UP=0;
  29. private static final int DIRECTION_DOWN=1;
  30. private static final int DIRECTION_LEFT=2;
  31. private static final int DIRECTION_RIGHT=3;
  32. private static final int SIZE=5;

  33. private String username=null;//用户名
  34. private int score=0;//分数
  35. private int highestscore=0;//历史最高分
  36. private TextView tvID=null;//用户名显示
  37. private TextView tvHighest=null;//最高分显示
  38. private TextView tvTime=null;//时间显示
  39. private TextView tvMark=null;//分数显示
  40. private SharedPreferences sp=null;

  41. private Handler mtimer;//定时器
  42. private int begin=0;//时间起点
  43. private Runnable runnable=null;//定时器回调
  44. private int singlewidth=0;
  45. private int singleheight=0;
  46. private float barwidth=0;
  47. private GestureDetector detector=null;

  48. private TextView[][] Pics=new TextView[SIZE][SIZE];
  49. private int [][] Data=new int[SIZE][SIZE];

  50. @Override
  51. protected void onCreate(Bundle savedInstanceState)
  52. {
  53.   super.onCreate(savedInstanceState);
  54.   setContentView(R.layout.activity_main);
  55.   
  56.   runnable=new Runnable()
  57.   {
  58.    @Override
  59.    public void run()
  60.    {
  61.     tvTime.setText(begin+"s");
  62.     tvMark.setText(score+"");
  63.     mtimer.postDelayed(this, 1000);
  64.     begin++;
  65.    }
  66.   };
  67.   
  68.   mtimer=new Handler();
  69.   
  70.   tvID=(TextView)findViewById(R.id.ID);
  71.   tvMark=(TextView)findViewById(R.id.mark);
  72.   tvTime=(TextView)findViewById(R.id.time);
  73.   tvHighest=(TextView)findViewById(R.id.highestscore);
  74.   
  75.   sp=getSharedPreferences("LAB2048",Activity.MODE_PRIVATE);
  76.   username=sp.getString("ID","");
  77.   tvTime.setText("0");
  78.   
  79.   highestscore=sp.getInt("HighestScore",0);
  80.   tvHighest.setText(highestscore+"");
  81.   
  82.   if(username.equals(""))
  83.   {
  84.    AlertDialog.Builder builder=new AlertDialog.Builder(this);
  85.    builder.setIcon(R.drawable.ic_launcher);
  86.    builder.setTitle("请输入ID");
  87.    final EditText et=new EditText(this);
  88.    builder.setView(et);
  89.    builder.setPositiveButton("确定", new OnClickListener()
  90.    {
  91.     @Override
  92.     public void onClick(DialogInterface dialog, int which)
  93.     {
  94.      String input=et.getText().toString();
  95.      sp.edit().putString("ID",input).commit();
  96.      username=input;
  97.      tvID.setText(username);
  98.     }
  99.    });
  100.    builder.show();
  101.   }
  102.   
  103.   tvID.setText(username);
  104.   tvMark.setText("0");
  105.   
  106.   Pics[0][0]=(TextView)findViewById(R.id.t00);
  107.   Pics[0][1]=(TextView)findViewById(R.id.t01);
  108.   Pics[0][2]=(TextView)findViewById(R.id.t02);
  109.   Pics[0][3]=(TextView)findViewById(R.id.t03);
  110.   Pics[0][4]=(TextView)findViewById(R.id.t04);
  111.   Pics[1][0]=(TextView)findViewById(R.id.t10);
  112.   Pics[1][1]=(TextView)findViewById(R.id.t11);
  113.   Pics[1][2]=(TextView)findViewById(R.id.t12);
  114.   Pics[1][3]=(TextView)findViewById(R.id.t13);
  115.   Pics[1][4]=(TextView)findViewById(R.id.t14);
  116.   Pics[2][0]=(TextView)findViewById(R.id.t20);
  117.   Pics[2][1]=(TextView)findViewById(R.id.t21);
  118.   Pics[2][2]=(TextView)findViewById(R.id.t22);
  119.   Pics[2][3]=(TextView)findViewById(R.id.t23);
  120.   Pics[2][4]=(TextView)findViewById(R.id.t24);
  121.   Pics[3][0]=(TextView)findViewById(R.id.t30);
  122.   Pics[3][1]=(TextView)findViewById(R.id.t31);
  123.   Pics[3][2]=(TextView)findViewById(R.id.t32);
  124.   Pics[3][3]=(TextView)findViewById(R.id.t33);
  125.   Pics[3][4]=(TextView)findViewById(R.id.t34);
  126.   Pics[4][0]=(TextView)findViewById(R.id.t40);
  127.   Pics[4][1]=(TextView)findViewById(R.id.t41);
  128.   Pics[4][2]=(TextView)findViewById(R.id.t42);
  129.   Pics[4][3]=(TextView)findViewById(R.id.t43);
  130.   Pics[4][4]=(TextView)findViewById(R.id.t44);
  131.   
  132.   LinearLayout ll=(LinearLayout)findViewById(R.id.l00);
  133.   singlewidth=ll.getMeasuredWidth();
  134.   singleheight=ll.getMeasuredHeight();
  135.   barwidth=(float)(singlewidth-Pics[0][0].getMeasuredWidth())/2;
  136.   
  137.   detector=new GestureDetector(this);
  138.   
  139.   InitGame();
  140. }
  141. public int RGB(int r,int g,int b)
  142. {
  143.   return (0x7f<<24)|((r&0xff)<<16)|((g&0xff)<<8)|(b&0xff);
  144. }

  145. public void AfxMessageBox(String str)
  146. {
  147.   Toast.makeText(this, str, Toast.LENGTH_LONG).show();
  148. }

  149. //提交分数->排名  继续
  150. public void ShowInfo(int goal)
  151. {
  152.   switch(goal)
  153.   {
  154.    case 0x800:
  155.     AfxMessageBox("恭喜,拿下LV1 BOSS");
  156.     break;
  157.    case 0x1000:
  158.     AfxMessageBox("恭喜,拿下LV2 BOSS");
  159.     break;
  160.    case 0x2000:
  161.     AfxMessageBox("恭喜,拿下LV3 BOSS");
  162.     break;
  163.    case 0x4000:
  164.     AfxMessageBox("恭喜,拿下LV4 BOSS");
  165.     break;
  166.    case 0x8000:
  167.     AfxMessageBox("恭喜,拿下LV5 BOSS");
  168.     break;
  169.    case 0x10000:
  170.     AfxMessageBox("恭喜,拿下LV6 BOSS");
  171.     break;
  172.   }
  173. }

  174. public void InitGame()
  175. {
  176.   score=0;
  177.   
  178.   mtimer.removeCallbacks(runnable);
  179.   //开启定时器:mtimer.postDelayed(runnable,1000);
  180.   begin=0;
  181.   
  182.   for(int i=0;i<SIZE;i++)
  183.   {
  184.    for(int j=0;j<SIZE;j++)
  185.    {
  186.     Data[i][j]=0;
  187.    }
  188.   }
  189.   GetLeftCellsToRandomPlace();
  190. }

  191. public boolean GetLeftCellsToRandomPlace()
  192. {
  193.   ArrayList<Integer> left=new ArrayList<Integer>();
  194.   for(int i=0;i<SIZE;i++)
  195.   {
  196.    for(int j=0;j<SIZE;j++)
  197.    {
  198.     if(Data[i][j] == 0)
  199.      left.add(i*SIZE+j);
  200.    }
  201.   }
  202.   
  203.   if(left.size() == 0)
  204.    return false;
  205.   
  206.   int sel=(int) (Math.random()*left.size());
  207.   int ran=(int) (Math.random()*10);
  208.   int selx=left.get(sel)/SIZE;
  209.   int sely=left.get(sel)%SIZE;
  210.   if(ran != 0)
  211.   {
  212.    Data[selx][sely]=2;
  213.   }
  214.   else
  215.   {
  216.    Data[selx][sely]=4;
  217.   }
  218.   
  219.   StartBirthAnimation(selx,sely);
  220.   
  221.   Update();
  222.   return true;
  223. }

  224. public Animation StartMoveAnimation(int fromix,int fromiy,int toix,int toiy)
  225. {
  226.   float fromXDelta=0.0f,toXDelta=0.0f,fromYDelta=0.0f,toYDelta=0.0f;
  227.   fromXDelta=fromix*singlewidth+barwidth;
  228.   fromYDelta=fromiy*singleheight+barwidth;
  229.   toXDelta=toix*singlewidth+barwidth;
  230.   toYDelta=toiy*singleheight+barwidth;
  231.   View v=Pics[fromix][fromiy];
  232.   Animation anim=new TranslateAnimation(fromXDelta,toXDelta,fromYDelta,toYDelta);
  233.   anim.setDuration(200);
  234.   v.startAnimation(anim);
  235.   return anim;
  236. }

  237. public Animation StartBirthAnimation(int ix,int iy)
  238. {
  239.   View v=Pics[ix][iy];
  240.   Animation anim=new AlphaAnimation(0,1);
  241.   anim.setDuration(200);
  242.   v.startAnimation(anim);
  243.   return anim;
  244. }

  245. public Animation StartDieAnimation(int ix,int iy)
  246. {
  247.   View v=Pics[ix][iy];
  248.   Animation anim=new AlphaAnimation(1,0);
  249.   anim.setDuration(200);
  250.   v.startAnimation(anim);
  251.   return anim;
  252. }

  253. public int Get(int x,int y)
  254. {
  255.   return Data[x][y];
  256. }

  257. public void Set(int x,int y,int val)
  258. {
  259.   Data[x][y]=val;
  260. }

  261. public boolean Combine(int direction)//动画
  262. {
  263.   boolean moved=false;
  264.   switch(direction)
  265.   {
  266.    case DIRECTION_LEFT:
  267.    {
  268.     for(int l=0;l<SIZE;l++)
  269.     {
  270.      //两两向左合并
  271.      int first=0,second;
  272.      boolean over=false;
  273.      while(first<SIZE && !over)
  274.      {
  275.       while(first<SIZE-1 && Get(l,first) == 0)
  276.        first++;
  277.       
  278.       if(first>=SIZE-1)
  279.       {
  280.        over=true;
  281.        break;
  282.       }
  283.       second=first+1;
  284.       while(second<SIZE && Get(l,second) == 0)
  285.        second++;
  286.       if(second>=SIZE)
  287.       {
  288.        over=true;
  289.        break;
  290.       }
  291.       if(Get(l,first) == Get(l,second))
  292.       {
  293.        Set(l,first,Get(l,first)+Get(l,second));
  294.        StartMoveAnimation(l,second,l,first);
  295.        ShowInfo(Get(l,first));
  296.        Set(l,second,0);
  297.        moved=true;
  298.        first=second+1;
  299.       }
  300.       else
  301.       {
  302.        first=second;
  303.       }
  304.      }
  305.      
  306.      //全部向左聚集
  307.      first=0;
  308.      while(first < SIZE && Get(l,first) != 0)
  309.       first++;//找到第一个空白处
  310.      if(first<SIZE)
  311.      {
  312.       second=first+1;
  313.       while(second<SIZE)
  314.       {//找到下一个有值处
  315.        while(second<SIZE && Get(l,second) == 0)
  316.        {
  317.         second++;
  318.        }
  319.        if(second<SIZE)
  320.        {
  321.         Set(l,first,Get(l,second));
  322.         StartMoveAnimation(l,second,l,first);
  323.         Set(l,second,0);
  324.         first++;
  325.         second++;
  326.         moved=true;
  327.        }
  328.       }
  329.      }
  330.     }
  331.     break;
  332.    }
  333.    
  334.    case DIRECTION_RIGHT:
  335.    {
  336.     for(int l=0;l<SIZE;l++)
  337.     {
  338.      //两两向右合并
  339.      int first=0,second;
  340.      boolean over=false;
  341.      while(first<SIZE && !over)
  342.      {
  343.       while(first<SIZE-1 && Get(l,SIZE-1-first) == 0)
  344.        first++;
  345.       
  346.       if(first>=SIZE-1)
  347.       {
  348.        over=true;
  349.        break;
  350.       }
  351.       
  352.       second=first+1;
  353.       while(second<SIZE && Get(l,SIZE-1-second) == 0)
  354.        second++;
  355.       
  356.       if(second>=SIZE)
  357.       {
  358.        over=true;
  359.        break;
  360.       }
  361.       
  362.       if(Get(l,SIZE-1-first) == Get(l,SIZE-1-second))
  363.       {
  364.        Set(l,SIZE-1-first,Get(l,SIZE-1-first)+Get(l,SIZE-1-second));
  365.        StartMoveAnimation(l,SIZE-1-second,l,SIZE-1-first);
  366.        ShowInfo(Get(l,first));
  367.        Set(l,SIZE-1-second,0);
  368.        moved=true;
  369.        first=second+1;
  370.       }
  371.       else
  372.       {
  373.        first=second;
  374.       }
  375.      }
  376.      
  377.      //全部向右聚集
  378.      first=0;
  379.      while(first < SIZE && Get(l,SIZE-1-first) != 0)
  380.       first++;//找到第一个空白处
  381.      if(first<SIZE)
  382.      {
  383.       second=first+1;
  384.       while(second<SIZE)
  385.       {//找到下一个有值处
  386.        while(second<SIZE && Get(l,SIZE-1-second) == 0)
  387.        {
  388.         second++;
  389.        }
  390.        if(second<SIZE)
  391.        {
  392.         Set(l,SIZE-1-first,Get(l,SIZE-1-second));
  393.         StartMoveAnimation(l,SIZE-1-second,l,SIZE-1-first);
  394.         Set(l,SIZE-1-second,0);
  395.         first++;
  396.         second++;
  397.         moved=true;
  398.        }
  399.       }
  400.      }
  401.     }
  402.     break;
  403.    }
  404.    
  405.    case DIRECTION_UP:
  406.    {
  407.     for(int c=0;c<SIZE;c++)
  408.     {
  409.      //两两向上合并
  410.      int first=0,second;
  411.      boolean over=false;
  412.      while(first<SIZE && !over)
  413.      {
  414.       while(first<SIZE-1 && Get(first,c) == 0)
  415.        first++;
  416.       
  417.       if(first>=SIZE-1)
  418.       {
  419.        over=true;
  420.        break;
  421.       }
  422.       
  423.       second=first+1;
  424.       while(second<SIZE && Get(second,c) == 0)
  425.        second++;
  426.       
  427.       if(second>=SIZE)
  428.       {
  429.        over=true;
  430.        break;
  431.       }
  432.       
  433.       if(Get(first,c) == Get(second,c))
  434.       {
  435.        Set(first,c,Get(first,c)+Get(second,c));
  436.        StartMoveAnimation(second,c,first,c);
  437.        ShowInfo(Get(first,c));
  438.        Set(second,c,0);
  439.        moved=true;
  440.        first=second+1;
  441.       }
  442.       else
  443.       {
  444.        first=second;
  445.       }
  446.      }
  447.      
  448.      //全部向上聚集
  449.      first=0;
  450.      while(first < SIZE && Get(first,c) != 0)
  451.       first++;//找到第一个空白处
  452.      if(first<SIZE)
  453.      {
  454.       second=first+1;
  455.       while(second<SIZE)
  456.       {//找到下一个有值处
  457.        while(second<SIZE && Get(second,c) == 0)
  458.        {
  459.         second++;
  460.        }
  461.        if(second<SIZE)
  462.        {
  463.         Set(first,c,Get(second,c));
  464.         StartMoveAnimation(second,c,first,c);
  465.         Set(second,c,0);
  466.         first++;
  467.         second++;
  468.         moved=true;
  469.        }
  470.       }
  471.      }
  472.     }
  473.     break;
  474.    }
  475.    
  476.    case DIRECTION_DOWN:
  477.    {
  478.     for(int c=0;c<SIZE;c++)
  479.     {
  480.      //两两向右合并
  481.      int first=0,second;
  482.      boolean over=false;
  483.      while(first<SIZE && !over)
  484.      {
  485.       while(first<SIZE-1 && Get(SIZE-1-first,c) == 0)
  486.        first++;
  487.       
  488.       if(first>=SIZE-1)
  489.       {
  490.        over=true;
  491.        break;
  492.       }
  493.       
  494.       second=first+1;
  495.       while(second<SIZE && Get(SIZE-1-second,c) == 0)
  496.        second++;
  497.       
  498.       if(second>=SIZE)
  499.       {
  500.        over=true;
  501.        break;
  502.       }
  503.       
  504.       if(Get(SIZE-1-first,c) == Get(SIZE-1-second,c))
  505.       {
  506.        Set(SIZE-1-first,c,Get(SIZE-1-first,c)+Get(SIZE-1-second,c));
  507.        StartMoveAnimation(SIZE-1-second,c,SIZE-1-first,c);
  508.        ShowInfo(Get(first,c));
  509.        Set(SIZE-1-second,c,0);
  510.        moved=true;
  511.        first=second+1;
  512.       }
  513.       else
  514.       {
  515.        first=second;
  516.       }
  517.      }
  518.      
  519.      //全部向右聚集
  520.      first=0;
  521.      while(first < SIZE && Get(SIZE-1-first,c) != 0)
  522.       first++;//找到第一个空白处
  523.      if(first<SIZE)
  524.      {
  525.       second=first+1;
  526.       while(second<SIZE)
  527.       {//找到下一个有值处
  528.        while(second<SIZE && Get(SIZE-1-second,c) == 0)
  529.        {
  530.         second++;
  531.        }
  532.        if(second<SIZE)
  533.        {
  534.         Set(SIZE-1-first,c,Get(SIZE-1-second,c));
  535.         StartMoveAnimation(SIZE-1-second,c,SIZE-1-first,c);
  536.         Set(SIZE-1-second,c,0);
  537.         first++;
  538.         second++;
  539.         moved=true;
  540.        }
  541.       }
  542.      }
  543.     }
  544.     break;
  545.    }
  546.   }
  547.   return moved;
  548. }

  549. public boolean Judge()
  550. {
  551.   int i,j;
  552.   for(i=0;i<SIZE;i++)
  553.   {
  554.    for(j=0;j<SIZE;j++)
  555.    {
  556.     if(Data[i][j] == 0)
  557.      return true;
  558.     if(i+1 < SIZE && Data[i][j] == Data[i+1][j])
  559.      return true;
  560.     if(j+1 < SIZE && Data[i][j] == Data[i][j+1])
  561.      return true;
  562.    }
  563.   }
  564.   
  565.   return false;
  566. }

  567. public int getColor(int val)
  568. {
  569.   switch(val)
  570.   {
  571.    case 0x0:
  572.     return RGB(255,255,255);
  573.    case 0x2:
  574.     return RGB(124,252,0);
  575.    case 0x4:
  576.     return RGB(102,205,170);
  577.    case 0x8:
  578.     return RGB(205,92,92);
  579.    case 0x10:
  580.     return RGB(255,215,0);
  581.    case 0x20:
  582.     return RGB(255,140,0);
  583.    case 0x40:
  584.     return RGB(219,112,147);
  585.    case 0x80:
  586.     return RGB(135,206,215);
  587.    case 0x100:
  588.     return RGB(0,0,255);
  589.    case 0x200:
  590.     return RGB(123,104,235);
  591.    case 0x400:
  592.     return RGB(0,255,0);
  593.    case 0x800:
  594.     return RGB(255,0,0);
  595.    case 0x1000:
  596.     return RGB(0,255,255);
  597.    case 0x2000:
  598.     return RGB(255,0,255);
  599.    case 0x4000:
  600.     return RGB(255,255,0);
  601.    case 0x8000:
  602.     return RGB(128,128,128);
  603.    case 0x10000:
  604.     return RGB(0,0,0);
  605.    default:
  606.     return RGB(0,0,0);
  607.   }
  608. }

  609. //相对于OnPaint
  610. public void Update()
  611. {
  612.   for(int i=0;i<SIZE;i++)
  613.   {
  614.    for(int j=0;j<SIZE;j++)
  615.    {
  616.     int color=getColor(Data[i][j]);
  617.     Pics[i][j].setBackgroundColor(color);
  618.     Pics[i][j].setTextColor(0xFF000000);
  619.     String buffer="";
  620.     switch(Data[i][j])
  621.     {
  622.      case 0x0:
  623.       break;
  624.    
  625.      case 0x2:
  626.       buffer="周志中";
  627.       break;
  628.       
  629.      case 0x4:
  630.       buffer="庞启雄";
  631.       break;

  632.      case 0x8:
  633.       buffer="刘柳";
  634.       break;

  635.      case 0x10:
  636.       buffer="汪松兴";
  637.       break;

  638.      case 0x20:
  639.       buffer="夏航宇";
  640.       break;

  641.      case 0x40:
  642.       buffer="李妍";
  643.       break;

  644.      case 0x80:
  645.       buffer="徐蕾";
  646.       break;

  647.      case 0x100:
  648.       buffer="李超";
  649.       break;

  650.      case 0x200:
  651.       buffer="吴云";
  652.       break;

  653.      case 0x400:
  654.       buffer="田原";
  655.       break;

  656.      case 0x800:
  657.       buffer="卢老师";
  658.       break;

  659.      case 0x1000:
  660.       buffer="胡老师";
  661.       break;

  662.      case 0x2000:
  663.       buffer="沈老师";
  664.       break;

  665.      case 0x4000:
  666.       buffer="孙院长";
  667.       break;

  668.      case 0x8000:
  669.       buffer="肖国镇";

  670.      default:
  671.       buffer="神";
  672.       break;
  673.     }
  674.     Pics[i][j].setText(buffer);
  675.    }
  676.   }
  677. }
  678. @Override
  679. public boolean onDown(MotionEvent e)
  680. {
  681.   return false;
  682. }
  683. @Override
  684. public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,float velocityY)
  685. {
  686.   int direction=-1;
  687.   if(e1.getX() - e2.getX() > FLIP_DISTANCE)
  688.   {
  689.    direction=DIRECTION_LEFT;
  690.   }
  691.   else if(e2.getX() - e1.getX() > FLIP_DISTANCE)
  692.   {
  693.    direction=DIRECTION_RIGHT;
  694.   }
  695.   
  696.   if(e1.getY() - e2.getY() > FLIP_DISTANCE)
  697.   {
  698.    direction=DIRECTION_UP;
  699.   }
  700.   else if(e2.getY() - e1.getY() > FLIP_DISTANCE)
  701.   {
  702.    direction=DIRECTION_DOWN;
  703.   }
  704.   
  705.   if(direction != -1)
  706.   {
  707.    if(Combine(direction))
  708.    {
  709.     GetLeftCellsToRandomPlace();
  710.     if(score == 0)
  711.     {
  712.      mtimer.postDelayed(runnable,1000);
  713.      begin=0;
  714.     }
  715.    
  716.     score += 100;
  717.     if(!Judge())
  718.     {
  719.      String str1,str2;
  720.      if(MeasureScore())
  721.       str1="失败!";
  722.      else
  723.       str1="成功!";
  724.      str2="最终得分:"+score;
  725.      
  726.       
  727.      if(score > highestscore)
  728.      {
  729.       highestscore=score;
  730.       tvHighest.setText(highestscore+"");
  731.       sp.edit().putInt("HighestScore",highestscore).commit();
  732.      }
  733.      AlertDialog.Builder builder=new AlertDialog.Builder(this);
  734.      builder.setTitle(str1);
  735.      builder.setMessage(str2);
  736.      builder.setPositiveButton("上传成绩",new OnClickListener()
  737.      {
  738.       @Override
  739.       public void onClick(DialogInterface dialog, int which)
  740.       {
  741.        Intent intent=new Intent(MainActivity.this,UploadMark.class);
  742.        intent.putExtra("id",username);
  743.        intent.putExtra("score",score);
  744.        startActivity(intent);
  745.        mtimer.removeCallbacks(runnable);
  746.        InitGame();
  747.       }
  748.      });
  749.      builder.setNegativeButton("继续游戏",new OnClickListener()
  750.      {
  751.       @Override
  752.       public void onClick(DialogInterface dialog, int which)
  753.       {
  754.        mtimer.removeCallbacks(runnable);
  755.        InitGame();
  756.       }
  757.      });
  758.      
  759.      builder.show();
  760.     }
  761.    }
  762.    return true;
  763.   }
  764.   return false;
  765. }
  766. public boolean MeasureScore()
  767. {
  768.   int measuredscore=0;
  769.   for(int i=0;i<SIZE;i++)
  770.   {
  771.    for(int j=0;j<SIZE;j++)
  772.    {
  773.     int val=Get(i,j);
  774.     if(val >= 2048)
  775.     {
  776.      measuredscore += val*100;
  777.     }
  778.    }
  779.   }
  780.   score += measuredscore;
  781.   if(measuredscore != 0)
  782.    return true;
  783.   else
  784.    return false;
  785. }

  786. @Override
  787. public void onLongPress(MotionEvent e)
  788. {
  789. }
  790. @Override
  791. public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,float distanceY)
  792. {
  793.   return false;
  794. }
  795. @Override
  796. public void onShowPress(MotionEvent e)
  797. {  
  798. }
  799. @Override
  800. public boolean onSingleTapUp(MotionEvent e)
  801. {
  802.   return false;
  803. }
  804. @Override
  805. public boolean onTouchEvent(MotionEvent event)
  806. {
  807.   return detector.onTouchEvent(event);
  808. }
  809. }

复制代码



UploadMark.java

  1. package com.game.lab2048;
  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import java.net.URL;
  5. import java.net.URLConnection;
  6. import java.util.ArrayList;
  7. import org.apache.http.HttpEntity;
  8. import org.apache.http.HttpResponse;
  9. import org.apache.http.StatusLine;
  10. import org.apache.http.client.ClientProtocolException;
  11. import org.apache.http.client.HttpResponseException;
  12. import org.apache.http.client.methods.HttpGet;
  13. import org.apache.http.impl.client.DefaultHttpClient;
  14. import org.xmlpull.v1.XmlPullParser;
  15. import org.xmlpull.v1.XmlPullParserException;
  16. import android.app.Activity;
  17. import android.content.Intent;
  18. import android.os.Bundle;
  19. import android.os.Handler;
  20. import android.os.Message;
  21. import android.util.Log;
  22. import android.util.Xml;
  23. import android.view.View;
  24. import android.view.ViewGroup;
  25. import android.widget.BaseAdapter;
  26. import android.widget.ListView;
  27. import android.widget.TextView;
  28. import android.widget.Toast;
  29. public class UploadMark extends Activity
  30. {
  31. private static final String TAG = "UploadMark";
  32. private String id=null;
  33. private String score=null;
  34. private ArrayList<data> da=new ArrayList<data>();
  35. private ListView list=null;
  36. private BaseAdapter adapter=null;

  37. private final class MyAdapter extends BaseAdapter
  38. {
  39.   @Override
  40.   public int getCount()
  41.   {
  42.    return da.size();
  43.   }
  44.   @Override
  45.   public long getItemId(int position)
  46.   {
  47.    return position;
  48.   }
  49.   @Override
  50.   public View getView(int position, View convertView, ViewGroup parent)
  51.   {
  52.    TextView tv=new TextView(UploadMark.this);
  53.    tv.setText(da.get(position).id+":"+da.get(position).score);
  54.    return tv;
  55.   }
  56.   @Override
  57.   public Object getItem(int position)
  58.   {
  59.    // TODO Auto-generated method stub
  60.    return null;
  61.   }
  62. }
  63. class data
  64. {
  65.   private String id;
  66.   private String score;
  67.   public String getId()
  68.   {
  69.    return id;
  70.   }
  71.   
  72.   public void setId(String id)
  73.   {
  74.    this.id = id;
  75.   }
  76.   
  77.   public String getScore()
  78.   {
  79.    return score;
  80.   }
  81.   
  82.   public void setScore(String score)
  83.   {
  84.    this.score = score;
  85.   }
  86. }

  87. @Override
  88. protected void onCreate(Bundle savedInstanceState)
  89. {
  90.   super.onCreate(savedInstanceState);
  91.   setContentView(R.layout.query);
  92.   
  93.   list=(ListView)findViewById(R.id.list);
  94.   adapter=new MyAdapter();
  95.   list.setAdapter(adapter);
  96.   
  97.   Intent intent=getIntent();
  98.   id=intent.getStringExtra("id");
  99.   score=intent.getStringExtra("score");

  100.   final Handler handler=new Handler()
  101.   {
  102.    @Override
  103.    public void handleMessage(Message msg)
  104.    {
  105.     adapter.notifyDataSetChanged();
  106.    }
  107.   };
  108.   
  109.   new Thread()
  110.   {
  111.    @Override
  112.    public void run()
  113.    {
  114.     try
  115.     {
  116.      getData(handler);
  117.     }
  118.     catch (XmlPullParserException e)
  119.     {
  120.      // TODO Auto-generated catch block
  121.      e.printStackTrace();
  122.     }  
  123.    }
  124.   }.start();
  125. }
  126. private void getData(final Handler handler) throws XmlPullParserException
  127. {
  128.   String url="[url=http://169.254.132.185:8080/game.jsp?id=]http://169.254.132.185:8080/game.jsp?id="+id+"&score="+score[/url];
  129.   
  130.   try
  131.   {
  132.    URLConnection conn=new URL(url).openConnection();
  133.    InputStream instream = conn.getInputStream();
  134.    data curdata=null;
  135.    
  136.    XmlPullParser parser=Xml.newPullParser();
  137.    parser.setInput(instream,"utf-8");
  138.    int type=parser.getEventType();
  139.    while(type != XmlPullParser.END_DOCUMENT)
  140.    {
  141.     if(type == XmlPullParser.START_TAG)
  142.     {
  143.      String name=parser.getName();
  144.      if("item".equals(name))
  145.      {
  146.       curdata=new data();
  147.      }
  148.      else if("id".equals(name))
  149.      {
  150.       curdata.setId(parser.nextText());
  151.      }
  152.      else if("score".equals(name))
  153.      {
  154.       curdata.setScore(parser.nextText());
  155.      }
  156.     }
  157.     else if(type == XmlPullParser.END_TAG)
  158.     {
  159.      String name=parser.getName();
  160.      if("item".equals(name))
  161.      {
  162.       da.add(curdata);
  163.      }
  164.     }
  165.     type=parser.next();
  166.    }
  167.    instream.close();
  168.    if(handler != null)
  169.     handler.sendEmptyMessage(0);
  170.   }
  171.   catch(Exception e)
  172.   {
  173.    e.printStackTrace();
  174.   }
  175. }
  176. }

复制代码


activity_main.xml

  1. <LinearLayout xmlns:android="[url=http://schemas.android.com/apk/res/android]http://schemas.android.com/apk/res/android[/url]"
  2.     xmlns:tools="[url=http://schemas.android.com/tools]http://schemas.android.com/tools[/url]"
  3.     android:layout_width="match_parent"
  4.     android:layout_height="match_parent"
  5.     android:orientation="vertical"
  6.     android:id="@+id/mainll"
  7.     android:background="#FFFFFF">
  8.     <LinearLayout
  9.         android:layout_width="match_parent"
  10.         android:layout_height="match_parent"
  11.         android:orientation="horizontal"
  12.         android:layout_weight="1">
  13.         
  14.         <LinearLayout
  15.             android:id="@+id/l00"
  16.             android:layout_width="match_parent"
  17.             android:layout_height="match_parent"
  18.             android:gravity="center"
  19.             android:background="@drawable/outline"
  20.             android:padding="5dip"
  21.             android:layout_weight="1">
  22.         
  23.          <TextView
  24.              android:id="@+id/t00"
  25.              android:layout_width="match_parent"
  26.              android:layout_height="match_parent"
  27.              android:gravity="center"
  28.              android:text=""
  29.              android:background="@null"/>
  30.         
  31.         </LinearLayout>
  32.         
  33.         <LinearLayout
  34.             android:id="@+id/l01"
  35.             android:layout_width="match_parent"
  36.             android:layout_height="match_parent"
  37.             android:gravity="center"
  38.             android:background="@drawable/outline"
  39.             android:padding="5dip"
  40.             android:layout_weight="1">
  41.         
  42.          <TextView
  43.              android:id="@+id/t01"
  44.              android:layout_width="match_parent"
  45.              android:layout_height="match_parent"
  46.              android:gravity="center"
  47.              android:text=""
  48.              android:background="@null"/>
  49.         
  50.         </LinearLayout>
  51.         
  52.         <LinearLayout
  53.             android:id="@+id/l02"
  54.             android:layout_width="match_parent"
  55.             android:layout_height="match_parent"
  56.             android:gravity="center"
  57.             android:background="@drawable/outline"
  58.             android:padding="5dip"
  59.             android:layout_weight="1">
  60.         
  61.          <TextView
  62.              android:id="@+id/t02"
  63.              android:layout_width="match_parent"
  64.              android:layout_height="match_parent"
  65.              android:gravity="center"
  66.              android:text=""
  67.              android:background="@null"/>
  68.         
  69.         </LinearLayout>
  70.         
  71.         <LinearLayout
  72.             android:id="@+id/l03"
  73.             android:layout_width="match_parent"
  74.             android:layout_height="match_parent"
  75.             android:gravity="center"
  76.             android:background="@drawable/outline"
  77.             android:padding="5dip"
  78.             android:layout_weight="1">
  79.         
  80.          <TextView
  81.              android:id="@+id/t03"
  82.              android:layout_width="match_parent"
  83.              android:layout_height="match_parent"
  84.              android:gravity="center"
  85.              android:text=""
  86.              android:background="@null"/>
  87.         
  88.         </LinearLayout>        
  89.         
  90.         <LinearLayout
  91.             android:id="@+id/l04"
  92.             android:layout_width="match_parent"
  93.             android:layout_height="match_parent"
  94.             android:gravity="center"
  95.             android:background="@drawable/outline"
  96.             android:padding="5dip"
  97.             android:layout_weight="1">
  98.         
  99.          <TextView
  100.              android:id="@+id/t04"
  101.              android:layout_width="match_parent"
  102.              android:layout_height="match_parent"
  103.              android:gravity="center"
  104.              android:text=""
  105.              android:background="@null"/>
  106.         
  107.         </LinearLayout>
  108.         
  109.     </LinearLayout>
  110.    
  111.     <LinearLayout
  112.         android:layout_width="match_parent"
  113.         android:layout_height="match_parent"
  114.         android:orientation="horizontal"
  115.         android:layout_weight="1">
  116.         
  117.         <LinearLayout
  118.             android:id="@+id/l10"
  119.             android:layout_width="match_parent"
  120.             android:layout_height="match_parent"
  121.             android:gravity="center"
  122.             android:background="@drawable/outline"
  123.             android:padding="5dip"
  124.             android:layout_weight="1">
  125.         
  126.          <TextView
  127.              android:id="@+id/t10"
  128.              android:layout_width="match_parent"
  129.              android:layout_height="match_parent"
  130.              android:gravity="center"
  131.              android:text=""
  132.              android:background="@null"/>
  133.         
  134.         </LinearLayout>
  135.         
  136.         <LinearLayout
  137.             android:id="@+id/l11"
  138.             android:layout_width="match_parent"
  139.             android:layout_height="match_parent"
  140.             android:gravity="center"
  141.             android:background="@drawable/outline"
  142.             android:padding="5dip"
  143.             android:layout_weight="1">
  144.         
  145.          <TextView
  146.              android:id="@+id/t11"
  147.              android:layout_width="match_parent"
  148.              android:layout_height="match_parent"
  149.              android:gravity="center"
  150.              android:text=""
  151.              android:background="@null"/>
  152.         
  153.         </LinearLayout>
  154.         
  155.         <LinearLayout
  156.             android:id="@+id/l12"
  157.             android:layout_width="match_parent"
  158.             android:layout_height="match_parent"
  159.             android:gravity="center"
  160.             android:background="@drawable/outline"
  161.             android:padding="5dip"
  162.             android:layout_weight="1">
  163.         
  164.          <TextView
  165.              android:id="@+id/t12"
  166.              android:layout_width="match_parent"
  167.              android:layout_height="match_parent"
  168.              android:gravity="center"
  169.              android:text=""
  170.              android:background="@null"/>
  171.         
  172.         </LinearLayout>
  173.         
  174.         <LinearLayout
  175.             android:id="@+id/l13"
  176.             android:layout_width="match_parent"
  177.             android:layout_height="match_parent"
  178.             android:gravity="center"
  179.             android:background="@drawable/outline"
  180.             android:padding="5dip"
  181.             android:layout_weight="1">
  182.         
  183.          <TextView
  184.              android:id="@+id/t13"
  185.              android:layout_width="match_parent"
  186.              android:layout_height="match_parent"
  187.              android:gravity="center"
  188.              android:text=""
  189.              android:background="@null"/>
  190.         
  191.         </LinearLayout>
  192.         <LinearLayout
  193.             android:id="@+id/l14"
  194.             android:layout_width="match_parent"
  195.             android:layout_height="match_parent"
  196.             android:gravity="center"
  197.             android:background="@drawable/outline"
  198.             android:padding="5dip"
  199.             android:layout_weight="1">
  200.         
  201.          <TextView
  202.              android:id="@+id/t14"
  203.              android:layout_width="match_parent"
  204.              android:layout_height="match_parent"
  205.              android:gravity="center"
  206.              android:text=""
  207.              android:background="@null"/>
  208.         
  209.         </LinearLayout>
  210.         
  211.     </LinearLayout>
  212.    
  213.     <LinearLayout
  214.         android:layout_width="match_parent"
  215.         android:layout_height="match_parent"
  216.         android:orientation="horizontal"
  217.         android:layout_weight="1">
  218.         
  219.         <LinearLayout
  220.             android:id="@+id/l20"
  221.             android:layout_width="match_parent"
  222.             android:layout_height="match_parent"
  223.             android:gravity="center"
  224.             android:background="@drawable/outline"
  225.             android:padding="5dip"
  226.             android:layout_weight="1">
  227.         
  228.          <TextView
  229.              android:id="@+id/t20"
  230.              android:layout_width="match_parent"
  231.              android:layout_height="match_parent"
  232.              android:gravity="center"
  233.              android:text=""
  234.              android:background="@null"/>
  235.         
  236.         </LinearLayout>
  237.         
  238.         <LinearLayout
  239.             android:id="@+id/l21"
  240.             android:layout_width="match_parent"
  241.             android:layout_height="match_parent"
  242.             android:gravity="center"
  243.             android:background="@drawable/outline"
  244.             android:padding="5dip"
  245.             android:layout_weight="1">
  246.         
  247.          <TextView
  248.              android:id="@+id/t21"
  249.              android:layout_width="match_parent"
  250.              android:layout_height="match_parent"
  251.              android:gravity="center"
  252.              android:text=""
  253.              android:background="@null"/>
  254.         
  255.         </LinearLayout>
  256.         
  257.         <LinearLayout
  258.             android:id="@+id/l22"
  259.             android:layout_width="match_parent"
  260.             android:layout_height="match_parent"
  261.             android:gravity="center"
  262.             android:background="@drawable/outline"
  263.             android:padding="5dip"
  264.             android:layout_weight="1">
  265.         
  266.          <TextView
  267.              android:id="@+id/t22"
  268.              android:layout_width="match_parent"
  269.              android:layout_height="match_parent"
  270.              android:gravity="center"
  271.              android:text=""
  272.              android:background="@null"/>
  273.         
  274.         </LinearLayout>
  275.         
  276.         <LinearLayout
  277.             android:id="@+id/l23"
  278.             android:layout_width="match_parent"
  279.             android:layout_height="match_parent"
  280.             android:gravity="center"
  281.             android:background="@drawable/outline"
  282.             android:padding="5dip"
  283.             android:layout_weight="1">
  284.         
  285.          <TextView
  286.              android:id="@+id/t23"
  287.              android:layout_width="match_parent"
  288.              android:layout_height="match_parent"
  289.              android:gravity="center"
  290.              android:text=""
  291.              android:background="@null"/>
  292.         
  293.         </LinearLayout>
  294.         <LinearLayout
  295.             android:id="@+id/l24"
  296.             android:layout_width="match_parent"
  297.             android:layout_height="match_parent"
  298.             android:gravity="center"
  299.             android:background="@drawable/outline"
  300.             android:padding="5dip"
  301.             android:layout_weight="1">
  302.         
  303.          <TextView
  304.              android:id="@+id/t24"
  305.              android:layout_width="match_parent"
  306.              android:layout_height="match_parent"
  307.              android:gravity="center"
  308.              android:text=""
  309.              android:background="@null"/>
  310.         
  311.         </LinearLayout>
  312.         
  313.     </LinearLayout>
  314.    
  315.     <LinearLayout
  316.         android:layout_width="match_parent"
  317.         android:layout_height="match_parent"
  318.         android:orientation="horizontal"
  319.         android:layout_weight="1">
  320.         
  321.         <LinearLayout
  322.             android:id="@+id/l30"
  323.             android:layout_width="match_parent"
  324.             android:layout_height="match_parent"
  325.             android:gravity="center"
  326.             android:background="@drawable/outline"
  327.             android:padding="5dip"
  328.             android:layout_weight="1">
  329.         
  330.          <TextView
  331.              android:id="@+id/t30"
  332.              android:layout_width="match_parent"
  333.              android:layout_height="match_parent"
  334.              android:gravity="center"
  335.              android:text=""
  336.              android:background="@null"/>
  337.         
  338.         </LinearLayout>
  339.         
  340.         <LinearLayout
  341.             android:id="@+id/l31"
  342.             android:layout_width="match_parent"
  343.             android:layout_height="match_parent"
  344.             android:gravity="center"
  345.             android:background="@drawable/outline"
  346.             android:padding="5dip"
  347.             android:layout_weight="1">
  348.         
  349.          <TextView
  350.              android:id="@+id/t31"
  351.              android:layout_width="match_parent"
  352.              android:layout_height="match_parent"
  353.              android:gravity="center"
  354.              android:text=""
  355.              android:background="@null"/>
  356.         
  357.         </LinearLayout>
  358.         
  359.         <LinearLayout
  360.             android:id="@+id/l32"
  361.             android:layout_width="match_parent"
  362.             android:layout_height="match_parent"
  363.             android:gravity="center"
  364.             android:background="@drawable/outline"
  365.             android:padding="5dip"
  366.             android:layout_weight="1">
  367.         
  368.          <TextView
  369.              android:id="@+id/t32"
  370.              android:layout_width="match_parent"
  371.              android:layout_height="match_parent"
  372.              android:gravity="center"
  373.              android:text=""
  374.              android:background="@null"/>
  375.         
  376.         </LinearLayout>
  377.         
  378.         <LinearLayout
  379.             android:id="@+id/l33"
  380.             android:layout_width="match_parent"
  381.             android:layout_height="match_parent"
  382.             android:gravity="center"
  383.             android:background="@drawable/outline"
  384.             android:padding="5dip"
  385.             android:layout_weight="1">
  386.         
  387.          <TextView
  388.              android:id="@+id/t33"
  389.              android:layout_width="match_parent"
  390.              android:layout_height="match_parent"
  391.              android:gravity="center"
  392.              android:text=""
  393.              android:background="@null"/>
  394.         
  395.         </LinearLayout>
  396.         <LinearLayout
  397.             android:id="@+id/l34"
  398.             android:layout_width="match_parent"
  399.             android:layout_height="match_parent"
  400.             android:gravity="center"
  401.             android:background="@drawable/outline"
  402.             android:padding="5dip"
  403.             android:layout_weight="1">
  404.         
  405.          <TextView
  406.              android:id="@+id/t34"
  407.              android:layout_width="match_parent"
  408.              android:layout_height="match_parent"
  409.              android:gravity="center"
  410.              android:text=""
  411.              android:background="@null"/>
  412.         
  413.         </LinearLayout>
  414.         
  415.     </LinearLayout>
  416.    
  417.     <LinearLayout
  418.         android:layout_width="match_parent"
  419.         android:layout_height="match_parent"
  420.         android:orientation="horizontal"
  421.         android:layout_weight="1">
  422.         
  423.         <LinearLayout
  424.             android:id="@+id/l40"
  425.             android:layout_width="match_parent"
  426.             android:layout_height="match_parent"
  427.             android:gravity="center"
  428.             android:background="@drawable/outline"
  429.             android:padding="5dip"
  430.             android:layout_weight="1">
  431.         
  432.          <TextView
  433.              android:id="@+id/t40"
  434.              android:layout_width="match_parent"
  435.              android:layout_height="match_parent"
  436.              android:gravity="center"
  437.              android:text=""
  438.              android:background="@null"/>
  439.         
  440.         </LinearLayout>
  441.         
  442.         <LinearLayout
  443.             android:id="@+id/l41"
  444.             android:layout_width="match_parent"
  445.             android:layout_height="match_parent"
  446.             android:gravity="center"
  447.             android:background="@drawable/outline"
  448.             android:padding="5dip"
  449.             android:layout_weight="1">
  450.         
  451.          <TextView
  452.              android:id="@+id/t41"
  453.              android:layout_width="match_parent"
  454.              android:layout_height="match_parent"
  455.              android:gravity="center"
  456.              android:text=""
  457.              android:background="@null"/>
  458.         
  459.         </LinearLayout>
  460.         
  461.         <LinearLayout
  462.             android:id="@+id/l42"
  463.             android:layout_width="match_parent"
  464.             android:layout_height="match_parent"
  465.             android:gravity="center"
  466.             android:background="@drawable/outline"
  467.             android:padding="5dip"
  468.             android:layout_weight="1">
  469.         
  470.          <TextView
  471.              android:id="@+id/t42"
  472.              android:layout_width="match_parent"
  473.              android:layout_height="match_parent"
  474.              android:gravity="center"
  475.              android:text=""
  476.              android:background="@null"/>
  477.         
  478.         </LinearLayout>
  479.         
  480.         <LinearLayout
  481.             android:id="@+id/l43"
  482.             android:layout_width="match_parent"
  483.             android:layout_height="match_parent"
  484.             android:gravity="center"
  485.             android:background="@drawable/outline"
  486.             android:padding="5dip"
  487.             android:layout_weight="1">
  488.         
  489.          <TextView
  490.              android:id="@+id/t43"
  491.              android:layout_width="match_parent"
  492.              android:layout_height="match_parent"
  493.              android:gravity="center"
  494.              android:text=""
  495.              android:background="@null"/>
  496.         
  497.         </LinearLayout>
  498.         <LinearLayout
  499.             android:id="@+id/l44"
  500.             android:layout_width="match_parent"
  501.             android:layout_height="match_parent"
  502.             android:gravity="center"
  503.             android:background="@drawable/outline"
  504.             android:padding="5dip"
  505.             android:layout_weight="1">
  506.         
  507.          <TextView
  508.              android:id="@+id/t44"
  509.              android:layout_width="match_parent"
  510.              android:layout_height="match_parent"
  511.              android:gravity="center"
  512.              android:text=""
  513.              android:background="@null"/>
  514.         
  515.         </LinearLayout>
  516.         
  517.     </LinearLayout>
  518.    
  519.     <LinearLayout
  520.         android:layout_width="match_parent"
  521.         android:layout_height="match_parent"
  522.         android:orientation="horizontal"
  523.         android:layout_weight="1">
  524.         
  525.         <TextView
  526.             android:layout_width="match_parent"
  527.             android:layout_height="match_parent"
  528.             android:layout_weight="1"
  529.             android:gravity="center_horizontal|bottom"
  530.             android:text="ID:"/>
  531.         
  532.         <TextView
  533.             android:id="@+id/ID"
  534.             android:layout_width="match_parent"
  535.             android:layout_height="match_parent"
  536.             android:layout_weight="1"
  537.             android:gravity="bottom|left"
  538.             android:text="ID"/>
  539.         
  540.         <TextView
  541.             android:layout_width="match_parent"
  542.             android:layout_height="match_parent"
  543.             android:layout_weight="1"
  544.             android:gravity="center_horizontal|bottom"
  545.             android:text="最高分:"/>
  546.         
  547.         <TextView
  548.             android:id="@+id/highestscore"
  549.             android:layout_width="match_parent"
  550.             android:layout_height="match_parent"
  551.             android:layout_weight="1"
  552.             android:gravity="bottom|left"
  553.             android:text="最高分"/>
  554.         
  555.     </LinearLayout>
  556.    
  557. <LinearLayout
  558.         android:layout_width="match_parent"
  559.         android:layout_height="match_parent"
  560.         android:orientation="horizontal"
  561.         android:layout_weight="1">
  562.         
  563.      <TextView
  564.             android:layout_width="match_parent"
  565.             android:layout_height="match_parent"
  566.             android:layout_weight="1"
  567.             android:gravity="center"
  568.             android:text="耗时:"/>
  569.         
  570.         <TextView
  571.             android:id="@+id/time"
  572.             android:layout_width="match_parent"
  573.             android:layout_height="match_parent"
  574.             android:layout_weight="1"
  575.             android:gravity="center_vertical|left"
  576.             android:text="time"/>
  577.      
  578.         <TextView
  579.             android:layout_width="match_parent"
  580.             android:layout_height="match_parent"
  581.             android:layout_weight="1"
  582.             android:gravity="center"
  583.             android:text="分数:"/>
  584.         
  585.         <TextView
  586.             android:id="@+id/mark"
  587.             android:layout_width="match_parent"
  588.             android:layout_height="match_parent"
  589.             android:layout_weight="1"
  590.             android:gravity="center_vertical|left"
  591.             android:text="mark"/>
  592.         
  593.     </LinearLayout>
  594.    
  595. </LinearLayout>

复制代码


quesy.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="[url=http://schemas.android.com/apk/res/android]http://schemas.android.com/apk/res/android[/url]"
  3.     android:layout_width="match_parent"
  4.     android:layout_height="match_parent"
  5.     android:orientation="vertical" >
  6.    
  7. <ListView
  8.      android:layout_width="fill_parent"
  9.      android:layout_height="fill_parent"
  10.      android:id="@+id/list"/>
  11.    
  12. </LinearLayout>

复制代码

回复

使用道具 举报

1112

主题

1653

回帖

7万

积分

用户组: 管理员

一只技术宅

UID
1
精华
245
威望
744 点
宅币
24265 个
贡献
46222 次
宅之契约
0 份
在线时间
2299 小时
注册时间
2014-1-26
发表于 2014-5-25 18:44:00 | 显示全部楼层
安卓版是有官方版的。嘛,还是加油,支持你,做了个山寨的2048。
不过我没测试也没看代码。我想说,如果格子不是4x4的话有点毁这个游戏了。
回复 赞! 靠!

使用道具 举报

QQ|Archiver|小黑屋|技术宅的结界 ( 滇ICP备16008837号 )|网站地图

GMT+8, 2024-5-5 17:57 , Processed in 0.041278 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表