├── .idea ├── .name ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── vcs.xml ├── modules.xml ├── runConfigurations.xml ├── compiler.xml ├── gradle.xml └── misc.xml ├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── 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 │ │ │ │ ├── api_key.xml │ │ │ │ ├── dimens.xml │ │ │ │ ├── styles.xml │ │ │ │ ├── strings.xml │ │ │ │ └── colors.xml │ │ │ ├── layout │ │ │ │ ├── activity_main.xml │ │ │ │ ├── fragment_game.xml │ │ │ │ └── fragment_intro.xml │ │ │ └── values-w820dp │ │ │ │ └── dimens.xml │ │ ├── java │ │ │ └── me │ │ │ │ └── mattlogan │ │ │ │ └── twentyseven │ │ │ │ ├── OnNearbyApiAvailableEvent.java │ │ │ │ ├── Plane.java │ │ │ │ ├── PlaneTracker.java │ │ │ │ ├── AppModule.java │ │ │ │ ├── messages │ │ │ │ ├── MessagePublisher.java │ │ │ │ └── IncomingMessageRouter.java │ │ │ │ ├── game │ │ │ │ ├── Game.java │ │ │ │ ├── GameFragment.java │ │ │ │ ├── WinChecker.java │ │ │ │ └── BoardView.java │ │ │ │ ├── intro │ │ │ │ └── IntroFragment.java │ │ │ │ └── MainActivity.java │ │ └── AndroidManifest.xml │ ├── androidTest │ │ └── java │ │ │ └── me │ │ │ └── mattlogan │ │ │ └── twentyseven │ │ │ └── ApplicationTest.java │ └── test │ │ └── java │ │ └── me │ │ └── mattlogan │ │ └── twentyseven │ │ ├── GameTest.java │ │ └── WinCheckerTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── README.md ├── gradle.properties ├── gradlew.bat └── gradlew /.idea/.name: -------------------------------------------------------------------------------- 1 | Twentyseven -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattlogan/Twenty-seven/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattlogan/Twenty-seven/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattlogan/Twenty-seven/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattlogan/Twenty-seven/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattlogan/Twenty-seven/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattlogan/Twenty-seven/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/java/me/mattlogan/twentyseven/OnNearbyApiAvailableEvent.java: -------------------------------------------------------------------------------- 1 | package me.mattlogan.twentyseven; 2 | 3 | public final class OnNearbyApiAvailableEvent { 4 | } 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/api_key.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | AIzaSyDDk0zt6wHVipPF0a2IsU_X-atebaiquz4 4 | 5 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | https://www.youtube.com/watch?v=8_pHdeu4Rks 2 | 3 | This is my submission for the Android Experiments 2016 contest. 4 | 5 | Twenty-seven is a three-dimensional tic-tac-toe game where the grid is a 3x3x3 cube and a player can win by connecting three spaces in any direction, including diagonals. Each vertical plane is represented by a separate Android device. 6 | 7 | The Android devices communicate via the Nearby Messages API. 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Twenty-seven 3 | Front 4 | Middle 5 | Back 6 | Waiting… 7 | %c\'s turn 8 | %c wins 9 | New game 10 | 11 | -------------------------------------------------------------------------------- /app/src/androidTest/java/me/mattlogan/twentyseven/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package me.mattlogan.twentyseven; 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/java/me/mattlogan/twentyseven/Plane.java: -------------------------------------------------------------------------------- 1 | package me.mattlogan.twentyseven; 2 | 3 | public enum Plane { 4 | FRONT(0), 5 | MIDDLE(1), 6 | BACK(2); 7 | 8 | private final int zValue; 9 | 10 | Plane(int zValue) { 11 | this.zValue = zValue; 12 | } 13 | 14 | public int zValue() { 15 | return zValue; 16 | } 17 | 18 | public String toDisplayString() { 19 | String uppercase = this.toString(); 20 | return uppercase.charAt(0) + uppercase.substring(1).toLowerCase(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/me/mattlogan/twentyseven/PlaneTracker.java: -------------------------------------------------------------------------------- 1 | package me.mattlogan.twentyseven; 2 | 3 | import timber.log.Timber; 4 | 5 | /** 6 | * Informs the rest of the application which plane this instance of the app represents in the 7 | * 3 dimensional tic tac toe space -- front, middle, or back 8 | */ 9 | public class PlaneTracker { 10 | 11 | private Plane plane; 12 | 13 | public void updatePlane(Plane plane) { 14 | Timber.d("updatePlane: %s", plane); 15 | this.plane = plane; 16 | } 17 | 18 | public Plane currentPlane() { 19 | return plane; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #830509 4 | #410000 5 | #50815A 6 | #333333 7 | #E7DC8C 8 | #FFFFFF 9 | #B20B38 10 | #F0AF00 11 | #649500 12 | #195B83 13 | #2F1B60 14 | 15 | 16 | -------------------------------------------------------------------------------- /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 /Users/matthewlogan/Library/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 | -------------------------------------------------------------------------------- /.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/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 23 | 24 | -------------------------------------------------------------------------------- /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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 15 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/test/java/me/mattlogan/twentyseven/GameTest.java: -------------------------------------------------------------------------------- 1 | package me.mattlogan.twentyseven; 2 | 3 | import org.junit.Test; 4 | 5 | import me.mattlogan.twentyseven.game.Game; 6 | 7 | import static junit.framework.Assert.assertEquals; 8 | 9 | public class GameTest { 10 | 11 | @Test 12 | public void testGameToMessage() { 13 | Game game = Game.createNewGame(); 14 | char[][][] grid = game.grid(); 15 | grid[0][0][0] = 'X'; 16 | grid[1][0][0] = 'X'; 17 | grid[2][0][0] = 'X'; 18 | 19 | grid[0][0][2] = 'O'; 20 | grid[1][1][2] = 'O'; 21 | grid[2][1][2] = 'O'; 22 | 23 | assertEquals("XXXEEEEEEEEEEEEEEEOEEEOOEEE_TURN_X", game.toString()); 24 | } 25 | 26 | @Test 27 | public void testMessageToGame() { 28 | Game game = Game.createNewGame(); 29 | char[][][] grid = game.grid(); 30 | grid[0][0][0] = 'X'; 31 | grid[1][0][0] = 'X'; 32 | grid[2][0][0] = 'X'; 33 | 34 | grid[0][0][2] = 'O'; 35 | grid[1][1][2] = 'O'; 36 | grid[2][1][2] = 'O'; 37 | 38 | assertEquals(game, Game.fromString("XXXEEEEEEEEEEEEEEEOEEEOOEEE_TURN_X")); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "me.mattlogan.twentyseven" 9 | minSdkVersion 19 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | 15 | testOptions { 16 | unitTests.all { 17 | testLogging { 18 | events "passed", "skipped", "failed", "standardOut", "standardError" 19 | } 20 | } 21 | } 22 | } 23 | 24 | dependencies { 25 | compile 'com.android.support:appcompat-v7:23.2.1' 26 | compile 'com.google.android.gms:play-services-nearby:8.4.0' 27 | compile 'com.jakewharton.timber:timber:4.1.1' 28 | compile 'com.jakewharton:butterknife:7.0.1' 29 | compile 'com.squareup:otto:1.3.8' 30 | compile 'com.squareup.dagger:dagger:1.2.2' 31 | provided 'com.squareup.dagger:dagger-compiler:1.2.2' 32 | compile 'com.android.support:percent:23.2.1' 33 | compile 'com.android.support:gridlayout-v7:23.2.1' 34 | 35 | testCompile 'junit:junit:4.12' 36 | } 37 | -------------------------------------------------------------------------------- /app/src/test/java/me/mattlogan/twentyseven/WinCheckerTest.java: -------------------------------------------------------------------------------- 1 | package me.mattlogan.twentyseven; 2 | 3 | import org.junit.Test; 4 | 5 | import me.mattlogan.twentyseven.game.Game; 6 | import me.mattlogan.twentyseven.game.WinChecker; 7 | 8 | import static org.junit.Assert.*; 9 | 10 | /** 11 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 12 | */ 13 | public class WinCheckerTest { 14 | 15 | @Test 16 | public void testHorizontalWinInFrontPlane() throws Exception { 17 | char[][][] grid = Game.createNewGame().grid(); 18 | grid[0][0][0] = 'X'; 19 | grid[0][1][0] = 'X'; 20 | grid[0][2][0] = 'X'; 21 | 22 | WinChecker.Win win = WinChecker.checkForWinner(grid); 23 | 24 | assertNotNull(win); 25 | assertTrue(win.winner() == 'X'); 26 | } 27 | 28 | @Test 29 | public void testCubeDiagonalWin() throws Exception { 30 | char[][][] grid = Game.createNewGame().grid(); 31 | grid[0][0][0] = 'O'; 32 | grid[1][1][1] = 'O'; 33 | grid[2][2][2] = 'O'; 34 | 35 | WinChecker.Win win = WinChecker.checkForWinner(grid); 36 | 37 | assertNotNull(win); 38 | assertTrue(win.winner() == 'O'); 39 | } 40 | 41 | @Test 42 | public void testNoWinner() throws Exception { 43 | char[][][] grid = Game.createNewGame().grid(); 44 | 45 | assertNull(WinChecker.checkForWinner(grid)); 46 | } 47 | } -------------------------------------------------------------------------------- /app/src/main/java/me/mattlogan/twentyseven/AppModule.java: -------------------------------------------------------------------------------- 1 | package me.mattlogan.twentyseven; 2 | 3 | import android.content.Context; 4 | 5 | import com.google.android.gms.common.api.GoogleApiClient; 6 | import com.google.android.gms.nearby.Nearby; 7 | import com.squareup.otto.Bus; 8 | 9 | import javax.inject.Singleton; 10 | 11 | import dagger.Module; 12 | import dagger.Provides; 13 | import me.mattlogan.twentyseven.game.GameFragment; 14 | import me.mattlogan.twentyseven.intro.IntroFragment; 15 | import me.mattlogan.twentyseven.messages.IncomingMessageRouter; 16 | import me.mattlogan.twentyseven.messages.MessagePublisher; 17 | 18 | @Module( 19 | injects = { 20 | MainActivity.class, 21 | IntroFragment.class, 22 | GameFragment.class 23 | } 24 | ) 25 | public final class AppModule { 26 | 27 | private final Context context; 28 | 29 | public AppModule(Context context) { 30 | this.context = context; 31 | } 32 | 33 | @Provides @Singleton Bus bus() { 34 | return new Bus(); 35 | } 36 | 37 | @Provides @Singleton PlaneTracker planeTracker() { 38 | return new PlaneTracker(); 39 | } 40 | 41 | @Provides @Singleton GoogleApiClient client() { 42 | return new GoogleApiClient.Builder(context) 43 | .addApi(Nearby.MESSAGES_API) 44 | .build(); 45 | } 46 | 47 | @Provides @Singleton IncomingMessageRouter router() { 48 | return new IncomingMessageRouter(); 49 | } 50 | 51 | @Provides @Singleton MessagePublisher publisher(GoogleApiClient client) { 52 | return new MessagePublisher(client); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_game.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 18 | 19 | 30 | 31 | 38 | 39 |