private void BuyButton_Click(object sender, RoutedEventArgs e) { Marketplace marketplace = Marketplace.Instance; List <Ride> buyableRides = marketplace.GetBuyableRides(park.ParkInventory); var item = ShopList.SelectedItem; if (item != null) { for (int i = 0; i < buyableRides.Count(); i++) { if (item.ToString() == buyableRides[i].Name) { Ride ride = buyableRides[i] as Ride; if (park.ParkWallet.Balance < ride.Cost) { MessageBox.Show(string.Format("You do not have enough money to buy {0}!", ride.Name)); return; } if (park.ParkInventory.Contains(ride)) { MessageBox.Show(string.Format("You already own {0}!", ride.Name)); return; } marketplace.Buy(ride, park.ParkWallet, park.ParkInventory); RefreshRides(); RefreshBalance(); } } } }
// Called when double clicked (check out the Activation property, it's set to TwoClick) private void ridesListView_ItemActivate(object sender, EventArgs e) { if (ridesListView.SelectedItems.Count > 0) { Marketplace marketplace = Marketplace.Instance; ListViewItem selectedRideItem = ridesListView.SelectedItems[0]; // Cast the Tag (object) back to Ride (we know there's a Ride in there) Ride ride = selectedRideItem.Tag as Ride; if (park.ParkWallet.Balance < ride.Cost) { MessageBox.Show(string.Format("You do not have enough money to buy {0}!", ride.Name)); return; } if (park.ParkInventory.Contains(ride)) { MessageBox.Show(string.Format("You already own {0}!", ride.Name)); return; } marketplace.Buy(ride, park.ParkWallet, park.ParkInventory); RefreshRides(); } }
public void MarketplaceTest_Buy() { var target = new Marketplace("Iron Market"); var order = new BuyOrder("Iron Ore", 1ul, 100ul, new Account(100ul)); target.Buy(order); Assert.AreEqual(1, target.BuyOrders.Count); }
public void MarketplaceTest_Update_MatchExact_InvertedOrder() { var target = new Marketplace("Iron Market"); target.Sell(new SellOrder(new Security("Iron Ore", 100ul), 1ul)); target.Buy(new BuyOrder("Iron Ore", 1ul, 100ul, new Account(100ul))); target.Update(); Assert.AreEqual(0, target.BuyOrders.Count); Assert.AreEqual(0, target.SellOrders.Count); }
private void btnBuy_Click(object sender, System.EventArgs e) { var order = _account.CreateBuyOrder(txtName.Text, ulong.Parse(txtQuantity.Text), ulong.Parse(txtPrice.Text)); _marketplace.Buy(order); }