Beispiel #1
0
        public static void Combat(Player player)
        {
            Random rnd   = new Random();
            Enemy  enemy = PersonFabric.CreateEnemy(player);

            Console.WriteLine("A level {0} {1} started a fight.", enemy.Level, enemy.Race);
            bool Fighting = true;
            bool Success  = false;

            while (Fighting)
            {
                if (enemy.Health <= 0)
                {
                    Fighting = false;
                    Win(player, enemy);
                }
                else if (player.Health <= 0)
                {
                    Fighting = false;
                    Lose(player);
                }
                else
                {
                    RenderInventory(player);
                    int DefenseVal = 0;
                    System.Threading.Thread.Sleep(100);
                    Console.WriteLine("Its your turn, you can:\n1. Attack\n2. Defend\n3. Open inventory.");
                    Console.WriteLine("{0}'s Health: {1}", player.Name, player.Health);
                    Console.WriteLine("{0}'s Health: {1}", enemy.Race, enemy.Health);
                    string plrInput = Console.ReadLine();
                    switch (plrInput)
                    {
                    case "1":
                        if (player.PrimaryWeapon != null)
                        {
                            int damage = player.Attack(enemy);
                            Console.WriteLine("{0} attacked enemy {1} with a {2}, the {1} lost {3} health.", player.Name, enemy.Race, player.PrimaryWeapon.ItemName, damage);
                            Success = true;
                        }

                        break;

                    case "2":
                        Success    = true;
                        DefenseVal = player.Defense;
                        break;

                    case "3":
                        if (!OpenInventory(player))
                        {
                            continue;
                        }
                        Success = true;
                        break;
                    }
                    System.Threading.Thread.Sleep(200);
                    RenderStats(player);
                    System.Threading.Thread.Sleep(100);
                    if (Success)
                    {
                        Success = false;
                        if (enemy.Health <= 0)
                        {
                            continue;
                        }
                    }
                    else if (Success == false)
                    {
                        Console.WriteLine("Incorrect input, turn skipped.");
                        continue;
                    }
                    if (enemy.Health < enemy.FullHealth / 4)
                    {
                        enemy.WillHeal = rnd.Next(0, 3) == 1 && enemy.HasFood;
                    }
                    if (enemy.WillHeal)
                    {
                        Item food = enemy.Food.First();
                        enemy.Heal(food);
                        Console.WriteLine("{0} healed {1}.", enemy.Race, food.Damage);
                    }
                    else if (DefenseVal > 0)
                    {
                        Console.WriteLine("{0} attacks.", enemy.Race);
                        System.Threading.Thread.Sleep(100);
                        Console.WriteLine("{0} defends.", player.Name);
                        if (enemy.Damage - DefenseVal > 0)
                        {
                            player.Health -= enemy.Damage - DefenseVal;
                        }
                        DefenseVal = 0;
                    }
                    else
                    {
                        Item enemyWeapon = enemy.Inventory[0];
                        int  damage      = enemy.Attack(player);
                        Console.WriteLine("{0} attacks, {1} loses {2} health.", enemy.Race, player.Name, damage);
                    }
                }
            }
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            string[] Places = { "Griglagg", "Ravenwood", "Dunwich", "Greenwood" };
            Console.WriteLine("Welcome to Dragon Eye, a terminal RPG!");
            System.Threading.Thread.Sleep(2000);
            Console.WriteLine("This game was created for the AI competition on repl.it");
            System.Threading.Thread.Sleep(2000);
            Player MainPlayer = PersonFabric.CreatePlayer();

            RenderStats(MainPlayer);
            RenderInventory(MainPlayer);
            Random rnd = new Random();

            Console.WriteLine("Your adventure begins..");
            while (true)
            {
                System.Threading.Thread.Sleep(1000);
                int travel = rnd.Next(0, 5);
                if (travel == 1)
                {
                    string place = Places[rnd.Next(0, Places.Length)];
                    Console.WriteLine("You travel to {0}.", place);
                }
                else
                {
                    int action = rnd.Next(0, 4); // 0 combat, 1 quest, 2 someone asks for gold, 3 find something
                    switch (action)
                    {
                    case 0:
                        Combat(MainPlayer);
                        break;

                    case 1:
                        Console.WriteLine("A fellow {0} asks {1} for 10 Gold Pieces, do you accept?", MainPlayer.Race, MainPlayer.Name);
                        Console.WriteLine("1. Yes\n2. No");
                        string Answer = Console.ReadLine();
                        switch (Answer)
                        {
                        case "1":
                            if (MainPlayer.GP < 10)
                            {
                                Console.WriteLine("You have only {0} Gold Pieces", MainPlayer.GP);
                            }
                            else
                            {
                                MainPlayer.GP -= 10;
                                Console.WriteLine("You gave the {0} 10 Gold Pieces.", MainPlayer.Race);
                                int giftSomething = rnd.Next(0, 2);
                                if (giftSomething == 1)
                                {
                                    Item giftItem = ItemFabric.CreateItem(MainPlayer.Level);
                                    MainPlayer.Inventory.Add(giftItem);
                                    Console.WriteLine("{0} gifts you a new {1}!", MainPlayer.Race, giftItem.ItemName);
                                }
                            }
                            break;

                        case "2":
                            Console.WriteLine("You refused to give the {0} Gold Pieces.", MainPlayer.Race);
                            break;

                        default:
                            Console.WriteLine("You refused to give the {0} Gold Pieces.", MainPlayer.Race);
                            break;
                        }
                        break;

                    case 2:
                        Console.WriteLine("Someone walks up to {0}, and asks him/her to slay a monster.", MainPlayer.Name);
                        System.Threading.Thread.Sleep(500);
                        if (rnd.Next(0, 2) == 1)
                        {
                            Console.WriteLine("{0} accepted the offer.", MainPlayer.Name);
                            Combat(MainPlayer);
                        }
                        else
                        {
                            Console.WriteLine("{0} declined the offer.", MainPlayer.Name);
                        }
                        break;

                    case 3:
                        Item newItem = ItemFabric.CreateItem(MainPlayer.Level);
                        MainPlayer.Inventory.Add(newItem);
                        Console.WriteLine("You found a {0}.", newItem.ItemName);
                        break;
                    }
                }
            }
        }