我也來開發2048之主界面設計

個人開發慣例。先把界面設計出來,看過我前面博客的朋友應該知道了。html


接上次。今天的主要目的是設計界面,主界面事實上比較簡單了,咱們先上圖:android


層次並不複雜。難點在於中間遊戲面板的設計,這個咱們留着下次具體講咯佈局

主佈局是一個LinearLayout。這個很是easy看出來,主要是Button樣式的改造,我使用了一個本身定義shape加selector來實現。這幾個Button主要就是shape顏色的不一樣spa

如下顯示一個Shape來演示樣例:設計

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true"><shape android:shape="rectangle">

            <!-- 填充的顏色 -->
            <solid android:color="#33444444" />
            <!-- 設置按鈕的四個角爲弧形 -->
            <!-- android:radius 弧形的半徑 -->
            <corners android:radius="10dip" />

            <!-- padding:Button裏面的文字與Button邊界的間隔 -->
            <padding android:bottom="1dp" android:left="1dp" android:right="1dp" android:top="1dp" />
        </shape></item>
    <item><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">

            <!-- 填充的顏色 -->
            <solid android:color="#3EC5FF" />
            <!-- 設置按鈕的四個角爲弧形 -->
            <!-- android:radius 弧形的半徑 -->
            <corners android:radius="10dip" />

            <!-- padding:Button裏面的文字與Button邊界的間隔 -->
            <padding android:bottom="1dp" android:left="1dp" android:right="1dp" android:top="1dp" />
        </shape></item>

</selector>

如下就是主佈局的全部代碼:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="3dp" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/title"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_margin="3dp"
                android:background="@drawable/orange_button"
                android:text="2048"
                android:textSize="50sp" />
        </LinearLayout>

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/score_title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_margin="5dp"
                android:background="@drawable/gray_button"
                android:gravity="center"
                android:text="Scroe"
                android:textSize="25sp" />

            <TextView
                android:id="@+id/scroe"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/score_title"
                android:layout_centerHorizontal="true"
                android:layout_margin="5dp"
                android:background="@drawable/light_orange_button"
                android:gravity="center"
                android:text="10000"
                android:textSize="15sp" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/record_title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_margin="5dp"
                android:background="@drawable/gray_button"
                android:gravity="center"
                android:text="Record"
                android:textSize="25sp" />

            <TextView
                android:id="@+id/record"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/record_title"
                android:layout_centerHorizontal="true"
                android:layout_margin="5dp"
                android:background="@drawable/light_orange_button"
                android:gravity="center"
                android:text="20000"
                android:textSize="15sp" />
        </RelativeLayout>
    </LinearLayout>

    <com.xys.game2048.view.GameView
        android:id="@+id/gameView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >
    </com.xys.game2048.view.GameView>

    <LinearLayout
        style="?android:attr/buttonBarStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:padding="3dp" >

        <Button
            android:id="@+id/btn_revert"
            style="?android:attr/buttonBarButtonStyle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="3dp"
            android:layout_weight="1"
            android:background="@drawable/blue_button"
            android:text="Revert" />

        <Button
            android:id="@+id/btn_restart"
            style="?android:attr/buttonBarButtonStyle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="3dp"
            android:layout_weight="1"
            android:background="@drawable/blue_button"
            android:text="Restart" />

        <Button
            android:id="@+id/btn_option"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="3dp"
            android:layout_weight="1"
            android:background="@drawable/blue_button"
            android:text="Options" />
    </LinearLayout>

</LinearLayout>

相信你們不用多少介紹也能看懂了,我就很少介紹了。


遊戲中要實現的功能主要有如下幾點:3d

一、主標題上顯示應該達到的目標,假設你沒達到過2048則顯示2048,假設超過了。則顯示下一個目標。如4096rest

二、Score記錄當前遊戲分數,Record記錄歷史最高記錄code

三、Revert用於撤銷上次的移動。玩過2048的確定深有感觸,一不當心移錯一步,就掉坑裏爬不出來了。但是現在市面上的2048基本上都沒這個功能。因此此次準備加上這個功能xml

四、Options。這個是國際慣例了htm


以上,今天的基本就是這樣。

PS 需要源代碼的朋友可以留言,無缺後會公佈全部源代碼

相關文章
相關標籤/搜索