Class: Tile
- Inherits:
-
Object
- Object
- Tile
- Defined in:
- lib/demigodGame/Tile.rb
Instance Attribute Summary collapse
-
#built_on ⇒ Object
readonly
Returns the value of attribute built_on.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
-
#accepts?(order) ⇒ Boolean
Checks if an order is valid.
-
#build(building) ⇒ Object
Adds building to tile, doesn’t check if valid building.
- #check_cost(order, resources) ⇒ Object
-
#initialize(x, y) ⇒ Tile
constructor
A new instance of Tile.
- #to_s ⇒ Object
Constructor Details
#initialize(x, y) ⇒ Tile
Returns a new instance of Tile.
10 11 12 13 14 |
# File 'lib/demigodGame/Tile.rb', line 10 def initialize(x, y) @x = x @y = y @type = '.' end |
Instance Attribute Details
#built_on ⇒ Object (readonly)
Returns the value of attribute built_on.
9 10 11 |
# File 'lib/demigodGame/Tile.rb', line 9 def built_on @built_on end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/demigodGame/Tile.rb', line 9 def @options end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
9 10 11 |
# File 'lib/demigodGame/Tile.rb', line 9 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
9 10 11 |
# File 'lib/demigodGame/Tile.rb', line 9 def y @y end |
Instance Method Details
#accepts?(order) ⇒ Boolean
Checks if an order is valid
27 28 29 30 31 32 33 34 |
# File 'lib/demigodGame/Tile.rb', line 27 def accepts?(order) return false if !order || !order.match( /\A\w\Z/) # vaild command @options.each do |check| # checks which order was given return true if (check.to_s == order) end false end |
#build(building) ⇒ Object
Adds building to tile, doesn’t check if valid building
21 22 23 24 |
# File 'lib/demigodGame/Tile.rb', line 21 def build(building) @built_on = building @buildable = [] end |
#check_cost(order, resources) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/demigodGame/Tile.rb', line 36 def check_cost(order, resources) cost = GameData.get_price(order) puts cost # checks each resource for the correct amount cost.each do |resource, amount| return false if amount > resources[resource] end return true end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/demigodGame/Tile.rb', line 16 def to_s "#{@type}#{@built_on}" end |