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.
@@ -1,133 +1,124 @@
1
- require 'studio_game/player'
2
-
3
- module StudioGame
4
- describe Player do
5
- before do
6
- @initial_health = 150
7
- @player = Player.new("larry", @initial_health)
8
- end
9
-
10
- it "has a capitalized name" do
11
- @player.name.should == "Larry"
12
- end
13
-
14
- it "has an initial health" do
15
- @player.health.should == 150
16
- end
17
-
18
- it "has a string representation" do
19
- @player.found_treasure(Treasure.new(:hammer, 50))
20
- @player.found_treasure(Treasure.new(:hammer, 50))
21
-
22
- @player.to_s.should == "I'm Larry with health = 150, points = 100, and score = 250."
23
- end
24
-
25
- it "increases health by 15 when w00ted" do
26
- @player.w00t
27
-
28
- @player.health.should == @initial_health + 15
29
- end
30
-
31
- it "decreases health by 10 when blammed" do
32
- @player.blam
33
-
34
- @player.health.should == @initial_health - 10
35
- end
36
-
37
- context "created with a default health" do
38
- before do
39
- @player = Player.new("larry")
40
- end
41
-
42
- it "has a health of 100" do
43
- @player.health.should == 100
44
- end
45
- end
46
-
47
- context "with a health greater than 100" do
48
- before do
49
- @player = Player.new("larry", 150)
50
- end
51
-
52
- it "is strong" do
53
- @player.should be_strong
54
- end
55
- end
56
-
57
- context "with a health of 100 or less" do
58
- before do
59
- @player = Player.new("larry", 100)
60
- end
61
-
62
- it "is wimpy" do
63
- @player.should_not be_strong
64
- end
65
- end
66
-
67
- context "in a collection of players" do
68
- before do
69
- @player1 = Player.new("moe", 100)
70
- @player2 = Player.new("larry", 200)
71
- @player3 = Player.new("curly", 300)
72
-
73
- @players = [@player1, @player2, @player3]
74
- end
75
-
76
- it "is sorted by decreasing score" do
77
- @players.sort.should == [@player3, @player2, @player1]
78
- end
79
- end
80
-
81
- it "computes a score as the sum of its health and points" do
82
- @player.found_treasure(Treasure.new(:hammer, 50))
83
- @player.found_treasure(Treasure.new(:hammer, 50))
84
-
85
- @player.score.should == 250
86
- end
87
-
88
- it "computes points as the sum of all treasure points" do
89
- @player.points.should == 0
90
-
91
- @player.found_treasure(Treasure.new(:hammer, 50))
92
-
93
- @player.points.should == 50
94
-
95
- @player.found_treasure(Treasure.new(:crowbar, 400))
96
-
97
- @player.points.should == 450
98
-
99
- @player.found_treasure(Treasure.new(:hammer, 50))
100
-
101
- @player.points.should == 500
102
- end
103
-
104
- it "yields each found treasure and its total points" do
105
- @player.found_treasure(Treasure.new(:skillet, 100))
106
- @player.found_treasure(Treasure.new(:skillet, 100))
107
- @player.found_treasure(Treasure.new(:hammer, 50))
108
- @player.found_treasure(Treasure.new(:bottle, 5))
109
- @player.found_treasure(Treasure.new(:bottle, 5))
110
- @player.found_treasure(Treasure.new(:bottle, 5))
111
- @player.found_treasure(Treasure.new(:bottle, 5))
112
- @player.found_treasure(Treasure.new(:bottle, 5))
113
-
114
- yielded = []
115
- @player.each_found_treasure do |treasure|
116
- yielded << treasure
117
- end
118
-
119
- yielded.should == [
120
- Treasure.new(:skillet, 200),
121
- Treasure.new(:hammer, 50),
122
- Treasure.new(:bottle, 25)
123
- ]
124
- end
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/treasure_trove'
2
-
3
- module StudioGame
4
- describe Treasure do
5
- before do
6
- @treasure = Treasure.new(:hammer, 50)
7
- end
8
-
9
- it "has a name attribute" do
10
- @treasure.name.should == :hammer
11
- end
12
-
13
- it "has a points attribute" do
14
- @treasure.points.should == 50
15
- end
16
- end
17
-
18
- describe TreasureTrove do
19
- it "has six treasures" do
20
- TreasureTrove::TREASURES.size.should == 6
21
- end
22
-
23
- it "has a pie worth 5 points" do
24
- TreasureTrove::TREASURES[0].should == Treasure.new(:pie, 5)
25
- end
26
-
27
- it "has a bottle worth 25 points" do
28
- TreasureTrove::TREASURES[1].should == Treasure.new(:bottle, 25)
29
- end
30
-
31
- it "has a hammer worth 50 points" do
32
- TreasureTrove::TREASURES[2].should == Treasure.new(:hammer, 50)
33
- end
34
-
35
- it "has a skillet worth 100 points" do
36
- TreasureTrove::TREASURES[3].should == Treasure.new(:skillet, 100)
37
- end
38
-
39
- it "has a broomstick worth 200 points" do
40
- TreasureTrove::TREASURES[4].should == Treasure.new(:broomstick, 200)
41
- end
42
-
43
- it "has a crowbar worth 400 points" do
44
- TreasureTrove::TREASURES[5].should == Treasure.new(:crowbar, 400)
45
- end
46
-
47
- it "returns a random treasure" do
48
- treasure = TreasureTrove.random
49
-
50
- TreasureTrove::TREASURES.should include(treasure)
51
- end
52
- end
53
- end
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.0.0
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: 2015-04-04 00:00:00.000000000 Z
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/beserk_player_spec.rb
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 random text-based game
76
+ summary: A simple text-based game
74
77
  test_files:
75
- - spec/studio_game/beserk_player_spec.rb
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