Created
March 14, 2014 17:35
-
-
Save elikem/9552740 to your computer and use it in GitHub Desktop.
Conway's Game of Life
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Board | |
| def initialize(height, width) | |
| @height = height | |
| @width = width | |
| @number_spaces = height * width | |
| end | |
| def height | |
| @height | |
| end | |
| def width | |
| @width | |
| end | |
| def number_spaces | |
| @number_spaces | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rspec' | |
| require 'board' | |
| describe Board do | |
| it 'initializes a board instance' do | |
| test_board = Board.new(10, 10) | |
| test_board.should be_an_instance_of Board | |
| end | |
| it 'initializes with correct number of spaces' do | |
| test_board = Board.new(10, 10) | |
| test_board.height.should eq 10 | |
| test_board.width.should eq 10 | |
| test_board.number_spaces.should eq 100 | |
| end | |
| # describe '.create' do | |
| # it 'creates a board object and fills it with space objects' do | |
| # test_board = Board.create(10, 10) | |
| # test_space = Space.new(2,3,false) | |
| # test_board | |
| # end | |
| # end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rspec' | |
| require 'space' | |
| describe Space do | |
| it 'should be an instance of Space' do | |
| test_space = Space.new(2,3) | |
| test_space.should be_an_instance_of Space | |
| end | |
| it 'should initialize with coordinates and "false" for dead state' do | |
| test_space = Space.new(2,3) | |
| test_space.x.should eq 2 | |
| test_space.y.should eq 3 | |
| test_space.state.should eq false | |
| end | |
| describe '.all' do | |
| it 'starts empty' do | |
| Space.all.should eq [] | |
| end | |
| it 'is filled with all spaces' do | |
| test_board = Board.new(10,10) | |
| test_space1 = Space.create(0,0) | |
| test_space2 = Space.create(1,0) | |
| Space.all.should eq [test_space1, test_space2] | |
| end | |
| end | |
| describe '.create' do | |
| it 'creates a space object and pushes into all_spaces array' do | |
| test_space = Space.create(0,0) | |
| Space.all.should eq [test_space] | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rspec' | |
| require 'space' | |
| describe Space do | |
| it 'should be an instance of Space' do | |
| test_space = Space.new(2,3) | |
| test_space.should be_an_instance_of Space | |
| end | |
| it 'should initialize with coordinates and "false" for dead state' do | |
| test_space = Space.new(2,3) | |
| test_space.x.should eq 2 | |
| test_space.y.should eq 3 | |
| test_space.state.should eq false | |
| end | |
| describe '.all' do | |
| it 'starts empty' do | |
| Space.all.should eq [] | |
| end | |
| it 'is filled with all spaces' do | |
| test_board = Board.new(10,10) | |
| test_space1 = Space.create(0,0) | |
| test_space2 = Space.create(1,0) | |
| Space.all.should eq [test_space1, test_space2] | |
| end | |
| end | |
| describe '.create' do | |
| it 'creates a space object and pushes into all_spaces array' do | |
| test_space = Space.create(0,0) | |
| Space.all.should eq [test_space] | |
| end | |
| end | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
here is how you should create each space...
(0..99).each do |x|
(0..99).each do |y|
@all_cells << Cell.new(x, y)
end
end