public static void RenderShopKeeperMenu(ShopKeeper shopKeeper, Hero hero)
        {
            Console.BackgroundColor = ConsoleColor.Black;
            ConsoleRenderer.Clear();
            int startingTop  = (Console.BufferHeight / 2) - 2;
            int startingLeft = 47;

            Console.SetCursorPosition(startingLeft, startingTop);

            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("The ShopKeeper {0} offers these items:", shopKeeper.Name);
            Console.CursorLeft = startingLeft;

            for (int i = 0; i < shopKeeper.Items.Length; i++)
            {
                if (shopKeeper.Items[i] != null)
                {
                    if (hero.Gold >= shopKeeper.Items[i].Value)
                    {
                        Console.ForegroundColor = ConsoleColor.DarkGreen;
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                    }
                    Console.WriteLine("{0}. {1} - {2} Price: {3}", i + 1, shopKeeper.Items[i].Name, shopKeeper.Items[i].Description, shopKeeper.Items[i].Value);
                    Console.CursorLeft = startingLeft;
                }
            }

            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("Esc: Exit.");
        }
Esempio n. 2
0
        private void SetPositionables(Board board)
        {
            board.FreeFloorsPos = new List <Position>(board.FloorsPos);

            foreach (var boardPositionable in this.BoardPositionables)
            {
                for (int i = 0; i < boardPositionable.MaxItemCount; i++)
                {
                    int check = BoardFactory.rand.Next(0, 100);

                    if (check < boardPositionable.ItemChance)
                    {
                        int randomFloor = BoardFactory.rand.Next(0, board.FloorsPos.Count); //freefloors
                        switch (boardPositionable.Name)
                        {
                        case "Gold": AddPositionableToBoard(new Gold(board.FloorsPos[randomFloor]), board, randomFloor); break;

                        case "HealthPotion": AddPositionableToBoard(new HealthPotion(board.FloorsPos[randomFloor]), board, randomFloor); break;

                        case "ManaPotion": AddPositionableToBoard(new ManaPotion(board.FloorsPos[randomFloor]), board, randomFloor); break;

                        case "RogueArmorStrong": AddPositionableToBoard(new RogueArmor(board.FloorsPos[randomFloor], 150, 5), board, randomFloor); break;

                        case "RogueArmorWeak": AddPositionableToBoard(new RogueArmor(board.FloorsPos[randomFloor], 70, 2), board, randomFloor); break;

                        case "WizardArmorStrong": AddPositionableToBoard(new WizardArmor(board.FloorsPos[randomFloor], 150, 5), board, randomFloor); break;

                        case "WizardArmorWeak": AddPositionableToBoard(new WizardArmor(board.FloorsPos[randomFloor], 70, 2), board, randomFloor); break;

                        case "RogueWeaponStrong": AddPositionableToBoard(new RogueWeapon(board.FloorsPos[randomFloor], 100, 5), board, randomFloor); break;

                        case "RogueWeaponWeak": AddPositionableToBoard(new RogueWeapon(board.FloorsPos[randomFloor], 50, 2), board, randomFloor); break;

                        case "WizardWeaponStrong": AddPositionableToBoard(new WizardWeapon(board.FloorsPos[randomFloor], 100, 5), board, randomFloor); break;

                        case "WizardWeaponWeak": AddPositionableToBoard(new WizardWeapon(board.FloorsPos[randomFloor], 50, 2), board, randomFloor); break;

                        case "Trinket": AddPositionableToBoard(new Trinket(board.FloorsPos[randomFloor]), board, randomFloor);
                            break;

                        case "ShopKeeper": AddPositionableToBoard(ShopKeeper.GetShopKeeper(board.FloorsPos[randomFloor]), board, randomFloor);
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public static ShopKeeper GetShopKeeper(Position position)
        {
            const string ShopKeeperName   = "Tayn Eeon";
            const int    ShopKeeperHealth = 1024;
            const int    ShopKeeperDamage = 1024;
            const int    ShopKeeperXP     = 1024;

            ShopKeeper shopKeeper = new ShopKeeper(ShopKeeperName, position, ShopKeeperHealth)
            {
                Damage = ShopKeeperDamage, XPGain = ShopKeeperXP
            };

            for (int i = 0; i < shopKeeper.items.Length; i++)
            {
                int randomItem      = ShopKeeper.rand.Next(0, 5);
                int randomItemLevel = ShopKeeper.rand.Next(1, 6);
                int itemValue       = randomItemLevel * 1000;

                switch (randomItem)
                {
                case 0:
                    shopKeeper.items[i] = new RogueArmor(new Position(), itemValue, randomItemLevel);
                    break;

                case 1:
                    shopKeeper.items[i] = new WizardArmor(new Position(), itemValue, randomItemLevel);
                    break;

                case 2:
                    shopKeeper.items[i] = new RogueWeapon(new Position(), itemValue, randomItemLevel);
                    break;

                case 3:
                    shopKeeper.items[i] = new WizardWeapon(new Position(), itemValue, randomItemLevel);
                    break;

                case 4:
                    shopKeeper.items[i] = new Trinket(new Position());
                    break;

                default:
                    throw new ArgumentException("Invalid random item.");
                }
            }

            return(shopKeeper);
        }
Esempio n. 4
0
        private int PlayBoard(Board board, List <Board> boards, Hero hero, int boardLevel, List <Monster> monsters)
        {
            bool itemSteppedByHero        = true;
            bool itemSteppedByMonster     = false;
            bool stairsSteppedOnByHero    = true;
            bool stairsSteppedOnByMonster = false;
            bool isNextToCharacter        = false;
            int  itemDescriptionLength    = 0;
            int  itemNameLength           = 0;

            foreach (var monster in monsters)
            {
                monster.Death += (sender, args) =>
                {
                    Monster mnstr = sender as Monster;
                    hero.Level.AddXP(mnstr.XPGain);
                };
            }

            ConsoleRenderer.RenderAllItems(board.PositionableObjects);
            while (hero.IsAlive)
            {
                Position desiredPos = input.SetMovement(board, hero.Position);
                ConsoleRenderer.RenderMove(board, hero, desiredPos);
                if (hero.Position == board.EntryStairPos && boardLevel > 0)
                {
                    if (boardLevel == boards.Count)
                    {
                        boards.Add(board);
                    }
                    else if (true)
                    {
                        boards[boardLevel] = board;
                    }
                    return(-1);
                }
                if (hero.Position == board.ExitStairPos)
                {
                    if (boardLevel == boards.Count)
                    {
                        boards.Add(board);
                    }
                    else if (true)
                    {
                        boards[boardLevel] = board;
                    }
                    return(1);
                }
                if (stairsSteppedOnByHero)
                {
                    ConsoleRenderer.RenderStairs(board);
                    stairsSteppedOnByHero = false;
                }
                if (hero.Position == board.EntryStairPos || hero.Position == board.ExitStairPos)
                {
                    stairsSteppedOnByHero = true;
                }
                if (itemSteppedByHero)
                {
                    ConsoleRenderer.RenderAllItems(board.PositionableObjects);
                    ConsoleRenderer.RemoveDescription(itemNameLength, itemDescriptionLength);
                    itemSteppedByHero = false;
                }
                if (isNextToCharacter)
                {
                    ConsoleRenderer.RenderAllItems(board.PositionableObjects);
                    ConsoleRenderer.RemoveDescription(itemNameLength, itemDescriptionLength);
                    itemSteppedByHero = false;
                }
                // GameEngine is alias to ConsoleRenderer.Engine just check the usings
                ConsoleRenderer.RenderStats(hero, boardLevel);
                //Always render the hero at the end so he can be on top on all the items and monsters !
                ConsoleRenderer.RenderCharacter(hero);
                foreach (var monster in monsters)
                {
                    if (hero.Position.Distance(monster.Position) < 1.5)
                    {
                        hero.TakeDamage(monster.Damage);
                    }
                    else if (hero.Position.Distance(monster.Position) < 5.5 && hero.Position.Distance(monster.Position) >= 1.5)
                    {
                        Position newPos = monster.NextMovingPosition(board, hero.Position);
                        if (MonsterMovement.IsValidMovement(board, newPos))
                        {
                            ConsoleRenderer.RenderMove(board, monster, newPos);
                            if (stairsSteppedOnByMonster)
                            {
                                ConsoleRenderer.RenderStairs(board);
                                stairsSteppedOnByMonster = false;
                            }
                            if (itemSteppedByMonster)
                            {
                                ConsoleRenderer.RenderAllItems(board.PositionableObjects);
                                itemSteppedByMonster = false;
                            }
                        }

                        if (monster.Position == board.EntryStairPos || monster.Position == board.ExitStairPos)
                        {
                            stairsSteppedOnByMonster = true;
                        }
                        foreach (var positionable in board.PositionableObjects)
                        {
                            if (monster.Position == positionable.Position)
                            {
                                if (positionable is Item)
                                {
                                    itemSteppedByMonster = true;
                                }
                            }
                        }

                        ConsoleRenderer.RenderCharacter(monster);
                    }

                    if (desiredPos == monster.Position)
                    {
                        monster.TakeDamage(hero.Weapon);
                    }
                }

                if (monsters.Any(mnstr => mnstr.IsAlive == false))
                {
                    var deadMonsters = monsters.Where(mnstr => mnstr.IsAlive == false).ToArray();
                    foreach (var monster in deadMonsters)
                    {
                        monsters.Remove(monster);
                        board.PositionableObjects.Remove(monster);
                        board.FreeFloorsPos.Add(monster.Position);
                        ConsoleRenderer.RenderObjectRemoval(monster.Position);
                    }
                }

                foreach (var positionable in board.PositionableObjects)
                {
                    if (positionable is Character)
                    {
                        if (hero.Position.Distance(positionable.Position) < 1.5)
                        {
                            ConsoleRenderer.RenderCharacterDescription(positionable as Character);
                            isNextToCharacter = true;
                        }

                        if (positionable is ShopKeeper && desiredPos == positionable.Position)
                        {
                            ShopKeeper shopKeeper = positionable as ShopKeeper;

                            do
                            {
                                ConsoleRenderer.RenderShopKeeperMenu(shopKeeper, hero);
                                ShopKeeperOptions option = input.ShopKeeperInteraction();
                                if (option == ShopKeeperOptions.Escape)
                                {
                                    break;
                                }
                                else if (option == ShopKeeperOptions.InvalidOption)
                                {
                                    ConsoleRenderer.Clear();
                                }
                                else
                                {
                                    int index = (int)option;

                                    if (shopKeeper.Items[index] != null && hero.Gold >= shopKeeper.Items[index].Value)
                                    {
                                        hero.Buy(shopKeeper.Items[index]);
                                        shopKeeper.Items[index] = null;
                                        break;
                                    }
                                }
                            } while (true);
                            ConsoleRenderer.Clear();
                            ConsoleRenderer.RenderPlayingScreen(hero, board, boardLevel);
                            ConsoleRenderer.RenderAllItems(board.PositionableObjects);
                        }
                    }


                    if (hero.Position == positionable.Position)
                    {
                        if (positionable is Item)
                        {
                            Item item = positionable as Item;
                            ConsoleRenderer.RenderItemDescription(item);
                            itemDescriptionLength = item.Description.Length;
                            itemNameLength        = item.Name.Length;
                            itemSteppedByHero     = true;
                            this.steppedOnItem    = (char)item.Icon;
                            this.itemColor        = item.ItemColor.ToConsoleColor();
                            hero.TakeItem(item, board);
                            break;
                        }

                        //tell me what shall i implement for the wizard armor ...please "ArmorSpell" WTF ?! :D
                        //if(item is WizardArmor && gandalf is Wizard && gandalf.Level.CurrentLevel>=item.NeededLvl)
                        //{
                        //	gandalf.TakeWizardArmor(item);
                        //	items.Remove(item);
                        //	this.steppedOnItem = ' ';
                        //	this.itemColor = ConsoleColor.White;
                        //	break;
                        //}
                    }



                    /*
                     * Implement later :
                     *
                     * if weapon
                     * if armor
                     *
                     */
                }
            }
            return(0);
        }