Beispiel #1
0
        public void TravelPlanetPrompt(Characters self, Planet toPlanet)
        {
            Formulas form             = new Formulas();
            double   distanceToPlanet = form.Dist2Points(self.location.PlanetCoordinate, toPlanet.PlanetCoordinate);

            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine($"Your max speed is {form.WarpSpeed(self.mySpaceShip.engines.speed)}");
            Console.Write($"Please enter a speed between zero and {self.mySpaceShip.engines.speed}: ");
            bool isValidSpeed = double.TryParse(Console.ReadLine(), out double selectedSpeed);

            if (isValidSpeed && selectedSpeed > 0 && selectedSpeed <= self.mySpaceShip.engines.speed)
            {
                Console.WriteLine($"Your trip to {toPlanet.PlanetName} will take approximately {form.TravelTime(selectedSpeed, distanceToPlanet)} years\nDo you accept?");
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.Write("\n[Janet] Press 'Y' for yes or 'N'....please pick yes: ");
                ConsoleKeyInfo option = new ConsoleKeyInfo();
                bool           valid  = true;
                Movement       game   = new Movement();

                while (valid)
                {
                    Console.ForegroundColor = ConsoleColor.White;
                    option = Console.ReadKey();
                    switch (option.Key)
                    {
                    case ConsoleKey.Y:
                        self.location = toPlanet;
                        game.MovementMain(self, distanceToPlanet, selectedSpeed);
                        MarketResources item = new MarketResources();
                        item.MarketGenerate(self);
                        valid = false;
                        break;

                    case ConsoleKey.N:
                        Console.Clear();
                        TravelMenu(self);
                        break;

                    default:
                        Console.WriteLine("Invalid input!");
                        break;
                    }
                }
            }
        }
Beispiel #2
0
        }                                           /// our fearless hero



        public void MovementMain(SpaceCadets.Characters self, double Distance, double Speed)  //list of asteroid?? mySpaceShip will be passed
        {
            bool      alive = true;
            Asteroids ast   = new Asteroids();

            InitGame(self.mySpaceShip.rep);
            int width  = Console.WindowWidth - 1;
            int height = Console.WindowHeight;
            List <Coordinate> AsteroidList = new List <Coordinate> {
            };

            for (int i = 0; i < width / 2; i++)
            {
                AsteroidList.Insert(AsteroidList.Count, ast.spawnAsteroid(width, height));
                ast.AsteroidMover(AsteroidList);
            }
            ConsoleKeyInfo keyInfo;
            int            CycleCounter = 0;
            double         refreshVar   = 50 / Speed;
            int            timeLength   = 2 * Convert.ToInt32(Math.Round(Distance) * 200); //200 * 5ms per loop = ceiling counter
            int            timeCounter  = 0;

            {
                while (alive && timeCounter < timeLength)
                {
                    if (CycleCounter == refreshVar)
                    {
                        ast.AsteroidMover(AsteroidList);
                        AsteroidList.Insert(AsteroidList.Count, ast.spawnAsteroid(width, height));
                        CycleCounter = 0;
                    }
                    System.Threading.Thread.Sleep(5);
                    CycleCounter++;
                    timeCounter++;

                    if (Console.KeyAvailable)
                    {
                        keyInfo = Console.ReadKey(true);
                        switch (keyInfo.Key)
                        {
                        case ConsoleKey.UpArrow:
                            MoveHero(0, -1, self.mySpaceShip.rep);
                            break;

                        case ConsoleKey.RightArrow:
                            MoveHero(1, 0, self.mySpaceShip.rep);
                            break;

                        case ConsoleKey.DownArrow:
                            MoveHero(0, 1, self.mySpaceShip.rep);
                            break;

                        case ConsoleKey.LeftArrow:
                            MoveHero(-1, 0, self.mySpaceShip.rep);
                            break;

                        case ConsoleKey.Spacebar:
                            AsteroidList.Insert(AsteroidList.Count, ast.spawnAsteroid(width, height));
                            break;
                        }
                    }

                    foreach (Coordinate asteroidCoor in AsteroidList)
                    {
                        if ((asteroidCoor.X >= Hero.X && asteroidCoor.X <= Hero.X + self.mySpaceShip.rep.Length) && asteroidCoor.Y == Hero.Y)
                        {
                            alive = false;
                        }
                    }
                }
            }
            Console.Clear();
            Console.SetCursorPosition(height, width);
            if (alive == true)
            {
                Formulas          form     = new Formulas();
                SpaceCadets.Menus menu     = new SpaceCadets.Menus();
                double            tripTime = Distance / form.WarpSpeed(Speed);
                self.mySpaceShip.fuel.weight -= Distance * 100;
                self.Age += tripTime;
                menu.MainMenu(self);
            }
            else if (alive == false)
            {
                Console.Clear();
                YouLostButNotReally();
            }
        }