Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- puts 'Press "r" and then "enter" to roll dice or "q" and then "enter" to quit or "s" and enter to see score'
- @ones = []
- @twos = []
- @threes = []
- @fours = []
- @fives = []
- @sixes = []
- @three_of_a_kind = []
- @four_of_a_kind = []
- @full_house = []
- @chance = []
- @small_straight = []
- @large_straight = []
- @yahtzee = []
- while true
- if @ones.first.nil? == true
- @ones_score = 0
- else
- @ones_score = @ones.first
- end
- if @twos.first.nil? == true
- @twos_score = 0
- else
- @twos_score = @twos.first
- end
- if @threes.first.nil? == true
- @threes_score = 0
- else
- @threes_score = @threes.first
- end
- if @fours.first.nil? == true
- @fours_score = 0
- else
- @fours_score = @fours.first
- end
- if @fives.first.nil? == true
- @fives_score = 0
- else
- @fives_score = @fives.first
- end
- if @sixes.first.nil? == true
- @sixes_score = 0
- else
- @sixes_score = @sixes.first
- end
- if @three_of_a_kind.first.nil? == true
- @three_of_a_kind_score = 0
- else
- @three_of_a_kind_score = @three_of_a_kind.first
- end
- if @four_of_a_kind.first.nil? == true
- @four_of_a_kind_score = 0
- else
- @four_of_a_kind_score = @four_of_a_kind.first
- end
- if @full_house.first.nil? == true
- @full_house_score = "You don't have a full house"
- @full_house_points = 0
- else
- @reduce_full_house = @full_house.reduce :+
- if @reduce_full_house == 5
- @full_house_points = 25
- @full_house_score = "You have a full house"
- else
- @full_house_score = "You saved something but it's not a full house"
- @full_house_points = 0
- end
- end
- if @small_straight.first.nil? == true
- @small_straight_score = "You don't have a small straight"
- @small_straight_points = 0
- else
- @reduce_small_straight = @small_straight.reduce :+
- if @reduce_small_straight == 3
- @small_straight_score = "You have a small straight"
- @small_straight_points = 30
- else
- @small_straight_score = "You saved something but it's not a small straight"
- @small_straight_points = 0
- end
- end
- if @large_straight.first.nil? == true
- @large_straight_score = "You don't have a large straight"
- @large_straight_points = 0
- else
- @reduce_large_straight = @large_straight.reduce :+
- if @reduce_large_straight == 4
- @large_straight_score = "You have a large straight"
- @large_straight_points = 40
- else
- @large_straight_score = "You saved something but it's not a large straight"
- @large_straight_points = 0
- end
- end
- if @chance.first.nil? == true
- @chance_score = "You haven't saved chance yet"
- @chance_points = 0
- else
- @chance_score = "Your chance is #{@chance.first}"
- @chance_points = @chance.first
- end
- if @yahtzee.first.nil? == true
- @yahtzee_score = "You don't have Yahtzee :("
- @yahtzee_points = 0
- else
- @yahtzee_points = 50
- @yahtzee_score = "You have Yahtzee:)"
- end
- input = gets.chomp
- break if input == 'q'
- if input == 's'
- @points = (@ones_score.to_i * 1) + (@twos_score.to_i * 2) + (@threes_score.to_i * 3) + (@fours_score.to_i * 4) + (@fives_score.to_i * 5) + (@sixes_score.to_i * 6) + (@three_of_a_kind_score.to_i * 3) + (@four_of_a_kind_score.to_i * 4) + @full_house_points + @chance_points + @small_straight_points + @large_straight_points + @yahtzee_points
- puts "You have #{@ones_score} ones"
- puts "You have #{@twos_score} twos"
- puts "You have #{@threes_score} threes"
- puts "You have #{@fours_score} fours"
- puts "You have #{@fives_score} fives"
- puts "You have #{@sixes_score} sixes"
- puts "You have #{@three_of_a_kind_score}'s as your three of a kind"
- puts "You have #{@four_of_a_kind_score}'s as your four of a kind"
- puts "#{@full_house_score}"
- puts "#{@large_straight_score}"
- puts "#{@small_straight_score}"
- puts "#{@chance_score}"
- puts "#{@yahtzee_score}"
- puts "Your current total points = #{@points}"
- print "High Score: "
- File.open("high_score.txt", "r") do |f|
- f.each_line do |line|
- if @points > line.to_i
- File.open("high_score.txt", "w") do |file|
- file.puts @points
- end
- end
- end
- end
- File.open("high_score.txt", "r") do |f|
- f.each_line do |line|
- puts line
- end
- end
- puts '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
- puts 'Type "r" and hit enter to roll again'
- elsif input == 'r'
- @random = 5.times.map{ 1 + Random.rand(6) }
- puts '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
- puts 'New Roll:'
- puts @random
- puts '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
- puts 'If you want to reroll some dice type the order number of the dice you wish to keep separated by a comma for example "1,3" would reroll all the dice except for the first and third. If you want to keep the entire roll type "skip". If you want to reroll all the dice type "reroll" and push enter.'
- 2.times do |num|
- dice_keep = gets.chomp
- if dice_keep.to_i != 0
- @save_dice = dice_keep.split(',')
- @save_dice.map! do |dice|
- dice.to_i - 1
- end
- @save_dice.map! do |reroll|
- @random[reroll]
- end
- @reroll_amnt = 5 - @save_dice.length
- @random = @reroll_amnt.times.map{ 1 + Random.rand(6) }
- @save_dice.each do |move|
- @random.unshift(move)
- end
- puts '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
- puts 'Updated Roll:'
- puts @random
- puts '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
- elsif dice_keep == "skip"
- puts '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
- puts @random
- puts '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
- elsif dice_keep == "reroll"
- @random = 5.times.map{ 1 + Random.rand(6) }
- puts '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
- puts "Reroll:"
- puts @random
- puts '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
- end
- if num != 1
- puts 'If you want to reroll some dice type the order number of the dice you wish to keep separated by a comma for example "1,3" would reroll all the dice except for the first and third. If you want to keep the entire roll type "skip". If you want to reroll all the dice type "reroll" and push enter.'
- end
- end
- puts 'Save 1s by typing "ones" and pressing enter'
- puts 'Save 2s by typing "twos" and pressing enter'
- puts 'Save 3s by typing "threes" and pressing enter'
- puts 'Save 4s by typing "fours" and pressing enter'
- puts 'Save 5s by typing "fives" and pressing enter'
- puts 'Save 6s by typing "sixes" and pressing enter'
- puts 'Save three of a kind by typing "three of a kind" and pressing enter'
- puts 'Save four of a kind by typing "four of a kind" and pressing enter'
- puts 'Save a full house by typing "full house" and pressing enter'
- puts 'Save a small straight by typing "small straight" and pressing enter'
- puts 'Save a large straight by typing "large straight" and pressing enter'
- puts 'Save chance by typing "chance" and pressing enter'
- puts 'Save Yahtzee by typing "yahtzee" and pressing enter'
- save_num = gets.chomp
- if save_num == 'ones'
- @ones.push(@random.count(1))
- puts "You saved #{@random.count(1)} ones"
- puts '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
- @random = nil
- puts 'Type "r" and push enter to roll again and "s" and then enter to see score'
- elsif save_num == 'twos'
- @twos.push(@random.count(2))
- puts "You saved #{@random.count(2)} twos"
- puts '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
- @random = nil
- puts 'Type "r" and push enter to roll again and "s" and then enter to see score'
- elsif save_num == 'threes'
- @threes.push(@random.count(3))
- puts "You saved #{@random.count(3)} threes"
- puts '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
- @random = nil
- puts 'Type "r" and push enter to roll again and "s" and then enter to see score'
- elsif save_num == 'fours'
- @fours.push(@random.count(4))
- puts "You saved #{@random.count(4)} fours"
- puts '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
- @random = nil
- puts 'Type "r" and push enter to roll again and "s" and then enter to see score'
- elsif save_num == 'fives'
- @fives.push(@random.count(5))
- puts "You saved #{@random.count(5)} fives"
- puts '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
- @random = nil
- puts 'Type "r" and push enter to roll again and "s" and then enter to see score'
- elsif save_num == 'sixes'
- @sixes.push(@random.count(6))
- puts "You saved #{@random.count(6)} sixes"
- puts '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
- @random = nil
- puts 'Type "r" and push enter to roll again and "s" and then enter to see score'
- elsif save_num == 'three of a kind'
- # Note didn't work with times do, look into why
- @numbers = (1..6).to_a
- @numbers.each do |kind|
- if @random.count(kind) == 3
- @three_of_a_kind.push(kind)
- end
- end
- puts "You saved #{@three_of_a_kind}'s as your three of a kind"
- puts '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
- @random = nil
- puts 'Type "r" and push enter to roll again and "s" and then enter to see score'
- elsif save_num == 'four of a kind'
- @numbers = (1..6).to_a
- @numbers.each do |kind|
- if @random.count(kind) == 4
- @four_of_a_kind.push(kind)
- end
- end
- puts "You saved #{@four_of_a_kind}'s as your four of a kind"
- puts '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
- @random = nil
- puts 'Type "r" and push enter to roll again and "s" and then enter to see score'
- elsif save_num == 'large straight'
- @random_sorted = @random.sort
- @random_sorted.each_cons(2) do |cons|
- if cons[1] == cons[0] + 1
- @large_straight.push(1)
- end
- end
- @reduce_large_straight = @large_straight.reduce :+
- if @reduce_large_straight == 4
- puts "You saved a large straight."
- else
- puts "You saved something in the large straight category, but it's not a large straight."
- end
- puts '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
- @random = nil
- puts 'Type "r" and push enter to roll again and "s" and then enter to see score'
- elsif save_num == 'small straight'
- @random_sorted = @random.sort
- @random_sorted.each_cons(2) do |cons|
- if cons[1] == cons[0] + 1
- @small_straight.push(1)
- end
- end
- @reduce_small_straight = @small_straight.reduce :+
- if @reduce_small_straight == 3
- puts "You saved a small straight."
- else
- puts "You saved something in the small straight category, but it's not a small straight."
- end
- puts 'Type "r" and push enter to roll again and "s" and then enter to see score'
- elsif save_num == 'chance'
- @reduce_chance = @random.reduce :+
- @chance.push(@reduce_chance)
- puts "Your chance score is #{@reduce_chance}"
- puts '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
- @random = nil
- puts 'Type "r" and push enter to roll again and "s" and then enter to see score'
- elsif save_num == 'yahtzee'
- @numbers = (1..6).to_a
- @numbers.each do |kind|
- if @random.count(kind) == 5
- @yahtzee.push(kind)
- end
- end
- if @yahtzee.first.nil? == true
- puts "You saved something in your yahtzee category, but it wasn't a yahtzee"
- else
- puts "You saved your Yahtzee!!!"
- end
- puts '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
- @random = nil
- puts 'Type "r" and push enter to roll again and "s" and then enter to see score'
- elsif save_num == 'full house'
- @numbers = (1..6).to_a
- @numbers.each do |kind|
- if @random.count(kind) == 3
- @full_house.push(3)
- binding
- end
- if @random.count(kind) == 2
- @full_house.push(2)
- end
- end
- @reduce_full_house = @full_house.reduce :+
- if @reduce_full_house == 5
- puts "You got a Full House."
- else
- puts "You saved something as a full house but sadly it's not a full house."
- end
- puts '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
- @random = nil
- puts 'Type "r" and push enter to roll again and "s" and then enter to see score'
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement