Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
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());
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }