This is a word jumble game, in a sense only the words are 'prearranged' in the code and the hint is readily available.
I'm trying to solve the issue of giving more freedom to the user since my code only accepts 'lowercase' letters while I want the user to be able to answer in which case he prefers.
I'm also trying to sort it by difficulty but I kind of gave it up.
I'm also having problem with the score. Let's say you play it and got a score of 500 then you played it again and gets a 600, the 'highscore' displays
P1 - 600
P2(up to P10) - 500
and sorry, the code is kind of messed up right now(I'm in a bit of a hurry so I haven't made it 'pretty' yet. I'm juggling my options to use 'switch' rather than 'if...else' at the moment. )
# include <iostream>
# include <string>
# include <iomanip>
# include <cmath>
# include <cstdlib>
using namespace std;
struct words{
string description;
string puzzle;
string answer;
int points;
};
struct player{
string name;
int score;
};
const int wordCount = 5;
int score = 0;
words easyWords[wordCount];
words mediumWords[wordCount];
words hardWords[wordCount];
player highscorers[10];
void initialize(){
easyWords[0].description ="clue: open it to enter you home";
easyWords[0].puzzle = "ORDO";
easyWords[0].answer = "door";
easyWords[0].points = 1000;
easyWords[1].description = "clue: made from trees ";
easyWords[1].puzzle = "PPERA";
easyWords[1].answer = "paper";
easyWords[1].points = 1000;
easyWords[2].description = "clue: i can see you wearing this";
easyWords[2].puzzle = "HSRIT";
easyWords[2].answer = "shirt";
easyWords[2].points = 1000;
easyWords[3].description = "clue:i see you not laughing, you lack this sense i guess";
easyWords[3].puzzle = "MUOHR";
easyWords[3].answer = "humor";
easyWords[3].points = 1000;
easyWords[4].description = "we need this for us to be able to smell";
easyWords[4].puzzle = "ONSE";
easyWords[4].answer = "nose";
easyWords[4].points = 1000;
mediumWords[0].description = "clue: money demanded for releasing captive";
mediumWords[0].puzzle = "NRMSOA";
mediumWords[0].answer = "ransom";
mediumWords[0].points = 3000;
mediumWords[1].description = "clue: synonym of the word for envious";
mediumWords[1].puzzle = "SOUVCTOE";
mediumWords[1].answer = "covetous";
mediumWords[1].points = 3000;
mediumWords[2].description = "clue: a group needs this";
mediumWords[2].puzzle = "EATOKRMW";
mediumWords[2].answer = "teamwork";
mediumWords[2].points = 3000;
mediumWords[3].description = "clue: the state of your heart after you've lost something";
mediumWords[3].puzzle = "ORENKB";
mediumWords[3].answer = "broken";
mediumWords[3].points = 3000;
mediumWords[4].description = "clue: use as an output device for computer.";
mediumWords[4].puzzle = "ITORNOM";
mediumWords[4].answer = "monitor";
mediumWords[4].points = 3000;
hardWords[0].description ="clue: it makes a person happy";
hardWords[0].puzzle = "MCOPLENTIM";
hardWords[0].answer = "compliment";
hardWords[0].points = 5000;
hardWords[1].description ="clue: subject about solutions";
hardWords[1].puzzle = "EMCIHTRSY";
hardWords[1].answer = "chemistry";
hardWords[1].points = 5000;
hardWords[2].description ="clue: I know you want to be this";
hardWords[2].puzzle = "LLIMONREIAI";
hardWords[2].answer = "millionaire";
hardWords[2].points = 5000;
hardWords[3].description ="clue: i see you're ......... with C++ functions and operators";
hardWords[3].puzzle = "VREOADLEDO";
hardWords[3].answer = "overloaded";
hardWords[3].points = 5000;
hardWords[4].description ="clue: Many students cram because of this";
hardWords[4].puzzle = "RCPOASNATTIINO";
hardWords[4].answer = "procastination";
hardWords[4].points = 5000;
}
void play(string level, int points, words wordsArr[]){
string ans;
for(int i=0; i < wordCount; i++){
cout<<"\n\n\n\n\n"<<"\t\t\t\t";
cout<<level<<" LEVEL"<<"\n\n";
cout<<"\t\t"<<"Note : You must answer in small letters."<<"\n\n";
cout<<"\t\t\t"<<"Player can only answer once."<<"\n\n\n";
cout<<"\t\t"<< wordsArr[i].description <<"\n\n";
cout<<"\t\t\t"<< wordsArr[i].puzzle <<"\n\n";
cout<<"\t\t\tAnswer: ";
cin>>ans;
if(ans == wordsArr[i].answer){
score += wordsArr[i].points;
cout<<"\n\n"<<"Press enter to continue"<<endl;
cin.ignore();
system("cls");
}else{
cout<<"\t\t\t"<<"Incorrect!"<<endl;
system("PAUSE");
system("cls");
}
}
}
void start(){
int select;
mymenu:
cout<<"\n\n\n\n\n\n";
cout<<"\t\t\t WORD TWISTER"<<"\n\n\n";
cout<<"\t\t\t1 New Game"<<"\n\n\n";
cout<<"\t\t\t2 Instructions"<<"\n\n\n";
cout<<"\t\t\t3 High scores"<<"\n\n";
cin>>select;
cin.ignore();
system("cls");
if (select == 1){
string name;
play("EASY", easyWords[0].points, easyWords);
play("MEDIUM", mediumWords[0].points, mediumWords);
play("HARD", hardWords[0].points, hardWords);
cout<<"Enter your name: ";
cin>>name;
for(int i = 0; i < 10; i++){
if(highscorers[i].score < score){
for(int j = i; j < 9; j++ ){
highscorers[j+1] = highscorers[j];
}
highscorers[i].score = score;
highscorers[i].name = name;
break;
}
}
score = 0;
cin.ignore();
system("cls");
goto mymenu;
}
else if (select == 2){
cout<<"\t\t\tMECHANICS OF GAME"<<"\n\n\n";
cout<<"1. There are three rounds for this game. (Easy, Medium and Hard)."<<endl;
cout<<"2. The player must be able to arrange the letters correctly to earn points."<<endl;
cout<<"3. After each round the points gets higher.\n"
<<" And lastly, The player should write his name after the game for the score"<<endl;
cout<<"\nEASY ROUND: Consist of FOUR TO FIVE LETTERS."<<endl;
cout<<"\nMEDIUM ROUND: Consist of SIX TO EIGHT LETTERS."<<endl;
cout<<"\nHARD ROUND: Consist of NINE TO FOURTEEN LETTERS."<<endl;
cin.ignore();
system("cls");
goto mymenu;
}
else if (select == 3){
cout<<"\n\n\n";
cout<<"\tRank"<<"\t\tName"<<"\t\t\tScore\n\n"<<endl;
for (int i = 0; i<10; i++){
cout<<"\t"<<i+1<<"\t\t"<<highscorers[i].name<<"\t\t\t"<<highscorers[i].score<<"pts."<<endl;
}
cin.ignore();
system("cls");
goto mymenu;
}
}
int main()
{
initialize();
start();
}

New Topic/Question
Reply



MultiQuote




|