コード例 #1
0
 private void PlaceTreasureBagsInMaze()
 {
     treasureBagList = new List <TreasureBag>();
     for (int i = 0; i < treasureCount; i++)
     {
         int         x             = (int)treasurePositionList[i].x;
         int         y             = (int)treasurePositionList[i].y;
         Vector3     floorPosition = mazeStructure.GetFloorPosition(x, y);
         TreasureBag obj           = new TreasureBag()
         {
             bag      = Object.Instantiate(treasurebag, new Vector3(floorPosition.x, 0f, floorPosition.z), Quaternion.identity) as GameObject,
             position = treasurePositionList[i]
         };
         treasureBagList.Add(obj);
     }
 }
コード例 #2
0
        static void PrintType(TreasureBag bag, ValuableItemType type, int amount)
        {
            if (amount > 0)
            {
                Console.WriteLine($"<{type}> ${amount}");

                var itemsOfType = bag.GetItems()
                                  .Where(i => i.Type == type)
                                  .OrderByDescending(i => i.Name)
                                  .ThenBy(i => i.Quantity);

                foreach (var item in itemsOfType)
                {
                    Console.WriteLine($"##{item.Name} - {item.Quantity}");
                }
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            int capacity = int.Parse(Console.ReadLine());

            var bag     = new TreasureBag(capacity);
            var content = Console.ReadLine().Split(' ');

            Console.WriteLine();

            for (int i = 0; i < content.Length - 1; i += 2)
            {
                string name     = content[i];
                int    quantity = int.Parse(content[i + 1]);

                bag.TryPutItem(name, quantity);
            }

            PrintValuables(bag);

            Console.ReadKey();
        }
コード例 #4
0
 static void PrintValuables(TreasureBag bag)
 {
     PrintType(bag, ValuableItemType.Gold, bag.GoldAmount);
     PrintType(bag, ValuableItemType.Gem, bag.GemAmount);
     PrintType(bag, ValuableItemType.Cash, bag.CashAmount);
 }