Created
April 20, 2022 23:10
-
-
Save caioertai/85c9f340174f1d21a94fc7797d56e265 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SlotMachine | |
VALUES = %w[x cherry seven bell star joker] | |
def initialize(slots) | |
@slots = slots | |
end | |
def play | |
@slots = [ | |
VALUES[1..-1].sample, | |
VALUES[1..-1].sample, | |
VALUES[1..-1].sample | |
] | |
end | |
def score | |
case @slots.uniq.count | |
when 1 | |
element = @slots.first | |
VALUES.index(element) * 10 | |
when 2 | |
return 0 unless @slots.include?("joker") | |
element = @slots.sort[1] | |
VALUES.index(element) * 5 | |
when 3 | |
0 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment