Sha256: 09719def9a6d7733b01fbc2ff688e910cf949c150c10aca627bcf2dd471979d3

Contents?: true

Size: 918 Bytes

Versions: 2

Compression:

Stored size: 918 Bytes

Contents

require_relative "card.rb"
class Hand # Creates an object that holds and can play cards. Interacts with Deck objects.
	@@deck = Deck.new.cards.shuffle!
    	attr_accessor :cards # @return [Array<CardDeck::Card>]
    	def initialize
		@cards = Array.new(3) {@@deck.shift}
	end
	
=begin
@param card [CardDeck::Card] the card played
@return [void]
@note Gameplay method
=end
	def play(card)
		if card.num == "King"
			$value = 99
		elsif card.num == "Joker"
			$value = 0
		else
			$value += card.value
		end
		i, done = 0, false
		for index in @cards
			if index.num == card.num and not done
				discard = @cards[i]
				@cards.delete_at i
				@cards.push @@deck.shift
				@@deck.push discard
				done = true
			end
			i += 1
		end
	end
		
=begin
@return [void]
Displays cards
=end
    	def view
		print "\tThese are your cards: "
        	@cards.each {|card| print "\t#{card.num}"}
    	end
    	alias inspect cards
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
99_game-3.1.4 lib/hand.rb
99_game-2.1.0 lib/hand.rb