Class: Cricket::Team

Inherits:
Object
  • Object
show all
Defined in:
lib/cricket/team.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/cricket/team.rb', line 7

def name
  @name
end

#totalObject (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

#displayTeamObject



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_earnObject



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