Created
January 13, 2016 22:38
-
-
Save Ebonkuab/d4a6748c23735c094fb3 to your computer and use it in GitHub Desktop.
following the TDD concept and using Rspec as the automated testing platform to code A simulation of Warcraft 3 barracks Simulator
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_accessor :gold,:food | |
def initialize ( ) | |
# Need to default the 2 instance variables here | |
# Also also give code outside this class access to these variables (via attr_reader, attr_writer or attr_accessor) | |
@gold = 1000 | |
@food = 80 | |
end | |
def can_train_footman? | |
if gold >= 135 && food >= 2 | |
true | |
else | |
false | |
end | |
end | |
def train_peasant | |
if can_train_peasant? | |
self.gold -= 90 | |
self.food -= 5 | |
Peasant.new | |
else | |
nil | |
end | |
end | |
def can_train_peasant? | |
if gold >= 90 && food >= 5 | |
true | |
else | |
false | |
end | |
end | |
def train_footman () | |
if can_train_footman? | |
self.gold -= 135 | |
self.food -= 2 | |
Footman.new | |
else | |
nil | |
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 | |
# attr_accessor :health_points,:attack_power | |
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_reader :health_points | |
attr_reader :attack_power | |
def initialize (health_points , attack_power ) | |
@health_points = health_points | |
@attack_power = attack_power | |
end | |
def damage (input) | |
@health_points -= input | |
end | |
def attack! ( enemy) | |
enemy.damage(@attack_power) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment