コード例 #1
0
        /// <summary>
        /// 運用工廠模式,根據傳入值回傳對應的英雄類別
        /// </summary>
        /// <param name="heroType">傳入選項的值</param>
        /// <returns></returns>
        public static IAvengers GetAvenger(string heroType)
        {
            IAvengers avenger;

            if (heroType == "1")
            {
                return(avenger = new DoctorStrange());
            }
            if (heroType == "2")
            {
                return(avenger = new Hulk());
            }

            return(null);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Daenyas/codingame
        private static void RefreshBoard(Board board)
        {
            // Clear board
            board.Clear();

            string[] inputs;

            board.MyGold     = int.Parse(Console.ReadLine());
            board.EnnemyGold = int.Parse(Console.ReadLine());
            board.RoundType  = int.Parse(Console.ReadLine()); // a positive value will show the number of heroes that await a command

            // Units
            int entityCount = int.Parse(Console.ReadLine());

            for (int i = 0; i < entityCount; i++)
            {
                inputs = Console.ReadLine().Split(' ');
                int    unitId           = int.Parse(inputs[0]);
                int    team             = int.Parse(inputs[1]);
                string unitType         = inputs[2]; // UNIT, HERO, TOWER, can also be GROOT from wood1
                int    x                = int.Parse(inputs[3]);
                int    y                = int.Parse(inputs[4]);
                int    attackRange      = int.Parse(inputs[5]);
                int    health           = int.Parse(inputs[6]);
                int    maxHealth        = int.Parse(inputs[7]);
                int    shield           = int.Parse(inputs[8]); // useful in bronze
                int    attackDamage     = int.Parse(inputs[9]);
                int    movementSpeed    = int.Parse(inputs[10]);
                int    stunDuration     = int.Parse(inputs[11]); // useful in bronze
                int    goldValue        = int.Parse(inputs[12]);
                int    countDown1       = int.Parse(inputs[13]); // all countDown and mana variables are useful starting in bronze
                int    countDown2       = int.Parse(inputs[14]);
                int    countDown3       = int.Parse(inputs[15]);
                int    mana             = int.Parse(inputs[16]);
                int    maxMana          = int.Parse(inputs[17]);
                int    manaRegeneration = int.Parse(inputs[18]);
                string heroType         = inputs[19];            // DEADPOOL, VALKYRIE, DOCTOR_STRANGE, HULK, IRONMAN
                int    isVisible        = int.Parse(inputs[20]); // 0 if it isn't
                int    itemsOwned       = int.Parse(inputs[21]); // useful from wood1

                Unit u;

                switch (unitType)
                {
                case "UNIT":
                    u = new Minion();
                    break;

                case "HERO":
                    switch (heroType)
                    {
                    case "DEADPOOL":
                        u = new Deadpool();
                        break;

                    case "VALKYRIE":
                        u = new Valkyrie();
                        break;

                    case "DOCTOR_STRANGE":
                        u = new DoctorStrange();
                        break;

                    case "HULK":
                        u = new Hulk();
                        break;

                    case "IRONMAN":
                    default:
                        u = new Ironman();
                        break;
                    }
                    //u.CountDown123
                    u.Mana    = mana;
                    u.MaxMana = maxMana;
                    //u.ManaRegen
                    //u.IsVisible
                    //u.Items
                    break;

                case "TOWER":
                    u = new Tower();
                    break;

                case "GROOT":
                default:
                    u = new NeutralMonster();
                    break;
                }

                u.Id          = unitId;
                u.TeamId      = team;
                u.X           = x;
                u.Y           = y;
                u.AttackRange = attackRange;
                u.Health      = health;
                u.MaxHealth   = maxHealth;
                //u.Shield =
                u.BaseAttackDamage  = attackDamage;
                u.BaseMovementSpeed = movementSpeed;
                //u.StunDuration
                //u.Gold

                board.Units.Add(u);
            }
        }