I made the popular Guess-The-Number game and included an AI version that picks random numbers. The AI version has slightly different Console
output that differ slightly, for example:
I generated a number between 1 and 100. Can you guess it?
You generated a number between 1 and 100. Let me try
First I did this:
Console.WriteLine("{0} generated a number between 1 and 100. {1}", ai? "I" : "You", ai? "Can you guess it?", "Let me try");
As this needed to be done a few more times, it looked very clumsy, but could implement both versions in one medium length method. After that I seperated the different versions and made two shorter methods GuessUser
and GuessAI
which are cleaner, but both share a lot of similar code, almost everything besides Console.WriteLine(x)
.
Is there a smart way to combine those two versions into a small method?