Battlefield 0.1.0.pre → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/battlefield.rb +31 -30
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d616d3d718f8b33cd6dcb57eb05bb5046775003
|
4
|
+
data.tar.gz: a150bef37cd0386fdd50af971fff5b147e3805ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2d8343e16f36e62fd2215c6eba1284f3dfa1d6a8be3185e5832d1eb7f6a8991c37d1202b521174b7dd18a0ac81e79e4437f8a79b6777c1c6be9a763b9da41da
|
7
|
+
data.tar.gz: 075d5eabe39d8651ea9cdfa432d11f288168a044186854f01f5e926452f7bb0dcdde640d4d0912c666ba94996e25cfbf4d0c043c62274b34ef9137ecce5b9906
|
data/lib/battlefield.rb
CHANGED
@@ -1,45 +1,36 @@
|
|
1
1
|
=begin
|
2
2
|
If you want to make a new enemy, you have two ways to do it:
|
3
3
|
1. Directly initialize it
|
4
|
-
_enemy_ = Creature.new
|
4
|
+
_enemy_ = Creature.new health
|
5
5
|
|
6
|
-
2. Create
|
7
|
-
class
|
8
|
-
def initialize; @health =
|
6
|
+
2. Create a new class
|
7
|
+
class Goblin
|
8
|
+
def initialize; @health = 5; end
|
9
9
|
end
|
10
10
|
|
11
11
|
|
12
12
|
Common ancestor of any battle-able objects
|
13
13
|
=end
|
14
14
|
class Creature
|
15
|
-
|
15
|
+
attr_reader :health
|
16
16
|
# Initializes a Creature. Parameter health sets the Creature's health.
|
17
|
-
def initialize(health)
|
18
|
-
@health = health
|
19
|
-
end
|
17
|
+
def initialize(health); @health = health; end
|
20
18
|
# Damage function
|
21
|
-
def damage(amt)
|
22
|
-
@health -= amt
|
23
|
-
end
|
19
|
+
def damage(amt); @health -= amt; end
|
24
20
|
# Rolling function - higher # = more power.
|
25
21
|
def roll
|
26
22
|
(1..6).to_a.sample; end
|
27
|
-
#
|
28
|
-
def droll
|
29
|
-
|
30
|
-
end
|
31
|
-
# The 1st argument is your attack power. The other is the enemy's. You heal c1 - c2 health.
|
23
|
+
# Roll twice
|
24
|
+
def droll; self.roll + self.roll; end
|
25
|
+
# The 1st argument is your attack power. The other is the enemy's. self heals c1 - c2 health.
|
32
26
|
def heal(c1, c2)
|
33
27
|
@health += c1 - c2
|
34
28
|
end
|
35
29
|
end
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
41
|
-
end
|
42
|
-
# ArmouredCreatures take a reduced amount of damage.
|
30
|
+
=begin
|
31
|
+
ArmouredCreatures take a reduced amount of damage.
|
32
|
+
This is a great superclass if you want damage reductions.
|
33
|
+
=end
|
43
34
|
class ArmouredCreature < Creature
|
44
35
|
attr_reader = :armour
|
45
36
|
# Initializes an ArmoredCreature. Parameter armour sets the damage reduction rate. It should be a float.
|
@@ -49,14 +40,22 @@ class ArmouredCreature < Creature
|
|
49
40
|
@health -= (amt*@armour)
|
50
41
|
end
|
51
42
|
end
|
52
|
-
#
|
43
|
+
# The Hero is the main character in any story. Works great for the player's avatar and can have armour.
|
44
|
+
class Hero < ArmouredCreature
|
45
|
+
# Initializes a new Hero. Sets health to 100. If you want your hero to have armour, set it as a float.
|
46
|
+
def initialize(armour = 1); @health = 100; end
|
47
|
+
end
|
48
|
+
=begin
|
49
|
+
Specify your combatants in parameters hero and enemy
|
50
|
+
|
51
|
+
If you want your hero to heal, set parameter 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 the parameter blank.
|
52
|
+
|
53
|
+
=end
|
53
54
|
def battle(hero, enemy, heal = false)
|
54
|
-
until hero.health <= 0
|
55
|
-
roll1 = hero.droll
|
56
|
-
roll2 = enemy.droll
|
55
|
+
until hero.health <= 0 || enemy.health <= 0
|
57
56
|
# You hit enemy and it takes your roll amount
|
58
57
|
if roll1 > roll2
|
59
|
-
if heal == "hero"
|
58
|
+
if heal == "hero" or heal == "both"
|
60
59
|
hero.heal roll1, roll2
|
61
60
|
puts "You gained #{roll1 - roll2} health"
|
62
61
|
sleep 1
|
@@ -66,7 +65,7 @@ def battle(hero, enemy, heal = false)
|
|
66
65
|
sleep 1
|
67
66
|
# Enemy hits you and you take its roll amount
|
68
67
|
elsif roll2 > roll1
|
69
|
-
if heal == "enemy"
|
68
|
+
if heal == "enemy" or heal == "both"
|
70
69
|
enemy.heal roll2, roll1
|
71
70
|
puts "The enemy gained #{roll2 - roll1} health"
|
72
71
|
sleep(1)
|
@@ -81,4 +80,6 @@ end
|
|
81
80
|
# Initializes a new Creature. If no arguments are given, health is set to 0.
|
82
81
|
def Creature(health = 0); Creature.new health; end
|
83
82
|
# Initializes a new ArmouredCreature. By default, health is set to 0 and armour is set to 0.5
|
84
|
-
def ArmouredCreature(health=0, armour=0.5); ArmouredCreature.new health, armour; end
|
83
|
+
def ArmouredCreature(health = 0, armour = 0.5); ArmouredCreature.new health, armour; end
|
84
|
+
# Alias for Hero.new. Remember to include the ()s if you give no arguments or you will get an error!
|
85
|
+
def Hero(armour = 1); Hero.new(armour); end
|
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.1.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zachary Perlmutter
|
@@ -30,12 +30,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
31
31
|
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 2.0.0
|
34
34
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
35
|
requirements:
|
36
|
-
- - '
|
36
|
+
- - '>='
|
37
37
|
- !ruby/object:Gem::Version
|
38
|
-
version:
|
38
|
+
version: '0'
|
39
39
|
requirements: []
|
40
40
|
rubyforge_project:
|
41
41
|
rubygems_version: 2.3.0
|