The letter S in a light blue, stylized speech bubble followed by SpeakBits
SpeakBitsThe letter S in a light blue, stylized speech bubble followed by SpeakBits
Trending
Top
New
Controversial
Search
Groups

Enjoying SpeakBits?

Support the development of it by donating to Patreon or Ko-Fi.
About
Rules
Terms
Privacy
EULA
Cookies
Blog
Have feedback? We'd love to hear it!

Ruby BlackJack

chat-to.dev
submitted
a year ago
bygorpo85totechnology

Summary

This is single player BTW. Pretty easy game that uses alot of methods that will come in handy when making larger applications. The first step is to create a method that generates a deck of cards. A standard deck has four suits, each with cards numbered from 1 to 13.

Each method performs a distinct role, making the code modular, easier to manage, and debug. Completed code: ``` def generate_deck cards = (1..13).to_a suits = ["Diamonds", "Clubs", "Spades", "Hearts"] deck = [] suits.each do |suit| cards.eachDo |card| deck << [card, suit] end end def shuffle_deck(deck) deck.shuffle end def inspect_cards(cards) card_labels = { 1 => "Ace", 11 => "Jack", 12 => "Queen", 13 => "King" } hand = cards.map { |c| card_

4

0 Comments

There are no comments on this post yet.