-
Notifications
You must be signed in to change notification settings - Fork 0
/
high_card.rb
71 lines (63 loc) · 1.75 KB
/
high_card.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
class HighCard
attr_accessor :deck
SUITS = ["Clubs", "Diamonds", "Hearts", "Spades"]
VALUES = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"]
def initialize
@deck = []
@comp_score = 0
@player_score = 0
@game_count = 0
SUITS.each do |suit|
VALUES.each do |value|
@deck << (value + " of " + suit)
end
end
end
def draw_card
unless @deck.empty?
@card = @deck.sample
@deck.delete(@card)
puts "You drew #{@card}"
return @card
end
end
def draw_computer
unless @deck.empty?
@comp_card = @deck.sample
@deck.delete(@comp_card)
puts "Computer drew #{@comp_card}"
return @comp_card
end
end
def deal
@game_count += 1
puts "Game " + @game_count.to_s
draw = draw_card.split(" ")
comp_draw = draw_computer.split(" ")
draw_value = VALUES.index(draw[0])
comp_value = VALUES.index(comp_draw[0])
if draw_value > comp_value
@player_score += 1
puts "Winner! You got the high card!\nPlayer - #{@player_score}\nComputer - #{@comp_score}"
elsif draw_value < comp_value
@comp_score += 1
puts "Womp, Womp. Computer got the high card!\nPlayer - #{@player_score}\nComputer - #{@comp_score}"
else
if SUITS.index(draw[2]) > SUITS.index(comp_draw[2])
@player_score += 1
puts "Winner! You got the high suit!\nPlayer - #{@player_score}\nComputer - #{@comp_score}"
else
@comp_score += 1
puts "Womp, Womp. Computer got the high suit!\nPlayer - #{@player_score}\nComputer - #{@comp_score}"
end
end
puts "*********************"
end
def full_deck
until @deck.empty?
deal
end
end
end
game = HighCard.new
game.full_deck