Skip to content

Instantly share code, notes, and snippets.

@smitfire
Last active December 20, 2015 00:19
Show Gist options
  • Save smitfire/6040881 to your computer and use it in GitHub Desktop.
Save smitfire/6040881 to your computer and use it in GitHub Desktop.
Blackspot drinking game. Ruby file
class Card
def deck
num = [2,3,4,5,6,7,8,9,10,"Jack","Queen","King","Ace"]
suit = ["spade", "club", "heart", "diamond"]
d = num.product(suit).shuffle
end
end
class Game
def initialize
@lb = "-------------------------------------------------"
c = Card.new
cd = c.deck
print "How many players? "
@pnum = gets.to_i
players = []
@pnum.times do
print "Enter your name "
name = gets.to_s.chomp
hand = cd.slice!(0..3)
players << name << hand
end
@s = []
players.each_slice(2) {|a| @s << a }
end
def play
p "<=========== ROUND ONE ==============>"
move_one
p "<=========== ROUND TWO ==============>"
move_two
p "<=========== ROUND THREE ==============>"
move_three
p "<=========== ROUND FOUR ==============>"
move_four
p "<==========Thanks for drinking===========>"
end
def move_one
# p @s
@s.each do |si|
cards = []
si[1].each_slice(1) {|cc| cards << cc[0..3]}
cards = cards.flatten(1)
c1 = cards[0]
c1s = c1[1]
cards.each do |ci|
if ci[0] == "Jack"
ci << 11
elsif ci[0] == "Queen"
ci << 12
elsif ci[0] == "King"
ci << 13
elsif ci[0] == "Ace"
ci << 15
else
ci << ci[0]
end
end
c1n = c1[2]
c1c = c1[0..1]
p "#{si[0]} guess whether your card is black or red? "
guess = gets.to_s.chomp
p @lb
if guess == "red" && ( c1s == "heart" || c1s == "diamond" )
p "#{si[0]} guessed right. #{si[0]} has a #{c1c}. #{si[0]} gives out #{c1n}"
p @lb
elsif guess == "black" && (c1s == "spade" || c1s == "club" )
p "#{si[0]} guessed right. #{si[0]} has a #{c1c}. #{si[0]} gives out #{c1n}"
p @lb
else
p "#{si[0]} has a #{c1c}. #{si[0]} must Drink #{c1n} fingers of the SAUCCCEEE"
p @lb
end
end
end
def move_two
@s.each do |si|
cards = []
si[1].each_slice(1) {|cc| cards << cc[0..3]}
cards = cards.flatten(1)
c1 = cards[0]
c2 = cards[1]
c1n = c1[2]
c2n = c2[2]
c1c = c1[0..1]
c2c = c2[0..1]
p "#{si[0]}'s first card is #{c1c}"
p "#{si[0]} guess whether your second card will be higher, lower, or the same "
guess = gets.to_s.chomp
p @lb
if guess == "higher" && (c2n > c1n)
p "CORRECT! #{si[0]}'s second card is #{c2c}. Hand out #{c2n} fingers!"
p @lb
elsif guess == "lower" && (c2n < c1n)
p "CORRECT! #{si[0]}'s second card is #{c2c}. Hand out #{c2n} fingers!"
p @lb
elsif guess == "same" && (c2n == c1n)
p "CORRECT! #{si[0]}'s second card is #{c2c}. Hand out #{c2n} fingers!"
p @lb
elsif guess == "higher" && (c2n <= c1n)
p "WRONG! #{si[0]}'s second card is #{c2c}. DRINK #{c2n} fingers!"
p @lb
elsif guess == "lower" && (c2n >= c1n)
p "WRONG! #{si[0]}'s second card is #{c2c} DRINK #{c2n} fingers!"
p @lb
end
end
end
def move_three
@s.each do |si|
cards = []
si[1].each_slice(1) {|cc| cards << cc[0..3]}
cards = cards.flatten(1)
c1 = cards[0]
c2 = cards[1]
c3 = cards[2]
c1n = c1[2]
c2n = c2[2]
c3n = c3[2]
c1c = c1[0..1]
c2c = c2[0..1]
c3c = c3[0..1]
p "#{si[0]}'s first two cards are #{c1c} and #{c2c}"
p "#{si[0]} guess whether your second card will be between, outside, or the same as the card values "
guess = gets.to_s.chomp
p @lb
if guess == "between" && ((c1n < c3n && c3n < c2n) || (c2n < c3n && c3n < c1n))
p "CORRECT! #{si[0]}'s third card is #{c3c}. Hand out #{c3n} fingers!"
p @lb
elsif guess == "outside" && ((c1n > c3n && c3n < c2n) || (c2n < c3n && c3n > c1n))
p "CORRECT! #{si[0]}'s third card is #{c3c}. Hand out #{c3n} fingers!"
p @lb
elsif guess == "same" && (c3n == c1n || c3n == c2n)
p "CORRECT! #{si[0]}'s third card is #{c3c}. Hand out #{c3n} fingers!"
p @lb
else
p "WRONG! #{si[0]}'s third card is #{c3c} DRINK #{c3n} fingers!"
p @lb
end
end
end
def move_four
@s.each do |si|
cards = []
si[1].each_slice(1) {|cc| cards << cc[0..4]}
cards = cards.flatten(1)
c4 = cards[3]
c4l = c4[0]
c4n = c4[2]
c4s = c4[1]
c4c = c4[0..1]
p "#{si[0]} try and guess the suit "
guess = gets.to_s.chomp
p @lb
if guess == c4s
p "#{si[0]} you are the BOMB!. The card is the #{c4l} of #{c4s}'s. Now make the others pay with their sobriety. Give out #{c4n*2} fingers"
p @lb
else
p "#{si[0]} the card is the #{c4l} of #{c4s}'s. You can eat that drink in the amount of #{c4n} fingers"
p @lb
end
end
end
end
g = Game.new
g.play
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment