예제 #1
0
        static void Main()
        {
            Postfix Post = null;                            //Postfix object used for conversion
            Utils.Menu menu;                                      //menu object to handle user interaction
            Choices choice;                                 //user's menu choice
            StreamReader rdr = null;                        //for file input
            OpenFileDialog dlg = null;
            DateTime CurrentDate = DateTime.Now;
            String Date = "";                               //Holds the current date
            Date += CurrentDate;
            String Title = "Infix to Postfix Conversion";   //Title of the program. Displayed in console title and program execution.
            String fileName;
            String Infix;                                   //Holds the infix expression read from the current line in the file.
            bool Valid = true;                              //Used to make conversion loop run only if a valid file was chosen

            Console.Title = Title;
            menu = new Utils.Menu("Menu");                        //Open a menu and add the choices
            menu = menu + "Open a file" + "Quit";
            choice = (Choices)menu.GetChoice();             //get the menu choice

            //Run the menu until quit option is chosen
            while (choice != Choices.QUIT)
            {
                //switch used for menu selection for easy expandability
                switch (choice)
                {
                    case Choices.OPEN:  //if user chose open file option

                    Console.Clear();
                    //run the open file dialog
                    dlg = new OpenFileDialog();
                    dlg.InitialDirectory = Application.StartupPath;
                    dlg.Title = "Open a Personal Library";
                    dlg.Filter = "text files|*.txt|all files|*.*";

                    if(dlg.ShowDialog() != DialogResult.Cancel)
                    {
                        fileName = dlg.FileName;
                        try
                        {
                            Valid = true;
                            rdr = new StreamReader(fileName);
                        }
                        catch (Exception)
                        {       //if file couldn't be opened, notify user and set Valid to false to skip conversion loop
                            Console.WriteLine("File could not be opened.");
                            Valid = false;
                            Utility.PressAnyKey();
                        }

                        //conversion loop. converts each line in the text file
                        while (Valid && rdr.Peek() != -1)
                        {
                            Console.Clear();
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.SetCursorPosition(Console.WindowWidth - Title.Length, 0);
                            Console.WriteLine(Title);
                            Console.SetCursorPosition(Console.WindowWidth - Date.Length, 1);
                            Console.WriteLine(Date);

                            Console.ForegroundColor = ConsoleColor.Blue;
                            Infix = rdr.ReadLine();
                            Console.WriteLine("Infix Expression: " + Infix + "\n\n");

                            Post = new Postfix(Infix);
                            Console.WriteLine("Postfix Expression: " + Post.PostfixExpression);
                            Utility.PressAnyKey();
                        }

                        if (rdr != null)    //close the file if a file was opened
                            rdr.Close();

                    }//if file was chosen

                    break;  //end of case OPEN

                }//end switch

                choice = (Choices)menu.GetChoice(); //get the next menu choice
            }//end while
        }
예제 #2
0
        /// <summary>
        ///     Initializes the <c>TargetSelector</c>, starting from the menu.
        /// </summary>
        /// <param name="rootMenu">
        ///     The parent menu
        /// </param>
        internal static void Initialize(Menu rootMenu)
        {
            Load.OnLoad += (sender, args) =>
                {
                    menu = new Menu("targetselector", "Target Selector");

                    if (GameObjects.EnemyHeroes.Any())
                    {
                        foreach (var enemy in GameObjects.EnemyHeroes)
                        {
                            var priority = HighestPriority.Any(t => t == enemy.ChampionName)
                                               ? 1
                                               : MedHighPriority.Any(t => t == enemy.ChampionName)
                                                     ? 2
                                                     : MedLowPriority.Any(t => t == enemy.ChampionName) ? 3 : 4;
                            menu.Add(new MenuSlider("ts" + enemy.ChampionName, enemy.ChampionName, priority, 0, 5));
                        }

                        menu.Add(new MenuSeparator("separatorOther", "Other Settings"));
                    }

                    menu.Add(new MenuBool("focusTarget", "Focus Selected Target", true));
                    menu.Add(new MenuBool("drawTarget", "Draw Target", true));
                    menu.Add(new MenuColor("drawTargetColor", "Draw Target Color", Color.Red));
                    menu.Add(new MenuSeparator("separatorMode", "Mode Selection"));
                    menu.Add(
                        new MenuList<TargetSelectorMode>("mode", "Mode")
                            { SelectedValue = TargetSelectorMode.AutoPriority });

                    rootMenu.Add(menu);

                    menu.MenuValueChanged += (objSender, objArgs) =>
                        {
                            var list = objSender as MenuList<TargetSelectorMode>;
                            if (list != null)
                            {
                                Mode = list.SelectedValue;
                            }
                        };

                    Drawing.OnDraw += eventArgs =>
                        {
                            if (menu["drawTarget"].GetValue<MenuBool>().Value && SelectedTarget.IsValidTarget())
                            {
                                var color = menu["drawTargetColor"].GetValue<MenuColor>().Color;
                                Drawing.DrawCircle(
                                    SelectedTarget.Position,
                                    150f,
                                    System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B));
                            }
                        };

                    Game.OnWndProc += eventArgs =>
                        {
                            if (eventArgs.Msg == (uint)WindowsMessages.LBUTTONDOWN)
                            {
                                SelectedTarget =
                                    GameObjects.EnemyHeroes.Where(
                                        hero => hero.IsValidTarget() && hero.DistanceSquared(Game.CursorPos) < 40000)
                                        .OrderBy(h => h.DistanceSquared(Game.CursorPos))
                                        .FirstOrDefault();
                            }
                        };

                    Mode = menu["mode"].GetValue<MenuList<TargetSelectorMode>>().SelectedValue;
                };
        }