Permalink
Browse files

add parsing

  • Loading branch information...
1 parent 1ee6b99 commit 5ad31647c7b56b46041200a6b779d903b2c47f6d @towski committed Dec 26, 2009
Showing with 13 additions and 0 deletions.
  1. +7 −0 lib/node.rb
  2. +6 −0 lib/terrain.rb
View
@@ -91,25 +91,32 @@ def to_s
class Flatland < Node
self.cost = 1
+ self.letter = '.'
end
class Start < Flatland
+ self.letter = ' '
end
class Goal < Flatland
+ self.letter = ' '
end
class Water < Node
def walkable?
false
end
+
+ self.letter = '~'
end
class Forest < Node
self.cost = 2
+ self.letter = '*'
end
class Mountain < Node
self.cost = 3
+ self.letter = '^'
end
View
@@ -10,4 +10,10 @@ class Terrain
def contains?(pos)
pos.x >= x and pos.x <= width and pos.y >= y and pos.y <= height
end
+
+ def self.parse(x, y, string)
+ string.split(//).each do |letter|
+ Node.find_by_letter(letter).new
+ end
+ end
end

0 comments on commit 5ad3164

Please sign in to comment.