knuckleheads_the_ones_doomed_to_fail 1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 840aa99ed2f5ee4f7ac739189a0e3a2eb186d7aad45bc01b0f549e227ebbe21f
4
+ data.tar.gz: bb2d18f07e5586f3eb4a76728a15f82e63c8bf7a34ac1b8b690dced1991208ae
5
+ SHA512:
6
+ metadata.gz: 6e53d162d6fb2550daf4f1857f2ccb3760201bb3545cc9673fbf637929ba1e4705b93cca8d680c45a6f478b8312f4861a12c2d75b77f66cc56fb83d80a5d7799
7
+ data.tar.gz: 03110bc5061e55ca8f5fd332d1746c931168ee456c7eb930c4a4dc755849d88651b21dff6093259947540f23d2800f19ac20cc7c142395d658c36183b7f030f2
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2020- Kylie Camp
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ Cute, fun game with some nerds to play! :)
@@ -0,0 +1,124 @@
1
+ require_relative '../lib/knuckleheads/game'
2
+ require_relative '../lib/knuckleheads/player'
3
+ require_relative '../lib/knuckleheads/game_turn_module'
4
+ require_relative '../lib/knuckleheads/die'
5
+ require_relative '../lib/knuckleheads/clumsy_player'
6
+ require_relative '../lib/knuckleheads/berserker_player'
7
+
8
+ players = []
9
+
10
+ knuckleheads = KnuckleheadsGame::Game.new("Knuckleheads")
11
+ default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
12
+ knuckleheads.load_players(ARGV.shift || default_player_file)
13
+
14
+ # knuckleheads.load_players(ARGV.shift || "players.csv")
15
+
16
+ puts knuckleheads.title
17
+
18
+ player1 = KnuckleheadsGame::Player.new("moore")
19
+ player2 = KnuckleheadsGame::Player.new("larry", 60)
20
+ # player2.name = "Lawrence"
21
+ player3 = KnuckleheadsGame::Player.new("curly", 125)
22
+ player4 = KnuckleheadsGame::Player.new("shemp", 90)
23
+
24
+ klutz = KnuckleheadsGame::ClumsyPlayer.new("klutz", 105)
25
+ berserker = KnuckleheadsGame::BerserkerPlayer.new("berserker", 50)
26
+
27
+ knuckleheads.add_player(klutz)
28
+ knuckleheads.add_player(berserker)
29
+
30
+ players = [player1, player2, player3, player4, klutz, berserker]
31
+
32
+ # knuckleheads.add_player(player1)
33
+ # knuckleheads.add_player(player2)
34
+ # knuckleheads.add_player(player3)
35
+ # knuckleheads.add_player(player4)
36
+
37
+ loop do
38
+ puts "\nHow many rounds would you like to play? (Or, 'quit' to exit.)"
39
+ answer = gets.chomp.downcase
40
+ case answer
41
+ when /^\d+$/
42
+ knuckleheads.play(answer.to_i)
43
+ when 'quit', 'exit', 'end'
44
+ knuckleheads.print_stats
45
+ break
46
+ else
47
+ "Please enter a number for the amount of rounds to play, or 'quit' to exit."
48
+ end
49
+ end
50
+
51
+ knuckleheads.save_high_scores
52
+
53
+ # players.each do |player|
54
+ # puts player.health
55
+ # end
56
+
57
+ # players.each do |player|
58
+ # puts player
59
+ # puts player.blam
60
+ # puts player.w00t
61
+ # puts player.w00t
62
+ # puts player
63
+ # puts "- - -"
64
+ # end
65
+
66
+ # puts "- - -\n\t"
67
+ # puts player3.blam
68
+ # puts player3.blam
69
+ # puts player3.blam
70
+ # puts player3
71
+ # puts player3.w00t
72
+ # puts player3
73
+
74
+ # def say_hello(name, health=100)
75
+ # puts "I'm #{name.capitalize} with a health of #{health} as of #{time}!"
76
+ # end
77
+
78
+ # def time
79
+ # current_time = Time.new
80
+ # current_time.strftime("%I:%M:%S")
81
+ # end
82
+
83
+ # say_hello("larry", 60)
84
+ # say_hello("curly", 125)
85
+ # say_hello("moe")
86
+ # say_hello("shemp", 90)
87
+
88
+
89
+ # # # name1 = 'larry'
90
+ # # # health1 = 60
91
+ # # # puts name1 + '\'s' + ' health is ' + health1.to_s
92
+
93
+ # # # name2 = 'curly'
94
+ # # # name3 = 'moe'
95
+
96
+ # # # puts "#{name1}'s health is #{health1}."
97
+ # # # puts "#{name1}'s health is #{health1 * 3}."
98
+
99
+ # # # puts "#{name1}'s health is #{health1 / 9.0}."
100
+ # # # puts "#{name1}'s health is #{health1 / 9}."
101
+
102
+ # # # puts "Players: \n\tlarry\n\tcurly\n\tmoe"
103
+
104
+ # # # puts "Players: \n\t#{name1}\n\t#{name2}\n\t#{name3}"
105
+
106
+ # # name1 = 'larry'
107
+ # # health1 = 60
108
+
109
+ # # name2 = 'curly'
110
+ # # health2 = 125
111
+
112
+ # # name3 = 'moe'
113
+ # # health3 = 100
114
+
115
+ # # name4 = 'shemp'
116
+ # # health4 = 90
117
+
118
+ # # health2 = health1
119
+ # # health1 = 30
120
+
121
+ # # puts "#{name1.capitalize}'s health is #{health1}."
122
+ # # puts "#{name2.upcase}'s health is #{health2}."
123
+ # # puts "#{name3}'s health is #{health3}.".center(50, '*')
124
+ # # puts "#{name4.capitalize.ljust(30, '.')} #{health4}"
@@ -0,0 +1,4 @@
1
+ Moore,100
2
+ Larry,60
3
+ Curly,125
4
+ Shemp,90
@@ -0,0 +1,5 @@
1
+ module Auditable
2
+ def audit
3
+ puts "Rolled a #{self.number} (#{self.class})."
4
+ end
5
+ end
@@ -0,0 +1,40 @@
1
+ require_relative 'player'
2
+
3
+ module KnuckleheadsGame
4
+
5
+ class BerserkerPlayer < Player
6
+
7
+ def initialize(name, health=100)
8
+ super(name, health)
9
+ @w00t_count = 0
10
+ end
11
+
12
+ def berserk?
13
+ @w00t_count > 5
14
+ end
15
+
16
+
17
+ def w00t
18
+ super
19
+ @w00t_count += 1
20
+ puts "#{@name} is going berserk!!" if berserk?
21
+ end
22
+
23
+ if __FILE__ == $0
24
+ berserker = KnuckleheadsGame::BerserkPlayer.new("berserker", 50)
25
+ 6.times { berserker.w00t }
26
+ 2.times { berserker.blam }
27
+
28
+ puts berserker.health
29
+ end
30
+
31
+ def blam
32
+ if berserk?
33
+ w00t
34
+ else
35
+ super
36
+ end
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,36 @@
1
+ require_relative 'player'
2
+ require_relative 'treasure_trove'
3
+
4
+ module KnuckleheadsGame
5
+
6
+ class ClumsyPlayer < Player
7
+
8
+ if __FILE__ == $0
9
+ clumsy = KnuckleheadsGame::ClumsyPlayer.new("klutz")
10
+
11
+ # potion = Treasure.new(:potion, 50)
12
+ # clumsy.found_treasures(potion)
13
+ # clumsy.found_treasures(potion)
14
+ # clumsy.found_treasures(potion)
15
+
16
+ strange_weapon = KnuckleheadsGame::Treasure.new(:strange_weapon, 200.0)
17
+ clumsy.found_treasures(strange_weapon)
18
+ clumsy.found_treasures(strange_weapon)
19
+
20
+ clumsy.each_found_treasure do |treasure|
21
+ puts "#{@treasure.points} total #{@treasure.name} points."
22
+ end
23
+
24
+ puts "#{clumsy.points}'s Grand Total Points:"
25
+ end
26
+
27
+ def found_treasures(treasure)
28
+ damaged_treasure = KnuckleheadsGame::Treasure.new(treasure.name, treasure.points / 2.0)
29
+ super(damaged_treasure)
30
+ # @point_score += treasure.points / 2.0
31
+ # @found_treasures[treasure.name] += treasure.points
32
+ # puts "#{@name} found a #{treasure.name} worth #{points}."
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,29 @@
1
+ require_relative 'game'
2
+ require_relative 'player'
3
+ require_relative 'game_turn_module'
4
+ require_relative 'auditable'
5
+
6
+ module KnuckleheadsGame
7
+
8
+ class Die
9
+ attr_reader :number
10
+
11
+ include Auditable
12
+
13
+ def initialize
14
+ roll
15
+ end
16
+
17
+ def roll
18
+ @number = rand(1..6)
19
+ audit
20
+ @number
21
+ end
22
+
23
+ # if __FILE__ == $0
24
+ # die = Die.new
25
+ # puts die.roll
26
+ # puts die.roll
27
+ # puts die.roll
28
+ end
29
+ end
@@ -0,0 +1,118 @@
1
+ require_relative 'player'
2
+ require_relative 'die'
3
+ require_relative 'game_turn_module'
4
+ require_relative 'treasure_trove'
5
+
6
+ module KnuckleheadsGame
7
+
8
+ class Game
9
+ attr_reader :title
10
+ attr_accessor :players
11
+
12
+ def initialize(title="Knuckleheads")
13
+ @title = title.capitalize
14
+ @players = []
15
+ end
16
+
17
+ def add_player(a_player)
18
+ @players << a_player
19
+ end
20
+
21
+ def load_players(from_file)
22
+ File.readlines(from_file).each do |line|
23
+ # name, health = line.split(',')
24
+ # player = Player.new(name, Integer(health))
25
+ add_player(KnuckleheadsGame::Player.from_csv(line))
26
+ end
27
+ end
28
+
29
+ def high_score_entry(player)
30
+ formatted_name = player.name.ljust(15, '-')
31
+ puts "\n\t#{formatted_name} #{player.score}"
32
+ end
33
+
34
+ def save(to_file="players.csv")
35
+ File.open(to_file, "w") do |file|
36
+ @players.sort.each do |player|
37
+ file.puts player.to_csv
38
+ end
39
+ end
40
+ end
41
+
42
+ def save_high_scores(to_file="high_scores.txt")
43
+ File.open(to_file, "w") do |file|
44
+ file.puts "#{title}'s High Scores:"
45
+ @players.sort.each do |player|
46
+ file.puts high_score_entry(player)
47
+ end
48
+ end
49
+ end
50
+
51
+ def play(rounds)
52
+ puts "\n\tThere are #{@players.size} players in the game."
53
+
54
+ treasures = KnuckleheadsGame::TreasureTrove::TREASURES
55
+ puts"\nThere are #{treasures.size} treasures to be found in the game. Good luck!"
56
+ treasures.each do |treasure|
57
+ puts "\n\tA #{treasure.name} is worth #{treasure.points} points."
58
+ end
59
+
60
+ puts "\n- - -"
61
+
62
+ @players.each do |player|
63
+ puts "\n#{player}"
64
+ end
65
+
66
+ puts "- - -"
67
+
68
+ 1.upto(rounds) do |round|
69
+ puts "\nRound #{round}: "
70
+
71
+ @players.each do |player|
72
+ KnuckleheadsGame::GameTurn.take_turn(player)
73
+ puts player
74
+ end
75
+ end
76
+ end
77
+
78
+ def print_name_and_health(player)
79
+ puts "\t#{player.name} (#{player.health})"
80
+ end
81
+
82
+ def print_stats
83
+ strong_players = @players.select{ |player| player.strong? }
84
+ wimpy_players = @players.reject{ |player| player.strong? }
85
+
86
+ puts "\nKnuckleheads's Statistics: "
87
+
88
+ puts "\n#{strong_players.size} strong player(s): "
89
+ strong_players.each do |player|
90
+ print_name_and_health(player)
91
+ end
92
+
93
+ puts "\n#{wimpy_players.size} wimpy player(s): "
94
+ wimpy_players.each do |player|
95
+ print_name_and_health(player)
96
+ end
97
+
98
+ # sorted_players = @players.sort { |a, b| b.score <=> a.score }
99
+
100
+ @players.sort.each do |player|
101
+ puts "\n#{player.name}'s Treasure Haul:"
102
+ formatted_name = player.name
103
+ player.each_found_treasure do |treasure|
104
+ puts "\t#{treasure.name}: #{treasure.points}"
105
+ end
106
+ end
107
+
108
+ puts "\nKnuckleheads's High Scores: "
109
+ @players.sort.each do |player|
110
+ # puts high_score_entry(player)
111
+ # formatted_name = player.name.ljust(15, '-')
112
+ # puts "\t#{formatted_name} #{player.score}"
113
+ end
114
+
115
+ end
116
+
117
+ end
118
+ end
@@ -0,0 +1,30 @@
1
+ require_relative 'player'
2
+ require_relative 'die'
3
+ require_relative 'game'
4
+ require_relative 'loaded_die'
5
+
6
+ module KnuckleheadsGame
7
+
8
+ module GameTurn
9
+ def self.take_turn(player)
10
+ die = KnuckleheadsGame::Die.new
11
+ # die = LoadedDie.new
12
+
13
+ number_rolled = die.roll
14
+
15
+ case die.roll
16
+ when 1..2
17
+ player.blam
18
+ when 3..4
19
+ puts "#{player.name} was skipped"
20
+ else
21
+ player.w00t
22
+ end
23
+
24
+ treasure = KnuckleheadsGame::TreasureTrove.random
25
+ player.found_treasures(treasure)
26
+ # puts "#{player.name} found a #{treasure.name}! It is worth #{treasure.points}."
27
+ # puts "#{player.name}'s current treasures are: #{@found_treasures}."
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,17 @@
1
+ require_relative 'auditable'
2
+
3
+ module KnuckleheadsGame
4
+
5
+ class LoadedDie
6
+ attr_reader :number
7
+
8
+ include Auditable
9
+
10
+ def roll
11
+ numbers = [ 1, 1, 2, 5, 6, 6]
12
+ @number = numbers.sample
13
+ audit
14
+ @number
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ module KnuckleheadsGame
2
+
3
+ module Playable
4
+
5
+ def blam
6
+ @health -= 10
7
+ puts "#{@name} got blammed!"
8
+ end
9
+
10
+ def w00t
11
+ @health += 15
12
+ puts "#{@name} got w00ted!"
13
+ end
14
+
15
+ def strong?
16
+ @health > 100
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,74 @@
1
+ require_relative 'game'
2
+ require_relative 'die'
3
+ require_relative 'treasure_trove'
4
+ require_relative 'playable'
5
+
6
+ module KnuckleheadsGame
7
+
8
+ class Player
9
+ attr_accessor :name
10
+ attr_reader :health
11
+
12
+ include Playable
13
+
14
+ def initialize(name, health=100)
15
+ @name = name.capitalize
16
+ @health = health
17
+ @found_treasures = Hash.new(0)
18
+ @point_score = 0
19
+ end
20
+
21
+ def self.from_csv(line)
22
+ name, health = line.split(',')
23
+ player = KnuckleheadsGame::Player.new(name, Integer(health))
24
+ end
25
+
26
+ def to_csv
27
+ "#{@name},#{@health}"
28
+ end
29
+
30
+ def load_players(from_file)
31
+ File.readlines(from_file).each do |line|
32
+ add_player(KnuckleheadsGame::Player.from_csv(line))
33
+ end
34
+ end
35
+
36
+ def found_treasures(treasure)
37
+ @found_treasures[treasure.name] += treasure.points
38
+
39
+ @point_score += treasure.points
40
+
41
+ puts "#{@name} found a #{treasure.name}! It is worth #{treasure.points}."
42
+ puts "#{@name}'s current treasures are: #{@found_treasures}."
43
+ end
44
+
45
+ def each_found_treasure
46
+ @found_treasures.each do |name, points|
47
+ yield KnuckleheadsGame::Treasure.new(name, points)
48
+ end
49
+ end
50
+
51
+ def points
52
+ @found_treasures.values.reduce(0, :+)
53
+ end
54
+
55
+ def score
56
+ @health + @point_score
57
+ end
58
+
59
+ def point_score
60
+ @score + points
61
+ end
62
+
63
+
64
+ def <=>(other)
65
+ other.score <=> score
66
+ end
67
+
68
+ def to_s
69
+ # say_hello changed to to_s
70
+ "I'm #{@name} with a health of #{@health}; my score is #{score}, and my treasure value is #{@point_score}.\n\t"
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,34 @@
1
+ module KnuckleheadsGame
2
+
3
+ Treasure = Struct.new(:name, :points)
4
+
5
+ module KnuckleheadsGame::TreasureTrove
6
+ TREASURES = [
7
+ KnuckleheadsGame::Treasure.new(:ration, 5.0),
8
+ # rations are 5sp; 10sp = 1gp, so 10 rations are 5g)
9
+ KnuckleheadsGame::Treasure.new(:bow, 25.0),
10
+ # simple ranged weapon of the person's proficiency (crossbow or shortbow)
11
+ KnuckleheadsGame::Treasure.new(:potion, 50.0),
12
+ # 1 potion of health = 50gp
13
+ KnuckleheadsGame::Treasure.new(:gemstone, 100.0),
14
+ # one of the 100gp gemstones is here as a reward: amber, amethyst, chrysoberyl, coral, garnet, jade, jet, pearl, spinel, tourmaline
15
+ KnuckleheadsGame::Treasure.new(:strange_armor, 200.0),
16
+ # armor of the person's proficiency that gives them +1 to their AC
17
+ KnuckleheadsGame::Treasure.new(:strange_weapon, 200.0),
18
+ # weapon of the person's proficiency that gives them +1 to their attack rolls; considered magical
19
+ KnuckleheadsGame::Treasure.new(:rare_armor, 400.0),
20
+ # armor of the person's proficiency that gives them +2 to their AC
21
+ KnuckleheadsGame::Treasure.new(:rare_weapon, 400.0)
22
+ # weapon of the person's proficiency that gives them +2 to their attack rolls; considered magical
23
+ ]
24
+
25
+ def self.random
26
+ TREASURES.sample
27
+ end
28
+
29
+ if __FILE__ == $0
30
+ puts KnuckleheadsGame::TreasureTrove::TREASURES
31
+ puts TREASURES.sample
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,33 @@
1
+ require 'knuckleheads/berserker_player'
2
+ require 'knuckleheads/player'
3
+
4
+ module KnuckleheadsGame
5
+
6
+ describe BerserkerPlayer do
7
+
8
+ before do
9
+ @initial_health = 50
10
+ @player = KnuckleheadsGame::BerserkerPlayer.new("berserker", @initial_health)
11
+ end
12
+
13
+ it "does not go bersek when w00ted up to 5 times" do
14
+ 1.upto(5) { @player.w00t }
15
+
16
+ @player.berserk?.should be_falsey
17
+ end
18
+
19
+ it "goes berserk when w00ted more than 5 times" do
20
+ 1.upto(6) { @player.w00t }
21
+
22
+ @player.berserk?.should be_truthy
23
+ end
24
+
25
+ it "gets w00ted instead of blammed when it's gone berserk" do
26
+ 1.upto(6) { @player.w00t }
27
+ 1.upto(2) { @player.blam }
28
+
29
+ @player.health.should == @initial_health + (8 * 15)
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,38 @@
1
+ require 'knuckleheads/player'
2
+ require 'knuckleheads/treasure_trove'
3
+ require 'knuckleheads/clumsy_player'
4
+
5
+ module KnuckleheadsGame
6
+
7
+ describe ClumsyPlayer do
8
+
9
+ before do
10
+ @player = KnuckleheadsGame::ClumsyPlayer.new("klutz")
11
+ end
12
+
13
+ it "only gets half the point value of each treasure" do
14
+ @player.points.should == 0
15
+
16
+ # potion = Treasure.new(:potion, 50)
17
+ # @player.found_treasures(potion)
18
+ # @player.found_treasures(potion)
19
+ # @player.found_treasures(potion)
20
+
21
+ # @player.points.should == 75
22
+
23
+ strange_weapon = KnuckleheadsGame::Treasure.new(:strange_weapon, 200.0)
24
+ @player.found_treasures(strange_weapon)
25
+ @player.found_treasures(strange_weapon)
26
+
27
+ @player.points.should == 200.0
28
+
29
+ yielded = []
30
+ @player.each_found_treasure do |treasure|
31
+ yielded << treasure
32
+ end
33
+
34
+ yielded.should == [KnuckleheadsGame::Treasure.new(:strange_weapon, 200.0)]
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,83 @@
1
+ require 'knuckleheads/game'
2
+ require 'knuckleheads/player'
3
+ require 'knuckleheads/die'
4
+
5
+ module KnuckleheadsGame
6
+
7
+ describe Game do
8
+ before do
9
+ @game = KnuckleheadsGame::Game.new("knuckleheads")
10
+
11
+ @initial_health1 = 100
12
+ @initial_health2 = 60
13
+ @initial_health3 = 125
14
+ @initial_health4 = 90
15
+
16
+ player1 = KnuckleheadsGame::Player.new("moore", @initial_health1)
17
+ player2 = KnuckleheadsGame::Player.new("larry", @initial_health2)
18
+ player3 = KnuckleheadsGame::Player.new("curly", @initial_health3)
19
+ player4 = KnuckleheadsGame::Player.new("shemp", @initial_health4)
20
+
21
+ @game.add_player(player1)
22
+ @game.add_player(player2)
23
+ @game.add_player(player3)
24
+ @game.add_player(player4)
25
+ end
26
+
27
+ it "has a capitalized title" do
28
+ knuckleheads = KnuckleheadsGame::Game.new("knuckleheads")
29
+
30
+ knuckleheads.title.should == "Knuckleheads"
31
+ end
32
+
33
+ it "has a string representation" do
34
+ @game.players[0].to_s.should == "I'm Moore with a health of 100; my score is 100, and my treasure value is 0.\n\t"
35
+ @game.players[1].to_s.should == "I'm Larry with a health of 60; my score is 60, and my treasure value is 0.\n\t"
36
+ @game.players[2].to_s.should == "I'm Curly with a health of 125; my score is 125, and my treasure value is 0.\n\t"
37
+ @game.players[3].to_s.should == "I'm Shemp with a health of 90; my score is 90, and my treasure value is 0.\n\t"
38
+ end
39
+
40
+ it "w00ts the player if a high number is rolled" do
41
+ Die.any_instance.stub(:roll).and_return(5)
42
+
43
+ @game.play(3)
44
+
45
+ @game.players[0].health.should == @initial_health1 + (15 * 3)
46
+ @game.players[1].health.should == @initial_health2 + (15 * 3)
47
+ @game.players[2].health.should == @initial_health3 + (15 * 3)
48
+ @game.players[3].health.should == @initial_health4 + (15 * 3)
49
+ end
50
+
51
+ it "skips the player if a medium number is rolled" do
52
+ Die.any_instance.stub(:roll).and_return(3)
53
+
54
+ @game.play(3)
55
+
56
+ @game.players[0].health.should == @initial_health1
57
+ @game.players[1].health.should == @initial_health2
58
+ @game.players[2].health.should == @initial_health3
59
+ @game.players[3].health.should == @initial_health4
60
+ end
61
+
62
+ it "blams the player if a low number is rolled" do
63
+ Die.any_instance.stub(:roll).and_return(1)
64
+
65
+ @game.play(3)
66
+
67
+ @game.players[0].health.should == @initial_health1 - (10 * 3)
68
+ @game.players[1].health.should == @initial_health2 - (10 * 3)
69
+ @game.players[2].health.should == @initial_health3 - (10 * 3)
70
+ @game.players[3].health.should == @initial_health4 - (10 * 3)
71
+ end
72
+
73
+ it "assigns a treasure for points during a player's turn" do
74
+ game = KnuckleheadsGame::Game.new("Knuckleheads")
75
+ player1 = KnuckleheadsGame::Player.new("moore", @initial_health1)
76
+
77
+ game.add_player(player1)
78
+ game.play(1)
79
+
80
+ player1.points.should_not be_zero
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,154 @@
1
+ require 'knuckleheads/player'
2
+ require 'knuckleheads/game'
3
+ require 'knuckleheads/game_turn_module'
4
+ require 'knuckleheads/die'
5
+ require 'knuckleheads/treasure_trove'
6
+
7
+ module KnuckleheadsGame
8
+
9
+ describe Player do
10
+
11
+ before do
12
+ @initial_health1 = 100
13
+ @initial_health2 = 60
14
+ @initial_health3 = 125
15
+ @initial_health4 = 90
16
+ end
17
+
18
+ it "has capitalized name" do
19
+ player1 = KnuckleheadsGame::Player.new("moore", 100)
20
+ player2 = KnuckleheadsGame::Player.new("larry", 60)
21
+ player3 = KnuckleheadsGame::Player.new("curly", 125)
22
+ player4 = KnuckleheadsGame::Player.new("shemp", 90)
23
+
24
+ player1.name.should == "Moore"
25
+ player2.name.should == "Larry"
26
+ player3.name.should == "Curly"
27
+ player4.name.should == "Shemp"
28
+ end
29
+
30
+ it "has a health value of" do
31
+ player1 = KnuckleheadsGame::Player.new("moore", 100)
32
+ player2 = KnuckleheadsGame::Player.new("larry", 60)
33
+ player3 = KnuckleheadsGame::Player.new("curly", 125)
34
+ player4 = KnuckleheadsGame::Player.new("shemp", 90)
35
+
36
+ player1.health.should == 100
37
+ player2.health.should == 60
38
+ player3.health.should == 125
39
+ player4.health.should == 90
40
+ end
41
+
42
+ it "computes a score as the sum of its health and points" do
43
+ player1 = KnuckleheadsGame::Player.new("moore", @initial_health1)
44
+
45
+ player1.found_treasures(KnuckleheadsGame::Treasure.new(:bow, 25))
46
+
47
+ player1.score.should == (@initial_health1 + 25)
48
+ end
49
+
50
+ it "computes points as the sum of all treasure points" do
51
+ player1 = KnuckleheadsGame::Player.new("moore", @initial_health1)
52
+ player1.found_treasures(KnuckleheadsGame::Treasure.new(:ration, 5))
53
+ player1.points.should == 5
54
+
55
+ player1.found_treasures(KnuckleheadsGame::Treasure.new(:bow, 25))
56
+ player1.points.should == 30
57
+
58
+ player1.found_treasures(Treasure.new(:gemstone, 100))
59
+ player1.points.should == 130
60
+
61
+ end
62
+
63
+ it "increases health by 15 when w00ted" do
64
+ player1 = KnuckleheadsGame::Player.new("moore", @initial_health1)
65
+ player1.w00t
66
+
67
+ player2 = KnuckleheadsGame::Player.new("larry", @initial_health2)
68
+ player2.w00t
69
+
70
+ player3 = KnuckleheadsGame::Player.new("curly", @initial_health3)
71
+ player3.w00t
72
+
73
+ player4 = KnuckleheadsGame::Player.new("shemp", @initial_health4)
74
+ player4.w00t
75
+
76
+ player1.health.should == @initial_health1 + 15
77
+ player2.health.should == @initial_health2 + 15
78
+ player3.health.should == @initial_health3 + 15
79
+ player4.health.should == @initial_health4 + 15
80
+ end
81
+
82
+ it "decreases health by 10 when w00ted" do
83
+ player1 = KnuckleheadsGame::Player.new("moore", @initial_health1)
84
+ player1.blam
85
+
86
+ player2 = KnuckleheadsGame::Player.new("larry", @initial_health2)
87
+ player2.blam
88
+
89
+ player3 = KnuckleheadsGame::Player.new("curly", @initial_health3)
90
+ player3.blam
91
+
92
+ player4 = KnuckleheadsGame::Player.new("shemp", @initial_health4)
93
+ player4.blam
94
+
95
+ player1.health.should == @initial_health1 - 10
96
+ player2.health.should == @initial_health2 - 10
97
+ player3.health.should == @initial_health3 - 10
98
+ player4.health.should == @initial_health4 - 10
99
+ end
100
+
101
+ it "yields each found treasure and its total points" do
102
+ player1 = KnuckleheadsGame::Player.new("moore", @initial_health1)
103
+
104
+ player1.found_treasures(KnuckleheadsGame::Treasure.new(:gemstone, 100))
105
+ player1.found_treasures(KnuckleheadsGame::Treasure.new(:gemstone, 100))
106
+ player1.found_treasures(KnuckleheadsGame::Treasure.new(:potion, 50))
107
+ player1.found_treasures(KnuckleheadsGame::Treasure.new(:ration, 5))
108
+ player1.found_treasures(KnuckleheadsGame::Treasure.new(:ration, 5))
109
+ player1.found_treasures(KnuckleheadsGame::Treasure.new(:ration, 5))
110
+ player1.found_treasures(KnuckleheadsGame::Treasure.new(:ration, 5))
111
+ player1.found_treasures(KnuckleheadsGame::Treasure.new(:ration, 5))
112
+
113
+ yielded = []
114
+ player1.each_found_treasure do |treasure|
115
+ yielded << treasure
116
+ end
117
+
118
+ yielded.should == [
119
+ KnuckleheadsGame::Treasure.new(:gemstone, 200),
120
+ KnuckleheadsGame::Treasure.new(:potion, 50),
121
+ KnuckleheadsGame::Treasure.new(:ration, 25)
122
+ ]
123
+ end
124
+
125
+ it "can be created from a CSV string" do
126
+ player = KnuckleheadsGame::Player.from_csv("moore,100")
127
+
128
+ player.name.should == "Moore"
129
+ player.health.should == 100
130
+ end
131
+
132
+ context "with a health greater than 100" do
133
+ before do
134
+ @player = KnuckleheadsGame::Player.new("curly", @initial_health3)
135
+ end
136
+
137
+ it "is strong" do
138
+ @player.should be_strong
139
+ end
140
+ end
141
+
142
+ context "with a health of 100 or less" do
143
+ before do
144
+ @player = KnuckleheadsGame::Player.new("moore", @initial_health1)
145
+ @player = KnuckleheadsGame::Player.new("larry", @initial_health2)
146
+ @player = KnuckleheadsGame::Player.new("shemp", @initial_health4)
147
+ end
148
+
149
+ it "is wimpy" do
150
+ @player.should_not be_strong
151
+ end
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,93 @@
1
+ require 'knuckleheads/treasure_trove'
2
+
3
+ module KnuckleheadsGame
4
+
5
+ describe Treasure do
6
+
7
+ before do
8
+ @treasure1 = KnuckleheadsGame::Treasure.new(:ration, 5.0)
9
+ @treasure2 = KnuckleheadsGame::Treasure.new(:bow, 25.0)
10
+ @treasure3 = KnuckleheadsGame::Treasure.new(:potion, 50.0)
11
+ @treasure4 = KnuckleheadsGame::Treasure.new(:gemstone, 100.0)
12
+ @treasure5 = KnuckleheadsGame::Treasure.new(:strange_armor, 200.0)
13
+ @treasure6 = KnuckleheadsGame::Treasure.new(:strange_weapon, 200.0)
14
+ @treasure7 = KnuckleheadsGame::Treasure.new(:rare_armor, 400.0)
15
+ @treasure8 = KnuckleheadsGame::Treasure.new(:rare_weapon, 400.0)
16
+ end
17
+
18
+ it "has a name attribute" do
19
+ @treasure1.name.should == :ration
20
+ @treasure2.name.should == :bow
21
+ @treasure3.name.should == :potion
22
+ @treasure4.name.should == :gemstone
23
+ @treasure5.name.should == :strange_armor
24
+ @treasure6.name.should == :strange_weapon
25
+ @treasure7.name.should == :rare_armor
26
+ @treasure8.name.should == :rare_weapon
27
+ end
28
+
29
+ it "has a value attribute" do
30
+ @treasure1.points.should == 5.0
31
+ @treasure2.points.should == 25.0
32
+ @treasure3.points.should == 50.0
33
+ @treasure4.points.should == 100.0
34
+ @treasure5.points.should == 200.0
35
+ @treasure6.points.should == 200.0
36
+ @treasure7.points.should == 400.0
37
+ @treasure8.points.should == 400.0
38
+ end
39
+ end
40
+
41
+ describe TreasureTrove do
42
+
43
+ it "has eight treasures" do
44
+ TreasureTrove::TREASURES.size.should == 8
45
+ end
46
+
47
+ it "has a ration, with a 5 value" do
48
+ TreasureTrove::TREASURES[0].should == KnuckleheadsGame::Treasure.new(:ration, 5.0)
49
+ # rations are 5sp; 10sp = 1gp, so 10 rations are 5g
50
+ end
51
+
52
+ it "has a ranged weapon, with a 25 value" do
53
+ TreasureTrove::TREASURES[1].should == KnuckleheadsGame::Treasure.new(:bow, 25.0)
54
+ # simple ranged weapon of the person's proficiency (crossbow or shortbow); 25 gp
55
+ end
56
+
57
+ it "has a health potion, with a 50 value" do
58
+ TreasureTrove::TREASURES[2].should == KnuckleheadsGame::Treasure.new(:potion, 50.0)
59
+ # 1 potion of health = 50gp
60
+ end
61
+
62
+ it "has a gemstone, with a 100 value" do
63
+ TreasureTrove::TREASURES[3].should == KnuckleheadsGame::Treasure.new(:gemstone, 100.0)
64
+ # one of the 100gp gemstones is here as a reward: amber, amethyst, chrysoberyl, coral, garnet, jade, jet, pearl, spinel, tourmaline
65
+ end
66
+
67
+ it "has a +1 armor, with a 200 value" do
68
+ TreasureTrove::TREASURES[4].should == KnuckleheadsGame::Treasure.new(:strange_armor, 200.0)
69
+ # armor of the person's proficiency that gives them +1 to their AC; 200 gp
70
+ end
71
+
72
+ it "has a +1 weapon, with a 200 value" do
73
+ TreasureTrove::TREASURES[5].should == KnuckleheadsGame::Treasure.new(:strange_weapon, 200.0)
74
+ # weapon of the person's proficiency that gives them +1 to their attack rolls; considered magical; 200 gp
75
+ end
76
+
77
+ it "has a +2 armor, with a 400 value" do
78
+ TreasureTrove::TREASURES[6].should == KnuckleheadsGame::Treasure.new(:rare_armor, 400.0)
79
+ # armor of the person's proficiency that gives them +2 to their AC; 400 gp
80
+ end
81
+
82
+ it "has a +2 weapon worth 400 gp" do
83
+ TreasureTrove::TREASURES[7].should == KnuckleheadsGame::Treasure.new(:rare_weapon, 400.0)
84
+ # weapon of the person's proficiency that gives them +2 to their attack rolls; considered magical; 400 gp
85
+ end
86
+
87
+ it "returns a random treasure" do
88
+ treasure = TreasureTrove.random
89
+
90
+ TreasureTrove::TREASURES.should include(treasure)
91
+ end
92
+ end
93
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knuckleheads_the_ones_doomed_to_fail
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kylie Camp
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-08-06 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: 2.8.0
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.8'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 2.8.0
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.8'
33
+ description: Cute, fun game with some nerds to play! :)
34
+ email: chiixil.84@gmail.com
35
+ executables:
36
+ - knuckleheads
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - LICENSE.txt
41
+ - README.txt
42
+ - bin/knuckleheads
43
+ - bin/players.csv
44
+ - lib/knuckleheads/auditable.rb
45
+ - lib/knuckleheads/berserker_player.rb
46
+ - lib/knuckleheads/clumsy_player.rb
47
+ - lib/knuckleheads/die.rb
48
+ - lib/knuckleheads/game.rb
49
+ - lib/knuckleheads/game_turn_module.rb
50
+ - lib/knuckleheads/loaded_die.rb
51
+ - lib/knuckleheads/playable.rb
52
+ - lib/knuckleheads/player.rb
53
+ - lib/knuckleheads/treasure_trove.rb
54
+ - spec/knuckleheads/berserker_player_spec.rb
55
+ - spec/knuckleheads/clumsy_player_spec.rb
56
+ - spec/knuckleheads/game_spec.rb
57
+ - spec/knuckleheads/player_spec.rb
58
+ - spec/knuckleheads/treasure_trove_spec.rb
59
+ homepage: https://github.com/roastpotential
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '1.9'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubygems_version: 3.0.3
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Cute, fun game with some nerds to play! :)
82
+ test_files:
83
+ - spec/knuckleheads/berserker_player_spec.rb
84
+ - spec/knuckleheads/clumsy_player_spec.rb
85
+ - spec/knuckleheads/game_spec.rb
86
+ - spec/knuckleheads/player_spec.rb
87
+ - spec/knuckleheads/treasure_trove_spec.rb