Class: Tile

Inherits:
Object
  • Object
show all
Defined in:
lib/demigodGame/Tile.rb

Direct Known Subclasses

Forest, Plains, Ridge, Sea

Instance Attribute Summary collapse

Instance Method Summary collapse

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_onObject (readonly)

Returns the value of attribute built_on.



9
10
11
# File 'lib/demigodGame/Tile.rb', line 9

def built_on
  @built_on
end

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/demigodGame/Tile.rb', line 9

def options
  @options
end

#xObject (readonly)

Returns the value of attribute x.



9
10
11
# File 'lib/demigodGame/Tile.rb', line 9

def x
  @x
end

#yObject (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

Returns:

  • (Boolean)


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_sObject



16
17
18
# File 'lib/demigodGame/Tile.rb', line 16

def to_s
  "#{@type}#{@built_on}"
end