public void OnPost() { IsStatus = true; ActiveGame.Players = new List <Player>(); // Reset last game state ActiveGame.Init(); // Loop through each form param foreach (var key in Request.Form.Keys) { // Only check names if (!key.Contains("name-")) { continue; } // Get name Request.Form.TryGetValue(key, out var names); var name = names.ToString(); // Check input validity if (!InputValidator.CheckValidPlayerName(name)) { IsError = true; StatusMsg = "Invalid player name!"; return; } ActiveGame.Players.Add(new Player(name, ShipLogic.GenGameShipList())); } // Set pointers ActiveGame.InitPlayerPointers(); StatusMsg = "Players created!"; }
private static void InitializePlayers() { var playerCount = ActiveGame.GetRuleVal(RuleType.PlayerCount); ActiveGame.Players = new List <Player>(); for (var i = 0; i < playerCount; i++) { string name; while (true) { name = NameMenu("Creating players", $"Input a name for player {i + 1}/{playerCount}"); // User chose to quit the menu if (name == null) { return; } // Check input validity if (!InputValidator.CheckValidPlayerName(name)) { Console.WriteLine("Invalid name!"); Console.ReadKey(true); continue; } break; } // Generate ships for the player based on current rules var ships = ShipLogic.GenGameShipList(); ActiveGame.Players.Add(new Player(name, ships)); } }