| | |
C++ game?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2004
Posts: 28
Reputation:
Solved Threads: 0
the using directive is almost like the #include command. it is using the namespace std (or standard) held in the iostream header file. what it does is it lets you use the line:
it's just more convenient...
i do recommend the SAMS book...
C++ Syntax (Toggle Plain Text)
cout << "Hello"; instead of needing std::cout << "Hello";
it's just more convenient...
i do recommend the SAMS book...
•
•
•
•
That dice game look awsome and i compiled and played it on my computer, using dev-c++.
though i had a question: How does the computer randomize the dice roll
"Technological progress is like an axe in the hands of a pathological criminal."
All my posts may be freely redistributed under the terms of the MIT license.
All my posts may be freely redistributed under the terms of the MIT license.
•
•
Join Date: Mar 2007
Posts: 11
Reputation:
Solved Threads: 0
I made a pretty sweet Number Hang Man Game. Im really noob but it wasnt hard.
lol it's kinda fun, anywayz add me on msn for any help with noob stuff.
<snip email>
peace
C++ Syntax (Toggle Plain Text)
// Number HangMan // By: David Seviour #include <iostream> #include <string> #include <sstream> #include <cstdlib> #include <iostream> #include <time.h> #include <windows.h> #include <string> #include <cstdlib> #include <ctime> using namespace std; int main () { int c; int w=8; int s=0; int l=0; int d; int e; int f; int g; int h; int i; int j; int k; startover: srand((unsigned)time(0)); int b; for(int index=0; index<1; index++){ b = (rand()%100)+1; } cout << "\n\n\n\n\n\n\n\n\n\n\n\n"; cout << " Loading."; Sleep(1000); system("cls"); cout << "\n\n\n\n\n\n\n\n\n\n\n\n"; cout << " Loading.."; Sleep(1000); system("cls"); cout << "\n\n\n\n\n\n\n\n\n\n\n\n"; cout << " Loading..."; Sleep(1000); system("cls"); cout << "\n\n\n\n\n\n\n\n\n\n\n\n"; cout << " Loading....Ready!" << endl; Sleep(1000); cout << "\n\n\n\n\n\n\n\n\n\n\n\n"; system("PAUSE"); system("cls"); system("title Numb4rs Hang Man"); cout << "NUMB4RS HANG MAN" << endl; cout << "By: David Seviour\n\n\n\n\n\n\n\n\n\n\n\n"; cout << " Press Alt+Enter for Full screen."; cout << "\n\n\n\n\n\n\n\n\n\n" << endl; system("PAUSE"); system("cls"); system("color 08"); system("title Numb4rs Hang Man"); c = 0; cout << "Number Hang Man!\n" << endl; cout << "So far You have " << l << " deaths and " << s << " survivors"; cout << "\n\n\n"; cout << "-------|" << endl; cout << "|" << endl; cout << "|" << endl; cout << "|" << endl; cout << "|" << endl; cout << "|" << endl; cout << "|" << endl; cout << "-----" << endl; cout << " Im a number Between 1-100" << endl; cout << "\n\n" << endl; cout << "Guess What number I Am..." << endl; cin >> d; if (d < b) { cout << "Go Higher!\n"; system("PAUSE"); goto loophigherlower;} else if (d > b) { cout << "Go Lower!\n"; system("PAUSE"); goto loophigherlower;} else if (d = b) {goto loopwin;} return 0; // _____________________________________________________________________________________________ loophigherlower: system("cls"); system("color 02"); system("title Numb4rs Hang Man"); c = c + 1; cout << "Try number " << c << " of 6"; if (c == w) goto LOSE; cout << "\n\n\n"; cout << "-------|" << endl; cout << "| O" << endl; cout << "|" << endl; cout << "|" << endl; cout << "|" << endl; cout << "|" << endl; cout << "|" << endl; cout << "-----" << endl; cout << " Im a number Between 1-100\n" << endl; cout << " You have selected the following numbers so far: " << d; cout << "\n\n" << endl; cout << "Guess What number I Am..." << endl; cin >> e; if (e < b) { cout << "Go Higher!\n"; system("PAUSE"); goto loophigherlower2;} else if (e > b) { cout << "Go Lower!\n"; system("PAUSE"); goto loophigherlower2;} else if (e = b) {goto loopwin;} return 0; //________________________________________________________________________________________________ loophigherlower2: system("cls"); system("color 09"); system("title Numb4rs Hang Man"); c = c + 1; cout << "Try number " << c << " of 6"; if (c == w) goto LOSE; cout << "\n\n\n"; cout << "-------|" << endl; cout << "| O" << endl; cout << "| |" << endl; cout << "|" << endl; cout << "|" << endl; cout << "|" << endl; cout << "|" << endl; cout << "-----" << endl; cout << " Im a number Between 1-100\n" << endl; cout << " You have selected the following numbers so far: " << d << "," << e; cout << "\n\n" << endl; cout << "Guess What number I Am..." << endl; cin >> f; if (f < b) { cout << "Go Higher!\n"; system("PAUSE"); goto loophigherlower3;} else if (f > b) { cout << "Go Lower!\n"; system("PAUSE"); goto loophigherlower3;} else if (f = b) {goto loopwin;} //__________________________________________________________________________________________ loophigherlower3: system("cls"); system("color 04"); system("title Numb4rs Hang Man"); c = c + 1; cout << "Try number " << c << " of 6"; if (c == w) goto LOSE; cout << "\n\n\n"; cout << "-------|" << endl; cout << "| O" << endl; cout << "| -|" << endl; cout << "|" << endl; cout << "|" << endl; cout << "|" << endl; cout << "|" << endl; cout << "-----" << endl; cout << " Im a number Between 1-100\n" << endl; cout << " You have selected the following numbers so far: " << d << "," << e << "," << f; cout << "\n\n" << endl; cout << "Guess What number I Am..." << endl; cin >> g; if (g < b) { cout << "Go Higher!\n"; system("PAUSE"); goto loophigherlower4;} else if (g > b) { cout << "Go Lower!\n"; system("PAUSE"); goto loophigherlower4;} else if (g = b) {goto loopwin;} //_______________________________________________________________________________________________ loophigherlower4: system("cls"); system("color 05"); system("title Numb4rs Hang Man"); c = c + 1; cout << "Try number " << c << " of 6"; if (c == w) goto LOSE; cout << "\n\n\n"; cout << "-------|" << endl; cout << "| O" << endl; cout << "| -|-" << endl; cout << "|" << endl; cout << "|" << endl; cout << "|" << endl; cout << "|" << endl; cout << "-----" << endl; cout << " Im a number Between 1-100\n" << endl; cout << " You have selected the following numbers so far: " << d << "," << e << "," << f << "," << g; cout << "\n\n" << endl; cout << "Guess What number I Am..." << endl; cin >> h; if (h < b) { cout << "Go Higher!\n"; system("PAUSE"); goto loophigherlower5;} else if (h > b) { cout << "Go Lower!\n"; system("PAUSE"); goto loophigherlower5;} else if (h = b) {goto loopwin;} //___________________________________________________________________________________________ loophigherlower5: system("cls"); system("color 02"); system("title Numb4rs Hang Man"); c = c + 1; cout << "Try number " << c << " of 6"; if (c == w) goto LOSE; cout << "\n\n\n"; cout << "-------|" << endl; cout << "| O" << endl; cout << "| -|-" << endl; cout << "| |" << endl; cout << "|" << endl; cout << "|" << endl; cout << "|" << endl; cout << "-----" << endl; cout << " Im a number Between 1-100\n" << endl; cout << " You have selected the following numbers so far: " << d << "," << e << "," << f << "," << g << "," << h; cout << "\n\n" << endl; cout << "Guess What number I Am..." << endl; cin >> i; if (i < b) { cout << "Go Higher!\n"; system("PAUSE"); goto loophigherlower6;} else if (i > b) { cout << "Go Lower!\n"; system("PAUSE"); goto loophigherlower6;} else if (i = b) {goto loopwin;} //_______________________________________________________________________________________________ loophigherlower6: system("cls"); system("color 09"); system("title Numb4rs Hang Man"); c = c + 1; cout << "Try number " << c << " of 6"; if (c == w) goto LOSE; cout << "\n\n\n"; cout << "-------|" << endl; cout << "| O" << endl; cout << "| -|-" << endl; cout << "| |" << endl; cout << "| o" << endl; cout << "|" << endl; cout << "|" << endl; cout << "-----" << endl; cout << " A number Between 1-100\n" << endl; cout << " You have selected the following numbers so far: " << d << "," << e << "," << f << "," << g << "," << h << "," << i; cout << "\n\n" << endl; cout << "Guess What number I Am... Last Try!!!" << endl; cin >> j; if (j < b) { cout << "\nHaHaHa!\n\n"; cout << "The Number Was " << b << "\n\n"; system("PAUSE"); goto loophigherlower7;} else if (j > b) { cout << "\nHeHeHe!\n\n"; cout << "The Number Was " << b << "\n\n"; system("PAUSE"); goto loophigherlower7;} else if (j = b) {goto loopwin;} return 0; //__________________________________________________________________________________________________ loophigherlower7: system("cls"); system("title Numb4rs Hang Man"); cout << "\n\n\n"; cout << "-------|" << endl; cout << "| O" << endl; cout << "| -|-" << endl; cout << "| |" << endl; cout << "| o o" << endl; cout << "|" << endl; cout << "|" << endl; cout << "-----" << endl; system("color fc"); system("color cf"); system("color fc"); system("color fc"); Sleep(100); system("color cf"); Sleep(100); system("color fc"); Sleep(100); system("color fc"); Sleep(100); system("color cf"); Sleep(500); system("color fc"); Sleep(500); system("color fc"); Sleep(1000); system("color cf"); Sleep(1000); system("color fc"); Sleep(200); system("cls"); cout << "\n\n\n"; cout << "-------|" << endl; cout << "| [" << endl; cout << "| O" << endl; cout << "| -|-" << endl; cout << "| |" << endl; cout << "| o o" << endl; cout << "|" << endl; cout << "-----" << endl; Sleep(200); system("cls"); cout << "\n\n\n"; cout << "-------|" << endl; cout << "| [" << endl; cout << "| ]" << endl; cout << "| O" << endl; cout << "| -|-" << endl; cout << "| |" << endl; cout << "| o o" << endl; cout << "-----" << endl; Sleep(3000); if (c == w) goto LOSE; //___________________________________________________________________________________________________ //____________________________________________________________________________________________________________ LOSE: system("cls"); cout << "\n\n"; cout << "You were Hung!\n\n"; system("PAUSE"); system("cls\n\n"); l = l + 1; goto startover; return 0; //_______________________________________________________________________________________________________________ loopwin: system("title WINNER!!!"); system("cls"); cout << "\n\n\n\n\n\n\n\n\n\n"; cout << " * * * * * * | " << endl; cout << " * * * * * * * * | " << endl; cout << " * * * * * * * * | " << endl; cout << " ** ** * * * O " << endl; system("color fc"); system("color 0f"); system("color e6"); system("color c3"); system("color ae"); system("color e3"); system("color 4c"); system("color a1"); system("color d2"); system("color fc"); system("color 0f"); system("color e6"); system("color c3"); system("color ae"); system("color e3"); system("color 4c"); system("color a1"); system("color d2"); system("color fc"); system("color 0f"); system("color e6"); system("color c3"); system("color ae"); system("color e3"); system("color 4c"); system("color a1"); system("color d2"); system("color fc"); system("color 0f"); system("color e6"); system("color c3"); system("color ae"); system("color e3"); system("color 4c"); system("color a1"); system("color d2"); system("color fc"); system("color 0f"); system("color e6"); system("color c3"); system("color ae"); system("color e3"); system("color 4c"); system("color a1"); system("color d2"); cout << "\n\n\n\n\n\n\n"; system("PAUSE"); system("cls\n\n"); s = s + 1; goto startover; return 0; }
lol it's kinda fun, anywayz add me on msn for any help with noob stuff.
<snip email>
peace
Last edited by Ancient Dragon; Nov 27th, 2007 at 9:56 am. Reason: snipped email
C++ Syntax (Toggle Plain Text)
//Preprocessor Directives #include<iostream> #include<string> #include<cstdlib> #include<cctype> #include<ctime> using namespace std; //Function Prototypes void SeedRandom(); void PrintHeader(); void PlayOneMatch(int&, int&, int&, int&, int&); int GetPlayerChoice(); int DrawNum(int); void PrintMove(int, int, int&, int&); void WonAGame(char, int&, int&, int&); void PrintFinalResults(int, int, int, int); void Reset(int&, int&, int&, int&, int&, int&, int&); //Main Driver int main() { char WinnerNumber = '0'; int GamesWon = 0, WinnerMoney = 0, LoserMoney = 0, Player1Money = 100, Player2Money = 100, Games1Won = 0, Games2Won = 0, TieCount = 0, MatchCounter = 0, TotalGames = 0; SeedRandom(); do{ Reset(GamesWon, WinnerMoney, LoserMoney, Games1Won, Games2Won, TieCount, MatchCounter); PrintHeader(); PlayOneMatch(Games1Won, Games2Won, TieCount, Player1Money, Player2Money); PrintFinalResults(Games1Won, Games2Won, TieCount, TotalGames+=3); }while(TotalGames < 20 || !Player1Money || !Player2Money); return 0; } //Function Definitions void SeedRandom() { srand(time(NULL)); } void PrintHeader() { cout << "\n\t----------=====******=====----------" << "\n\tRock, Paper, and Scissors:" << "\n\t----------=====******=====----------" << "\n\n\tThis program plays the EXCITING game of Rock, Paper," << "\n\tand Scissors. Two players choose either Rock, Paper or Scissors," << "\n\tand the results of their picks are compared. Each match is" << "\n\tdetermined as follows:" << "\n\n\tPlayer 1 Player 2 Result" << "\n\t-------- -------- ------" << "\n\t--- --- Any matching combo. A tie!" << "\n\n\tNow you are about to play against world-class computer" << "\n\tchampion Dr. Windows. You are Player 1, and the computer" << "\n\tis Player 2. Player 2's moves are randomly chosen by the computer." << "\n\tBoth players start with $100 and the game is finished when either one player" << "\n\treaches $0 or there have been 3 matches played. The bet per metch is $5."; } void PlayOneMatch(int& Games1Won, int& Games2Won, int& TieCount, int& Player1Money, int& Player2Money) { int playerchoice = 0, computerchoice = 0, MatchCounter = 0; do{ cout << "\n\n\tPlayer 1, Enter your choice of" << "\n\t 1 Rock" << "\n\t 2 Paper" << "\n\t 3 Scissors -> "; playerchoice = GetPlayerChoice(); computerchoice = DrawNum(3); if(playerchoice == computerchoice) TieCount++; else if(playerchoice > computerchoice || playerchoice == 1 && computerchoice == 3) { ++Games1Won; WonAGame('1', Games1Won, Player1Money, Player2Money); } else { ++Games2Won; WonAGame('2', Games2Won, Player2Money, Player1Money); } PrintMove(playerchoice, computerchoice, Player2Money, Player1Money); MatchCounter++; }while(MatchCounter < 3 || !Player1Money || !Player2Money); } int GetPlayerChoice() { char choice = '0'; cin.get(choice); cin.ignore(1000,'\n'); while(!isdigit(choice) || choice < '1' || choice > '3') { cout << "\n\t\aThat was not a valid entry. Please try again -> "; cin.get(choice); cin.ignore(1000,'\n'); } return atoi(&choice); } int DrawNum(int max) { double x = RAND_MAX + 1.0; int y = 0; y = static_cast<int> (1 + rand() * (max / x)); return (y); } void PrintMove(int Move1, int Move2, int& Player1Money, int& Player2Money) { string action[] = {"rock", "paper", "scissors"}; cout << "\n\n\tRESULTS OF THIS MOVE" << "\n\t=-=-=-=-=-=-=-=-=-=-" << "\n\t Player 1 Player 2 Player 1's Player 2's" << "\n\tNumber Action Number Action Winner Money Money" << "\n\t------ ------ ------ ------ ------ ----- -----" << "\n\t " << Move1 << " " << action[Move1-1] << " " << Move2 << " " << action[Move2-1] << " "; if(Move1 == Move2) cout << "A tie!"; else if(Move1 > Move2 || Move1 == 1 && Move2 == 3) cout << "Player 1!"; else cout << "Player 2!"; cout << " $" << Player1Money << " $" << Player2Money; } void WonAGame(char WinnerNumber, int& GamesWon, int& WinnerMoney, int& LoserMoney) { switch(WinnerNumber) { case '1': WinnerMoney-=5; LoserMoney+=5; break; case '2': LoserMoney+=5; WinnerMoney-=5; break; } } void PrintFinalResults(int Games1Won, int Games2Won, int TieCount, int TotalGames) { cout << "\n\n\n\tAnd there you have it folks, the final match between our two" << "\n\tcontestants. The final results for tonight's game are as follows:" << "\n\n\t Player 1 Player 2" << "\n\t ======== ========" << "\n\tGames Won: " << Games1Won << " " << Games2Won << "\n\tPercent Won: " << static_cast<int>(((double)Games1Won/3)*100) << "% " << static_cast<int>(((double)Games2Won/3)*100) << '%' << "\n\n\t\tTotal games tied: " << TieCount << "\n\t\tTotal games played: " << TotalGames << "\n\t\tThe overall winner is "; if(Games1Won == Games2Won) cout << "Both!"; else if(Games1Won > Games2Won) cout << "Player 1!"; else cout << "Player 2!"; cout << "\n\n\tStop in again soon to play another exciting match!!!\n\n\n\n\n\n"; } void Reset(int& GamesWon, int& WinnerMoney, int& LoserMoney, int& Games1Won, int& Games2Won, int& TieCount, int& MatchCounter) { GamesWon = 0; WinnerMoney = 0; LoserMoney = 0; Games1Won = 0; Games2Won = 0; TieCount = 0; MatchCounter = 0; }
![]() |
Similar Threads
- looking for C++ London 3D Game Porgrammers - Growing proffessional startup company (Software Development Job Offers)
- Motion Behavior Engineer - C++ - Game Engine (Software Development Job Offers)
- News Story: Palin and Obama kick ass in Mercenaries 2 game (Game Development)
- Roblox seeks Game and Graphics Guru (Software Development Job Offers)
- game programmer needed (Software Development Job Offers)
- Ajax Game Developer Needed for a small project (Web Development Job Offers)
- News Story: Wall Street Best Bet? Video Game Makers (Game Development)
Other Threads in the C++ Forum
- Previous Thread: C++ arrays
- Next Thread: Alternatives to arrays?
| Thread Tools | Search this Thread |
api array arrays based binary c++ c/c++ calculator char char* class classes code coding compile console conversion convert count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets




thnx for posting it pretty cool, but use the [ C O D E ] [ / C O D E ] tags next time plz I had to school for almost an hour on my laptops little 800x600 resolution lol 

