-
Notifications
You must be signed in to change notification settings - Fork 3
/
FTD.rb
138 lines (118 loc) · 2.65 KB
/
FTD.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
class FTD
DEALER_DRINKS = 5
MAX_GETS = 3
MAX_GUESSES = 2
attr_accessor :table, :deck, :players
attr_reader :complete, :gets, :guess_count
def initialize
start_fresh
end
def start_fresh
@deck = Deck.new
@deck.add_deck
@deck.shuffle
@table = Deck.new
@players = Player_Bench.new
@current_card = @deck.draw
@guess_count = 0
@prev_guesses = Array.new
@gets = 0
@complete = false
end
def player
@players[player_i]
end
def player_i
@players.actors[:player]
end
def dealer
@players[dealer_i]
end
def dealer_i
@players.actors[:dealer]
end
def guess(guess)
guess = case guess
when /j/i then 11
when /q/i then 12
when /k/i then 13
when /a/i then 14
else guess
end
guess = Card.new(guess.to_i-2, 1)
@prev_guesses.push(guess)
@guess_count += 1
if @current_card < guess
return -1
elsif @current_card > guess
return 1
else
return 0
end
end
def end_turn
last_guess = @prev_guesses.pop
turn_results = Hash.new(0)
turn_results[:next_dealer] = false
if @current_card.rank.to_n == last_guess.rank.to_n
turn_results[:dealers_drinks] = (MAX_GUESSES - @guess_count+1) * DEALER_DRINKS
dealer.add_drinks(turn_results[:dealers_drinks])
@gets = 0
if(@guess_count == 1)
puts "Bullseye"
player.got_bullseye
else
puts "Correct"
player.was_correct
end
else
turn_results[:players_drinks] = (last_guess.rank.to_n - @current_card.rank.to_n).abs
player.add_drinks(turn_results[:players_drinks])
@gets += 1
puts "Just turn"
player.just_turn
end
if(@gets >= MAX_GETS)
turn_results[:next_dealer] = true
@gets = 0
end
@guess_count = 0
turn_results[:card_string] = @current_card.to_s
@table.place @current_card
if(@deck.size > 0)
@current_card = @deck.draw
else
@complete = true
end
turn_results
end
def status
table_counts = Hash.new(0)
@table.each do |card|
table_counts[card.rank.to_c] += 1
end
#puts table_counts
output = "\nPlayed Cards:\n"
(0..13).each { output += "-" }
output += "\n"
(1..4).each do |row|
Rank::CHARS.each do |rank|
if(table_counts[rank] >= row)
if(table_counts[rank] == 4)
output += "X"
else
output += rank.to_s
end
else
rank.to_s.length.times do
output += " "
end
end
end
output += "\n"
end
(0..13).each { output += "-" }
output += "\n"
output
end
end