Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > Mac OS X Development Forums > Objective-C, Python, Ruby Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-14-2009, 02:12 PM   #1 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 39
Arcadiu is on a distinguished road
Default Tic Tac Toe/ Naughts & Crosses trouble

Title says it all really (almost!). Well I have been reading various books and such and I decided to try and incorporate all the things I have been learning about into one accomplishable task yet hard at the same time (for example planning the logic and designing it ect...)

So I have the board printed out and the "didWin" boolean method however I have come across one error that I can't seem to get around!

It says 'move' undeclared (first use in this function) despite having a

return move;

line in my code after 'move' is assigned?

Also, I was wondering if anyone could help me solve the problem of listing ALL the possible ways of winning?

Thanks!

Arcadiu

P.S Could you also point out things that aren't so good (waste of code) and what is good or could be done better. Thanks!

Code:
#import <Cocoa/Cocoa.h>
@interface Board : NSObject
{
	char square1; 
	char square2; 
	char square3; 
	char square4; 
	char square5; 
	char square6; 
	char square7; 
	char square8; 
	char square9; 
	BOOL didWin;
	int move;
}


-(void) print;
-(BOOL) didWin;
-(int) getMove;
-(void) setSquare: (int) squareNumber;

@end

@implementation Board

-(void) setSquare: (int) squareNumber
{
	switch (move) {
		case 1:
			square1 = 'X';
			break;
		case 2:
			square2 = 'X';
			break;
		case 3:
			square3 = 'X';
			break;
		case 4:
			square4 = 'X';
			break;
		case 5:
			square5 = 'X';
			break;
		case 6:
			square6 = 'X';
			break;
		case 7:
			square7 = 'X';
			break;
		case 8:
			square8 = 'X';
			break;
		case 9:
			square9 = 'X';
			break;
	}
}
-(int) getMove
{
	NSLog(@"Please enter the square you would like to place an 'X' on!");
	scanf("%i", &move);
	return move;
}
	
-(void) print
{
	square1 = '1';
	square2 = '2'; 
	square3 = '3'; 
	square4 = '4'; 
	square5 = '5'; 
	square6 = '6'; 
	square7 = '7'; 
	square8 = '8'; 
	square9 = '9'; 
	
	NSLog(@"----|----|----");
	NSLog(@" %c  | %c  | %c ", square1, square2, square3);
	NSLog(@"----|----|----");
	NSLog(@" %c  | %c  | %c ", square4, square5, square6);
	NSLog(@"----|----|----");
	NSLog(@" %c  | %c  | %c ", square7, square8, square9);
	NSLog(@"----|----|----");
}
-(BOOL) didWin
{
	if (square1 == 'X' && square2 == 'X' && square3 == 'X')
	return didWin = TRUE;
	
	else 
		return 0;
}
@end

int main()
{
	Board *myGame = [[Board alloc] init];
	do{
		[myGame print];
		[myGame getMove];
		[myGame setSquare: move]; //<-------BUG HERE
		[myGame didWin];
	} 
	
	while ([myGame didWin] == FALSE);
	
	if ([myGame didWin] == TRUE)
	{
		NSLog(@"You have won the game!!!");
		return 0;
	}
		
	return 0;
}
__________________
Ultimate Pointer Website For Beginners (It Even Helped Me Understand)

http://www.cs.ucr.edu/~pdiloren/C++_Pointers/
Arcadiu is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 462
16 members and 446 guests
7twenty7, AlanFloyd, David-T, iAppDeveloper, imac74, Jaxen66, logan, lovoyl, markuschow, Music Man, mutantskin, Sami Gh, SLIC, solardrift, unicornleo, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,683
Threads: 94,131
Posts: 402,932
Top Poster: BrianSlick (7,990)
Welcome to our newest member, unicornleo
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:08 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0