zoukankan      html  css  js  c++  java
  • 《2048》开发1——游戏介绍和布局

    之前研究了极客学院的2048源码,深受启发,于是也自己动手做了一个简单的2048app,仅供学习与交流。

    首先先介绍一下2048的玩法:

    有4*4列的方块,每一个方块代表一个数值。游戏初始化的时候只有两个方块有值,上面的值有可能是2和2,或者是2和4,这种概论大致是1:9.

    在游戏操作界面当中滑动时,比如说向左滑动,当相邻两个卡片数值相同时两个卡片合并,数值相加;当卡片的左侧没有值时,移动到靠最左侧一方。每移动一次,在空白的卡片上随机出现一个数值2.当卡片已经填满整个4*4列方块,且没有相邻的值相等的情况下,游戏结束。


    游戏的主要布局如图所示,分为当前分数,最高分,游戏的操作界面,重新开始游戏的按钮。

    <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:tools="http://schemas.android.com/tools"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
     
       android:paddingLeft="@dimen/activity_horizontal_margin"
       android:paddingRight="@dimen/activity_horizontal_margin"
     
       tools:context="com.Lemon.game2048.MainActivity"
       android:orientation="vertical">
             <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                 android:orientation="horizontal"
                 android:paddingBottom="70px"
                 android:paddingTop="70px">
              
                  <TextView
                      android:id="@+id/tvScore"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                      android:textStyle="bold"
                      android:textSize="10pt"/>
                  <TextView
                      android:id="@+id/tvBestScore"
                     android:layout_width="wrap_content"       
                     android:layout_height="wrap_content"
                      android:textStyle="bold"
                      android:textSize="10pt"
                      android:layout_weight="1"
                      android:gravity="right"/>
             </LinearLayout>
              <LinearLayout
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                       android:orientation="horizontal"
                       android:paddingTop="155px"
                       android:paddingBottom="100px">
                   <Button
                          android:id="@+id/btnNewGame"
                          android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="重新开始游戏"
                    />
             </LinearLayout>
    </LinearLayout>

    首先定义父布局为线性布局,再设置一个子布局为线性布局,并将方向设置为垂直方向,定义距离顶部和底部的间距。然后分别放置两个TextView,          分别表示当前的分数和最高分数,设置字体大小和属性,设置的最高分数的TextView靠右端放置。接着又定义了一个子布局线性布局,放置一个Button按钮,用来重新游戏。布局就先介绍到这。

  • 相关阅读:
    mysql怎么导入大文件的sql文件
    php函数研究
    php实现实现代码多主从,切换,轮询,健康检查
    php实现单个用户禁止重复登录,防止同一用户同时登陆
    php使用p3p实现cookies跨域设置 实现单点登录,全站登录
    实现页面浏览统计
    遍历目录删除指定MD5值的文件
    boot.img的修改
    “逃离大厦”游戏的破解
    Android漏洞——将Android恶意代码隐藏在图片中
  • 原文地址:https://www.cnblogs.com/lemonhome/p/4492635.html
Copyright © 2011-2022 走看看