Kotlin Tic Tac Toy Game

Rahul Khatri
Yellow Roses
Published in
3 min readSep 27, 2018

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 1

Step 2: Now Name the project, domain name, click on check box which says add Kotlin support.

step 2

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 3

Step 4: Select Template, i have selected Empty Activity because i don’t need any Template. Press Next Button

step 4

Step 5: Just press Finish. This is only to change name of first activity.

step 5

Step 6: Now real coding start. Remove unnecessary code from activity_main.xml, write below code.

activity_main.xml

Explanation: Create 9 button. Here I have used TableLayout inside it TableRow.

Step 7: Now inside MainActivity.kt, write the code

On click button logic MainActivity.kt

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

Game Logic MainActivity.kt

Explanation:Create a function after the end of btnTicTac method.

Step 9: To show Winner

To Show Winner MainActivity.kt

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

MainActivity.kt

Now Run app.

It will look like.

--

--