Exemplo n.º 1
0
        public Pokemon(string name, double hp = 10.0, double att = 1.0, double def = 1.0, PokemonType type = null)
        {
            if (hp < 0 || att < 0 || def < 0)
            {
                throw new ArgumentException("生命、攻擊力、防禦力都不能是負的");
            }

            this.Name = name;
            this.HP   = hp;
            this.ATT  = att;
            this.DEF  = def;
            this.Type = type;
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            // 建立好屬性相剋表
            var water = new PokemonType("水");
            var grass = new PokemonType("草");
            var fire  = new PokemonType("火");

            water.StrongAgainst = fire;
            water.WeakAgainst   = grass;
            grass.StrongAgainst = water;
            grass.WeakAgainst   = fire;
            fire.StrongAgainst  = grass;
            fire.WeakAgainst    = water;

            // 做出三隻神奇寶貝
            var bulbasaur  = new Pokemon("妙蛙種子", 10, 2, 1, grass);
            var squirtle   = new Pokemon("傑尼龜", 10, 2, 1, water);
            var charmander = new Pokemon("小火龍", 10, 2, 1, fire);

            bool turn = true; // 如果true則是第一隻神奇寶貝的回合; 如果是false是第二支的回合

            // 設定
            var player1 = bulbasaur; // 把這邊改掉
            var player2 = squirtle;  // 把這邊改掉

            // 開始打架(比方說妙蛙種子對傑尼龜)
            while (!player1.IsDead && !player2.IsDead)
            {
                if (turn)
                {
                    Console.WriteLine(player1.Name + "的回合,發動攻擊");
                    player1.Attack(player2);
                }
                else
                {
                    Console.WriteLine(player2.Name + "的回合,發動攻擊");
                    player2.Attack(player1);
                }
                Console.WriteLine("目前狀況:");
                Console.WriteLine(player1);
                Console.WriteLine(player2);
                Console.WriteLine("*********** 按任意鍵繼續");
                turn = !turn; //這樣就可以輪流
                Console.Read();
            }

            Console.WriteLine("對決結束");
            Console.Read();
        }
Exemplo n.º 3
0
 public Pokemon(String name, PokemonType type, PokemonType effectiveAgainst)
 {
     Name             = name;
     Type             = type;
     EffectiveAgainst = effectiveAgainst;
 }