Kotlin Tic Tac Toy Game
Android App using Kotlin as programming language, A Simple Tic Tac Toy Game App.
First open Android Studio,
Step 1: Go inside File -> New -> New Project. Image below display hoe to do that.
If your android studio is 3.x it has build in Kotlin support.
Step 2: Now Name the project, domain name, click on check box which says add Kotlin support.
Step 3: Select Target device. it means min version of android in which app will run. I have selected API 16. Press Next button.
Step 4: Select Template, i have selected Empty Activity because i don’t need any Template. Press Next Button
Step 5: Just press Finish. This is only to change name of first activity.
Step 6: Now real coding start. Remove unnecessary code from activity_main.xml, write below code.
Explanation: Create 9 button. Here I have used TableLayout inside it TableRow.
Step 7: Now inside MainActivity.kt, write the code
Explanation: Create a function inside AppCompatActivity, after the end of onCreate method. Now Run app
This is to check all the button working or not.
Step 8: Game logic
Explanation:Create a function after the end of btnTicTac method.
Step 9: To show Winner
Explanation: Create a function after the end of GameLogic method.
Here i have alert dialog box which will open a player win. It will ask to play again or leave game.
Here SomeActivity::class.java refers to any activity but you need to create it or either remove the entire line. That means comment the below line
// startActivity(Intent(this, SomeActivity::class.java))
Step 10: Entire MainActivity.kt
Now Run app.
It will look like.