示例#1
0
        static void Main(string[] args)
        {
            Engine engine = Engine.Instance;

            Screen screen = new Screen();

            engine.ActiveScreen = screen;
            engine.DebugEnabled = true;

            Tabs tabs = new Tabs(screen, new[] { "Texts", "Forms", "Drawings", "Charts", "Spinners", "Tables" }, 77, 26)
            {
                X = 1,
                Y = 2
            };

            StatusBar statusBar = new StatusBar(screen)
            {
                TextLeft   = "Left Text",
                TextCenter = "Status Bar",
                TextRight  = "Right Text"
            };

            MenuBar menuBar = new MenuBar(screen, new MenuItem(" ==CLIForms== ", null, true,
                                                               new MenuItem("Menu 1",
                                                                            new MenuItem("Item 1",
                                                                                         new MenuItem("Sub-Item 1"),
                                                                                         new MenuItem("Sub-Item 2"))
                                                                            , new MenuItem("Item 2")
                                                                            , new MenuItem("Item looong")),
                                                               new MenuItem("Menu 2"),
                                                               new MenuItem("Menu 3")));


            // ==== Texts Tab ====

            Label simpleLabel = new Label(null, "Simple Label")
            {
                X = 1,
                Y = 1
            };

            tabs.AddChild(simpleLabel, "Texts");

            Label multiLinesLabel = new Label(null, "Multi\nLines\nLabel")
            {
                X = 1,
                Y = 3
            };

            tabs.AddChild(multiLinesLabel, "Texts");

            FIG fig = new FIG(null, "FIGLet", "dosrebel")
            {
                X = 1,
                Y = 10
            };

            tabs.AddChild(fig, "Texts");

            // ==== Forms Tab ====

            Button button = new Button(null, "Button")
            {
                X     = 1,
                Y     = 1,
                Width = 10
            };

            tabs.AddChild(button, "Forms");

            Textbox simpleTextbox = new Textbox(null, "", "PlaceHolder", width: 20)
            {
                X = 1,
                Y = 5
            };

            tabs.AddChild(simpleTextbox, "Forms");

            Textbox simpleTextboxPwd = new Textbox(null, "", "Password", width: 20)
            {
                X          = 1,
                Y          = 7,
                IsPassword = true
            };

            tabs.AddChild(simpleTextboxPwd, "Forms");

            Checkbox checkbox = new Checkbox(null, "Checkbox")
            {
                X = 1,
                Y = 9
            };

            tabs.AddChild(checkbox, "Forms");

            Radio radio1 = new Radio(null, "Radio 1")
            {
                X = 1,
                Y = 12
            };

            tabs.AddChild(radio1, "Forms");

            Radio radio2 = new Radio(null, "Radio 2")
            {
                X = 1,
                Y = 14
            };

            tabs.AddChild(radio2, "Forms");

            Toggle toggle = new Toggle(null, "toggle")
            {
                X = 1,
                Y = 16
            };

            tabs.AddChild(toggle, "Forms");

            SingleLineListBox singleLineTextbox = new SingleLineListBox(null, new[]
            {
                new { id = 1, Text = "First Element" },
                new { id = 2, Text = "Second Element" },
                new { id = 3, Text = "Third Element" }
            }, "List Box")
            {
                X = 25,
                Y = 2,
                DisplayProperty = "Text"
            };

            tabs.AddChild(singleLineTextbox, "Forms");

            // ==== Drawings Tab ====
            Box box = new Box(null, 20, 10)
            {
                X = 1,
                Y = 1
            };

            tabs.AddChild(box, "Drawings");

            VericalLine vline = new VericalLine(null, 15)
            {
                X = 25,
                Y = 1
            };

            tabs.AddChild(vline, "Drawings");

            HorizontalLine hline = new HorizontalLine(null, 15)
            {
                X    = 27,
                Y    = 1,
                End1 = LineEndingStyle.T,
                End2 = LineEndingStyle.Plus
            };

            tabs.AddChild(hline, "Drawings");

            // ==== Charts Tab ====

            HorizontalChart hchart = new HorizontalChart(null, new List <float>()
            {
                0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            })
            {
                X      = 1,
                Y      = 1,
                Height = 7,
                DataForegroundColor = new[] { ConsoleColor.Cyan, ConsoleColor.Green, ConsoleColor.Magenta },
                ChartType           = ChartType.Point
            };

            tabs.AddChild(hchart, "Charts");

            // ==== Spinner Tab ====
            TinySpinner tinySpinner = new TinySpinner(null)
            {
                X = 1,
                Y = 1
            };

            tabs.AddChild(tinySpinner, "Spinners");

            Spinner spinner = new Spinner(null)
            {
                X = 4,
                Y = 1
            };

            tabs.AddChild(spinner, "Spinners");

            SpinnerBar spinnerBar = new SpinnerBar(null)
            {
                X = 8,
                Y = 1
            };

            tabs.AddChild(spinnerBar, "Spinners");

            // ==== Tables Tab ====
            SimpleTable table = new SimpleTable(null)
            {
                X                 = 1,
                Y                 = 1,
                ColumnCount       = 5,
                LineCount         = 4,
                ColumnsWidth      = new[] { 4, 15, 15, 5, 15 },
                ColumnsAlignments = new[]
                {
                    AlignmentStyle.Right, AlignmentStyle.Left, AlignmentStyle.Left, AlignmentStyle.Right,
                    AlignmentStyle.Left
                },
                TableStyle = TableStyle.CompactWithHeaderNoExtBorder
            };


            table[0] = new [] { "ID", "Name", "Surname", "Age", "Town" };

            table[0, 1] = "1";
            table[1, 1] = "John";
            table[2, 1] = "Doe";
            table[3, 1] = "25";
            table[4, 1] = "Paris";

            table[0, 2] = "2";
            table[1, 2] = "Mickel";
            table[2, 2] = "Mercy";
            table[3, 2] = "30";
            table[4, 2] = "Luxembourg";

            table[0, 3] = "3";
            table[1, 3] = "Albert";
            table[2, 3] = "Wood";
            table[3, 3] = "18";
            table[4, 3] = "JacksonVille";

            tabs.AddChild(table, "Tables");

            //tabs.ActiveTab = 3;

            engine.Start();

            // Console.ReadLine();
        }
示例#2
0
 private static void ReturnInfoFromButtons(RootWindow root, Button returnFromSell, Button returnFromBuy, Button returnFromStory, Button returnFromRetire, Button returnFromQuit, DisplayMainStatus buyBox, DisplayMainStatus sellBox, DisplayMainStatus storyBox, DisplayMainStatus retireBox, DisplayMainStatus quitBox, TinySpinner tinyspin, Spinner spinny)
 {
     returnFromBuy.Clicked += (s, e) =>
     {
         buyBox.Hide();
         TurnOnSpinners(spinny, tinyspin);
         root.Run();
     };
     returnFromSell.Clicked += (s, e) =>
     {
         sellBox.Hide();
         TurnOnSpinners(spinny, tinyspin);
         root.Run();
     };
     returnFromStory.Clicked += (s, e) =>
     {
         storyBox.Hide();
         TurnOnSpinners(spinny, tinyspin);
         root.Run();
     };
     returnFromRetire.Clicked += (s, e) =>
     {
         retireBox.Hide();
         TurnOnSpinners(spinny, tinyspin);
         root.Run();
     };
     returnFromQuit.Clicked += (s, e) =>
     {
         quitBox.Hide();
         TurnOnSpinners(spinny, tinyspin);
         root.Run();
     };
 }
示例#3
0
 private static void TurnOnSpinners(Spinner spinny, TinySpinner tinyspin)
 {
     spinny.Visible   = true;
     tinyspin.Visible = true;
 }
示例#4
0
 private static void TurnOffSpinners(Spinner spinny, TinySpinner tinyspin)
 {
     spinny.Visible   = false;
     tinyspin.Visible = false;
 }
示例#5
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();
        }