Skip to content

A classic two-player Tic Tac Toe game for Android built with Kotlin and XML layouts. Features include win/draw detection, score tracking, game state persistence, and a clean, intuitive UI.

Notifications You must be signed in to change notification settings

sinemistoktas/android-tic_tac_toe_app

Repository files navigation

Tic Tac Toe Android App

by Sinemis Toktaş

This is a simple two-player Tic Tac Toe game built using Kotlin and XML layouts for Android.

Features

  • 3x3 grid with touch interaction
  • Win/draw detection
  • Score tracking
  • Play again and reset options
  • Game and UI state persistence using onSaveInstanceState()

Requirements

  • Android Studio
  • Kotlin
  • Target SDK: API 28+

How to Run

  1. Clone the repo or open the project in Android Studio.
  2. Run the app on an emulator or physical device.

Implementation Details

Classes Implemented

  • MainActivity.kt: Manages the UI logic and responds to user interactions.
  • TicTacToeGame.kt: Contains the game logic including board state, win/draw checking, and score keeping.

Game Logic

The game logic is encapsulated in TicTacToeGame, a class that maintains the board, current turn, player scores, and win/draw state. It includes methods for:

  • Making moves
  • Switching turns
  • Checking win and draw conditions
  • Resetting game or board
  • Exposing necessary getters for state recovery

UI and State Handling

  • The UI is defined using XML layouts and manipulated in MainActivity.
  • A list of buttons is used to represent the 3x3 game board.
  • Each move updates both the board UI and the internal state.
  • After each move, the app checks if a player has won or if the game ends in a draw.
  • The game state (board, turn, scores) is saved using onSaveInstanceState() and restored in onCreate() to survive screen rotation.
  • Turn display and text colors are also restored accordingly.

UI Event Handling

  • boardButtonClicked() responds to player moves.
  • playAgainButtonClicked() resets only the board.
  • resetGameButtonClicked() resets both board and scores.

Screenshots

External Resources

About

A classic two-player Tic Tac Toe game for Android built with Kotlin and XML layouts. Features include win/draw detection, score tracking, game state persistence, and a clean, intuitive UI.

Topics

Resources

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages