コード例 #1
0
ファイル: RangedUnit.cs プロジェクト: MotherOfAzarath/Task1
 private int DistanceTo(Unit u)
 {
     if (u.GetType() == typeof(RangedUnit))
     {
         RangedUnit m = (RangedUnit)u;
         int        d = Math.Abs(Xpos - m.Xpos) + Math.Abs(Ypos - m.Ypos);
         return(d);
     }
     else
     {
         return(0);
     }
 }
コード例 #2
0
ファイル: RangedUnit.cs プロジェクト: MotherOfAzarath/Task1
 public override bool AttackRange(Unit u)
 {
     if (u.GetType() == typeof(RangedUnit))
     {
         RangedUnit M = (RangedUnit)u;
         if (DistanceTo(u) <= attackRange)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     return(false);
 }
コード例 #3
0
        public Map(int maxX, int maxY, int numUnits)
        {
            units = new Unit[numUnits];
            for (int i = 0; i < numUnits; i++)
            {
                if (i <= 10)
                {
                    MeeleeUnit M = new MeeleeUnit(r.Next(0, maxX), r.Next(0, maxY), r.Next(5, 10) * 10, r.Next(5, 20), 1, 1, i % 2, "ground.jpg", "archer");
                    Units[i] = M;
                }


                if (i > 10)
                {
                    RangedUnit R = new RangedUnit(r.Next(0, maxX), r.Next(0, maxY), r.Next(5, 10) * 10, r.Next(5, 20), 1, 1, i % 2, "ground.jpg", "archer");
                    Units[i] = R;
                }
            }
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: MotherOfAzarath/Task1
        private void DisplayMap()
        {
            groupBox1.Controls.Clear();
            foreach (Unit u in map.Units)
            {
                if (u.GetType() == typeof(MeeleeUnit))
                {
                    int start_x = 20;
                    int start_Y = 20;
                    start_x = groupBox1.Location.X;
                    start_Y = groupBox1.Location.Y;
                    MeeleeUnit m    = (MeeleeUnit)u;
                    PictureBox Pbox = new PictureBox();

                    Pbox.Size          = new Size(Size, Size);
                    Pbox.Location      = new Point(start_x + (m.Xpos * Size), start_Y + (m.Ypos * Size));
                    Pbox.SizeMode      = PictureBoxSizeMode.Zoom;
                    Pbox.ImageLocation = "ground.jpg";

                    if (m.Fact == 1)
                    {
                        Pbox.ImageLocation = "red.png";
                    }
                    else
                    {
                        Pbox.ImageLocation = "red.png";
                    }
                    if (m.isDead())
                    {
                        Pbox.ImageLocation = "ground.jpg";
                    }
                    groupBox1.Controls.Add(Pbox);
                    Pbox.Click += new EventHandler(Picture_Click);
                }
            }
            foreach (Unit u in map.Units)
            {
                if (u.GetType() == typeof(RangedUnit))
                {
                    int start_x = 20;
                    int start_Y = 20;
                    start_x = groupBox1.Location.X;
                    start_Y = groupBox1.Location.Y;
                    RangedUnit m    = (RangedUnit)u;
                    PictureBox Pbox = new PictureBox();

                    Pbox.Size          = new Size(Size, Size);
                    Pbox.Location      = new Point(start_x + (m.Xpos * Size), start_Y + (m.Ypos * Size));
                    Pbox.SizeMode      = PictureBoxSizeMode.Zoom;
                    Pbox.ImageLocation = "ground.jpg";

                    if (m.Fact == 1)
                    {
                        Pbox.ImageLocation = "purple.png";
                    }
                    else
                    {
                        Pbox.ImageLocation = "purple.png";
                    }
                    if (m.isDead())
                    {
                        Pbox.ImageLocation = "DirtGround.jpg";
                    }
                    groupBox1.Controls.Add(Pbox);
                    Pbox.Click += new EventHandler(Picture_Click);
                }
            }
        }
コード例 #5
0
ファイル: Form1.cs プロジェクト: MotherOfAzarath/Task1
        private void UpdateMap()
        {
            foreach (Unit u in map.Units)
            {
                if (u.GetType() == typeof(MeeleeUnit))
                {
                    MeeleeUnit m = (MeeleeUnit)u;

                    if (m.health < 25)
                    {
                        switch (r.Next(0, 4))
                        {
                        case 0: ((MeeleeUnit)u).NewMovePos(Direction.North); break;

                        case 1: ((MeeleeUnit)u).NewMovePos(Direction.East); break;

                        case 2: ((MeeleeUnit)u).NewMovePos(Direction.South); break;

                        case 3: ((MeeleeUnit)u).NewMovePos(Direction.West); break;
                        }
                    }
                    else
                    {
                        bool inCombat = false;
                        foreach (Unit e in map.Units)
                        {
                            if (u.AttackRange(e))
                            {
                                u.Combat(e);
                                inCombat = true;
                            }
                        }
                        if (!inCombat)
                        {
                            Unit c = u.UnitDistance(map.Units);
                            m.NewMovePos(m.Directionto(c));
                        }
                    }
                }
            }
            foreach (Unit u in map.Units)
            {
                if (u.GetType() == typeof(RangedUnit))
                {
                    RangedUnit m = (RangedUnit)u;

                    if (m.health < 25)
                    {
                        switch (r.Next(0, 4))
                        {
                        case 0: ((RangedUnit)u).NewMovePos(Direction.North); break;

                        case 1: ((RangedUnit)u).NewMovePos(Direction.East); break;

                        case 2: ((RangedUnit)u).NewMovePos(Direction.South); break;

                        case 3: ((RangedUnit)u).NewMovePos(Direction.West); break;
                        }
                    }
                    else
                    {
                        bool inCombat = false;
                        foreach (Unit e in map.Units)
                        {
                            if (u.AttackRange(e))
                            {
                                u.Combat(e);
                                inCombat = true;
                            }
                        }
                        if (!inCombat)
                        {
                            Unit c = u.UnitDistance(map.Units);
                            m.NewMovePos(m.Directionto(c));
                        }
                    }
                }
            }
        }