Вам нужно вызвать нужные вам методы из основной функции следующим образом ...
static void Main(string[] args)
{
Console.WriteLine("Hey! Welcome to Tina's Dice Game.");
Console.WriteLine("Let's start!");
EvenOrOdd();
playAgain();
}
Лучше всего вызвать playAgain
внутри EvenOrOdd
метода, чтобы все выглядело чище.
static void Main(string[] args)
{
Console.WriteLine("Hey! Welcome to Tina's Dice Game.");
Console.WriteLine("Let's start!");
EvenOrOdd();
}
public static int numberofInvokes = 0;
public void EvenOrOdd()
{
numberofInvokes += 1;
Random rnd = new Random();
int x = rnd.Next(1, 7);
int y = rnd.Next(1, 7);
int added = x + y;
if (added % 2 == 0)
{
Console.WriteLine("I got" + " " + x + " " + "and" + " " + y);
Console.WriteLine("Evens are better than odds.");
}
else
{
Console.WriteLine("I got" + " " + x + " " + "and" + " " + y);
Console.WriteLine("Odds are still cool!");
}
playAgain(); //Call playAgain from here.
}
public void playAgain()
{
Console.WriteLine("Do you want to play again?");
string val = Console.ReadLine();
if (val == "yes")
{
EvenOrOdd();
}
else
{
Console.WriteLine("The number of times the dice was thrown is:" + " " + numberofInvokes);
Console.WriteLine("Thanks for playing, come play again soon!");
}
}