Battlefield 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/battle +8 -2
- data/lib/battlefield.rb +93 -46
- data/lib/battlestruct.rb +8 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5b802002ffaef02c5d8439cf65bb4623d36dc4c
|
4
|
+
data.tar.gz: acf7ee523ece0f4b6a0cecb2823e0942cff5bc35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddcee7797f335bb2b80e81decd91dcfe5adaa278c284dc6806ef26803b94518bc64ef590768dc3c895131c548517e15d28838b2ac3cd846e6882e16cbec63bb1
|
7
|
+
data.tar.gz: f5ce7e75f38dc6720870be08e8d176fb58075ad30fa52a873f44dbeff233ff84b8c1f30e1225e0033159432bc70efa20b28a038bf7f3d31da1e4b6da12850d76
|
data/bin/battle
CHANGED
@@ -1,4 +1,10 @@
|
|
1
1
|
#!/usr/bin/env/ruby
|
2
|
-
|
3
2
|
require 'Battlefield'
|
4
|
-
|
3
|
+
for code in ARGV; code = instance_exec {code}; end
|
4
|
+
|
5
|
+
case ARGV.length
|
6
|
+
when 0 then battle
|
7
|
+
when 1 then battle ARGV[0]
|
8
|
+
when 2 then battle ARGV[0], ARGV[1]
|
9
|
+
else; battle ARGV[0], ARGV[1], ARGV[2]
|
10
|
+
end
|
data/lib/battlefield.rb
CHANGED
@@ -1,89 +1,136 @@
|
|
1
|
+
require_relative 'battlestruct.rb'
|
2
|
+
=begin
|
3
|
+
Used with Creature and its subclasses.
|
4
|
+
Armour decreases damage taken in Creature#damage.
|
5
|
+
There are two ways of initialization:
|
6
|
+
1. Direct
|
7
|
+
_armour_ = Armour
|
8
|
+
_armour_ = Armour _protection_
|
9
|
+
2. Create a subclass
|
10
|
+
class _Platemail_ < Armour
|
11
|
+
def initialize; @protection = _5_; end
|
12
|
+
end
|
13
|
+
You can change @protection at any time.
|
14
|
+
=end
|
15
|
+
class Armour
|
16
|
+
attr_accessor :protection
|
17
|
+
# Initializes a new Armour. Set original protection here. Alias: Armour()
|
18
|
+
def initialize(protection); @protection = protection; end
|
19
|
+
end
|
20
|
+
=begin
|
21
|
+
Used w/ Creature and its subclasses.
|
22
|
+
Weapons add to the attacking power of Creature#attack.
|
23
|
+
There are two ways to create one:
|
24
|
+
1. Directly initialize it
|
25
|
+
_weapon_ = Weapon()
|
26
|
+
_weapon_ = Weapon _power_
|
27
|
+
2. Create a subclass
|
28
|
+
class _Dragonfire_ < Weapon
|
29
|
+
def initialize; @power = _1000_; end
|
30
|
+
end
|
31
|
+
You can change your power after initialization:
|
32
|
+
(Lets say your weapon was damaged)
|
33
|
+
_weapon_.power -= _lostPower_
|
34
|
+
(Now you get it improved)
|
35
|
+
_weapon_.power += _gainedPower_
|
36
|
+
=end
|
37
|
+
class Weapon
|
38
|
+
attr_accessor :power
|
39
|
+
# Creates a new Weapon. Set the original power of the Weapon here. Aliases: Weapon()
|
40
|
+
def initialize(power); @power = power; end
|
41
|
+
end
|
1
42
|
=begin
|
2
43
|
If you want to make a new enemy, you have two ways to do it:
|
3
44
|
1. Directly initialize it
|
4
|
-
_enemy_ = Creature
|
5
|
-
|
45
|
+
_enemy_ = Creature _health_
|
46
|
+
_enemy_ = Creature _health_, _armour_
|
47
|
+
_enemy_ = Creature _health_, _armour_, _weapon_
|
6
48
|
2. Create a new class
|
7
|
-
class Goblin
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
|
49
|
+
class Goblin
|
50
|
+
def initialize; @health, @armour, @weapon = _5_, _Armour()_, _Weapon()_; end
|
51
|
+
end
|
52
|
+
You can change weapons and armour after initialization as well.
|
12
53
|
Common ancestor of any battle-able objects
|
13
54
|
=end
|
14
55
|
class Creature
|
15
56
|
attr_reader :health
|
16
|
-
|
17
|
-
|
18
|
-
#
|
19
|
-
def
|
57
|
+
attr_accessor :armour, :weapon
|
58
|
+
protected :damage
|
59
|
+
# Initializes a Creature. Parameter health sets the Creature's health. Parameter armour sets the Creature's armour, which reduces damage taken and should be a kind of Armour. Parameter weapon sets the Creature's weapon, which increases the damage taken on others and should be a kind of Weapon.
|
60
|
+
def initialize(health, armour, weapon); @health, @armour, @weapon = health, armour, weapon; end
|
61
|
+
# Damage function. Takes into account armour.
|
62
|
+
def damage(amt); @health -= (amt - armour.protection); end
|
20
63
|
# Rolling function - higher # = more power.
|
21
64
|
def roll; (1..6).to_a.sample; end
|
22
65
|
# Roll twice
|
23
66
|
def droll; self.roll + self.roll; end
|
24
67
|
# The 1st argument is your attack power. The other is the enemy's. self heals c1 - c2 health.
|
25
|
-
def heal(
|
68
|
+
def heal(c1, c2)
|
26
69
|
@health += c1 - c2
|
27
70
|
end
|
71
|
+
# Attacking function. Takes into account @weapon.
|
72
|
+
def attack(enemy, amt); enemy.damage amt + weapon.power; end
|
28
73
|
end
|
74
|
+
|
29
75
|
# Any error you get during a battle. If you get a different one, wait for the next update.
|
30
76
|
class BattleError < Exception; end
|
31
|
-
=begin
|
32
|
-
ArmouredCreatures take a reduced amount of damage.
|
33
|
-
This is a great superclass if you want damage reductions.
|
34
|
-
=end
|
35
|
-
class ArmouredCreature < Creature
|
36
|
-
attr_reader = :armour
|
37
|
-
# Initializes an ArmoredCreature. Parameter armour sets the damage reduction rate. It should be a float.
|
38
|
-
def initialize(health, armour); @health, @armour = health, armour; end
|
39
|
-
# Reduces damage by multiplying it by armour.
|
40
|
-
def damage(amt)
|
41
|
-
@health -= (amt * @armour)
|
42
|
-
end
|
43
|
-
end
|
44
77
|
# The Hero is the main character in any story. Works great for the player's avatar and can have armour.
|
45
|
-
class Hero <
|
46
|
-
# Initializes a new Hero. Sets health to 100.
|
47
|
-
def initialize(armour); @health, @armour = 100, armour; end
|
78
|
+
class Hero < Creature
|
79
|
+
# Initializes a new Hero. Sets health to 100. See Creature#new for the parameters armour and weapon
|
80
|
+
def initialize(armour, weapon); @health, @armour, weapon = 100, armour, weapon; end
|
48
81
|
end
|
49
82
|
=begin
|
50
|
-
|
83
|
+
Strongly recommended keys -> :hero, :enemy
|
84
|
+
Recommended keys -> :heal
|
85
|
+
|
86
|
+
:hero should be a kind of Hero. This is your fighter.
|
51
87
|
|
52
|
-
|
88
|
+
:enemy should be a kind of Creature. This is the enemy. If it is also a kind of Hero, use it in :hero instead.
|
53
89
|
|
90
|
+
:heal can be set to:
|
91
|
+
1. false(default) - allows no one to heal during the battle
|
92
|
+
2. 'hero' - allows the hero to heal during the battle
|
93
|
+
3. 'enemy' - allows the enemy to heal during the battle
|
94
|
+
4.'both' - allows the hero and enemy to both heal during the battle
|
95
|
+
This is also the name of the executable. To use the executable, treat it as the method battle.
|
54
96
|
=end
|
55
|
-
def battle(
|
56
|
-
|
57
|
-
|
58
|
-
|
97
|
+
def battle(arg = Hash.new)
|
98
|
+
:hero = Hero() unless defined? :hero
|
99
|
+
:enemy = Creature() unless defined? :enemy
|
100
|
+
:heal = false unless defined? :enemy
|
101
|
+
raise(BattleError, "You must specify which party to heal.") unless :heal == "both" || :heal == "hero" || :heal == "enemy" || :heal == false
|
102
|
+
until :hero.health <= 0 || :enemy.health <= 0
|
103
|
+
roll1, roll2 = :hero.droll, :enemy.droll
|
59
104
|
# You hit enemy and it takes your roll amount
|
60
105
|
if roll1 > roll2
|
61
|
-
if heal == "hero" or heal == "both"
|
62
|
-
hero.heal roll1, roll2
|
106
|
+
if :heal == "hero" or :heal == "both"
|
107
|
+
:hero.heal roll1, roll2
|
63
108
|
puts "You gained #{roll1 - roll2} health"
|
64
109
|
sleep 1
|
65
110
|
end
|
66
111
|
puts "The enemy took #{roll1} damage"
|
67
|
-
|
112
|
+
:hero.attack :enemy, roll1
|
68
113
|
sleep 1
|
69
114
|
# Enemy hits you and you take its roll amount
|
70
115
|
elsif roll2 > roll1
|
71
|
-
if heal == "enemy" or heal == "both"
|
72
|
-
enemy.heal roll2, roll1
|
116
|
+
if :heal == "enemy" or :heal == "both"
|
117
|
+
:enemy.heal roll2, roll1
|
73
118
|
puts "The enemy gained #{roll2 - roll1} health"
|
74
119
|
sleep(1)
|
75
120
|
end
|
76
121
|
puts "You took #{roll2} damage"
|
77
|
-
|
122
|
+
:enemy.attack :hero, roll2
|
78
123
|
sleep 1
|
79
124
|
end
|
80
|
-
puts "
|
125
|
+
puts "\nYou: #{:hero.health} #{:enemy}: #{:enemy.health}\n"
|
81
126
|
sleep 2
|
82
127
|
end
|
83
128
|
end
|
84
|
-
# Initializes a new
|
85
|
-
def
|
86
|
-
# Initializes a new
|
87
|
-
def
|
129
|
+
# Initializes a new Weapon. If there are no arguments, power is set to 0.
|
130
|
+
def Weapon(power = 0); Weapon.new power; end
|
131
|
+
# Initializes a new Armour object. If there are no arguments, protection is set to 0.
|
132
|
+
def Armour(protection = 0); Armour.new protection; end
|
133
|
+
# Initializes a new Creature. If no arguments are given, health is set to 1, armour is set to Armour(0), and weapon is set to Weapon(0).
|
134
|
+
def Creature(health = 1, armour = Armour(), weapon = Weapon()); Creature.new health, armour, weapon; end
|
88
135
|
# Alias for Hero.new. Remember to include the ()s if you give no arguments or you will get an error!
|
89
|
-
def Hero(armour =
|
136
|
+
def Hero(armour = Armour(), weapon = Weapon()); Hero.new(armour); end
|
data/lib/battlestruct.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# Initializes a new Weapon. If there are no arguments, power is set to 0.
|
2
|
+
def Weapon(power = 0); Weapon.new power; end
|
3
|
+
# Initializes a new Armour object. If there are no arguments, protection is set to 0.
|
4
|
+
def Armour(protection = 0); Armour.new protection; end
|
5
|
+
# Initializes a new Creature. If no arguments are given, health is set to 1, armour is set to Armour(0), and weapon is set to Weapon(0).
|
6
|
+
def Creature(health = 1, armour = Armour(), weapon = Weapon()); Creature.new health, armour, weapon; end
|
7
|
+
# Alias for Hero.new. Remember to include the ()s if you give no arguments or you will get an error!
|
8
|
+
def Hero(armour = Armour(), weapon = Weapon()); Hero.new(armour); end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Battlefield
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zachary Perlmutter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
Allows you to create combatants and let them battle. Useful for pick-your-path text games. Comes with an executable for simulating battles.
|
@@ -20,6 +20,7 @@ extra_rdoc_files: []
|
|
20
20
|
files:
|
21
21
|
- bin/battle
|
22
22
|
- lib/battlefield.rb
|
23
|
+
- lib/battlestruct.rb
|
23
24
|
- test/battlefield_test.rb
|
24
25
|
homepage: https://rubygems.org/gems/Battlefield
|
25
26
|
licenses:
|
@@ -31,12 +32,12 @@ require_paths:
|
|
31
32
|
- lib
|
32
33
|
required_ruby_version: !ruby/object:Gem::Requirement
|
33
34
|
requirements:
|
34
|
-
- -
|
35
|
+
- - ">="
|
35
36
|
- !ruby/object:Gem::Version
|
36
37
|
version: 2.0.0
|
37
38
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
39
|
requirements:
|
39
|
-
- -
|
40
|
+
- - ">="
|
40
41
|
- !ruby/object:Gem::Version
|
41
42
|
version: '0'
|
42
43
|
requirements: []
|