コード例 #1
0
        private static void ConductBattle(FightQueue queue)
        {
            while (queue.AllAlive())
            {
                int dmg;
                if (queue.CurrentUnit() is Player player)
                {
                    Console.WriteLine("Choose type of attack: 1) Melee, 2) Magic");
                    ConsoleKeyInfo input = Console.ReadKey();

                    // TODO: Convert ConsoleKeyInfo value to AttackType enumerator.
                    dmg = CalculatePlayerDamage(player, input);
                }
                else
                {
                    dmg = queue.CurrentUnit().Attack + RollD4();
                }

                queue.NextUnit().Hp -= dmg;
                Console.WriteLine($"Unit {queue.CurrentUnit().Name} dealt {dmg} damage.");

                if (queue.NextUnit().IsAlive == false)
                {
                    Console.WriteLine($"Unit {queue.NextUnit().Name} is dead");
                    break;
                }
                queue.AdvanceQueue();
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var player  = new Player("Alice", hp: 50, attack: 4, initiative: 5, magic: 2);
            var monster = new Monster("Bob", 20, 5, 3, magic: 0);

            Console.WriteLine($"Your player name is {player.Name}");
            Console.WriteLine($"You stared fight with a monsert {monster.Name}");

            List <UnitBase> queueOrder;

            queueOrder = GetQueueOrder(player, monster);

            FightQueue queue = new FightQueue(queueOrder);

            ConductBattle(queue);
            Console.WriteLine($"Fight ended.");
        }