Battlefield 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/battlefield.rb +59 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 210a4f4f36973f80a5e880600253ee143cc923c7
|
4
|
+
data.tar.gz: 16d32697c5ba3539a4f5c3f43f167a3564f0cd43
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 86a7436b251c1ec505193ecab3f96af32b4c57ce5818575465a052ceadc7ae0cecf032f5ddb0cc347ddd8e9c60fa94ba5f3f39bb6c4d07d04ab0e8d760d5e9ef
|
7
|
+
data.tar.gz: 61a5349f3d5b5fb29f844d34e80c4114fcc21030013c6e4b4c9724756670a0888405abb8eb712a9d38f14ee28eb44dd3a6bd9b1fdf5f98d6e99a5b90f861b8d8
|
data/lib/battlefield.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
=begin
|
2
|
+
If you want to make a new enemy, you have two ways to do it.
|
3
|
+
|
4
|
+
1. Directly initialize it
|
5
|
+
Creature.new (insert health here)
|
6
|
+
|
7
|
+
2. Create a new class
|
8
|
+
class (Insert enemy name here) < Creature
|
9
|
+
def initialize; @health = _insert health here_; end
|
10
|
+
end
|
11
|
+
=end
|
12
|
+
class Creature # Common ancestor of any battle-able objects
|
13
|
+
attr_accessor :health
|
14
|
+
def initialize(health = 0) # Really should specify health and now you can battle
|
15
|
+
@health = health
|
16
|
+
end
|
17
|
+
def damage(amt) # Damage function
|
18
|
+
@health -= amt
|
19
|
+
end
|
20
|
+
def roll # rolling function - higher # = more power
|
21
|
+
(1..6).to_a.sample; end
|
22
|
+
def droll # roll twice
|
23
|
+
self.roll + self.roll
|
24
|
+
end
|
25
|
+
def heal(c1, c2) # The 1st argument is your attack power. The other is the enemy's. You heal c1 - c2 health
|
26
|
+
@health += c1 - c2
|
27
|
+
end
|
28
|
+
end
|
29
|
+
class Hero < Creature # hero object - to use, create an instance first
|
30
|
+
def initialize # The hero starts with 100 health
|
31
|
+
@health = 100
|
32
|
+
end
|
33
|
+
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.
|
35
|
+
until hero.health <= 0 or enemy.health <= 0
|
36
|
+
roll1 = hero.droll
|
37
|
+
roll2 = enemy.droll
|
38
|
+
if roll1 > roll2 # You hit enemy and it takes your roll amount
|
39
|
+
if heal == "hero" || "both"
|
40
|
+
hero.heal roll1, roll2
|
41
|
+
puts "You gained #{roll1 - roll2} health"
|
42
|
+
sleep 1
|
43
|
+
end
|
44
|
+
puts "The enemy took #{roll1} damage"
|
45
|
+
enemy.damage roll1
|
46
|
+
sleep 1
|
47
|
+
elsif roll2 > roll1 # Enemy hits you and you take its roll amount
|
48
|
+
if heal == "enemy" || "both"
|
49
|
+
enemy.heal roll2, roll1
|
50
|
+
puts "The enemy gained #{roll2 - roll1} health"
|
51
|
+
sleep(1)
|
52
|
+
end
|
53
|
+
puts "You took #{roll2} damage"
|
54
|
+
hero.damage roll2
|
55
|
+
sleep 1
|
56
|
+
end
|
57
|
+
sleep 2
|
58
|
+
end
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Battlefield
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Zachary Perlmutter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-19 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |
|
14
|
+
Allows you to create combatants and let them battle
|
15
|
+
email: zrp200@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/battlefield.rb
|
21
|
+
homepage:
|
22
|
+
licenses: []
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.9.3
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.3.0
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Allows your objects to battle
|
44
|
+
test_files: []
|