Beispiel #1
0
    static void Main()
    {
        //giving CoinPurse a reference
        CoinPurse myCoinPurse = new CoinPurse();

        //showing that we have nothing in the coin purse
        Console.WriteLine("we have nothing in the coin purse: {0:f2}", myCoinPurse.totalCoins());
        //adding 3 pennies into the coin purse
        myCoinPurse.addPennies(3);
        //showing the resulting amount of money in the coin purse
        Console.WriteLine("here we added three pennies; {0:f2}", myCoinPurse.totalCoins());
        //adding 4 nickles into the coin purse
        myCoinPurse.addNickles(4);
        //showing that we added 4 nickles into the coin purse
        Console.WriteLine("here we add four nickles on top of the three pennies: {0:f2}", myCoinPurse.totalCoins());
        //adding 2 dimes into the coin purse
        myCoinPurse.addDimes(2);
        //showing that we added 2 coins into the purse
        Console.WriteLine("here are the two added dimes: {0:f2}", myCoinPurse.totalCoins());
        //adding a quarter
        myCoinPurse.addQuarters(1);
        //showing that we added the quarter
        Console.WriteLine("here we add a quarter: {0:f2}", myCoinPurse.totalCoins());
        //taking 20 cents out of the total in the coin purse
        myCoinPurse.takeDimes(2);
        //showing that we took 20 cents out of the coin purse
        Console.WriteLine("here we take two dimes out, or twenty cents. {0:f2}", myCoinPurse.totalCoins());
        myCoinPurse.emptyCoins(0);
        Console.WriteLine("here we empty the coin purse into something less \nfeminine like a satchel or a batman piggy bank: {0}", myCoinPurse.totalCoins());
        myCoinPurse.addQuarters(5);
        Console.WriteLine("{0}", myCoinPurse.totalCoins());
        Console.ReadLine();
    } //end main
Beispiel #2
0
 public Entity(int strength, int dex, int con, int intelligence, int wisdom, int charisma)
 {
     Ammunition = new List <Ammunition>();
     Purse      = new CoinPurse();
     Weapons    = new List <Weapon>();
     Strength   = new Strength()
     {
         Score = strength
     };
     Dexterity = new Dexterity()
     {
         Score = dex
     };
     Constitution = new Constitution()
     {
         Score = con
     };
     Intelligence = new Intelligence()
     {
         Score = intelligence
     };
     Wisdom = new Wisdom()
     {
         Score = wisdom
     };
     Charisma = new Charisma()
     {
         Score = charisma
     };
 }
Beispiel #3
0
        public void SpendingMoneySubtractsFromThePurse()
        {
            var purse = new CoinPurse();

            purse.SetValue(58342);
            purse.Spend(7328);
            Assert.Equal(51014, purse.Value);
        }
        public void TestRegisterObserverAddsToObserverList()
        {
            CoinPurse             coinPurse             = new CoinPurse();
            MockCoinPurseObserver mockCoinPurseObserver = new MockCoinPurseObserver();

            coinPurse.RegisterObserver(mockCoinPurseObserver);
            Assert.AreEqual(1, coinPurse.Observers.Count);
            Assert.AreEqual(mockCoinPurseObserver, coinPurse.Observers[0]);
        }
Beispiel #5
0
        public void SetValueWillFillInWithGoldCoinsToMeetValue()
        {
            var purse = new CoinPurse();

            purse.SetValue(37243);
            Assert.Equal(372, purse.Gold.Pieces);
            Assert.Equal(4, purse.Silver.Pieces);
            Assert.Equal(3, purse.Copper.Pieces);
        }
Beispiel #6
0
        public void CoinPursesCanStoreAllTheCoins()
        {
            var purse = new CoinPurse();

            purse.AddPlatinum(3);
            purse.AddGold(53);
            purse.AddSilver(85);
            purse.AddCopper(23);
            Assert.Equal(9173, purse.Value);
        }
        public void TestClearNotifiesObservers()
        {
            CoinPurse             coinPurse             = new CoinPurse();
            MockCoin              mockCoin              = new MockCoin();
            MockCoinPurseObserver mockCoinPurseObserver = new MockCoinPurseObserver();

            coinPurse.RegisterObserver(mockCoinPurseObserver);
            coinPurse.Clear();

            Assert.AreEqual(1, mockCoinPurseObserver.NumberOfTimesCoinPurseUpdatedCalled);
        }
        public void TestAddPutsCoinIntoCoinList()
        {
            CoinPurse coinPurse = new CoinPurse();
            MockCoin  coinAdded = new MockCoin();

            coinPurse.AddCoin(coinAdded);
            Assert.AreEqual(new List <ICoin>()
            {
                coinAdded
            }, coinPurse.Coins);
        }
Beispiel #9
0
 public Entity()
 {
     Strength     = new Strength();
     Dexterity    = new Dexterity();
     Constitution = new Constitution();
     Intelligence = new Intelligence();
     Wisdom       = new Wisdom();
     Charisma     = new Charisma();
     Weapons      = new List <Weapon>();
     Ammunition   = new List <Ammunition>();
     Purse        = new CoinPurse();
 }
Beispiel #10
0
        public void CanCheckIfYouCanAffordAnItem()
        {
            var purse = new CoinPurse(4842);
            var item  = new DummyItem();

            item.Value = 3293;
            var expensive = new DummyItem();

            expensive.Value = 49348;

            Assert.True(purse.CanAfford(item));
            Assert.False(purse.CanAfford(expensive));
        }
        public void TestAmountAvailableReturnsTotalValueOfCoinsInPurse()
        {
            CoinPurse coinPurse = new CoinPurse();

            decimal  expectedValueOfAllCoins = 5.55m;
            MockCoin coinAdded = new MockCoin()
            {
                ValueToReturn = expectedValueOfAllCoins
            };

            coinPurse.AddCoin(coinAdded);
            Assert.AreEqual(expectedValueOfAllCoins, coinPurse.AmountAvailable);
        }
        public void TestClearReturnsAllCoinsAndEmptiesPurse()
        {
            CoinPurse coinPurse = new CoinPurse();
            MockCoin  mockCoin  = new MockCoin();

            coinPurse.AddCoin(mockCoin);

            List <ICoin> coinsReturnedFromClear = coinPurse.Clear();

            Assert.AreEqual(1, coinsReturnedFromClear.Count);
            Assert.AreEqual(mockCoin, coinsReturnedFromClear[0]);

            Assert.AreEqual(0, coinPurse.Coins.Count);
        }
Beispiel #13
0
        public void ConvertCoinPurseToGold()
        {
            CoinPurse coins = new CoinPurse
            {
                Copper   = 3245,
                Silver   = 170,
                Electrum = 28,
                Gold     = 1800,
                Platinum = 30
            };

            double result = coins.GetValueInGold();

            Assert.AreEqual(2163.45, result);
        }
        public void TestUpdatesOberserversWhenCoinIsAddedToCoinPurse()
        {
            CoinPurse coinPurse = new CoinPurse();

            MockCoinPurseObserver mockCoinPurseObserverOne = new MockCoinPurseObserver();
            MockCoinPurseObserver mockCoinPurseObserverTwo = new MockCoinPurseObserver();

            coinPurse.RegisterObserver(mockCoinPurseObserverOne);
            coinPurse.RegisterObserver(mockCoinPurseObserverTwo);

            coinPurse.AddCoin(new MockCoin());

            Assert.AreEqual(1, mockCoinPurseObserverOne.NumberOfTimesCoinPurseUpdatedCalled);
            Assert.AreEqual(1, mockCoinPurseObserverTwo.NumberOfTimesCoinPurseUpdatedCalled);
        }
        /// <summary>
        /// Author:     Brian Sabotta
        /// Created:    10/30/2019
        /// Notes:      Gets a descriptor string for CoinPurses which contain change details for each line in the source file.
        /// </summary>
        /// <param name="sourceData">A collection of lines of text, representing source data to be processed.</param>
        /// <returns>Returns a descriptor string of all CoinPurses generated for every line in the source file.</returns>
        private static string GetAllCoinPurseDescriptors(IEnumerable <string> sourceData)
        {
            var returnValue = new StringBuilder();

            foreach (var currentLine in sourceData)
            {
                //Break up each line by splitting on the comma delimiter
                var dataRow = currentLine.Split(',');
                if (dataRow.Length > 1)
                {
                    var currentPurse = CoinPurse.GetChangePurse(dataRow[0], dataRow[1]);
                    //Example output has double-spacing, so we'll do the same for ease of reading.
                    returnValue.AppendLine($"{currentPurse.GetCollectionVerboseString()}{Environment.NewLine}");
                }
            }
            return(returnValue.ToString());
        }
 void OnTriggerEnter(Collider collider)
 {
     if (collectionType == CollectionTypes.Coins)
     {
         CoinPurse coinPurse = collider.gameObject.GetComponent <CoinPurse>();
         if (coinPurse != null)
         {
             if (particles != null)
             {
                 GameObject initParticles = GameObject.Instantiate(particles);
                 initParticles.transform.position = transform.position;
             }
             coinPurse.AddCoins(value);
             DestroyObject(this.gameObject);
         }
     }
 }
        public void TestAddPutsCoinIntoCoinListMultipleCoins()
        {
            CoinPurse coinPurse = new CoinPurse();

            MockCoin firstCoinAdded  = new MockCoin();
            MockCoin secondCoinAdded = new MockCoin();
            MockCoin thirdCoinAdded  = new MockCoin();

            List <ICoin> expectedCoins = new List <ICoin>()
            {
                firstCoinAdded,
                secondCoinAdded,
                thirdCoinAdded
            };

            coinPurse.AddCoin(firstCoinAdded);
            coinPurse.AddCoin(secondCoinAdded);
            coinPurse.AddCoin(thirdCoinAdded);

            Assert.AreEqual(expectedCoins, coinPurse.Coins);
        }
        public void TestAmountAvailableReturnsTotalValueOfCoinsInPurseMultipleCoins()
        {
            CoinPurse coinPurse = new CoinPurse();

            decimal expectedValueOfAllCoins = 0;

            const decimal firstCoinValue = 1.25m;
            MockCoin      firstCoinAdded = new MockCoin()
            {
                ValueToReturn = firstCoinValue
            };

            expectedValueOfAllCoins += firstCoinValue;

            const decimal secondCoinValue = 0.25m;
            MockCoin      secondCoinAdded = new MockCoin()
            {
                ValueToReturn = secondCoinValue
            };

            expectedValueOfAllCoins += secondCoinValue;

            const decimal thirdCoinValue = 4.25m;
            MockCoin      thirdCoinAdded = new MockCoin()
            {
                ValueToReturn = thirdCoinValue
            };

            expectedValueOfAllCoins += thirdCoinValue;

            coinPurse.AddCoin(firstCoinAdded);
            coinPurse.AddCoin(secondCoinAdded);
            coinPurse.AddCoin(thirdCoinAdded);

            Assert.AreEqual(expectedValueOfAllCoins, coinPurse.AmountAvailable);
        }
        public void TestCoinPurseStartsWithEmptyCoinList()
        {
            CoinPurse coinPurse = new CoinPurse();

            Assert.AreEqual(new List <ICoin>(), coinPurse.Coins);
        }
Beispiel #20
0
 public void Purchase(IGear item)
 {
     CoinPurse.Spend(item.Value);
     AddGear(item);
 }
Beispiel #21
0
        public void IfYouDoNotHaveEnoughMoneyThrowError()
        {
            var purse = new CoinPurse(3923);

            Assert.Throws <InsufficientFundsException>(() => purse.Spend(484234));
        }
Beispiel #22
0
        public void CanInitializePurseToValue()
        {
            var purse = new CoinPurse(4824);

            Assert.Equal(4824, purse.Value);
        }
Beispiel #23
0
        private void ButtonEventListener(object sender, EventArgs eventArgs)
        {
            List <ICoin> coinsFromPurse = CoinPurse.Clear();

            coinsFromPurse.ForEach(coin => CoinReturn.AddCoin(coin));
        }
Beispiel #24
0
 private void OnGetData(GetDataEventArgs e)
 {
     if (!e.Handled)
     {
         if (e.MsgID == PacketTypes.PlayerSlot)
         {
             using (BinaryReader br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)))
             {
                 byte  id     = br.ReadByte();
                 byte  slot   = br.ReadByte();
                 short stack  = br.ReadInt16();
                 byte  prefix = br.ReadByte();
                 short netID  = br.ReadInt16();
             }
         }
         if (e.MsgID == PacketTypes.ChestGetContents)
         {
             using (BinaryReader br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)))
             {
                 short tileX = br.ReadInt16();
                 short tileY = br.ReadInt16();
                 foreach (ShopChest sc in shop)
                 {
                     if (sc != null)
                     {
                         var r = new RUDD.Region("", new Vector2(tileX - 1, tileY - 1), new Vector2(tileX + 1, tileY + 1));
                         if (r.Contains(sc.x, sc.y))
                         {
                             for (int i = 0; i < sc.chest.item.Length; i++)
                             {
                                 if (sc.contents[i] != null)
                                 {
                                     if (sc.refill || resetContents[sc.index2])
                                     {
                                         Main.chest[sc.index].item[i].netDefaults(sc.contents[i].type);
                                         Main.chest[sc.index].item[i].stack  = sc.contents[i].stack;
                                         Main.chest[sc.index].item[i].prefix = sc.contents[i].prefix;
                                         TShock.Players[sc.owner].SendData(PacketTypes.ChestItem, "", sc.index, i, Main.chest[sc.index].item[i].stack, Main.chest[sc.index].item[i].prefix, Main.chest[sc.index].item[i].type);
                                     }
                                 }
                             }
                             resetContents[sc.index2] = false;
                             break;
                         }
                     }
                 }
             }
         }
         if (e.MsgID == PacketTypes.ChestItem)
         {
             using (BinaryReader br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)))
             {
                 short cID    = br.ReadInt16();
                 byte  slot   = br.ReadByte();
                 short stack  = br.ReadInt16();
                 byte  prefix = br.ReadByte();
                 short itemID = br.ReadInt16();
                 foreach (ShopChest sc in shop)
                 {
                     if (sc != null)
                     {
                         if (sc.index == cID)
                         {
                             Player player = null;
                             foreach (Player p in Main.player)
                             {
                                 if (p.chest == sc.index)
                                 {
                                     player = p;
                                     break;
                                 }
                             }
                             if (player != null)
                             {
                                 if (itemID == 0)
                                 {
                                     if (sc.contents != null)
                                     {
                                         if (sc.contents[slot] != null)
                                         {
                                             if (sc.contents[slot].type != 0)
                                             {
                                                 int value = sc.contents[slot].value == 0 ? sc.chest.item[slot].value : sc.contents[slot].value;
                                                 value = Main.hardMode && priceDouble ? value * 2 : value;
                                                 if (!CoinPurse.ShopItem(player.whoAmI, value))
                                                 {
                                                     active[player.whoAmI]         = new ShopChest();
                                                     active[player.whoAmI].invalid = new Item();
                                                     active[player.whoAmI].invalid.netDefaults(sc.contents[slot].type);
                                                     active[player.whoAmI].invalid.stack  = sc.contents[slot].stack;
                                                     active[player.whoAmI].invalid.prefix = sc.contents[slot].prefix;
                                                     TShock.Players[player.whoAmI].SendInfoMessage(string.Concat("This item requires ", value, " copper."));
                                                     justBought[player.whoAmI] = true;
                                                     resetContents[sc.index2]  = true;
                                                 }
                                                 else
                                                 {
                                                     var block = CoinStorage.data.GetBlock(TShock.Players[player.whoAmI].UUID);
                                                     block.WriteValue("Deliver", "True");
                                                     block.IncreaseValue("Coins", value);
                                                     soldItem[sc.owner] = true;
                                                     if (!sc.refill)
                                                     {
                                                         sc.contents[slot].type = 0;
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                             break;
                         }
                     }
                 }
             }
         }
         else if (e.MsgID == PacketTypes.ChestOpen)
         {
             using (BinaryReader br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)))
             {
                 short id = br.ReadInt16();
                 short x  = br.ReadInt16();
                 short y  = br.ReadInt16();
             }
         }
         else if (e.MsgID == PacketTypes.PlaceChest)
         {
             using (BinaryReader br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)))
             {
                 byte  id    = br.ReadByte();
                 short tileX = br.ReadInt16();
                 short tileY = br.ReadInt16();
             }
         }
         if (e.MsgID == PacketTypes.Tile)
         {
             using (BinaryReader br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)))
             {
                 byte  action = br.ReadByte();
                 short x      = br.ReadInt16();
                 short y      = br.ReadInt16();
                 if (action == 0)
                 {
                     foreach (Player player in Main.player)
                     {
                         if (player.active)
                         {
                             if (canSelect[player.whoAmI])
                             {
                                 if (Main.tile[x, y].type == TileID.Containers)
                                 {
                                     for (int i = 0; i < shop.Length; i++)
                                     {
                                         if (shop[i] == null || !shop[i].enabled)
                                         {
                                             for (int j = 0; j < Main.chest.Length; j++)
                                             {
                                                 if (new Microsoft.Xna.Framework.Rectangle(Main.chest[j].x * 16, Main.chest[j].y * 16, 32, 32).Contains(x * 16 + 8, y * 16 + 8))
                                                 {
                                                     shop[i]          = new ShopChest();
                                                     shop[i].chest    = Main.chest[j];
                                                     shop[i].contents = ShopItem.Convert(Main.chest[j].item, priceFloor[player.whoAmI]);
                                                     shop[i].index    = j;
                                                     shop[i].index2   = i;
                                                     shop[i].x        = Main.chest[j].x;
                                                     shop[i].y        = Main.chest[j].y;
                                                     shop[i].enabled  = true;
                                                     shop[i].active   = true;
                                                     shop[i].owner    = player.whoAmI;
                                                     shop[i].value    = priceFloor[player.whoAmI];
                                                     shop[i].refill   = chestRefill[player.whoAmI];
                                                     CoinStorage.WriteBlock(TShock.Players[player.whoAmI]);
                                                     if (data.BlockExists("Chest" + j))
                                                     {
                                                         var block = data.GetBlock("Chest" + j);
                                                         block.WriteValue("ChestX", x.ToString());
                                                         block.WriteValue("ChestY", y.ToString());
                                                         block.WriteValue("Index", j.ToString());
                                                         block.WriteValue("OwnerID", player.whoAmI.ToString());
                                                         block.WriteValue("Price", priceFloor[player.whoAmI].ToString());
                                                         block.WriteValue("Refill", chestRefill[player.whoAmI].ToString());
                                                         for (int m = 0; m < shop[i].contents.Length; m++)
                                                         {
                                                             block.WriteValue("Slot" + m, shop[i].contents[m].type.ToString());
                                                         }
                                                     }
                                                     canSelect[player.whoAmI]  = false;
                                                     priceFloor[player.whoAmI] = 0;
                                                     TShock.Players[player.whoAmI].SendSuccessMessage("The chest is now set as a shop.");
                                                     break;
                                                 }
                                             }
                                             break;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #25
0
        private void AetherShop(CommandArgs e)
        {
            if (!dropOpt || !shopOpt)
            {
                return;
            }
            string cmd = e.Message.Substring(e.Message.IndexOf(' ') + 1);
            string opt = string.Empty;

            if (cmd.Contains(' '))
            {
                opt = cmd.Substring(cmd.IndexOf(' ') + 1);
            }
            string text = string.Empty;
            int    who  = e.Player.Index;

            foreach (Item inv in Main.player[who].inventory)
            {
                foreach (var ai in invp[who].aether)
                {
                    if (ai.item.IsTheSameAs(inv))
                    {
                        ai.item.owner = who;
                    }
                }
            }
            switch (cmd.Contains(" ") ? cmd.Substring(0, cmd.IndexOf(" ")) : cmd)
            {
            case "list":
                foreach (var ai in invp[who].aether)
                {
                    if (ai.newOwner == who || !NotCoin(ai.item) || ai.newOwner != 255)
                    {
                        ai.unbuyable = true;
                        continue;
                    }
                    if (!string.IsNullOrEmpty(ai.item.Name))
                    {
                        text += string.Concat(ai.item.Name, " (", ai.item.value, " copper) ");
                    }
                }
                e.Player.SendInfoMessage(text == string.Empty ? "The items have expired or been reacquired." : text);
                break;

            case "buy":
                foreach (var ai in invp[who].aether)
                {
                    if (ai.unbuyable || ai.newOwner == who || ai.newOwner != 255 || !NotCoin(ai.item))
                    {
                        continue;
                    }
                    invp[who].coinBank = CoinPurse.CoinInit(who);
                    buyBack[who]       = true;
                    int value = ai.item.shopCustomPrice.HasValue ? ai.item.shopCustomPrice.Value : ai.item.value;
                    if (opt.ToLower().Replace(" ", "") == ai.item.Name.ToLower().Replace(" ", ""))
                    {
                        if (CoinPurse.ShopItem(who, value))
                        {
                            Item clone = ai.item.Clone();
                            foreach (Item i in Main.item)
                            {
                                if (i.IsTheSameAs(ai.item))
                                {
                                    i.active = false;
                                    i.SetDefaults(0);
                                    break;
                                }
                            }
                            e.Player.GiveItem(clone.type, clone.Name, clone.width, clone.height, clone.stack, clone.prefix);
                            e.Player.SendSuccessMessage(string.Concat("Reacquiring ", ai.item.Name, " complete."));
                            invp[who].aether.Remove(ai);
                            break;
                        }
                        else
                        {
                            e.Player.SendInfoMessage("The cost necessary for this item has not been acquired.");
                        }
                    }
                }
                break;

            default:
                break;
            }
        }