Exemplo n.º 1
0
        private static DialogListBox GameDialogBox(RootWindow root)
        {
            var displayGameDialog = new DisplayGameDialog(root)
            {
                Text = "Game Dialog", Width = 98, Height = 10, Top = 40, Left = 2, Border = BorderStyle.Thin
            };
            var dialogList = new DialogListBox(displayGameDialog)
            {
                Top = 1, Left = 0, Width = 98, Height = 8, Border = BorderStyle.Thin, Visible = true
            };

            return(dialogList);
        }
Exemplo n.º 2
0
        private static string CheckIfValidNumOrQ(DialogListBox dialogList)
        {
            ConsoleKeyInfo numChar;

            numChar = Console.ReadKey(true);
            string numString = "";
            int    numInt    = 0;

            try
            {
                numString = numChar.KeyChar.ToString();
            }
            catch (Exception)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                dialogList.Items.Add("That is not what we were looking for.  Please enter a number 1 to 9 or the letter 'q'.");
                dialogList.Items.Add("Giving you default value of '1'");
                Console.ResetColor();
                return("1");
            }
            if (numString == "q")
            {
                return(numString);
            }

            try
            {
                numInt = int.Parse(numString);
            }
            catch (Exception)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                dialogList.Items.Add("That is not what we were looking for.  Please enter a number 1 to 9 or the letter 'q'.");
                Console.ResetColor();
            }
            if (numInt > 0 && numInt < 10)
            {
                return(numString);
            }
            Console.ForegroundColor = ConsoleColor.Red;
            dialogList.Items.Add("You set a wrong value, so your warp value is set to 1.");
            Console.ResetColor();
            return("1");
        }
Exemplo n.º 3
0
        private static string CheckIfValidYorN(DialogListBox dialogList)
        {
            ConsoleKeyInfo numChar;

            numChar = Console.ReadKey(true);
            string numString = "";

            try
            {
                numString = numChar.KeyChar.ToString();
            }
            catch (Exception)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                dialogList.Items.Add("That is not what we were looking for. Some");
                Console.ResetColor();
                return("n");
            }
            return(numString);
        }
Exemplo n.º 4
0
        private static void TravelDataToDialogBox(Location oldLocation, Location newLocation, int warpSpeed, List <Planet> planets, Ship ship, Player player, DialogListBox dialogList, ListBox planetList)
        {
            dialogList.Items.Clear();
            dialogList.Items.Add("You traveled to " + planets[planetList.SelectedIndex].name);
            double tempTime, tempFuel, tempDistance = 42.9;

            tempDistance         = SpaceTravel.DistanceCalculation(oldLocation, newLocation);
            (tempTime, tempFuel) = SpaceTravel.WarpSpeedCalcuation(tempDistance, warpSpeed);
            dialogList.Items.Add("Distance was " + tempDistance + " lightyears");
            dialogList.Items.Add("You used " + tempFuel + " fuelies (the official fuel of NASCAR)");
            dialogList.Items.Add("And it took " + tempTime + " years.");
        }
Exemplo n.º 5
0
 private static bool travelCheck(double tempTime, double tempFuel, Player player, Ship ship, DialogListBox dialogList)
 {
     if (((tempTime + player.Age) <= 70) && (tempFuel < ship.fuelLevel))
     {
         return(true);
     }
     else
     {
         if ((tempTime + player.Age) > 70)
         {
             dialogList.Items.Add("Sorry, you are too old for that trip!  Use more Warp speed, or just retire!");
         }
         else
         {
             dialogList.Items.Add("You don't have enough fuel to make the trip at that warp speed. Try something slower");
         }
         return(false);
     }
 }
Exemplo n.º 6
0
        private static (int, bool) GetWarpSpeed(Location oldLocation, Location newLocation, Ship ship, Player player, DialogListBox dialogList)
        {
            //TODO list of warp speed and it shows you the list of calculations

            int  warpSpeed = 7;
            bool done      = false;
            bool travelYes = false;

            do
            {
                dialogList.Items.Clear();
                dialogList.Items.Add("Enter 'q' to exit the warp speed selection");
                dialogList.Items.Add("What is your warp speed of choice (1-9): ");

                string numString = CheckIfValidNumOrQ(dialogList);

                if (numString == "q")
                {
                    done = true;
                    dialogList.Items.Clear();
                }
                else
                {
                    warpSpeed = int.Parse(numString);
                    double tempTime, tempFuel, tempDistance = 42.9;
                    tempDistance         = SpaceTravel.DistanceCalculation(oldLocation, newLocation);
                    (tempTime, tempFuel) = SpaceTravel.WarpSpeedCalcuation(tempDistance, warpSpeed);
                    dialogList.Items.Add("That is " + tempDistance + " lightyears away");
                    dialogList.Items.Add("You will use " + tempFuel + " fuelies to get there at Warp " + warpSpeed);
                    dialogList.Items.Add("And will take " + tempTime + " years.");
                    bool   canTravel = travelCheck(tempTime, tempFuel, player, ship, dialogList);
                    string answer    = "n";
                    if (canTravel)
                    {
                        dialogList.Items.Add("Do you want to go now? Y/N: ");
                        answer = CheckIfValidYorN(dialogList);
                    }

                    if (answer == "y")
                    {
                        done      = true;
                        travelYes = true;
                    }
                    else
                    {
                        dialogList.Items.Add("Do you want to try a different Warp speed? y/n: ");
                        answer = CheckIfValidYorN(dialogList);
                        if (answer == "n")
                        {
                            done      = true;
                            travelYes = false;
                        }
                    }
                };
            } while (!done);

            return(warpSpeed, travelYes);
        }
Exemplo n.º 7
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();
        }