Esempio n. 1
0
 private void sellButton_Click(object sender, EventArgs e)
 {
     if (coinsListView.SelectedItems.Count == 0)
     {
         MessageBox.Show("Select a coin before selling");
     }
     else
     {
         CoinListItem  coinListItem = (CoinListItem)coinsListView.SelectedItems[0].Tag;
         int           coinId       = coinListItem.Coin.Id;
         InventoryCoin iCoin        = gc.Player.FindInventoryCoinById(coinId);
         Coin          d            = iCoin.Coin;
         if (iCoin.Count == 0)
         {
             MessageBox.Show($"You have no {d.Name} to sell.");
         }
         else
         {
             int    maxNum   = gc.GetMaxCoinsToSell(d.Id);
             string coinName = gc.Player.CurrentLocation.Coins[coinId].Name;
             using (var bsf = new BuySellForm(coinName, "sell", maxNum,
                                              gc.GetAverageProfit(coinId)))
             {
                 var result = bsf.ShowDialog();
                 if (result == DialogResult.OK && bsf.Input > 0)
                 {
                     gc.SellCoins(coinId, bsf.Input);
                     DisplayGameInfo();
                 }
             }
         }
     }
 }
Esempio n. 2
0
 private void buyButton_Click(object sender, EventArgs e)
 {
     if (coinsListView.SelectedItems.Count == 0)
     {
         MessageBox.Show("Select a drug before buying");
     }
     else
     {
         // Dependency issues have been resolved via creation of a DrugListItem class
         CoinListItem coinListItem = (CoinListItem)coinsListView.SelectedItems[0].Tag;
         int          coinId       = coinListItem.Coin.Id;
         int          maxNum       = gc.GetMaxCoinsToBuy(coinId);
         string       coinName     = gc.Player.CurrentLocation.Coins[coinId].Name;
         using (var bsf = new BuySellForm(coinName, "buy", maxNum, gc.GetAverageProfit(coinId)))
         {
             var result = bsf.ShowDialog();
             if (result == DialogResult.OK && bsf.Input > 0)
             {
                 gc.BuyCoins(coinId, bsf.Input);
                 DisplayGameInfo();
             }
         }
     }
 }