class Player

Constants

ScoreAbbr

Attributes

score[R]

Public Class Methods

new() click to toggle source
# File lib/player.rb, line 24
def initialize
        @score = ScoreSheet.new
end

Public Instance Methods

display_dice(i) click to toggle source

@param i [Fixnum] times rolled @return [String]

end

# File lib/player.rb, line 45
def display_dice(i)
        sleep 0.5
        result = String.new
        result << String.new.center(80, ?-) + ?\n 
        result << "Here are your dice. You have have #{3-i} #{i==2? "roll":"rolls"} remaining.\n\n\n"
        result << "\tDice\t\tZ\tX\tC\tV\tB" + ?\n
        result << "\tValues\t\t" + score.dice.values.map{|value| value.to_s}.join(?\t) + ?\n
        result << String.new.center(80, ?-) + ?\n
        return result
end
take_turn() click to toggle source

@todo finish method @return [void]

end

# File lib/player.rb, line 32
def take_turn
        turn_over = false
        (1..3).each do |i|
                puts display_dice i
                turn_over = user_input i 
                break if turn_over
        end
end
user_input(i) click to toggle source

@param i [Fixnum] Amount of times rolled @return [Boolean] @note Gameplay

end

# File lib/player.rb, line 61
def user_input(i)

        print_instructions i

        input = gets.chomp.downcase
        user_input = Set.new(input.split(''))
        dice_controls = Set.new("zxcvb".split(''))

        # If user wants to enter score
        if ScoreAbbr.keys.include? input.to_sym
                user_enter_score input.to_sym, i
        # Else if user wants to roll the dice
        elsif i < 3 && (user_input.subset? dice_controls)
                user_roll_dice input, dice_controls
        else
                invalid_input
        end
end

Private Instance Methods

invalid_input() click to toggle source
# File lib/player.rb, line 116
def invalid_input
        puts "Invalid input. Please try again."
        sleep 1.5
        puts ?\n
        user_input i
end
print_instructions(i) click to toggle source

Private methods need to be indented properly

user_enter_score(input_symbol, i) click to toggle source
# File lib/player.rb, line 90
def user_enter_score input_symbol, i
        field = ScoreAbbr[input_symbol]
        @score.enter_score field
        puts score
        @score.dice.roll_all
        sleep 2
        return true
rescue
        puts "\n"
        sleep 0.5
        puts " You have already entered a score for that category. Try again. ".center(80, '!')
        sleep 1.5
        puts "\n"
        user_input i
end
user_roll_dice(input, dice_controls) click to toggle source
# File lib/player.rb, line 106
def user_roll_dice input, dice_controls
        dice_to_roll = (0..4).to_a.select { |index| input.include? dice_controls.to_a[index]}
        @score.dice.roll(dice_to_roll)
        sleep 0.5
        2.times {puts ?\n}
        puts " Rolling Dice!\ ".center 80, "* "
        sleep 1
        return false 
end