Thread: Almost done with the Tic Tac Toe, but I need 1 more easy thing. PLEASE HELP!!!

  1. #16
    Registered User
    Join Date
    Oct 2001
    Posts
    11

    yeah

    Maybe you should try using a program like notepad to learn to read C++ before you put it in an IDE that does the work for you. You just posted your code blindly and it doesn't work as is... sorry for your confusion.

  2. #17
    Registered User
    Join Date
    Oct 2001
    Posts
    11

    Cool it's all good

    it's cool... we are all in this together, just trying to be helpful and add a little sarcastic humor to the messages

  3. #18
    DockyD
    Guest

    I get this error

    I get this error when compiling : -
    Compiling...
    tic tac toe.cpp
    c:\program files\microsoft visual studio\vc98\include\poppack.h(1) : error C2019: expected preprocessor directive, found '-'
    c:\program files\microsoft visual studio\vc98\include\poppack.h(3) : fatal error C1021: invalid preprocessor command 'Descriptions'
    Error executing cl.exe.

    tic tac toe.obj - 2 error(s), 0 warning(s)

  4. #19
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    int main(int q, int w, int moves, char choose, char choose1)

    what the f*&k is that?!
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #20
    Registered User
    Join Date
    Oct 2001
    Posts
    38

    Smile

    Whooooooo Hoooooooo!!

    I just wanted to say you guys rule!!! All of youThanks 1000xs! It was all perfect and I put exactly what you said Stoned_Coder (Id like to especially thank you man), but it still didnt work. And thats cause I forgot to define the stupid thing! LOL. But I did and it all worked perfectly.

    I want to thank all you guys who helped out and tried to help me in this trying time. Thanks alot. Its GREATLY appreciated

  6. #21
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    You people have inspired me! I spent the last 2 days making a Tic Tac Toe game of my own, and I've finally finished! Exept for ironing the errors and bugs out..
    One problem, which of these two if statements would be better used.

    if ((board[0][0] == board[0][1] && board[0][1] == board[0][2]) && board[0][2] != '*')

    -or-

    if ((board[0][0] == board[0][1] && board[0][1] == board[0][2]) != '*')

    The second one gives me a warning in MSVC++ 6.0, and the first doesn't. But the first seems like I would work, with less code.

  7. #22
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802

    Lightbulb Few more things :)

    Well heres my code, I've spent about an hour trying to iron out the errors, I got most of 'em but these two still elude me. I don't know if this will even work yet, as I haven't gotten it to compile yet. Any help would be appreciated.

    Code:
    Errors:
    --------------------Configuration: tictac - Win32 Debug--------------------
    Compiling...
    tictac.cpp
    C:\Windows\Desktop\TicTac\tictac.cpp(23) : error C2660: 'setCoords' : function does not take 0 parameters
    C:\Windows\Desktop\TicTac\tictac.cpp(51) : error C2660: 'checkWin' : function does not take 0 parameters
    Error executing cl.exe.
    
    tictac.obj - 2 error(s), 0 warning(s)


    Code:
    Code:
    #include <iostream.h> 
    #include <windows.h> //for system("CLS"); 
    
    
    //VARIABLE DEFINITIONS AND PROTOTYPES
    void title(void);
    void key(void);
    void printNames(void);
    void printTable(void);
    bool checkWin(bool player);
    int setCoords(int x, int y, bool player);
    int getInput(void);
    char board[3][3];
    bool whichplayermove;
    char name1[50];
    char name2[50];
    short int i;
    short int ii;
    short int x,y;
    short int moves;
    char input;
    char playagain;
    int didassigncoords = setCoords();
    //END VARS AND PROTOS
    
    int main(void)
    {
    	title();
    	printNames();
    	getInput();
    	setCoords(x, y, whichplayermove);
    	if (didassigncoords == 0)
    	{		
    		checkWin(whichplayermove);
    		if (checkWin(whichplayermove) == 1)
    		{ 
    			if (whichplayermove == 0) {whichplayermove++;}
    			if (whichplayermove == 1) {whichplayermove = 0;}
    			moves++;
    			if (moves == 9) 
    			{
    				cout << "No winner this time! Play again? (Y/N)->";
    				cin>>playagain;
    				if (playagain == 'Y' || playagain == 'y') { main();} else {	return 0;}
    			}	
    			else
    			{
    				getInput();
    			}	
    		}
    		if (checkWin() == 0)
    		{
    			cout << "Congrats! Play again? (Y/N)->";
    			cin>>playagain;
    			if (playagain == 'Y' || playagain == 'y') { main();} else {	return 0;}
    		}
    	}
    }
    
    bool checkWin(bool player)
    {	
    	//CHECK ROWS
    	if ((board[0][0] == board[0][1] && board[0][1] == board[0][2]) != '*')
    	{
    		cout<<"You've won Player "<<player<<".\n";
    		return 0;
    	}
    	if ((board[1][0] == board[1][1] && board[1][1] == board[1][2]) != '*')
    	{
    		cout<<"You've won Player "<<player<<".\n";
    		return 0;
    	}
    	if ((board[2][0] == board[2][1] && board[2][1] == board[2][2]) != '*')
    	{
    		cout<<"You've won Player "<<player<<".\n";
    		return 0;
    	}
    	//CHECK COLUMNS
    	if ((board[0][0] == board[1][0] && board[1][0] == board[2][0]) != '*')
    	{
    		cout<<"You've won Player "<<player<<".\n";
    		return 0;
    	}
    	if ((board[0][1] == board[1][1] && board[1][1] == board[2][1]) != '*')
    	{
    		cout<<"You've won Player "<<player<<".\n";
    		return 0;
    	}
    	if ((board[0][2] == board[1][2] && board[1][2] == board[2][2]) != '*')
    	{
    		cout<<"You've won Player "<<player<<".\n";
    		return 0;
    	}
    	//CHECK DIAGONALS
    	if ((board[0][2] == board[1][1] && board[1][1] == board[2][2]) != '*')
    	{	
    		cout<<"You've won Player "<<player<<".\n";
    		return 0;
    	}
    	if ((board[2][0] == board[1][1] && board[1][1] == board[0][2]) != '*')
    	{	
    		cout<<"You've won Player "<<player<<".\n";
    		return 0;
    	}
    	return 1;
    }
    
    void title()
    {
    	cout <<"+-+-+ +-+-+ +--+  +-+-+ +--+ +--+  +-+-+ +--+ +--+";
    	cout <<"  |     |   |       |   |__| |       |   |  | |__ ";
    	cout <<"  |     |   |       |   |  | |       |   |  | |   ";
    	cout <<"  +   +-+-+ +--+    +   +  + +--+    +   +--+ +--+";
    	cout <<"\n";
    	cout <<"By: Dual-Catfish ([email protected])                 ";
    }
    
    	
    
    void key(void)
    {
    	cout<<"-----------\n";
    	cout<<"(1) (2) (3)\n";
    	cout<<"(4) (5) (6)\n";
    	cout<<"(7) (8) (9)\n";
    	cout<<"-----------\n";
    }
    
    
    void printNames(void)
    {
    	cout << "Enter your name player 1->";
    	cin.getline(name1, 50, '\n');
    	cout << "\n";
    	cout << "Enter your name player 2->";
    	cin.getline(name2, 50, '\n');
    	for (i=0;i<3;i++)
    	{
    		board[i][0]='*';
    		board[0][i]='*';
    		for (ii=0;ii<3;ii++)
    		{
    			board[i][ii]='*';
    		}
    	}
    
    }
    
    
    void printTable(void)
    {
    	cout << "+---+---+---+" <<endl;
    	cout << "|"<<board[0][0]<<"|"<<board[0][1]<<"|"<<board[0][2]<<"|" <<endl;
    	cout << "+---+---+---+" <<endl;
    	cout << "|"<<board[1][0]<<"|"<<board[1][1]<<"|"<<board[1][2]<<"|" <<endl;
    	cout << "+---+---+---+" <<endl;
    	cout << "|"<<board[2][0]<<"|"<<board[2][1]<<"|"<<board[2][2]<<"|" <<endl;
    	cout << "+---+---+---+" <<endl;
    }
    
    int setCoords(int x, int y, bool player)
    {
    	if (board[x][y] == '*')
    	{
    		if (whichplayermove == 0) {
    			board[x][y] = 'X';
    			return 0;
    		}else{
    			board[x][y] = 'O';
    			return 0;
    		}
    	}else{
    		cout << "That move has already been made.\n";
    		getInput();
    		return 1;
    	}
    	
    }
    
    int getInput(void)
    {
    	printTable();
    	cout << "\nMake your move Player " << whichplayermove+1 << ". (Refer to below key)\n";
    	key();
    	cout << "Move->";
        cin>>input;
    	switch (input)
    	{
    		case '1': { x = 0; y = 0; break; }
    		case '2': { x = 0; y = 1; break; }
    		case '3': { x = 0; y = 2; break; }
    		case '4': { x = 1; y = 0; break; }
    		case '5': { x = 1; y = 1; break; }
    		case '6': { x = 1; y = 2; break; }
    		case '7': { x = 2; y = 0; break; }
    		case '8': { x = 2; y = 1; break; }
    		case '9': { x = 2; y = 2; break; }
    		{
    			cout << "Invalid input, please restate.\n";
    			getInput();
    		}
    	}
    	system("CLS");
    	return 0;

  8. #23
    In The Light
    Join Date
    Oct 2001
    Posts
    598
    Howdy all,
    I cut pasted and ran the block posted by "runtojesus"
    Besides the linker error i expected "unresolved external ...endl (i won't go into on this post i have already asked about this) i got a linker error "unresolved external ...flush...
    Is flush a VC specific operator or is this another Borland problem. What is an alternative to flush.

    After deleting the flush operators & changing endl to "\n" the game seemed to run just fine with the exception of an oddly placed random X or O on the board.

    I am a shamless C++ newbie so i will take any working code i can get for disection and learning purposes. keep them coming.

    M.R.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. tic tac toe crashes :(
    By stien in forum Game Programming
    Replies: 4
    Last Post: 05-13-2007, 06:25 PM
  2. Tic Tac Toe... so close...
    By SlayerBlade in forum C Programming
    Replies: 14
    Last Post: 10-10-2005, 08:58 PM
  3. Tic Tac Toe AI help please...
    By Rune Hunter in forum Game Programming
    Replies: 12
    Last Post: 11-05-2004, 04:24 PM
  4. my tic tac toe is done .. fear?
    By gunder in forum Game Programming
    Replies: 2
    Last Post: 09-14-2003, 11:33 PM
  5. Tic - Tac - Toe...
    By TheUnknowingOne in forum Game Programming
    Replies: 1
    Last Post: 09-10-2002, 06:01 AM