Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 0 additions & 80 deletions blackjack/test.rb
Original file line number Diff line number Diff line change
@@ -1,80 +0,0 @@
require 'pry'
# require './cards.rb'
# # require './aces.rb'
# require './wallet.rb'
# Deck.new
#
# Wallet.new

class DealCard

def initialize
random
bets
playing
winner
end
def random
@numbers = [2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 11]
@house = @numbers.sample(2)
@dealercards = @house.reduce(:+)
end
def hit
puts "your total is #{@playercards} press one if you want to hit?"
take_hit = gets.to_i
case take_hit
when 1
@the_hit = @numbers.sample(1)
@the_hit << @playercards
@hit_total = @the_hit.reduce(:+)
puts "you new total is #{@hit_total}"
end
end
def bets
new_num = [2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 11]
@gambler = new_num.sample(2)
@playercards = @gambler.reduce(:+)
end

def playing
puts "press 1, lets play"
puts "press 2 to exit"
input = gets.to_i
case input
when 1
hand
when 2
exit
end
end
def hand
puts "your cards are #{@gambler}"
sleep(0.5)
hit
dealer_hand
end
def dealer_hand
puts "dealers cards are #{@house.first} shows #{@dealercards}"
sleep(0.5)
end
def winner

case
when @playercards < @dealercards
puts "dealer wins"
when @playercards > @dealercards
puts "player wins"
when @dealercards > 21
puts "dealer busted"
when @playercards > 21
puts "player busted"
when @playercards == @dealercards
puts "its a tie"
else
puts "else puts wierd"
end
end
end


@deal = DealCard.new
56 changes: 14 additions & 42 deletions blackjack/wallet.rb
Original file line number Diff line number Diff line change
@@ -1,43 +1,15 @@
#
# def compare
# dealer_hand = 21
# hand = 21
# winner
# end
# def winner
# case compare
# when dealer_hand >= hand
# puts "dealer wins"
# when dealer_hand > hand
# puts "dealer busted"
# when dealer_hand < hand
# puts "player wins"
# when dealer_hand < hand
# puts "player busted"
# when
# dealer_hand == 21
# puts "dealer hit 21"
# else hand == 21
# puts "player hit 21"
# end
# end
# puts winner
def basic
@hand = 20
@dealer =
case
when hand < dealer
puts "dealer wins"
when hand > dealer
puts "player wins"
when dealer > 21
puts "dealer busted"
when hand > 21
puts "player busted"
else
puts "its a tie"


class Wallet
def initialize
@wallet = 500
end
def view_balance
puts
puts "Your current balance is #{@wallet}"
end
def decrease_balance(amount)
@wallet -= amount
end
def increase_balance(amount)
@wallet += amount
end
end
end
puts basic
19 changes: 9 additions & 10 deletions blackjack/blackjack.rb → classes/blackjack.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
require 'pry'
# require './cards.rb'
# # require './aces.rb'
# require './wallet.rb'
require './wallet.rb'
# Deck.new
#
# Wallet.new

class DealCard
class DealCard < Wallet
puts "your current balance is#{}"

def initialize
random
Expand All @@ -23,8 +24,7 @@ def random

@house_hit = @numbers.sample(1)
@dealer_after_hit = @house.concat(@house_hit)
@dealer_total = @dealer_after_hit.reduce(:+) || @dealercard.reduce(:+)
binding.pry
@dealer_total = @dealer_after_hit.reduce(:+)
end
end
def hit
Expand Down Expand Up @@ -84,12 +84,11 @@ def dealer_hand
end
def winner
puts "the dealers total is #{@dealer_total || @dealercards}"
win_num = 21
case
when @dealer_total > win_num
@win_num = 21
case @win_num
when @dealer_total > @win_num
puts "dealer busted"
when @hit_total > win_num
binding.pry
when @hit_total > @win_num
puts "player busted"
when @hit_total < @dealer_total
puts "dealer wins"
Expand All @@ -98,7 +97,7 @@ def winner
when @hit_total == @dealer_total
puts "its a tie"
else
puts "wierd"
puts "both of you busted"
end
end
end
Expand Down
29 changes: 29 additions & 0 deletions classes/rps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
puts "chose r s or p"


computer = "rsp"[rand(3)].chr

player = $stdin.gets.chomp.downcase

case [ player, computer]

when ['r', 's'], ['s', 'p'], ['r', 's']

puts "You win"

when ['r', 'r'], ['s', 's'], ['p', 'p']
puts "you tied"

when ['r', 'p'], ['s', 'r'], ['p', 's']
puts " you lose"
end

puts "the computer chose: #{computer.upcase}"

rsp = {
1 => "rock",
2 => "paper",
3 => "scissors",

}
puts rsp[1]