public static void Exit(ExitOption option) { int ret; // IntPtr tokenHandle = IntPtr.Zero; ret = OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref tokenHandle); // long luid = 0; ret = LookupPrivilegeValue(null, SE_SHUTDOWN_NAME, ref luid); // TOKEN_PRIVILEGES tp; tp.PrivilegeCount = 1; tp.Privilege.Luid = luid; tp.Privilege.Attributes = SE_PRIVILEGE_ENABLED; ret = AdjustTokenPrivileges(tokenHandle, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero); // ExitWindowExFlags flag; switch (option) { case ExitOption.Logoff: flag = ExitWindowExFlags.EWX_LOGOFF; break; case ExitOption.Reboot: flag = ExitWindowExFlags.EWX_REBOOT; break; default: flag = ExitWindowExFlags.EWX_POWEROFF; break; } ret = ExitWindowsEx(flag | ExitWindowExFlags.EWX_FORCE, 0); }
static void Main(string[] args) { PrintCitizenOption printCitizen = new PrintCitizenOption(); Option1 option1 = new Option1(); ExitOption existOption = new ExitOption(); Validation validation = new Validation(); ConsoleSystem consoleSystem = new ConsoleSystem(); MenuBuilder <string> menuBuilderString = new MenuBuilder <string>(consoleSystem, validation); MenuBuilder <int> menuBuilderInt = new MenuBuilder <int>(consoleSystem, validation); var menu = menuBuilderString .AddOption(option1.OptionMessage, option1) .AddOption(existOption.OptionMessage, existOption); var menu2 = menuBuilderInt .AddOption(1, new MenuOption <string>(menu.Build(), "new menu")) .AddOption(2, printCitizen) .AddOption(3, existOption) .Build(); menu .AddOption("return to previous menu", new MenuOption <int>(menu2, "new menu")) .Build(); menu2.RunMenu(); }
public RocketMenu(IRocketFactory rocketFactory, IBattery battery) : base() { _rocketFactory = rocketFactory; _battery = battery; _optionAddRocket = new OptionAddRocket(_rocketFactory, ConsoleSystem); _optionBatteryReport = new OptionBatteryReport(_battery, ConsoleSystem); _optionEmptyingBattery = new OptionEmptyingBattery(_battery, ConsoleSystem); _optionLaunchAllRockets = new OptionLaunchAllRockets(_battery, ConsoleSystem); _optionLaunchRockets = new OptionLaunchRockets(_battery, ConsoleSystem); _exitOption = new ExitOption(); }
protected override void Compose() { Options = new[] { PlayOption, ExitOption }; PlayOption.SetParent(MainMenu); ExitOption.SetParent(MainMenu); ShipSelector.SetParent(MainMenu); }
static void Main(string[] args) { IWriter writer = new ConsoleWriter(); IOption firstOption = new ConcatOption(writer); IOption secondOption = new UpperCaseOption(writer); IDictionary <int, IOption> Subdictionary = new Dictionary <int, IOption>(); IMenu <int> subMenu = new Menu <int>(Subdictionary); IMenuDisplayer <int> displaySubMenu = new ConsoleDisplayer <int>(writer); IValidator <int> validator = new MenuValidator <int>(); IReader reader = new ConsoleReader(writer); IDataReader <int> dataReader = new DataReader <int>(validator, reader); IUserMenu <int> userSubMenu = new UserMenu <int>(displaySubMenu, dataReader, writer); IOption thirdOption = new SubDicitonaryOption <int>(userSubMenu, subMenu); IOption lastOption = new ExitOption(); IMengedMenu <int> subMengedMenu = new MengedMenu <int>(subMenu); subMengedMenu.AddOption(1, firstOption); subMengedMenu.AddOption(4, lastOption); IDictionary <int, IOption> dictionary = new Dictionary <int, IOption>(); IMenu <int> menu = new Menu <int>(dictionary); IMengedMenu <int> mengedMenu = new MengedMenu <int>(menu); mengedMenu.AddOption(1, firstOption); mengedMenu.AddOption(2, secondOption); mengedMenu.AddOption(3, thirdOption); mengedMenu.AddOption(4, lastOption); IMenuDisplayer <int> displayMenu = new ConsoleDisplayer <int>(writer); //IValidator<int> validator = new MenuValidator<int>(); //IReader reader = new ConsoleReader(writer); //IDataReader<int> dataReader = new DataReader<int>(validator, reader); IUserMenu <int> mainMenu = new UserMenu <int>(displayMenu, dataReader, writer); mainMenu.Run(menu); }
IEnumerator EndBattle() { Debug.Log("EndBattle"); // set battle has ended BattleHasEnded = true; battleHasEnded.Raise(); // Remove highlight from active unit ActiveUnitUI.HighlightActiveUnitInBattle(false); //// Set exit button variable //BattleExit exitButton = GetBattleExitButton(); //// Activate exit battle button; //exitButton.gameObject.SetActive(true); // Deactivate all other battle buttons; // SetBattleControlsActive(false); // Check who win battle if (!playerPartyPanel.CanFight()) { Debug.Log("Player cannot fight anymore"); // player cannot fight anymore // verify if player has flee from battle if (playerPartyPanel.HasEscapedBattle()) { Debug.Log("Player has escaped battle"); // On exit: move it 2 tiles away from other party exitOption = ExitOption.FleePlayer; } else { Debug.Log("Player lost battle and was destroyed"); // verify if battle was with city Garnizon: // .. this is not needed here because city garnizon cannot initiate fight // On exit: destroy player party exitOption = ExitOption.DestroyPlayer; } // Show how much experience was earned by enemy party enemyPartyPanel.GrantAndShowExperienceGained(playerPartyPanel); } else { Debug.Log("Enemy cannot fight anymore"); // verify if enemy has flee from battle if (enemyPartyPanel.HasEscapedBattle()) { Debug.Log("Enemy has escaped battle"); // On exit: move it 2 tiles away from other party exitOption = ExitOption.FleeEnemy; } else { Debug.Log("Enemy lost battle and was destroyed"); // verify if battle was with city Garnizon: if (enemyPartyPanel.GetHeroParty().PartyMode == PartyMode.Garnizon) { // On exit: enter city Debug.Log("Enter city on exit"); exitOption = ExitOption.EnterCity; } else if (enemyPartyPanel.GetHeroParty().PartyMode == PartyMode.Party) { // On exit: destroy enemy party exitOption = ExitOption.DestroyEnemy; } else { Debug.LogError("Unknown party mode " + enemyPartyPanel.GetHeroParty().PartyMode.ToString()); } } // Show how much experience was earned by player party playerPartyPanel.GrantAndShowExperienceGained(enemyPartyPanel); } // Remove all buffs and debuffs enemyPartyPanel.RemoveAllBuffsAndDebuffs(); playerPartyPanel.RemoveAllBuffsAndDebuffs(); // unblock input InputBlocker.SetActive(false); yield return(null); }
public void SetExitOption(ExitOption value) { exitOption = value; }