Created
June 28, 2016 22:48
-
-
Save shinobcrc/a137a51c885f41cca001513ef4d65680 to your computer and use it in GitHub Desktop.
warcraft3.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://classic.battle.net/war3/human/units/footman.shtml | |
class Footman < Unit | |
def initialize | |
super(60, 10) | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Peasant < Unit | |
def initialize | |
super(35, 0) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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