├── .gitignore ├── .idea ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── LICENSE ├── README.md ├── apk └── Tic Tac Toe.apk ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── zeph7 │ │ └── tictactoe │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── zeph7 │ │ │ └── tictactoe │ │ │ ├── MainActivity.kt │ │ │ ├── SecondActivity.kt │ │ │ ├── SplashActivity.kt │ │ │ ├── ThirdActivity.kt │ │ │ └── WonActivity.kt │ └── res │ │ ├── anim │ │ ├── blink.xml │ │ ├── clockwise.xml │ │ ├── fade.xml │ │ ├── move.xml │ │ ├── slide.xml │ │ ├── zoom.xml │ │ └── zoom2.xml │ │ ├── drawable-hdpi │ │ └── ic_launcher_.png │ │ ├── drawable-mdpi │ │ └── ic_launcher_.png │ │ ├── drawable-v24 │ │ ├── board.png │ │ ├── board2.png │ │ ├── drawable-hdpi │ │ │ └── ic_launcher_.png │ │ ├── drawable-mdpi │ │ │ └── ic_launcher_.png │ │ ├── drawable-xhdpi │ │ │ └── ic_launcher_.png │ │ ├── drawable-xxhdpi │ │ │ └── ic_launcher_.png │ │ ├── drawable-xxxhdpi │ │ │ └── ic_launcher_.png │ │ ├── gameon.png │ │ ├── ic_launcher_foreground.xml │ │ ├── logo.png │ │ ├── particle.png │ │ ├── tac.png │ │ ├── tic.png │ │ ├── tic2.png │ │ ├── tic3.png │ │ └── tictactoe.png │ │ ├── drawable-xhdpi │ │ └── ic_launcher_.png │ │ ├── drawable-xxhdpi │ │ └── ic_launcher_.png │ │ ├── drawable-xxxhdpi │ │ └── ic_launcher_.png │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── font │ │ ├── muli_bold.xml │ │ └── muli_extralight.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── activity_second.xml │ │ ├── activity_splash.xml │ │ ├── activity_third.xml │ │ └── activity_won.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── tic3.png │ │ └── values │ │ ├── colors.xml │ │ ├── font_certs.xml │ │ ├── preloaded_fonts.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── zeph7 │ └── tictactoe │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenshots ├── img1.jpg ├── img2.jpg ├── img3.jpg └── img4.jpg └── 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 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Ashish Pandey 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tic Tac Toe app 2 | 3 | [![License](https://img.shields.io/github/license/ashish7zeph/android-kotlin-TicTacToe-game.svg?style=for-the-badge)](https://github.com/ashish7zeph/android-kotlin-TicTacToe-game/blob/master/LICENSE) 4 | [![Github contributors](https://img.shields.io/github/contributors/ashish7zeph/android-kotlin-TicTacToe-game.svg?style=for-the-badge)](https://github.com/ashish7zeph/android-kotlin-TicTacToe-game/graphs/contributors) 5 | [![Language max %](https://img.shields.io/github/languages/top/ashish7zeph/android-kotlin-TicTacToe-game.svg?colorB=orange&style=for-the-badge)](https://kotlinlang.org/) 6 | 7 | [![build for android](https://forthebadge.com/images/badges/built-for-android.svg)](https://www.android.com/) 8 | 9 | ## Overview 10 | 11 | Build a Tic Tac Toe android app with kotlin support 12 | 13 | It is the regular Tic Tac Toe game with two gameplay modes `Multiplayer` for two players and another `Single Player` for one player playing against a computer algorithm 14 | 15 | Its a fun game!! 16 | 17 | ## Features 18 | 19 | * Single player mode 20 | * Multi player mode 21 | * Splash screen 22 | * Animation styles 23 | * Minimal Design 24 | * Simplified Theme 25 | * Responsive BackPress 26 | 27 | ## Platform 28 | -> Android Studio 29 | -> With Kotlin Support 30 | 31 | ## Instructions 32 | 33 | 1. Clone or download the repo: `https://github.com/ashish7zeph/android-kotlin-TicTacToe-game` 34 | 2. Navigate to the folder `android-kotlin-TicTacToe-game` 35 | 3. Navigate to the folder `android-kotlin-TicTacToe-game/app/src/` to access developers content 36 | 3. Navigate to the folder `apk` for users to access apk 37 | 4. Copy the apk from folder `apk` to an android phone 38 | 5. Install the apk 39 | 40 | The app is finally installed on your Android mobile device !! 41 | To directly download the apk visit the [link](https://github.com/ashish7zeph/android-kotlin-TicTacToe-game/tree/master/apk) 42 | 43 | # Screenshots: 44 | 45 |
46 | App image 47 | App image 48 | App image 49 |
50 | 51 | ## Kotlin Android Activity 52 | 53 | Kotlin code of the splash screen activity in this project is shown below. For kotlin code of other activities visit the [link](https://github.com/ashish7zeph/android-kotlin-TicTacToe-game/tree/master/app/src/main/java/com/zeph7/tictactoe) 54 | 55 | ```kotlin 56 | package com.zeph7.tictactoe 57 | 58 | import android.content.Intent 59 | import android.support.v7.app.AppCompatActivity 60 | import android.os.Bundle 61 | import android.os.Handler 62 | import android.view.Window 63 | import android.view.WindowManager 64 | import android.view.animation.AnimationUtils 65 | import kotlinx.android.synthetic.main.activity_splash.* 66 | 67 | class SplashActivity : AppCompatActivity() { 68 | 69 | override fun onCreate(savedInstanceState: Bundle?) { 70 | super.onCreate(savedInstanceState) 71 | 72 | window.requestFeature(Window.FEATURE_NO_TITLE) 73 | 74 | window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 75 | WindowManager.LayoutParams.FLAG_FULLSCREEN) 76 | 77 | setContentView(R.layout.activity_splash) 78 | 79 | val anim = AnimationUtils.loadAnimation(applicationContext, R.anim.zoom) 80 | imageViewLogo.startAnimation(anim) 81 | 82 | Handler().postDelayed({ 83 | startActivity(Intent(this@SplashActivity, MainActivity::class.java)) 84 | }, 5000) 85 | } 86 | } 87 | ``` 88 | -------------------------------------------------------------------------------- /apk/Tic Tac Toe.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeph7/android-kotlin-TicTacToe-game/354f2b78bb68c6490fe4e329c07933ae6a219b9a/apk/Tic Tac Toe.apk -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'kotlin-android' 4 | 5 | apply plugin: 'kotlin-android-extensions' 6 | 7 | android { 8 | compileSdkVersion 26 9 | defaultConfig { 10 | applicationId "com.zeph7.tictactoe" 11 | minSdkVersion 16 12 | targetSdkVersion 26 13 | versionCode 1 14 | versionName "1.0" 15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | } 24 | 25 | dependencies { 26 | implementation fileTree(dir: 'libs', include: ['*.jar']) 27 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" 28 | implementation 'com.android.support:appcompat-v7:26.1.0' 29 | implementation 'com.android.support.constraint:constraint-layout:1.1.2' 30 | testImplementation 'junit:junit:4.12' 31 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 32 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 33 | } 34 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/zeph7/tictactoe/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.zeph7.tictactoe 2 | 3 | import android.support.test.InstrumentationRegistry 4 | import android.support.test.runner.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getTargetContext() 22 | assertEquals("com.zeph7.tictactoe", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 15 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 27 | 28 | 31 | 32 | 35 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/java/com/zeph7/tictactoe/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.zeph7.tictactoe 2 | 3 | import android.content.Intent 4 | import android.support.v7.app.AppCompatActivity 5 | import android.os.Bundle 6 | import android.transition.Explode 7 | import android.view.Window 8 | import android.view.WindowManager 9 | import android.view.animation.AnimationUtils 10 | import android.widget.Toast 11 | import kotlinx.android.synthetic.main.activity_main.* 12 | 13 | class MainActivity : AppCompatActivity() { 14 | 15 | override fun onCreate(savedInstanceState: Bundle?) { 16 | super.onCreate(savedInstanceState) 17 | window.requestFeature(Window.FEATURE_NO_TITLE) 18 | window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 19 | WindowManager.LayoutParams.FLAG_FULLSCREEN) 20 | window.requestFeature(Window.FEATURE_CONTENT_TRANSITIONS) 21 | setContentView(R.layout.activity_main) 22 | 23 | val animClockwise = AnimationUtils.loadAnimation(applicationContext, R.anim.clockwise) 24 | val animMove = AnimationUtils.loadAnimation(applicationContext, R.anim.move) 25 | val animFade = AnimationUtils.loadAnimation(applicationContext, R.anim.fade) 26 | val animSlide = AnimationUtils.loadAnimation(applicationContext, R.anim.slide) 27 | val animZoom = AnimationUtils.loadAnimation(applicationContext, R.anim.zoom) 28 | val animZoom2 = AnimationUtils.loadAnimation(applicationContext, R.anim.zoom2) 29 | val animBlink = AnimationUtils.loadAnimation(applicationContext, R.anim.blink) 30 | imgTicTacToe.startAnimation(animBlink) 31 | zephGames.startAnimation(animClockwise) 32 | 33 | btnSingle.setOnClickListener{ 34 | btnSingle.startAnimation(animZoom2) 35 | startActivity(Intent(this@MainActivity, SecondActivity::class.java)) 36 | } 37 | 38 | btnMulti.setOnClickListener{ 39 | btnMulti.startAnimation(animZoom2) 40 | startActivity(Intent(this@MainActivity, ThirdActivity::class.java)) 41 | } 42 | 43 | imgTicTacToe.setOnClickListener{ 44 | imgTicTacToe.startAnimation(animBlink) 45 | } 46 | 47 | zephGames.setOnClickListener{ 48 | zephGames.startAnimation(animClockwise) 49 | } 50 | 51 | // back ImageView 52 | imageViewBack.setOnClickListener { 53 | finish() 54 | moveTaskToBack(true) 55 | } 56 | 57 | // quit ImageView 58 | imageViewQuit.setOnClickListener { 59 | finish() 60 | moveTaskToBack(true) 61 | } 62 | 63 | } 64 | 65 | // for handling back button of the Android Device 66 | override fun onBackPressed() { 67 | super.onBackPressed() 68 | moveTaskToBack(true) 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /app/src/main/java/com/zeph7/tictactoe/SecondActivity.kt: -------------------------------------------------------------------------------- 1 | package com.zeph7.tictactoe 2 | 3 | import android.content.Context 4 | import android.content.Intent 5 | import android.support.v7.app.AppCompatActivity 6 | import android.os.Bundle 7 | import android.view.Window 8 | import android.view.WindowManager 9 | import android.view.animation.AnimationUtils 10 | import kotlinx.android.synthetic.main.activity_third.* 11 | import java.text.FieldPosition 12 | import java.util.* 13 | import kotlin.collections.ArrayList 14 | 15 | class SecondActivity : AppCompatActivity() { 16 | 17 | override fun onCreate(savedInstanceState: Bundle?) { 18 | super.onCreate(savedInstanceState) 19 | window.requestFeature(Window.FEATURE_NO_TITLE) 20 | window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 21 | WindowManager.LayoutParams.FLAG_FULLSCREEN) 22 | setContentView(R.layout.activity_second) 23 | 24 | val anim = AnimationUtils.loadAnimation(applicationContext, R.anim.move) 25 | imageViewGameOn.startAnimation(anim) 26 | 27 | var board = arrayListOf("", "", "", "", "", "", "", "", "") 28 | 29 | button0.setOnClickListener { 30 | if (board[0] == "") { 31 | button0.text = "X" 32 | board[0] = "X" 33 | if(!isBoardFull(board) && !result(board, "X")) { 34 | val position = getComputerMove(board) 35 | board[position] = "O" 36 | displayComputerButton(position) 37 | } 38 | } 39 | resultOut(board) 40 | } 41 | 42 | button1.setOnClickListener { 43 | if (board[1] == "") { 44 | button1.text = "X" 45 | board[1] = "X" 46 | if(!isBoardFull(board) && !result(board, "X")) { 47 | val position = getComputerMove(board) 48 | board[position] = "O" 49 | displayComputerButton(position) 50 | } 51 | } 52 | resultOut(board) 53 | } 54 | 55 | button2.setOnClickListener { 56 | if (board[2] == "") { 57 | button2.text = "X" 58 | board[2] = "X" 59 | if(!isBoardFull(board) && !result(board, "X")) { 60 | val position = getComputerMove(board) 61 | board[position] = "O" 62 | displayComputerButton(position) 63 | } 64 | } 65 | resultOut(board) 66 | } 67 | 68 | button3.setOnClickListener { 69 | if (board[3] == "") { 70 | button3.text = "X" 71 | board[3] = "X" 72 | if(!isBoardFull(board) && !result(board, "X")) { 73 | val position = getComputerMove(board) 74 | board[position] = "O" 75 | displayComputerButton(position) 76 | } 77 | } 78 | resultOut(board) 79 | } 80 | 81 | button4.setOnClickListener { 82 | if (board[4] == "") { 83 | button4.text = "X" 84 | board[4] = "X" 85 | if(!isBoardFull(board) && !result(board, "X")) { 86 | val position = getComputerMove(board) 87 | board[position] = "O" 88 | displayComputerButton(position) 89 | } 90 | } 91 | resultOut(board) 92 | } 93 | 94 | button5.setOnClickListener { 95 | if (board[5] == "") { 96 | button5.text = "X" 97 | board[5] = "X" 98 | if(!isBoardFull(board) && !result(board, "X")) { 99 | val position = getComputerMove(board) 100 | board[position] = "O" 101 | displayComputerButton(position) 102 | } 103 | } 104 | resultOut(board) 105 | } 106 | 107 | button6.setOnClickListener { 108 | if (board[6] == "") { 109 | button6.text = "X" 110 | board[6] = "X" 111 | if(!isBoardFull(board) && !result(board, "X")) { 112 | val position = getComputerMove(board) 113 | board[position] = "O" 114 | displayComputerButton(position) 115 | } 116 | } 117 | resultOut(board) 118 | } 119 | 120 | button7.setOnClickListener { 121 | if (board[7] == "") { 122 | button7.text = "X" 123 | board[7] = "X" 124 | if(!isBoardFull(board) && !result(board, "X")) { 125 | val position = getComputerMove(board) 126 | board[position] = "O" 127 | displayComputerButton(position) 128 | } 129 | } 130 | resultOut(board) 131 | } 132 | 133 | button8.setOnClickListener { 134 | if (board[8] == "") { 135 | button8.text = "X" 136 | board[8] = "X" 137 | if(!isBoardFull(board) && !result(board, "X")) { 138 | val position = getComputerMove(board) 139 | board[position] = "O" 140 | displayComputerButton(position) 141 | } 142 | } 143 | resultOut(board) 144 | } 145 | 146 | buttonReset.setOnClickListener{ 147 | startActivity(Intent(this@SecondActivity, SecondActivity::class.java)) 148 | } 149 | 150 | // back ImageView 151 | imageViewBack.setOnClickListener{ 152 | startActivity(Intent(this@SecondActivity, MainActivity::class.java)) 153 | } 154 | 155 | // quit ImageView 156 | imageViewQuit.setOnClickListener { 157 | finish() 158 | moveTaskToBack(true) //to quit app 159 | } 160 | 161 | } 162 | 163 | private fun getComputerMove(board: ArrayList): Int { 164 | 165 | //check if computer can win in this move 166 | for (i in 0..board.count()-1){ 167 | var copy: ArrayList = getBoardCopy(board) 168 | if(copy[i] == "") copy[i] = "O" 169 | if(result(copy, "O")) return i 170 | } 171 | 172 | //check if player could win in the next move 173 | for (i in 0..board.count()-1){ 174 | var copy2 = getBoardCopy(board) 175 | if(copy2[i] == "") copy2[i] = "X" 176 | if(result(copy2, "X")) return i 177 | } 178 | 179 | //try to take corners if its free 180 | var move = choseRandomMove(board, arrayListOf(0, 2, 6, 8)) 181 | if(move != -1) 182 | return move 183 | 184 | //try to take center if its free 185 | if(board[4] == "") return 4 186 | 187 | //move on one of the sides 188 | return choseRandomMove(board, arrayListOf(1, 3, 5, 7)) 189 | } 190 | 191 | 192 | private fun choseRandomMove(board: ArrayList, list: ArrayList): Int { 193 | var possibleMoves = arrayListOf() 194 | for (i in list){ 195 | if(board[i] == "") possibleMoves.add(i) 196 | } 197 | if(possibleMoves.isEmpty()) return -1 198 | else { 199 | var index = Random().nextInt(possibleMoves.count()) 200 | return possibleMoves[index] 201 | } 202 | } 203 | 204 | private fun getBoardCopy(board: ArrayList): ArrayList { 205 | var bd = arrayListOf("", "", "", "", "", "", "", "", "") 206 | for (i in 0..board.count()-1) { 207 | bd[i] = board[i] 208 | } 209 | return bd 210 | } 211 | 212 | private fun isBoardFull(board: ArrayList): Boolean { 213 | for (i in board) 214 | if(i != "X" && i != "O") return false 215 | return true 216 | } 217 | 218 | 219 | private fun resultOut(board: ArrayList){ 220 | if(result(board, "X")){ 221 | startActivity(Intent(this@SecondActivity, WonActivity::class.java).putExtra("player", "YOU")) 222 | }else if(result(board, "O")){ 223 | startActivity(Intent(this@SecondActivity, WonActivity::class.java).putExtra("player", "COMPUTER")) 224 | } 225 | if(isBoardFull(board)){ 226 | startActivity(Intent(this@SecondActivity, WonActivity::class.java).putExtra("player", "Tie")) 227 | } 228 | } 229 | 230 | 231 | private fun result(bd: ArrayList, s: String): Boolean = 232 | if(bd[0] == s && bd[1] == s && bd[2] == s) true 233 | else if(bd[3] == s && bd[4] == s && bd[5] == s) true 234 | else if(bd[6] == s && bd[7] == s && bd[8] == s) true 235 | else if(bd[0] == s && bd[3] == s && bd[6] == s) true 236 | else if(bd[1] == s && bd[4] == s && bd[7] == s) true 237 | else if(bd[2] == s && bd[5] == s && bd[8] == s) true 238 | else if(bd[0] == s && bd[4] == s && bd[8] == s) true 239 | else if(bd[2] == s && bd[4] == s && bd[6] == s) true 240 | else false 241 | 242 | 243 | private fun displayComputerButton(position: Int){ 244 | if(position == 0) button0.text = "O" 245 | else if(position == 1) button1.text = "O" 246 | else if(position == 2) button2.text = "O" 247 | else if(position == 3) button3.text = "O" 248 | else if(position == 4) button4.text = "O" 249 | else if(position == 5) button5.text = "O" 250 | else if(position == 6) button6.text = "O" 251 | else if(position == 7) button7.text = "O" 252 | else if(position == 8) button8.text = "O" 253 | } 254 | 255 | 256 | // for handling back buttton of the Android Device 257 | override fun onBackPressed() { 258 | super.onBackPressed() 259 | startActivity(Intent(this@SecondActivity, MainActivity::class.java)) 260 | } 261 | 262 | } 263 | -------------------------------------------------------------------------------- /app/src/main/java/com/zeph7/tictactoe/SplashActivity.kt: -------------------------------------------------------------------------------- 1 | package com.zeph7.tictactoe 2 | 3 | import android.content.Intent 4 | import android.support.v7.app.AppCompatActivity 5 | import android.os.Bundle 6 | import android.os.Handler 7 | import android.view.Window 8 | import android.view.WindowManager 9 | import android.view.animation.AnimationUtils 10 | import kotlinx.android.synthetic.main.activity_splash.* 11 | 12 | class SplashActivity : AppCompatActivity() { 13 | 14 | override fun onCreate(savedInstanceState: Bundle?) { 15 | super.onCreate(savedInstanceState) 16 | 17 | window.requestFeature(Window.FEATURE_NO_TITLE) 18 | 19 | window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 20 | WindowManager.LayoutParams.FLAG_FULLSCREEN) 21 | 22 | setContentView(R.layout.activity_splash) 23 | 24 | val anim = AnimationUtils.loadAnimation(applicationContext, R.anim.zoom) 25 | imageViewLogo.startAnimation(anim) 26 | 27 | Handler().postDelayed({ 28 | startActivity(Intent(this@SplashActivity, MainActivity::class.java)) 29 | }, 5000) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/zeph7/tictactoe/ThirdActivity.kt: -------------------------------------------------------------------------------- 1 | package com.zeph7.tictactoe 2 | 3 | import android.content.Intent 4 | import android.support.v7.app.AppCompatActivity 5 | import android.os.Bundle 6 | import android.view.Window 7 | import android.view.WindowManager 8 | import android.view.animation.AnimationUtils 9 | import kotlinx.android.synthetic.main.activity_third.* 10 | import kotlin.system.exitProcess 11 | 12 | class ThirdActivity : AppCompatActivity() { 13 | 14 | override fun onCreate(savedInstanceState: Bundle?) { 15 | super.onCreate(savedInstanceState) 16 | window.requestFeature(Window.FEATURE_NO_TITLE) 17 | window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 18 | WindowManager.LayoutParams.FLAG_FULLSCREEN) 19 | setContentView(R.layout.activity_third) 20 | 21 | val anim = AnimationUtils.loadAnimation(applicationContext, R.anim.move) 22 | imageViewGameOn.startAnimation(anim) 23 | 24 | var chance = "X" 25 | var board = arrayListOf("", "", "", "", "", "", "", "", "") 26 | 27 | button0.setOnClickListener { 28 | if (board[0] != "") 29 | else if (chance == "X") { 30 | button0.text = "X" 31 | board[0] = "X" 32 | chance = "O" 33 | } else { 34 | button0.text = "O" 35 | board[0] = "O" 36 | chance = "X" 37 | } 38 | resultOut(board) 39 | } 40 | 41 | button1.setOnClickListener { 42 | if (board[1] != "") 43 | else if (chance == "X") { 44 | button1.text = "X" 45 | board[1] = "X" 46 | chance = "O" 47 | } else { 48 | button1.text = "O" 49 | board[1] = "O" 50 | chance = "X" 51 | } 52 | resultOut(board) 53 | } 54 | 55 | button2.setOnClickListener { 56 | if (board[2] != "") 57 | else if (chance == "X") { 58 | button2.text = "X" 59 | board[2] = "X" 60 | chance = "O" 61 | } else { 62 | button2.text = "O" 63 | board[2] = "O" 64 | chance = "X" 65 | } 66 | resultOut(board) 67 | } 68 | 69 | button3.setOnClickListener { 70 | if (board[3] != "") 71 | else if (chance == "X") { 72 | button3.text = "X" 73 | board[3] = "X" 74 | chance = "O" 75 | } else { 76 | button3.text = "O" 77 | board[3] = "O" 78 | chance = "X" 79 | } 80 | resultOut(board) 81 | } 82 | 83 | button4.setOnClickListener { 84 | if (board[4] != "") 85 | else if (chance == "X") { 86 | button4.text = "X" 87 | board[4] = "X" 88 | chance = "O" 89 | } else { 90 | button4.text = "O" 91 | board[4] = "O" 92 | chance = "X" 93 | } 94 | resultOut(board) 95 | } 96 | 97 | button5.setOnClickListener { 98 | if (board[5] != "") 99 | else if (chance == "X") { 100 | button5.text = "X" 101 | board[5] = "X" 102 | chance = "O" 103 | } else { 104 | button5.text = "O" 105 | board[5] = "O" 106 | chance = "X" 107 | } 108 | resultOut(board) 109 | } 110 | 111 | button6.setOnClickListener { 112 | if (board[6] != "") 113 | else if (chance == "X") { 114 | button6.text = "X" 115 | board[6] = "X" 116 | chance = "O" 117 | } else { 118 | button6.text = "O" 119 | board[6] = "O" 120 | chance = "X" 121 | } 122 | resultOut(board) 123 | } 124 | 125 | button7.setOnClickListener { 126 | if (board[7] != "") 127 | else if (chance == "X") { 128 | button7.text = "X" 129 | board[7] = "X" 130 | chance = "O" 131 | } else { 132 | button7.text = "O" 133 | board[7] = "O" 134 | chance = "X" 135 | } 136 | resultOut(board) 137 | } 138 | 139 | button8.setOnClickListener { 140 | if (board[8] != "") 141 | else if (chance == "X") { 142 | button8.text = "X" 143 | board[8] = "X" 144 | chance = "O" 145 | } else { 146 | button8.text = "O" 147 | board[8] = "O" 148 | chance = "X" 149 | } 150 | resultOut(board) 151 | } 152 | 153 | buttonReset.setOnClickListener{ 154 | startActivity(Intent(this@ThirdActivity, ThirdActivity::class.java)) 155 | } 156 | 157 | // back ImageView 158 | imageViewBack.setOnClickListener{ 159 | startActivity(Intent(this@ThirdActivity, MainActivity::class.java)) 160 | } 161 | 162 | // quit ImageView 163 | imageViewQuit.setOnClickListener { 164 | finish() 165 | moveTaskToBack(true) //to quit app 166 | } 167 | 168 | } 169 | 170 | private fun resultOut(board: ArrayList){ 171 | if(result(board, "X")){ 172 | startActivity(Intent(this@ThirdActivity, WonActivity::class.java).putExtra("player", "X")) 173 | }else if(result(board, "O")){ 174 | startActivity(Intent(this@ThirdActivity, WonActivity::class.java).putExtra("player", "O")) 175 | } 176 | if(isBoardFull(board)){ 177 | startActivity(Intent(this@ThirdActivity, WonActivity::class.java).putExtra("player", "Tie")) 178 | } 179 | } 180 | 181 | private fun isBoardFull(board: ArrayList): Boolean { 182 | for (i in board) 183 | if(i != "X" && i != "O") return false 184 | return true 185 | } 186 | 187 | private fun result(bd: ArrayList, s: String): Boolean = 188 | if(bd[0] == s && bd[1] == s && bd[2] == s) true 189 | else if(bd[3] == s && bd[4] == s && bd[5] == s) true 190 | else if(bd[6] == s && bd[7] == s && bd[8] == s) true 191 | else if(bd[0] == s && bd[3] == s && bd[6] == s) true 192 | else if(bd[1] == s && bd[4] == s && bd[7] == s) true 193 | else if(bd[2] == s && bd[5] == s && bd[8] == s) true 194 | else if(bd[0] == s && bd[4] == s && bd[8] == s) true 195 | else if(bd[2] == s && bd[4] == s && bd[6] == s) true 196 | else false 197 | 198 | // for handling back buttton of the Android Device 199 | override fun onBackPressed() { 200 | super.onBackPressed() 201 | startActivity(Intent(this@ThirdActivity, MainActivity::class.java)) 202 | } 203 | 204 | } 205 | -------------------------------------------------------------------------------- /app/src/main/java/com/zeph7/tictactoe/WonActivity.kt: -------------------------------------------------------------------------------- 1 | package com.zeph7.tictactoe 2 | 3 | import android.content.Intent 4 | import android.support.v7.app.AppCompatActivity 5 | import android.os.Bundle 6 | import android.os.Handler 7 | import android.view.Window 8 | import android.view.WindowManager 9 | import android.view.animation.AnimationUtils 10 | import kotlinx.android.synthetic.main.activity_won.* 11 | 12 | class WonActivity : AppCompatActivity() { 13 | 14 | override fun onCreate(savedInstanceState: Bundle?) { 15 | super.onCreate(savedInstanceState) 16 | window.requestFeature(Window.FEATURE_NO_TITLE) 17 | window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 18 | WindowManager.LayoutParams.FLAG_FULLSCREEN) 19 | setContentView(R.layout.activity_won) 20 | 21 | val player = intent.getStringExtra("player") 22 | if(player == "Tie") textViewWon.text = "TIE" 23 | else textViewWon.text = "$player WON" 24 | 25 | val anim = AnimationUtils.loadAnimation(applicationContext, R.anim.zoom) 26 | textViewWon.startAnimation(anim) 27 | 28 | Handler().postDelayed({ 29 | startActivity(Intent(this@WonActivity, MainActivity::class.java)) 30 | }, 3000) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/res/anim/blink.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/anim/clockwise.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | 18 | 19 | 20 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/res/anim/fade.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 | 11 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/anim/move.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/anim/zoom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14 | 15 | 16 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/res/anim/zoom2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | 14 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_launcher_.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeph7/android-kotlin-TicTacToe-game/354f2b78bb68c6490fe4e329c07933ae6a219b9a/app/src/main/res/drawable-hdpi/ic_launcher_.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_launcher_.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeph7/android-kotlin-TicTacToe-game/354f2b78bb68c6490fe4e329c07933ae6a219b9a/app/src/main/res/drawable-mdpi/ic_launcher_.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/board.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeph7/android-kotlin-TicTacToe-game/354f2b78bb68c6490fe4e329c07933ae6a219b9a/app/src/main/res/drawable-v24/board.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/board2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeph7/android-kotlin-TicTacToe-game/354f2b78bb68c6490fe4e329c07933ae6a219b9a/app/src/main/res/drawable-v24/board2.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/drawable-hdpi/ic_launcher_.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeph7/android-kotlin-TicTacToe-game/354f2b78bb68c6490fe4e329c07933ae6a219b9a/app/src/main/res/drawable-v24/drawable-hdpi/ic_launcher_.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/drawable-mdpi/ic_launcher_.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeph7/android-kotlin-TicTacToe-game/354f2b78bb68c6490fe4e329c07933ae6a219b9a/app/src/main/res/drawable-v24/drawable-mdpi/ic_launcher_.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/drawable-xhdpi/ic_launcher_.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeph7/android-kotlin-TicTacToe-game/354f2b78bb68c6490fe4e329c07933ae6a219b9a/app/src/main/res/drawable-v24/drawable-xhdpi/ic_launcher_.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/drawable-xxhdpi/ic_launcher_.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeph7/android-kotlin-TicTacToe-game/354f2b78bb68c6490fe4e329c07933ae6a219b9a/app/src/main/res/drawable-v24/drawable-xxhdpi/ic_launcher_.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/drawable-xxxhdpi/ic_launcher_.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeph7/android-kotlin-TicTacToe-game/354f2b78bb68c6490fe4e329c07933ae6a219b9a/app/src/main/res/drawable-v24/drawable-xxxhdpi/ic_launcher_.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/gameon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeph7/android-kotlin-TicTacToe-game/354f2b78bb68c6490fe4e329c07933ae6a219b9a/app/src/main/res/drawable-v24/gameon.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeph7/android-kotlin-TicTacToe-game/354f2b78bb68c6490fe4e329c07933ae6a219b9a/app/src/main/res/drawable-v24/logo.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/particle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeph7/android-kotlin-TicTacToe-game/354f2b78bb68c6490fe4e329c07933ae6a219b9a/app/src/main/res/drawable-v24/particle.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/tac.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeph7/android-kotlin-TicTacToe-game/354f2b78bb68c6490fe4e329c07933ae6a219b9a/app/src/main/res/drawable-v24/tac.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/tic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeph7/android-kotlin-TicTacToe-game/354f2b78bb68c6490fe4e329c07933ae6a219b9a/app/src/main/res/drawable-v24/tic.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/tic2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeph7/android-kotlin-TicTacToe-game/354f2b78bb68c6490fe4e329c07933ae6a219b9a/app/src/main/res/drawable-v24/tic2.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/tic3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeph7/android-kotlin-TicTacToe-game/354f2b78bb68c6490fe4e329c07933ae6a219b9a/app/src/main/res/drawable-v24/tic3.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/tictactoe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeph7/android-kotlin-TicTacToe-game/354f2b78bb68c6490fe4e329c07933ae6a219b9a/app/src/main/res/drawable-v24/tictactoe.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_launcher_.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeph7/android-kotlin-TicTacToe-game/354f2b78bb68c6490fe4e329c07933ae6a219b9a/app/src/main/res/drawable-xhdpi/ic_launcher_.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_launcher_.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeph7/android-kotlin-TicTacToe-game/354f2b78bb68c6490fe4e329c07933ae6a219b9a/app/src/main/res/drawable-xxhdpi/ic_launcher_.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_launcher_.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeph7/android-kotlin-TicTacToe-game/354f2b78bb68c6490fe4e329c07933ae6a219b9a/app/src/main/res/drawable-xxxhdpi/ic_launcher_.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/font/muli_bold.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/font/muli_extralight.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 |