├── PuzzleGame ├── app │ ├── .gitignore │ ├── src │ │ ├── main │ │ │ ├── res │ │ │ │ ├── drawable │ │ │ │ │ └── empty.9.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ ├── lb.jpeg │ │ │ │ │ ├── ll.jpg │ │ │ │ │ ├── dfzs.jpg │ │ │ │ │ ├── dmxyzy.jpg │ │ │ │ │ ├── sdhy.jpg │ │ │ │ │ ├── app_icon.png │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ ├── app_icon.png │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ ├── app_icon.png │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── values │ │ │ │ │ ├── colors.xml │ │ │ │ │ ├── arrays.xml │ │ │ │ │ ├── styles.xml │ │ │ │ │ └── strings.xml │ │ │ │ └── layout │ │ │ │ │ ├── item_list.xml │ │ │ │ │ ├── dialog_select_image.xml │ │ │ │ │ └── activity_main.xml │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── mg │ │ │ │ │ └── axe │ │ │ │ │ └── puzzlegame │ │ │ │ │ ├── module │ │ │ │ │ ├── ImageSoures.java │ │ │ │ │ └── ImagePiece.java │ │ │ │ │ ├── game │ │ │ │ │ ├── Game.java │ │ │ │ │ └── PuzzleGame.java │ │ │ │ │ ├── dialog │ │ │ │ │ ├── SuccessDialog.java │ │ │ │ │ └── SelectImageDialog.java │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ ├── Utils │ │ │ │ │ └── Utils.java │ │ │ │ │ └── ui │ │ │ │ │ └── PuzzleLayout.java │ │ │ └── AndroidManifest.xml │ │ ├── test │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── mg │ │ │ │ └── axe │ │ │ │ └── puzzlegame │ │ │ │ └── ExampleUnitTest.java │ │ └── androidTest │ │ │ └── java │ │ │ └── com │ │ │ └── mg │ │ │ └── axe │ │ │ └── puzzlegame │ │ │ └── ExampleInstrumentedTest.java │ ├── proguard-rules.pro │ └── build.gradle ├── .idea │ ├── sonarlint │ │ └── issuestore │ │ │ └── index.pb │ ├── copyright │ │ └── profiles_settings.xml │ ├── modules.xml │ ├── runConfigurations.xml │ ├── gradle.xml │ ├── compiler.xml │ └── misc.xml ├── settings.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── .gitignore ├── build.gradle ├── gradle.properties ├── gradlew.bat └── gradlew └── README.md /PuzzleGame/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /PuzzleGame/.idea/sonarlint/issuestore/index.pb: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /PuzzleGame/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /PuzzleGame/.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /PuzzleGame/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxeChen/PuzzleGame/HEAD/PuzzleGame/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/res/drawable/empty.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxeChen/PuzzleGame/HEAD/PuzzleGame/app/src/main/res/drawable/empty.9.png -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/res/mipmap-xxhdpi/lb.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxeChen/PuzzleGame/HEAD/PuzzleGame/app/src/main/res/mipmap-xxhdpi/lb.jpeg -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/res/mipmap-xxhdpi/ll.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxeChen/PuzzleGame/HEAD/PuzzleGame/app/src/main/res/mipmap-xxhdpi/ll.jpg -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/res/mipmap-hdpi/app_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxeChen/PuzzleGame/HEAD/PuzzleGame/app/src/main/res/mipmap-hdpi/app_icon.png -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/res/mipmap-xxhdpi/dfzs.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxeChen/PuzzleGame/HEAD/PuzzleGame/app/src/main/res/mipmap-xxhdpi/dfzs.jpg -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/res/mipmap-xxhdpi/dmxyzy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxeChen/PuzzleGame/HEAD/PuzzleGame/app/src/main/res/mipmap-xxhdpi/dmxyzy.jpg -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/res/mipmap-xxhdpi/sdhy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxeChen/PuzzleGame/HEAD/PuzzleGame/app/src/main/res/mipmap-xxhdpi/sdhy.jpg -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/res/mipmap-xhdpi/app_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxeChen/PuzzleGame/HEAD/PuzzleGame/app/src/main/res/mipmap-xhdpi/app_icon.png -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/res/mipmap-xxhdpi/app_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxeChen/PuzzleGame/HEAD/PuzzleGame/app/src/main/res/mipmap-xxhdpi/app_icon.png -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxeChen/PuzzleGame/HEAD/PuzzleGame/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxeChen/PuzzleGame/HEAD/PuzzleGame/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxeChen/PuzzleGame/HEAD/PuzzleGame/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxeChen/PuzzleGame/HEAD/PuzzleGame/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxeChen/PuzzleGame/HEAD/PuzzleGame/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxeChen/PuzzleGame/HEAD/PuzzleGame/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxeChen/PuzzleGame/HEAD/PuzzleGame/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxeChen/PuzzleGame/HEAD/PuzzleGame/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxeChen/PuzzleGame/HEAD/PuzzleGame/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxeChen/PuzzleGame/HEAD/PuzzleGame/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /PuzzleGame/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/res/values/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | @string/game_mode_normal 5 | @string/game_mode_exchange 6 | 7 | 8 | -------------------------------------------------------------------------------- /PuzzleGame/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Jul 13 10:24:14 CST 2017 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-3.3-all.zip 7 | -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/res/layout/item_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/res/layout/dialog_select_image.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/java/com/mg/axe/puzzlegame/module/ImageSoures.java: -------------------------------------------------------------------------------- 1 | package com.mg.axe.puzzlegame.module; 2 | 3 | import com.mg.axe.puzzlegame.R; 4 | 5 | /** 6 | * Created by Axe on 2017/7/15. 7 | */ 8 | 9 | public class ImageSoures { 10 | public static final int[] imageSours = {R.mipmap.sdhy, R.mipmap.dmxyzy, R.mipmap.dfzs, R.mipmap.lb, R.mipmap.ll}; 11 | } 12 | -------------------------------------------------------------------------------- /PuzzleGame/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /PuzzleGame/app/src/test/java/com/mg/axe/puzzlegame/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.mg.axe.puzzlegame; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | PuzzleGame 3 | 普通模式 4 | 交换模式 5 | 已经是最高等级 6 | 已经是最低等级 7 | 成功! 8 | 你已经完成拼图,是否挑战下一个等级? 9 | 下一等级 10 | 取消 11 | 12 | 13 | -------------------------------------------------------------------------------- /PuzzleGame/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.3.3' 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PuzzleGame   2 | 通过继承ViewGroup的自定义控件做的一个拼图游戏。 3 | 4 | 效果图:   5 | ![oneplus-oneplus a3010-2017-07-16-00-48-36_20170716004944](https://user-images.githubusercontent.com/19148112/28248996-a4cf2772-6a80-11e7-9776-800a2f5803bc.gif) 6 | ![oneplus-oneplus a3010-2017-07-16-00-50-03_20170716005256](https://user-images.githubusercontent.com/19148112/28248997-a66f7488-6a80-11e7-8877-de45332f685c.gif)   7 | 8 | 2017/7/26 添加应用图标   9 | 10 | ![图标](https://user-images.githubusercontent.com/19148112/28603105-bcb32962-71f4-11e7-805d-db8546f1988f.png) 11 | 12 | 博客地址: 13 | http://www.jianshu.com/p/11899d1e1dea 14 | -------------------------------------------------------------------------------- /PuzzleGame/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/java/com/mg/axe/puzzlegame/game/Game.java: -------------------------------------------------------------------------------- 1 | package com.mg.axe.puzzlegame.game; 2 | 3 | /** 4 | * @Author Zaifeng 5 | * @Create 2017/7/13 0013 6 | * @Description Content 7 | */ 8 | 9 | public interface Game { 10 | 11 | /** 12 | * 增加难度 13 | */ 14 | public void addLevel(); 15 | 16 | /** 17 | * 减少难度 18 | */ 19 | public void reduceLevel(); 20 | 21 | /** 22 | * 修改游戏模式 23 | */ 24 | public void changeMode(String gameMode); 25 | 26 | /** 27 | * 修改图片 28 | * 29 | * @param res 30 | */ 31 | public void changeImage(int res); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /PuzzleGame/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /PuzzleGame/.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 | -------------------------------------------------------------------------------- /PuzzleGame/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /PuzzleGame/app/src/androidTest/java/com/mg/axe/puzzlegame/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.mg.axe.puzzlegame; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.mg.axe.puzzlegame", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /PuzzleGame/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 C:\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 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /PuzzleGame/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "26.0.0" 6 | defaultConfig { 7 | applicationId "com.mg.axe.puzzlegame" 8 | minSdkVersion 15 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 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 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:25.3.1' 28 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 29 | testCompile 'junit:junit:4.12' 30 | compile 'com.android.support:design:26.0.0-alpha1' 31 | } 32 | -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/java/com/mg/axe/puzzlegame/module/ImagePiece.java: -------------------------------------------------------------------------------- 1 | package com.mg.axe.puzzlegame.module; 2 | 3 | import android.graphics.Bitmap; 4 | import android.widget.ImageView; 5 | 6 | /** 7 | * Created by Administrator on 2016/9/8 0008. 8 | */ 9 | public class ImagePiece { 10 | 11 | public static final int TYPE_NORMAL = 0; 12 | public static final int TYPE_EMPTY = 1; 13 | 14 | private int type = TYPE_NORMAL; 15 | private int index; 16 | private Bitmap bitmap; 17 | private ImageView imageView; 18 | 19 | public ImageView getImageView() { 20 | return imageView; 21 | } 22 | 23 | public void setImageView(ImageView imageView) { 24 | this.imageView = imageView; 25 | } 26 | 27 | public int getType() { 28 | return type; 29 | } 30 | 31 | public void setType(int type) { 32 | this.type = type; 33 | } 34 | 35 | public int getIndex() { 36 | return index; 37 | } 38 | 39 | public void setIndex(int index) { 40 | this.index = index; 41 | } 42 | 43 | public Bitmap getBitmap() { 44 | return bitmap; 45 | } 46 | 47 | public void setBitmap(Bitmap bitmap) { 48 | this.bitmap = bitmap; 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return super.toString(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/java/com/mg/axe/puzzlegame/dialog/SuccessDialog.java: -------------------------------------------------------------------------------- 1 | package com.mg.axe.puzzlegame.dialog; 2 | 3 | import android.app.AlertDialog; 4 | import android.app.Dialog; 5 | import android.app.DialogFragment; 6 | import android.content.DialogInterface; 7 | import android.os.Bundle; 8 | 9 | import com.mg.axe.puzzlegame.R; 10 | 11 | /** 12 | * Created by Axe on 2017/7/15. 13 | */ 14 | 15 | public class SuccessDialog extends DialogFragment { 16 | 17 | public OnButtonClickListener buttonClickListener; 18 | 19 | @Override 20 | public Dialog onCreateDialog(Bundle savedInstanceState) { 21 | AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()) 22 | .setTitle(getString(R.string.success)); 23 | builder.setMessage(getString(R.string.success_description)). 24 | setPositiveButton(getString(R.string.next_level), new DialogInterface.OnClickListener() { 25 | @Override 26 | public void onClick(DialogInterface dialog, int which) { 27 | if (buttonClickListener != null) { 28 | buttonClickListener.nextLevelClick(); 29 | } 30 | } 31 | }) 32 | .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { 33 | @Override 34 | public void onClick(DialogInterface dialog, int which) { 35 | if (buttonClickListener != null) { 36 | buttonClickListener.cancelClick(); 37 | } 38 | } 39 | }); 40 | 41 | return builder.create(); 42 | 43 | } 44 | 45 | public void addButtonClickListener(OnButtonClickListener listener) { 46 | this.buttonClickListener = listener; 47 | } 48 | 49 | public interface OnButtonClickListener { 50 | public void nextLevelClick(); 51 | 52 | public void cancelClick(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /PuzzleGame/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /PuzzleGame/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 | -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/java/com/mg/axe/puzzlegame/game/PuzzleGame.java: -------------------------------------------------------------------------------- 1 | package com.mg.axe.puzzlegame.game; 2 | 3 | import android.content.Context; 4 | import android.os.Handler; 5 | import android.os.Message; 6 | import android.support.annotation.NonNull; 7 | import android.widget.Toast; 8 | 9 | import com.mg.axe.puzzlegame.R; 10 | import com.mg.axe.puzzlegame.ui.PuzzleLayout; 11 | 12 | /** 13 | * @Author Zaifeng 14 | * @Create 2017/7/13 0013 15 | * @Description Content 16 | */ 17 | 18 | public class PuzzleGame implements Game, PuzzleLayout.SuccessListener { 19 | 20 | private PuzzleLayout puzzleLayou; 21 | private GameStateListener stateListener; 22 | private Context context; 23 | 24 | public void addGameStateListener(GameStateListener stateListener) { 25 | this.stateListener = stateListener; 26 | } 27 | 28 | public PuzzleGame(@NonNull Context context, @NonNull PuzzleLayout puzzleLayout) { 29 | this.context = context.getApplicationContext(); 30 | this.puzzleLayou = puzzleLayout; 31 | puzzleLayou.addSuccessListener(this); 32 | } 33 | 34 | private boolean checkNull() { 35 | return puzzleLayou == null; 36 | } 37 | 38 | @Override 39 | public void addLevel() { 40 | if (checkNull()) { 41 | return; 42 | } 43 | if (!puzzleLayou.addCount()) { 44 | Toast.makeText(context, context.getString(R.string.already_the_most_level), Toast.LENGTH_SHORT).show(); 45 | } 46 | if (stateListener != null) { 47 | stateListener.setLevel(getLevel()); 48 | } 49 | } 50 | 51 | @Override 52 | public void reduceLevel() { 53 | if (checkNull()) { 54 | return; 55 | } 56 | if (!puzzleLayou.reduceCount()) { 57 | Toast.makeText(context, context.getString(R.string.already_the_less_level), Toast.LENGTH_SHORT).show(); 58 | } 59 | if (stateListener != null) { 60 | stateListener.setLevel(getLevel()); 61 | } 62 | } 63 | 64 | @Override 65 | public void changeMode(String gameMode) { 66 | puzzleLayou.changeMode(gameMode); 67 | } 68 | 69 | @Override 70 | public void changeImage(int res) { 71 | puzzleLayou.changeRes(res); 72 | } 73 | 74 | public int getLevel() { 75 | if (checkNull()) { 76 | return 0; 77 | } 78 | int count = puzzleLayou.getCount(); 79 | return count - 3 + 1; 80 | } 81 | 82 | @Override 83 | public void success() { 84 | if (stateListener != null) { 85 | stateListener.gameSuccess(getLevel()); 86 | } 87 | } 88 | 89 | public interface GameStateListener { 90 | public void setLevel(int level); 91 | 92 | public void gameSuccess(int level); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /PuzzleGame/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | 22 | 23 | 32 | 33 | 43 | 44 | 54 | 55 |