Studio_game_KAS 1.01
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.
- data/LICENSE +0 -0
- data/README +0 -0
- data/bin/high_scores.txt +7 -0
- data/bin/playerbank.cvs +4 -0
- data/bin/special_hi_play.cvs +3 -0
- data/bin/studio_game +35 -0
- data/lib/high_scores.txt +6 -0
- data/lib/studio_game/auditable.rb +9 -0
- data/lib/studio_game/berserk_player.rb +37 -0
- data/lib/studio_game/clumsy_player.rb +38 -0
- data/lib/studio_game/die.rb +21 -0
- data/lib/studio_game/game.rb +94 -0
- data/lib/studio_game/game_turn.rb +28 -0
- data/lib/studio_game/input_players.rb +0 -0
- data/lib/studio_game/iterator.rb +127 -0
- data/lib/studio_game/loaded_die.rb +17 -0
- data/lib/studio_game/playable.rb +17 -0
- data/lib/studio_game/player.rb +82 -0
- data/lib/studio_game/swagbag.rb +68 -0
- data/spec/studio_game/berserk_player_spec.rb +31 -0
- data/spec/studio_game/clumsy_player_spec.rb +33 -0
- data/spec/studio_game/game_spec.rb +46 -0
- data/spec/studio_game/player_spec.rb +29 -0
- metadata +88 -0
data/LICENSE
ADDED
|
File without changes
|
data/README
ADDED
|
File without changes
|
data/bin/high_scores.txt
ADDED
data/bin/playerbank.cvs
ADDED
data/bin/studio_game
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require_relative '../lib/studio_game/game.rb'
|
|
4
|
+
require_relative '../lib/studio_game/clumsy_player'
|
|
5
|
+
require_relative '../lib/studio_game/berserk_player'
|
|
6
|
+
|
|
7
|
+
knuckleheads = StudioGame::Game.new("Cheap THrills")
|
|
8
|
+
|
|
9
|
+
default_player_file =
|
|
10
|
+
File.join(File.dirname(__FILE__),'playerbank.cvs' )
|
|
11
|
+
knuckleheads.load_players(ARGV.shift || default_player_file)
|
|
12
|
+
|
|
13
|
+
klutz = StudioGame::ClumsyPlayer.new "Klutz", 105
|
|
14
|
+
knuckleheads.add_player(klutz)
|
|
15
|
+
|
|
16
|
+
berserker = StudioGame::BerserkPlayer.new("berserker", 50)
|
|
17
|
+
knuckleheads.add_player(berserker)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
loop do
|
|
21
|
+
puts "\nHow many turns?('quit' to exit)"
|
|
22
|
+
input = gets.chomp.downcase
|
|
23
|
+
case input
|
|
24
|
+
when /^\d+$/
|
|
25
|
+
knuckleheads.play(input.to_i)
|
|
26
|
+
when input = 'quit','exit'
|
|
27
|
+
knuckleheads.print_status
|
|
28
|
+
break
|
|
29
|
+
else
|
|
30
|
+
puts "please enter a numer or 'quit'"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
knuckleheads.print_status.sort
|
|
35
|
+
knuckleheads.save_high_scores
|
data/lib/high_scores.txt
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require_relative 'player'
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
4
|
+
|
|
5
|
+
class BerserkPlayer < Player
|
|
6
|
+
def initialize(name, health=100)
|
|
7
|
+
super(name, health)
|
|
8
|
+
@w00t_count = 0
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def berserk?
|
|
12
|
+
@w00t_count > 5
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def w00ted
|
|
16
|
+
super
|
|
17
|
+
@w00t_count +=1
|
|
18
|
+
puts "#{@name} is berserk!" if berserk?
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def blam
|
|
22
|
+
if berserk?
|
|
23
|
+
w00ted
|
|
24
|
+
else
|
|
25
|
+
super
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
if __FILE__ == $0
|
|
31
|
+
berserker = BerserkPlayer.new("berserker", 50)
|
|
32
|
+
6.times { berserker.w00ted }
|
|
33
|
+
2.times { berserker.blam }
|
|
34
|
+
puts berserker.health
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
|
|
2
|
+
require_relative 'player'
|
|
3
|
+
|
|
4
|
+
module StudioGame
|
|
5
|
+
|
|
6
|
+
class ClumsyPlayer < Player
|
|
7
|
+
attr_reader :boost_factor
|
|
8
|
+
def initialize (name, health=100, boost_factor=1)
|
|
9
|
+
super(name,health)
|
|
10
|
+
@boost_factor = boost_factor
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def found_treasure(treasure)
|
|
14
|
+
damaged_treasure = Swag.new(treasure.name, treasure.points / 2)
|
|
15
|
+
super(damaged_treasure)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def w00ted
|
|
19
|
+
@boost_factor.times {super}
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
if __FILE__ == $0
|
|
24
|
+
clumsy = ClumsyPlayer.new("klutz")
|
|
25
|
+
hammer = Swag.new(:hammer, 50)
|
|
26
|
+
clumsy.found_treasure(hammer)
|
|
27
|
+
clumsy.found_treasure(hammer)
|
|
28
|
+
clumsy.found_treasure(hammer)
|
|
29
|
+
|
|
30
|
+
crowbar = Swag.new(:crowbar, 400)
|
|
31
|
+
clumsy.found_treasure(crowbar)
|
|
32
|
+
|
|
33
|
+
clumsy.each_found_treasure do |treasure|
|
|
34
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
|
35
|
+
end
|
|
36
|
+
puts "#{clumsy.points} grand total points"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
require_relative 'player'
|
|
2
|
+
require_relative 'die'
|
|
3
|
+
require_relative 'swagbag'
|
|
4
|
+
require_relative 'game_turn'
|
|
5
|
+
require 'csv'
|
|
6
|
+
|
|
7
|
+
module StudioGame
|
|
8
|
+
|
|
9
|
+
class Game
|
|
10
|
+
attr_reader :game
|
|
11
|
+
|
|
12
|
+
def initialize game
|
|
13
|
+
@game = game
|
|
14
|
+
@players = []
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def add_player a_player
|
|
18
|
+
@players.push(a_player)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def load_players(from_file)
|
|
22
|
+
File.foreach(from_file) do |line|
|
|
23
|
+
add_player(Player.from_csv(line))
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def play (turn)
|
|
28
|
+
puts "There are #{@players.size} players in #{@game}:\n"
|
|
29
|
+
puts @players.sort
|
|
30
|
+
|
|
31
|
+
swag = SwagBag::SWAGS
|
|
32
|
+
puts " \n THere are #{swag.size} pieces of Swag here."
|
|
33
|
+
swag.each do |swag|
|
|
34
|
+
puts "#{swag.name} has #{swag.points} value"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# figure out how to add up all the points for swag box
|
|
38
|
+
1.upto(turn) do |count|
|
|
39
|
+
puts "\nTurn number #{count}:"
|
|
40
|
+
@players.each do |player|
|
|
41
|
+
GameTurn.take_turn(player)
|
|
42
|
+
treat = SwagBag.random
|
|
43
|
+
puts "#{player.name} got a #{treat.name} worth $#{treat.points}"
|
|
44
|
+
# puts player
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def total_points
|
|
50
|
+
@players.reduce(0) { |sum, player| sum + player.points}
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def high_score_entry(player)
|
|
54
|
+
formatted_name = player.name.ljust(20, '.')
|
|
55
|
+
"#{player.name},total #{player.points} "
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def print_status
|
|
59
|
+
weak, strong = @players.partition { |player| player.strong?}
|
|
60
|
+
|
|
61
|
+
puts "\nWeak:"
|
|
62
|
+
puts weak.sort
|
|
63
|
+
|
|
64
|
+
puts "\nStrong:"
|
|
65
|
+
puts strong.sort
|
|
66
|
+
|
|
67
|
+
puts "\n$#{total_points} of swag."
|
|
68
|
+
sorted_players = @players.sort
|
|
69
|
+
|
|
70
|
+
puts "\n#{@title} High Scores:"
|
|
71
|
+
@players.sort.each do |player|
|
|
72
|
+
puts high_score_entry(player)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def save_high_scores(to_file = "high_scores.txt")
|
|
76
|
+
File.open(to_file, "w") do |file|
|
|
77
|
+
file.puts "#{@title} High Scores:"
|
|
78
|
+
@players.sort.each do |player|
|
|
79
|
+
file.puts high_score_entry(player)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
puts "\n#{@game} High Score Winner: "
|
|
85
|
+
sorted_players.each do |player|
|
|
86
|
+
puts "\n#{player.name}'s point totals:"
|
|
87
|
+
player.each_found_treasure do |treasure|
|
|
88
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
|
89
|
+
end
|
|
90
|
+
puts "#{player.points} grand total points."
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require_relative 'die'
|
|
2
|
+
require_relative 'player'
|
|
3
|
+
require_relative 'loaded_die'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
module StudioGame
|
|
7
|
+
|
|
8
|
+
module GameTurn
|
|
9
|
+
|
|
10
|
+
def self.take_turn player
|
|
11
|
+
@player = player
|
|
12
|
+
die = LoadedDie.new
|
|
13
|
+
case die.roll
|
|
14
|
+
when 1..2
|
|
15
|
+
player.blam
|
|
16
|
+
puts "#{@player}"
|
|
17
|
+
when 3..4
|
|
18
|
+
puts "#{@player} was skipped"
|
|
19
|
+
else
|
|
20
|
+
player.w00ted
|
|
21
|
+
puts "#{@player}"
|
|
22
|
+
end
|
|
23
|
+
treasure = SwagBag.random
|
|
24
|
+
player.found_treasure(treasure)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
#
|
|
10
|
+
# def palindrome?(string)
|
|
11
|
+
# 1 = 1 + 1
|
|
12
|
+
# end
|
|
13
|
+
#
|
|
14
|
+
# puts palindrome?("dsfgfdg")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# def
|
|
18
|
+
|
|
19
|
+
#
|
|
20
|
+
# def five_times
|
|
21
|
+
# 1.upto(2) do |count|
|
|
22
|
+
# yield (count)
|
|
23
|
+
# end
|
|
24
|
+
# end
|
|
25
|
+
#
|
|
26
|
+
# def n_times(number)
|
|
27
|
+
# 1.upto(number) do |count|
|
|
28
|
+
# yield count
|
|
29
|
+
# end
|
|
30
|
+
# end
|
|
31
|
+
#
|
|
32
|
+
#
|
|
33
|
+
# # five_times do |n|
|
|
34
|
+
# # puts "#{n} situps"
|
|
35
|
+
# # puts "#{n} pushups"
|
|
36
|
+
# # puts "#{n} chinups"
|
|
37
|
+
# # end
|
|
38
|
+
#
|
|
39
|
+
# n_times(2) do |n|
|
|
40
|
+
# puts "#{n} new situps"
|
|
41
|
+
# puts "#{n} pushups"
|
|
42
|
+
# puts "#{n} chinups"
|
|
43
|
+
# end
|
|
44
|
+
#
|
|
45
|
+
# def simple
|
|
46
|
+
# puts 'Here comes the code block!'
|
|
47
|
+
# yield
|
|
48
|
+
# puts 'There was the code block!'
|
|
49
|
+
# end
|
|
50
|
+
#
|
|
51
|
+
# simple { puts 'This called with a yield' }
|
|
52
|
+
#
|
|
53
|
+
# class Talker
|
|
54
|
+
#
|
|
55
|
+
# def talk
|
|
56
|
+
# @x = 2
|
|
57
|
+
# puts " x is #{@x} wtf"
|
|
58
|
+
# end
|
|
59
|
+
# end
|
|
60
|
+
# t = Talker.new
|
|
61
|
+
# t.talk
|
|
62
|
+
|
|
63
|
+
# t.ancestors
|
|
64
|
+
#
|
|
65
|
+
# puts t
|
|
66
|
+
# t.acestors
|
|
67
|
+
# class Best
|
|
68
|
+
# puts " trying something"
|
|
69
|
+
# end
|
|
70
|
+
#
|
|
71
|
+
# x = Best.new
|
|
72
|
+
#
|
|
73
|
+
# puts x
|
|
74
|
+
|
|
75
|
+
# class C
|
|
76
|
+
# def talk
|
|
77
|
+
# puts " HI !"
|
|
78
|
+
# end
|
|
79
|
+
# end
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
#
|
|
83
|
+
# class C
|
|
84
|
+
# puts " hi!"
|
|
85
|
+
# end
|
|
86
|
+
#
|
|
87
|
+
# class C
|
|
88
|
+
# puts self
|
|
89
|
+
# end
|
|
90
|
+
#
|
|
91
|
+
# obj = Object.new
|
|
92
|
+
# class << obj
|
|
93
|
+
# self
|
|
94
|
+
# end
|
|
95
|
+
#
|
|
96
|
+
# puts obj
|
|
97
|
+
#
|
|
98
|
+
#
|
|
99
|
+
#
|
|
100
|
+
# class Person
|
|
101
|
+
# attr_accessor :name
|
|
102
|
+
# end
|
|
103
|
+
#
|
|
104
|
+
# d = Person.new
|
|
105
|
+
# d.name = " Daren"
|
|
106
|
+
# @name = " Bill"
|
|
107
|
+
# puts d.name
|
|
108
|
+
# d.instance_eval { puts @name }
|
|
109
|
+
#
|
|
110
|
+
# def palindrome
|
|
111
|
+
# puts "tring"
|
|
112
|
+
# yield
|
|
113
|
+
# end
|
|
114
|
+
|
|
115
|
+
# str1 = "A man, a plan, a canal -- Panama"
|
|
116
|
+
#
|
|
117
|
+
# str1.palindrome?("A man, a plan, a canal -- Panama")
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
|
|
2
|
+
require_relative 'game_turn'
|
|
3
|
+
require_relative 'swagbag'
|
|
4
|
+
require_relative 'playable'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
module StudioGame
|
|
8
|
+
|
|
9
|
+
class Player
|
|
10
|
+
include Playable
|
|
11
|
+
attr_accessor :name,:score,:health
|
|
12
|
+
attr_reader
|
|
13
|
+
|
|
14
|
+
def initialize name ,health=50,score =0
|
|
15
|
+
# def initialize name ,health = rand(180...300) ,score = 0
|
|
16
|
+
@name = name.capitalize
|
|
17
|
+
@health = health
|
|
18
|
+
@score = score
|
|
19
|
+
@found_treasure = Hash.new(0)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# I had to create instance variables( @name , @health) to pass variables
|
|
23
|
+
# to the status method inside this player class
|
|
24
|
+
|
|
25
|
+
def to_s # player status
|
|
26
|
+
"#{@name}'s current score = #{score}"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def say_hello
|
|
30
|
+
"I'm #{@name.capitalize} with a health of #{@health}"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def <=>(the_other)
|
|
34
|
+
the_other.score <=> score
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def points
|
|
38
|
+
@found_treasure.values.reduce(0,:+)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def score
|
|
42
|
+
points + @health
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def found_treasure(treasure)
|
|
46
|
+
@found_treasure[treasure.name] += treasure.points
|
|
47
|
+
puts "#{@name} got #{treasure.name} worth #{treasure.points}."
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# puts "#{@name}'s swag: #{@found_treasure}"
|
|
51
|
+
# treasure = SwagBag.random
|
|
52
|
+
# player.found_treasure(treasure)
|
|
53
|
+
|
|
54
|
+
# def each_found_treasure
|
|
55
|
+
# @found_treasures.each do |name, points|
|
|
56
|
+
# yield Treasure.new(name, points)
|
|
57
|
+
# end
|
|
58
|
+
|
|
59
|
+
def each_found_treasure
|
|
60
|
+
@found_treasure.each do |name, points|
|
|
61
|
+
treasure = Swag.new(name, points)
|
|
62
|
+
yield treasure
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def self.from_csv(string)
|
|
67
|
+
name, health = string.split(',')
|
|
68
|
+
new(name, Integer(health))
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
if __FILE__ == $0
|
|
73
|
+
player = Player.new("moe")
|
|
74
|
+
puts player.name
|
|
75
|
+
puts player.health
|
|
76
|
+
player.w00ted
|
|
77
|
+
puts player.health
|
|
78
|
+
player.blam
|
|
79
|
+
puts player.health
|
|
80
|
+
# puts player.found_treasure(treasure)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
module StudioGame
|
|
2
|
+
# A Struct is a collection of attributes and saves us
|
|
3
|
+
# from having to write a class
|
|
4
|
+
Swag = Struct.new :name, :points
|
|
5
|
+
|
|
6
|
+
module SwagBag
|
|
7
|
+
SWAGS = [
|
|
8
|
+
Swag.new(:tshirt, 10),
|
|
9
|
+
Swag.new(:watch, 100),
|
|
10
|
+
Swag.new(:keyboard, 50),
|
|
11
|
+
Swag.new(:juices, 20)
|
|
12
|
+
# Swag.new(:hammer, 20)
|
|
13
|
+
# Swag.new(:crowbar, 20)
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
def self.random
|
|
17
|
+
SWAGS.sample
|
|
18
|
+
# this returns a single sample from the Array
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
if __FILE__ == $0
|
|
24
|
+
puts SwagBag::SWAGS
|
|
25
|
+
|
|
26
|
+
swag = SwagBag.random
|
|
27
|
+
|
|
28
|
+
# swag = SWAG.sample
|
|
29
|
+
puts"enjoy a #{swag.name} you greedy bastard, it's worth $#{swag.points}"
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
# This below was just to prove that symbols can be created
|
|
34
|
+
# using structs eliminating the need to create a class
|
|
35
|
+
# specifically for this purpose.
|
|
36
|
+
|
|
37
|
+
# equipment = Swag.new('T-shirt', 20)
|
|
38
|
+
# puts equipment
|
|
39
|
+
# puts equipment.name
|
|
40
|
+
# puts equipment.points
|
|
41
|
+
#
|
|
42
|
+
# money = Swag.new '$5000.00', 5000
|
|
43
|
+
# puts money
|
|
44
|
+
# puts money.name
|
|
45
|
+
# puts money.points
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# 1.upto(5) do |p|
|
|
50
|
+
#
|
|
51
|
+
# puts "kjhkj #{p}"
|
|
52
|
+
# puts "jill#{p}"
|
|
53
|
+
# puts "kill#{p}"
|
|
54
|
+
# end
|
|
55
|
+
|
|
56
|
+
# class Snack
|
|
57
|
+
# attr_reader :name, :carbs
|
|
58
|
+
#
|
|
59
|
+
# def initialize(name, carbs = 0)
|
|
60
|
+
#
|
|
61
|
+
# @name = name
|
|
62
|
+
# @carbs = carbs
|
|
63
|
+
# end
|
|
64
|
+
# def to_s # player status
|
|
65
|
+
# "#{@name}, #{@carbs} "
|
|
66
|
+
# end
|
|
67
|
+
# end
|
|
68
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module StudioGame
|
|
2
|
+
|
|
3
|
+
require 'studio_game/berserk_player'
|
|
4
|
+
|
|
5
|
+
describe BerserkPlayer do
|
|
6
|
+
|
|
7
|
+
before do
|
|
8
|
+
@initial_health = 50
|
|
9
|
+
@player = BerserkPlayer.new("berserker", @initial_health)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "does not go berserk when w00ted up to 5 times" do
|
|
13
|
+
1.upto(5) { @player.w00ted }
|
|
14
|
+
|
|
15
|
+
@player.berserk?.should be_false
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "goes berserk when w00ted more than 5 times" do
|
|
19
|
+
1.upto(6) { @player.w00ted }
|
|
20
|
+
|
|
21
|
+
@player.berserk?.should be_true
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "gets w00ted instead of blammed when it's gone berserk" do
|
|
25
|
+
1.upto(6) { @player.w00ted }
|
|
26
|
+
1.upto(2) { @player.blam }
|
|
27
|
+
puts @initial_health
|
|
28
|
+
@player.health.should == @initial_health + (8 * 15)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module StudioGame
|
|
2
|
+
|
|
3
|
+
require 'studio_game/clumsy_player'
|
|
4
|
+
|
|
5
|
+
describe ClumsyPlayer do
|
|
6
|
+
before do
|
|
7
|
+
@player = ClumsyPlayer.new("klutz")
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "only gets half the point value for each treasure" do
|
|
11
|
+
@player.points.should == 0
|
|
12
|
+
|
|
13
|
+
hammer = Swag.new(:hammer, 50)
|
|
14
|
+
@player.found_treasure(hammer)
|
|
15
|
+
@player.found_treasure(hammer)
|
|
16
|
+
@player.found_treasure(hammer)
|
|
17
|
+
|
|
18
|
+
@player.points.should == 75
|
|
19
|
+
|
|
20
|
+
crowbar = Swag.new(:crowbar, 400)
|
|
21
|
+
@player.found_treasure(crowbar)
|
|
22
|
+
|
|
23
|
+
@player.points.should == 275
|
|
24
|
+
|
|
25
|
+
yielded = []
|
|
26
|
+
@player.each_found_treasure do |treasure|
|
|
27
|
+
yielded << treasure
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
yielded.should == [Swag.new(:hammer, 75), Swag.new(:crowbar, 200)]
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module StudioGame
|
|
2
|
+
|
|
3
|
+
require 'studio_game/game'
|
|
4
|
+
# require 'player'
|
|
5
|
+
|
|
6
|
+
describe Game do
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
@game = Game.new("GAME_01_S0N")
|
|
10
|
+
|
|
11
|
+
@initial_health = 50
|
|
12
|
+
@player = Player.new("SMoo", @initial_health)
|
|
13
|
+
|
|
14
|
+
@game.add_player(@player)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "when it rolls high" do
|
|
18
|
+
Die.any_instance.stub(:roll).and_return(6)
|
|
19
|
+
|
|
20
|
+
@game.play(1)
|
|
21
|
+
@player.health.should == @initial_health + 5
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "skips the player when it rolls a medium number" do
|
|
25
|
+
Die.any_instance.stub(:roll).and_return(3)
|
|
26
|
+
|
|
27
|
+
@game.play(1)
|
|
28
|
+
@player.health.should == @initial_health
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
it "when it rolls a low number" do
|
|
33
|
+
Die.any_instance.stub(:roll).and_return(2)
|
|
34
|
+
|
|
35
|
+
@game.play(1)
|
|
36
|
+
@player.health.should == @initial_health - 10
|
|
37
|
+
end
|
|
38
|
+
#
|
|
39
|
+
# it "when it rolls low" do
|
|
40
|
+
# Die.any_instance.stub(:roll).and_return(3)
|
|
41
|
+
#
|
|
42
|
+
# @game.play
|
|
43
|
+
# @player.health.should == (@initial_health - 5)
|
|
44
|
+
# end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module StudioGame
|
|
2
|
+
|
|
3
|
+
require 'studio_game/player'
|
|
4
|
+
|
|
5
|
+
describe Player do
|
|
6
|
+
|
|
7
|
+
context "with a health greater than 100 " do
|
|
8
|
+
before do
|
|
9
|
+
@player = Player.new("Moe", 150)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "is strong" do
|
|
13
|
+
@player.should be_strong
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
context "with a health of 100" do
|
|
17
|
+
before do
|
|
18
|
+
@player = Player.new("Snow", 80)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it " is an average joe" do
|
|
22
|
+
@player.should_not be_strong
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
|
metadata
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: Studio_game_KAS
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: '1.01'
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- KAS
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2012-06-24 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: rspec
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
type: :development
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ! '>='
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '0'
|
|
30
|
+
description: ''
|
|
31
|
+
email: dek1dek@gmail.com
|
|
32
|
+
executables:
|
|
33
|
+
- studio_game
|
|
34
|
+
extensions: []
|
|
35
|
+
extra_rdoc_files: []
|
|
36
|
+
files:
|
|
37
|
+
- bin/high_scores.txt
|
|
38
|
+
- bin/playerbank.cvs
|
|
39
|
+
- bin/special_hi_play.cvs
|
|
40
|
+
- bin/studio_game
|
|
41
|
+
- lib/high_scores.txt
|
|
42
|
+
- lib/studio_game/auditable.rb
|
|
43
|
+
- lib/studio_game/berserk_player.rb
|
|
44
|
+
- lib/studio_game/clumsy_player.rb
|
|
45
|
+
- lib/studio_game/die.rb
|
|
46
|
+
- lib/studio_game/game.rb
|
|
47
|
+
- lib/studio_game/game_turn.rb
|
|
48
|
+
- lib/studio_game/input_players.rb
|
|
49
|
+
- lib/studio_game/iterator.rb
|
|
50
|
+
- lib/studio_game/loaded_die.rb
|
|
51
|
+
- lib/studio_game/playable.rb
|
|
52
|
+
- lib/studio_game/player.rb
|
|
53
|
+
- lib/studio_game/swagbag.rb
|
|
54
|
+
- spec/studio_game/berserk_player_spec.rb
|
|
55
|
+
- spec/studio_game/clumsy_player_spec.rb
|
|
56
|
+
- spec/studio_game/game_spec.rb
|
|
57
|
+
- spec/studio_game/player_spec.rb
|
|
58
|
+
- LICENSE
|
|
59
|
+
- README
|
|
60
|
+
homepage: ''
|
|
61
|
+
licenses: []
|
|
62
|
+
post_install_message:
|
|
63
|
+
rdoc_options: []
|
|
64
|
+
require_paths:
|
|
65
|
+
- lib
|
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
67
|
+
none: false
|
|
68
|
+
requirements:
|
|
69
|
+
- - ! '>='
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
version: '1.9'
|
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
|
+
none: false
|
|
74
|
+
requirements:
|
|
75
|
+
- - ! '>='
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '0'
|
|
78
|
+
requirements: []
|
|
79
|
+
rubyforge_project:
|
|
80
|
+
rubygems_version: 1.8.24
|
|
81
|
+
signing_key:
|
|
82
|
+
specification_version: 3
|
|
83
|
+
summary: first pure Ruby tutorial
|
|
84
|
+
test_files:
|
|
85
|
+
- spec/studio_game/berserk_player_spec.rb
|
|
86
|
+
- spec/studio_game/clumsy_player_spec.rb
|
|
87
|
+
- spec/studio_game/game_spec.rb
|
|
88
|
+
- spec/studio_game/player_spec.rb
|