| | |
Game dev woes
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2005
Posts: 175
Reputation:
Solved Threads: 0
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?
How would I go about implementing the srand function to make this "word bank" of jumbled words be drawn from at random?
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.
•
•
•
•
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.
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.
•
•
Join Date: Jul 2005
Posts: 1,673
Reputation:
Solved Threads: 261
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.
•
•
•
•
call rand % numberOfStringInTheArray to get a ranom int to represent the row of the table to use.
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
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
•
•
•
•
Originally Posted by kahaj
Narue's site? Where would I find that at?
•
•
Join Date: Sep 2005
Posts: 175
Reputation:
Solved Threads: 0
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...
C++ Syntax (Toggle Plain Text)
//Unjumb #include <iostream> using namespace std; char arrayjum[2][2] = {{BRIDEGROOM, CEPHAS, CLAY }, {RIGRMOOBED, SEACHP, YLCA }}; int main() { cout << "Unjumb. Unjumble Biblical names, places, and other words of importance. \n" << endl; cout << "All of the words in Unjumb are from the King James version of the Bible. \n\n" << endl; 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; cout << "The jumbled words all end up being one word, never any spaces. \n\n" << endl; return 0; }
Better:
Even better:
C++ Syntax (Toggle Plain Text)
//Unjumb #include <iostream> using namespace std; char *arraynonjum [3] = {"BRIDEGROOM", "CEPHAS", "CLAY" }; char *arrayjum[3] = {"RIGRMOOBED", "SEACHP", "YLCA" }; int main() { cout << "Unjumb. Unjumble Biblical names, places, and other words of importance. \n" << endl; cout << "All of the words in Unjumb are from the King James version of the Bible. \n\n" << endl; 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; cout << "The jumbled words all end up being one word, never any spaces. \n\n" << endl; for ( int i=0;i< 3;i++) { cout<<arrayjum[i]<<"="<<arraynonjum[i]<<endl; } return 0; }
Even better:
C++ Syntax (Toggle Plain Text)
//Unjumb #include <iostream> #include <map> #include <algorithm> using namespace std; int main() { map<string,string> myMap; myMap["RIGRMOOBED"]="BRIDEGROOM"; myMap["SEACHP"]="CEPHAS"; myMap["YLCA"]="CLAY"; cout << "Unjumb. Unjumble Biblical names, places, and other words of importance. \n" << endl; cout << "All of the words in Unjumb are from the King James version of the Bible. \n\n" << endl; 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; cout << "The jumbled words all end up being one word, never any spaces. \n\n" << endl; cout<<"ALL:"<<endl; for (map<string,string>::iterator i= myMap.begin();i != myMap.end();i++) { cout<<i->first<<"="<<i->second<<endl; } cout<<"SPECIFIC:"<<endl; cout<<"RIGRMOOBED is:"<<myMap["RIGRMOOBED"]<<endl; cout<<"YLCA is:"<<myMap["YLCA"]<<endl; cout<<"SEACHP is:"<<myMap["SEACHP"]<<endl; return 0; } ./Temp Unjumb. Unjumble Biblical names, places, and other words of importance. All of the words in Unjumb are from the King James version of the Bible. If you can't figure the word out, the real answer will be given and you'll be given the next word. The jumbled words all end up being one word, never any spaces. ALL: RIGRMOOBED=BRIDEGROOM SEACHP=CEPHAS YLCA=CLAY SPECIFIC: RIGRMOOBED is:BRIDEGROOM YLCA is:CLAY SEACHP is:CEPHAS
![]() |
Other Threads in the C++ Forum
- Previous Thread: Regarding ImageMagic
- Next Thread: Need help writing a delay function in C++
| Thread Tools | Search this Thread |
api array based beginner bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion count database delete deploy desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project proxy python random read recursion recursive return sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






