99_game 3.1.4 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +8 -8
  2. data/bin/99_game +29 -33
  3. data/lib/99_game.rb +5 -7
  4. data/lib/hand.rb +9 -6
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Nzc0ODVkYmEzZmMxYTZjNmMzZGYzMTVjYzM3ZWQ1NWJiNjc1OWZlOQ==
4
+ NDIwODlkMTM2MzQ3NmFkMGRhZWNlZWZlZTAyNDA5YmFhNzYxNTU5ZA==
5
5
  data.tar.gz: !binary |-
6
- OTMzZjU3MTkwYzE0YmJlNDlmYjA4NzdjZTg1YWUxMGJkODc5MzkxOQ==
6
+ ZTk5MmExMWRmOTVhNDlkNGI5Y2Q4NDRmYTJhMzg1YTNmMWY3NTFmMw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NTNhYjk4NGYwNmE4ZjEwOGNkZjdkNDQ1NjU4NGU4YTZjY2ViOTg3NGY0MDZj
10
- YjAzOWEwZjE5YTkxM2VkMDdiNmE3ZDdhNzVhYWU4NGY2NzljYWQzODQ3NzVj
11
- ODlkY2M3NjM1ZjRlYWQ0NGJhM2EwZGI2NDNlYjhkOWVlYmVjMTA=
9
+ NzMzNWE0MzgxZjJkMmQ4YWQyZTA2MDBiNjhlOWYzOWEwMDlmNjg5NjY0ODIw
10
+ ODQwOGYxZWY0OWM5M2NhODkwZWJlNjQzYjdiYmRkYTZjMDcxZjNjYzA3OWQ0
11
+ ZjA0MWU0YmQzZTM3OGM2NzA0NjkyYWUwNjU1NmFhMWRjOTQ1OTc=
12
12
  data.tar.gz: !binary |-
13
- YTE3Nzk5NGEwNDIzZWU3NGNmNTE1ODE1ZGQwNDYxZmIxZTg2NDQxMDJjYWMz
14
- NzE2N2ZiNjk0YjRhYTdlNzBhMmYxZmVmNmY1OWQ2ZGQ4NjNjYjFmNWYxNzJm
15
- NDU0N2M0YjA3NmVlNDNjNjdjOGVlMDcyNjkyYTNkZDYzMzVlN2Q=
13
+ YmMyY2E1ZGU0NmQ4YWJlMzg4MGE5YTIwZjMwMWUwMDQ4NjdiNmQ3M2I3MDA4
14
+ YzQ0MDYxM2Q1OGQ3NDY0YzNlMDRlNTdiNGM5OTM3OTI1ZTVlNjMxYjQ4NGYw
15
+ NmE2Njk1OGJkZmI4MzZmZjEyNDVmNWNiYmFkOGNhMmM5NTNiNDI=
@@ -1,8 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  require '99_game'
3
3
  include CardDeck
4
- deck = Deck.new jokers: true
5
- deck.cards.shuffle!
6
4
  BEGIN { # Looks at its arguements
7
5
  ARGV[0] = "-h" if ARGV.first == "--help"
8
6
  ARGV[0] = "-v" if ARGV[0] == "--version"
@@ -23,56 +21,54 @@ BEGIN { # Looks at its arguements
23
21
  puts "\u00B7 Gameplay"
24
22
  puts "\t\u00B7 Your goal is to get your opponent to bring the value over 99 by playing 1 of your 3 cards."
25
23
  puts "\t\u00B7 A card will usually increase the value by itself, but there are a few exceptions:"
26
- puts "\t\t\u00B7 Aces are worth 1"
27
- puts "\t\t\u00B7 2 - 10 are worth themselves, with the exception of 4 and 9"
28
- puts "\t\t\u00B7 4, 9, and Jacks are worth 0"
29
- puts "\t\t\u00B7 Queens decrease the value by 10"
30
- puts "\t\t\u00B7 Kings set the value to 99"
31
- puts "\t\t\u00B7 Jokers set the value to 0"
24
+ puts "\t\u00B7 Aces are worth 1"
25
+ puts "\t\u00B7 2 - 10 are worth themselves, with the exception of 4 and 9"
26
+ puts "\t\u00B7 4, 9, and Jacks are worth 0"
27
+ puts "\t\u00B7 Queens decrease the value by 10"
28
+ puts "\t\u00B7 Kings set the value to 99"
29
+ puts "\t\u00B7 Jokers set the value to 0"
32
30
  exit
33
31
  end
34
32
  }
35
33
  END { # Thanks for playing
36
34
  sleep 1.5
37
- puts "\n\tThanks for playing 99!"
35
+ puts "\nThanks for playing 99!"
38
36
  sleep 2.5
39
37
  }
40
38
  $value, value1, value2, value3, dealer, user = 0,0,0,0, Hand.new, Hand.new
41
39
  loop do
42
- puts "\n\tIt is the dealer's turn!"
43
- i = 1
40
+ puts "\nIt's the dealer's turn!"
41
+ i = 0
44
42
  for card in dealer.cards
45
- case i
46
- when 1 then value1 = card_test card, $value
47
- when 2 then value2 = card_test card, $value
48
- when 3 then value3 = card_test card, $value
49
- end
50
- i += 1
43
+ case i += 1
44
+ when 1 then value1 = card_test card, $value
45
+ when 2 then value2 = card_test card, $value
46
+ when 3 then value3 = card_test card, $value
47
+ end
51
48
  end
52
49
  if value1 >= value2 && value1 >= value3
53
- $card = dealer.cards[0].num
54
- dealer.play dealer.cards[0]
50
+ $card = dealer.play dealer.cards.first
55
51
  elsif value2 >= value1 && value2 >= value3
56
- $card = dealer.cards[1].num
57
- dealer.play dealer.cards[1]
52
+ $card = dealer.play dealer.cards[1]
58
53
  else
59
- $card = dealer.cards[2].num
60
- dealer.play dealer.cards[2]
54
+ $card = dealer.play dealer.cards[2]
61
55
  end
62
56
  pause 1.5
63
- puts "\tThe dealer played a(n) #{$card}"
57
+ puts "The dealer played a(n) #{$card}"
64
58
  pause(0.5)
65
- puts "\tThe value is now #{$value}\n"
59
+ puts "The value is now #{$value}\n"
66
60
  pause(1.5)
67
61
  if $value > 99 # Runs when you win and exits loop
68
- puts "\tYou win!"
62
+ puts "You win!"
69
63
  break
70
64
  end
71
- puts "\tIt's your turn!"
65
+ puts "It's your turn!"
72
66
  pause 1
73
- user.view
67
+ user.view_cards
74
68
  pause 0.5
75
- print "\tPick a card to play by typing in the name of the card => "
69
+ puts "Pick a card to play by typing in the name of the card"
70
+ sleep 0.2
71
+ print "> "
76
72
  input, playing = gets.chomp, true
77
73
  user.cards.each do |card|
78
74
  if card.num == converter(input) && playing
@@ -81,12 +77,12 @@ loop do
81
77
  end
82
78
  end
83
79
  pause 1
84
- puts "\tYou drew a(n) #{user.cards[2].num}"
85
- pause(0.5)
86
- puts "\tThe value is now #{$value}"
80
+ puts "You drew a(n) #{user.cards[2]}"
81
+ pause 0.5
82
+ puts "The value is now #{$value}"
87
83
  pause(1.5)
88
84
  if $value > 99 # Runs when dealer wins and exits loop
89
- puts "\tYou lose"
85
+ puts "You lose..."
90
86
  break
91
87
  end
92
88
  end
@@ -1,11 +1,9 @@
1
1
  autoload :CardDeck, "card_deck"
2
2
  autoload :Card, "card"
3
3
  autoload :Hand, "hand"
4
-
5
4
  =begin
6
5
  @param card [CardDeck::Card]
7
6
  @param actual_value [Integer]
8
- @param test_value [Integer]
9
7
  @return [Integer]
10
8
  @note Used by the CPU to determine which card to play. Parameter card needs to be an instance of Card.
11
9
  =end
@@ -48,11 +46,11 @@ def converter(input)
48
46
  raise(CardError, "Input cannot be blank") if input == String.new
49
47
  if input.to_i.zero?
50
48
  case input.capitalize
51
- when ?$ then "Joker"
52
- when ?K then "King"
53
- when ?J then "Jack"
54
- when ?Q then "Queen"
55
- when ?A then "Ace"
49
+ when ?$, "Joker" then "Joker"
50
+ when ?K, "King" then "King"
51
+ when ?J, "Jack" then "Jack"
52
+ when ?Q, "Queen" then "Queen"
53
+ when ?A, "Ace" then "Ace"
56
54
  end
57
55
  else
58
56
  input.to_i
@@ -1,9 +1,10 @@
1
1
  require_relative "card.rb"
2
+ $deck = Deck.new(jokers: true).cards.shuffle!
2
3
  class Hand # Creates an object that holds and can play cards. Interacts with Deck objects.
3
4
  @@deck = Deck.new.cards.shuffle!
4
5
  attr_accessor :cards # @return [Array<CardDeck::Card>]
5
6
  def initialize
6
- @cards = Array.new(3) {@@deck.shift}
7
+ @cards = Array.new(3) {$deck.shift}
7
8
  end
8
9
 
9
10
  =begin
@@ -12,6 +13,7 @@ class Hand # Creates an object that holds and can play cards. Interacts with Dec
12
13
  @note Gameplay method
13
14
  =end
14
15
  def play(card)
16
+ raise "Card not found" unless @cards.include? card
15
17
  if card.num == "King"
16
18
  $value = 99
17
19
  elsif card.num == "Joker"
@@ -24,21 +26,22 @@ class Hand # Creates an object that holds and can play cards. Interacts with Dec
24
26
  if index.num == card.num and not done
25
27
  discard = @cards[i]
26
28
  @cards.delete_at i
27
- @cards.push @@deck.shift
28
- @@deck.push discard
29
+ @cards.push $deck.shift
30
+ $deck.push discard
29
31
  done = true
30
32
  end
31
33
  i += 1
32
34
  end
35
+ card
33
36
  end
34
37
 
35
38
  =begin
36
39
  @return [void]
37
40
  Displays cards
38
41
  =end
39
- def view
40
- print "\tThese are your cards: "
41
- @cards.each {|card| print "\t#{card.num}"}
42
+ def view_cards
43
+ print "These are your cards: "
44
+ @cards.each {|card| print "\t#{card}"}
42
45
  end
43
46
  alias inspect cards
44
47
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: 99_game
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.4
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zachary Roth Perlmutter