Example #1
0
        public void Run()
        {
            ConsoleStuff.PrintTitle();

            ConsoleStuff.FormatAndPrint(ConsoleStuff.structureList);

            var play     = true;
            var newInput = true;

            while (play)
            {
                var isProcessed = false;

                if (newInput)
                {
                    ConsoleStuff.PrintInputRequest();

                    var input = Console.ReadLine();

                    isProcessed = ProcessInput(input);
                }

                if (isProcessed || !newInput)
                {
                    Update();
                    Render();
                }
                else
                {
                    Console.WriteLine("Input was not processed.");
                }

                ConsoleStuff.PrintContinueRequest();

                ConsoleStuff.ProcessContinueInput(ref play, ref newInput);
            }
        }
Example #2
0
        public bool ProcessInput(string input)
        {
            var inputs           = input.Split(" ");
            var desiredStructure = Convert.ToChar(inputs[0]);
            int floorNumber;
            int startX;

            //general input
            if (!ConsoleInputValidation.IsValidInputLength(inputs))
            {
                Console.WriteLine("Not enough input");
                return(false);
            }

            //0th input
            var nullableStructure = ConsoleStuff.GetStructureFromInput(desiredStructure);

            if (nullableStructure == null)
            {
                Console.WriteLine("Invalid Structure.");
                return(false);
            }
            var structure = (StructureTypes)nullableStructure;

            if (!tower.IsLobbyBuilt())
            {
                if (!(structure is StructureTypes.Lobby))
                {
                    Console.WriteLine("Must Build Lobby first");
                    return(false);
                }
            }
            //1st input
            int.TryParse(inputs[1], out floorNumber);

            if (!FloorValidation.IsValidFloorForMap(floorNumber))
            {
                Console.WriteLine("Floor is too large or small.");
                return(false);
            }
            if (FloorValidation.IsLobbyFloor(floorNumber))
            {
                if (!(structure is StructureTypes.Lobby))
                {
                    if (!(structure is StructureTypes.StairCase || (structure is StructureTypes.Elevator)))
                    {
                        Console.WriteLine("Lobby must be on first floor.");
                        return(false);
                    }
                }
            }
            var isExistingFloor = tower.IsValidExistingFloorNumber(floorNumber);

            if (!isExistingFloor)
            {
                if (!tower.IsNextFloorNumber(floorNumber))
                {
                    Console.WriteLine("Floor does not existing and preceding floor has not be created.");
                    return(false);
                }
            }
            //2nd input
            int.TryParse(inputs[2], out startX);
            //3rd input if any
            var endX  = GetEndX(inputs, startX, structure);
            var range = new Range(startX, endX);

            //validate range
            if (!(FloorValidation.IsValidRangeOnMap(range)))
            {
                Console.WriteLine("Invalid range on map.");
                return(false);
            }
            //range exists on parent floor

            if (!(structure == StructureTypes.StairCase || structure == StructureTypes.Elevator))
            {
                if (isExistingFloor && FloorValidation.IsFloorRangePreexisting(range, tower.Floors[floorNumber]))
                {
                    Console.WriteLine("Invalid range. Must be larger than current floor range");
                    return(false);
                }
                if (structure != StructureTypes.Lobby && FloorValidation.IsRangeExistingOnParent(range, tower.Floors[floorNumber - 1].Range))
                {
                    Console.WriteLine("Invalid range. Bottom floor does not have this range.");
                    return(false);
                }
            }
            //stairs and elevators
            else
            {
                if (!tower.IsValidExistingFloorNumber(floorNumber))
                {
                    Console.WriteLine("FloorNumber does not exist.");
                }
                if (structure == StructureTypes.StairCase &&
                    !tower.IsValidExistingFloorNumber(floorNumber + 1))
                {
                    Console.WriteLine("Top  floor does not exist.");
                    return(false);
                }
            }

            if (!PayForStructure(structure, isExistingFloor, floorNumber, range))
            {
                Console.WriteLine("Insuffient Funds.");
                return(false);
            }

            //Make Stuff
            if (!builder.BuildStuff(floorNumber, range, structure, isExistingFloor, tower))
            {
                Console.WriteLine("Something has gone terribily wrong.");
                return(false);
            }

            return(true);
        }
Example #3
0
 private void Render()
 {
     ConsoleStuff.PrintGameStats(tower, time, this.GlobalProperties);
 }