Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling Main( ) from another class

I have a class named TestMaze. I have another class named DisplayHome which has a method called gameOver():

public void gameOver()
    {
        Console.Write("GAME OVER!");
        Console.Write("Play Again? Y/N");
        if(char.ToLower(Convert.ToChar(Console.Read())=='y')
            //Main()
        else
            Environment.Exit(1);
    }

How can I call the Main method?
PS. they have the same namespace. I just need to know how can I call the Main method again.

like image 827
Reinan Contawi Avatar asked Dec 28 '22 17:12

Reinan Contawi


2 Answers

You should have a Play() method inside your Main... and GameOver() should call Play() if user enters 'y'.

like image 169
c0deNinja Avatar answered Jan 13 '23 12:01

c0deNinja


Refactor your code. Move whatever needs to be called into another function, and call it from both, main, and gameOver.

like image 24
K Mehta Avatar answered Jan 13 '23 12:01

K Mehta