Skip to content

Instantly share code, notes, and snippets.

@shinobcrc
Created June 28, 2016 22:48
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 shinobcrc/a137a51c885f41cca001513ef4d65680 to your computer and use it in GitHub Desktop.
Save shinobcrc/a137a51c885f41cca001513ef4d65680 to your computer and use it in GitHub Desktop.
warcraft3.rb
require_relative 'footman'
class Barracks
attr_reader :gold, :food
def initialize
@gold = 1000
@food = 80
end
def can_train_footman?
if (food < 2 || gold < 135)
return false
else
true
end
end
def train_footman
@gold = gold - 135
@food = food - 2
if can_train_footman? == false
return nil
else
footman = Footman.new
end
end
def can_train_peasant?
if (food < 5 || gold < 90)
return false
else
true
end
end
def train_peasant
@gold -= 90
@food -= 5
if can_train_peasant? == false
return nil
else
peasant = Peasant.new
end
end
end
# http://classic.battle.net/war3/human/units/footman.shtml
class Footman < Unit
def initialize
super(60, 10)
end
end
class Peasant < Unit
def initialize
super(35, 0)
end
end
class Unit
attr_accessor :health_points, :attack_power
def initialize(hp, ap)
@health_points = hp
@attack_power = ap
end
def attack!(enemy)
enemy.damage(attack_power)
end
def damage(ap)
@health_points -= ap
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment