# dorsath/genicity

First genicity scenario's done.

Peter de Ruijter committed Feb 27, 2012
1 parent 4f6d560 commit aebf212c4669f1855d763de019473f2a21f11535
Showing with 44 additions and 8 deletions.
1. +8 −7 features/step_definitions/genicity_steps.rb
2. +5 −0 lib/city.rb
3. +1 −0 lib/genicity.rb
4. +10 −0 lib/grid_point.rb
5. +20 −1 lib/land.rb
 @@ -4,28 +4,29 @@ Then /^I should have an empty land\$/ do @land.cities.should be_empty + @land.grid.size.should == 10000 end Given /^I have a land\$/ do - pending # express the regexp above with the code you wish you had + @land = Land.new end When /^I start a new city\$/ do - pending # express the regexp above with the code you wish you had + @land.start_city end Then /^I should have a new city on that land\$/ do - pending # express the regexp above with the code you wish you had + @land.cities.count.should == 1 end Given /^I am a empty city\$/ do - pending # express the regexp above with the code you wish you had + @land = Land.new + @city = @land.start_city end When /^years pass\$/ do - pending # express the regexp above with the code you wish you had end -Then /^I should be a city of (\d+) inhabitants\$/ do |arg1| - pending # express the regexp above with the code you wish you had +Then /^I should be a city of (\d+) inhabitants\$/ do |number| + @city.inhabitants.should == number end
 @@ -0,0 +1,5 @@ +class City + def inhabitants + 0 + end +end
 @@ -1 +1,2 @@ require 'land' +require 'city'
 @@ -0,0 +1,10 @@ +class GridPoint + attr_accessor :type + attr_reader :x, :y + + def initialize hash + @x = hash[:x] + @y = hash[:y] + self.type = hash[:type] + end +end
 @@ -1,7 +1,26 @@ +require 'grid_point' + class Land - attr_accessor :cities + attr_accessor :cities, :grid def initialize self.cities = [] + self.grid = [] + + set_grid! + end + + def set_grid! + 100.times do |x| + 100.times do |y| + grid << GridPoint.new(:x => x, :y => y, :type => :grass) + end + end + end + + def start_city(*args) + self.cities << city = City.new(*args) + + city end end