看了徐宜生android群英传的拼图例子,也想参照他的写一个拼图游戏。本文的拼图游戏中对图片处理的方式和书中的基本是一直的,但是游戏方法却与之不同。
书中的拼图是通过GridView的点击事件,交换两张图片,达成拼图目的,但是个人认为这样的拼图过于简单,很容易就能达成目标,
于是收到小时候玩的数字推盘的游戏的启发,将数字替换成文字,大大增加了游戏的难度(ps:本人目前没玩出来过)。主要使用recyclerView与ontouch结合,实现拼图效果,当然判断拼图是否有解的算法还没给出,敬请期待后续更新。
首先简单介绍一下布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tool="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tool:context=".activity.GameActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:popupTheme="@style/Theme.AppCompat.Light.NoActionBar">
</android.support.v7.widget.Toolbar>
<LinearLayout
android:id="@+id/lay_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="@dimen/margin_8dp"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:text="@string/jigsaw_time"
android:textSize="@dimen/sp_middle" />
<TextView
android:id="@+id/jigsaw_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="@dimen/margin_8dp"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:textSize="@dimen/sp_middle" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="@dimen/margin_8dp"
android:ellipsize="end"
android:gravity="center"