battle_royal 1.0.1
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 +7 -0
- data/LICENSE +21 -0
- data/README.md +19 -0
- data/bin/battle +35 -0
- data/bin/csv/favorite_players.csv +3 -0
- data/bin/csv/players.csv +3 -0
- data/lib/battle_royal/advantaged_player.rb +29 -0
- data/lib/battle_royal/game.rb +118 -0
- data/lib/battle_royal/lame_player.rb +35 -0
- data/lib/battle_royal/playable.rb +17 -0
- data/lib/battle_royal/player.rb +61 -0
- data/lib/battle_royal/roll.rb +16 -0
- data/lib/battle_royal/weapon_chest.rb +18 -0
- data/spec/battle_royal/advantaged_player_spec.rb +26 -0
- data/spec/battle_royal/game_spec.rb +21 -0
- data/spec/battle_royal/lame_player_spec.rb +31 -0
- data/spec/battle_royal/player_spec.rb +108 -0
- data/spec/battle_royal/weapon_chest_spec.rb +46 -0
- metadata +99 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 5d5a69a461cf3ee8f5718cc78cda04e54099256d
|
|
4
|
+
data.tar.gz: a74cf3cccc3d1f191378d1ed34ced29699e004dd
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 6463afd892bbcfa7b9c36ff8ddfaefb8907b0bc3a7fbf7617b19b2027d4a0aa85d0a2fdad51f966d4adb32d66f7c733bbcec7c9f22dc64feef1e356adc5d0209
|
|
7
|
+
data.tar.gz: c74e2e2728c4df57e249749d921086f8e00e8c79fef96e3cdede2c021521254e052a80e70947e48e4b7f07b9d5cf7ab225d155f136b9af90503e42b502a89981
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015 Shane Barringer
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
## battle royal
|
|
2
|
+
A Mortal Kombat influenced battle royal gem
|
|
3
|
+
|
|
4
|
+
### To Use
|
|
5
|
+
run `gem install battle_royal`
|
|
6
|
+
|
|
7
|
+
In your terminal simply run `$ battle`
|
|
8
|
+
|
|
9
|
+
### Notes
|
|
10
|
+
|
|
11
|
+
Currently, the game allows for users to input a certain number of rounds. The battle will run until there is only 1 player standing.
|
|
12
|
+
I recommend that you run the game for at least 10 - 100 rounds
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### To Contribute
|
|
16
|
+
1. Fork
|
|
17
|
+
2. Clone
|
|
18
|
+
3. Create a New Branch
|
|
19
|
+
4. Submit a Pull Request
|
data/bin/battle
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require_relative '../lib/battle_royal/game'
|
|
4
|
+
|
|
5
|
+
puts 'Welcome to the Battle Royal. Please enter a name for the competition: '
|
|
6
|
+
name = gets.chomp.capitalize
|
|
7
|
+
|
|
8
|
+
throwdown = BattleRoyal::Game.new(name.empty? ? 'Throwdown' : name)
|
|
9
|
+
|
|
10
|
+
default_players_file = File.join(File.dirname(__FILE__), 'csv/favorite_players.csv')
|
|
11
|
+
throwdown.load_players(ARGV.shift || default_players_file)
|
|
12
|
+
lame = BattleRoyal::LamePlayer.new('Stryker', 105, 5)
|
|
13
|
+
throwdown.add_player(lame)
|
|
14
|
+
awesome = BattleRoyal::AdvantagedPlayer.new('Scorpion', 120)
|
|
15
|
+
throwdown.add_player(awesome)
|
|
16
|
+
puts "#{throwdown.title} Begin!"
|
|
17
|
+
|
|
18
|
+
loop do
|
|
19
|
+
puts "\nHow many rounds would you like to play? (type 'quit' to exit)"
|
|
20
|
+
rounds = gets.chomp.downcase
|
|
21
|
+
|
|
22
|
+
case rounds
|
|
23
|
+
when /^\d+$/
|
|
24
|
+
throwdown.play(rounds.to_i) # { throwdown.total_points >= 10_000 }
|
|
25
|
+
when 'quit', 'exit', 'n'
|
|
26
|
+
throwdown.result
|
|
27
|
+
throwdown.winning
|
|
28
|
+
break
|
|
29
|
+
else
|
|
30
|
+
puts 'please enter a number'
|
|
31
|
+
sleep(1)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
throwdown.save_high_scores
|
data/bin/csv/players.csv
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require_relative 'player'
|
|
2
|
+
module BattleRoyal
|
|
3
|
+
class AdvantagedPlayer < Player
|
|
4
|
+
def initialize(name, health = 100)
|
|
5
|
+
super(name, health)
|
|
6
|
+
@power_up_count = 0
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def advantaged?
|
|
10
|
+
@power_up_count > 5
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def power_up
|
|
14
|
+
super
|
|
15
|
+
@power_up_count += 1
|
|
16
|
+
puts "#{@name} is advantaged!" if advantaged?
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def damage
|
|
20
|
+
advantaged? ? power_up : super
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
if __FILE__ == $PROGRAM_NAME
|
|
25
|
+
advantaged = AdvantagedPlayer.new('advantaged', 50)
|
|
26
|
+
6.times { advantaged.power_up }
|
|
27
|
+
2.times { advantaged.damage }
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
require_relative 'player'
|
|
2
|
+
require_relative 'roll'
|
|
3
|
+
require_relative 'weapon_chest'
|
|
4
|
+
require_relative 'lame_player'
|
|
5
|
+
require_relative 'advantaged_player'
|
|
6
|
+
require 'csv'
|
|
7
|
+
module BattleRoyal
|
|
8
|
+
class Game
|
|
9
|
+
attr_accessor :title, :players, :toasty
|
|
10
|
+
def initialize(title)
|
|
11
|
+
@title = title
|
|
12
|
+
@players = [].sort
|
|
13
|
+
@total_points = 0
|
|
14
|
+
@toasty = []
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def add_player(player)
|
|
18
|
+
@players << player
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def load_players(some_file)
|
|
22
|
+
CSV.foreach(some_file).each do |line|
|
|
23
|
+
add_player(Player.from_csv(line))
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def save_high_scores
|
|
28
|
+
File.open("#{title}.txt", 'w') do |file|
|
|
29
|
+
file.puts "#{@title} High Scores:"
|
|
30
|
+
@players.sort_by(&:score).reverse_each do |player|
|
|
31
|
+
file.puts sort_and_score(player)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def start_of_game
|
|
37
|
+
puts "There are #{@players.size} players and #{WeaponChest::WEAPONS.count} weapons available in this game: "
|
|
38
|
+
|
|
39
|
+
WeaponChest::WEAPONS.each { |x| puts "A #{x.name} is worth #{x.points} points" }
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def attack_player
|
|
43
|
+
@players.sample
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def fatality?(player)
|
|
47
|
+
player.health < 0
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def play(rounds)
|
|
51
|
+
start_of_game
|
|
52
|
+
1.upto(rounds) do
|
|
53
|
+
# if a block is given AND the block returns true, break out of loop.
|
|
54
|
+
break if yield if block_given?
|
|
55
|
+
if @players.count > 1
|
|
56
|
+
@players.shuffle.each do |player|
|
|
57
|
+
if !fatality?(player)
|
|
58
|
+
Roll.turn(player)
|
|
59
|
+
sleep(0.5)
|
|
60
|
+
player.attack(attack_player, player.found_weapon(Roll.weapon(player)))
|
|
61
|
+
sleep(0.5)
|
|
62
|
+
player.points
|
|
63
|
+
elsif fatality?(player)
|
|
64
|
+
@toasty << @players.find { |x| x == player }
|
|
65
|
+
puts "\n#{player.name} is no longer with us"
|
|
66
|
+
@players.delete(player)
|
|
67
|
+
sleep(0.5)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
else
|
|
71
|
+
puts "\n#{@players[0].name.upcase} IS THE LAST MAN STANDING!!! "
|
|
72
|
+
break
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
@players |= @toasty
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def print_player_and_health(criteria)
|
|
79
|
+
criteria.sort_by(&:score).reverse_each do |player|
|
|
80
|
+
puts "\n#{player.name}'s point totals: "
|
|
81
|
+
player.each_found_weapon do |weapon|
|
|
82
|
+
puts "#{weapon.points} total #{weapon.name} points"
|
|
83
|
+
end
|
|
84
|
+
puts "#{player.points} grand total points"
|
|
85
|
+
puts "health: #{player.health}"
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def result
|
|
90
|
+
stronger, weaker = @players.partition(&:strong?)
|
|
91
|
+
puts "\n Statistics:"
|
|
92
|
+
|
|
93
|
+
puts "\n#{stronger.size} strong players:"
|
|
94
|
+
print_player_and_health(stronger)
|
|
95
|
+
|
|
96
|
+
puts "\n#{weaker.size} weaker players:"
|
|
97
|
+
print_player_and_health(weaker)
|
|
98
|
+
|
|
99
|
+
puts "\n#{total_points} total points for this match"
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def winning
|
|
103
|
+
puts "\nScoreboard: "
|
|
104
|
+
@players.sort_by(&:score).reverse_each do |player|
|
|
105
|
+
puts sort_and_score(player)
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def sort_and_score(player)
|
|
110
|
+
formatted_name = player.name.ljust(20, '.')
|
|
111
|
+
"#{formatted_name} #{player.score}"
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def total_points
|
|
115
|
+
@players.inject(0) { |sum, player| sum + player.points }
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require_relative 'player'
|
|
2
|
+
module BattleRoyal
|
|
3
|
+
class LamePlayer < Player
|
|
4
|
+
def initialize(name, health = 100, boost = 1)
|
|
5
|
+
super(name, health)
|
|
6
|
+
@boost = boost
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def found_weapon(weapon)
|
|
10
|
+
damaged_weapon = Weapon.new(weapon.name, weapon.points / 2)
|
|
11
|
+
super(damaged_weapon)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def power_up
|
|
15
|
+
@boost.times { super }
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
if __FILE__ == $PROGRAM_NAME
|
|
20
|
+
lame = LamePlayer.new('klutz')
|
|
21
|
+
|
|
22
|
+
axe = Weapon.new(:axe, 50)
|
|
23
|
+
lame.found_weapon(axe)
|
|
24
|
+
lame.found_weapon(axe)
|
|
25
|
+
lame.found_weapon(axe)
|
|
26
|
+
|
|
27
|
+
sabre = Weapon.new(:sabre, 400)
|
|
28
|
+
lame.found_weapon(sabre)
|
|
29
|
+
|
|
30
|
+
lame.each_found_weapon do |weapon|
|
|
31
|
+
puts "#{weapon.points} total #{weapon.name} points"
|
|
32
|
+
end
|
|
33
|
+
puts "#{lame.points} grand total points"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module BattleRoyal
|
|
2
|
+
module Playable
|
|
3
|
+
def power_up
|
|
4
|
+
self.health += 15
|
|
5
|
+
puts "\n#{name} got a power up!"
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def damage
|
|
9
|
+
self.health -= 10
|
|
10
|
+
puts "\n#{name} got damaged and now has a health of #{health}"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def strong?
|
|
14
|
+
self.health >= 100
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require_relative 'weapon_chest'
|
|
2
|
+
require_relative 'playable'
|
|
3
|
+
module BattleRoyal
|
|
4
|
+
class Player
|
|
5
|
+
include Playable
|
|
6
|
+
|
|
7
|
+
attr_accessor :name, :health
|
|
8
|
+
def initialize(name, health = 100)
|
|
9
|
+
@name = name.capitalize
|
|
10
|
+
@health = health
|
|
11
|
+
@found_weapons = Hash.new(0)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def to_s
|
|
15
|
+
"#{@name} health = #{@health}, points = #{points}, and score = #{score}"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.from_csv(string)
|
|
19
|
+
Player.new(string[0], string[1].to_i)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def found_weapon(weapon)
|
|
23
|
+
@found_weapons[weapon.name] += weapon.points
|
|
24
|
+
print "\n#{@name} found a #{weapon.name} worth #{weapon.points} damage points"
|
|
25
|
+
|
|
26
|
+
@found_weapons[weapon.name]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def attack(player, found_weapon)
|
|
30
|
+
@health = health - found_weapon
|
|
31
|
+
print " and attacked #{player.name} \n"
|
|
32
|
+
sleep(0.5)
|
|
33
|
+
puts "#{player.name}'s health is now: #{player.health} \n"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def points
|
|
37
|
+
@found_weapons.values.inject(0, :+)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def each_found_weapon
|
|
41
|
+
@found_weapons.each do |name, points|
|
|
42
|
+
yield Weapon.new(name, points)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def score
|
|
47
|
+
points + @health
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
if __FILE__ == $PROGRAM_NAME
|
|
53
|
+
# part of the readme
|
|
54
|
+
player = Player.new('Scorpion')
|
|
55
|
+
puts player.name
|
|
56
|
+
puts player.health
|
|
57
|
+
player.power_up
|
|
58
|
+
puts player.health
|
|
59
|
+
player.damage
|
|
60
|
+
puts player.health
|
|
61
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module BattleRoyal
|
|
2
|
+
module Roll
|
|
3
|
+
def self.actions
|
|
4
|
+
[:power_up, :damage, nil]
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def self.turn(player)
|
|
8
|
+
action = actions.sample
|
|
9
|
+
!action.nil? ? player.send(action) : puts("\n#{player.name} missed a turn")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.weapon(_player)
|
|
13
|
+
WeaponChest.random
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module BattleRoyal
|
|
2
|
+
Weapon = Struct.new(:name, :points)
|
|
3
|
+
|
|
4
|
+
module WeaponChest
|
|
5
|
+
WEAPONS = [
|
|
6
|
+
Weapon.new("throwing star".to_sym, 5),
|
|
7
|
+
Weapon.new(:staff, 25),
|
|
8
|
+
Weapon.new(:axe, 50),
|
|
9
|
+
Weapon.new(:mace, 100),
|
|
10
|
+
Weapon.new(:katana, 200),
|
|
11
|
+
Weapon.new(:sabre, 400)
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
def self.random
|
|
15
|
+
WEAPONS.sample
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'battle_royal/advantaged_player'
|
|
2
|
+
module BattleRoyal
|
|
3
|
+
describe AdvantagedPlayer do
|
|
4
|
+
before do
|
|
5
|
+
@initial_health = 50
|
|
6
|
+
@player = AdvantagedPlayer.new('advantaged', @initial_health)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it 'does not go advantaged when power_uped up to 5 times' do
|
|
10
|
+
1.upto(5) { @player.power_up }
|
|
11
|
+
expect(@player.advantaged?).to be_falsey
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'goes advantaged when power_uped more than 5 times' do
|
|
15
|
+
1.upto(6) { @player.power_up }
|
|
16
|
+
expect(@player.advantaged?).to be_truthy
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "gets power_uped instead of damagemed when it's gone advantaged" do
|
|
20
|
+
1.upto(6) { @player.power_up }
|
|
21
|
+
1.upto(2) { @player.damage }
|
|
22
|
+
|
|
23
|
+
expect(@player.health).to be(@initial_health + (8 * 15))
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'battle_royal/game'
|
|
2
|
+
module BattleRoyal
|
|
3
|
+
describe Game do
|
|
4
|
+
it 'computes total points as the sum of all player points' do
|
|
5
|
+
$stdout = StringIO.new
|
|
6
|
+
game = Game.new('battle')
|
|
7
|
+
|
|
8
|
+
player1 = Player.new('scorpion')
|
|
9
|
+
player2 = Player.new('stryker')
|
|
10
|
+
|
|
11
|
+
game.add_player(player1)
|
|
12
|
+
game.add_player(player2)
|
|
13
|
+
|
|
14
|
+
player1.found_weapon(Weapon.new(:axe, 50))
|
|
15
|
+
player1.found_weapon(Weapon.new(:axe, 50))
|
|
16
|
+
player2.found_weapon(Weapon.new(:sabre, 400))
|
|
17
|
+
|
|
18
|
+
expect(game.total_points).to eq(500)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'battle_royal/lame_player'
|
|
2
|
+
module BattleRoyal
|
|
3
|
+
describe LamePlayer do
|
|
4
|
+
before do
|
|
5
|
+
@player = LamePlayer.new('stryker')
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it 'only gets half the point value for each weapon' do
|
|
9
|
+
expect(@player.points).to eq(0)
|
|
10
|
+
|
|
11
|
+
axe = Weapon.new(:axe, 50)
|
|
12
|
+
@player.found_weapon(axe)
|
|
13
|
+
@player.found_weapon(axe)
|
|
14
|
+
@player.found_weapon(axe)
|
|
15
|
+
|
|
16
|
+
expect(@player.points).to eq(75)
|
|
17
|
+
|
|
18
|
+
sabre = Weapon.new(:sabre, 400)
|
|
19
|
+
@player.found_weapon(sabre)
|
|
20
|
+
|
|
21
|
+
expect(@player.points).to eq(275)
|
|
22
|
+
|
|
23
|
+
yielded = []
|
|
24
|
+
@player.each_found_weapon do |weapon|
|
|
25
|
+
yielded << weapon
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
expect(yielded).to eq([Weapon.new(:axe, 75), Weapon.new(:sabre, 200)])
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
require 'battle_royal/player'
|
|
2
|
+
require 'battle_royal/weapon_chest'
|
|
3
|
+
|
|
4
|
+
module BattleRoyal
|
|
5
|
+
describe Player do
|
|
6
|
+
before do
|
|
7
|
+
# removes string output for power_up and damage methods while spec is running(only)
|
|
8
|
+
$stdout = StringIO.new
|
|
9
|
+
|
|
10
|
+
@initial_health = 150
|
|
11
|
+
@player = Player.new('stryker', @initial_health)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def found_weapon
|
|
15
|
+
@player.found_weapon(Weapon.new(:axe, 50))
|
|
16
|
+
end
|
|
17
|
+
it 'has a capitalized name' do
|
|
18
|
+
expect(@player.name).to eq('Stryker')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'has an initial health' do
|
|
22
|
+
expect(@player.health).to eq(150)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'has a string representation' do
|
|
26
|
+
2.times { found_weapon }
|
|
27
|
+
|
|
28
|
+
expect(@player.to_s).to eq('Stryker health = 150, points = 100, and score = 250')
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'computes a score as the sum of its health and points' do
|
|
32
|
+
2.times { found_weapon }
|
|
33
|
+
|
|
34
|
+
expect(@player.score).to eq(250)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'increases health by 15 when power_uped' do
|
|
38
|
+
@player.power_up
|
|
39
|
+
expect(@player.health).to eq(@initial_health + 15)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'decreases health by 10 when damagemed' do
|
|
43
|
+
@player.damage
|
|
44
|
+
expect(@player.health).to eq(@initial_health - 10)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
context 'player has health of 150' do
|
|
48
|
+
before do
|
|
49
|
+
@initial_health = 150
|
|
50
|
+
@player = Player.new('stryker', @initial_health)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'returns true if player is strong' do
|
|
54
|
+
expect(@player).to be_strong
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
context 'player has health of 100 or less' do
|
|
59
|
+
before do
|
|
60
|
+
@initial_health = 99
|
|
61
|
+
@player = Player.new('scorpion', @initial_health)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'returns false if player health is less 100 or less' do
|
|
65
|
+
expect(@player).not_to be_strong
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
context 'players collect weapons' do
|
|
69
|
+
it 'computes points as the sum of all weapon points' do
|
|
70
|
+
expect(@player.points).to eq(0)
|
|
71
|
+
|
|
72
|
+
@player.found_weapon(Weapon.new(:axe, 50))
|
|
73
|
+
|
|
74
|
+
expect(@player.points).to eq(50)
|
|
75
|
+
|
|
76
|
+
@player.found_weapon(Weapon.new(:sabre, 400))
|
|
77
|
+
|
|
78
|
+
expect(@player.points).to eq(450)
|
|
79
|
+
|
|
80
|
+
@player.found_weapon(Weapon.new(:axe, 50))
|
|
81
|
+
|
|
82
|
+
expect(@player.points).to eq(500)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it 'yields each found weapon and its total points' do
|
|
87
|
+
@player.found_weapon(Weapon.new(:mace, 100))
|
|
88
|
+
@player.found_weapon(Weapon.new(:mace, 100))
|
|
89
|
+
@player.found_weapon(Weapon.new(:axe, 50))
|
|
90
|
+
@player.found_weapon(Weapon.new(:staff, 5))
|
|
91
|
+
@player.found_weapon(Weapon.new(:staff, 5))
|
|
92
|
+
@player.found_weapon(Weapon.new(:staff, 5))
|
|
93
|
+
@player.found_weapon(Weapon.new(:staff, 5))
|
|
94
|
+
@player.found_weapon(Weapon.new(:staff, 5))
|
|
95
|
+
|
|
96
|
+
yielded = []
|
|
97
|
+
@player.each_found_weapon do |weapon|
|
|
98
|
+
yielded << weapon
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
expect(yielded).to eq([
|
|
102
|
+
Weapon.new(:mace, 200),
|
|
103
|
+
Weapon.new(:axe, 50),
|
|
104
|
+
Weapon.new(:staff, 25)
|
|
105
|
+
])
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require 'battle_royal/weapon_chest'
|
|
2
|
+
module BattleRoyal
|
|
3
|
+
describe Weapon do
|
|
4
|
+
before do
|
|
5
|
+
@weapon = Weapon.new(:axe, 50)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it 'has a name attribute' do
|
|
9
|
+
expect(@weapon.name).to eq(:axe)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'has a points attribute' do
|
|
13
|
+
expect(@weapon.points).to eq(50)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe WeaponChest do
|
|
18
|
+
it 'has six weapons' do
|
|
19
|
+
expect(WeaponChest::WEAPONS.size).to eq(6)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'has a throwing_star worth 5 points' do
|
|
23
|
+
expect(WeaponChest::WEAPONS[0]).to eq (Weapon.new(:throwing_star, 5))
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'has a staff worth 25 points' do
|
|
27
|
+
expect(WeaponChest::WEAPONS[1]).to eq (Weapon.new(:staff, 25))
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'has a axe worth 50 points' do
|
|
31
|
+
expect(WeaponChest::WEAPONS[2]).to eq (Weapon.new(:axe, 50))
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'has a mace worth 100 points' do
|
|
35
|
+
expect(WeaponChest::WEAPONS[3]).to eq (Weapon.new(:mace, 100))
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'has a katana worth 200 points' do
|
|
39
|
+
expect(WeaponChest::WEAPONS[4]).to eq (Weapon.new(:katana, 200))
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'has a sabre worth 400 points' do
|
|
43
|
+
expect(WeaponChest::WEAPONS[5]).to eq (Weapon.new(:sabre, 400))
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: battle_royal
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- "@shanebarringer"
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-10-28 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rspec
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
description: |
|
|
28
|
+
## battle royal
|
|
29
|
+
A Mortal Kombat influenced battle royal gem
|
|
30
|
+
|
|
31
|
+
### To Use
|
|
32
|
+
run `gem install battle_royal`
|
|
33
|
+
|
|
34
|
+
In your terminal simply run `$ battle`
|
|
35
|
+
|
|
36
|
+
### Notes
|
|
37
|
+
|
|
38
|
+
Currently, the game allows for users to input a certain number of rounds. The battle will run until there is only 1 player standing.
|
|
39
|
+
I recommend that you run the game for at least 10 - 100 rounds
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
### To Contribute
|
|
43
|
+
1. Fork
|
|
44
|
+
2. Clone
|
|
45
|
+
3. Create a New Branch
|
|
46
|
+
4. Submit a Pull Request
|
|
47
|
+
email: shane.barringer@outlook.com
|
|
48
|
+
executables:
|
|
49
|
+
- battle
|
|
50
|
+
extensions: []
|
|
51
|
+
extra_rdoc_files: []
|
|
52
|
+
files:
|
|
53
|
+
- LICENSE
|
|
54
|
+
- README.md
|
|
55
|
+
- bin/battle
|
|
56
|
+
- bin/csv/favorite_players.csv
|
|
57
|
+
- bin/csv/players.csv
|
|
58
|
+
- lib/battle_royal/advantaged_player.rb
|
|
59
|
+
- lib/battle_royal/game.rb
|
|
60
|
+
- lib/battle_royal/lame_player.rb
|
|
61
|
+
- lib/battle_royal/playable.rb
|
|
62
|
+
- lib/battle_royal/player.rb
|
|
63
|
+
- lib/battle_royal/roll.rb
|
|
64
|
+
- lib/battle_royal/weapon_chest.rb
|
|
65
|
+
- spec/battle_royal/advantaged_player_spec.rb
|
|
66
|
+
- spec/battle_royal/game_spec.rb
|
|
67
|
+
- spec/battle_royal/lame_player_spec.rb
|
|
68
|
+
- spec/battle_royal/player_spec.rb
|
|
69
|
+
- spec/battle_royal/weapon_chest_spec.rb
|
|
70
|
+
homepage: https://github.com/shanebarringer/battle_royal
|
|
71
|
+
licenses:
|
|
72
|
+
- MIT
|
|
73
|
+
metadata: {}
|
|
74
|
+
post_install_message:
|
|
75
|
+
rdoc_options: []
|
|
76
|
+
require_paths:
|
|
77
|
+
- lib
|
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '1.9'
|
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
|
+
requirements:
|
|
85
|
+
- - ">="
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: '0'
|
|
88
|
+
requirements: []
|
|
89
|
+
rubyforge_project:
|
|
90
|
+
rubygems_version: 2.4.6
|
|
91
|
+
signing_key:
|
|
92
|
+
specification_version: 4
|
|
93
|
+
summary: A Mortal Kombat influenced Battle Royal
|
|
94
|
+
test_files:
|
|
95
|
+
- spec/battle_royal/advantaged_player_spec.rb
|
|
96
|
+
- spec/battle_royal/game_spec.rb
|
|
97
|
+
- spec/battle_royal/lame_player_spec.rb
|
|
98
|
+
- spec/battle_royal/player_spec.rb
|
|
99
|
+
- spec/battle_royal/weapon_chest_spec.rb
|