Jump to content
  • Advertisement
Sign in to follow this  
M0o

Score system

This topic is 2541 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

so here i am again at the end of another chapter and i am stuck yet again. i need to add a scoring system into a "word jumble" game and i know where to start =\




// Word Jumble
// The classic word jumble game where the player can ask for a hint

[size="1"]#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

[size="1"]using namespace std;

[size="1"]int main()
{
enum fields {WORD, HINT, NUM_FIELDS};
const int NUM_WORDS = 5;
const string WORDS[NUM_WORDS][NUM_FIELDS] =
{
{"wall", "Do you feel you're banging your head against something?"},
{"glasses", "These might help you see the answer."},
{"labored", "Going slowly, is it?"},
{"persistent", "Keep at it."},
{"jumble", "It's what the game is all about."}
};

[size="1"] srand(time(0));
int choice = (rand() % NUM_WORDS);
string theWord = WORDS[choice][WORD]; // word to guess
string theHint = WORDS[choice][HINT]; // hint for word

[size="1"] string jumble = theWord; // jumbled version of word
int length = jumble.size();
for (int i=0; i<length; ++i)
{
int index1 = (rand() % length);
int index2 = (rand() % length);
char temp = jumble[index1];
jumble[index1] = jumble[index2];
jumble[index2] = temp;
}

[size="1"] cout << "\t\t\tWelcome to Word Jumble!\n\n";
cout << "Unscramble the letters to make a word.\n";
cout << "Enter 'hint' for a hint.\n";
cout << "Enter 'quit' to quit the game.\n\n";
cout << "The jumble is: " << jumble;

[size="1"] string guess;
cout << "\n\nYour guess: ";
cin >> guess;

[size="1"] while ((guess != theWord) && (guess != "quit"))
{
if (guess == "hint")
cout << theHint;
else
cout << "Sorry, that's not it.";

[size="1"] cout <<"\n\nYour guess: ";
cin >> guess;
}

[size="1"] if (guess == theWord)
cout << "\nThat's it! You guessed it!\n";

[size="1"] cout << "\nThanks for playing.\n";

[size="1"] return 0;
}

Share this post


Link to post
Share on other sites
Advertisement
i have a basic idea but i dunno what to do with it.

const int score = 0;
enum points {wall = 4, glasses = 7, labored = 7, persistent = 10, hint = -5};

Share this post


Link to post
Share on other sites
Can't recall if enums are classed as ints or unsigned ints, if unsigned then that -5 for a hint will cause problems. It looks likr your calculating the score based on the length of the word. Since your using std::string you can do:

int totalScore = 0;
int hintPenalty = 5;

int wordScore = theWord.length();
totalScore += wordScore;

or if you use a hint
totalScore -= hintPenalty;

Share this post


Link to post
Share on other sites
thanx, that was so simple sometime i think if i can really do this :( press on i guess thanx again

Share this post


Link to post
Share on other sites

Can't recall if enums are classed as ints or unsigned ints, if unsigned then that -5 for a hint will cause problems. It looks likr your calculating the score based on the length of the word. Since your using std::string you can do:

int totalScore = 0;
int hintPenalty = 5;

int wordScore = theWord.length();
totalScore += wordScore;

or if you use a hint
totalScore -= hintPenalty;




hey iv got the points to work but i dunno how to get the hint penalty to work properly can you help please?

Share this post


Link to post
Share on other sites

if (hintUsed == true) {
totalScore -= hintPenalty;
}

// where hintUsed is a flag set to true when a hint is used


aaaa thanx i guess i just need to practise using all of these values coz i keep forgetting about them

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!