安卓Andriod使用入门(三)【2048游戏】

天才,就其本质而说,只不过是一种对事业、对工作过盛的热爱而已。——高尔基


game2048Activity.java代码:

package siso.geekworld;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.TextView;

import game.domain.AnimLayer;
import game.service.GameService;

public class game2048Activity extends ActionBarActivity {
        private TextView tv_bestRecord;
        private int score;
        private TextView tv_score;
        private static game2048Activity game2048activity = null;
        private AnimLayer animLayer = null;
        public AnimLayer getAnimLayer() {
            return animLayer;
        }
        public game2048Activity(){
            game2048activity = this;
        }
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_game2048);
            tv_score = (TextView) findViewById(R.id.tv_score);
            animLayer = (AnimLayer) findViewById(R.id.animLayer);
            tv_bestRecord = (TextView) findViewById(R.id.bestRecord);
        }
        public void showBestRecord(){
            tv_bestRecord.setText(GameService.getBest()+"");
        }
        public void clearScore(){
            score = 0;
            showScore();
        }
        public void showScore() {
            tv_score.setText(score+"");
        }
        public void addScore(int s){
            score += s;
            showScore();
        }
        public int getScore(){
            return score;
        }
        public static game2048Activity getgame2048Activity() {
            return game2048activity;
        }

    }

activity_game2048.xml内容:

<?xml version="1.0" encoding="utf-8"?>
    <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"
        tools:context="siso.geekworld.game2048Activity" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:baselineAligned="false"
            android:orientation="horizontal" >

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#ffb3b3b3"
                android:gravity="center_horizontal"
                android:orientation="vertical" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/score"
                    android:textColor="#ffffffff"
                    android:textSize="25sp" />

                <TextView
                    android:id="@+id/tv_score"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="#ffffffff"
                    android:textSize="25sp" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#ffE9DC77"
                android:gravity="center_horizontal"
                android:orientation="vertical" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="#ffffffff"
                    android:text="@string/best"
                    android:textSize="25sp" />

                <TextView
                    android:id="@+id/bestRecord"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="#ffffffff"
                    android:textSize="25sp" />
            </LinearLayout>
        </LinearLayout>

        <FrameLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1" >

            <game.domain.GameView
                android:id="@+id/gameView"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" >
            </game.domain.GameView>

            <game.domain.AnimLayer
                android:id="@+id/animLayer"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" >
            </game.domain.AnimLayer>
        </FrameLayout>

    </LinearLayout>

strings.xml内容:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name" translatable="false">2048</string>
    <string name="hello_world" translatable="false">Hello world!</string>
    <string name="action_settings" translatable="false">Settings</string>
    <string name="score" translatable="false">得分</string>
    <string name="best" translatable="false">最高分</string>
    <string name="enterAnimation" translatable="false">An Animation during enter the game</string>
    <string name="sign" translatable="false">©2014.10&#160;&#160;&#160;&#160;作者&#160;&#160;&#160;&#160;lz</string>

</resources>

styles.xml内容:

<resources>
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light"> </style>

<style name="AppTheme" parent="AppBaseTheme">       
</style>

</resources>

其他层,结构,类

这里写图片描述

运行结果如图:

这里写图片描述

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值