Skip to content

Commit

Permalink
Move main logic from main menu to main method
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuinny committed Dec 23, 2023
1 parent b4ec16c commit 21be4b3
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions Source/Oligopoly.Game/Code/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class Program
private static List<Company> Companies = new List<Company>();
private static List<Event> Events = new List<Event>();
private static List<Event> GlobalEvents = new List<Event>();
private static bool CloseRequested = false;
private static int GameMode;
private static int Difficulty;
private static int TurnCounter;
Expand All @@ -19,7 +20,7 @@ public class Program
private const decimal WinningNetWorth = 50000.00M;

/// <summary>
/// Entry point for the game.
/// Contains entry point and main logic of the game.
/// </summary>
private static void Main()
{
Expand All @@ -30,6 +31,31 @@ private static void Main()
Console.BufferWidth = Console.WindowWidth;
Console.BufferHeight = Console.WindowHeight;
}

while (!CloseRequested)
{
switch (DisplayMainMenuScreen())
{
case 0:
LoadEmbeddedResources();
DisplayGameSetupMenu(false);
DisplayIntroductionLetter();
GameLoop();
break;
case 1:
LoadEmbeddedResources();
LoadGame();
DisplayGameSetupMenu(true);
GameLoop();
break;
case 2:
DisplayAboutGameMenu();
break;
case 3:
DisplayExitMenu();
break;
}
}
DisplayMainMenuScreen();
}

Expand Down Expand Up @@ -206,7 +232,7 @@ private static bool LoadGame()
/// <summary>
/// Displays main menu to the console.
/// </summary>
private static void DisplayMainMenuScreen()
private static int DisplayMainMenuScreen()
{
string prompt = @"
██████╗ ██╗ ██╗ ██████╗ ██████╗ ██████╗ ██████╗ ██╗ ██╗ ██╗
Expand All @@ -219,30 +245,8 @@ Use up and down arrow keys to select an option
";
string[] options = { "Play", "Load", "About", "Exit" };
Menu mainMenu = new Menu(prompt, options);
while (true)
{
switch (mainMenu.RunMenu())
{
case 0:
LoadEmbeddedResources();
DisplayGameSetupMenu(false);
DisplayIntroductionLetter();
GameLoop();
break;
case 1:
LoadEmbeddedResources();
LoadGame();
DisplayGameSetupMenu(true);
GameLoop();
break;
case 2:
DisplayAboutGameMenu();
break;
case 3:
DisplayExitMenu();
break;
}
}

return mainMenu.RunMenu();
}

/// <summary>
Expand Down Expand Up @@ -677,7 +681,7 @@ private static void DisplayExitMenu()
switch (exitMenu.RunMenu())
{
case 0:
Environment.Exit(0);
CloseRequested = true;
break;
}
}
Expand Down

0 comments on commit 21be4b3

Please sign in to comment.