greed_chido 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7a331bfb486f5355d4260920d84a72e4b59756a1
4
+ data.tar.gz: 9372645986c2c934f07f2cfb204d5cf268fd227d
5
+ SHA512:
6
+ metadata.gz: 843c9b6ac4dba22ef72f3794b03fe8f4a9bc6bb867c12a0d563e7cdcc4089a9af35c172532a494dc3f4190748523ac0853de3e159718fbcba12ef92b8070732d
7
+ data.tar.gz: 647e534c8934169b3d6323c898f85572dc73c3120bc27aa5ca3ee498d776b4829223e602d0ae82251b647413edf00430a8e6000313b277affb7aed5832297b0e
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "greed_chido"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/Board.rb ADDED
@@ -0,0 +1,150 @@
1
+ require 'Player'
2
+ require 'ScoreTable'
3
+ require 'Help'
4
+ require 'colorize'
5
+
6
+ class Board
7
+ @@listPlayer = []
8
+ @@scoreTable = ScoreTable.new
9
+ @@support = Help.new
10
+
11
+ public
12
+ def initialize
13
+ 'Write game.menu to start the game'
14
+ end
15
+
16
+ #To control the start of the game and the ending
17
+ def menu()
18
+ system('clear')
19
+ puts '==================== M E N U ===================='.colorize(:light_blue)
20
+ puts " Press enter to start".colorize(:green)
21
+ gets.chomp
22
+ @@support.help
23
+ numberPlayers
24
+ sleep (0)
25
+ game
26
+ return "Finishing the game"
27
+ end
28
+
29
+ public
30
+
31
+ #To get started with the players and their profiles
32
+ def numberPlayers
33
+ list = []
34
+ system('clear')
35
+ numberPlayer = validNumberPlayer
36
+ 3.times {puts "\n"}
37
+ i = 1
38
+ numberPlayer.times do |player|
39
+ player = capturePlayer(i)
40
+ @@listPlayer << player
41
+ i+=1
42
+ end
43
+ @@scoreTable.displayListPlayer(@@listPlayer)
44
+ return "Validation of players"
45
+ end
46
+
47
+ #To validate the number of player that will play
48
+ def validNumberPlayer
49
+ numberPlayer = 0
50
+ loop do
51
+ print "How many players? | "
52
+ numberPlayer = gets.chomp.to_i
53
+ @@support.help if numberPlayer == 0
54
+ return numberPlayer if numberPlayer != nil and numberPlayer > 1
55
+ end
56
+ end
57
+
58
+ #To capture the name of the player
59
+ def capturePlayer(numberOfPlayer)
60
+ loop do
61
+ player = Player.new
62
+ puts '---------------------------'
63
+ print "Name of player ##{numberOfPlayer} : ".colorize(:green)
64
+ player.name = gets.chomp.capitalize
65
+ player.score = 0
66
+ player.arrayV = []
67
+ return player if player.name != nil and @@scoreTable.checkName(@@listPlayer,player.name)
68
+ end
69
+ end
70
+
71
+ #To control all the flow of the game
72
+ def game
73
+ player = 0
74
+ dices = 5
75
+ winner = -1
76
+ @@scoreTable.displayPoints( @@listPlayer )
77
+ loop do
78
+ dices.times{ @@listPlayer[ player ].arrayV << rollDice }
79
+ @@listPlayer[ player ].arrayV.sort!
80
+ @@scoreTable.displayTurn(@@listPlayer, player)
81
+ dices = updatePlayer( player )
82
+ player+=1 if dices == 0
83
+ dices = 5 if dices == 0
84
+ player = 0 if player >= @@listPlayer.length
85
+ winner = @@scoreTable.winner(@@listPlayer)
86
+ break if winner >= 0
87
+ 2.times { puts "\n " }
88
+ end
89
+ @@scoreTable.celebrate(winner,@@listPlayer)
90
+ system('clear')
91
+ puts "~~~~~~~~~~~~~~~~ Thanks for playing ~~~~~~~~~~~~~~~~~"
92
+ puts "~~~~~~~~~~~~~ Gem created by rubiocanino ~~~~~~~~~~~~~"
93
+ puts ""
94
+ end
95
+
96
+ #To update the values of the array of values get it from rolling the dices
97
+ def updatePlayer(player)
98
+ puts "\n"
99
+ print "#{ frase } | "
100
+ print " #{@@listPlayer[player].name }".colorize(:green)
101
+ print " you roll : "
102
+ valuesOfRoll = @@listPlayer[player].arrayV
103
+ p valuesOfRoll
104
+ arrayValuesPoints = @@scoreTable.evaluate(@@listPlayer, player)
105
+ scoreRolling = arrayValuesPoints.pop
106
+ print "You got : "
107
+ print "#{scoreRolling}".colorize(:green) if scoreRolling > 0
108
+ print "#{scoreRolling}".colorize(:red) if scoreRolling == 0
109
+ print " points "
110
+ gets.chomp
111
+ @@listPlayer[ player ].score += scoreRolling
112
+ dices = arrayValuesPoints.length
113
+ @@listPlayer[ player ].arrayV = []
114
+ dices = 0 if scoreRolling == 0
115
+ @@listPlayer[ player ].score = 0 if @@listPlayer[ player ].score < 300 and dices == 0
116
+ return dices
117
+ end
118
+
119
+ #To got the value of rolling a dice
120
+ def rollDice
121
+ value = 1
122
+ loop do
123
+ value = (rand * 6.5).to_i
124
+ break if value >0
125
+ end
126
+ return value
127
+ end
128
+
129
+ #To change the quote of the play
130
+ def frase
131
+ option = 0
132
+ loop do
133
+ option = (rand * 5.5).to_i
134
+ break if option > 0
135
+ end
136
+ case option
137
+ when 1
138
+ return "Amazing! "
139
+ when 2
140
+ return "Good roll! "
141
+ when 3
142
+ return "Incredible! "
143
+ when 4
144
+ return "Good movement! "
145
+ when 5
146
+ return "Are you cheating? "
147
+ end
148
+ end
149
+
150
+ end
data/lib/Help.rb ADDED
@@ -0,0 +1,97 @@
1
+ class Help
2
+ def initialize; end
3
+ @@line = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
4
+
5
+ #To control all the options to bring help to the player
6
+ def help
7
+ check = false
8
+ loop do
9
+ system('clear')
10
+ puts "Rules of the game"
11
+ puts @@line.colorize(:light_blue)
12
+ puts "1) How many player can be? "
13
+ puts "2) How can I do make points? "
14
+ puts "3) Example of making points. "
15
+ puts "4) How many points do I need to win? "
16
+ puts "5) Exit or just enter to START the game. ".colorize(:red)
17
+ puts @@line.colorize(:light_blue)
18
+ print "Option: "
19
+ answer = gets.chomp.to_i
20
+ case answer
21
+ when 0
22
+ check = true
23
+ when 1
24
+ space
25
+ help_players
26
+ when 2
27
+ space
28
+ help_HowToDoPoints
29
+ when 3
30
+ space
31
+ help_ExamplePoints
32
+ when 4
33
+ space
34
+ help_HowManyPoints
35
+ when 5
36
+ check = true
37
+ else
38
+ print "Sorry I don't know."
39
+ system('clear')
40
+ end
41
+ break if check
42
+ end
43
+ system('clear')
44
+ end
45
+
46
+ #To put space between the menu and the option that was selectionated
47
+ def space
48
+ 3.times { puts "\n"}
49
+ end
50
+
51
+ #To display the confirmation
52
+ def pressToContinue
53
+ puts "\n"
54
+ print "Press enter to continue. "
55
+ gets.chomp
56
+ end
57
+
58
+ #To display how many player can play
59
+ def help_players
60
+ puts "Greed is a dice game played among 2 or more players, using 5"
61
+ puts "six-sided dice."
62
+ pressToContinue
63
+ end
64
+
65
+ #To display the options of how can you do Points
66
+ def help_HowToDoPoints
67
+ puts "Each player takes a turn consisting of one or more rolls of the dice."
68
+ puts "On the first roll of the game, a player rolls all five dice which are"
69
+ puts "scored according to the following:"
70
+ puts "\n"
71
+ puts "\tThree 1's => 1000 points"
72
+ puts "\tThree 6's => 600 points"
73
+ puts "\tThree 5's => 500 points"
74
+ puts "\tThree 4's => 400 points"
75
+ puts "\tThree 3's => 300 points"
76
+ puts "\tThree 2's => 200 points"
77
+ puts "\tOne 1 => 100 points"
78
+ puts "\tOne 5 => 50 points"
79
+ pressToContinue
80
+ end
81
+
82
+ #To display an example of how works the make points
83
+ def help_ExamplePoints
84
+ puts " Throw Score"
85
+ puts "--------- ------------------"
86
+ puts "5 1 3 4 1 50 + 2 * 100 = 250"
87
+ puts "1 1 1 3 1 1000 + 100 = 1100"
88
+ puts "2 4 4 5 4 400 + 50 = 450"
89
+ pressToContinue
90
+ end
91
+
92
+ #To display how many points do you need for win
93
+ def help_HowManyPoints
94
+ puts " You need to have 1500 or more points to win the game."
95
+ pressToContinue
96
+ end
97
+ end
data/lib/Player.rb ADDED
@@ -0,0 +1,5 @@
1
+ class Player
2
+ #To create the attributes of the Player
3
+ attr_accessor :name,:score,:arrayV
4
+ attr_writer :name,:score,:arrayV
5
+ end
data/lib/ScoreTable.rb ADDED
@@ -0,0 +1,134 @@
1
+ require 'colorize'
2
+
3
+ class ScoreTable
4
+ @@line = '|||||||||||||||||||||||||||||||||||'.colorize(:light_blue)
5
+
6
+ #To display the name of the player and their points
7
+ def displayPoints(listPlayer)
8
+ system('clear')
9
+ puts '||||||||||| P O I N T S |||||||||||'.colorize(:light_blue)
10
+ listPlayer.each do |player|
11
+ print "\t #{player.name}\t | "
12
+ puts "#{player.score}".colorize(:green)
13
+ end
14
+ puts @@line
15
+ end
16
+
17
+ #To display all the players
18
+ def displayListPlayer(listPlayer)
19
+ system('clear')
20
+ puts '|||||||||| P L A Y E R S ||||||||||'.colorize(:light_blue)
21
+ listPlayer.each { |player| puts "\t #{player.name}" }
22
+ puts @@line
23
+ end
24
+
25
+ #To check if the name is available
26
+ def checkName(listPlayer,newPlayer)
27
+ checkName = []
28
+ checkName = listPlayer.map {|player| player.name == newPlayer}
29
+ if checkName.include?(true) and newPlayer != nil
30
+ puts 'This name it\'s already took it.'.colorize(:red)
31
+ return false
32
+ else
33
+ return true
34
+ end
35
+ end
36
+
37
+ #To control the workflow of getting the score and actualize the values of the dice
38
+ def evaluate(listPlayer,player)
39
+ matches = countMatches(listPlayer[player].arrayV)
40
+ arrayOfValues = getPoints(matches,listPlayer[player].arrayV)
41
+ return arrayOfValues
42
+ end
43
+
44
+ #To count the matches of each value of the array of values
45
+ def countMatches (valuesDice)
46
+ matches = []
47
+ matches << valuesDice.count(1)
48
+ matches << valuesDice.count(2)
49
+ matches << valuesDice.count(3)
50
+ matches << valuesDice.count(4)
51
+ matches << valuesDice.count(5)
52
+ matches << valuesDice.count(6)
53
+ return matches
54
+ end
55
+
56
+ #To get the score of the array of values and return the actualize array with the score
57
+ def getPoints(matches,valuesDice)
58
+ score = 0
59
+ matches.each_with_index do |number,index|
60
+ case index
61
+ when 0
62
+ score = 1000 if number >= 3
63
+ valuesDice = actualize(3,1,valuesDice) if number >= 3
64
+ puts "Three 1's => 1000 points".colorize(:blue) if number >=3
65
+ score += 100 if number == 1
66
+ puts " One 1 => 100 points".colorize(:blue) if number == 1
67
+ valuesDice = actualize(1,1,valuesDice) if number == 1
68
+ when 1
69
+ score += 200 if number >= 3
70
+ valuesDice = actualize(3,2,valuesDice) if number >= 3
71
+ puts " Three 2's => 200 points".colorize(:blue) if number >=3
72
+ when 2
73
+ score += 300 if number >= 3
74
+ valuesDice = actualize(3,3,valuesDice) if number >= 3
75
+ puts " Three 3's => 300 points".colorize(:blue) if number >=3
76
+ when 3
77
+ score += 400 if number >= 3
78
+ valuesDice = actualize(3,4,valuesDice) if number >= 3
79
+ puts " Three 4's => 400 points".colorize(:blue) if number >=3
80
+ when 4
81
+ score += 500 if number >= 3
82
+ valuesDice = actualize(3,5,valuesDice) if number >= 3
83
+ puts " Three 5's => 500 points".colorize(:blue) if number >=3
84
+ score += 50 if number == 1
85
+ valuesDice = actualize(1,5,valuesDice) if number == 1
86
+ puts " One 5 => 50 points".colorize(:blue) if number == 1
87
+ when 5
88
+ score += 600 if number >= 3
89
+ valuesDice = actualize(3,6,valuesDice) if number >= 3
90
+ puts " Three 6's => 600 points".colorize(:blue) if number >=3
91
+ end
92
+ end
93
+ valuesDice << score
94
+ return valuesDice
95
+ end
96
+
97
+ #To delete the dices that make points and return just the once that doesn't
98
+ def actualize(timesToDelete,value,valuesDice)
99
+ timesToDelete.times { valuesDice.delete_at(valuesDice.index(value)) }
100
+ return valuesDice
101
+ end
102
+
103
+ #To verify if in the game exist a winners
104
+ def winner (listPlayers)
105
+ winner = -1
106
+ listPlayers.each_with_index do |player,index|
107
+ winner = index if player.score >= 1500
108
+ break if winner >= 0
109
+ end
110
+ return winner
111
+ end
112
+
113
+ #To celebrate the winner of the game
114
+ def celebrate (winner,listOfPlayers)
115
+ system('clear')
116
+ 3.times { puts "========= C O N G R A T U L A T I O N S =========".colorize(:green) }
117
+ puts "------------------> #{listOfPlayers[ winner ].name} <------------------".upcase.colorize(:red)
118
+ puts "================ You deserve it! ================".colorize(:green)
119
+ gets.chomp
120
+ end
121
+
122
+ #To display who is gonna roll
123
+ def displayTurn(listPlayer,player)
124
+ self.displayPoints( listPlayer )
125
+ 2.times { puts "\n"}
126
+ print "--> Your turn "
127
+ puts " #{listPlayer[player].name}".colorize(:green)
128
+ puts "Roll the dices! "
129
+ print "Press "
130
+ print "enter ".colorize(:red)
131
+ print "to roll: "
132
+ gets.chomp
133
+ end
134
+ end
@@ -0,0 +1,3 @@
1
+ module GreedChido
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,14 @@
1
+ require "greed_chido/version"
2
+ require 'colorize'
3
+ require 'Help'
4
+ require 'Player'
5
+ require 'ScoreTable'
6
+ require 'Board'
7
+
8
+ module GreedChido
9
+ class Greed
10
+ def initialize
11
+ game = Board.new.menu
12
+ end
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: greed_chido
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Saul Rubio
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.8.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.1
55
+ description: Practically you only need to press enter all the game, and make some
56
+ nice time when you play the gem.
57
+ email:
58
+ - rubiocanino98@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - bin/console
64
+ - bin/setup
65
+ - lib/Board.rb
66
+ - lib/Help.rb
67
+ - lib/Player.rb
68
+ - lib/ScoreTable.rb
69
+ - lib/greed_chido.rb
70
+ - lib/greed_chido/version.rb
71
+ homepage: https://github.com/rubiocanino/greed_chido
72
+ licenses:
73
+ - MIT
74
+ metadata:
75
+ allowed_push_host: https://rubygems.org
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.5.2.1
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: This game it's based of Greed Game in the Koans of Ruby
96
+ test_files: []