protected virtual string GetPlayerName(IConsoleWindow console) { console.Write(Position.Zero, ConsoleColor.Green, "Enter Player's Name: "); console.Render(); Console.ForegroundColor = ConsoleColor.White; return(ConsoleInputReader.ReadLine()); }
private string GetPlayerName() { string name; ConsoleRenderer.ForegroundColor(ConsoleColor.Green); ConsoleRenderer.Write("Type player's name : "); ConsoleRenderer.ResetColor(); ConsoleRenderer.WriteLine("(including only small and capital letters and between 2 and 10 characters)"); while (true) { try { name = ConsoleInputReader.ReadLine(); if (!PlayerNamePattern.IsMatch(name)) { throw new ArgumentException("Invalid name. Try again."); } break; } catch (ArgumentException ex) { ConsoleRenderer.WriteLine(ex.Message); } } ConsoleRenderer.ForegroundColor(ConsoleColor.Green); ConsoleRenderer.WriteLine("Player name set to: {0}", name); ConsoleRenderer.ResetColor(); return(name); }
private IRace GetPlayerRace() { ConsoleRenderer.ForegroundColor(ConsoleColor.Green); ConsoleRenderer.WriteLine("Choose a race : "); ConsoleRenderer.ResetColor(); for (int i = 0; i < this.availableRaces.Count; i++) { IRace currentRace = Activator.CreateInstance(this.availableRaces[i]) as IRace; ConsoleRenderer.WriteLine("{0}: {1} - (Health: {2}, Damage: {3})", i + 1, this.availableRaces[i].Name, currentRace.Health, currentRace.Damage); } int index; while (true) { try { string raceNumber = ConsoleInputReader.ReadLine(); if (!int.TryParse(raceNumber, out index)) { throw new ArgumentException("Please enter a valid race number."); } index = int.Parse(raceNumber); if (index < 1 || index > this.availableRaces.Count) { throw new ArgumentOutOfRangeException("Please enter a valid race number."); } break; } catch (ArgumentOutOfRangeException ex) { ConsoleRenderer.WriteLine(ex.Message); } catch (ArgumentException ex) { ConsoleRenderer.WriteLine(ex.Message); } } ConsoleRenderer.ForegroundColor(ConsoleColor.Green); ConsoleRenderer.WriteLine("Race chosen: {0}", this.availableRaces[index - 1].Name); ConsoleRenderer.ResetColor(); return(Activator.CreateInstance(this.availableRaces[index - 1]) as IRace); }