Andoridゲーム2048開発(一)

5315 ワード

最近Androidプラットフォームの下のゲームが大ヒットしました---2048.開発プロセスを以下に記録します.筆者はAndroid開発初心者なので、この文を借りてAndroid開発の流れを熟知してほしい.
まずGame 2048のゲーム項目を作成します.最低プラットフォームはAndroid 4です.0(API 14)、最高サポートプラットフォームAndroid 4.4(API 19)、その後Nextに進み、作成が完了したらactivity_を変更します.main.xmlファイル.デフォルトのレイアウトをLinearLayoutレイアウトに変更します.次にLinearyoutレイアウトをネストし、ユーザーのゲーム点数の表示を行います.
 
<LinearLayout xmlns: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:orientation="vertical"

    android:paddingBottom="@dimen/activity_vertical_margin"

    android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    tools:context=".MainActivity" >



    <LinearLayout

        android:layout_width="wrap_content"

        android:layout_height="fill_parent" >



        <TextView

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="@string/score" />



        <TextView

            android:id="@+id/tvScore"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content" />

    </LinearLayout>

    

    <GridLayout

        android:layout_width="fill_parent"

        android:layout_height="0dp"

        android:layout_weight="1"

        android:id="@+id/gameView"

        ></GridLayout>

</LinearLayout>

その後、メインパッケージにゲームメインインタフェースGameViewクラスを作成し、GridLayoutレイアウト方式を使用してメインインタフェースの表示に使用するため、GameViewクラスはGridLayoutを継承し、すべての3つの構造方法を作成します.次にGameViewクラスでは、ゲームの開始方法としてinitGameView()を作成します.次に、マスターメソッドのパスcomを見つける.skk . game2048 .GameView、acitvity_main.xmlファイルでプライマリメソッドをバインドする
    <com.skk.game2048.GameView 

        android:layout_width="fill_parent"

        android:layout_height="0dp"

        android:layout_weight="1"

        android:id="@+id/gameView"

        ></com.skk.game2048.GameView>

プライマリメソッドコード
package com.skk.game2048;



import android.content.Context;

import android.util.AttributeSet;

import android.widget.GridLayout;



public class GameView extends GridLayout {



    public GameView(Context context) {

        super(context);

        initGameView();

    }



    public GameView(Context context, AttributeSet attrs) {

        super(context, attrs);

        initGameView();

    }



    public GameView(Context context, AttributeSet attrs, int defStyle) {

        super(context, attrs, defStyle);

        initGameView();

    }

    

    private void initGameView(){

        

    }



}