class Board

Public Class Methods

new() click to toggle source
# File lib/Board.rb, line 12
def initialize
  'Write game.menu to start the game'
end

Public Instance Methods

capturePlayer(numberOfPlayer) click to toggle source

To capture the name of the player

# 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() click to toggle source

To change the quote of the play

# 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() click to toggle source

To control all the flow of the game

# 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() click to toggle source

To control the start of the game and the ending

numberPlayers() click to toggle source

To get started with the players and their profiles

# 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() click to toggle source

To got the value of rolling a dice

# 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) click to toggle source

To update the values of the array of values get it from rolling the dices

# 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() click to toggle source

To validate the number of player that will play

# 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