public static Player GetPlayer(Player newPlayer, List <Player> myPlayers) { // Local variables string inputString; Player myPlayer = new Player(0, null, 0, 0, 0, 0, null, null, null); StandardMessages.PromptPlayerSignIn(); inputString = Console.ReadLine(); switch (inputString) { case "1": newPlayer = CreatePlayerFile(newPlayer); myPlayer.ID = newPlayer.ID; myPlayer.Name = newPlayer.Name; myPlayer.PlayerPassword = newPlayer.PlayerPassword; myPlayer.PlayerClass = newPlayer.PlayerClass; myPlayer.PlayerRace = newPlayer.PlayerRace; return(myPlayer); case "2": GetReturningPlayer(newPlayer, myPlayers); myPlayer.ID = newPlayer.ID; myPlayer.Name = newPlayer.Name; myPlayer.PlayerPassword = newPlayer.PlayerPassword; myPlayer.PlayerClass = newPlayer.PlayerClass; myPlayer.PlayerRace = newPlayer.PlayerRace; return(myPlayer); default: Console.WriteLine("ERROR: You must enter 1 or 2 to select an option."); return(null); } }
public static Player GetReturningPlayer(Player myPlayer, List <Player> myPlayers) { // Local variables string inputString = null; int playerCount = 0; int playerChoice = 0; myPlayers = GetPlayers(myPlayer); bool playerVerified = false; do { foreach (Player player in myPlayers) { Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine($"{player.ID}. {player.Name} - {player.PlayerRace} {player.PlayerClass}"); Console.ForegroundColor = ConsoleColor.Yellow; playerCount++; } do { Console.Write("Enter a number to choose a character profile: "); playerChoice = int.Parse(Console.ReadLine()); } while (playerChoice > playerCount || playerChoice <= 0); myPlayer.ID = myPlayers[playerChoice - 1].ID; myPlayer.Name = myPlayers[playerChoice - 1].Name; myPlayer.PlayerPassword = myPlayers[playerChoice - 1].PlayerPassword; myPlayer.PlayerClass = myPlayers[playerChoice - 1].PlayerClass; myPlayer.PlayerRace = myPlayers[playerChoice - 1].PlayerRace; int passwordAttempts = 0; while (inputString != myPlayer.PlayerPassword && passwordAttempts < 3) { inputString = StandardMessages.PromptPlayerPassword(); if (inputString == myPlayer.PlayerPassword) { playerVerified = true; } else { passwordAttempts++; } } } while (playerVerified == false); return(myPlayer); }
public static Player CreatePlayerFile(Player myPlayer) { // Local variables int playerCount = -1; try { List <Player> myPlayers = new List <Player>(); List <string> lines = File.ReadAllLines("Players.csv").ToList(); foreach (var line in lines) { playerCount++; } myPlayer.ID = playerCount + 1; myPlayer.Name = StandardMessages.PromptPlayerName(); myPlayer.PlayerPassword = StandardMessages.PromptPlayerPassword(); // TODO validate password do { myPlayer.PlayerRace = GetNewPlayerRace(StandardMessages.PromptPlayerRace()); } while (myPlayer.PlayerRace == null); do { myPlayer.PlayerClass = GetNewPlayerClass(StandardMessages.PromptPlayerClass()); } while (myPlayer.PlayerClass == null); lines.Add($"{myPlayer.ID},{myPlayer.Name},{myPlayer.PlayerPassword},{myPlayer.PlayerClass},{myPlayer.PlayerRace}"); File.WriteAllLines("Players.csv", lines); return(myPlayer); } catch (Exception ex) { Console.WriteLine("Data Write Error from PlayerFile.cs", ex); return(null); } }