// Parsing a line representing a potion private static void ParsePotion(Shop shop, string[] itemParam) { string name; int minEffect; int maxEffect; int cost; if (itemParam.Length == 6) { name = itemParam[1]; minEffect = Convert.ToInt32(itemParam[2]); maxEffect = Convert.ToInt32(itemParam[3]); cost = Convert.ToInt32(itemParam[4]); if (itemParam[5].Length == 1) { try { switch (itemParam[5][0]) { case 'H': shop.AddItem(new HealingPotion( name: name, cost: cost, minEffect: minEffect, maxEffect: maxEffect)); break; case 'D': shop.AddItem(new DamagePotion( name: name, cost: cost, minEffect: minEffect, maxEffect: maxEffect)); break; default: throw new ParserException( "Cannot get potion type"); } } catch (OverflowException e) { throw new ParserException("Integer too big"); } catch (FormatException e) { throw new ParserException("Failed to parse integer"); } } else { throw new ParserException("Cannot get potion type"); } } else { throw new ParserException("Invalid number of parameters"); } }
public GringottsItem() : base("Gringotts Bank") { Shop = new Shop("Gringotts Bank", true, false); var tItem = DungeonManager.GetDungeonItem(Constants.tDungeon); var gItem = DungeonManager.GetDungeonItem(Constants.gDungeon); Shop.AddItem(tItem); Shop.AddItem(gItem); }
public void TestAdd5ToShop() { Shop shop = (Shop)Factory.Create(MarketRole.SHOP); shop.AddItem((Item)Factory.Create(MarketRole.ITEM)); shop.AddItem((Item)Factory.Create(MarketRole.ITEM)); shop.AddItem((Item)Factory.Create(MarketRole.ITEM)); shop.AddItem((Item)Factory.Create(MarketRole.ITEM)); shop.AddItem((Item)Factory.Create(MarketRole.ITEM)); Assert.AreEqual(5, shop.inventorySize); }
public void AddItem_MakeSureItemIsAdded_IncreaseItemsSizeBy1() { var shop = new Shop("pharmacy"); Assert.That(shop.Items.Count, Is.EqualTo(0)); shop.AddItem("111", "1", "222"); Assert.That(shop.Items.Count, Is.EqualTo(1)); shop.AddItem("111", "2", "222"); Assert.That(shop.Items.Count, Is.EqualTo(1)); }
public static Shop Create() { var shop = new Shop(); shop.AddItem(new ShopItem() { Name = "Turret", Cost = 100 }); shop.AddItem(new ShopItem() { Name = "Missile Launcher", Cost = 300 }); return(shop); }
public void AddItem_whenItem_thenAddsItemToStock() { string item = "Doggy Gucci bag"; _shop.AddItem(item); _shop.ItemsInShop.Should().Contain("Doggy Gucci bag"); }
public void TestCheckRecentlyAddedItem() { Shop shop = (Shop)Factory.Create(MarketRole.SHOP); Item item = (Item)Factory.Create(MarketRole.ITEM); shop.AddItem(item); Assert.AreEqual(item, shop.CheckRecentlyAddedItem()); }
public OlivandersItem() : base("Olivanders' Wands") { Shop = new Shop("Olivanders' Wands", true); var item = new GenericItem("Wand") { InteractEventTask = DecideWandInteractEvent }; Shop.AddItem(item); }
public void Initialize() { _state = "Game Manager initialized.."; _state.FancyDebug(); Debug.Log(_state); LootStack.Push("Sword of Doom"); LootStack.Push("HP Boost"); LootStack.Push("Golden Key"); LootStack.Push("Pair of Winged Boots"); LootStack.Push("Mythril Bracer"); var itemShop = new Shop <Collectable>(); itemShop.AddItem(new Potion()); itemShop.AddItem(new Antidote()); Debug.Log("There are " + itemShop.GetStockCount <Potion>() + " items for sale."); debug(_state); LogWithDelegate(debug); }
private void LoadShops() { #region Shop Locations Shop leakyCauldronBar = new Shop("Leaky Cauldron Bar"); leakyCauldronBar.AddItem(new Butterbeer()); leakyCauldronBar.AddItem(new Tea()); myShops.Add(ELocations.LEAKY_CAULDRON_SHOP, leakyCauldronBar); #endregion #region Shop Selector var diagonAlley = new ShopSelector("Diagon Alley"); diagonAlley.AddItem(new OlivandersItem()); diagonAlley.AddItem(new GringottsItem()); myShopSelectors.Add(ELocations.DIAGON_ALLEY_SHOP, diagonAlley); #endregion }
private void NewToolStripMenuItem_Click(object sender, EventArgs e) { var itemForm = new ItemForm(_shop.Items); if (itemForm.ShowDialog() == DialogResult.OK) { _shop.AddItem(itemForm.Item); itemBindingSource.ResetBindings(false); _isChanged = true; var ind = ItemsGridView.Rows.Count - 1; ItemsGridView.Rows[ind].Selected = true; ItemsGridView.FirstDisplayedScrollingRowIndex = ind; } }
// Parses a line representing a weapon private static void ParseWeapon(Shop shop, string[] itemParam) { string name; int minDamage; int maxDamage; int cost; string damageType; string weaponType; if (itemParam.Length == 7) { try { name = itemParam[1]; minDamage = Convert.ToInt32(itemParam[2]); maxDamage = Convert.ToInt32(itemParam[3]); cost = Convert.ToInt32(itemParam[4]); damageType = itemParam[5]; weaponType = itemParam[6]; shop.AddItem(new Weapon(name: name, cost: cost, minEffect: minDamage, maxEffect: maxDamage, weaponType: weaponType, damageType: damageType)); } catch (OverflowException e) { throw new ParserException("Integer is too large"); } catch (FormatException e) { throw new ParserException("Failed to parse integer"); } } else { throw new ParserException("Invalid number of parameters"); } }
/// <summary> /// Moves some or all of the specified Items to the Shop. /// </summary> /// <param name="iInventoryItem">The index of the OrderItem in the Player Inventory to be moved to the shop.</param> /// <param name="quantity"></param> /// <param name="iSlot"></param> /// <returns></returns> public void MoveItemsToShop(int iInventoryItem, int iSlot) { string temp = GameMaster.MSG_GEN_NA; bool itemMoved = Shop.AddItem(WarehouseInventory.Items[iInventoryItem].ItemID, iSlot); if (itemMoved) { if (WarehouseInventory.Items[iInventoryItem].Quantity > 1) { WarehouseInventory.Items[iInventoryItem].ReduceQuantity(1, false, out temp); } else { WarehouseInventory.RemoveItem(iInventoryItem, out temp); } } else { Debug.Log("***The specified Shop Item slot is already in use."); } }
public void ReadCSV(Shop pharmacy, string path) { using (var reader = new StreamReader(path)) { string itemNumber = ""; string itemDescription = ""; while (!reader.EndOfStream) { var line = reader.ReadLine(); var values = line.Split(';'); foreach (var item in values) { var entries = item.Split(","); if (!string.IsNullOrWhiteSpace(entries[1])) { itemNumber = entries[1]; } if (!string.IsNullOrWhiteSpace(entries[2])) { itemDescription = entries[2]; } foreach (var keyword in pharmacy.PharmacySearch) { if (!string.IsNullOrWhiteSpace(entries[3]) && entries[3].ToLower().Contains(keyword.Trim())) { var revenue = entries[5] + entries[6]; pharmacy.AddItem(itemNumber, itemDescription, entries[4], revenue); } } } } } WriteToCsv(pharmacy, path); }
// Parses a line representing armour private static void ParseArmour(Shop shop, string[] itemParam) { string name; int minDefence; int maxDefence; int cost; string material; if (itemParam.Length == 6) { try { name = itemParam[1]; minDefence = Convert.ToInt32(itemParam[2]); maxDefence = Convert.ToInt32(itemParam[3]); cost = Convert.ToInt32(itemParam[4]); material = itemParam[5]; shop.AddItem(new Armour(name: name, cost: cost, minEffect: minDefence, maxEffect: maxDefence, material: material)); } catch (OverflowException e) { throw new ParserException("Iteger too large"); } catch (FormatException e) { throw new ParserException("Failed to parse integer"); } } else { throw new ParserException("Invalid number of parameters"); } }
// Fuegt Item dem Shop hinzu public void AddShopItem() { shop.AddItem(gameObject.GetComponent <Item>()); }
public Form1() { InitializeComponent(); myShop = new Shop(); Item apple = new Item("Apple", 3, 500); Item computer = new Item("Computer", 3000, 104); Item banana = new Item("Banana", 2, 9000); Item cellPhone = new Item("Cell Phone", 8000, 40); Item bottle = new Item("Bottle", 10, 300); Item milk = new Item("Milk", 5, 4000); Item toiletPaper = new Item("Toilet Paper", 1, 50000); Item mask = new Item("Mask", 1, 4000); Item pencil = new Item("Pencil", 0.3, 5000); Item book = new Item("Book", 2, 4000); Item shirt = new Item("Shirt", 20, 360); myShop.AddItem(apple); myShop.AddItem(computer); myShop.AddItem(banana); myShop.AddItem(cellPhone); myShop.AddItem(bottle); myShop.AddItem(milk); myShop.AddItem(toiletPaper); myShop.AddItem(mask); myShop.AddItem(pencil); myShop.AddItem(book); myShop.AddItem(shirt); myShop.OrderService.AddOrder("zhong yuan"); myShop.Sell("Apple", 3, myShop.OrderService.Orders[0]); myShop.Sell("Milk", 3, myShop.OrderService.Orders[0]); myShop.OrderService.AddOrder("zhang qianshu"); myShop.Sell("Book", 1, myShop.OrderService.Orders[1]); myShop.Sell("shirt", 1, myShop.OrderService.Orders[1]); myShop.OrderService.AddOrder("meng suhua"); myShop.Sell("Cell phone", 1, myShop.OrderService.Orders[2]); myShop.Sell("computer", 2, myShop.OrderService.Orders[2]); myShop.Sell("shirt", 3, myShop.OrderService.Orders[2]); myShop.Sell("toilet paper", 13, myShop.OrderService.Orders[2]); // 初始数据载入数据库 using (var db = new OrderContext(true)) { db.Shops.Add(myShop); db.SaveChanges(); } waysComboBox.Items.Add("通过订单名检索"); waysComboBox.Items.Add("通过商品名检索"); waysComboBox.Items.Add("通过顾客名检索"); orderBindingSource.DataSource = myShop.OrderService.Orders; }
static void Main(string[] args) { var shop = new Shop(); IPrint cPrint = new ConsolePrintServices(); IAddMoney addMoney = new AddMoneyService(); IReader Read = new ConsoleReadService(); User user = new User(addMoney); var startApp = true; cPrint.Print($"{Message.welcomeMessage}{Message.nextCommand}"); Creation.CreateFirstItems(shop); while (startApp) { try { var text = Read.GetValue(); string[] textArr = Regex.Split(text, " "); switch (textArr[0].ToLower()) { case "balance": cPrint.Print($"{Message.currentBalance}{user.Balance}\n{Message.nextCommand}"); break; case "add": var addItem = textArr[1]; var addAmount = int.Parse(textArr[2]); cPrint.Print($"{shop.AddItem(addItem, addAmount)}{Message.nextCommand}"); break; case "buy": var itemToBuy = textArr[1]; var amountToBuy = int.Parse(textArr[2]); cPrint.Print($"{shop.BuyItem(user, itemToBuy, amountToBuy)}{Message.nextCommand}"); break; case "list": shop.GetItemList(); cPrint.Print($"{Message.nextCommand}"); break; case "topup": var amount = decimal.Parse(textArr[1]); user.AddMoney(user, amount); cPrint.Print($"{Message.addedMoney + amount}{Message.nextCommand}"); break; case "exit": startApp = false; break; default: throw new InvalidOperationException(); } } catch (InvalidOperationException) { cPrint.Print(Message.noSuchCommand); } catch (Exception e) { startApp = false; cPrint.Print(e.Message); } } }
public Form1() { InitializeComponent(); myShop = new Shop(); myShop.AddItem("Apple", 3, 500); myShop.AddItem("Computer", 3000, 104); myShop.AddItem("Banana", 2, 9000); myShop.AddItem("Cell Phone", 8000, 40); myShop.AddItem("Bottle", 10, 300); myShop.AddItem("Milk", 5, 4000); myShop.AddItem("Toilet Paper", 1, 50000); myShop.AddItem("Mask", 1, 4000); myShop.AddItem("Pencil", 0.3, 5000); myShop.AddItem("Book", 2, 4000); myShop.AddItem("Shirt", 20, 360); myShop.OrderService.AddOrder("jotaro"); myShop.Sell("Apple", 3, myShop.OrderService.Orders[0]); myShop.Sell("Milk", 3, myShop.OrderService.Orders[0]); myShop.OrderService.AddOrder("josuke"); myShop.Sell("Book", 1, myShop.OrderService.Orders[1]); myShop.OrderService.AddOrder("giorno"); myShop.Sell("Cell phone", 1, myShop.OrderService.Orders[2]); myShop.Sell("computer", 2, myShop.OrderService.Orders[2]); myShop.Sell("shirt", 3, myShop.OrderService.Orders[2]); myShop.Sell("toilet paper", 13, myShop.OrderService.Orders[2]); waysComboBox.Items.Add("通过订单名检索"); waysComboBox.Items.Add("通过商品名检索"); waysComboBox.Items.Add("通过顾客名检索"); orderBindingSource.DataSource = myShop.OrderService.Orders; }