Esempio n. 1
0
 private void SaveUser(UserController userController, ItemController itemController)
 {
     userController.CurrentUser.Experience += CurrentBoss.DropExp;
     userController.CurrentUser.Money      += CurrentBoss.MoneyDrop;
     if (IsWin)
     {
         userController.CurrentUser.Win += 1;
     }
     else
     {
         userController.CurrentUser.Loss += 1;
     }
     if (CurrentBoss.Items != null)
     {
         userController.CurrentUser.Items.AddRange(CurrentBoss.Items);
         itemController.SaveItems();
     }
     userController.Save();
 }
Esempio n. 2
0
        //TODO: Зробити нормальну перевірку в циклі якщо недостатньо грошей
        public void BuyItem(int id, User user)
        {
            UserController userController = new UserController(CurrentUser.Name);
            ItemController itemController = new ItemController(CurrentUser);

            while (true)
            {
                CurrentUser = user;
                CurrentItem = Items.Find(x => x.Id == id && x.UserName == CurrentUser.Name);

                if (CurrentItem != null)
                {
                    CurrentItem.UserName = CurrentUser.Name;
                    if (CurrentItem.Price > CurrentUser.Money)
                    {
                        Messages($"Недостатнь коштів на рахунку: {CurrentUser.Money}", false);
                    }
                    else
                    {
                        CurrentUser.Weight += CurrentItem.Weigth;
                        if (!(CurrentUser.Weight >= userController.CurrentUser.MaxWeight))
                        {
                            userController.CurrentUser.Money  -= CurrentItem.Price;
                            userController.CurrentUser.Weight += CurrentItem.Weigth;
                            itemController.Items.Add(CurrentItem);
                            itemController.SaveItems();
                            userController.Save();
                            Messages($"Ви успішно купили: {CurrentItem.Name}", true);
                            break;
                        }
                        else
                        {
                            Messages("Вага предметів в вашому інветарі більша або рівна за вашу норму, " +
                                     "ви не можете купити предмет!", false);
                            break;
                        }
                    }
                }
            }
        }