cricket 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5282d0c34519b69884ec52b63f2a98a0a39772af
4
+ data.tar.gz: a985986ae2dd6944bdeea621043ffe60fe739bea
5
+ SHA512:
6
+ metadata.gz: ab8034a2983bb9b9db2b75fba5fd37d98daa76f2ed48e9b09b1a2df4d6894e201a20e67202c7dce828b1576173a0f9bf745cd7bba361dac401b792db0ff4e5ab
7
+ data.tar.gz: 1047ddeb6127a8d5dccce12ab708b7fbedafd3562b7a4d11ffc64f97b42965ba1d72d4563115afb68edf0ffe405c4a862ec9c09e4a49f2279524d2626701f1a4
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ Prank7@2014
2
+
3
+ Copyright's are BULLSHIT.
4
+ ALL PERMISSIONS GRANTED.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ - You may not use this Software in other training contexts.
14
+
15
+ - The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,3 @@
1
+ Learning how to make a Gem while using all major concepts of Ruby Language.
2
+
3
+ Cricket gem is a silly interactive game, it lets you play a console based game.
@@ -0,0 +1,142 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/cricket/team'
3
+
4
+ puts "\n"
5
+ puts "Welcome To a Cricket Game!".center(100,"*")
6
+
7
+ game_format = "Odi"
8
+
9
+ loop do
10
+ puts "\nWhat Format do you want to play(Test, Odi, T20)?"
11
+ game_format = gets.chomp.capitalize
12
+
13
+ case game_format
14
+ when "Odi","Test","T20"
15
+ game_format = game_format.capitalize
16
+ break
17
+ else
18
+ puts "Please Enter 'Odi' or 'Test' or 'T20' only"
19
+ end
20
+ end
21
+
22
+ players_in_a_side = 0
23
+
24
+ loop do
25
+ puts "\nHow many a side?"
26
+ players_in_a_side = gets.chomp
27
+
28
+ case players_in_a_side
29
+ when /^\d+/
30
+ players_in_a_side = players_in_a_side.to_i
31
+ break
32
+ else
33
+ puts "Please Enter a Number"
34
+ end
35
+ end
36
+
37
+
38
+ # Get first team Name from the User
39
+ puts "\nName Your First Team:"
40
+ first_team = gets.chomp
41
+ team1 = Cricket::Team.new(first_team)
42
+
43
+ # Get first team PlayerNames from the User
44
+ team1_players = []
45
+
46
+ players_in_a_side.times do |number|
47
+ puts "Enter Name of Player#{number+1} in #{first_team}:"
48
+ team1_players[number] = Cricket::Player.new(gets.chomp)
49
+ team1.add_Players(team1_players[number])
50
+ end
51
+
52
+ team1.displayTeam
53
+
54
+ # Get Second team Name from the User
55
+ puts "\nName Your Second Team:"
56
+ second_team = gets.chomp
57
+ team2 = Cricket::Team.new(second_team)
58
+
59
+ # Get Second team PlayerNames from the User
60
+ team2_players = []
61
+
62
+ players_in_a_side.times do |number|
63
+ puts "Enter Name of Player#{number+1} in #{second_team}:"
64
+ team2_players[number] = Cricket::Player.new(gets.chomp)
65
+ team2.add_Players(team1_players[number])
66
+ end
67
+
68
+ team2.displayTeam
69
+
70
+ puts "\nEnter anything to play the Match!"
71
+ gets
72
+
73
+ puts "Match Details".center(100, "*")
74
+ # p1 = Player.new("Rahul")
75
+ # # puts p1
76
+ # # puts p1.playODI(77)
77
+ # # puts p1.playTest(152)
78
+ # # puts p1.playT20(34)
79
+
80
+
81
+ # p2 = Player.new("Sachin")
82
+ # # puts p2
83
+ # # puts p2.playODI(77)
84
+ # # puts p2.playTest(152)
85
+
86
+
87
+
88
+
89
+ # p3 = Player.new("Dhoni")
90
+ # puts p3
91
+ # puts p3.playT20(20)
92
+ # puts p2.nickname
93
+
94
+
95
+ ### Arrays ###
96
+
97
+ #players = []
98
+ #players[0] = p1
99
+ #players.push(p2)
100
+ #players << p3
101
+ #puts "#{players} #{players.size}"
102
+
103
+
104
+ # a1 = Player.new("Ponting")
105
+
106
+ # a2 = Player.new("Clark")
107
+
108
+ # a3 = Player.new("Faulkner")
109
+
110
+
111
+
112
+ # team1.add_Players(p1)
113
+ # team1.add_Players(p2)
114
+ # team1.add_Players(p3)
115
+
116
+
117
+
118
+
119
+ team1.play(game_format)
120
+ team2.play(game_format)
121
+
122
+ puts "Result".center(100,"*")
123
+
124
+ if team1.total > team2.total
125
+ puts "\nTeam #{team1.name} won by #{team1.total-team2.total} runs! Congrats!"
126
+ elsif team1.total < team2.total
127
+ puts "\nTeam #{team2.name} won by #{team2.total-team1.total} runs! Congrats!"
128
+ else
129
+ puts "\nWoah! Both teams Scored #{team1.total} runs! Match Ends in Tie!"
130
+ end
131
+
132
+
133
+ puts "\nThanks for playing this dumb game of Cricket!"
134
+
135
+
136
+ # aus = Team.new("Australia")
137
+ # aus.add_Players(a1)
138
+ # aus.add_Players(a2)
139
+ # aus.add_Players(a3)
140
+
141
+ # aus.displayTeam
142
+ # aus.play("T20")
@@ -0,0 +1,24 @@
1
+ require_relative 'team'
2
+
3
+ module Cricket
4
+ module Game
5
+
6
+ def self.playerScore(player, gameType)
7
+ gameType = gameType.capitalize
8
+ case gameType
9
+ when "Test"
10
+ balls = rand(0..400)
11
+ player.playTest(balls)
12
+ when "Odi"
13
+ balls = rand(0..175)
14
+ player.playODI(balls)
15
+ when "T20"
16
+ balls = rand(0..75)
17
+ player.playT20(balls)
18
+ else
19
+ puts "Wrong GameType"
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,63 @@
1
+ module Cricket
2
+ class Player
3
+ attr_reader :name, :specialist
4
+
5
+ def initialize(name)
6
+ @name = name.capitalize
7
+ types_of_batsman = ["Test", "Odi", "T20"]
8
+ @specialist = types_of_batsman[rand(0..2)]
9
+ @sponsors = Hash.new(0)
10
+ end
11
+
12
+ def to_s
13
+ "This is #{@name}, a #{@specialist.to_s} specialist, nicknamed #{nickname}."
14
+ end
15
+
16
+ def nickname
17
+ @name + "India"
18
+ end
19
+
20
+ def playTest(balls)
21
+ if @specialist == "Test"
22
+ run = (balls * 0.7).to_i
23
+ else
24
+ run = (balls * 0.5).to_i
25
+ end
26
+ end
27
+
28
+ def playODI(balls)
29
+ if @specialist == "Odi"
30
+ run = (balls * 1.1).to_i
31
+ else
32
+ run = (balls * 1)
33
+ end
34
+ end
35
+
36
+ def playT20(balls)
37
+ if @specialist == "T20"
38
+ run = (balls * 1.8).to_i
39
+ else
40
+ run = (balls * 1.2).to_i
41
+ end
42
+ end
43
+
44
+ def all_sponsors(sponsor)
45
+ @sponsors[sponsor.name] += sponsor.earn
46
+ end
47
+
48
+ def earning
49
+ @sponsors.values.reduce(0, :+)
50
+ end
51
+
52
+
53
+ end
54
+
55
+
56
+ # __FILE__ refers to this file, $0 means current runing file
57
+ if __FILE__ == $0
58
+ player1 = Cricket::Player.new("Kohli", "ODI")
59
+ puts player1.name
60
+ puts player1.playTest(120)
61
+ puts player1.playT20(23)
62
+ end
63
+ end
@@ -0,0 +1,15 @@
1
+ player1 = "Rahul"
2
+ score1 = 13500
3
+ player2 = "Sachin"
4
+ score2 = 14000
5
+ player3 = "Sourav"
6
+ score3 = 12000
7
+ player4= "Laxman"
8
+ score4 = 10000
9
+
10
+ puts "#{player1} has runs #{score1}."
11
+ puts "#{player2.upcase} has runs #{score2}."
12
+ puts "#{player3} has runs #{score3}".center(30,"#")
13
+ puts "#{player4.ljust(30,'.')} #{score4} runs"
14
+
15
+
@@ -0,0 +1,17 @@
1
+ module Cricket
2
+
3
+ Sponsor = Struct.new(:name, :earn)
4
+
5
+ module Sponsors
6
+
7
+ SPONSORS = [Sponsor.new(:Bsnl, 10),
8
+ Sponsor.new(:Sahara, 20),
9
+ Sponsor.new(:Vodafone, 30),
10
+ Sponsor.new(:LIC, 15)]
11
+
12
+ def self.random
13
+ SPONSORS.sample
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,48 @@
1
+ require_relative 'player'
2
+ require_relative 'game'
3
+ require_relative 'sponsors'
4
+
5
+ module Cricket
6
+ class Team
7
+ attr_reader :total, :name
8
+ def initialize(name)
9
+ @name = name
10
+ @players = []
11
+ @score = []
12
+ @total = 0
13
+ end
14
+
15
+ def add_Players(player)
16
+ @players << player
17
+ end
18
+
19
+ def displayTeam
20
+ puts "\nThe Team #{@name} has:"
21
+ @players.each do |player|
22
+ 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. "
23
+ end
24
+ end
25
+
26
+ def play(gameType)
27
+ puts "\n #{@name}'s Scorecard"
28
+ @players.each do |player|
29
+ individualScore = Game.playerScore(player, gameType)
30
+ sponsored_by = Sponsors.random
31
+ player.all_sponsors(sponsored_by)
32
+ puts "#{player.name} scored #{individualScore} (Sponsored by #{sponsored_by.name} #{sponsored_by.earn} )"
33
+ @score << individualScore
34
+ end
35
+
36
+ @total = @score.reduce(:+)
37
+ puts "\nTotal Score: #{@total}"
38
+ puts "Total Earning of team: #{total_earn}"
39
+ end
40
+
41
+ def total_earn
42
+ @players.reduce(0) do |sum, player|
43
+ sum + (player.earning)
44
+ end
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,24 @@
1
+ require 'cricket/player'
2
+
3
+ module Cricket
4
+ describe Player do
5
+
6
+ before do
7
+ @specialist = "test"
8
+ @p1 = Cricket::Player.new("rahul")
9
+ end
10
+
11
+ it "has a capitalized title" do
12
+ @p1.name.should == "Rahul"
13
+ end
14
+
15
+ it "has a capitalized specialist" do
16
+ @p1.specialist.should == "Test"
17
+ end
18
+
19
+ it "should score at a strike rate of 70" do
20
+ @p1.playTest(100).should == 70
21
+ end
22
+
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cricket
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Prank7
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-11 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
+ Learning how to make a Gem while using all major concepts of Ruby Language.
29
+
30
+ Cricket gem is a silly interactive game, it lets you play a console based game.
31
+ email: prashant.abhishek7g@gmail.com
32
+ executables:
33
+ - cricket
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - LICENSE
38
+ - README
39
+ - bin/cricket
40
+ - lib/cricket/game.rb
41
+ - lib/cricket/player.rb
42
+ - lib/cricket/players.rb
43
+ - lib/cricket/sponsors.rb
44
+ - lib/cricket/team.rb
45
+ - spec/cricket/player_rspec.rb
46
+ homepage: https://github.com/prank7/cricket-gem
47
+ licenses: []
48
+ metadata: {}
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '1.9'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 2.2.2
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: Lets you play a cricket game in console
69
+ test_files:
70
+ - spec/cricket/player_rspec.rb