Help needed with Dos Game!

This is a discussion on Help needed with Dos Game! within the C++ Programming forums, part of the General Programming Boards category; Hi all, I created a simple game (my first one) with C++. It works well except for when I try ...

  1. #1
    Registered User marCplusplus's Avatar
    Join Date
    Nov 2001
    Posts
    68

    Help needed with Dos Game!

    Hi all,

    I created a simple game (my first one) with C++.
    It works well except for when I try to exit whilst I'm playing a game.
    Have a look at the code and you'll see what I mean
    Also, I tried to create an option in which the user can return to the main menu after a game has ended.
    While this worked, when you try to start another new game, it skips the first input

    Here goes:

    (LOOK BELOW)

    Let me know if you can help

    Thanks
    Marc
    Last edited by marCplusplus; 08-31-2002 at 06:40 PM.
    No matter how much you know, you NEVER know enough.

  2. #2
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    i believe this is what we call "gazillion-page-code-that-hurts-peoples-eyes".
    PLEASE narrow it down :X

  3. #3
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469
    I was looking over some of the code. You could really make some of it _much_ shorter

  4. #4
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469
    OK
    Code:
    system("CLS");
    cout<<"\n\n\t[[ Scissors, Paper, Stone 2002 ]] - [ Coded by mvb ]";
    cout<<"\n\n\t[ N E W    G A M E ]";
    cout<<"\n\n\tGAME TYPE:";
    Make a function that does that. It'll make your program a lot shorter.
    Code:
                    system("CLS");
    	cout<<"\n\n\n\n\t\t[    Starting Game    ]";
    	cout<<flush;
    	Sleep(300);
    	system("CLS");
    	cout<<"\n\n\n\n\t\t [   Starting Game   ]";
    	cout<<flush;
    	Sleep(300);
    	system("CLS");
    	cout<<"\n\n\n\n\t\t  [  Starting Game  ]";
    	cout<<flush;
    	Sleep(300);
    	system("CLS");
    	cout<<"\n\n\n\n\t\t   [ Starting Game ]";
    	cout<<flush;
    	Sleep(300);
    It's called a loop. Make it shorter and come back when you did.
    And I'm sure there's more

  5. #5
    Registered User marCplusplus's Avatar
    Join Date
    Nov 2001
    Posts
    68
    Here's a shorter version of my 'game' :)

    Code:
    #include <iostream.h>
    #include <windows.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <time.h>
    
    // function declerations
    void maingame();
    void newgame();
    void help();
    void exitgame();
    void calculate(int gamer, int computer);
    void infinite();
    void points();
    void sessionnumber();
    void personal();
    void pointdetails();
    void gametype();
    void title();
    void loading();
    void checkinput();
    void choice();
    void draw();
    void userwin();
    void AIwin();
    void exitingame();
    void update();
    
    // global variables
    int ingamechoice, AIchoice, userscore, AIscore, menuchoice, pointwin, pointdraw, pointloss, sessions, session, sessionchoice, pointslimit,i;
    char username[12];
    char AIname[12];
    char name[3][10] = { "Scissors" , "Paper" , "Stone" };
    char scorevis,quit;
    
    // main function
    int main()
    {
    	maingame();
    	return 0;
    }
    
    // maingame() function
    void maingame()
    {
    	userscore = 0;
    	AIscore = 0;
    	cout<<flush;
    	do
    	{
    		system("CLS");
    		title();
    		cout<<"\n\n\t[ BETA V3.00 ]";
    		cout<<"\n\n\t[ M E N U ]";
    		cout<<"\n\n\t[1] Start New Game";
    		cout<<"\n\t[2] Help";
    		cout<<"\n\t[3] Exit Game";
    		cout<<"\n\n\tChoice :: [ ]\b\b";
    		cout<<flush;
    		menuchoice = getche();
    	} while (!( menuchoice == '1' || menuchoice == '2' || menuchoice == '3'));
    
    	switch(menuchoice)
    	{
    	case '1': 
    		newgame();
    	case '2': 
    		help();
    		maingame();
    	case '3': 
    		exitgame();
    		break;
    	default: maingame();
    	}
    }
    
    // newgame() function
    void newgame()
    {
    	personal();
    	cout<<"\n\n\t\tYour first name [ max: 10 char ]";
    	cout<<"\n\n\t\tPlayer 1:\t[            ]\b\b\b\b\b\b\b\b\b\b\b\b"<<flush;
    	cin.getline(username,12);
    	cout<<"\n\n\t\tOpponent's (computer) name [ max: 10 char ]";
    	cout<<"\n\n\t\tPlayer 2:\t[            ]\b\b\b\b\b\b\b\b\b\b\b\b";
    	cin.getline(AIname,12);
    	while (strcmp(username,AIname) == 0)
    	{
    		personal();
    		cout<<"\n\n\t[ Please re enter - Names may not be identical. ]";
    		cout<<"\n\n\t\tYour first name [ max: 10 char ]";
    		cout<<"\n\n\t\tPlayer 1:\t[            ]\b\b\b\b\b\b\b\b\b\b\b\b"<<flush;
    		cin.getline(username,12);
    		cout<<"\n\n\t\tOpponent's (computer) name [ max: 10 char ]";
    		cout<<"\n\n\t\tPlayer 2:\t[            ]\b\b\b\b\b\b\b\b\b\b\b\b";
    		cin.getline(AIname,12);
    	}
    	for(i=1; i>0; i--)
    	{
    		do
    		{
    			pointdetails();
    			cout<<"\n\n\tPoints for a win [ between 1 and 100 ]...";
    			cout<<"\n\n\t\t>> ";
    			cin>>pointwin;
    			checkinput();
    		} while (pointwin < 1 || pointwin > 100 );
    	}
    	for(i=1; i>0; i--)
    	{
    		do
    		{
    			pointdetails();
    			cout<<"\n\n\tPoints for a win [ between 1 and 100 ]...";
    			cout<<"\n\t\t>> "<<pointwin;
    			cout<<"\n\n\tPoints for a draw [ between 0 and 100 ]...";
    			cout<<"\n\n\t\t>> ";
    			cin>>pointdraw;
    			checkinput();
    		} while (pointdraw < 0 || pointdraw > 100 );
    	}
    	for(i=1; i>0; i--)
    	{
    		do
    		{
    			pointdetails();
    			cout<<"\n\n\tPoints for a win [ between 1 and 100 ]...";
    			cout<<"\n\t\t>> "<<pointwin;
    			cout<<"\n\n\tPoints for a draw [ between 0 and 100 ]...";
    			cout<<"\n\t\t>> "<<pointdraw;
    			cout<<"\n\n\tPoints for a loss [ between 0 and 100 ]...";
    			cout<<"\n\n\t\t>> ";
    			cin>>pointloss;
    			checkinput();
    		} while (pointloss < 0 || pointloss > 100 );
    	}
    	pointdetails();
    	cout<<"\n\n\tPoints for a win [ between 1 and 100 ]...";
    	cout<<"\n\t\t>> "<<pointwin;
    	cout<<"\n\n\tPoints for a draw [ between 0 and 100 ]...";
    	cout<<"\n\t\t>> "<<pointdraw;
    	cout<<"\n\n\tPoints for a loss [ between 0 and 100 ]...";
    	cout<<"\n\t\t>> "<<pointloss;
    	cout<<flush;
    	Sleep(1000);
    	int gametypex;
    	do
    	{
    		gametype();
    		cout<<"\n\n\t[1] Play till an amount of points are won";
    		cout<<"\n\n\t[2] Play a number of sessions";
    		cout<<"\n\n\t[3] Play unlimited number of sessions";
    		cout<<"\n\n\tChoice :: [ ]\b\b";
    		cout<<flush;
    		gametypex = getche();
    	} while (!( gametypex == '1' || gametypex == '2' || gametypex == '3'));
    	switch (gametypex)
    	{
    	case '1':
    		{
    			do
    			{
    				gametype();
    				cout<<"\n\n\t[ Play till an amount of points are won ]";
    				cout<<"\n\n\tMax. Points... ";
    				cout<<"\n\n\t>> ";
    				cin>>pointslimit;
    			} while (pointslimit < 1 || pointslimit > 1000000);
    			do
    			{
    				gametype();
    				cout<<"\n\n\t[ Play till an amount of points are won ]";
    				cout<<"\n\n\tMax. Points... ";
    				cout<<"\n\n\t>> "<<pointslimit;
    				cout<<"\n\n\n\tScore visible while playing...YES (y) / NO (n)";
    				cout<<"\n\n\t>> ";
    				cin>>scorevis;
    			} while (scorevis != 'y' && scorevis != 'n');
    			gametype();
    			cout<<"\n\n\t[ Play till an amount of points are won ]";
    			cout<<"\n\n\tMax. Points... ";
    			cout<<"\n\n\t>> "<<pointslimit;
    			cout<<"\n\n\n\tScore visible while playing...YES (y) / NO (n)";
    			cout<<"\n\n\t>> ";
    			if (scorevis == 'y')
    				cout<<"Yes";
    			else cout<<"No";
    			break;
    		}
    	case '2':
    		{
    			do
    			{
    				gametype();
    				cout<<"\n\n\t[ Play a number of sessions ]";
    				cout<<"\n\n\tNo. of sessions [ between 1 and 1000000 ]...";
    				cout<<"\n\n\t>> ";
    				cin>>sessions;
    			} while (sessions < 1 || sessions > 1000000);
    			system("CLS");
    			title();
    			cout<<"\n\n\t[ N E W    G A M E ]";
    			cout<<"\n\n\tGAME TYPE:";
    			cout<<"\n\n\t[ Play a number of sessions ]";
    			cout<<"\n\n\tNo. of sessions [ between 1 and 1000000 ]...";
    			cout<<"\n\n\t>> "<<sessions;
    			break;
    		}
    	case '3':
    		{
    			gametype();
    			cout<<"\n\n\t[ Play unlimited number of sessions ]";
    			break;
    		}
    	}
    	cout<<flush;
    	Sleep(500);
    	loading();
    	if (gametypex == '3')
    	{
    		session = 0;
    		infinite();
    	}
    	else if (gametypex == '1')
    	{
    		session = 0;
    		points();
    	}
    	else if (gametypex == '2')
    	{
    		session = 0;
    		sessionnumber();
    	}
    }
    
    // help() function
    void help()
    {
    	cout<<flush;
    	system("CLS");
    	title();
    	cout<<"\n\n\t[ H E L P ]";
    	cout<<"\n\n\tTo play, you must choose one of three objects.";
    	cout<<"\n\tYou may choose either scissors, paper or stone.";
    	cout<<"\n\tNext, the computer will randomly choose one.";
    	cout<<"\n\n\tThe winner is chosen after the two choices";
    	cout<<"\n\tare compared. Remember that:";
    	cout<<"\n\n\tScissors beats Paper (it cuts)";
    	cout<<"\n\tPaper beats Stone (it wraps)";
    	cout<<"\n\tStone beats Scissors (it blunts)";
    	cout<<"\n\n\t[ Press any key to return to the main menu ]";
    	cout<<flush;
    	getch();
    }
    
    void exitgame()
    {
    	
    	do
    	{
    		system("CLS");
    		cout<<"\n\n\tDo you really want to QUIT? (y or n)";
    		cout<<"\n\n\tChoice :: [ ]\b\b";
    		cout<<flush;
    		quit = getche();
    	} while (quit != 'y' && quit != 'n');
    	if (quit == 'y')
    		exit(0);
    	else
    		maingame();
    }
    
    // calculate() function
    void calculate(int gamer, int computer)
    {
    	if (gamer == 1)
    	{
    		if (computer == 1)
    		{
    			draw();
    		}
    		if (computer == 2)
    		{
    			cout<<"\n\n\n\t[ SCISSORS CUT PAPER! - "<<username<<" WINS! ]";
    			userwin();
    		}
    		if (computer == 3)
    		{
    			cout<<"\n\n\n\t[ STONE BRAKES SCISSORS! - "<<AIname<<" WINS! ]";
    			AIwin();
    		}
    	}
    	if (gamer == 2)
    	{
    		if (computer == 1)
    		{
    			cout<<"\n\n\n\t[ SCISSORS CUT PAPER! - "<<AIname<<" WINS! ]";
    			AIwin();
    		}
    		if (computer == 2)
    		{
    			draw();
    		}
    		if (computer == 3)
    		{
    			cout<<"\n\n\n\t[ PAPER COVERS STONE! - "<<username<<" WINS! ]";
    			userwin();
    		}
    	}
    	if (gamer == 3)
    	{
    		if (computer == 1)
    		{
    			cout<<"\n\n\n\t[ STONE BRAKES SCISSORS! - "<<username<<" WINS! ]";
    			userwin();
    		}
    		if (computer == 2)
    		{
    			cout<<"\n\n\n\t[ PAPER COVERS STONE! - "<<AIname<<" WINS! ]";
    			AIwin();
    		}
    		if (computer == 3)
    		{
    			draw();
    		}
    	}
    }
    void infinite()
    {
    	for (;;)
    	{
    		session++;
    		do
    		{
    			cout<<flush;
    			system("CLS");
    			cout<<flush;
    			title();
    			choice();
    			cin>>ingamechoice;
    		} while (ingamechoice < 1 || ingamechoice > 3 );
    		system("CLS");
    		title();
    		cout<<"\n\n\t[ S E S S I O N   "<<session<<" ]";
    		cout<<"\n\n\tYou have chosen [ "<<name[ingamechoice-1]<<" ]..."<<flush;
    		srand(time(NULL));
    		AIchoice = rand()%3;
    		cout<<"\n\n\tYour Opponent has chosen [ "<<name[AIchoice]<<" ]...";
    		cout<<flush;
    		Sleep(300);
    		calculate(ingamechoice,AIchoice+1);
    		cout<<"\n\n\n\t[1] Continue to next session";
    		cout<<"\n\t[2] Check scores";
    		cout<<"\n\t[3] Exit";
    		cout<<"\n\n\tChoice :: [ ]\b\b";
    		cout<<flush;
    		int state = 0;
    		for (;;)
    		{
    			sessionchoice = getch();
    			if (sessionchoice == '1' || sessionchoice == '2' || sessionchoice == '3')
    			{
    				cout<<sessionchoice;
    				state = 1;
    			}
    		if (state == 1)
    			break;
    		} 
    		switch(sessionchoice)
    		{
    		case '1': 
    			continue;
    			break;
    		case '2':
    			{
    				cout<<flush;
    				system("CLS");
    				title();
    				cout<<"\n\n\t[ S C O R E S ]";
    				update();
    				cout<<"\n\n\n\t[ Press any key to continue ]";
    				cout<<flush;
    				getch();
    				continue;
    				break;
    			}
    		case '3':
    				exitingame();
    		}
    	};
    }
    void points()
    {
    	cout<<flush;
    	system("CLS");
    	cout<<flush;
    	title();
    	cout<<"\n\n\tFirst player to reach ["<<pointslimit<<"] points WINS the game!";
    	cout<<"\n\n\n\t[ Press any key to start ]";
    	cout<<flush;
    	getch();
    	for (;;)
    	{
    		session++;
    		do
    		{
    			cout<<flush;
    			system("CLS");
    			cout<<flush;
    			title();
    			choice();
    			cout<<flush;
    			cin>>ingamechoice;
    		} while (ingamechoice < 1 || ingamechoice > 3);
    		system("CLS");
    		title();
    		cout<<"\n\n\t[ S E S S I O N   "<<session<<" ]";
    		cout<<"\n\n\tYou have chosen [ "<<name[ingamechoice-1]<<" ]..."<<flush;
    		srand(time(NULL));
    		AIchoice = rand()%3;
    		cout<<"\n\n\tYour Opponent has chosen [ "<<name[AIchoice]<<" ]...";
    		cout<<flush;
    		Sleep(300);
    		calculate(ingamechoice,AIchoice+1);
    		if (userscore > pointslimit && userscore > AIscore)
    		{
    			cout<<flush;
    			system("CLS");
    			title();
    			cout<<"\n\n\t[ WE HAVE A WINNER! ]";
    			update();
    			cout<<"\n\n\n\t"<<username<<" reached "<<pointslimit<<" first!";
    			cout<<"\n\n\tCongratulations "<<username<<", you have won the game!";
    			cout<<"\n\n\n\t[ Press any key to exit ]";
    			cout<<flush;
    			getch();
    			exitgame();
    		}
    		else if (AIscore > pointslimit && AIscore > userscore )
    		{
    			cout<<flush;
    			system("CLS");
    			title();
    			cout<<"\n\n\t[ WE HAVE A WINNER! ]";
    			update();
    			cout<<"\n\n\n\t"<<AIname<<" reached "<<pointslimit<<" first!";
    			cout<<"\n\n\tSorry "<<username<<", better luck next time!";
    			cout<<"\n\n\n\t[ Press any key to exit ]";
    			cout<<flush;
    			getch();
    			exitgame();
    		}
    		else if (AIscore > pointslimit && AIscore == userscore )
    		{
    			cout<<flush;
    			system("CLS");
    			title();
    			cout<<"\n\n\t[ WE HAVE A DRAW! ]";
    			update();
    			cout<<"\n\n\n\t"<<username<<" and "<<AIname<<" reached "<<pointslimit<<" at the same time!";
    			cout<<"\n\n\tNice try "<<username<<", better luck next time!";
    			cout<<"\n\n\n\t[ Press any key to exit ]";
    			cout<<flush;
    			getch();
    			exitgame();
    		}
    		cout<<"\n\n\n\t[1] Continue to next session";
    		if (scorevis == 'y')
    		{
    			cout<<"\n\t[2] Check scores";
    			cout<<"\n\t[3] Exit";
    			cout<<"\n\n\tChoice :: [ ]\b\b";
    			cout<<flush;
    			int state = 0;
    			for (;;)
    			{
    				sessionchoice = getch();
    				if (sessionchoice == '1' || sessionchoice == '2' || sessionchoice == '3')
    				{
    					cout<<sessionchoice;
    					state = 1;
    				}
    			if (state == 1)
    				break;
    			} 
    			switch(sessionchoice)
    			{
    			case '1': 
    				continue;
    				break;
    			case '2':
    				{
    					cout<<flush;
    					system("CLS");
    					title();
    					cout<<"\n\n\t[ S C O R E S ]";
    					update();
    					cout<<"\n\n\n\t[ Press any key to continue ]";
    					cout<<flush;
    					getch();
    					continue;
    					break;
    				}
    			case '3':
    				exitingame();
    			}
    		}
    		else if (scorevis == 'n')
    		{
    			cout<<"\n\t[2] Exit";
    			cout<<"\n\n\tChoice :: [ ]\b\b";
    			cout<<flush;
    			int state = 0;
    			for (;;)
    			{
    				sessionchoice = getch();
    				if (sessionchoice == '1' || sessionchoice == '2')
    				{
    					cout<<sessionchoice;
    					state = 1;
    				}
    			if (state == 1)
    				break;
    			} 
    			switch(sessionchoice)
    			{
    			case '1': 
    				continue;
    				break;
    			case '2':
    				exitingame();
    			}
    		
    		}
    	}
    }
    void sessionnumber()
    {
    	cout<<flush;
    	system("CLS");
    	cout<<flush;
    	title();
    	cout<<"\n\n\tThe game will end after "<<sessions<<" sessions!";
    	cout<<"\n\n\n\t[ Press any key to start ]";
    	cout<<flush;
    	getch();
    	for (;;)
    	{
    		session++;
    		do
    		{
    			cout<<flush;
    			system("CLS");
    			cout<<flush;
    			title();
    			choice();
    			cin>>ingamechoice;
    		} while (ingamechoice < 1 || ingamechoice > 3 );
    		system("CLS");
    		title();
    		cout<<"\n\n\t[ S E S S I O N   "<<session<<" ]";
    		cout<<"\n\n\tYou have chosen [ "<<name[ingamechoice-1]<<" ]..."<<flush;
    		srand(time(NULL));
    		AIchoice = rand()%3;
    		cout<<"\n\n\tYour Opponent has chosen [ "<<name[AIchoice]<<" ]...";
    		cout<<flush;
    		Sleep(300);
    		calculate(ingamechoice,AIchoice+1);
    		if (session == sessions)
    		{
    			if (userscore > AIscore)
    			{
    				cout<<flush;
    				system("CLS");
    				title();
    				cout<<"\n\n\t[ WE HAVE A WINNER! ]";
    				update();
    				cout<<"\n\n\n\t"<<username<<" has more points than "<<AIname<<"!";
    				cout<<"\n\n\tCongratulations "<<username<<", you have won the game!";
    				cout<<"\n\n\n\t[ Press any key to exit ]";
    				cout<<flush;
    				getch();
    				exitgame();
    			}
    			else if (AIscore > userscore)
    			{
    				cout<<flush;
    				system("CLS");
    				title();
    				cout<<"\n\n\t[ WE HAVE A WINNER! ]";
    				update();
    				cout<<"\n\n\n\t"<<AIname<<" has more points than "<<username<<"!";
    				cout<<"\n\n\tSorry "<<username<<", better luck next time!";
    				cout<<"\n\n\n\t[ Press any key to exit ]";
    				cout<<flush;
    				getch();
    				exitgame();
    			}
    			else if (AIscore == userscore)
    			{
    				cout<<flush;
    				system("CLS");
    				title();
    				cout<<"\n\n\t[ WE HAVE A DRAW! ]";
    				update();
    				cout<<"\n\n\n\t"<<username<<" and "<<AIname<<" reached "<<pointslimit<<" at the same time!";
    				cout<<"\n\n\tNice try "<<username<<", better luck next time!";
    				cout<<"\n\n\n\t[ Press any key to exit ]";
    				cout<<flush;
    				getch();
    				exitgame();
    			}
    		}
    		cout<<"\n\n\n\t[1] Continue to next session";
    		cout<<"\n\t[2] Check scores";
    		cout<<"\n\t[3] Exit";
    		cout<<"\n\n\tChoice :: [ ]\b\b";
    		cout<<flush;
    		int state = 0;
    		for (;;)
    		{
    			sessionchoice = getch();
    			if (sessionchoice == '1' || sessionchoice == '2' || sessionchoice == '3')
    			{
    				cout<<sessionchoice;
    				state = 1;
    			}
    		if (state == 1)
    			break;
    		} 
    		switch(sessionchoice)
    		{
    		case '1': 
    			continue;
    			break;
    		case '2':
    			{
    				cout<<flush;
    				system("CLS");
    				title();
    				cout<<"\n\n\t[ S C O R E S ]";
    				update();
    				cout<<"\n\n\n\t[ Press any key to continue ]";
    				cout<<flush;
    				getch();
    				continue;
    				break;
    			}
    		case '3':
    				exitingame();
    		}
    	};
    }
    void personal()
    {
    	system("CLS");
    	title();
    	cout<<"\n\n\t[ N E W    G A M E ]";
    	cout<<"\n\n\tPERSONAL DETAILS:";
    }
    void pointdetails()
    {
    	system("CLS");
    	title();
    	cout<<"\n\n\t[ N E W    G A M E ]";
    	cout<<"\n\n\tPOINTS DETAILS:";
    }
    void gametype()
    {
    	system("CLS");
    	title();
    	cout<<"\n\n\t[ N E W    G A M E ]";
    	cout<<"\n\n\tGAME TYPE:";
    }
    void title()
    {
    cout<<"\n\n\t[[ Scissors, Paper, Stone 2002 ]] - [ Coded by mvb ]";
    }
    void loading()
    {
    	system("CLS");
    	cout<<"\n\n\n\n\t\t[    Starting Game    ]";
    	cout<<flush;
    	Sleep(300);
    	system("CLS");
    	cout<<"\n\n\n\n\t\t [   Starting Game   ]";
    	cout<<flush;
    	Sleep(300);
    	system("CLS");
    	cout<<"\n\n\n\n\t\t  [  Starting Game  ]";
    	cout<<flush;
    	Sleep(300);
    	system("CLS");
    	cout<<"\n\n\n\n\t\t   [ Starting Game ]";
    	cout<<flush;
    	Sleep(300);
    }
    void checkinput()
    {			
    	if (cin.fail())
    	{
    	   cin.clear();
    	   cin.ignore();
    	   i++;
    	}
    }
    void choice()
    {
    	cout<<"\n\n\t[ S E S S I O N   "<<session<<" ]";
    	cout<<"\n\n\tPlease choose between...";
    	cout<<"\n\n\t\t[1] Scissors";
    	cout<<"\n\n\t\t[2] Paper";
    	cout<<"\n\n\t\t[3] Stone";
    	cout<<"\n\n\tChoice :: [ ]\b\b";
    }
    void draw()
    {
    	cout<<"\n\n\n\t[ DRAW - NOBODY WINS! ]";
    	cout<<"\n\n\t"<<username<<": ";
    	if (pointdraw == 1)
    		cout<<"1 point";
    	else
    		cout<<pointdraw<<" points";
    	cout<<"\n\n\t"<<AIname<<": ";
    	if (pointdraw == 1)
    		cout<<"1 point";
    	else
    		cout<<pointdraw<<" points";
    	userscore += pointdraw;
    	AIscore += pointdraw;
    }
    void userwin()
    {
    	cout<<"\n\n\t"<<username<<": ";
    	if (pointwin == 1)
    		cout<<"1 point";
    	else
    		cout<<pointwin<<" points";
    	cout<<"\n\n\t"<<AIname<<": ";
    	if (pointloss == 1)
    		cout<<"1 point";
    	else
    		cout<<pointloss<<" points";
    	userscore += pointwin;
    	AIscore += pointloss;
    }
    void AIwin()
    {
    	cout<<"\n\n\t"<<username<<": ";
    	if (pointloss == 1)
    		cout<<"1 point";
    	else
    		cout<<pointloss<<" points";
    	cout<<"\n\n\t"<<AIname<<": ";
    	if (pointwin == 1)
    		cout<<"1 point";
    	else
    		cout<<pointwin<<" points";
    	userscore += pointloss;
    	AIscore += pointwin;
    }
    void exitingame()
    {
    	do
    	{
    		system("CLS");
    		cout<<"\n\n\tDo you really want to QUIT? (y or n)";
    		cout<<"\n\n\tChoice :: [ ]\b\b";
    		cout<<flush;
    		quit = getche();
    	} while (quit != 'y' && quit != 'n');
    	if (quit == 'y')
    		exit(0);
    }
    void update()
    {
    	cout<<"\n\n\t[ After ";
    	if (session == 1)
    		cout<<"1 session ]";
    	else 
    		cout<<session<<" sessions ]";
    	cout<<"\n\n\n\t"<<username<<"...";
    	if (userscore == 1)
    		cout<<"1 point";
    	else
    		cout<<userscore<<" points";
    	cout<<"\n\n\t"<<AIname<<"...";
    	if (AIscore == 1)
    		cout<<"1 point";
    	else
    		cout<<AIscore<<" points";
    }
    Last edited by marCplusplus; 08-31-2002 at 05:14 PM.
    No matter how much you know, you NEVER know enough.

  6. #6
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469

    Talking

    Ooops, forgot to tell you. Something that big should be attatched. It gives me headaches and I don't like scrolling down rthat much.

  7. #7
    Registered User marCplusplus's Avatar
    Join Date
    Nov 2001
    Posts
    68
    I'll keep that in mind for next time
    No matter how much you know, you NEVER know enough.

  8. #8
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    wouldnt it be easier to just show the part thats malfunctioning? O_o

  9. #9
    Registered User marCplusplus's Avatar
    Join Date
    Nov 2001
    Posts
    68
    You're good...

    Here...

    Code:
    // newgame() function
    void newgame()
    {
    	personal();
    	cout<<"\n\n\t\tYour first name [ max: 10 char ]";
    	cout<<"\n\n\t\tPlayer 1:\t[            ]\b\b\b\b\b\b\b\b\b\b\b\b"<<flush;
    	cin.getline(username,12);
    	cout<<"\n\n\t\tOpponent's (computer) name [ max: 10 char ]";
    	cout<<"\n\n\t\tPlayer 2:\t[            ]\b\b\b\b\b\b\b\b\b\b\b\b";
    	cin.getline(AIname,12);
    	while (strcmp(username,AIname) == 0)
    	{
    		personal();
    		cout<<"\n\n\t[ Please re enter - Names may not be identical. ]";
    		cout<<"\n\n\t\tYour first name [ max: 10 char ]";
    		cout<<"\n\n\t\tPlayer 1:\t[            ]\b\b\b\b\b\b\b\b\b\b\b\b"<<flush;
    		cin.getline(username,12);
    		cout<<"\n\n\t\tOpponent's (computer) name [ max: 10 char ]";
    		cout<<"\n\n\t\tPlayer 2:\t[            ]\b\b\b\b\b\b\b\b\b\b\b\b";
    		cin.getline(AIname,12);
    	}
    The first time the function is run, it works well.
    The second time, it skips the first input (user's name).

    I'll keep the next problem for later

    Rgrds,
    Marc
    No matter how much you know, you NEVER know enough.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. game engine advice?
    By stien in forum Game Programming
    Replies: 0
    Last Post: 01-23-2007, 02:46 PM
  2. Battleship Game (Win32 EXP Needed)
    By ElWhapo in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 01-15-2005, 09:10 PM
  3. dos game help
    By kwm32 in forum Game Programming
    Replies: 7
    Last Post: 03-28-2004, 05:28 PM
  4. My next 'dos console' game...
    By Leeman_s in forum C++ Programming
    Replies: 5
    Last Post: 11-09-2001, 05:08 AM
  5. MS DOS game with c++
    By Jeremy G in forum C++ Programming
    Replies: 7
    Last Post: 11-08-2001, 08:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21