private static void Main() { // Start console ConsoleManager.Start(); ConsoleManager.Initialize(); // Wait for console to get ready TODO: Actually check for when ConsoleManager is ready Thread.Sleep(1000); // Ask what game to start StartCommand command; while (true) { // Write available commands Console.WriteLine("Pick one of the following commands", Color.White); foreach (string commandName in Enum.GetNames(typeof(StartCommand))) // TODO: Also number the commands { Console.WriteLine(commandName, Color.White); } // Get and parse input if (!Enum.TryParse(ConsoleManager.GetPriorityInput(), true, out command)) { Console.WriteLine("Input invalid, try again.", Color.Red); } // Break loop on successful parse else { break; } } // Start game switch (command) { case StartCommand.Local: StartLocal(); break; case StartCommand.P2P: StartPeerToPeer(); break; case StartCommand.Client: StartClient(); break; case StartCommand.Server: StartServer(); break; case StartCommand.ClientAndServer: StartClientAndServer(); break; default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Gets input for a player /// </summary> /// <param name="player"></param> public static Player GetPlayerSettingsInput() { // Get name string name = null; const int maxNameLength = 12; while (true) { Console.Write("Input name: ", System.Drawing.Color.White); name = ConsoleManager.GetPriorityInput(); if (name.Length > maxNameLength) { Console.WriteLine($"That name is too long, max length is {maxNameLength}", System.Drawing.Color.Red); continue; } if (name.Length < 1) { Console.WriteLine("Name can not be empty", System.Drawing.Color.Red); continue; } if (name == "empty") { System.Console.WriteLine("i guess it can be empty..."); } break; } // Get shape PlayerShape shape; while (true) { // Write available shapes Console.WriteLine("Available shapes: ", System.Drawing.Color.White); foreach (string s in Enum.GetNames(typeof(PlayerShape))) { Console.WriteLine(s, System.Drawing.Color.White); } Console.Write("Input shape: ", System.Drawing.Color.White); string str = ConsoleManager.GetPriorityInput(); if (int.TryParse(str, out int shapeInt)) { if (shapeInt < 1 || shapeInt > Enum.GetNames(typeof(PlayerShape)).Length) // TODO: Separate { Console.WriteLine("incorrect input, try again.", System.Drawing.Color.Red); continue; } shape = (PlayerShape)shapeInt - 1; } else { if (!Enum.TryParse(str, true, out shape)) { Console.WriteLine("incorrect input, try again.", System.Drawing.Color.Red); continue; } } break; } // Get drawingColor PlayerColor color; while (true) { Console.Write("Colors: ", System.Drawing.Color.White); string[] cs = Enum.GetNames(typeof(PlayerColor)); for (int i = 0; i < cs.Length; i++) { Console.Write($"{cs[i]} ", PlayerColors.Colors[i].ToSystemColor()); } if (!Enum.TryParse(ConsoleManager.WaitGetPriorityInput("\nInput color: ", false), true, out color)) { Console.WriteLine("incorrect input, try again.", System.Drawing.Color.Red); continue; } break; } Console.WriteLine($"Created player {name} using {color} {shape}.", PlayerColors.Colors[(int)color].ToSystemColor()); return(new Player(name, shape, color)); }