-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeck-of-cards.rb
More file actions
116 lines (108 loc) · 2.28 KB
/
deck-of-cards.rb
File metadata and controls
116 lines (108 loc) · 2.28 KB
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
puts 'Welcome to the Casino!'
def array_gen(array)
suits = ['Spades', 'Hearts', 'Diamonds', 'Clubs']
cards = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King']
array = []
count = 0
count2 = 0
count3 = 0
while count < 4
while count2 < 13
hash = { suit: suits[count], card: cards[count2], dealt: false}
array.push(hash)
#puts array[count3][:suit]
count2 += 1
count3 += 1
end
count += 1
count2 = 0
end
return array
end
def draw(array, cards)
number = rand(52)
if cards == 0
puts 'There are no more cards in the deck!'
elsif array[number][:dealt] == true
draw(array, cards)
else
array[number][:dealt] = true
puts '*' * 60
puts '*' * 60
print 'You drew '
puts array[number][:card] + ' of ' + array[number][:suit]
puts '*' * 60
puts '*' * 60
return array[number]
end
end
def gameloop(array, user, cards)
def view_deck(array)
count3 = 0
while count3 < 52
if array[count3][:dealt] == false
puts array[count3][:card] + ' of ' + array[count3][:suit]
else
end
count3 += 1
end
end
puts 'v - View Deck'
puts 's - Shuffle Deck'
puts 'd - Draw a Card'
puts 'h - View Hand'
puts 'q - Quit'
print 'What would you like to do? '
input = gets.chomp
input.downcase!
if input == 'v'
puts '*' * 60
puts '*' * 60
view_deck(array)
puts '*' * 60
puts '*' * 60
puts '-------'
gameloop(array, user, cards)
elsif input == 's'
puts '*' * 60
puts '*' * 60
array = array.sort_by{rand}
puts 'The deck has been shuffled!'
puts '*' * 60
puts '*' * 60
puts '-------'
gameloop(array, user, cards)
elsif input == 'd'
user.push(draw(array, cards))
cards = cards - 1
puts '-------'
gameloop(array, user, cards)
elsif input == 'h'
puts '*' * 60
puts '*' * 60
puts "You have #{52-cards} cards in your hand!"
puts 'Your hand includes the following:'
count3 = 0
while count3 < 52
if array[count3][:dealt] == true
puts array[count3][:card] + ' of ' + array[count3][:suit]
else
end
count3 += 1
end
puts '*' * 60
puts '*' * 60
puts '-------'
gameloop(array, user, cards)
elsif input == 'q'
puts 'Goodbye!'
else
puts 'Please enter a valid input!'
gameloop(array, user, cards)
end
end
array = []
user = []
cards = 52
array = array_gen(array)
gameloop(array, user, cards)