Skip to content

chrisr3ddington/game-of-life

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Conway's Game of Life

An interactive implementation of Conway's Game of Life using HTML5 Canvas with the following features:

  • Responsive grid that adapts to window size
  • Color-coded cells based on neighbor count
  • Toroidal array implementation (edges wrap around)
  • Page visibility optimization (pauses when tab is inactive)

Implementation Details

The game is built using vanilla JavaScript with classes handling different aspects:

  • GameState: Manages the application state
  • GridManager: Handles grid initialization and game rules
  • CanvasManager: Controls canvas setup and resizing
  • Renderer: Responsible for drawing cells with dynamic coloring
  • GameLoop: Manages animation and page visibility
classDiagram
    class GameState {
        +canvas
        +ctx
        +width
        +height
        +grid
        +isPageVisible
        +animationFrameId
    }
    
    class CanvasManager {
        +init()
        +resize()
    }
    
    class GridManager {
        +init()
        +countNeighbors(x, y)
        +update()
    }
    
    class Renderer {
        +getColorForNeighbors(neighbors)
        +draw()
    }
    
    class GameLoop {
        +animate()
        +handleVisibilityChange()
    }
    
    GameState <.. CanvasManager : uses
    GameState <.. GridManager : uses
    GameState <.. Renderer : uses
    GameState <.. GameLoop : uses
    CanvasManager <.. GameLoop : uses
    GridManager <.. Renderer : uses
Loading

Getting Started

  1. Clone the repository
  2. Open index.html in a web browser
  3. Watch the Game of Life evolve!

Contributing

Contributions are welcome! Here are some ways you can contribute:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Setup

The project uses a simple structure:

License

This project is open source and available under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published