├── .gitignore
├── .idea
├── codeStyles
│ └── Project.xml
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── luoye
│ │ └── pintu
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── assets
│ │ └── back.jpg
│ ├── java
│ │ └── com
│ │ │ └── luoye
│ │ │ └── pintu
│ │ │ ├── Board.java
│ │ │ ├── MainActivity.java
│ │ │ ├── MainView.java
│ │ │ ├── Point.java
│ │ │ └── util
│ │ │ └── MLog.java
│ └── res
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── luoye
│ └── pintu
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── screenshots
└── test.gif
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | xmlns:android
14 |
15 | ^$
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | xmlns:.*
25 |
26 | ^$
27 |
28 |
29 | BY_NAME
30 |
31 |
32 |
33 |
34 |
35 |
36 | .*:id
37 |
38 | http://schemas.android.com/apk/res/android
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | .*:name
48 |
49 | http://schemas.android.com/apk/res/android
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | name
59 |
60 | ^$
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | style
70 |
71 | ^$
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | .*
81 |
82 | ^$
83 |
84 |
85 | BY_NAME
86 |
87 |
88 |
89 |
90 |
91 |
92 | .*
93 |
94 | http://schemas.android.com/apk/res/android
95 |
96 |
97 | ANDROID_ATTRIBUTE_ORDER
98 |
99 |
100 |
101 |
102 |
103 |
104 | .*
105 |
106 | .*
107 |
108 |
109 | BY_NAME
110 |
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
22 |
23 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 | 1.8
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PuzzleGame
2 |
3 | 
4 |
5 |
6 | Android拼图小游戏,讲解请看:
7 | https://www.cnblogs.com/luoyesiqiu/p/10052236.html
8 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.luoye.pintu"
9 | minSdkVersion 17
10 | targetSdkVersion 25
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | testCompile 'junit:junit:4.12'
25 | }
26 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in d:\Users\Administrator\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/luoye/pintu/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.luoye.pintu;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/assets/back.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luoyesiqiu/PuzzleGame/34cc420610e43e94c7acd88599d198e0906294e7/app/src/main/assets/back.jpg
--------------------------------------------------------------------------------
/app/src/main/java/com/luoye/pintu/Board.java:
--------------------------------------------------------------------------------
1 | package com.luoye.pintu;
2 |
3 | import android.util.Log;
4 |
5 | import java.util.Random;
6 |
7 | /**
8 | * 用来保存块数据的类
9 | * 注意:x对应的是col,y对应的row
10 | */
11 | public class Board {
12 | private static final String TAG = "Board";
13 | private int[][] array = null;
14 | private int row = 0;
15 | private int col = 0;
16 |
17 | //四个方向
18 | private int[][] dir = {
19 | {0, 1},//下
20 | {1, 0},//右
21 | {0, -1},//上
22 | {-1, 0}//左
23 | };
24 |
25 | private void createIntegerArray(int row, int col) {
26 | array = new int[row][col];
27 | int idx = 0;
28 | for (int i = 0; i < row; i++)
29 | for (int j = 0; j < col; j++)
30 | array[i][j] = idx++;
31 | }
32 |
33 | /**
34 | * 移动块的位置
35 | *
36 | * @param srcX
37 | * @param srcY
38 | * @param xOffset
39 | * @param yOffset
40 | * @return 新的位置,错误返回new Point(-1,-1);
41 | */
42 | private Point move(int srcX, int srcY, int xOffset, int yOffset) {
43 | int x = srcX + xOffset;
44 | int y = srcY + yOffset;
45 | if (x < 0 || y < 0 || x >= col || y >= row)
46 | return new Point(-1, -1);
47 |
48 | int temp = array[y][x];
49 | array[y][x] = array[srcY][srcX];
50 | array[srcY][srcX] = temp;
51 |
52 | return new Point(x, y);
53 | }
54 |
55 | /**
56 | * 得到下一个可以移动的位置
57 | *
58 | * @param src
59 | * @return
60 | */
61 | private Point getNextPoint(Point src) {
62 | Random rd = new Random();
63 | int idx = rd.nextInt(4);//产生0~3的随机数
64 | int xOffset = dir[idx][0];
65 | int yOffset = dir[idx][1];
66 | Point newPoint = move(src.getX(), src.getY(), xOffset, yOffset);
67 | if (newPoint.getX() != -1 && newPoint.getY() != -1) {
68 | return newPoint;
69 | }
70 | return getNextPoint(src);
71 | }
72 |
73 | /**
74 | * 生成拼图数据
75 | *
76 | * @param row
77 | * @param col
78 | * @return
79 | */
80 | public int[][] createRandomBoard(int row, int col) {
81 | if (row < 2 || col < 2)
82 | throw new IllegalArgumentException("行和列都不能小于2");
83 | this.row = row;
84 | this.col = col;
85 | createIntegerArray(row, col);
86 | int count = 0;
87 | Point tempPoint = new Point(col - 1, row - 1);
88 | Random rd = new Random();
89 | int num = rd.nextInt(100) + 20;//产生20~119的随机数
90 | while (count < num) {
91 | tempPoint = getNextPoint(tempPoint);
92 | count++;
93 | }
94 | return array;
95 | }
96 |
97 | /**
98 | * 判断是否拼图成功
99 | *
100 | * @param arr
101 | * @return
102 | */
103 | public boolean isSuccess(int[][] arr) {
104 | int idx = 0;
105 | for (int i = 0; i < arr.length; i++) {
106 | for (int j = 0; j < arr[i].length && idx < row * col - 1; j++) {
107 | if (arr[idx / row][idx % col] > arr[(idx + 1) / row][(idx + 1) % col]) {
108 | return false;
109 | }
110 | idx++;
111 | }
112 | }
113 | return true;
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/app/src/main/java/com/luoye/pintu/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.luoye.pintu;
2 |
3 | import android.app.Activity;
4 | import android.content.pm.FeatureInfo;
5 | import android.os.Bundle;
6 | import android.util.DisplayMetrics;
7 |
8 | public class MainActivity extends Activity {
9 |
10 | private static int screenWidth;
11 | private static int screenHeight;
12 | @Override
13 | protected void onCreate(Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | requestWindowFeature(1);
16 | getWindow().setFlags(1024,1024);
17 | DisplayMetrics metrics =new DisplayMetrics();
18 | getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
19 | screenWidth = metrics.widthPixels;
20 | screenHeight = metrics.heightPixels;
21 | setContentView(new MainView(this));
22 |
23 | }
24 |
25 | public static int getScreenWidth() {
26 | return screenWidth;
27 | }
28 |
29 | public static int getScreenHeight() {
30 | return screenHeight;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/luoye/pintu/MainView.java:
--------------------------------------------------------------------------------
1 | package com.luoye.pintu;
2 |
3 | import android.app.AlertDialog;
4 | import android.content.Context;
5 | import android.content.DialogInterface;
6 | import android.content.res.AssetManager;
7 | import android.graphics.Bitmap;
8 | import android.graphics.BitmapFactory;
9 | import android.graphics.Canvas;
10 | import android.graphics.Color;
11 | import android.graphics.Paint;
12 | import android.view.MotionEvent;
13 | import android.view.View;
14 |
15 | import com.luoye.pintu.util.MLog;
16 |
17 | import java.io.IOException;
18 | import java.io.InputStream;
19 |
20 | /**
21 | * Created by zyw on 2017/10/18.
22 | */
23 | public class MainView extends View {
24 | private static final String TAG = MainView.class.getSimpleName();
25 | private Context context;
26 | private Bitmap back;
27 | private Paint paint;
28 | private int tileWidth;
29 | private int tileHeight;
30 | private Bitmap[] bitmapTiles;
31 | private int[][] dataTiles;
32 | private Board tilesBoard;
33 | private final int COL = 3;
34 | private final int ROW = 3;
35 | private int[][] dir = {
36 | {-1, 0},//左
37 | {0, -1},//上
38 | {1, 0},//右
39 | {0, 1}//下
40 | };
41 | private boolean isSuccess;
42 |
43 | int steps = 0;
44 |
45 | public MainView(Context context) {
46 | super(context);
47 | this.context = context;
48 | paint = new Paint();
49 | paint.setAntiAlias(true);
50 | init();
51 | startGame();
52 | MLog.d(TAG, MainActivity.getScreenWidth() + "," + MainActivity.getScreenHeight());
53 | }
54 |
55 | /**
56 | * 初始化
57 | */
58 | private void init() {
59 | //载入图像,并将图片切成块
60 | AssetManager assetManager = context.getAssets();
61 | try {
62 | InputStream assetInputStream = assetManager.open("back.jpg");
63 | Bitmap bitmap = BitmapFactory.decodeStream(assetInputStream);
64 | back = Bitmap.createScaledBitmap(bitmap, MainActivity.getScreenWidth(), MainActivity.getScreenHeight(), true);
65 | } catch (IOException e) {
66 | e.printStackTrace();
67 | }
68 | tileWidth = back.getWidth() / COL;
69 | tileHeight = back.getHeight() / ROW;
70 | bitmapTiles = new Bitmap[COL * ROW];
71 | int idx = 0;
72 | for (int i = 0; i < ROW; i++) {
73 | for (int j = 0; j < COL; j++) {
74 | bitmapTiles[idx++] = Bitmap.createBitmap(back, j * tileWidth, i * tileHeight, tileWidth, tileHeight);
75 | }
76 | }
77 | }
78 |
79 | /**
80 | * 开始游戏
81 | */
82 | private void startGame() {
83 | tilesBoard = new Board();
84 | dataTiles = tilesBoard.createRandomBoard(ROW, COL);
85 | isSuccess = false;
86 | steps = 0;
87 | invalidate();
88 | }
89 |
90 | @Override
91 | protected void onDraw(Canvas canvas) {
92 | canvas.drawColor(Color.GRAY);
93 | for (int i = 0; i < ROW; i++) {
94 | for (int j = 0; j < COL; j++) {
95 | int idx = dataTiles[i][j];
96 | if (idx == ROW * COL - 1 && !isSuccess)
97 | continue;
98 | canvas.drawBitmap(bitmapTiles[idx], j * tileWidth, i * tileHeight, paint);
99 | }
100 | }
101 | }
102 |
103 | /**
104 | * 将屏幕上的点转换成,对应拼图块的索引
105 | *
106 | * @param x
107 | * @param y
108 | * @return
109 | */
110 | private Point xyToIndex(int x, int y) {
111 | int extraX = x % tileWidth > 0 ? 1 : 0;
112 | int extraY = x % tileWidth > 0 ? 1 : 0;
113 | int col = x / tileWidth + extraX;
114 | int row = y / tileHeight + extraY;
115 |
116 | return new Point(col - 1, row - 1);
117 | }
118 |
119 | @Override
120 | public boolean onTouchEvent(MotionEvent event) {
121 | if (event.getAction() == MotionEvent.ACTION_DOWN) {
122 | Point point = xyToIndex((int) event.getX(), (int) event.getY());
123 |
124 | for (int i = 0; i < dir.length; i++) {
125 | int newX = point.getX() + dir[i][0];
126 | int newY = point.getY() + dir[i][1];
127 |
128 | if (newX >= 0 && newX < COL && newY >= 0 && newY < ROW) {
129 | if (dataTiles[newY][newX] == COL * ROW - 1) {
130 | steps++;
131 | int temp = dataTiles[point.getY()][point.getX()];
132 | dataTiles[point.getY()][point.getX()] = dataTiles[newY][newX];
133 | dataTiles[newY][newX] = temp;
134 | invalidate();
135 | if (tilesBoard.isSuccess(dataTiles)) {
136 | isSuccess = true;
137 | invalidate();
138 | String successText = String.format("恭喜你拼图成功,移动了%d次", steps);
139 | new AlertDialog.Builder(context)
140 | .setTitle("拼图成功")
141 | .setCancelable(false)
142 | .setMessage(successText)
143 | .setPositiveButton("重新开始", new DialogInterface.OnClickListener() {
144 | @Override
145 | public void onClick(DialogInterface dialog, int which) {
146 | startGame();
147 | }
148 | })
149 | .setNegativeButton("退出游戏", new DialogInterface.OnClickListener() {
150 | @Override
151 | public void onClick(DialogInterface dialog, int which) {
152 | System.exit(0);
153 | }
154 | })
155 | .create()
156 | .show();
157 | }
158 | }
159 | }
160 | }
161 | }
162 | return true;
163 | }
164 |
165 | private void printArray(int[][] arr) {
166 | StringBuilder sb = new StringBuilder();
167 | for (int i = 0; i < arr.length; i++) {
168 | for (int j = 0; j < arr[i].length; j++) {
169 | sb.append(arr[i][j] + ",");
170 | }
171 | sb.append("\n");
172 | }
173 | MLog.d(TAG, sb.toString());
174 | }
175 |
176 | }
177 |
--------------------------------------------------------------------------------
/app/src/main/java/com/luoye/pintu/Point.java:
--------------------------------------------------------------------------------
1 | package com.luoye.pintu;
2 |
3 | /**
4 | * Created by zyw on 2017/10/19.
5 | */
6 | public class Point {
7 | public Point(int x, int y) {
8 | this.x = x;
9 | this.y = y;
10 | }
11 |
12 | public int getX() {
13 | return x;
14 | }
15 |
16 | public void setX(int x) {
17 | this.x = x;
18 | }
19 |
20 | public int getY() {
21 | return y;
22 | }
23 |
24 | public void setY(int y) {
25 | this.y = y;
26 | }
27 |
28 | private int x=0;
29 | private int y=0;
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/luoye/pintu/util/MLog.java:
--------------------------------------------------------------------------------
1 | package com.luoye.pintu.util;
2 |
3 | import android.util.Log;
4 |
5 | public class MLog {
6 | private static final String PROCESS = "Puzzle";
7 | private static boolean DEBUG = true;
8 | public static final void d(String tag,String log){
9 | if(DEBUG){
10 | Log.d(PROCESS+"_"+tag,log);
11 | }
12 | }
13 |
14 | public static final void i(String tag,String log){
15 | if(DEBUG){
16 | Log.i(PROCESS+"_"+tag,log);
17 | }
18 | }
19 |
20 | public static final void w(String tag,String log){
21 | if(DEBUG){
22 | Log.w(PROCESS+"_"+tag,log);
23 | }
24 | }
25 |
26 | public static final void e(String tag,String log){
27 | if(DEBUG){
28 | Log.e(PROCESS+"_"+tag,log);
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luoyesiqiu/PuzzleGame/34cc420610e43e94c7acd88599d198e0906294e7/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luoyesiqiu/PuzzleGame/34cc420610e43e94c7acd88599d198e0906294e7/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luoyesiqiu/PuzzleGame/34cc420610e43e94c7acd88599d198e0906294e7/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luoyesiqiu/PuzzleGame/34cc420610e43e94c7acd88599d198e0906294e7/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luoyesiqiu/PuzzleGame/34cc420610e43e94c7acd88599d198e0906294e7/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 拼图
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/test/java/com/luoye/pintu/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.luoye.pintu;
2 |
3 | import org.junit.Test;
4 |
5 | /**
6 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
7 | */
8 | public class ExampleUnitTest {
9 | @Test
10 | public void addition_isCorrect() throws Exception {
11 | Board board =new Board();
12 | }
13 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.0.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | ## Project-wide Gradle settings.
2 | #
3 | # For more details on how to configure your build environment visit
4 | # http://www.gradle.org/docs/current/userguide/build_environment.html
5 | #
6 | # Specifies the JVM arguments used for the daemon process.
7 | # The setting is particularly useful for tweaking memory settings.
8 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
10 | #
11 | # When configured, Gradle will run in incubating parallel mode.
12 | # This option should only be used with decoupled projects. More details, visit
13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14 | # org.gradle.parallel=true
15 | #Wed Oct 18 13:10:37 CST 2017
16 | systemProp.http.proxyHost=mirrors.neusoft.edu.cn
17 | systemProp.http.proxyPort=80
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luoyesiqiu/PuzzleGame/34cc420610e43e94c7acd88599d198e0906294e7/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/screenshots/test.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luoyesiqiu/PuzzleGame/34cc420610e43e94c7acd88599d198e0906294e7/screenshots/test.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------