🎮 System Design + Java Program for Tic-Tac-Toe (TicTac)
In this mini system design, we’ll build a console-based Tic-Tac-Toe game in Java.
We’ll keep it:
-
Simple
-
Readable
-
Data-structure focused
🧠 High-Level Design
We’ll design 3 main parts:
-
Board – stores the grid and game state
-
Player – represents X and O
-
Game – controls turns, input, and winning logic
Data Structures Used
-
char[][] board = new char[3][3];
→ 3x3 grid for the game -
char currentPlayer = 'X';
→ Tracks who is playing now -
Simple methods to:
-
printBoard() -
makeMove(row, col) -
checkWin() -
isDraw()
-
No complex frameworks. Just core Java + basic data structures.
📦 Class Design Overview
1️⃣ Board Class
Responsibilities:
-
Initialize empty board
-
Print the board
-
Validate and update moves
-
Check winner / draw
2️⃣ TicTacToeGame Class
Responsibilities:
-
Run the game loop
-
Switch players
-
Take input from console
-
Use
Boardto perform actions
✅ Full Java Program – Simple Tic-Tac-Toe
🧩 How This Relates to System Design (in a Simple Way)
Even though this is a small console program, it still uses good design ideas:
-
Separation of Concerns
-
Board→ game state & logic -
TicTacToeGame→ input + game loop
-
-
Encapsulation
-
Board hides its internal
gridand exposes only methods
-
-
Data Structures
-
2D array
char[][]is the core structure
-
No comments:
Post a Comment