studio_game_tarikl 1.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
+ SHA1:
3
+ metadata.gz: ada7ce27d0d28830151c51faf48463eaee643126
4
+ data.tar.gz: 0056ef273763e12feee8d6f1330f2d6a717b5cfc
5
+ SHA512:
6
+ metadata.gz: 138a9a80d03d26705820967e03b256f7dd856f8112996bdc5ae4325d3e2aa517ac7eb12d51ac7b50068f310ae8da46b05e74e07926e5030525b42946f5401d6a
7
+ data.tar.gz: 4e1ce1560d25263f0fec5bb99f0e6f67e57f22d5ca3042a484b6f7e5ce9f0bffe523004ac28f0d14776e72a198902e72fbb7a2277ff25acebc890fce2a703961
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2016 <TARIK - Pragmatic Studio>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in the
5
+ Software without restriction, including without limitation the rights to use, copy,
6
+ modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
7
+ and to permit persons to whom the Software is furnished to do so, subject to the
8
+ 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 IMPLIED,
14
+ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
15
+ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
16
+ FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18
+ DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,9 @@
1
+ Studio Game 2016
2
+ -Tarik- Pragmatic Studio
3
+ launch "studio_game" and let the magic shine
4
+ A role-playing game is a game in which the participants assume the roles
5
+ of characters and collaboratively create stories. Participants determine
6
+ the actions of their characters based on their characterisation,
7
+ and the actions succeed or fail according to a formal system of rules and
8
+ guidelines. Within the rules, they may improvise freely; their choices
9
+ shape the direction and outcome of the games.
@@ -0,0 +1,3 @@
1
+ moe,100
2
+ larry,60
3
+ curly,125
@@ -0,0 +1,6 @@
1
+ Knuckeheads High Scores:
2
+ Theo.......................... 2240
3
+ Alvin......................... 1490
4
+ Berserker..................... 1130
5
+ Klutz......................... 815.0
6
+ Simon......................... 800
@@ -0,0 +1,3 @@
1
+ Alvin,100
2
+ Simon,60
3
+ Theo,125
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/studio_game/game'
3
+ require_relative '../lib/studio_game/player'
4
+ require_relative '../lib/studio_game/clumsy_player'
5
+ require_relative '../lib/studio_game/berserk_player'
6
+
7
+ module StudioGame
8
+
9
+ player1= Player.new("moe")
10
+ player2= Player.new("larry",60)
11
+ player3= Player.new("curly",125)
12
+
13
+ knuckleheads = StudioGame::Game.new("Knuckeheads")
14
+ default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
15
+ knuckleheads.load_players(ARGV.shift || default_player_file)
16
+ # knuckleheads.add_player(player1)
17
+ # knuckleheads.add_player(player2)
18
+ # knuckleheads.add_player(player3)
19
+ clumpsy_player1= ClumsyPlayer.new("klutz",105,3)
20
+ knuckleheads.add_player(clumpsy_player1)
21
+
22
+ berserk_player1= BerserkPlayer.new("berserker",50)
23
+ knuckleheads.add_player(berserk_player1)
24
+
25
+ loop do
26
+ puts "\nHow many game rounds ? ('quit' to exit )"
27
+ answer = gets.chomp.downcase
28
+ case answer
29
+ when /^\d+$/
30
+ knuckleheads.play(answer.to_i)
31
+ when 'quit','exit'
32
+ knuckleheads.print_stats
33
+ break
34
+ else
35
+ puts "Please enter a number or 'quit'"
36
+ end
37
+ end
38
+
39
+ knuckleheads.save_high_scores
40
+ end
41
+ #knuckleheads.play(answer.to_i) { knuckleheads.total_points >=15000 }
42
+ # player4= Player.new("Alvin", 40)
43
+ # player5= Player.new("Simon", 50)
44
+ # player6= Player.new("Theodore", 60)
45
+ #
46
+ # chipmunks = Game.new("Chipmunks")
47
+ #
48
+ # chipmunks.add_player(player4)
49
+ # chipmunks.add_player(player5)
50
+ # chipmunks.add_player(player6)
51
+ # chipmunks.play
@@ -0,0 +1,8 @@
1
+ module StudioGame
2
+ module Auditable
3
+ def audit
4
+ puts "Rolled a #{self.number} (#{self.class})"
5
+ end
6
+
7
+ end
8
+ end
@@ -0,0 +1,30 @@
1
+ require_relative 'player'
2
+ module StudioGame
3
+ class BerserkPlayer < Player
4
+ def initialize(name,health=100)
5
+ super(name,health)
6
+ @w00t_count=0
7
+ end
8
+
9
+ def berserk?
10
+ @w00t_count > 5
11
+ end
12
+
13
+ def w00t
14
+ super
15
+ @w00t_count +=1
16
+ puts "#{@name} is berserk!" if berserk?
17
+ end
18
+
19
+ def blam
20
+ berserk? ? w00t : super
21
+ end
22
+
23
+ end
24
+
25
+ if __FILE__ == $0
26
+ berserker = BerserkPlayer.new("berserker", 50)
27
+ 6.times { berserker.w00t }
28
+ 2.times { berserker.blam }
29
+ end
30
+ end
@@ -0,0 +1,38 @@
1
+ require_relative 'player'
2
+ module StudioGame
3
+ class ClumsyPlayer < Player
4
+ attr_reader :boost_factor
5
+
6
+ def initialize(name, health=100, boost_factor=1)
7
+ super(name,health)
8
+ @boost_factor=boost_factor
9
+ end
10
+
11
+ def w00t
12
+ @boost_factor.times{ super }
13
+ end
14
+
15
+ def found_treasure (treasure)
16
+ super(Treasure.new(treasure.name, treasure.points / 2.0))
17
+ # @found_treasures[treasure.name] += treasure.points/2.0
18
+ # puts "#{@name} found a #{treasure.name} worth #{treasure.points} points."
19
+ # puts "#{@name}'s treasures #{@found_treasures}"
20
+ end
21
+ end
22
+
23
+ if __FILE__ == $0
24
+ clumsy = ClumsyPlayer.new("klutz")
25
+ hammer = Treasure.new(:hammer, 50)
26
+ clumsy.found_treasure(hammer)
27
+ clumsy.found_treasure(hammer)
28
+ clumsy.found_treasure(hammer)
29
+
30
+ crowbar = Treasure.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,12 @@
1
+ require_relative 'auditable'
2
+ module StudioGame
3
+ class Die
4
+ include Auditable
5
+ attr_reader :number
6
+ def roll
7
+ @number=rand(1..6)
8
+ audit
9
+ @number
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ require_relative 'player'
2
+
3
+ File.readlines("players.csv").each do |line|
4
+ name, point = line.split(',')
5
+ player = Player.new(name, point.to_i)
6
+ puts player
7
+ end
@@ -0,0 +1,92 @@
1
+ require_relative('die')
2
+ require_relative('game_turn')
3
+ require_relative('treasure_trove')
4
+ require 'csv'
5
+ module StudioGame
6
+ class Game
7
+ attr_reader :title
8
+
9
+ def initialize(title)
10
+ @title = title
11
+ @players = []
12
+ end
13
+
14
+ def add_player(player)
15
+ @players << player
16
+ end
17
+
18
+ def high_score_entry(player)
19
+ "#{player.name.ljust(30, '.')} #{player.score}"
20
+ end
21
+ =begin
22
+ def load_players(from_file)
23
+ File.readlines(from_file).each do |line|
24
+ add_player(Player.from_csv(line))
25
+ end
26
+ end
27
+ =end
28
+ def load_players(from_file)
29
+ CSV.foreach(from_file) do |row|
30
+ add_player(Player.new(row.first, Integer(row.last)))
31
+ end
32
+ end
33
+
34
+ def save_high_scores(to_file='high_scores.txt')
35
+ File.open(to_file,'w') do |file|
36
+ file.puts "#{@title} High Scores:\n"
37
+ @players.sort.each do |player|
38
+ file.puts high_score_entry(player)
39
+ end
40
+ end
41
+ end
42
+
43
+ def play(rounds)
44
+ puts "There are #{@players.size} players in #{@title}:"
45
+ puts @players
46
+ treasures = TreasureTrove::TREASURES
47
+ puts "\nThe trove contains #{treasures.size} treasures!"
48
+ treasures.each do |tr|
49
+ puts "#{tr.name.to_s.ljust(30, '_')} #{tr.points}"
50
+ end
51
+ 1.upto(rounds) do |round|
52
+ if block_given?
53
+ break if yield
54
+ end
55
+ puts "\nRound #{round}:"
56
+ @players.each do |a_player|
57
+ GameTurn.take_turn(a_player)
58
+ puts a_player
59
+ end
60
+ end
61
+ end
62
+
63
+ def print_name_and_health(players)
64
+ players.each { |player| puts "#{player.name} (#{player.health})" }
65
+ end
66
+
67
+ def total_points
68
+ @players.reduce(0) { |sum, player| sum + player.points }
69
+ end
70
+
71
+ def print_stats
72
+ strong, wimpy = @players.partition(&:strong?)
73
+ puts "\n#{@title} Statistics:"
74
+ puts "\n#{strong.size} strong players:"
75
+ print_name_and_health(strong)
76
+ puts "\n#{wimpy.size} wimpy players:"
77
+ print_name_and_health(wimpy)
78
+ puts "\n#{@title} High Scores:"
79
+ @players.sort.each { |player| puts high_score_entry(player) }
80
+ puts "\n#{@title} Total points:"
81
+ @players.sort.each do |player|
82
+ puts "\n#{player.name}'s point totals:"
83
+ player.each_found_treasure do |tr|
84
+ puts "#{tr.points} total #{tr.name} points"
85
+ end
86
+ puts "#{player.points} grand total points"
87
+ end
88
+ puts "\n#{@title} Grand Total points:"
89
+ puts total_points.to_s
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,23 @@
1
+ require_relative 'die'
2
+ #require_relative 'loaded_die'
3
+ require_relative 'player'
4
+ require_relative 'treasure_trove'
5
+ module StudioGame
6
+ module GameTurn
7
+ def self.take_turn(a_player)
8
+ die = Die.new
9
+ #die= LoadedDie.new
10
+ number_rolled = die.roll
11
+ case number_rolled
12
+ when 1..2
13
+ a_player.blam
14
+ when 5..6
15
+ a_player.w00t
16
+ else
17
+ puts "#{a_player.name} was skipped"
18
+ end
19
+ treasure_found = TreasureTrove.random
20
+ a_player.found_treasure(treasure_found)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,6 @@
1
+ Knuckeheads High Scores:
2
+ Simon......................... 2365
3
+ Alvin......................... 1560
4
+ Berserker..................... 1225
5
+ Theo.......................... 1020
6
+ Klutz......................... 787.5
@@ -0,0 +1,13 @@
1
+ require_relative 'auditable'
2
+ module StudioGame
3
+ class LoadedDie
4
+ include Auditable
5
+ attr_reader :number
6
+ def roll
7
+ numbers = [1, 1, 2, 5, 6, 6]
8
+ @number = numbers.sample
9
+ audit
10
+ @number
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+
2
+ module StudioGame
3
+ module Playable
4
+
5
+ def blam
6
+ self.health -= 10
7
+ puts "#{name} got blammed!"
8
+ end
9
+
10
+ def w00t
11
+ self.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,69 @@
1
+ require_relative 'treasure_trove'
2
+ require_relative 'playable'
3
+ module StudioGame
4
+ class Player
5
+ include Playable
6
+ attr_accessor :name
7
+ attr_accessor :health
8
+
9
+ def initialize(name,health=100)
10
+ @name = name.capitalize
11
+ @health = health
12
+ @found_treasures = Hash.new(0)
13
+ end
14
+
15
+ #Ruby generated the default name= method for you when you
16
+ #used "attr_accessor :name", but you can easily override it.
17
+ #For example, if we want to capitalize the name before
18
+ #it's assigned, all we need to do is explicitly define
19
+ #a "name=" method in the Player class:
20
+ def name=(new_name)
21
+ @name=new_name.capitalize
22
+ end
23
+
24
+ def score
25
+ @health + points
26
+ end
27
+
28
+ def to_s
29
+ "I'm #{@name} with a health = #{@health}, points = #{points}, and a score = #{score}."
30
+ end
31
+
32
+ def self.from_csv(string)
33
+ name, health = string.split(',')
34
+ Player.new(name,Integer(health))
35
+ end
36
+
37
+ def <=>(other)
38
+ other.score <=> score
39
+ end
40
+
41
+ def found_treasure (treasure)
42
+ @found_treasures[treasure.name] += treasure.points
43
+ puts "#{@name} found a #{treasure.name} worth #{treasure.points} points."
44
+ puts "#{@name}'s treasures #{@found_treasures}"
45
+ end
46
+
47
+ def points
48
+ @found_treasures.values.reduce(0,:+)
49
+ end
50
+
51
+ def each_found_treasure
52
+ @found_treasures.each do |name, points|
53
+ treasure_recreated = Treasure.new(name, points)
54
+ yield treasure_recreated
55
+ end
56
+ end
57
+
58
+ end
59
+
60
+ if __FILE__ == $0
61
+ player = Player.new("moe")
62
+ puts player.name
63
+ puts player.health
64
+ player.w00t
65
+ puts player.health
66
+ player.blam
67
+ puts player.health
68
+ end
69
+ end
@@ -0,0 +1,20 @@
1
+
2
+ module StudioGame
3
+ Treasure = Struct.new(:name, :points)
4
+
5
+ module TreasureTrove
6
+ TREASURES = [
7
+ Treasure.new(:pie, 5),
8
+ Treasure.new(:bottle, 25),
9
+ Treasure.new(:hammer,50),
10
+ Treasure.new(:skillet, 100),
11
+ Treasure.new(:broomstick, 200),
12
+ Treasure.new(:crowbar, 400)
13
+ ]
14
+
15
+ def self.random
16
+ TREASURES.sample
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,31 @@
1
+ require 'studio_game/berserk_player'
2
+ module StudioGame
3
+ describe BerserkPlayer do
4
+
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
+ expect(@player.berserk?).to be_falsey
13
+ #@player.berserk?.should be_falsey
14
+
15
+ end
16
+
17
+ it "goes berserk when w00ted more than 5 times" do
18
+ 1.upto(6) { @player.w00t }
19
+ expect(@player.berserk?).to be_truthy
20
+ #@player.berserk?.should be_truthy
21
+ end
22
+
23
+ it "gets w00ted instead of blammed when it's gone berserk" do
24
+ 1.upto(6) { @player.w00t }
25
+ 1.upto(2) { @player.blam }
26
+ expected_health=@initial_health + (8 * 15)
27
+ expect(@player.health).to eq(expected_health)
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,50 @@
1
+ require 'studio_game/clumsy_player'
2
+
3
+ module StudioGame
4
+ describe ClumsyPlayer do
5
+ before do
6
+ @player = ClumsyPlayer.new("klutz")
7
+ end
8
+
9
+ it "only gets half the point value for each treasure" do
10
+ expect(@player.points).to eq 0
11
+
12
+ hammer = Treasure.new(:hammer, 50)
13
+ @player.found_treasure(hammer)
14
+ @player.found_treasure(hammer)
15
+ @player.found_treasure(hammer)
16
+
17
+ expect(@player.points).to eq 75
18
+
19
+ crowbar = Treasure.new(:crowbar, 400)
20
+ @player.found_treasure(crowbar)
21
+
22
+ expect(@player.points).to eq 275
23
+
24
+ yielded = []
25
+ @player.each_found_treasure do |treasure|
26
+ yielded << treasure
27
+ end
28
+
29
+ expect(yielded).to eq [Treasure.new(:hammer, 75), Treasure.new(:crowbar, 200)]
30
+ end
31
+
32
+ context "with a boost factor" do
33
+ before do
34
+ @initial_health = 100
35
+ @boost_factor = 5
36
+ @player = ClumsyPlayer.new("klutz", @initial_health, @boost_factor)
37
+ end
38
+
39
+ it "has a boost factor" do
40
+ expect(@player.boost_factor).to eq(5)
41
+ end
42
+
43
+ it "gets boost factor number of w00ts when w00ted" do
44
+ @player.w00t
45
+
46
+ expect(@player.health).to eq(@initial_health + (15 * @boost_factor))
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,61 @@
1
+ require 'studio_game/game'
2
+ require 'studio_game/player'
3
+ module StudioGame
4
+ describe Game do
5
+ before do
6
+ $stdout = StringIO.new
7
+
8
+ @game = Game.new('knuckleheads')
9
+
10
+ @initial_health = 100
11
+ @player = Player.new('moe', @initial_health)
12
+
13
+ @game.add_player(@player)
14
+ end
15
+
16
+ it 'w00ts the player if a high number is rolled' do
17
+ allow_any_instance_of(Die).to receive(:roll).and_return(5)
18
+ @game.play(2)
19
+ expect(@player.health).to eq(@initial_health + 15 * 2)
20
+ end
21
+
22
+ it 'skip the player if 3 or 4 is rolled' do
23
+ allow_any_instance_of(Die).to receive(:roll).and_return(3)
24
+ @game.play(2)
25
+ expect(@player.health).to eq(@initial_health)
26
+ end
27
+
28
+ it 'blams the player if a low number is rolled' do
29
+ allow_any_instance_of(Die).to receive(:roll).and_return(1)
30
+ @game.play(2)
31
+ expect(@player.health).to eq(@initial_health - 10 * 2)
32
+ end
33
+
34
+ it "assigns a treasure for points during a player's turn" do
35
+ game = Game.new('Knuckleheads')
36
+ player = Player.new('moe')
37
+
38
+ game.add_player(player)
39
+
40
+ game.play(1)
41
+
42
+ expect(player.points).not_to be_zero
43
+ end
44
+
45
+ it 'computes total points as the sum of all player points' do
46
+ game = Game.new('Knuckleheads')
47
+
48
+ player1 = Player.new('moe')
49
+ player2 = Player.new('larry')
50
+
51
+ game.add_player(player1)
52
+ game.add_player(player2)
53
+
54
+ player1.found_treasure(Treasure.new(:hammer, 50))
55
+ player1.found_treasure(Treasure.new(:hammer, 50))
56
+ player2.found_treasure(Treasure.new(:crowbar, 400))
57
+
58
+ expect(game.total_points).to eq(500)
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,118 @@
1
+ require 'studio_game/player'
2
+ require 'studio_game/treasure_trove'
3
+
4
+ module StudioGame
5
+ describe Player do
6
+ before do
7
+ $stdout = StringIO.new
8
+ @initial_health = 150
9
+ @player = Player.new('john', @initial_health)
10
+ end
11
+
12
+ it 'has a capitalize name' do
13
+ expect(@player.name).to eq('John')
14
+ end
15
+
16
+ it 'has an initial health' do
17
+ expect(@player.health).to eq(@initial_health)
18
+ end
19
+
20
+ it 'has a string representation' do
21
+ @player.found_treasure(Treasure.new(:hammer, 50))
22
+ @player.found_treasure(Treasure.new(:hammer, 50))
23
+
24
+ expect(@player.to_s).to eq("I'm John with a health = 150, points = 100, and a score = 250.")
25
+ end
26
+
27
+ it 'increases health by 15 when w00ted' do
28
+ @player.w00t
29
+ expect(@player.health).to eq(@initial_health + 15)
30
+ end
31
+
32
+ it 'decreases health by 10 when blammed' do
33
+ @player.blam
34
+ expect(@player.health).to eq(@initial_health - 10)
35
+ end
36
+
37
+ context 'with a health greater than 100' do
38
+ before do
39
+ @player = Player.new('larry', 150)
40
+ end
41
+ it 'is strong' do
42
+ expect(@player).to be_strong
43
+ end
44
+ end
45
+
46
+ context 'with a health of 100 or less' do
47
+ before do
48
+ @player = Player.new('larry', 100)
49
+ end
50
+ it 'is wimp' do
51
+ expect(@player).not_to be_strong
52
+ end
53
+ end
54
+ context 'in a collection of players' do
55
+ before do
56
+ @player1 = Player.new('moe', 100)
57
+ @player2 = Player.new('larry', 200)
58
+ @player3 = Player.new('curly', 300)
59
+
60
+ @players = [@player1, @player2, @player3]
61
+ end
62
+
63
+ it 'is sorted by decreasing score' do
64
+ expect(@players.sort).to eq([@player3, @player2, @player1])
65
+ end
66
+ end
67
+ it 'computes points as the sum of all treasure points' do
68
+ expect(@player.points).to eq(0)
69
+
70
+ @player.found_treasure(Treasure.new(:hammer, 50))
71
+
72
+ expect(@player.points).to eq(50)
73
+
74
+ @player.found_treasure(Treasure.new(:crowbar, 400))
75
+
76
+ expect(@player.points).to eq(450)
77
+
78
+ @player.found_treasure(Treasure.new(:hammer, 50))
79
+
80
+ expect(@player.points).to eq(500)
81
+ end
82
+ it 'computes a score as the sum of its health and points' do
83
+ @player.found_treasure(Treasure.new(:hammer, 50))
84
+ @player.found_treasure(Treasure.new(:hammer, 50))
85
+
86
+ expect(@player.score).to eq(250)
87
+ end
88
+
89
+ it 'yields each found treasure and its total points' do
90
+ @player.found_treasure(Treasure.new(:skillet, 100))
91
+ @player.found_treasure(Treasure.new(:skillet, 100))
92
+ @player.found_treasure(Treasure.new(:hammer, 50))
93
+ @player.found_treasure(Treasure.new(:bottle, 5))
94
+ @player.found_treasure(Treasure.new(:bottle, 5))
95
+ @player.found_treasure(Treasure.new(:bottle, 5))
96
+ @player.found_treasure(Treasure.new(:bottle, 5))
97
+ @player.found_treasure(Treasure.new(:bottle, 5))
98
+
99
+ yielded = []
100
+ @player.each_found_treasure do |treasure|
101
+ yielded << treasure
102
+ end
103
+
104
+ expect(yielded).to eq( [
105
+ Treasure.new(:skillet, 200),
106
+ Treasure.new(:hammer, 50),
107
+ Treasure.new(:bottle, 25)
108
+ ] )
109
+ end
110
+
111
+ it "can be created from a CSV string" do
112
+ player = Player.from_csv("larry,150")
113
+
114
+ expect(player.name).to eq("Larry")
115
+ expect(player.health).to eq(150)
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,56 @@
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
+ expect(@treasure.name).to eq(:hammer)
12
+ end
13
+
14
+ it "has a points attribute" do
15
+ expect(@treasure.points).to eq(50)
16
+ end
17
+
18
+ end
19
+
20
+ describe TreasureTrove do
21
+
22
+ it "has six treasures" do
23
+ expect(TreasureTrove::TREASURES.size).to eq(6)
24
+ end
25
+
26
+ it "has a pie worth 5 points" do
27
+ expect(TreasureTrove::TREASURES[0]).to eq(Treasure.new(:pie, 5))
28
+ end
29
+
30
+ it "has a bottle worth 25 points" do
31
+ expect(TreasureTrove::TREASURES[1]).to eq(Treasure.new(:bottle, 25))
32
+ end
33
+
34
+ it "has a hammer worth 50 points" do
35
+ expect(TreasureTrove::TREASURES[2]).to eq(Treasure.new(:hammer, 50))
36
+ end
37
+
38
+ it "has a skillet worth 100 points" do
39
+ expect(TreasureTrove::TREASURES[3]).to eq(Treasure.new(:skillet, 100))
40
+ end
41
+
42
+ it "has a broomstick worth 200 points" do
43
+ expect(TreasureTrove::TREASURES[4]).to eq(Treasure.new(:broomstick, 200))
44
+ end
45
+
46
+ it "has a crowbar worth 400 points" do
47
+ expect(TreasureTrove::TREASURES[5]).to eq(Treasure.new(:crowbar, 400))
48
+ end
49
+
50
+ it "returns a random treasure" do
51
+ treasure = TreasureTrove.random
52
+ expect(TreasureTrove::TREASURES).to include(treasure)
53
+ end
54
+
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: studio_game_tarikl
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - TARIK LAHCEN - pragmatic studio
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-22 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
+ Studio Game 2016
29
+ -Tarik- Pragmatic Studio
30
+ launch "studio_game" and let the magic shine
31
+ A role-playing game is a game in which the participants assume the roles
32
+ of characters and collaboratively create stories. Participants determine
33
+ the actions of their characters based on their characterisation,
34
+ and the actions succeed or fail according to a formal system of rules and
35
+ guidelines. Within the rules, they may improvise freely; their choices
36
+ shape the direction and outcome of the games.
37
+ email: tarikla@gmail.com
38
+ executables:
39
+ - studio_game
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - LICENSE
44
+ - README
45
+ - bin/favorite_players.csv
46
+ - bin/high_scores.txt
47
+ - bin/players.csv
48
+ - bin/studio_game
49
+ - lib/studio_game/auditable.rb
50
+ - lib/studio_game/berserk_player.rb
51
+ - lib/studio_game/clumsy_player.rb
52
+ - lib/studio_game/die.rb
53
+ - lib/studio_game/file.rb
54
+ - lib/studio_game/game.rb
55
+ - lib/studio_game/game_turn.rb
56
+ - lib/studio_game/high_scores.txt
57
+ - lib/studio_game/loaded_die.rb
58
+ - lib/studio_game/playable.rb
59
+ - lib/studio_game/player.rb
60
+ - lib/studio_game/treasure_trove.rb
61
+ - spec/berserk_player_spec.rb
62
+ - spec/clumsy_player_spec.rb
63
+ - spec/game_spec.rb
64
+ - spec/player_spec.rb
65
+ - spec/treasure_trove_spec.rb
66
+ homepage: https://twitter.com/tarik_lahcen
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '1.9'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.5.1
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: enjoy this awesome little game
90
+ test_files:
91
+ - spec/berserk_player_spec.rb
92
+ - spec/clumsy_player_spec.rb
93
+ - spec/game_spec.rb
94
+ - spec/player_spec.rb
95
+ - spec/treasure_trove_spec.rb