Skip to content

Instantly share code, notes, and snippets.

@FioFiyo
Created June 29, 2016 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FioFiyo/0ebb98c65e8ef4785a890d32a79035f9 to your computer and use it in GitHub Desktop.
Save FioFiyo/0ebb98c65e8ef4785a890d32a79035f9 to your computer and use it in GitHub Desktop.
Warcraft3: Create classes and methods for the specs to pass.
class Barracks
attr_reader :gold, :food
def initialize
@gold = 1000
@food = 80
end
def train_footman
if can_train_footman?
@gold -= 135
@food -= 2
Footman.new
end
end
def can_train_footman?
gold >= 135 && food >= 80
end
def train_peasant
if can_train_peasant?
@gold -= 90
@food -= 5
Peasant.new
end
end
def can_train_peasant?
gold >= 90 && food >= 5
end
end
# http://classic.battle.net/war3/human/units/footman.shtml
class Footman < Unit
def initialize
super(60,80)
end
def attack!(enemy)
enemy.damage(10)
end
def damage(attack_power)
@health_points -= attack_power
end
end
class Peasant < Unit
def initialize
super(35,0)
end
end
class Unit
attr_reader :health_points, :attack_power
def initialize(health_points, attack_power)
@health_points = health_points
@attack_power = attack_power
end
def damage(attack_power)
@health_points -= attack_power
end
def attack!(enemy_unit)
enemy_unit.damage(3)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment