onstwedder.com

All that you have is your soul

Posts tagged Cocoa

2 notes &

Cocoa Coding:BlackJack tutorial - Part 12

Looking back I have made a working blackjack. But there are still a few open ends. So let’s start with the cleaning of the view. This removes all the drawn cards (of both hands) from the window’s NSView. Currently it was done in the BlackJackController’s startGame: method and while I do feel it should be initiated from there, the code actually doing the work should be moved to the BlackJackView class. 

Again this is to keep inline with the MVC-model. The V in MVC, stands for the View, and it should do the stuff that’s needed for displaying the information (or erasing some of it, in this case).

So the startGame: method looked liked this:

-(IBAction) startGame:(id)sender{
    
    for (NSImageView *timageview in [(BlackJackView *)self.view imageviews]) {
		[timageview removeFromSuperview];
	}
	[[(BlackJackView *)self.view imageviews] removeAllObjects];
	
    
    blackJackModel = [[BlackJackModel alloc] initWithController:self]; 
    [blackJackModel setupGame];  
}

And after the moving of the actual functionality of removing it will be turned into this:

-(IBAction) startGame:(id)sender{
	[(BlackJackView *)self.view cleanView];
    blackJackModel = [[BlackJackModel alloc] initWithController:self]; 
    [blackJackModel setupGame];  
}

Read more …

Filed under blackjack programming mac osx Cocoa Tutorial Xcode

0 notes &

Cocoa Coding:BlackJack tutorial - PART 11

And here it is. The (near) final part of the blackjack tutorial. In which i change nearly all the files, except the xibs, the AppDelegates and the deck class. The rest is changed - so this is one heck of an episode in the tutorial.

The main thing I’ve done now, is implement a real MVC-model. That means that the BlackJackModel class needs to do everything that has to do with blackjack. The controller needs only to receive the notifications from the view (a click on a button) and needs to set the view, based on signals from the BlackJackModel.

The BlackJackView is the least changed. All I did here is add a method that can set the HiddenStatus of the three button. I figured these buttons’ hidden status are kind of always set together, so i made one method:

-(void) hideHitBtn:(BOOL)hideHit standBtn:(BOOL)hideStand restartBtn:(BOOL)hideRestart
{
    [self.hitBtn setHidden:hideHit];
    [self.standBtn setHidden:hideStand];
    [self.restartBtn setHidden:hideRestart];
}

Read more …

Filed under blackjack mac objective-c osx coding programming Cocoa Tutorial Xcode

9 notes &

Cocoa Coding:BlackJack tutorial - PART 10.5

The tutorial took more time than expected, so i kinda finished it off quite quickly. I did mention a couple of things being left open. Stuff that was just plain wrong - like the ace always returning a pipvalue of 11, and stuff that was sneakily wrong. Like the model being in the controller.

So I’ve decided to clean it up. But when I tried to start to fix it. My family wanted some attention and of course they have the first right to claim me.

Now the coming week I will be very busy - so the follow up will be either tomorrow or somewhere next week.

Read about the MVC-model here:

“we do MVC” and apple’s Model-View-Controller document

Filed under mvc osx objective-c Cocoa Tutorial Xcode

3 notes &

Cocoa Coding:BlackJack tutorial - PART 10

So the last part of magic, before I need to do some major tweaking, is done in the stand: method in the BlackJackController.

I’ve already promised that I would add some AI there and for this short part of the tutorial, all I’ll do is make the dealer either draw a card or stand.

After I’ll add that - it’s sort of finished.

However there will be some points open and ready to discuss later on (not limited to these):

Read more …

Filed under programming mac objective-c osx Cocoa Tutorial Xcode

7 notes &

Cocoa coding:Blackjack tutorial - part 9

Well. That looks really smart. But how come after clicking I still see a start button and not the hit and stand button. Obviously, it is because I haven’t said anything in the code about it yet. 

And that’s what I will do now.

First I’ll declare the hitCard: and stand: methods in the BlackJackController.h - They look the same as the existing startGame: method.

Read more …

Filed under objective-c programming coding blackjack Cocoa Tutorial Xcode

2 notes &

Cocoa coding: Blackjack tutorial - part 8

In this part I’ll finally show those images of the cards in the application.

Of course since everything is already in it’s place - in the last part I’ve dealt the cards into the appropriate hands- all I need to do now, is add a way to show the images that belong to the cards in the hands.

The blackJackController knows the blackJackView and knows the blackJackModel that the hands are part of. So stuff needs to be done in the blackJackController.

First though, I decided it would be handy if a hand instance would “know” what type it was. Either a player’s hand or a table’s hand. So that means I have to add a property HandType (as an enumeration of Player or Table) and have it set through a new init, namely initWithHandType. 

Read more …

Filed under objective-c programming coding blackjack Cocoa Tutorial Xcode

2 notes &

Cocoa coding: Blackjack tutorial - part 7

Looking at what I have now: a couple of classes for the Hand, Deck and Card. Then there is the BlackJackView and the BlackJackController and of course the tutorial21AppDelegate.

So let’s pretend I know what the Model-View-Controller (MVC) model is, and since i see a View and a Controller, the only thing missing is the Model. So let’s create a BlackJackModel file. If nothing else, it will look really smart.

Our model will have to know all about Blackjack. The model needs to be aware there are two hands: a playerhand and a tablehand. Also it has to be aware of the deck (of cards). And It has be smart enough to setup a game.

So, add a new class to the files, and choose it’s template to be “Objective-C class”. Be sure to make it a subclass of NSObject.

Read more …

Filed under objective-c blackjack osx Cocoa Tutorial Xcode

2 notes &

Cocoa coding: Blackjack tutorial - part 6

In this part I will set up the MainMenu.xib, containing the “window” of the application. That’s the one I’ve ignored up to now, by going straight to the Log Console.

Basically in the MainMenu.xib I only changed the window title to “Blackjack”. 

That’s it so far. 

Now I am going to add a BlackJackView Class. In the Classes directory add new file, choose as template: Mac OS X | Cocoa | Objective-C class. After clicking Next, the popup will ask you what Subclass it should be. Change this into: NSView.

Read more …

Filed under english blackjack mac osx Cocoa Tutorial Xcode

0 notes &

Cocoa coding: Blackjack tutorial - part 5

So there’s a couple of things I want do to the card class:
1) add a property that will set the card open or close.
2) calculating the pipvalue differently if the property is close.
3) Add an NSImage to the card, that will either return the image of the card or a closed card, again depending on the property.

Also we’re gonna need some cards images. Of course you can draw them yourself in your almost-legal-if-you-actually-were-a-student-still-photoshop or whatever kind of drawing program you have. But for this tutorial, i am going to be lazy (again). So let’s use google to look for a nice deck. The first hit when typing: “deck of cards image” links to www.jfitz.com/cards/ and what would you know, it has a deck of playing cards as images in a zip. I choose the classic set and the .png format. Because PNG is how we roll these days on the interwebs.

Read more …

Filed under objective-c blackjack mac osx coding Cocoa Tutorial Xcode