/** * Creates an item with a random range of features */ public static Iitem CreateRandom(double price) { Array values = Enum.GetValues(typeof(ItemProperties)); TSRandom random = TSRandom.Instance; List <Object> propertiesChosen = new List <Object>(); var itemProps = new List <ItemProperties>(); int i = 0; while (random.Next(10) < (4 - i)) { //make sure there is no duplicate property while (true) { var nextProperty = values.GetValue(random.Next(values.Length)); if (propertiesChosen.Contains(nextProperty)) { continue; } propertiesChosen.Add(nextProperty); break; } itemProps.Add((ItemProperties)propertiesChosen[propertiesChosen.Count - 1]); i++; } return(CreateSpecific(price, itemProps.ToArray())); }
public Consumer(string name, List <Store> stores) { _rng = TSRandom.Instance; Name = name; _log = Log.Instance; _stores = stores; _wish_list = new List <Iitem>(); int list_count = _rng.Next(3, 5); for (int i = 0; i < list_count; i++) { _wish_list.Add(ItemFactory.CreateRandom(0)); // Price in this case is not imporant } }
/** * This method will start the Store and generete random items and * put a pricetag on it. */ public void StartStore() { while (_running || _items.Count > 0) { if (_running) { double price = _rng.Next(10, 5500); Iitem newItem = ItemFactory.CreateRandom(price); _log.Write(Name, "Made item: " + newItem.GetName() + " - " + newItem.GetDesc() + ". Sells For: " + newItem.GetPrice()); DeliverItem(newItem); } Thread.Sleep(1000); } }