- Fork this repo
- Clone your Fork
- Complete the requirements in Xcode
- Commit often
- Open a pull request
- Submit a link of your Fork to Canvas
In this assessment, your task will be to build a BlackJack command-line app. The MVP (minimal viable product, basic requirements) of this project will be a one-player game against the computer.
You are free to use Google, StackOverflow, your notes in working through this assessment. Best of luck, address each problem as a sub-task and keep chipping away. You all got this!
In keeping with object-oriented programming in our BlackJack game a card will be the main data of the game.
- The Card has 4 instance properties
suit
,value
,isFaceCard
andface
suit
is a diamond, heart, spade or clubvalue
represents the score value of a card 2 - 10 represent their face value, jack, queen, and king's value is 10. Ace can be 1 or 11.isFaceCard
is used in the creation of the cards arrayface
is an optional FaceCard again only used during the creation of the cards in the newDeck() method
- The Card has a type method
newDeck(:_)
that returns an array of 52 cards [Card]. Since an Ace card can have a value of 1 or 11 you can decide by passing in 1 or 11 as an argument when calling newDeck() - The stringyfy() method returns a String representation of the current card instance. e.g "10
♣️ " or "4♦️ "
- Create a new Swift file called Suit, create an enum of the same name that has a diamond, heart, spade and club case.
- Make the raw value a String.
- Assign the diamond case "
♦️ ", heart case "♥️ ", spade "♠️ " and club "♣️ " - Make sure your enum conforms to CaseIterable in order for the newDeck() method to work.
- Create a new Swift file called FaceCard, create an enum of the same name that has a jack, queen and king case.
- Make the raw value a String.
- Assign the jack case "🎃", queen case "👸" and king "🤴"
- Make sure your enum conforms to CaseIterable in order for the newDeck() method to work.
- Create a new Swift file called Player, create a struct of the same name.
- Add the following properties
score
of type Int,cards
array of type [Card] andplayerName
of type String.
Create a new Swift file called Game, create a class of the same name.
The Game object has the following instance properties:
deck
is an array of [Card]player
is a PlayerhitPlayer
is a Bool
The Game object has the following computed properties:
hasMoreCards
returns a BoolrandomComputerScore
returns an Int
The Game object has the following methods:
newGame()
resets the gamestopHits()
called if the user wishes to pass their turn. In that case the computer draws a random number and a winner is chosen between the computer's score and the player's score.hitMe()
called as the user requests more cards from the deckcomputerVsPlayer()
draws a random number for the computer and determines the winner of the game.gameStatus()
takes in the player's card and determines the current score. Here the player score options can be, BlackJack, Bust or Continue playing as their status is still valid for game play.
- Create an instance of the Game()
- Call newGame on the newly created instance above.
- Create a gameOver instance and set it to
false
. This will be used in yourrepeat-while
to determine if game play should stop. - Use a
repeat-while
to allow the user options between getting new cards by calling the hitMe() method or passing by calling the stopHits() method. - When the player has won or lost ask them if they would wish to continue playing another round.