Ejemplo n.º 1
0
        private void ShopItem()
        {
            // WHo are you?
            Character c = _characterService.ReadByCharacterId(io.PromptUserForInt("What is your character's id?"));

            // Oh Hello... character
            io.DisplayCharacter(c);


            // have a look at my wares
            bool keepGoing = true;

            do
            {
                try
                {
                    io.DisplayItems(_characterService.RetrieveAvailableItems());

                    //What would you like to buy?
                    int itemId = io.PromptUserForInt("Select Item");

                    // attempt a sale
                    _characterService.BuyItem(c.Id, itemId);
                    keepGoing = false;
                }
                catch (NoItemAvailableException e)
                {
                    io.Display(e.Message);
                    keepGoing = false;
                }
                catch (Exception e)
                {
                    // you've done something wrong!
                    io.Display(e.Message);
                    if (c.Gold <= 0)
                    {
                        keepGoing = false;
                    }
                }
            } while (keepGoing);
        }