2 notes &
Cocoa coding: Blackjack tutorial - part 1.
*This is part of a objective-C, cocoa tutorial, that will result in a working blackjack for a os x*.
Previous chapter: blackjack tutorial part 0.
Next chapter: to be added (later).
The first thing is to map out what we’ll want. Which in this blackjack tutorial is quite easy. We want to end up with a working blackjack.
So what do we need:
1) Playing cards which can return:
- what card it is ( a number or a jack, queen, king or ace)
- what suit it is ( hearts, clubs, diamonds, spades)
- point value ( if it’s hearts 7 -> it will return 7. A jack or e.g. queen will return 10)
- if it’s an ace the point value can be 1 or 11.*
*) let’s worry about that later, in start we’ll just return 11.
2) A deck of cards, with the following functions:
- shuffle.
- draw a card
3) Players hand and a table’s hand with the following functions:
- Add a card
- Result the total points in hand.
4) Some kind of AI to let the “house” draw cards, some mechanism to draw cards. The good news is that the AI is really simple. Blackjack rules are the following: The bank has to draw a card if his cards hand are worse than yours and if his hand is below 17 (say a jack and a five) he just has to draw a card. If his hand is the same as yours or better, he’ll pass. If he has over 21, he is bust. There’s not much AI in there.
5) The game mechanics:
- if player is playing: either hit or stand or go bust
- if table is playing - apply “A.I.” from 4.
- count who won and play again.
That’s it.
To make this part 1 of a cocoa coding tutorial (and not just a describing blackjack tutorial), i’ll start by saying how to setup the project in Xcode.
1) So open Xcode. (If you don’t have it yet. Get it a developer.apple.com - you need to register, but it is free).
2) Click “Create a new Xcode project”.
3) Choose Mac OS X - Application - Cocoa Application. (leave all checkboxes default)
4) Save As: Tutorial21. (or what you want to call it.)
5) Set up a subversion project for it. So you can keep track of different versions of your documents. (See also: (Installing and) Configuring Subversion for Xcode )
6) You’ll know have (something like) this:

Great! So let’s start… with the next part.
*This is part of a objective-C, cocoa tutorial, that will result in a working blackjack for a os x*.
Previous chapter: blackjack tutorial - part 0
Next chapter: blackjack tutorial - part 2