Пример #1
0
        /*
         *
         * Checks whenever the Player has won or lost. If so give the appropriate Exp and give loot to the player, followed by a congrats display alert.
         * Pop the current page back to the dungeon if display alert is closed, and rest the dungeon boss character and its HP.
         * Param Nothing.
         * Returns Nothing.
         */
        private async Task CheckHP()
        {
            if (WON)
            {
                Random   rnd         = new Random();
                int      lootindx    = rnd.Next(0, 2);
                int      expgained   = Convert.ToInt32(dungeon.boss.Health * .3);
                string[] loot        = { "SteelSword", "IronSword", "WoodenSpoon" };
                string   currentloot = loot[lootindx];
                UserModel.AddOntoLine("Weapons:", currentloot + ",", dungeon.items.Localfile);
                try
                {
                    dungeon.items.Invfile.Object.Weapons += currentloot + ",";
                    await dungeon.weapon.UpdateInv();
                }
                catch { }

                dungeon.weapon.Rebuild();
                await dungeon.stats.ExpEnterAsync(expgained);

                await dungeon.stats.AddBossDefeated();
                await DisplayAlert("YOU WIN", string.Format("Loot: {0}\nExp gained: {1}\nExp left: {2}", currentloot, expgained, dungeon.stats.ExpLeft()), "Close");

                if (await dungeon.stats.StatsCheckAsync())
                {
                    await DisplayAlert("Congrats", string.Format("You are now Level: {0}\nCurrent Health: {1}", UserModel.CheckForstring(dungeon.stats.Localfile, "LEVEL:"), UserModel.CheckForstring(dungeon.stats.Localfile, "HEALTH:")), "Close");
                }
            }
            else
            {
                Random   rnd         = new Random();
                int      lootindx    = rnd.Next(0, 1);
                int      expgained   = Convert.ToInt32(dungeon.boss.Health * .1);
                string[] loot        = { "WoodenSpoon", "WoodenBow" };
                string   currentloot = loot[lootindx];
                UserModel.AddOntoLine("Weapons:", currentloot + ",", dungeon.items.Localfile);
                try
                {
                    dungeon.items.Invfile.Object.Weapons += currentloot + ",";
                    await dungeon.weapon.UpdateInv();
                }
                catch { }

                dungeon.weapon.Rebuild();
                await dungeon.stats.ExpEnterAsync(expgained);
                await DisplayAlert("YOU LOSE", string.Format("Loot: {0}\nExp gained: {1}\nExp left: {2}", currentloot, expgained, dungeon.stats.ExpLeft()), "Close");

                if (await dungeon.stats.StatsCheckAsync())
                {
                    await DisplayAlert("Congrats", string.Format("You are now Level: {0}\nCurrent Health: {1}", UserModel.CheckForstring(dungeon.stats.Localfile, "LEVEL:"), UserModel.CheckForstring(dungeon.stats.Localfile, "HEALTH:")), "Close");
                }
            }
            UserModel.Rewrite("Updated:", DateTime.Now.ToString(), dungeon.user.LocalLogin);
            dungeon.Shop.Rebuild();
            dungeon.realdungeon.Reselect();
            dungeon.InitializeBoss();
            await this.Navigation.PopModalAsync();
        }
Пример #2
0
        public async System.Threading.Tasks.Task <bool> BuyAsync(InventoryItemsModel items, int typecase, string ChoItem, bool test = false)
        {
            foreach (ItemModel item in Characters.Characters)
            {
                if (ChoItem == item.item)
                {
                    await Application.Current.MainPage.DisplayAlert("Error", "Already have this Character", "Close");

                    return(false);
                }
            }

            int CurrentGold = CurrentGold = Int32.Parse(UserModel.CheckForstring(items.Localfile, "Gold:"));
            int Price       = 0;
            int TotalGold;

            if (typecase == 0)
            {
                Price = WeaponInfoModel.ObtainWeaponValue(ChoItem);
            }
            else if (typecase == 1)
            {
                Price = ItemInfoModel.ObtainItemValue(ChoItem);
            }
            else
            {
                Price = 50;
            }
            TotalGold = CurrentGold - Price;
            if (CurrentGold - Price >= 0)
            {
                if (typecase == 0)
                {
                    UserModel.AddOntoLine("Weapons:", ChoItem + ",", items.Localfile);
                    try
                    {
                        items.Invfile.Object.Weapons += ChoItem + ",";
                    }catch { }
                    Weapon.Rebuild();
                }
                else if (typecase == 1)
                {
                    UserModel.AddOntoLine("Items:", ChoItem + ",", items.Localfile);
                    try
                    {
                        items.Invfile.Object.Items += ChoItem + ",";
                    }catch { }
                    Inv.Rebuild();
                }
                else
                {
                    UserModel.AddOntoLine("Characters:", ChoItem + ",", items.Localfile);
                    try
                    {
                        items.Invfile.Object.Characters += ChoItem + ",";
                    }
                    catch { }
                    Characters.Rebuild();
                }
                UserModel.Rewrite("Gold:", TotalGold.ToString(), items.Localfile); //Rewrite the gold values
                try
                {
                    items.Invfile.Object.Gold = TotalGold.ToString();
                    await items.UpdateInv();
                }
                catch { }
                Gold = UserModel.CheckForstring(items.Localfile, "Gold:");
                if (!test)
                {
                    await Application.Current.MainPage.DisplayAlert("Success", string.Format("You bought a {0}.", ChoItem), "Close");
                }
                return(true);
            }
            else
            {
                int remainder = CurrentGold - Price;
                remainder = remainder * -1;
                if (!test)
                {
                    await Application.Current.MainPage.DisplayAlert("Error", string.Format("You need {0} more gold to purchase this item", remainder.ToString()), "Close");
                }
                return(false);
            }
        }