studio_game_3 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +7 -0
- data/README +1 -0
- data/bin/players.csv +3 -3
- data/bin/studio_game +42 -33
- data/lib/studio_game/auditable.rb +7 -7
- data/lib/studio_game/berserk_player.rb +37 -38
- data/lib/studio_game/clumsy_player.rb +29 -30
- data/lib/studio_game/die.rb +23 -26
- data/lib/studio_game/game.rb +92 -98
- data/lib/studio_game/game_turn.rb +26 -28
- data/lib/studio_game/loaded_die.rb +18 -23
- data/lib/studio_game/playable.rb +16 -33
- data/lib/studio_game/player.rb +79 -59
- data/lib/studio_game/treasure_trove.rb +19 -18
- data/spec/studio_game/berserk_player_spec.rb +33 -0
- data/spec/studio_game/clumsy_player_spec.rb +34 -32
- data/spec/studio_game/game_spec.rb +63 -69
- data/spec/studio_game/player_spec.rb +124 -133
- data/spec/studio_game/treasure_trove_spec.rb +67 -53
- metadata +10 -7
- data/spec/studio_game/beserk_player_spec.rb +0 -29
@@ -1,133 +1,124 @@
|
|
1
|
-
require 'studio_game
|
2
|
-
|
3
|
-
module StudioGame
|
4
|
-
describe Player do
|
5
|
-
before do
|
6
|
-
|
7
|
-
@
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
@player.found_treasure(Treasure.new(:hammer, 50))
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
@player.
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
@player.
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
it "
|
82
|
-
@player.found_treasure(Treasure.new(:
|
83
|
-
@player.found_treasure(Treasure.new(:
|
84
|
-
|
85
|
-
@player.
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
@player.
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
it "can be created from a CSV string" do
|
127
|
-
player = Player.from_csv("larry,150")
|
128
|
-
|
129
|
-
player.name.should == "Larry"
|
130
|
-
player.health.should == 150
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
1
|
+
require 'studio_game\player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
describe Player do
|
5
|
+
before do
|
6
|
+
$stdout = StringIO.new
|
7
|
+
@initial_health = 150
|
8
|
+
@player = Player.new('larry', @initial_health)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "has a capitalized name" do
|
12
|
+
@player.name.should == 'Larry'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "has an initial health" do
|
16
|
+
@player.health.should == @initial_health
|
17
|
+
end
|
18
|
+
|
19
|
+
it "has a string representation" do
|
20
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
21
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
22
|
+
|
23
|
+
@player.to_s.should == "I'm Larry with health = 150, points = 100 and score = 250."
|
24
|
+
end
|
25
|
+
|
26
|
+
it "computes a score as the sum of its health and points" do
|
27
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
28
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
29
|
+
|
30
|
+
@player.score.should == 250
|
31
|
+
end
|
32
|
+
|
33
|
+
it "increases health by 15 when w00ted" do
|
34
|
+
@player.woot
|
35
|
+
|
36
|
+
@player.health.should == @initial_health + 15
|
37
|
+
end
|
38
|
+
|
39
|
+
it "decreases health by 10 when blammed" do
|
40
|
+
@player.blam
|
41
|
+
|
42
|
+
@player.health.should == @initial_health - 10
|
43
|
+
end
|
44
|
+
|
45
|
+
context "with more than 100 health" do
|
46
|
+
before do
|
47
|
+
@player = Player.new('larry', 150)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "is a strong player" do
|
51
|
+
@player.should be_strong
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with 100 health or less" do
|
56
|
+
before do
|
57
|
+
@player = Player.new('larry', 100)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "is a wimpy player" do
|
61
|
+
@player.should_not be_strong
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it "computes points as the sum of all treasure points" do
|
66
|
+
@player.points.should == 0
|
67
|
+
|
68
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
69
|
+
|
70
|
+
@player.points.should == 50
|
71
|
+
|
72
|
+
@player.found_treasure(Treasure.new(:crowbar, 400))
|
73
|
+
|
74
|
+
@player.points.should == 450
|
75
|
+
|
76
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
77
|
+
|
78
|
+
@player.points.should == 500
|
79
|
+
end
|
80
|
+
|
81
|
+
it "yields each found treasure and its total points" do
|
82
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
83
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
84
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
85
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
86
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
87
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
88
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
89
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
90
|
+
|
91
|
+
yielded = []
|
92
|
+
@player.each_found_treasure do |treasure|
|
93
|
+
yielded << treasure
|
94
|
+
end
|
95
|
+
|
96
|
+
yielded.should == [
|
97
|
+
Treasure.new(:skillet, 200),
|
98
|
+
Treasure.new(:hammer, 50),
|
99
|
+
Treasure.new(:bottle, 25)
|
100
|
+
]
|
101
|
+
end
|
102
|
+
|
103
|
+
it "can be created from a csv string" do
|
104
|
+
player = Player.from_csv("larry,150")
|
105
|
+
|
106
|
+
player.name.should == 'Larry'
|
107
|
+
|
108
|
+
player.health.should == 150
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
@@ -1,53 +1,67 @@
|
|
1
|
-
require 'studio_game
|
2
|
-
|
3
|
-
module StudioGame
|
4
|
-
describe Treasure do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
1
|
+
require 'studio_game\treasure_trove'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
describe Treasure do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@treasure = Treasure.new(:hammer, 50)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "has a name attribute" do
|
11
|
+
@treasure.name.should == :hammer
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has a points attribute" do
|
15
|
+
@treasure.points.should == 50
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
describe TreasureTrove do
|
21
|
+
|
22
|
+
it "has six treasures" do
|
23
|
+
TreasureTrove::TREASURES.size.should == 6
|
24
|
+
end
|
25
|
+
|
26
|
+
it "has a pie worth 5 points" do
|
27
|
+
TreasureTrove::TREASURES[0].should == Treasure.new(:pie, 5)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "has a bottle worth 25 points" do
|
31
|
+
TreasureTrove::TREASURES[1].should == Treasure.new(:bottle, 25)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "has a hammer worth 50 points" do
|
35
|
+
TreasureTrove::TREASURES[2].should == Treasure.new(:hammer, 50)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "has a skillet worth 100 points" do
|
39
|
+
TreasureTrove::TREASURES[3].should == Treasure.new(:skillet, 100)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "has a broomstick worth 200 points" do
|
43
|
+
TreasureTrove::TREASURES[4].should == Treasure.new(:broomstick, 200)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "has a crowbar worth 400 points" do
|
47
|
+
TreasureTrove::TREASURES[5].should == Treasure.new(:crowbar, 400)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns a random treasure" do
|
51
|
+
treasure = TreasureTrove.random
|
52
|
+
|
53
|
+
TreasureTrove::TREASURES.should include(treasure)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: studio_game_3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fergus O'Connell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
description:
|
27
|
+
description: 'A simple text-based game from one of Pragmatic Studio''s ruby courses. '
|
28
28
|
email:
|
29
29
|
executables:
|
30
30
|
- studio_game
|
@@ -43,13 +43,16 @@ files:
|
|
43
43
|
- lib/studio_game/playable.rb
|
44
44
|
- lib/studio_game/player.rb
|
45
45
|
- lib/studio_game/treasure_trove.rb
|
46
|
-
- spec/studio_game/
|
46
|
+
- spec/studio_game/berserk_player_spec.rb
|
47
47
|
- spec/studio_game/clumsy_player_spec.rb
|
48
48
|
- spec/studio_game/game_spec.rb
|
49
49
|
- spec/studio_game/player_spec.rb
|
50
50
|
- spec/studio_game/treasure_trove_spec.rb
|
51
|
+
- LICENSE
|
52
|
+
- README
|
51
53
|
homepage:
|
52
|
-
licenses:
|
54
|
+
licenses:
|
55
|
+
- MIT
|
53
56
|
metadata: {}
|
54
57
|
post_install_message:
|
55
58
|
rdoc_options: []
|
@@ -70,9 +73,9 @@ rubyforge_project:
|
|
70
73
|
rubygems_version: 2.0.14
|
71
74
|
signing_key:
|
72
75
|
specification_version: 4
|
73
|
-
summary: A
|
76
|
+
summary: A simple text-based game
|
74
77
|
test_files:
|
75
|
-
- spec/studio_game/
|
78
|
+
- spec/studio_game/berserk_player_spec.rb
|
76
79
|
- spec/studio_game/clumsy_player_spec.rb
|
77
80
|
- spec/studio_game/game_spec.rb
|
78
81
|
- spec/studio_game/player_spec.rb
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'studio_game/berserk_player'
|
2
|
-
|
3
|
-
module StudioGame
|
4
|
-
describe BerserkPlayer do
|
5
|
-
before do
|
6
|
-
@initial_health = 50
|
7
|
-
@player = BerserkPlayer.new("berserker", @initial_health)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "does not go berserk when w00ted up to 5 times" do
|
11
|
-
1.upto(5) { @player.w00t }
|
12
|
-
|
13
|
-
@player.berserk?.should be_false
|
14
|
-
end
|
15
|
-
|
16
|
-
it "goes berserk when w00ted more than 5 times" do
|
17
|
-
1.upto(6) { @player.w00t }
|
18
|
-
|
19
|
-
@player.berserk?.should be_true
|
20
|
-
end
|
21
|
-
|
22
|
-
it "gets w00ted instead of blammed when it's gone berserk" do
|
23
|
-
1.upto(6) { @player.w00t }
|
24
|
-
1.upto(2) { @player.blam }
|
25
|
-
|
26
|
-
@player.health.should == @initial_health + (8 * 15)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|