Reputation: 9
So I am making a guess the word game in a windows form program in C#, and one of the requirements are that I must include a scoring system. (start out with 100 points, each time a wrong letter is guessed 10 points are subtracted from the total 100 and if you guess right it adds 10 to the total 100.) I have everything else working except for the points. I could really use some help as to how to fix this problem. Mind taking a look?`
public void CheckLetter(string word)
{
lblWord.Text = "";
corLetter += word[0];
score = score;
int amountToUpdate = 0;
score = score + amountToUpdate;
for (int i = 0; i < mysteryWord.Length; i++)
{
count = 0;
for (int j = 0; j < corLetter.Length; j++)
{
if (corLetter[j]== mysteryWord[i])
{
lblWord.Text += corLetter[j].ToString().ToUpper();
count++;
}
}
if (count == 0)
{
lblWord.Text += "_ ";
}
}
bool letterInWord = false;
for (int i = 0; i < word.Length; i++)
{
if (rtbGuess.Text == mysteryWord[i].ToString())
{
letterInWord = true;
}
}
score = score + amountToUpdate;
lblPoints.Text = (score).ToString();
if (!letterInWord)
{
lblPoints.Text = (score = score - 10).ToString();
}
}`
Upvotes: 0
Views: 1366
Reputation: 4006
What exactly isn't working about the score? I just wrote some code up real quick, and had the score working fine. I see lots of things in your code I don't understand though, like:
score = score;
int amountToUpdate = 0;
score = score + amountToUpdate;
at the beginning, and:
score = score + amountToUpdate;
lblPoints.Text = (score).ToString();
at the end. Some of your variable names help, like rtbGuess tell me the guesses are typed into a rich text box.
Anyway, your code checks if the letter is incorrect, but not if it IS correct:
if (!letterInWord)
{
lblScore.Text = (int.Parse(lblScore.Text) - 10).ToString();
}
else
{
lblScore.Text = (int.Parse(lblScore.Text) + 10).ToString();
}
Upvotes: 2