99_game 3.2.0 → 3.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +8 -8
  2. data/bin/99_game +56 -52
  3. data/lib/99_game.rb +6 -7
  4. data/lib/hand.rb +8 -11
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDIwODlkMTM2MzQ3NmFkMGRhZWNlZWZlZTAyNDA5YmFhNzYxNTU5ZA==
4
+ M2JlNmYzM2M3YzNlZjBmM2EwYTFlMjNmMGYyYWJlMzNhN2YyNDNmOA==
5
5
  data.tar.gz: !binary |-
6
- ZTk5MmExMWRmOTVhNDlkNGI5Y2Q4NDRmYTJhMzg1YTNmMWY3NTFmMw==
6
+ ZGNkNjVhYTE2NDcxZTAzYmU0NmZlNjk0MzE4MjRlY2FmNzZjMzVhOA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NzMzNWE0MzgxZjJkMmQ4YWQyZTA2MDBiNjhlOWYzOWEwMDlmNjg5NjY0ODIw
10
- ODQwOGYxZWY0OWM5M2NhODkwZWJlNjQzYjdiYmRkYTZjMDcxZjNjYzA3OWQ0
11
- ZjA0MWU0YmQzZTM3OGM2NzA0NjkyYWUwNjU1NmFhMWRjOTQ1OTc=
9
+ Y2E2NDdkNDBhZDBmNzU1MDZkZjU5M2QwN2NmMWEyMGE3YjI4OWI2MzA5ZWEx
10
+ M2JlODk0ODk3ODA2N2M1OTMxMjFmY2Q0ZjZmYWYzODBhNWE5YzM1YzA0NmM4
11
+ ZDM4ZTkzNDlmNjc1NmQ5MWEzNTQzNGZmZThkMjViN2ExZGI0MTQ=
12
12
  data.tar.gz: !binary |-
13
- YmMyY2E1ZGU0NmQ4YWJlMzg4MGE5YTIwZjMwMWUwMDQ4NjdiNmQ3M2I3MDA4
14
- YzQ0MDYxM2Q1OGQ3NDY0YzNlMDRlNTdiNGM5OTM3OTI1ZTVlNjMxYjQ4NGYw
15
- NmE2Njk1OGJkZmI4MzZmZjEyNDVmNWNiYmFkOGNhMmM5NTNiNDI=
13
+ YjA2NGE1YzgzMmM3NjBlNGZiNjZlN2VlY2VlNjI1ZTZhNjc0ZjJjN2Y5MDVj
14
+ YmM5Y2FlNzFjODY5ZDYxOTIyMzIwZjJmNDFhNTFjMzQwZTNlZWM2ODgwMTIw
15
+ ZDJkZmFlODk1NGQ1YmQ3ZmU2ZjcwODdmMGY3NTFiZmUxMDNlZTI=
@@ -6,13 +6,13 @@ BEGIN { # Looks at its arguements
6
6
  ARGV[0] = "-v" if ARGV[0] == "--version"
7
7
  case ARGV[0]
8
8
  when "-v"
9
- puts "3.1.2"
9
+ puts "3.2.2"
10
10
  exit
11
11
  when "-h"
12
12
  puts "\u00B7 Commands"
13
13
  puts "\t\u00b7 -v/--version - display version"
14
14
  puts "\t\u00B7 -h/--help - shows this message\n"
15
- puts "\u00B7 Abbrevations"
15
+ puts "\u00B7 Abbrevations can be used instead of inputting the whole name of a card"
16
16
  puts "\t\u00B7 J -> Jack"
17
17
  puts "\t\u00b7 Q -> Queen"
18
18
  puts "\t\u00b7 K -> King"
@@ -21,12 +21,11 @@ BEGIN { # Looks at its arguements
21
21
  puts "\u00B7 Gameplay"
22
22
  puts "\t\u00B7 Your goal is to get your opponent to bring the value over 99 by playing 1 of your 3 cards."
23
23
  puts "\t\u00B7 A card will usually increase the value by itself, but there are a few exceptions:"
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"
24
+ puts "\t\t\u00B7 Aces are worth 1"
25
+ puts "\t\tu00B7 4, 9, and Jacks are worth 0"
26
+ puts "\t\t\u00B7 Queens decrease the value by 10"
27
+ puts "\t\t\u00B7 Kings set the value to 99"
28
+ puts "\t\t\u00B7 Jokers set the value to 0"
30
29
  exit
31
30
  end
32
31
  }
@@ -37,54 +36,59 @@ END { # Thanks for playing
37
36
  }
38
37
  $value, value1, value2, value3, dealer, user = 0,0,0,0, Hand.new, Hand.new
39
38
  loop do
40
- puts "\nIt's the dealer's turn!"
41
- i = 0
42
- for card in dealer.cards
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
39
+ puts "\nIt's the dealer's turn!"
40
+ i = 0
41
+ for card in dealer.cards
42
+ case i += 1
43
+ when 1 then value1 = card_test card, $value
44
+ when 2 then value2 = card_test card, $value
45
+ when 3 then value3 = card_test card, $value
46
+ end
47
47
  end
48
- end
49
- if value1 >= value2 && value1 >= value3
50
- $card = dealer.play dealer.cards.first
51
- elsif value2 >= value1 && value2 >= value3
52
- $card = dealer.play dealer.cards[1]
53
- else
54
- $card = dealer.play dealer.cards[2]
55
- end
56
- pause 1.5
57
- puts "The dealer played a(n) #{$card}"
58
- pause(0.5)
59
- puts "The value is now #{$value}\n"
60
- pause(1.5)
61
- if $value > 99 # Runs when you win and exits loop
62
- puts "You win!"
63
- break
64
- end
65
- puts "It's your turn!"
66
- pause 1
67
- user.view_cards
68
- pause 0.5
69
- puts "Pick a card to play by typing in the name of the card"
70
- sleep 0.2
71
- print "> "
72
- input, playing = gets.chomp, true
73
- user.cards.each do |card|
74
- if card.num == converter(input) && playing
75
- user.play card
76
- playing = false
48
+ if value1 >= value2 && value1 >= value3
49
+ $card = dealer.play dealer.cards.first
50
+ elsif value2 >= value1 && value2 >= value3
51
+ $card = dealer.play dealer.cards[1]
52
+ else
53
+ $card = dealer.play dealer.cards.last
77
54
  end
78
- end
55
+ pause 1.5
56
+ puts "The dealer played #{$card}"
57
+ pause(0.5)
58
+ puts "The value is now #{$value}\n"
59
+ pause(1.5)
60
+ if $value > 99 # Runs when you win and exits loop
61
+ puts "You win!"
62
+ break
63
+ end
64
+ puts "It's your turn!"
65
+ pause 1
66
+ user.view_cards
67
+ pause 0.5
68
+ puts "Pick a card to play by typing in the name of the card"
69
+ sleep 0.2
70
+ playing = true
71
+ while playing
72
+ print "> "
73
+ input = gets.chomp
74
+ user.cards.each do |card|
75
+ if card.num == converter(input) && playing
76
+ user.play card
77
+ playing = false
78
+ end
79
+ end
80
+ sleep 0.2
81
+ puts "Illegal input. Please enter a legal card" if playing
82
+ end
79
83
  pause 1
80
- puts "You drew a(n) #{user.cards[2]}"
84
+ puts "You drew #{user.cards.last}"
81
85
  pause 0.5
82
- puts "The value is now #{$value}"
83
- pause(1.5)
84
- if $value > 99 # Runs when dealer wins and exits loop
85
- puts "You lose..."
86
- break
87
- end
86
+ puts "The value is now #{$value}"
87
+ pause(1.5)
88
+ if $value > 99 # Runs when dealer wins and exits loop
89
+ puts "You lose..."
90
+ break
91
+ end
88
92
  end
89
93
  __END__
90
94
  Programmed by: Zachary Perlmutter
@@ -8,15 +8,14 @@ autoload :Hand, "hand"
8
8
  @note Used by the CPU to determine which card to play. Parameter card needs to be an instance of Card.
9
9
  =end
10
10
  def card_test(card, actual_value)
11
- if card.num == "King"
12
- test_value = 99
13
- elsif card.num == "Joker"
14
- test_value = 0
11
+ test_value = case card.num
12
+ when "King" then 99
13
+ when "Joker" then 0
15
14
  else
16
- test_value = actual_value + card.value
15
+ actual_value + card.value
17
16
  end
18
- test_value = -100 if test_value > 99
19
- return test_value
17
+ test_value = -1 if test_value > 99
18
+ test_value
20
19
  end
21
20
  # Tests if obj is not nil.
22
21
  def not_nil?(obj)
@@ -7,11 +7,9 @@ class Hand # Creates an object that holds and can play cards. Interacts with Dec
7
7
  @cards = Array.new(3) {$deck.shift}
8
8
  end
9
9
 
10
- =begin
11
- @param card [CardDeck::Card] the card played
12
- @return [void]
13
- @note Gameplay method
14
- =end
10
+ # @param card [CardDeck::Card] the card played
11
+ # @return [void]
12
+ # @note Gameplay method
15
13
  def play(card)
16
14
  raise "Card not found" unless @cards.include? card
17
15
  if card.num == "King"
@@ -29,19 +27,18 @@ class Hand # Creates an object that holds and can play cards. Interacts with Dec
29
27
  @cards.push $deck.shift
30
28
  $deck.push discard
31
29
  done = true
30
+ $deck.shuffle!
32
31
  end
33
32
  i += 1
34
33
  end
35
34
  card
36
35
  end
37
36
 
38
- =begin
39
- @return [void]
40
- Displays cards
41
- =end
37
+ # @return [void]
38
+ # Displays cards
42
39
  def view_cards
43
- print "These are your cards: "
44
- @cards.each {|card| print "\t#{card}"}
40
+ print "These are your cards: "
41
+ @cards.each {|card| print "#{card} "}
45
42
  end
46
43
  alias inspect cards
47
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: 99_game
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zachary Roth Perlmutter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-10 00:00:00.000000000 Z
11
+ date: 2016-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: card_deck