private void SellResourcesButton_Click(int amount, Colony tempColony, MarketStorageElement resource) { List <ResourceInt> storage = tempColony.GetStorage(); for (int i = 0; i < storage.Count(); i++) { if (storage[i].Type.TypeString == resource.ResType.TypeString) { if (storage[i].Number < amount) { Console.WriteLine(storage[i].Number + " " + resource.Amount); ShowStatus("Excuse me this f*cking colony doesn't have enough resources to sell them"); return; } } } //double before = resource["amount"]; double price = resource.Sell * amount; tempColony.SellResource(resource, amount, price); resource.Amount += amount; //double after = resource["amount"]; //resource["sell"] *= before / after; _market.SetNewResourceData(resource); }
private void ResourceListInit() { for (int i = 0; i < _prices.Count(); i++) { MarketStorageElement el = _prices[i]; ResourcesSelectedList.Items.Add(el.ResType.TypeString); } }
private List <MarketStorageElement> PricesInit() { List <MarketStorageElement> list = new List <MarketStorageElement>(); MarketStorageElement wood = new MarketStorageElement(type: new Wood(), amount: 100, buy: 6, sell: 5); MarketStorageElement stone = new MarketStorageElement(type: new Stone(), amount: 100, buy: 6, sell: 5); MarketStorageElement food = new MarketStorageElement(type: new Food(), amount: 100, buy: 6, sell: 5); list.Add(wood); list.Add(stone); list.Add(food); return(list); }
public void SetNewResourceData(MarketStorageElement resource) { // if something has been changed this method changes particular resource for (int i = 0; i < _priceList.Count(); i++) { if (_priceList[i].ResType.TypeString == resource.ResType.TypeString) { _priceList[i] = resource; } } }
public void BuyResource(MarketStorageElement resource, int amount, double price) { Money -= price; for (int i = 0; i < storage.Count(); i++) { if (resource.ResType.TypeString == storage[i].Type.TypeString) { storage[i] = ChangeStorage(storage[i], amount); } } }
public void SellResource(MarketStorageElement resource, int amount, double price) { for (int i = 0; i < storage.Count(); i++) { if (resource.ResType.TypeString == storage[i].Type.TypeString) { storage[i] = ChangeStorage(storage[i], -amount); } } //_storage[resource.ResType.TypeString].Amount -= amount; Money += price; }
private void BuyResourcesButton_Click(int amount, Colony tempColony, MarketStorageElement resource) { if (tempColony.Money < resource.Buy * amount || resource.Amount < amount) { ShowStatus("Excuse me there are no damn resources or you're just poor f**k. Good luck!"); return; } double price = resource.Buy * amount; tempColony.BuyResource(resource, amount, price); resource.Amount -= amount; _market.SetNewResourceData(resource); }
public MarketStorageElement DefineResourceType(string type) { for (int i = 0; i < _priceList.Count(); i++) { if (_priceList[i].ResType.TypeString == type) { return(_priceList[i]); } } Console.WriteLine("Can't define market resource type!"); MarketStorageElement error = new MarketStorageElement(); return(error); }
private void BuySellButton_Click(object sender, EventArgs e) { // there should be selected resources and input shouln't be empty if (ResourcesSelectedList.SelectedItem == null || ResourceAmountInput.Text == "") { ShowStatus("You didn't select any f*****g resource or didn't type any text."); return; } string resourceType = ResourcesSelectedList.SelectedItem.ToString(); // Some planet should be selected if (PlanetsSelectList.SelectedItem == null || ColoniesSelectList.SelectedItem == null) { ShowStatus("Excuse me. Select at least one f*****g planet or colony. Thank you."); return; } string tempPlanetName = PlanetsSelectList.SelectedItem.ToString(); Planet tempPlanet = DefinePlanetByName(tempPlanetName); string text = ColoniesSelectList.SelectedItem.ToString(); Colony tempColony = DefineColonyByName(text, tempPlanet.GetColonies(), tempPlanet); MarketStorageElement resource = _market.DefineResourceType(resourceType); // get market prices for resource string amountText = ResourceAmountInput.Text; ResourceAmountInput.Text = ""; if (int.TryParse(amountText, out int amount)) { if (amount < 0) { ShowStatus("Excuse me your you typed some shit with minus. Please try again."); return; } var btn = (Button)sender; string name = (btn.Name); if (name == "BuyResourcesButton") { BuyResourcesButton_Click(amount, tempColony, resource); } else if (name == "SellResourcesButton") { SellResourcesButton_Click(amount, tempColony, resource); } } else { ShowStatus("Excuse me you typed some shit. Not a number"); } }
private void ShowMarketStatus() { MarketPanel.Controls.Clear(); _prices = _market.GetPriceList(); int yPosition = 0; Label typeColumn = new Label { Location = new Point(0, 30 * yPosition), Text = "Type", Height = 30, Width = 50 }; Label amountColumn = new Label { Location = new Point(60, 30 * yPosition), Text = "Amount", Height = 30, Width = 50 }; Label buyColumn = new Label { Location = new Point(120, 30 * yPosition), Text = "Buy", Height = 30, Width = 50 }; Label sellColumn = new Label { Location = new Point(180, 30 * yPosition), Text = "Sell", Height = 30, Width = 50 }; MarketPanel.Controls.Add(typeColumn); MarketPanel.Controls.Add(amountColumn); MarketPanel.Controls.Add(buyColumn); MarketPanel.Controls.Add(sellColumn); yPosition += 1; for (int i = 0; i < _prices.Count(); i++) { int xPosition = 0; MarketStorageElement el = _prices[i]; Label newLabel = new Label(); newLabel.Location = new Point(xPosition * 60, 30 * yPosition); newLabel.Text = el.ResType.TypeString; newLabel.Height = 30; newLabel.Width = 50; xPosition++; MarketPanel.Controls.Add(newLabel); Label newLabel2 = new Label(); newLabel2.Location = new Point(xPosition * 60, 30 * yPosition); newLabel2.Text = el.Amount.ToString(); newLabel2.Height = 30; newLabel2.Width = 50; xPosition++; MarketPanel.Controls.Add(newLabel2); Label newLabel3 = new Label(); newLabel3.Location = new Point(xPosition * 60, 30 * yPosition); newLabel3.Text = el.Buy.ToString(); newLabel3.Height = 30; newLabel3.Width = 50; xPosition++; MarketPanel.Controls.Add(newLabel3); Label newLabel4 = new Label(); newLabel4.Location = new Point(xPosition * 60, 30 * yPosition); newLabel4.Text = el.Sell.ToString(); newLabel4.Height = 30; newLabel4.Width = 50; xPosition++; MarketPanel.Controls.Add(newLabel4); yPosition++; } }