Class: Board
- Inherits:
-
Object
- Object
- Board
- Defined in:
- lib/Board.rb
Constant Summary collapse
- @@listPlayer =
[]
- @@scoreTable =
ScoreTable.new
- @@support =
Help.new
Instance Method Summary collapse
-
#capturePlayer(numberOfPlayer) ⇒ Object
To capture the name of the player.
-
#frase ⇒ Object
To change the quote of the play.
-
#game ⇒ Object
To control all the flow of the game.
-
#initialize ⇒ Board
constructor
A new instance of Board.
-
#menu ⇒ Object
To control the start of the game and the ending.
-
#numberPlayers ⇒ Object
To get started with the players and their profiles.
-
#rollDice ⇒ Object
To got the value of rolling a dice.
-
#updatePlayer(player) ⇒ Object
To update the values of the array of values get it from rolling the dices.
-
#validNumberPlayer ⇒ Object
To validate the number of player that will play.
Constructor Details
#initialize ⇒ Board
Returns a new instance of Board.
12 13 14 |
# File 'lib/Board.rb', line 12 def initialize 'Write game.menu to start the game' end |
Instance Method Details
#capturePlayer(numberOfPlayer) ⇒ Object
To capture the name of the player
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/Board.rb', line 59 def capturePlayer(numberOfPlayer) loop do player = Player.new puts '---------------------------' print "Name of player ##{numberOfPlayer} : ".colorize(:green) player.name = gets.chomp.capitalize player.score = 0 player.arrayV = [] return player if player.name != nil and @@scoreTable.checkName(@@listPlayer,player.name) end end |
#frase ⇒ Object
To change the quote of the play
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/Board.rb', line 130 def frase option = 0 loop do option = (rand * 5.5).to_i break if option > 0 end case option when 1 return "Amazing! " when 2 return "Good roll! " when 3 return "Incredible! " when 4 return "Good movement! " when 5 return "Are you cheating? " end end |
#game ⇒ Object
To control all the flow of the game
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/Board.rb', line 72 def game player = 0 dices = 5 winner = -1 @@scoreTable.displayPoints( @@listPlayer ) loop do dices.times{ @@listPlayer[ player ].arrayV << rollDice } @@listPlayer[ player ].arrayV.sort! @@scoreTable.displayTurn(@@listPlayer, player) dices = updatePlayer( player ) player+=1 if dices == 0 dices = 5 if dices == 0 player = 0 if player >= @@listPlayer.length winner = @@scoreTable.winner(@@listPlayer) break if winner >= 0 2.times { puts "\n " } end @@scoreTable.celebrate(winner,@@listPlayer) system('clear') puts "~~~~~~~~~~~~~~~~ Thanks for playing ~~~~~~~~~~~~~~~~~" puts "~~~~~~~~~~~~~ Gem created by rubiocanino ~~~~~~~~~~~~~" puts "" end |
#menu ⇒ Object
To control the start of the game and the ending
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/Board.rb', line 17 def () system('clear') puts '==================== M E N U ===================='.colorize(:light_blue) puts " Press enter to start".colorize(:green) gets.chomp @@support.help numberPlayers sleep (0) game return "Finishing the game" end |
#numberPlayers ⇒ Object
To get started with the players and their profiles
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/Board.rb', line 32 def numberPlayers list = [] system('clear') numberPlayer = validNumberPlayer 3.times {puts "\n"} i = 1 numberPlayer.times do |player| player = capturePlayer(i) @@listPlayer << player i+=1 end @@scoreTable.displayListPlayer(@@listPlayer) return "Validation of players" end |
#rollDice ⇒ Object
To got the value of rolling a dice
120 121 122 123 124 125 126 127 |
# File 'lib/Board.rb', line 120 def rollDice value = 1 loop do value = (rand * 6.5).to_i break if value >0 end return value end |
#updatePlayer(player) ⇒ Object
To update the values of the array of values get it from rolling the dices
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/Board.rb', line 97 def updatePlayer(player) puts "\n" print "#{ frase } | " print " #{@@listPlayer[player].name }".colorize(:green) print " you roll : " valuesOfRoll = @@listPlayer[player].arrayV p valuesOfRoll arrayValuesPoints = @@scoreTable.evaluate(@@listPlayer, player) scoreRolling = arrayValuesPoints.pop print "You got : " print "#{scoreRolling}".colorize(:green) if scoreRolling > 0 print "#{scoreRolling}".colorize(:red) if scoreRolling == 0 print " points " gets.chomp @@listPlayer[ player ].score += scoreRolling dices = arrayValuesPoints.length @@listPlayer[ player ].arrayV = [] dices = 0 if scoreRolling == 0 @@listPlayer[ player ].score = 0 if @@listPlayer[ player ].score < 300 and dices == 0 return dices end |
#validNumberPlayer ⇒ Object
To validate the number of player that will play
48 49 50 51 52 53 54 55 56 |
# File 'lib/Board.rb', line 48 def validNumberPlayer numberPlayer = 0 loop do print "How many players? | " numberPlayer = gets.chomp.to_i @@support.help if numberPlayer == 0 return numberPlayer if numberPlayer != nil and numberPlayer > 1 end end |