Giter Club home page Giter Club logo

pygame-of-life's Introduction

alt text

This is an implementation of Conway's Game of Life written as an exercise in learning Python, Pygame, and MVC. Written during Hacker School, Batch[4], Fall 2012.

The Rules

The universe is an infinite grid of square cells, each dead or alive. A cell dies or lives on to the next generation based on the states of its 8 neighbors. For every tick in time:

  • any live cell with less than 2 live neighbors dies
  • any live cell with exactly 2 or 3 live neighbors continues living
  • any live cell with more than 3 live neighbors dies
  • any dead cell with exactly 3 live neighbors becomes alive

Install Requirements

  • Python 2.7.3
  • Pygame
  • a clone of this repo: git clone https://github.com/heyhuyen/pygame-of-life.git

Playing the Game

Run python life.py and behold, the universe!

Controls

  1. Use the mouse to configure the universe's cells (the squares).
  2. Hit the RETURN key to see them come to life.
  3. Hit RETURN again to pause.
  4. You can continue configuring cells while the universe is live or paused.

Cell Colors

  • black = dead
  • green = alive
  • blue = your mouse position
  • red = selected (configuring)

The Code

MVC + Event Manager structure modeled after this pygame tutorial.

event_manager.py : defines event classes and queues up event notifications to broadcast to registered listeners.

universe.py : the model. Game class maintains the game's state. Universe class represents the universe as 2-D list of 0s and 1s, where 0 is a dead cell and 1 is a live cell, and handles logic for evolution of cells from one generation to the next.

pygame_view.py : the view, which consists of a background with lines to depict a grid. Uses pygame sprites and sprite groups to render and update colored cells.

life.py : the controller. CPUSpinnerController class runs the game clock. InputController class handles mouse and keyboard input.

##Todo/Extension Ideas

  • add a start/splash screen
  • enable player to specify universe dimensions
  • provide preconfigured patterns
  • go backwards in time?!?!

pygame-of-life's People

Contributors

heyhuyen avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.