Class: Cricket::Team
- Inherits:
-
Object
- Object
- Cricket::Team
- Defined in:
- lib/cricket/team.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
- #add_Players(player) ⇒ Object
- #displayTeam ⇒ Object
-
#initialize(name) ⇒ Team
constructor
A new instance of Team.
- #play(gameType) ⇒ Object
- #total_earn ⇒ Object
Constructor Details
#initialize(name) ⇒ Team
Returns a new instance of Team.
8 9 10 11 12 13 |
# File 'lib/cricket/team.rb', line 8 def initialize(name) @name = name @players = [] @score = [] @total = 0 end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/cricket/team.rb', line 7 def name @name end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
7 8 9 |
# File 'lib/cricket/team.rb', line 7 def total @total end |
Instance Method Details
#add_Players(player) ⇒ Object
15 16 17 |
# File 'lib/cricket/team.rb', line 15 def add_Players(player) @players << player end |
#displayTeam ⇒ Object
19 20 21 22 23 24 |
# File 'lib/cricket/team.rb', line 19 def displayTeam puts "\nThe Team #{@name} has:" @players.each do |player| puts "#{player.name}, #{player.specialist} specialist, has strike rate of #{player.playTest(100)} in Test, #{player.playODI(100)} in ODI, #{player.playT20(100)} in T20. " end end |
#play(gameType) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/cricket/team.rb', line 26 def play(gameType) puts "\n #{@name}'s Scorecard" @players.each do |player| individualScore = Game.playerScore(player, gameType) sponsored_by = Sponsors.random player.all_sponsors(sponsored_by) puts "#{player.name} scored #{individualScore} (Sponsored by #{sponsored_by.name} #{sponsored_by.earn} )" @score << individualScore end @total = @score.reduce(:+) puts "\nTotal Score: #{@total}" puts "Total Earning of team: #{total_earn}" end |
#total_earn ⇒ Object
41 42 43 44 45 |
# File 'lib/cricket/team.rb', line 41 def total_earn @players.reduce(0) do |sum, player| sum + (player.earning) end end |