944,038 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 25773
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Jan 1st, 2007
-2

How to make a C++ game??

Expand Post »
Ok, im not that much of a geeky smart guy in C++,
but i've got some skillz..
so im trying to make a very simple game that will randomize
1 number for the computer and 1 number for the person using the program and whomever(person or computer) gets the highest number(lets say 1-10) wins, and keeps score also...
If anyone can just post here, or help me make this program in anyway that would be awsome!!!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
lotsofsloths is offline Offline
44 posts
since Jan 2007
Jan 1st, 2007
0

Re: How to make a C++ game??

First of all, I suggest taking a look at the short tutorial on random numbers here - http://www.daniweb.com/tutorials/tutorial1769.html
Reputation Points: 307
Solved Threads: 62
Posting Pro
Bench is offline Offline
565 posts
since Feb 2006
Jan 3rd, 2007
0

Re: How to make a C++ game??

As for keeping score, you could have two variables.
C++ Syntax (Toggle Plain Text)
  1. int games_won_by_computer;
  2. int games_won_by_player;

Once you're done that game, you could try a guessing game where the user guesses a random number in as few tries as possible.
Reputation Points: 185
Solved Threads: 28
Posting Whiz in Training
dwks is offline Offline
269 posts
since Nov 2005
Jan 7th, 2007
0

Re: How to make a C++ game??

Ok, im not that much of a geeky smart guy in C++,
but i've got some skillz..
so im trying to make a very simple game that will randomize
1 number for the computer and 1 number for the person using the program and whomever(person or computer) gets the highest number(lets say 1-10) wins, and keeps score also...
If anyone can just post here, or help me make this program in anyway that would be awsome!!!
its very simple
wat exactly u want ?
source code ??
Reputation Points: 9
Solved Threads: 3
Light Poster
apurv is offline Offline
45 posts
since Jan 2007
Nov 10th, 2009
-1
Re: How to make a C++ game??
i want to know how in c++
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hylex is offline Offline
1 posts
since Nov 2009
Aug 7th, 2010
-1
Re: How to make a C++ game??
// 07/08/10 04:52
C++ Syntax (Toggle Plain Text)
  1. /*
  2.   Guess the computers Number game
  3. */
  4.  
  5. //main
  6. #include <iostream>
  7. #include <string>
  8. #include <conio.h>
  9.  
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14. double firmver = 0.01;; // Game version
  15.  
  16. cout << "\t\t\tGuess Num " << firmver;
  17. cout << "\nCompete with the computer.\nTry to guess the right number!\nSee how thinks faster!\n\n";
  18. cout << "Do you want to play?(yes/no || y/n)" << endl;
  19.  
  20. string playgame; // to check if player wants to play
  21. cin >> playgame;
  22. cin.get();
  23.  
  24. // Does player want to play?
  25. if(playgame == "yes" || playgame == "YES"
  26. || playgame == "Yes" || playgame == "y"
  27. || playgame == "Y")
  28. {
  29. cout << "Press any key to start" << endl;
  30.  
  31. //Game loop
  32. while(playgame == "yes" || playgame == "YES"
  33. || playgame == "Yes" || playgame == "y"
  34. || playgame == "Y")
  35. {
  36. int psnum; //player secret num
  37. int csnum; //computer secret num
  38.  
  39.  
  40.  
  41. long pgnum; //player guess num
  42. int cgnum; // computer guess num
  43.  
  44. int amountpg = 1; // amount player guesses max 3 times per guess
  45. int amountcg = 0; // amount computer guesses max 3 times per guess
  46.  
  47. psnum = rand() % 50 + 1; // Initiliaze player secret num from 1-50;
  48. csnum = rand() % 50 + 1; // Initiliaze computer secret num from 1-50;
  49. cout << amountpg << endl;
  50.  
  51. while(amountpg != 3)
  52. {
  53. cout << "Please guess your number" << endl;
  54.  
  55. cin >> pgnum;
  56.  
  57. if(pgnum == psnum)
  58. {
  59. cout << "You guessed right" << endl;
  60. amountpg = 0;
  61. }
  62.  
  63. if (pgnum > psnum)
  64. {
  65. cout << "It is too high" << endl;
  66. amountpg++;
  67. cout << amountpg << endl;
  68. }
  69.  
  70. if (pgnum < psnum)
  71. {
  72. cout << "It is too low" << endl;
  73. amountpg;
  74. cout << amountpg << endl;
  75. }
  76. }
  77.  
  78. cout << "You guessed 3 times wrong! Concentrate on solving the next guess" << endl;
  79. psnum = rand() % 50 + 1; // Initiliaze player secret num from 1-50;
  80. amountpg == 0;
  81.  
  82. }
  83. }
  84. }
Last edited by Nick Evan; Aug 31st, 2010 at 4:31 am. Reason: Added code-tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
registerdt2post is offline Offline
1 posts
since Aug 2010
Aug 31st, 2010
-2
Re: How to make a C++ game??
how run above program
Reputation Points: 10
Solved Threads: 0
Newbie Poster
DIBYENDU SINGHA is offline Offline
1 posts
since Aug 2010
Aug 31st, 2010
0
Re: How to make a C++ game??
You need a compiler. There mare many free compilers just a google away.
click here
Last edited by CJX3711; Aug 31st, 2010 at 8:58 am.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
CJX3711 is offline Offline
8 posts
since Aug 2010
Aug 31st, 2010
1
Re: How to make a C++ game??
Did half a programming class just register to post in this thread?
Reputation Points: 817
Solved Threads: 32
Nearly a Posting Virtuoso
Duki is offline Offline
1,474 posts
since Jun 2006
Apr 1st, 2011
-1

robtop

#include<iostream>
#include<string>

using namespace std;

int main()
{
string s;
cout << "Please enter your first name followed by a newline\n";
cin >> s;
cout << "Hello, " << s << '\n';
return 0; // this return statement isn't necessary
Reputation Points: 10
Solved Threads: 0
Newbie Poster
devill2 is offline Offline
1 posts
since Apr 2011

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Segmentation Fault on Circular List Size 1
Next Thread in C++ Forum Timeline: Memory Leak Extracting String from Char Buffer





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC