Пример #1
0
 private void SetRandomGoodsPrice(Goods[] goods, Random rand, TravelMenu travelMenu)
 {
     goods[1].SetPriceOfGood(rand.Next(1, 4500));
     goods[2].SetPriceOfGood(rand.Next(1, 3000));
     goods[3].SetPriceOfGood(rand.Next(1, 200));
     goods[4].SetPriceOfGood(rand.Next(1, 500));
     goods[5].SetPriceOfGood(rand.Next(1, 250));
     goods[6].SetPriceOfGood(rand.Next(1, 100));
     goods[7].SetPriceOfGood(rand.Next(100000, 400000));
     travelMenu.hasTravelled = false;
 }
Пример #2
0
        public UserInterface()
        {
            Random rand = new Random();
            //create and display story
            var story = new Story();

            //create goods
            var goods = CreateGoods();

            //Create ships
            var ships = CreateShips();

            //Create Planets
            var planets = CreatePlanets(rand);

            BuyMenu     buyMenu     = new BuyMenu();
            SellMenu    sellMenu    = new SellMenu();
            BuyShipMenu buyShipMenu = new BuyShipMenu();
            TravelMenu  travelMenu  = new TravelMenu();

            travelMenu.CalculateDistanceBetweenPlanets(planets);

            //Create user
            Console.Write("\nPlease enter your name: ");
            var player = new User(Console.ReadLine());

            //create warpSpeed
            var travel = new WarpSpeed();

            var  currentShip = ships[1];
            bool exit;

            player.SetCurrentPlanet(planets[0]);
            string exitMessage = "";

            do
            {
                var goodsQuantity = player.GetCurrentInventoryQuantities();
                int choice;
                Console.Clear();
                player.CalculateYears();
                exit = CheckExitCondition(player);
                if (exit)
                {
                    exitMessage = GetExitMessage(player);
                    break;
                }
                if (travelMenu.hasTravelled)
                {
                    SetRandomGoodsPrice(goods, rand, travelMenu);
                }

                do
                {
                    Console.Clear();
                    choice = DisplayMainMenu(player, currentShip);
                } while (choice < -1 || choice > 5 || choice == 0);

                switch (choice)
                {
                case -1:
                    exitMessage = "You have decided to retire.";
                    exit        = true;
                    break;

                case 1:
                    Console.Clear();
                    buyMenu.DisplayBuyMenu(player, goods);
                    Console.WriteLine(buyMenu.CheckBuy(player, goods));
                    Console.ReadLine();
                    break;

                case 2:
                    Console.Clear();
                    sellMenu.DisplaySellMenu(player, goods);
                    Console.WriteLine(SellMenu.CheckSell(player, goods, goodsQuantity));
                    Console.ReadLine();
                    break;

                case 3:
                    Console.Clear();
                    var options = travelMenu.DisplayTravelMenu(player, planets, currentShip);
                    choice = travelMenu.GetPlanetChoice(options);
                    Console.WriteLine(travelMenu.TryTravel(choice, currentShip, player, planets, travel));
                    Console.ReadLine();
                    break;

                case 4:
                    Console.Clear();
                    buyShipMenu.DisplayBuyShipMenu(player, ships, currentShip);
                    Console.WriteLine(BuyShipMenu.TryBuyShip(player, currentShip, ships));
                    Console.ReadLine();
                    break;

                case 5:
                    Console.Clear();
                    currentShip.RefuelShip(player, currentShip);
                    break;
                }
            } while (exit == false);
            story.DisplayEnd(player, exitMessage);
        }