Oplossing opgave 3

using System;
using System.Collections.Generic;
using System.Linq;

namespace MagicCastingGame
{
    public enum ManaType { Water, Bos, Zon, Vuur, Dood }

    public class CastingCost
    {
        public ManaType ColoredTypeNeeded { get; }
        public int AmountColoredTypeNeeded { get; }
        public int AmountUncoloredTypeNeeded { get; }

        public CastingCost(ManaType type, int colored, int uncolored)
        {
            ColoredTypeNeeded = type;
            AmountColoredTypeNeeded = colored;
            AmountUncoloredTypeNeeded = uncolored;
        }
    }

    public class CreatureKaart
    {
        public string CreatureName { get; }
        public CastingCost Cost { get; }
        public string SpecialAbilities { get; }
        public string FlavourText { get; }

        private int _attack;
        private int _defense;

        public int Attack
        {
            get { return _attack; }
            private set
            {
                if (value < 0)
                {
                    _attack = 0;
                }
                else
                {
                    _attack = value;
                }
            }
        }

        public int Defense
        {
            get { return _defense; }
            private set
            {
                if (value < 0)
                {
                    _defense = 0;
                }
                else
                {
                    _defense = value;
                }
            }
        }

        public CreatureKaart(string name, CastingCost cost, string abilities, string flavour, int attack, int defense)
        {
            CreatureName = name;
            Cost = cost;
            SpecialAbilities = abilities;
            FlavourText = flavour;
            Attack = attack;
            Defense = defense;
        }

        public void ChangeAttack(bool increase)
        {
            if (increase)
                Attack++;
            else
                Attack--;
        }

        public void ToonKaart()
        {
            Console.WriteLine("*******************************************************");
            Console.WriteLine($"{CreatureName} ({Cost.AmountUncoloredTypeNeeded} kleurloos, {Cost.AmountColoredTypeNeeded} {Cost.ColoredTypeNeeded} mana)");
            Console.WriteLine("*******************************************************");
            Console.WriteLine($"\"{FlavourText}\"");
            Console.WriteLine("-------------------------------------------------------");
            Console.WriteLine($"    Abilities: {SpecialAbilities}");
            Console.WriteLine($"    Attack: {Attack}");
            Console.WriteLine($"    Defense: {Defense}");
            Console.WriteLine("-------------------------------------------------------");
        }
    }

    public class LandKaart
    {
        public string Naam { get; }
        public ManaType ManaType { get; }

        public LandKaart(string naam, ManaType manaType)
        {
            Naam = naam;
            ManaType = manaType;
        }

        public void ToonKaart()
        {
            Console.WriteLine("*******************************************************");
            Console.WriteLine($"{Naam} ({ManaType} mana)");
            Console.WriteLine("*******************************************************");
        }

        public static bool CastTest(List<LandKaart> deck, CreatureKaart creature)
        {
            int coloredAvailable = 0;
            int totalAvailable = 0;

            foreach (LandKaart kaart in deck)
            {
                if (kaart.ManaType == creature.Cost.ColoredTypeNeeded)
                {
                    coloredAvailable++;
                }
                totalAvailable++;
            }

            if (coloredAvailable >= creature.Cost.AmountColoredTypeNeeded &&
                totalAvailable >= creature.Cost.AmountColoredTypeNeeded + creature.Cost.AmountUncoloredTypeNeeded)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }

    class Program
    {
        static void Main()
        {
            // Stap 1: Landen maken
            List<LandKaart> deck = new List<LandKaart>();
            foreach (ManaType type in Enum.GetValues(typeof(ManaType)))
            {
                Console.WriteLine($"Aantal {type}?");
                int aantal = int.Parse(Console.ReadLine());
                for (int i = 0; i < aantal; i++)
                {
                    deck.Add(new LandKaart(type.ToString(), type));
                }
            }

            // Stap 2: Creature aanmaken
            var djinn = new CreatureKaart(
                "Mahamoti Djinn",
                new CastingCost(ManaType.Water, 2, 4),
                "Flying",
                "Of royal blood among the spirits [etcetc]",
                5,
                6
            );

            var kindercatch = new CreatureKaart(
                "KinderCatch",
                new CastingCost(ManaType.Bos, 3, 3),
                "",
                "A rather sneaky beast",
                3,
                4
            );

            var goat = new CreatureKaart(
                "Mountain Goat",
                new CastingCost(ManaType.Vuur, 1, 0),
                "Mountainwalk",
                "Climbs higher than any goat",
                2,
                1
            );

            var creatures = new List<CreatureKaart> { djinn, kindercatch, goat };
            Console.WriteLine("Welk dier wens je te maken?");
            for (int i = 0; i < creatures.Count; i++)
            {
                Console.WriteLine($"({i + 1})");
                creatures[i].ToonKaart();
            }

            int keuze = int.Parse(Console.ReadLine());
            var gekozenDier = creatures[keuze - 1];

            // Stap 3: Cast test
            bool kanGemaaktWorden = LandKaart.CastTest(deck, gekozenDier);

            if (kanGemaaktWorden)
            {
                Console.WriteLine("Dier kan gemaakt worden");
            }
            else
            {
                Console.WriteLine("Dier kan niet gemaakt worden");
            }
        }
    }
}

Last updated

Was this helpful?