Last active
August 9, 2020 06:18
-
-
Save Voidsay/a4435292ca4795b647857d6a364411b4 to your computer and use it in GitHub Desktop.
Fixed Tech-Helper503's Sourcecode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace guessing_game | |
{ | |
class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
//Initialization | |
//Console.WindowWidth = 1280;//no one cares about the size especially in such a simple beginner game | |
//Console.WindowHeight = 720; | |
Random ranNumGen = new Random(); | |
//Rules | |
Console.WriteLine("I am going to choose a random number:"); | |
Console.WriteLine("\tAnd you'll have to guess it."); | |
Console.WriteLine("\tYou have 3 attempts:"); | |
Console.WriteLine("\t\tsAnd If you lose all attempts,"); | |
Console.WriteLine("You will lose..."); | |
Console.WriteLine("If not,You wil win!"); | |
//Instanciancing the game | |
int randomNum = ranNumGen.GetHashCode();//why? literaly no reason to do this use "Random" class instead, it even gives you control on the range! | |
int attemps = 0; | |
//Starting the game | |
Console.WriteLine("Starting the game...."); | |
Console.WriteLine("I have made a choice "); | |
int code = 0;//needs to be declared fairly early | |
rewindepoint: | |
Console.WriteLine("Here it is:" + randomNum);// don't put out the number! That's the whole point of the game. | |
Console.WriteLine("Ready"); | |
string ready = Console.ReadLine(); | |
while (attemps < 2)//not <=3 you will get 4 attempts like this | |
{ | |
Console.WriteLine("Whats the code?"); | |
Int32.TryParse(Console.ReadLine(), out code);// will catch all invalid entries and prevent crash | |
if (code != randomNum) | |
{ | |
Console.WriteLine("Wrong.Try again"); | |
attemps++; | |
} | |
else if (code == randomNum) | |
{ | |
Console.WriteLine("Correct.The code is:" + code + ".Thanks for playing");//formating was a little messy replaced Write with Writeline | |
Console.WriteLine("Play again to see the rewind part by getting all three attemps wrong"); | |
Console.ReadLine();//just so it doesn't imidiatly closes | |
return; | |
} | |
} | |
if (code != randomNum) | |
{ | |
//Wait for a key | |
var key = Console.ReadKey(); | |
//Prints out the key then rewinds | |
Console.WriteLine("\nYou pressed the " + key + " key");//added \n for formating | |
Console.WriteLine("Rewinding..."); | |
//Console.WriteLine("Here it is:" + randomNum); | |
attemps = 0;//needs to be reset | |
goto rewindepoint;// because I can't be bothered to actually think of a good loop, don't do this at home kids it's bad style. | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment