Battlefield 0.0.2 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/battlefield.rb +35 -13
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7473da22e3acc7b70e63ecede93c16ab0c91b2f8
4
- data.tar.gz: 584a0b312f54ec4911352873107c927426941db3
3
+ metadata.gz: ea35d68f2814c70585aa9f1520c7eb501cf6365d
4
+ data.tar.gz: 7e1e69a87a0f70caaae3f96f68341d7d4d32044a
5
5
  SHA512:
6
- metadata.gz: 64fbad08b08d1dec9ea4b86f3a6d1d77ab69f0aaaaae2c016a808e01c8a0954b43673f52de66672fb9524b6b1b93eb71a5e6d27bc1f4c9dea02fbddf47174f05
7
- data.tar.gz: 8eed8418bb8d053606431351aab3b8aae0a08bb4904af6e0efe85fa5163db781aadd16597ab7a97c8f0a4e4c4da85084a1e961589216ffc534837618cfc80c2e
6
+ metadata.gz: d53ac2d164dc1bc2680f7a286c13e65f93d993c2fed8d708dc7d3e5e082ad0f45cc94ffc1fe62bf5eed8687adc7c685a070a1587baef37244e9a7513e6340b56
7
+ data.tar.gz: b938407b8c1622d7e47a28a961a7f57e33255418ffbeefe15e38e06836b8d99f19554fd8143407b1cb46dde17681df000819b6fea018f3a5ab94e3bc77a93f67
data/lib/battlefield.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  =begin
2
- If you want to make a new enemy, you have two ways to do it.
3
-
2
+ If you want to make a new enemy, you have two ways to do it:
4
3
  1. Directly initialize it
5
4
  Creature.new (insert health here)
6
5
 
@@ -8,34 +7,56 @@ Creature.new (insert health here)
8
7
  class (Insert enemy name here) < Creature
9
8
  def initialize; @health = _insert health here_; end
10
9
  end
10
+
11
+
12
+ Common ancestor of any battle-able objects
11
13
  =end
12
- class Creature # Common ancestor of any battle-able objects
14
+ class Creature
13
15
  attr_accessor :health
14
- def initialize(health = 0) # Really should specify health and now you can battle
16
+ # Really should specify health and now you can battle
17
+ def initialize(health = 0)
15
18
  @health = health
16
19
  end
17
- def damage(amt) # Damage function
20
+ # Damage function
21
+ def damage(amt)
18
22
  @health -= amt
19
23
  end
20
- def roll # rolling function - higher # = more power
24
+ # rolling function - higher # = more power
25
+ def roll
21
26
  (1..6).to_a.sample; end
22
- def droll # roll twice
27
+ # roll twice
28
+ def droll
23
29
  self.roll + self.roll
24
30
  end
25
- def heal(c1, c2) # The 1st argument is your attack power. The other is the enemy's. You heal c1 - c2 health
31
+ # The 1st argument is your attack power. The other is the enemy's. You heal c1 - c2 health
32
+ def heal(c1, c2)
26
33
  @health += c1 - c2
27
34
  end
28
35
  end
29
- class Hero < Creature # hero object - to use, create an instance first
30
- def initialize # The hero starts with 100 health
36
+ # To use, create an instance first
37
+ class Hero < Creature
38
+ # The hero starts with 100 health
39
+ def initialize
31
40
  @health = 100
32
41
  end
33
42
  end
34
- def battle(hero, enemy, heal = false) # specify your combatants. If you want your hero to heal, set heal to 'hero'. If you want your enemy to heal, set heal to 'enemy'. If you want them both to heal, set heal to 'both'. Otherwise leave it blank.
43
+ # Initializes an ArmoredCreature. It takes a reduced amount of damage.
44
+ class ArmoredCreature < Creature
45
+ attr_reader = :armour
46
+ # specify damage reduction as a float in parameter armour
47
+ def initialize(health = 0, armour = 0.5); @health, @armour = health, armor; end
48
+ # Reduces damage by multiplying it by armour
49
+ def damage(amt)
50
+ @health -= (amt*@armour)
51
+ end
52
+ end
53
+ # specify your combatants. If you want your hero to heal, set heal to 'hero'. If you want your enemy to heal, set heal to 'enemy'. If you want them both to heal, set heal to 'both'. Otherwise leave it blank.
54
+ def battle(hero, enemy, heal = false)
35
55
  until hero.health <= 0 or enemy.health <= 0
36
56
  roll1 = hero.droll
37
57
  roll2 = enemy.droll
38
- if roll1 > roll2 # You hit enemy and it takes your roll amount
58
+ # You hit enemy and it takes your roll amount
59
+ if roll1 > roll2
39
60
  if heal == "hero" || "both"
40
61
  hero.heal roll1, roll2
41
62
  puts "You gained #{roll1 - roll2} health"
@@ -44,7 +65,8 @@ def battle(hero, enemy, heal = false) # specify your combatants. If you want you
44
65
  puts "The enemy took #{roll1} damage"
45
66
  enemy.damage roll1
46
67
  sleep 1
47
- elsif roll2 > roll1 # Enemy hits you and you take its roll amount
68
+ # Enemy hits you and you take its roll amount
69
+ elsif roll2 > roll1
48
70
  if heal == "enemy" || "both"
49
71
  enemy.heal roll2, roll1
50
72
  puts "The enemy gained #{roll2 - roll1} health"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Battlefield
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zachary Perlmutter