Ejemplo n.º 1
0
 private static void PrepWorkForTravel(out Location oldLocation, List <Planet> planets, Ship ship, Player player, StatusListBox status, ListBox planetList, out string planetName, out List <string> statusitems)
 {
     planetName  = planets[planetList.SelectedIndex].name;
     oldLocation = ship.location;
     statusitems = CurrentInfo.Update(player, ship, planets);
     foreach (var item in statusitems)
     {
         status.Items.Add(item);
     }
 }
Ejemplo n.º 2
0
        private static List <string> UpdateStatusBox(List <Planet> planets, Ship ship, Player player, StatusListBox status)
        {
            List <string> statusitems = CurrentInfo.Update(player, ship, planets);

            status.Items.Clear();
            foreach (var item in statusitems)
            {
                status.Items.Add(item);
            }

            return(statusitems);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            int      consoleWidth  = 150;
            int      consoleHeight = 52;
            Location oldLocation   = new Location(1, 1);
            Location newLocation   = new Location();
            var      root          = new RootWindow();
            var      planets       = Planet.PopulatePlanets();

            Console.SetWindowSize(consoleWidth, consoleHeight);

            Location shipLocation = new Location(1, 1);
            var      ship         = new Ship(shipLocation, Item.shipItemList());

            Console.WriteLine();
            Console.Write("Enter Your Name:  ");
            string name = "Zaphod Beeblebrox";

            Console.Clear();
            Console.WriteLine(Planet.Backstory());

            name = ForAQuickIntroCommentMeOut();

            var player = new Player(name);

            // Application.Init();

            // Create the windows on the display
            var           displayMap = MapBoxInitialize(root, planets); //Map and starfield
            StatusListBox status     = CurrentStatusBox(root);          //Status box "Galactic Hawker" box
            DialogListBox dialogList = GameDialogBox(root);             //Game Dialog Box

            //Creates the box for the Action buttons

            Button showTravelButton, showBuyButton, showSellButton, showStoryButton, showRetireButton, showQuitButton, warpButton, returnFromSell, returnFromBuy, returnFromStory, returnFromRetire, returnFromQuit;

            ActionButtonBox(root, out showTravelButton, out showBuyButton, out showSellButton, out showStoryButton, out showRetireButton, out showQuitButton);

            DisplayPlanetList displayPlanetList;
            ListBox           planetList;

            PlanetListBox(root, out displayPlanetList, out planetList);

            ListBox inventoryList = InventoryListBox(root);

            UpdateInventoryList(ship, inventoryList);

            PopulatePlanetListForTravel(planets, planetList);

            //Create all the popup boxes
            DisplayMainStatus warpSpeedBox, buyBox, sellBox, storyBox, retireBox, quitBox;


            AllPopUpBoxes(displayMap, out warpButton, out returnFromSell, out returnFromBuy, out returnFromStory, out returnFromRetire, out returnFromQuit, out warpSpeedBox, out buyBox, out sellBox, out storyBox, out retireBox, out quitBox);

            ConsoleColor colorRed  = (ConsoleColor)4;
            ConsoleColor colorBlue = (ConsoleColor)1;

            Spinner spinny = new Spinner(displayMap)
            {
                Top = 0, Left = 1, Spinning = true, Visible = true, Foreground = colorRed
            };
            TinySpinner tinyspin = new TinySpinner(displayMap)
            {
                Top = 1, Left = 2, Spinning = true, Visible = true, Background = colorBlue
            };

            ReturnInfoFromButtons(root, returnFromSell, returnFromBuy, returnFromStory, returnFromRetire, returnFromQuit, buyBox, sellBox, storyBox, retireBox, quitBox, tinyspin, spinny);

            // Start the business of what happens when they use enters stuff

            //TRAVEL BUTTON SELECTION
            showTravelButton.Clicked += (s, e) =>
            {
                //   showTravelButton.Hide();


                planetList.Show(); planetList.SetFocus();
            };
            string        planetName;
            List <string> statusitems;

            PrepWorkForTravel(out oldLocation, planets, ship, player, status, planetList, out planetName, out statusitems);

            planetList.Clicked += (s, e) =>
            {
                int  warpSpeed = 8;
                bool travelYes = false;
                newLocation = planets[planetList.SelectedIndex].location;

                (warpSpeed, travelYes) = GetWarpSpeed(oldLocation, newLocation, ship, player, dialogList);

                warpSpeedBox.Hide();

                if (travelYes)
                {
                    TravelDataToDialogBox(oldLocation, newLocation, warpSpeed, planets, ship, player, dialogList, planetList);

                    SpaceTravel.TravelToNewPlanet(oldLocation, newLocation, ship, player, warpSpeed);

                    Random getAttacked = new Random();
                    int    randomEvent = getAttacked.Next(0, 50);
                    if (randomEvent == 19)
                    {
                        TurnOffSpinners(spinny, tinyspin);
                        KilledByPirates(ship, player);
                    }
                    if (randomEvent == 42)
                    {
                        TurnOffSpinners(spinny, tinyspin);
                        KilledByTribbles(ship, player);
                    }

                    spinny.Top    = newLocation.y - 1;
                    spinny.Left   = newLocation.x;
                    tinyspin.Top  = newLocation.y;
                    tinyspin.Left = newLocation.x + 1;

                    ship.planetName = planets[planetList.SelectedIndex].name;
                }

                status.Items.Clear();

                statusitems = CurrentInfo.Update(player, ship, planets);
                oldLocation = ship.location;

                foreach (var item in statusitems)
                {
                    status.Items.Add(item);
                }
                root.Run();
            };


            // PURCHASE SECTION
            showBuyButton.Clicked += (s, e) =>
            {
                TurnOffSpinners(spinny, tinyspin);
                buyBox.Show();

                ListBox buyList;
                buyList = new ListBox(buyBox)
                {
                    Top = 1, Left = 1, Width = 43, Height = 8, Border = BorderStyle.Thin, Visible = true
                };

                string currentShipPlanetName = ship.planetName;
                var    currentIndex          = planets.FindIndex(x => x.name.Contains(currentShipPlanetName));

                buyList.Items.Clear();
                CreateAndPopulateBuyList(planets, buyList, currentIndex);

                buyList.SetFocus();
                buyList.Clicked += (s, e) =>
                {
                    int currentItem;
                    currentItem = buyList.SelectedIndex;
                    var    currentPlanet   = planets[currentIndex];
                    double cost            = currentPlanet.itemList[currentItem].planetCostFactor * currentPlanet.itemList[currentItem].value;
                    var    currentItemName = currentPlanet.itemList[currentItem].name;
                    double weight          = currentPlanet.itemList[currentItem].weight;
                    double newCapacity     = ship.totalCapacity - weight;

                    if (currentItemName == "Fuel              ") // special case for fuel
                    {
                        cost = 1;
                        if (EnoughMoney(player, cost))
                        {
                            dialogList.Items.Clear();
                            dialogList.Items.Add("You bought some " + currentItemName);
                            ship.fuelLevel += 500;;
                            player.Money   -= 25;
                        }
                        else
                        {
                            dialogList.Items.Clear();
                            dialogList.Items.Add("You don't have enough money to buy that!");
                        }
                    }
                    else
                    if (newCapacity >= 0)
                    {
                        {
                            if (EnoughMoney(player, cost))
                            {
                                var shipItemIndex = ship.cargoList.FindIndex(x => x.name.Contains(currentItemName));

                                if (shipItemIndex >= 0)
                                {
                                    ship.cargoList[shipItemIndex].quantity++;
                                    ship.totalCapacity -= weight;
                                    dialogList.Items.Clear();
                                    dialogList.Items.Add("You bought some " + currentItemName);
                                    UpdateInventoryList(ship, inventoryList);
                                    player.Money -= cost;
                                }
                            }
                            else
                            {
                                dialogList.Items.Clear();
                                dialogList.Items.Add("You don't have enough money to buy that!");
                            }
                        }
                    }
                    else
                    {
                        dialogList.Items.Clear();
                        dialogList.Items.Add("Your ship doesn't have the capacity to hold that too!");
                    }
                    statusitems = UpdateStatusBox(planets, ship, player, status);
                };
            };

            // SELLING SECTION
            showSellButton.Clicked += (s, e) =>
            {
                TurnOffSpinners(spinny, tinyspin);
                sellBox.Show();

                ListBox sellList;
                sellList = new ListBox(sellBox)
                {
                    Top = 1, Left = 1, Width = 43, Height = 8, Border = BorderStyle.Thin, Visible = true
                };

                string currentShipPlanetName = ship.planetName;
                var    currentIndex          = planets.FindIndex(x => x.name.Contains(currentShipPlanetName));

                sellList.Items.Clear();
                CreateAndPopulateSellList(planets, sellList, currentIndex);

                sellList.SetFocus();
                sellList.Clicked += (s, e) =>
                {
                    int currentItem;
                    currentItem = sellList.SelectedIndex;
                    var    currentPlanet   = planets[currentIndex];
                    double sellPrice       = currentPlanet.itemList[currentItem].planetCostFactor * currentPlanet.itemList[currentItem].value;
                    var    currentItemName = currentPlanet.itemList[currentItem].name;
                    double weight          = currentPlanet.itemList[currentItem].weight;
                    double newCapacity     = ship.totalCapacity - weight;

                    if (currentItemName == "Fuel              ") // special case for fuel
                    {
                        if (ship.fuelLevel > 0)
                        {
                            sellPrice = 1;
                            dialogList.Items.Clear();
                            dialogList.Items.Add("You sold some " + currentItemName);
                            ship.fuelLevel -= 100;;
                            player.Money++;
                            if (player.Money > 100000)
                            {
                                TheRichEnding(ship, player);
                            }
                        }
                        else
                        {
                            dialogList.Items.Clear();
                            dialogList.Items.Add("You don't have any " + currentItemName + " go buy some!");
                        }
                    }
                    else
                    {
                        var shipItemIndex = ship.cargoList.FindIndex(x => x.name.Contains(currentItemName));

                        if (shipItemIndex >= 0)
                        {
                            if (ship.cargoList[shipItemIndex].quantity > 0)
                            {
                                ship.cargoList[shipItemIndex].quantity--;
                                ship.totalCapacity += weight;
                                dialogList.Items.Clear();
                                dialogList.Items.Add("You sold some " + currentItemName);
                                UpdateInventoryList(ship, inventoryList);
                                player.Money += sellPrice;

                                if (player.Money > 100000)
                                {
                                    TheRichEnding(ship, player);
                                }
                            }
                            else
                            {
                                dialogList.Items.Clear();
                                dialogList.Items.Add("You don't have any " + currentItemName + " go buy some!");
                            }
                        }
                        else
                        {
                            dialogList.Items.Clear();
                            dialogList.Items.Add("That is some kind of error that shouldn't have happened!  Weird!!!");
                        }
                    }
                    statusitems = UpdateStatusBox(planets, ship, player, status);
                };
            };

            //STORY SECTION
            showStoryButton.Clicked += (s, e) =>
            {
                TurnOffSpinners(spinny, tinyspin);

                storyBox.Show();

                ReadPlanetInfoToTheConsole(planets);
            };

            //USER WANTS TO LIVE THE GOOD LIFE AND RETIRE
            showRetireButton.Clicked += (s, e) =>
            {
                TurnOffSpinners(spinny, tinyspin);

                UserMadeAGreatChoiceAndRetired(ship, player);

                Environment.Exit(42);
                // retireBox.Show();
            };

            //USER WANTS TO QUIT
            showQuitButton.Clicked += (s, e) =>
            {
                TurnOffSpinners(spinny, tinyspin);

                UserDecidedToQuit();

                // quitBox.Show();
                Environment.Exit(90210);
            };

            root.Run();
        }