public static int SecondsFromMidnight(DateTime time)
return time.Hour * 3600 + time.Minute * 60 + time.Second;
public static int MillsecondsFromMidnight(DateTime time)
return SecondsFromMidnight(time) * 1000 + time.Millisecond;
public static int rndNumberBetween(int min, int max)
oraCorrente = DateTime.Now;
sec = MillsecondsFromMidnight(oraCorrente);
public static int askInt(string question)
Console.WriteLine(question);
answer = Console.ReadLine();
InputOk = Int32.TryParse(answer, out number);
public static int askIntBetween(int min, int max, string question)
n = askInt(question + " (tra " + min + " e " + max + ")");
tuttoOk = (n >= min) && (n <= max);
public static bool HaiIndovinato(int n1, int n2, int s1, int s2, out int giuste, out int sbagliate)
if ( (!bn1) && (!bs2) && (n1==s2) )
if ((!bn2) && (!bs1) && (n2==s1))
public static void Main()
s1 = rndNumberBetween(MIN, MAX);
s2 = rndNumberBetween(MIN, MAX);
Console.WriteLine("segreto = " + s1 + s2);
n1 = askIntBetween(MIN, MAX, "dammi il primo numero");
n2 = askIntBetween(MIN, MAX, "dammi il secondo numero");
indovinato = HaiIndovinato(n1, n2, s1, s2, out giuste, out sbagliate);
Console.WriteLine("ritenta! Giuste:" + giuste + " - sbagliate: " + sbagliate);
{ Console.WriteLine("Bravo! hai indovinato con tentativi: " + tentativi); }