public Situation HandleSituation(Situation currentSituation, GameController gameController) { Player player = gameController.player; SituationContainer situations = gameController.situations; Branch branch = situations.GetBranch(currentSituation.objectID); Situation resultSituation = currentSituation; MenuDrawer.Select( branch.title, Dictionaries.Merge( branch.nextSituations.ToDictionary( (NextSituation nextSituation) => Pair(nextSituation.title, Action(() => { resultSituation = situations.RandomSituationByIDs(nextSituation.IDs); })) ), MakeDictionary( Pair("Инвентарь", Action(() => InventoryController.Start(player))), Pair("Сохраниться", EmptyAction), Pair("Выйти", ThrowAction(new GameOverException())) ) ) ); return(resultSituation); }
public Situation HandleSituation(Situation currentSituation, GameController gameController) { Player player = gameController.player; SituationContainer situations = gameController.situations; ItemContainer items = gameController.items; Quest quest = situations.GetQuest(currentSituation.objectID); Situation resultSituation = currentSituation; Item questItem = items.ResolveReference(quest.questItem); MenuDrawer.Select( $"Вы встретили {quest.holderName}. Он/она/оно предлагает вам квест.", MakeDictionary( Pair($"Дать {quest.questItem.count}x {questItem.name}", Action(() => { int requiredCount = quest.questItem.count; int realCount = player.CountOfItemInInventory(questItem); if (realCount < requiredCount) { MenuDrawer.ShowInfoDialog($"Вам нехватает {requiredCount - realCount}x {questItem.name}."); } else { player.RemoveItemFromInventory(questItem, requiredCount); player.coins += quest.coinsReward; foreach (ItemReference rewardItemRef in quest.itemsReward) { Item rewardItem = items.ResolveReference(rewardItemRef); player.AddItemToInventory(rewardItem, rewardItemRef.count); } string rewardItemsString = quest.itemsReward .Map(items.ResolveReferenceAndCount) .Map(TupleFunc((Item item, int count) => $"{count}x {item.name}")) .Join(", "); if (rewardItemsString.IsEmpty()) { MenuDrawer.ShowInfoDialog($"Квест выполнен! Вы получили за квест {quest.coinsReward} монет."); } else { MenuDrawer.ShowInfoDialog($"Квест выполнен! Вы получили за квест {rewardItemsString} и " + $"{quest.coinsReward} монет."); } } })), Pair("Уйти", Action(() => { resultSituation = situations.RandomSituationByIDs(quest.situationsOnCancel); })), Pair("Инвентарь", Action(() => InventoryController.Start(player))), Pair("Сохраниться", EmptyAction), Pair("Выйти", ThrowAction(new GameOverException())) ) ); return(resultSituation); }
private void Awake() { _ingredientMover = FindObjectOfType <IngredientMover>(); _menuDrawer = GetComponentInParent <MenuDrawer>(); _ingredientSlice = GetComponent <IngredientSlice>(); // is called after menuDrawer is initialized since it is the one assigning the start position. _menuDrawer.OnInitialized += LogStartTransform; }
public OSPairPage() { this.InitializeComponent(); menu = MenuDrawer.GetInstance(); if (menu != null) { menu.Title("Pair"); menu.ShowMenu(); menu.SelectItem((int)MainPage.Page.PAIR); } }
public OSSettings() { this.InitializeComponent(); menu = MenuDrawer.GetInstance(); if (menu != null) { menu.Title("Settings"); menu.ShowMenu(); menu.SelectItem((int)MainPage.Page.SETTINGS); } }
public Situation HandleSituation(Situation currentSituation, GameController gameController) { Player player = gameController.player; SituationContainer situations = gameController.situations; ItemContainer items = gameController.items; Merchant merchant = situations.GetMerchant(currentSituation.objectID); Situation resultSituation = currentSituation; Dictionary <string, Action> actions = merchant.items.ToDictionary( (MerchantItem itemRef) => { int itemPrice = itemRef.price; Item item = items.GetByTypeAndID(itemRef.type, itemRef.id); string title = $"Купить '{item.name}' ({item.description}) - {itemPrice} монет"; return(Pair(title, Action(() => { if (player.coins >= itemPrice) { if (player.inventory.Count < Player.MAX_INVENTORY_SIZE) { player.AddItemToInventory(item); player.coins -= itemPrice; MenuDrawer.ShowInfoDialog($"Вы купили '{item.name}'!"); } else { MenuDrawer.ShowInfoDialog("Вам нехватает места в инвентаре!"); } } else { MenuDrawer.ShowInfoDialog($"Вам нехватает {itemPrice - player.coins} монет!"); } }))); } ); MenuDrawer.Select( $"Вы провстречали '{merchant.name}' ({merchant.type}). Ваши монеты: {player.coins}.", Dictionaries.Merge( actions, MakeDictionary( Pair("Продолжить", Action(() => { resultSituation = situations.RandomSituationByIDs(merchant.nextSituations); })), Pair("Инвентарь", Action(() => InventoryController.Start(player))), Pair("Сохраниться", EmptyAction), Pair("Выйти", ThrowAction(new GameOverException())) ) ) ); return(resultSituation); }
public OSHomePage() { this.InitializeComponent(); menu = MenuDrawer.GetInstance(); if (menu != null) { menu.Title("Home"); menu.HideMenu(); menu.SelectItem((int)MainPage.Page.HOME); } }
public OSFlyPage() { this.InitializeComponent(); menu = MenuDrawer.GetInstance(); if (menu != null) { menu.HideMenu(); } Settings settings = ((Settings)ControlPanel.DataContext); ControlGyroscope.Enable = settings.SetGyroscope; ControlJoystick.Enable = settings.SetPad; }
public Form1() { InitializeComponent(); try { Cursor = new Cursor(Path.Combine(AppDomain.CurrentDomain.BaseDirectory !, @"Sprites\cursor.ico")); _menuDrawer = new MenuDrawer(); _gameDrawer = new GameDrawer(); _resultScreenDrawer = new ResultScreenDrawer(); _levelRedactorDrawer = new LevelRedactorDrawer(); KeyDown += KeyDownProcessor; KeyUp += KeyUpProcessor; MouseWheel += MouseWheelProcessor; InitEngine(); } catch (Exception e) { Console.WriteLine(e.Data); Console.WriteLine(e.Message); Console.WriteLine(e.Source); Console.WriteLine(e.StackTrace); } }
public Situation HandleSituation(Situation currentSituation, GameController gameController) { Player player = gameController.player; SituationContainer situations = gameController.situations; ItemContainer items = gameController.items; Enemy enemy = situations.GetEnemy(currentSituation.objectID); Situation resultSituation = currentSituation; MenuDrawer.Select( $"{enemy.name} встаёт на вашем пути. У него {enemy.health}/{enemy.maxHealth} здоровья, " + $"{enemy.defense} защиты и {enemy.attack} атаки.", MakeDictionary( Pair("Сразиться", Action(() => { int enemyHealth = enemy.health; string resultSituationID = ""; while (resultSituationID.IsEmpty()) { MenuDrawer.Select( $"Игрок ({player.health}/{player.maxHealth} HP, {player.attack} ATK, {player.defense} DEF) " + $"VS {enemy.name} ({enemyHealth}/{enemy.maxHealth} HP, {enemy.attack} ATK, {enemy.defense} DEF)", MakeDictionary <string, Action>( Pair <string, Action>("Атаковать", () => { enemyHealth -= ComputeRealDamage(player.attack, enemy.defense); if (enemyHealth <= 0) { resultSituationID = enemy.situationsOnDefeat.RandomElement(); player.coins += enemy.coinsReward; foreach (ItemReference dropRef in enemy.drop) { Item item = items.ResolveReference(dropRef); for (int i = 0; i < dropRef.count; i++) { player.AddItemToInventory(item); } } if (enemy.drop.IsEmpty()) { MenuDrawer.ShowInfoDialog($"{enemy.name} повержен! Вы получили за это " + $"{enemy.coinsReward} монет."); } else { IEnumerable <string> dropNames = enemy.drop .Select((ItemReference itemRef) => { Item item = items.GetByTypeAndID(itemRef.type, itemRef.id); return($"{itemRef.count}x {item.name}"); }); string dropString = string.Join(", ", dropNames); MenuDrawer.ShowInfoDialog($"{enemy.name} повержен! Вы получили за это " + $"{dropString} и {enemy.coinsReward} монет."); } } else { int damageToPlayer = ComputeRealDamage(enemy.attack, player.defense); player.health -= damageToPlayer; if (player.health <= 0) { MenuDrawer.ShowInfoDialog($"Вас убил {enemy.name}!"); throw new GameOverException(); } MenuDrawer.ShowInfoDialog($"{enemy.name} нанёс вам {damageToPlayer} урона."); } }), Pair <string, Action>("Инвентарь", () => InventoryController.Start(player)), Pair <string, Action>("Убежать", () => { resultSituationID = enemy.situationsOnRunAway.RandomElement(); }) ) ); } resultSituation = situations.GetSituation(resultSituationID); })), Pair("Убежать", Action(() => { resultSituation = situations.RandomSituationByIDs(enemy.situationsOnRunAway); })), Pair("Инвентарь", Action(() => InventoryController.Start(player))), Pair("Сохраниться", EmptyAction), Pair("Выйти", ThrowAction(new GameOverException())) ) ); return(resultSituation); }
public Situation HandleSituation(Situation currentSituation, GameController gameController) { Player player = gameController.player; SituationContainer situations = gameController.situations; ItemContainer items = gameController.items; CraftingPlace craftingPlace = situations.GetCraftingPlace(currentSituation.objectID); Situation resultSituation = currentSituation; var actions = craftingPlace.crafts.ToDictionary((Craft craft) => { List <Tuple <Item, int> > ingredientsAndCounts = craft.ingredients.Map(items.ResolveReferenceAndCount); List <string> ingredientsNames = ingredientsAndCounts .Map(TupleFunc((Item ingredient, int count) => $"{count}x {ingredient.name}")); Item craftResult = items.ResolveReference(craft.result); var craftTitle = $"{ingredientsNames.Join(" + ")} => {craft.result.count}x {craftResult.name}"; return(Pair(craftTitle, Action(() => { List <Tuple <Item, int> > missingIngredients = ingredientsAndCounts .Map(TupleFunc((Item ingredient, int requiredCount) => { int realCount = player.CountOfItemInInventory(ingredient); return Tuple.Create(ingredient, requiredCount - realCount); })) .Filter(TupleFunc((Item ingredient, int missingCount) => missingCount > 0)); if (missingIngredients.IsEmpty()) { int ingredientsCount = ingredientsAndCounts .Map(TupleFunc((Item ingredient, int count) => count)) .Sum(); int inventorySizeAfterCraft = player.inventory.Count - ingredientsCount + craft.result.count; if (inventorySizeAfterCraft < Player.MAX_INVENTORY_SIZE) { ingredientsAndCounts.ForEach(TupleAction <Item, int>(player.RemoveItemFromInventory)); player.AddItemToInventory(craftResult, craft.result.count); MenuDrawer.ShowInfoDialog($"Вы скрафтили {craft.result.count}x {craftResult.name}!"); } else { MenuDrawer.ShowInfoDialog("Вам нехватает места в инвентаре!"); } } else { string missingIngredientsString = missingIngredients .Map(TupleFunc((Item ingredient, int count) => $"{count}x {ingredient.name}")) .Join(", "); MenuDrawer.ShowInfoDialog($"Вам нехватает {missingIngredientsString}!"); } }))); }); MenuDrawer.Select( craftingPlace.name, Dictionaries.Merge( actions, MakeDictionary( Pair("Продолжить", Action(() => { resultSituation = situations.RandomSituationByIDs(craftingPlace.nextSituations); })), Pair("Инвентарь", Action(() => InventoryController.Start(player))), Pair("Сохраниться", EmptyAction), Pair("Выйти", ThrowAction(new GameOverException())) ) ) ); return(resultSituation); }
public static void Start(Player player) { var state = InventoryState.ShowInventory; Item currentItem = null; Selectable currentSelectable = null; Consumable currentConsumable = null; while (state != InventoryState.Exit) { switch (state) { case InventoryState.ShowInventory: { var actions = new Dictionary <string, Action>(); IEnumerable <Selectable> selectables = player.inventory .Where(item => item is Selectable) .Cast <Selectable>(); foreach (var selectable in selectables) { int count = selectables.Count(it => it.Equals(selectable)); actions[$"{selectable.name} ({count})"] = () => { currentSelectable = selectable; state = InventoryState.ShowSelectable; }; } IEnumerable <Consumable> consumables = player.inventory .Where(item => item is Consumable) .Cast <Consumable>(); foreach (var consumable in consumables) { int count = consumables.Count(it => it.Equals(consumable)); actions[$"{consumable.name} ({count})"] = () => { currentConsumable = consumable; state = InventoryState.ShowConsumable; }; } IEnumerable <Item> items = player.inventory .Where(item => !(item is Consumable || item is Selectable)); foreach (var item in items) { int count = items.Count(it => it.Equals(item)); actions[$"{item.name} ({count})"] = () => { currentItem = item; state = InventoryState.ShowItem; }; } string title = $"Инвертарь (здоровье - {player.health}/{player.maxHealth}, " + $"атака - {player.attack}, защита - {player.defense}, " + $"монеты - {player.coins})"; actions["Назад"] = () => { state = InventoryState.Exit; }; MenuDrawer.Select(title, actions); } break; case InventoryState.ShowItem: { int count = player.inventory .Where(item => !(item is Consumable || item is Selectable)) .Count(it => it.Equals(currentItem)); string itemTitle = $"{currentItem.name} ({count}) - {currentItem.description}"; MenuDrawer.Select(itemTitle, new Dictionary <string, Action> { { "Выбросить", () => { player.RemoveItemFromInventory(currentItem); state = InventoryState.ShowInventory; } }, { "Назад", () => { state = InventoryState.ShowInventory; } } }); } break; case InventoryState.ShowSelectable: { int count = player.inventory .Where(item => item is Selectable) .Count(it => it.Equals(currentSelectable)); string selectableTitle = (currentSelectable.isSelected) ? $"{currentSelectable.name} ({count}) (Выбрано) - {currentSelectable.description}" : $"{currentSelectable.name} ({count}) (Не выбрано) - {currentSelectable.description}"; MenuDrawer.Select(selectableTitle, new Dictionary <string, Action> { { "Выбрать", () => { player.SelectItemInInventory(currentSelectable); state = InventoryState.ShowInventory; } }, { "Отключить", () => { player.DeselectItemInInventory(currentSelectable); state = InventoryState.ShowInventory; } }, { "Выбросить", () => { player.RemoveItemFromInventory(currentSelectable); state = InventoryState.ShowInventory; } }, { "Назад", () => { state = InventoryState.ShowInventory; } } }); } break; case InventoryState.ShowConsumable: { int count = player.inventory .Where(item => item is Consumable) .Count(it => it.Equals(currentConsumable)); string consumableTitle = $"{currentConsumable.name} ({count}) - {currentConsumable.description}"; MenuDrawer.Select(consumableTitle, new Dictionary <string, Action> { { "Использовать", () => { player.ConsumeItemFromInventory(currentConsumable); state = InventoryState.ShowInventory; } }, { "Выбросить", () => { player.RemoveItemFromInventory(currentSelectable); state = InventoryState.ShowInventory; } }, { "Назад", () => { state = InventoryState.ShowInventory; } } }); } break; case InventoryState.Exit: break; } } }
public static void Main() { try { Console.CursorVisible = false; PrepareLoading(); DoLoading(); #if !DEBUG FinishLoading(); #endif Console.WriteLine(Assets["asciiArts"]["title.txt"].content); var state = MenuState.MainMenu; while (state != MenuState.ExitGame) { switch (state) { case MenuState.MainMenu: MenuDrawer.Select(new Dictionary <string, Action> { { "Новая Игра", () => { state = MenuState.NewGame; } }, { "Загрузить Игру", () => { state = MenuState.LoadGame; } }, { "Настройки", () => { state = MenuState.Settings; } }, { "Выйти Из Игры", () => { state = MenuState.ExitGame; } } }); break; case MenuState.NewGame: Dictionary <string, Action> actions = Campaigns.ToDictionary(campaign => { return(new KeyValuePair <string, Action>(campaign.name, () => { var gameController = new GameController(campaign.situations, campaign.items); gameController.Start(); // В GameController'е стоит свой game-loop, поэтому, // когда он завершится (игрок выйдет из игры) - контроль вернётся сюда state = MenuState.MainMenu; })); }); actions["Назад"] = () => { state = MenuState.MainMenu; }; MenuDrawer.Select("Новая Игра: Выбор кампании", actions); break; case MenuState.LoadGame: MenuDrawer.Select("Загрузить игру", new Dictionary <string, Action> { { "<Тут нет сохраений. Ты можешь начать новую игру>", () => { state = MenuState.NewGame; } }, { "Назад", () => { state = MenuState.MainMenu; } } }); break; case MenuState.Settings: MenuDrawer.Select("Настройки", new Dictionary <string, Action> { { "<Пока что, тут ничего нет>", () => { state = MenuState.Settings; } }, { "Назад", () => { state = MenuState.MainMenu; } } }); break; case MenuState.ExitGame: break; } } } catch (Exception e) { Console.Error.WriteLine(e); } finally { Console.CursorVisible = true; ModLoader.DestroyMods(); } }