public static Option Login() { ConsoleWriter.ClearScreen(); var lines = File.ReadAllLines(@"UI/maps/3b.Login.txt"); var loginText = TextEditor.Add.DrawablesAt(lines, 0); TextEditor.Center.AllUnitsInXDir(loginText, Console.WindowWidth); TextEditor.Center.InYDir(loginText, Console.WindowHeight); ConsoleWriter.TryAppend(loginText); ConsoleWriter.Update(); var colons = loginText.FindAll(x => x.Chars == ":"); var nameLine = new InputLine(colons[0], 50, ForegroundColor); var accountName = nameLine.GetInputString(false); var passwordLine = new InputLine(colons[1], 50, ForegroundColor); var password = passwordLine.GetInputString(true); LineTools.ClearAt((nameLine.X, nameLine.Y), accountName); LineTools.ClearAt((passwordLine.X, passwordLine.Y), password); ConsoleWriter.ClearScreen(); Console.SetCursorPosition(Console.WindowWidth / 2 - 10, Console.WindowHeight / 2 - 3); Console.ForegroundColor = ConsoleColor.Green; Console.Write("Validating login..."); _account = DatabaseManagement.AccountManagement.ValidateLogin(accountName, password); return(_account != null ? Option.Account : Option.Start); }
public static Option Registration() { ConsoleWriter.ClearScreen(); var lines = File.ReadAllLines(@"UI/maps/4a.Registration.txt"); var drawables = TextEditor.Add.DrawablesAt(lines, 0); TextEditor.Center.AllUnitsInXDir(drawables, Console.WindowWidth); TextEditor.Center.InYDir(drawables, Console.WindowHeight); ConsoleWriter.TryAppend(drawables); ConsoleWriter.Update(); Func <IDrawable, (int X, int Y)> getCoord = drawable => (drawable.CoordinateX + 2, drawable.CoordinateY); var colons = drawables.FindAll(x => x.Chars == ":"); var nameCoord = getCoord(colons[0]); var pass1Coord = getCoord(colons[1]); var pass2Coord = getCoord(colons[2]); Console.ForegroundColor = ConsoleColor.Green; LineTools.SetCursor(nameCoord); var nameLine = new InputLine(nameCoord.X, nameCoord.Y, 30, ConsoleColor.Green); var pass1Line = new InputLine(pass1Coord.X, pass1Coord.Y, 30, ConsoleColor.Green); var pass2Line = new InputLine(pass2Coord.X, pass2Coord.Y, 30, ConsoleColor.Green); var accountName = ""; var password1 = ""; var password2 = ""; do { accountName = nameLine.GetInputString(false); password1 = pass1Line.GetInputString(true); password2 = pass2Line.GetInputString(true); LineTools.ClearAt(nameCoord, accountName); LineTools.ClearAt(pass1Coord, password1); LineTools.ClearAt(pass2Coord, password2); } while (password1 != password2 || accountName.Length <= 5 || password1.Length <= 5); _namepass = (accountName, password1); if (DatabaseManagement.AccountManagement.Exists(accountName, true)) { ConsoleWriter.ClearScreen(); LineTools.SetCursor(nameCoord); Console.Write("Account name is already taken!"); Console.ReadLine(); return(Option.Start); } return(Option.RegisterShip); }