//
//  HangmanModel.m
//  Hangman
//
//  Created by Richard Wicentowski on 1/26/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "HangmanModel.h"


@implementation HangmanModel

//automatically creates getter and setter
@synthesize revealedWord;

- (id)init
{
	if (self = [super init]) {
		mysteryWord = @"PIZZA";
		revealedWord = @"-----";
		badGuesses = 0; // initialized to 0 if you hadn't done it
		maxBadGuesses = 9;
	}
	return self;
}


- (void)guessedLetter:(NSString *)letter
{
	BOOL found = NO;
	for (int i = 0; i < [mysteryWord length]; i++) {
		NSRange range = NSMakeRange(i, 1);
		if ([mysteryWord compare:letter 
						 options:NSCaseInsensitiveSearch 
						   range:range] == NSOrderedSame) {
			self.revealedWord = [revealedWord 
							stringByReplacingCharactersInRange:range 
							withString:letter];
			found = YES;
		}
	}
	if (!found) { badGuesses++; }
}

- (void)dealloc
{
	[mysteryWord release];
	[revealedWord release];
	[super dealloc];
}

@end
