Game dev woes

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2005
Posts: 175
Reputation: kahaj is an unknown quantity at this point 
Solved Threads: 0
kahaj kahaj is offline Offline
Junior Poster

Game dev woes

 
0
  #1
Dec 23rd, 2005
I'm trying to create a simple text-based word jumble game. Basically, I'm trying to create a bank of jumbled words. Ppl can try to solve the jumble. If it's right, it will cout something about having it right. If it's wrong, it will cout something about sorry, but it should have been "answer".

How would I go about implementing the srand function to make this "word bank" of jumbled words be drawn from at random?
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 466
Reputation: winbatch is on a distinguished road 
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

Re: Game dev woes

 
0
  #2
Dec 23rd, 2005
Have a text file with 2 columns. Load the columns into a map<string,string> . Pick a random word from the map by using a function like srand() (keeping in mind that the number must be below the .size() of the map. if the answer they provide equals the value in the map for that key, they get it right.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,596
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 711
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Game dev woes

 
0
  #3
Dec 23rd, 2005
Originally Posted by winbatch
Have a text file with 2 columns. Load the columns into a map<string,string> . Pick a random word from the map by using a function like srand() (keeping in mind that the number must be below the .size() of the map. if the answer they provide equals the value in the map for that key, they get it right.
Another way is to have a word list file like above, except only with the correctly spelled words. Then you read a word, copy it, do a random shuffle, and use those two strings. That way the jumble will be more likely to change often without the tediousness of editing the file.

Better yet, you can also read the file into a vector and do a random shuffle on it as well as the words so that people who play the game often will have a harder time finding patterns and remembering the word order to win more easily.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,673
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 261
Lerner Lerner is offline Offline
Posting Virtuoso

Re: Game dev woes

 
0
  #4
Dec 23rd, 2005
There is more than one way to do most tasks. You can probably accomplish this task by using index values and an an array of strings. Develop a 2d array of strings to represent each word available. The first column could represent the scrambled word and the second the correct word. Call srand once in the project. call rand % numberOfStringInTheArray to get a ranom int to represent the row of the table to use. Use array[index][0] to get the scrambled word and array[index][1] to get the correct version.
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 251
Reputation: dwks has a spectacular aura about dwks has a spectacular aura about 
Solved Threads: 25
dwks's Avatar
dwks dwks is offline Offline
Posting Whiz in Training

Re: Game dev woes

 
0
  #5
Dec 23rd, 2005
call rand % numberOfStringInTheArray to get a ranom int to represent the row of the table to use.
See Narue's site.
dwk

Seek and ye shall find.

"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.

"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison

"The only real mistake is the one from which we learn nothing."
-- John Powell
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 175
Reputation: kahaj is an unknown quantity at this point 
Solved Threads: 0
kahaj kahaj is offline Offline
Junior Poster

Re: Game dev woes

 
0
  #6
Dec 23rd, 2005
Thank you Lerner. I was thinking that using an array would be the easiest way. At least it seems to be for a novice such as myself. I'll give this route a try.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 175
Reputation: kahaj is an unknown quantity at this point 
Solved Threads: 0
kahaj kahaj is offline Offline
Junior Poster

Re: Game dev woes

 
0
  #7
Dec 23rd, 2005
Narue's site? Where would I find that at?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 421
Reputation: JoBe is on a distinguished road 
Solved Threads: 4
JoBe's Avatar
JoBe JoBe is offline Offline
Posting Pro in Training

Re: Game dev woes

 
0
  #8
Dec 24th, 2005
Originally Posted by kahaj
Narue's site? Where would I find that at?
Here ya go: The Eternally Confuzzled World of Narue :mrgreen:
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 175
Reputation: kahaj is an unknown quantity at this point 
Solved Threads: 0
kahaj kahaj is offline Offline
Junior Poster

Re: Game dev woes

 
0
  #9
Dec 31st, 2005
Here is what I have so far. It keeps giving me a message that I need to declare the items in the array. I didn't think this had to be done individually since they were part of an array. Then again, I've never really used arrays much before...

  1. //Unjumb
  2.  
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. char arrayjum[2][2] = {{BRIDEGROOM, CEPHAS, CLAY },
  7. {RIGRMOOBED, SEACHP, YLCA }};
  8.  
  9. int main()
  10. {
  11.  
  12. cout << "Unjumb. Unjumble Biblical names, places, and other words of importance. \n" << endl;
  13. cout << "All of the words in Unjumb are from the King James version of the Bible. \n\n" << endl;
  14. cout << "If you can't figure the word out, the real answer will be given and you'll be given the next word. \n" << endl;
  15. cout << "The jumbled words all end up being one word, never any spaces. \n\n" << endl;
  16.  
  17.  
  18. return 0;
  19.  
  20. }
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 466
Reputation: winbatch is on a distinguished road 
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

Re: Game dev woes

 
0
  #10
Dec 31st, 2005
Better:
  1. //Unjumb
  2. #include <iostream>
  3. using namespace std;
  4. char *arraynonjum [3] = {"BRIDEGROOM", "CEPHAS", "CLAY" };
  5. char *arrayjum[3] = {"RIGRMOOBED", "SEACHP", "YLCA" };
  6. int main()
  7. {
  8. cout << "Unjumb. Unjumble Biblical names, places, and other words of importance. \n" << endl;
  9. cout << "All of the words in Unjumb are from the King James version of the Bible. \n\n" << endl;
  10. cout << "If you can't figure the word out, the real answer will be given and you'll be given the next word. \
  11. n" << endl;
  12. cout << "The jumbled words all end up being one word, never any spaces. \n\n" << endl;
  13. for ( int i=0;i< 3;i++)
  14. {
  15. cout<<arrayjum[i]<<"="<<arraynonjum[i]<<endl;
  16. }
  17. return 0;
  18. }

Even better:
  1. //Unjumb
  2. #include <iostream>
  3. #include <map>
  4. #include <algorithm>
  5. using namespace std;
  6. int main()
  7. {
  8. map<string,string> myMap;
  9. myMap["RIGRMOOBED"]="BRIDEGROOM";
  10. myMap["SEACHP"]="CEPHAS";
  11. myMap["YLCA"]="CLAY";
  12.  
  13. cout << "Unjumb. Unjumble Biblical names, places, and other words of importance. \n" << endl;
  14. cout << "All of the words in Unjumb are from the King James version of the Bible. \n\n" << endl;
  15. cout << "If you can't figure the word out, the real answer will be given and you'll be given the next word. \
  16. n" << endl;
  17. cout << "The jumbled words all end up being one word, never any spaces. \n\n" << endl;
  18. cout<<"ALL:"<<endl;
  19. for (map<string,string>::iterator i= myMap.begin();i != myMap.end();i++)
  20. {
  21. cout<<i->first<<"="<<i->second<<endl;
  22. }
  23. cout<<"SPECIFIC:"<<endl;
  24. cout<<"RIGRMOOBED is:"<<myMap["RIGRMOOBED"]<<endl;
  25. cout<<"YLCA is:"<<myMap["YLCA"]<<endl;
  26. cout<<"SEACHP is:"<<myMap["SEACHP"]<<endl;
  27. return 0;
  28. }
  29.  
  30. ./Temp
  31. Unjumb. Unjumble Biblical names, places, and other words of importance.
  32. All of the words in Unjumb are from the King James version of the Bible.
  33.  
  34. If you can't figure the word out, the real answer will be given and you'll be given the next word.
  35. The jumbled words all end up being one word, never any spaces.
  36.  
  37. ALL:
  38. RIGRMOOBED=BRIDEGROOM
  39. SEACHP=CEPHAS
  40. YLCA=CLAY
  41. SPECIFIC:
  42. RIGRMOOBED is:BRIDEGROOM
  43. YLCA is:CLAY
  44. SEACHP is:CEPHAS
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC