public static Option RegisterShip(bool reRegister = false)
        {
            ConsoleWriter.ClearScreen();
            var lines     = File.ReadAllLines(@"UI/maps/5a.RegisterShip.txt");
            var drawables = TextEditor.Add.DrawablesAt(lines, 0);
            var nextLine  = drawables.Max(x => x.CoordinateY);
            var ships     = APICollector.ReturnShipsAsync().Where(s => double.Parse(s.ShipLength) <= 150).ToArray();
            var shipLines = ships.Select(x => "$ " + x.Model).ToArray();

            drawables.AddRange(TextEditor.Add.DrawablesAt(shipLines, nextLine + 3));
            TextEditor.Center.ToScreen(drawables, Console.WindowWidth, Console.WindowHeight);

            var selectionList = new SelectionList <SpaceShip>(ForegroundColor, '$');

            selectionList.GetCharPositions(drawables);
            selectionList.AddSelections(ships);
            ConsoleWriter.TryAppend(drawables);
            ConsoleWriter.Update();

            var ship = selectionList.GetSelection();

            if (reRegister)
            {
                DatabaseManagement.AccountManagement.ReRegisterShip(_account, ship);
                return(Option.Account);
            }

            DatabaseManagement.AccountManagement.Register(_account.User, ship, _namepass.accountName,
                                                          _namepass.password);
            return(Option.Login);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public static Option Receipts()
        {
            ConsoleWriter.ClearScreen();
            var lines     = File.ReadAllLines(@"UI/maps/7.Receipts.txt");
            var drawables = TextEditor.Add.DrawablesAt(lines, 0);

            TextEditor.Center.AllUnitsInXDir(drawables, Console.WindowWidth);
            ConsoleWriter.TryAppend(drawables);
            ConsoleWriter.Update();
            var receipts = DatabaseManagement.AccountManagement.GetAccountReceipts(_account);

            var receiptStrings = new List <string[]>();

            foreach (var receipt in receipts)
            {
                var addReceiptList = new string[]
                {
                    "____________________________",
                    "",
                    "Start time: " + receipt.StartTime,
                    "",
                    "End time: " + receipt.EndTime,
                    "",
                    "Price: " + receipt.Price,
                    "",
                    "",
                };
                receiptStrings.Add(addReceiptList);
            }

            var boxes = new List <BoxData>();
            var maxY  = drawables.Max(x => x.CoordinateY);

            Console.ForegroundColor = ConsoleColor.Green;

            int leftX =
                receiptStrings.Count > 4 ? Console.WindowWidth / 6 :
                receiptStrings.Count > 3 ? Console.WindowWidth / 5 :
                receiptStrings.Count > 2 ? Console.WindowWidth / 4 :
                receiptStrings.Count > 0 ? Console.WindowWidth / 3 : 0;

            int x = 0;
            int y = 0;

            foreach (var r in receiptStrings)
            {
                var newBox = new BoxData((leftX + x * 40, maxY + 5 + y * 10));
                newBox.Update(r);
                x++;
                y = x == 4 ? y + 1 : y;
                x = x == 4 ? 0 : x;
            }

            Console.ReadLine();
            return(Option.Account);
        }
        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);
        }
Esempio n. 5
0
        public static void Exit()
        {
            ConsoleWriter.ClearScreen();
            var lines     = File.ReadAllLines(@"UI/maps/8.Exit.txt");
            var drawables = TextEditor.Add.DrawablesAt(lines, 0);

            TextEditor.Center.ToScreen(drawables, Console.WindowWidth, Console.WindowHeight);
            ConsoleWriter.TryAppend(drawables);
            ConsoleWriter.Update();
            Thread.Sleep(2000);
            Environment.Exit(0);
        }
Esempio n. 6
0
        public static Option Welcome()
        {
            ConsoleWriter.ClearScreen();
            var lines       = File.ReadAllLines(@"UI/maps/1.Welcome.txt");
            var welcomeText = TextEditor.Add.DrawablesAt(lines, 0);

            TextEditor.Center.ToScreen(welcomeText, Console.WindowWidth, Console.WindowHeight);
            ConsoleWriter.TryAppend(welcomeText);
            ConsoleWriter.Update();

            return(Option.Start);
        }
Esempio n. 7
0
        public static Option Start()
        {
            ConsoleWriter.ClearScreen();
            var lines     = File.ReadAllLines(@"UI/maps/2.Start.txt");
            var drawables = TextEditor.Add.DrawablesAt(lines, 0);

            TextEditor.Center.ToScreen(drawables, Console.WindowWidth, Console.WindowHeight);
            var selectionList = new SelectionList <Option>(ConsoleColor.Green, '$');

            selectionList.GetCharPositions(drawables);
            selectionList.AddSelections(new[] { Option.Login, Option.Identification, Option.Exit });
            ConsoleWriter.TryAppend(drawables);
            ConsoleWriter.Update();

            return(selectionList.GetSelection());
        }
        public static Option HomePlanet()
        {
            ConsoleWriter.ClearScreen();
            var lines     = File.ReadAllLines(@"UI/maps/7.Homeplanet.txt");
            var drawables = TextEditor.Add.DrawablesAt(lines, 0);

            TextEditor.Center.ToScreen(drawables, Console.WindowWidth, Console.WindowHeight);

            var drawProps = drawables.FindAll(x => x.Chars == "¤");

            drawables = drawables.Except(drawProps).ToList();

            var props    = drawProps.Select(x => (x.CoordinateX, x.CoordinateY)).ToList();
            var home     = new LineData(props[0]);
            var rotation = new LineData(props[1]);
            var orbital  = new LineData(props[2]);
            var diameter = new LineData(props[3]);
            var climate  = new LineData(props[4]);
            var pop      = new LineData(props[5]);

            var homeplanet = _account.User.Homeplanet;

            Console.ForegroundColor = ConsoleColor.Green;
            home.Update(homeplanet.Name);
            rotation.Update(homeplanet.RotationPeriod);
            orbital.Update(homeplanet.OrbitalPeriod);
            diameter.Update(homeplanet.Diameter);
            climate.Update(homeplanet.Climate);
            pop.Update(homeplanet.Population);

            ConsoleWriter.TryAppend(drawables);
            ConsoleWriter.Update();

            Console.ForegroundColor = ConsoleColor.Green;


            Console.ReadLine();
            return(Option.Account);
        }
Esempio n. 9
0
        public static Option Account()
        {
            ConsoleWriter.ClearScreen();
            var lines     = File.ReadAllLines(@"UI/maps/6.Account.txt");
            var drawables = TextEditor.Add.DrawablesAt(lines, 0);

            TextEditor.Center.ToScreen(drawables, Console.WindowWidth, Console.WindowHeight);
            var parameterCoords = drawables.FindAll(x => x.Chars == "¤").ToList()
                                  .Select(x => (x.CoordinateX, x.CoordinateY)).ToList();

            var nameCoord = parameterCoords[0];
            var shipCoord = parameterCoords[1];

            var selectionList = new SelectionList <Option>(ForegroundColor, '$');

            selectionList.GetCharPositions(drawables);
            selectionList.AddSelections(new[]
            {
                Option.Parking,
                Option.Receipts,
                Option.ReRegisterShip,
                Option.Homeplanet,
                Option.Logout,
                Option.Exit
            });
            ConsoleWriter.TryAppend(drawables);
            ConsoleWriter.Update();

            Console.ForegroundColor = ConsoleColor.Green;
            LineTools.SetCursor(nameCoord);
            Console.Write(_account.User.Name);
            LineTools.SetCursor(shipCoord);
            Console.Write(_account.SpaceShip.Model);

            return(selectionList.GetSelection());
        }
Esempio n. 10
0
        public static Option Parking()
        {
            ConsoleWriter.ClearScreen();

            var lines     = File.ReadAllLines(@"UI/maps/7.Parking.txt");
            var drawables = TextEditor.Add.DrawablesAt(lines, 0);

            TextEditor.Center.ToScreen(drawables, Console.WindowWidth, Console.WindowHeight);
            var selectionList = new SelectionList <Option>(ConsoleColor.Green, '$');

            selectionList.GetCharPositions(drawables);
            selectionList.AddSelections(new[]
            {
                Option.PurchaseTicket,
                Option.ReEnterhours,
                Option.Account
            });

            var drawProps      = drawables.FindAll(x => x.Chars == "¤");
            var props          = drawProps.Select(x => (x.CoordinateX, x.CoordinateY)).ToList();
            var parkFromXY     = props[0];
            var pricePerHourXY = props[1];
            var shipLengthXY   = props[2];

            var calculatedPriceXY = props[3];
            var enterHoursXY      = props[4];
            var receiptXY         = props[5];
            var openNext          = DatabaseManagement.ParkingManagement.CheckParkingStatus();

            Console.ForegroundColor = ConsoleColor.Green;
            LineTools.SetCursor(parkFromXY);

            if (openNext.isOpen)
            {
                Console.Write("Now");
            }
            else
            {
                Console.Write(openNext.nextAvailable);
            }

            LineTools.SetCursor(pricePerHourXY);
            Console.Write(DatabaseManagement.ParkingManagement.CalculatePrice(_account.SpaceShip, 1) * 60);
            LineTools.SetCursor(shipLengthXY);
            Console.Write(_account.SpaceShip.ShipLength);

            ConsoleWriter.TryAppend(drawables.Except(drawProps).ToList());
            ConsoleWriter.Update();

            Option menuSel;
            double hours;


            var timeGetter = new TimeGetter(enterHoursXY, calculatedPriceXY, 10000,
                                            DatabaseManagement.ParkingManagement.CalculatePrice);

            if (openNext.isOpen == false)
            {
                Console.ReadKey(true);
                return(Option.Account);
            }

            do
            {
                hours   = timeGetter.GetMinutes(_account.SpaceShip);
                menuSel = selectionList.GetSelection();

                if (menuSel == Option.PurchaseTicket && hours == 0)
                {
                    menuSel = Option.ReEnterhours;
                }
            } while (menuSel == Option.ReEnterhours);

            if (Option.PurchaseTicket == menuSel)
            {
                ConsoleWriter.ClearScreen();

                var receipt = DatabaseManagement.ParkingManagement.SendInvoice(_account, hours);
                var boxData = new BoxData((Console.WindowWidth / 2 - 10, parkFromXY.CoordinateY));
                boxData.Update(new[] { "Loading receipt..." });

                string[] receiptString =
                {
                    "Purchase successful!",
                    "",
                    "Ticket Holder: " + receipt.Account.AccountName,
                    "Start time: " + receipt.StartTime,
                    "End time: " + receipt.EndTime,
                    "Price: " + receipt.Price
                };
                boxData.Update(receiptString);

                Console.ReadKey(true);
            }

            return(Option.Account);
        }
Esempio n. 11
0
        public static Option Identification()
        {
            ConsoleWriter.ClearScreen();
            var lines     = File.ReadAllLines(@"UI/maps/3a.Identification.txt");
            var drawables = TextEditor.Add.DrawablesAt(lines, 0);

            TextEditor.Center.ToScreen(drawables, Console.WindowWidth, Console.WindowHeight);
            ConsoleWriter.TryAppend(drawables);
            ConsoleWriter.Update();
            Console.CursorVisible   = true;
            Console.ForegroundColor = ConsoleColor.Green;

            Func <string, (int X, int Y)> GetCoord = chr =>
            {
                var drawable = drawables.Find(x => x.Chars == chr);
                return(drawable.CoordinateX, drawable.CoordinateY);
            };
            Action <string> Clear = clear =>
            {
                Console.CursorVisible = false;
                foreach (var c in clear)
                {
                    Console.Write(" ");
                }
                Console.CursorVisible = true;
            };

            var fCoord       = GetCoord("F");
            var nameEndCoord = GetCoord(":");

            LineTools.SetCursor((nameEndCoord.X + 2, nameEndCoord.Y));
            var username = Console.ReadLine();

            LineTools.ClearAt(fCoord, "First name: " + username);
            Console.Write("Security question loading...");

            Func <string, string> getSecurityAnswer = securityQuestion =>
            {
                LineTools.ClearAt(fCoord, "Security question loading...");
                Console.Write(securityQuestion + " ");
                return(Console.ReadLine());
            };

            var user = DatabaseManagement.AccountManagement.IdentifyWithQuestion(username, getSecurityAnswer);

            LineTools.ClearAt(fCoord, "Security question loading... plus the long answer that i cleared now!");

            if (user == null)
            {
                ConsoleWriter.ClearScreen();
                LineTools.SetCursor(fCoord);
                Console.Write("Incorrect answer or incorrect name input");
                Console.ReadKey(true);
                return(Option.Start);
            }

            var registrationExists = DatabaseManagement.AccountManagement.Exists(username, true);
            var userExists         = DatabaseManagement.AccountManagement.Exists(user.Name, false);

            if (registrationExists == false && userExists == false)
            {
                _account.User = user;
                return(Option.Registration);
            }


            LineTools.SetCursor(fCoord);
            Console.WriteLine("User is already registered");
            Thread.Sleep(1000);
            return(Option.Start);
        }