-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhorse_race.rb
executable file
·109 lines (90 loc) · 2.71 KB
/
horse_race.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
require './new_cards.rb'
COLUMN_HEIGHT = 10
def aceless_deck
deck = Deck.new
deck.add_deck
deck.cards.delete_at 12
deck.cards.delete_at 24
deck.cards.delete_at 36
deck.cards.delete_at 48
deck
end
def print_grid
COLUMN_HEIGHT.times do |i|
print_heart = @ace_heights['Heart'] == i
print_diamond = @ace_heights['Diamond'] == i
print_club = @ace_heights['Club'] == i
print_spade = @ace_heights['Spade'] == i
# tops of cards
print "+-+ "
print print_heart ? "+-+" : " "
print print_diamond ? "+-+" : " "
print print_club ? "+-+" : " "
print print_spade ? "+-+" : " "
print "\n"
# card body
# column
if i > @current_col
print "|#{@column[i].suit.to_c}| "
else
print "|*| "
end
print print_heart ? "|h|" : " "
print print_diamond ? "|d|" : " "
print print_club ? "|c|" : " "
print print_spade ? "|s|" : " "
print "\n"
# card bottoms
print "+-+ "
print print_heart ? "+-+" : " "
print print_diamond ? "+-+" : " "
print print_club ? "+-+" : " "
print print_spade ? "+-+" : " "
print "\n"
end
end
deck = aceless_deck
deck.shuffle
@column = Deck.new
COLUMN_HEIGHT.times do
@column << deck.draw
end
@ace_heights = { 'Heart' => COLUMN_HEIGHT-1,
'Diamond' => COLUMN_HEIGHT-1,
'Club' => COLUMN_HEIGHT-1,
'Spade' => COLUMN_HEIGHT-1 }
@ace_peaks = { 'Heart' => COLUMN_HEIGHT-1,
'Diamond' => COLUMN_HEIGHT-1,
'Club' => COLUMN_HEIGHT-1,
'Spade' => COLUMN_HEIGHT-1 }
@current_col = COLUMN_HEIGHT - 1
puts "Game Start"
print_grid
puts "Press enter to draw first card..."
input = gets
while @ace_heights['Heart'] < COLUMN_HEIGHT &&
@ace_heights['Diamond'] < COLUMN_HEIGHT &&
@ace_heights['Club'] < COLUMN_HEIGHT &&
@ace_heights['Spade'] < COLUMN_HEIGHT
deck = aceless_deck if deck.size == 0
current_card = deck.draw
@ace_heights[current_card.suit.to_s] -= 1
@ace_peaks[current_card.suit.to_s] -= 1
if @ace_peaks['Heart'] < @current_col &&
@ace_peaks['Diamond'] < @current_col &&
@ace_peaks['Club'] < @current_col &&
@ace_peaks['Spade'] < @current_col &&
@ace_heights['Heart'] < @current_col &&
@ace_heights['Diamond'] < @current_col &&
@ace_heights['Club'] < @current_col &&
@ace_heights['Spade'] < @current_col
puts "Decrementing #{@column[@current_col].suit.to_s}"
@ace_heights[@column[@current_col].suit.to_s] += 1
@current_col -= 1
end
puts "\n\n\n\n"
puts "Card Drawn: #{current_card}"
print_grid
puts "Press enter to draw next card..."
input = gets
end