Skip to content

ItsNickBarry/game-of-life

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The Game of Life

One of John Conway's great contributions to the field of combinatorial game theory, as well as one of his many regrets.

This implementation of the Game of Life is projected onto a toroidal surface.

Take a look at the project site.

Usage

To embed the Game of Life on your website, for whatever reason, first add the scripts in the lib directory:

<script type="text/javascript" src="lib/Game.js"></script>
<script type="text/javascript" src="lib/Board.js"></script>
<script type="text/javascript" src="lib/Cell.js"></script>

Use a custom script to initialize a GameOfLife.Game object:

GameOfLife.game = new GameOfLife.Game(options);

The constructor accepts an options hash, which may contain the following properties:

height

The number of rows on the board; default 30

width

The number of columns on the board; default 30

defaultPopulationDensity

The probability that each cell will be live when generated; default .3

boardElement

The DOM element into which the board will be appended

clearElement

The DOM element which, when clicked, will clear the board

counterElement

A DOM element which will be updated to display how many in-game generations have passed

resetElement

A DOM element which, when clicked, will reset the game

tickElement

A DOM element which, if the game is paused, will progress the game by one generation

toggleElement

A DOM element which will start or pause the game

tickInterval

The time, in milliseconds, between each game tick; default 100

clickToToggle

A boolean specifying whether cells may be toggled by clicking

DOM elements which are not present in the options hash will be generated by the game. They may be accessed through the following functions:

Game.prototype.getBoardElement();
Game.prototype.getCounterElement();
Game.prototype.getResetElement();
Game.prototype.getTickElement();
Game.prototype.getToggleElement();

Style the board with CSS rules for the following classes. Style should be limited to visual effects; page flow should not be modified:

.gol-board {
  /*the board*/
}
.gol-row {
  /*a row of cells on the board*/
}
.gol-cell {
  /*a cell on the board*/
}
.live {
  /*a live cell*/
}
.active {
  /*the toggleElement when the game is running*/
}

Acknowledgment

The project site is made with Skeleton, which is released by David Gamache under the MIT license.

It makes use of icons from Font Awesome, which are released under the SIL Open Font License.