public override void LocationEvent(World world, Player player)
        {
            base.LocationEvent(world, player);

            //get all the armor from the player's inventory
            Armor[]  armors    = player.Inventory.OfType <Armor>().ToArray();
            string[] decisions = new string[armors.Length + 1];
            for (int i = 0; i < decisions.Length; i++)
            {
                decisions[i] = i < armors.Length ? $"{armors[i].Name} for {Price.ToString("C")}" : "Nothing";
            }

            //input validation loop
            while (true)
            {
                Console.WriteLine($"What armor do you want to repair?\nMoney: {player.Money.ToString("C")}");
                int answer = DecisionHandler.MakeDecision(decisions);
                if (answer == armors.Length)
                {
                    break;
                }
                else if (Price > player.Money)
                {
                    Console.WriteLine("You don't have enough money!");
                }
                else
                {
                    player.RepairArmor(armors[answer], Price);
                }
            }
        }
예제 #2
0
        protected override void AdjacentEvent(World world, Player player)
        {
            base.AdjacentEvent(world, player);

            if (IsOpen)
            {
                return;
            }
            //prompt user to open door
            Console.WriteLine($"You found {Name}. Do you want to unlock it?");
            int answer = DecisionHandler.MakeDecision(new string[] { "Yes", "No" }, "");

            if (answer == 0)
            {
                //get all keys in their inventory
                List <Key> keys = player.Inventory.OfType <Key>().ToList();

                //try unlocking door
                if (TryOpen(keys))
                {
                    Console.WriteLine($"You unlocked {Name}!\n");
                    IsOpen = true;
                }
                else
                {
                    Console.WriteLine($"You don't have the right keys.\n");
                }
            }
        }
예제 #3
0
        public override void LocationEvent(World world, Player player)
        {
            base.LocationEvent(world, player);

            string[] decisions = new string[ShopItems.Length + 1];
            for (int i = 0; i < decisions.Length; i++)
            {
                decisions[i] = i < ShopItems.Length ? $"{ShopItems[i].item} for {ShopItems[i].price.ToString("C")}" : "Nothing";
            }

            while (true)
            {
                Console.WriteLine($"What do you want to buy?\nMoney: {player.Money.ToString("C")}");
                int answer = DecisionHandler.MakeDecision(decisions);
                if (answer == ShopItems.Length)
                {
                    break;
                }
                else if (ShopItems[answer].price > player.Money)
                {
                    Console.WriteLine("You don't have enough money!");
                }
                else
                {
                    player.PurchaceItem(ShopItems[answer]);
                }
            }
        }
예제 #4
0
        //when the player is at this location
        public virtual void LocationEvent(World world, Player player)
        {
            //display location
            Console.WriteLine($"\n{Name}:\n{Description}\n");

            //for adjacent locations
            int[,] directions = new int[, ] {
                { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }
            };

            //find any items
            List <Item> items = world.Items.FindAll(item => world.GetLocation(item) == this);

            //if there are any items, prompt user if they want to get an item
            if (items.Count > 0)
            {
                Console.WriteLine($"{player.Name}, there are items here! what will you pick up?");

                //item pickup loop
                while (true)
                {
                    //setup decisions for the player
                    string[] decisions = new string[items.Count + 1];
                    for (int i = 0; i < decisions.Length; i++)
                    {
                        decisions[i] = i < items.Count ? items[i].Name : "Nothing";
                    }
                    //prompt player
                    int itemIndex = DecisionHandler.MakeDecision(decisions, "You picked up");
                    //if player chooses the last option, then they don't pick up anything
                    if (itemIndex != items.Count)
                    {
                        //drop any items of a similar type that are forced single
                        Item similarItem = player.Inventory.Find(x => x.ForceSingle == true && x.Tag == items[itemIndex].Tag);
                        if (similarItem != null)
                        {
                            Console.WriteLine($"You dropped {similarItem.Name} in it's place.");
                            world.EntityDropItem(player, similarItem);
                        }
                        //pick up item
                        Item item = items[itemIndex];
                        world.EntityGetItem(player, item);
                        items.Remove(item);
                    }
                    else
                    {
                        break;
                    }
                    if (items.Count == 0)
                    {
                        break;
                    }
                }
            }

            //run the adjacent location events
            for (int i = 0; i < directions.GetLength(0); i++)
            {
                int dirX = player.Pos.x + directions[i, 0];
                int dirY = player.Pos.y + directions[i, 1];

                Location adjacent = world.GetLocation(dirX, dirY);
                if (adjacent == null)
                {
                    continue;
                }
                adjacent.AdjacentEvent(world, player);
            }
        }