Sign in to follow this  
M0o

Score system

Recommended Posts

M0o    100
[size="2"]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 =\




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

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

[size="1"]using namespace std;[/size]

[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]

[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]

[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]

[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]

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

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

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

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

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

[size="1"] return 0;
}[/code]
[/size]

Share this post


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

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

Share this post


Link to post
Share on other sites
Nanoha    2682
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:

[code]int totalScore = 0;
int hintPenalty = 5;

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

or if you use a hint
totalScore -= hintPenalty;[/code]

Share this post


Link to post
Share on other sites
M0o    100
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
M0o    100
[quote name='Nanoha' timestamp='1310308388' post='4833333']
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:

[code]int totalScore = 0;
int hintPenalty = 5;

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

or if you use a hint
totalScore -= hintPenalty;[/code]
[/quote]


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
M0o    100
[quote name='ihappyaccident' timestamp='1310318476' post='4833397']
if (hintUsed == true) {
totalScore -= hintPenalty;
}

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this