Published on

Create a Color Memory Game in Excel

Authors

Create a Color Memory Game in Excel

Let's create a fun memory game where players need to remember a sequence of colors. This simple game helps improve memory while demonstrating Excel's animation and timing capabilities.

Game Overview

  • Game shows a sequence of colors
  • Colors disappear after a brief display
  • Player must click colors in the correct order
  • Score increases with each successful round
  • Game gets harder as you progress

Step-by-Step Tutorial

1. Setting Up the Game Board

First, let's create our game interface:

  • Cells B2:E2: These will be our four colored buttons
  • Cell B4: "Current Score:"
  • Cell C4: Will show the player's score
  • Cell B6: "Status:"
  • Cell C6: Will show game messages

2. Creating the Color Buttons

  1. Format cells B2:E2 as squares:

    • Set row height to 50
    • Set column width to make cells square
    • Center align all cells
  2. Color the cells:

    • B2: Red (ColorIndex = 3)
    • C2: Blue (ColorIndex = 5)
    • D2: Yellow (ColorIndex = 6)
    • E2: Green (ColorIndex = 4)

3. Adding VBA Code

Public Sequence(1 To 10) As Integer
Public CurrentLength As Integer
Public PlayerPosition As Integer
Public Score As Integer

Sub StartGame()
    Score = 0
    Range("C4").Value = Score
    CurrentLength = 1
    ShowSequence
End Sub

Sub ShowSequence()
    Range("C6").Value = "Watch carefully..."
    Application.Wait Now + TimeValue("00:00:01")
    
    ' Generate new sequence
    Randomize
    For i = 1 To CurrentLength
        Sequence(i) = Int(Rnd * 4) + 1
    Next i
    
    ' Show sequence
    For i = 1 To CurrentLength
        FlashCell Sequence(i)
    Next i
    
    PlayerPosition = 1
    Range("C6").Value = "Your turn! Click the colors in order"
End Sub

Sub FlashCell(ColorPosition As Integer)
    Dim cell As Range
    Set cell = Range("B2").Offset(0, ColorPosition - 1)
    
    ' Store original color
    Dim originalColor As Integer
    originalColor = cell.Interior.ColorIndex
    
    ' Flash white
    cell.Interior.ColorIndex = 2
    Application.Wait Now + TimeValue("00:00:0.3")
    
    ' Return to original color
    cell.Interior.ColorIndex = originalColor
    Application.Wait Now + TimeValue("00:00:0.2")
End Sub

Sub ColorClick(ColorPosition As Integer)
    If PlayerPosition = 0 Then Exit Sub
    
    If Sequence(PlayerPosition) = ColorPosition Then
        ' Correct choice
        If PlayerPosition = CurrentLength Then
            ' Completed sequence
            Score = Score + CurrentLength
            Range("C4").Value = Score
            Range("C6").Value = "Correct! Next sequence..."
            CurrentLength = CurrentLength + 1
            PlayerPosition = 0
            Application.Wait Now + TimeValue("00:00:01")
            ShowSequence
        Else
            ' Continue sequence
            PlayerPosition = PlayerPosition + 1
        End If
    Else
        ' Wrong choice
        Range("C6").Value = "Game Over! Score: " & Score
        PlayerPosition = 0
    End If
End Sub

4. Adding Button Actions

  1. Right-click each colored cell and assign macros:

    • Red (B2): =ColorClick(1)
    • Blue (C2): =ColorClick(2)
    • Yellow (D2): =ColorClick(3)
    • Green (E2): =ColorClick(4)
  2. Add a "New Game" button:

    • Insert a button labeled "Start New Game"
    • Assign it to the StartGame macro

How to Play

  1. Click "Start New Game"
  2. Watch the sequence of flashing colors
  3. Click the colors in the same order they appeared
  4. Each correct sequence adds to your score
  5. Game continues until you make a mistake

Understanding the Game Mechanics

This game demonstrates several Excel gaming concepts:

  1. Visual Effects: Using cell colors for game elements
  2. Memory Mechanics: Storing and checking sequences
  3. Progressive Difficulty: Increasing sequence length
  4. Score System: Rewarding successful memory recall

Download

You can download the game template here (Coming soon)

Next Steps

Try these modifications to enhance the game:

  1. Add sound effects for correct/incorrect sequences
  2. Include different difficulty levels
  3. Add a high score system

Stay tuned for more Excel game development tutorials!


This memory game shows how Excel can create engaging cognitive games using simple cell formatting and basic VBA code. It's a perfect example of turning Excel into an interactive gaming platform.