I have to create a guessing game which i have done but i want to add more features to it;
*increase in difficulty with each round.
*The player can only have 5 tries before it is game over.
*The player is timed.
*There is a scoring system.
At the moment i am concentrating on creating the different levels and i have a problem with the amount of attempts the player can take.
I have introduced a for loop: for(int iCounter = 0; iCounter < 5; iCounter++)
I experimented with placing this in numerous places in the code but where i have placed it now seems to be the only place it has worked.
I want the game to display a failed message if the 5th turn is incorrect. I have tried to change the numbers in the if statement and the for loop to numbers above and below 5 however nothing works.
When the player reaches the 5th turn they can enter a guess for a 6th time and then a failed message is displayed.
Also i have experimented with a for loop to increase the difficulty.
I would like the maximum randomly generated number to be increased by 10 with each turn.
But increase the number of attempts by 2 with each turn. I have tried to look through the books i have and on the internet but the code carries on with the first level or doesn't work at all.
I haven't looked into timers or scoring yet but if anybody would like to give me any tips that would be helpful.
Apologies if code isnt tagged properly (first time on the forum, however i think i've done it correctly)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication27
{
class Program
{
static void Main(string[] args)
{
while (true)//Starting a while loop so the program will keep going until the user guesses the correct number.
{
for (int iCounter = 0; iCounter < 5; iCounter++)/* for loop is created so the player can only have 5 attempts before failing.
{
Random winningNumber = new Random();//declaring and assigning the winning number to the random number
int returnValue = winningNumber.Next(1, 11);//Converting the random number into an integer
int userNumber = 0;//starts user number guess at the integer 0
int numberOfGuesses = 0;//starts the guess count at integer 0
while (userNumber != returnValue)//starts a while loop
{
Console.WriteLine("I am thinking of a number between 1 and 10\nTake 5 or less guesses to find out the number?");
userNumber = int.Parse(Console.ReadLine());// converts user input into an integer
numberOfGuesses++;//counts number of guesses the user has
if (iCounter > 5)//If the player takes more than 5 tries they fail the game
{//NEED TO MAKE THE FAILED MESSAGE COME UP AFTER THE FIFTH TURN THAT HAS FAILED!!!!!
Console.WriteLine("You have failed to guess the number i am thinking in 5 or less attemps\nGame Over\nWould you like to start again?yes/no");
string sUserNewChoice;//creating new variable for nre choice
sUserNewChoice = Console.ReadLine();
if (sUserNewChoice == "no")
Environment.Exit(0);//if the player does not want to play again the console will exit
else if (sUserNewChoice == "yes")
Main(args);// if the player does want to player again the game will start from the very beginning.
else
{
Console.WriteLine("Please choose yes or no");
return;
}
}
if (userNumber == 0)//if statement returning to the beginning of the code if 0 is entered.
return;
else if (userNumber < returnValue)//else if statement to command the appropriate action if a user inputs a number lower than the winning number.
{
Console.WriteLine("The number i am thinking of is higher than " + userNumber + ". You have taken " + numberOfGuesses + "\nGuess again (Press Enter to try again)");
Console.ReadLine();
Console.Clear();
++iCounter;
continue;//continues the loop
}
else if (userNumber > returnValue)// else if statement to command the appropriate action if a user inputs a higer number than the winning number.
{
Console.WriteLine("The number i am thinking of is lower than " + userNumber + ". You have taken " + numberOfGuesses + "\nGuess again (press Enter to try again)");
Console.ReadLine();
Console.Clear();
++iCounter;
continue;
}
}
Console.WriteLine("Well done! The answer was " + returnValue + "\nYou took " + numberOfGuesses + " guesses.");
Console.ReadLine();
Console.Clear();
string userChoice;//creates a new variable based on user text input
Console.WriteLine("Would you like to play the next level? yes/no");
userChoice = Console.ReadLine();
Console.Clear();
while (userChoice == "no")
if (userChoice == "no")//if statement responding to users input
{
Console.WriteLine("Thank you for playing\nGoodbye");
Environment.Exit(0);// Exits the whole program rather than breaking the loop
}
else if (userChoice == "yes")
continue;//continues to read the code
}
}
}
}
}
I will appreciate anyone that helps me to solve this problem.
my code is neater in visual studios than it appears on here, sorry if it is hard to read.

New Topic/Question
Reply



MultiQuote





|