Published on

Create a Stylish TicTacToe Game in Excel

Authors

Game Overview

Create a classic TicTacToe game in Excel with a modern, clean design. Players take turns marking X's and O's in a 3x3 grid, aiming to get three in a row.

Here's how the game interface looks:

Game Interface Layout:
+-----+-----+-----+------------+
|  X  |  O  |     | Player X's |
+-----+-----+-----+   Turn     |
|     |  X  |     |           |
+-----+-----+-----+ Game in    |
|  O  |     |     | Progress   |
+-----+-----+-----+  [Reset]   |

Design Elements

Game Board Layout

  • Use cells A1:C3 for the game grid
  • Set column width and row height to 60 pixels for perfect squares
  • Apply thick borders to create the classic grid pattern:
    Selection.Borders(xlEdgeLeft).Weight = xlMedium
    Selection.Borders(xlEdgeRight).Weight = xlMedium
    Selection.Borders(xlEdgeTop).Weight = xlMedium
    Selection.Borders(xlEdgeBottom).Weight = xlMedium
    

Visual Styling

  • Background: Light gray (#F5F5F5) for empty cells
  • Player X: Bold "X" in blue (#007BFF)
  • Player O: Bold "O" in red (#DC3545)
  • Font: Calibri, 36pt, centered
  • Hover Effect: Slightly darker background on mouseover

Game Status Area

  • Current Player Display (D1): "Player X's Turn" / "Player O's Turn"
  • Game Status (D2): "Game in Progress" / "Winner!" / "Draw!"
  • Reset Button (D3): Simple button to clear the board

Cell Formatting

  1. Select the game board (A1:C3)
  2. Format cells:
With Selection
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlCenter
    .Font.Name = "Calibri"
    .Font.Size = 36
    .Font.Bold = True
End With
  1. Add conditional formatting for:
  • X cells: Blue color with white background
  • O cells: Red color with white background
  • Empty cells: Light gray background
  • Winning combination: Green background highlight

Game Logic

Cell Validation

Use Data Validation to only allow "X" or "O":

With Selection.Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
         Operator:=xlBetween, Formula1:="X,O"
End With

Turn Management

Track current player in a hidden cell (E1):

=IF(MOD(COUNTA(A1:C3),2)=0,"X","O")

Win Detection

Check for winning combinations using array formulas:

=OR(
    AND(A1=B1,B1=C1,A1<>""), // Row 1
    AND(A2=B2,B2=C2,A2<>""), // Row 2
    AND(A3=B3,B3=C3,A3<>""), // Row 3
    AND(A1=A2,A2=A3,A1<>""), // Column 1
    AND(B1=B2,B2=B3,B1<>""), // Column 2
    AND(C1=C2,C2=C3,C1<>""), // Column 3
    AND(A1=B2,B2=C3,A1<>""), // Diagonal 1
    AND(C1=B2,B2=A3,C1<>"")  // Diagonal 2
)

User Experience

  1. Clear visual feedback:

    • Highlight current player's turn
    • Show winning combination in green
    • Display clear game status messages
  2. Easy interaction:

    • Single-click to place X or O
    • Reset button to start new game
    • Prevent moves after game ends
  3. Responsive design:

    • Cells resize with window
    • Maintains square proportions
    • Clear visibility on all zoom levels

Enhancement Ideas

  1. Add sound effects for:

    • Placing X/O
    • Winning
    • Draw game
  2. Include animations:

    • Piece placement
    • Win celebration
    • Board reset
  3. Track statistics:

    • Games played
    • Win ratio
    • Average moves per game

This design creates a professional-looking game that's both fun to play and easy to understand. The clean layout and clear visual feedback make it perfect for learning Excel game development basics.

Game Progress Example

Here's how the game looks when X player wins:

Game Interface Layout:

+-----+-----+-----+------------+
|  X  |  O  |  O  |   Game    |
+-----+-----+-----+   Over!    |
|     |  X  |  O  |           |
+-----+-----+-----+ Player X   |
|     |     |  X  |  Wins!    |
+-----+-----+-----+  [Reset]   |