예제 #1
0
 public Direction Directionto(Unit u)
 {
     if (u.GetType() == typeof(RangesUnit))
     {
         RangesUnit r = (RangesUnit)u;
         if (r.Xpos < Xpos)
         {
             return(Direction.North);
         }
         else if (r.Ypos > Ypos)
         {
             return(Direction.East);
         }
         else if (r.Xpos > xpos)
         {
             return(Direction.South);
         }
         else
         {
             return(Direction.West);
         }
     }
     else
     {
         return(Direction.North);
     }
 }
예제 #2
0
 private int Distance(Unit u)
 {
     if (u.GetType() == typeof(RangesUnit))
     {
         RangesUnit r = (RangesUnit)u;
         int        d = Math.Abs(Xpos - r.Xpos) + Math.Abs(Ypos - r.Ypos);
         return(d);
     }
     else
     {
         return(0);
     }
 }
예제 #3
0
 public override bool Range(Unit u)
 {
     if (u.GetType() == typeof(RangesUnit))
     {
         RangesUnit m = (RangesUnit)u;
         if (Distance(u) <= Attackrange)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
예제 #4
0
        private void Button_Click(object sender, EventArgs e)
        {
            int x = (((Button)sender).Location.X - GBMap.Location.X) / SIZE;
            int y = (((Button)sender).Location.Y - GBMap.Location.Y) / SIZE;

            txtInfo.Text = x + " " + y;
            foreach (Unit u in map.Units)
            {
                if (u.GetType() == typeof(MeleeUnit))
                {
                    MeleeUnit m = (MeleeUnit)u;
                    if (m.Xpos == x && m.Ypos == y)
                    {
                        txtInfo.Text = "Melee" + m.ToString();
                    }
                }
            }
            foreach (Unit Y in map.Units)
            {
                if (y.GetType() == typeof(RangesUnit))
                {
                    RangesUnit r = (RangesUnit)Y;
                    if (r.Xpos == x && r.Ypos == y)
                    {
                        txtInfo.Text = "Archer" + r.ToString();
                    }
                }
            }
            foreach (Unit X in map.Units)
            {
                if (y.GetType() == typeof(Grubs))
                {
                    Grubs G = (Grubs)X;
                    if (G.Xpos == x && G.Ypos == y)
                    {
                        txtInfo.Text = "Grubs" + G.ToString();
                    }
                }
            }
        }
예제 #5
0
파일: Map.cs 프로젝트: WhiteHornet/Task3.1
        public Map(int maxx, int maxy, int numUnits, int numBuilding)
        {
            building = new Building[numBuilding];
            units    = new Unit[numUnits];
            for (int i = 0; i < numUnits / 3; i++)
            {
                MeleeUnit M = new MeleeUnit(R.Next(0, maxx),
                                            R.Next(0, maxy),
                                            50,
                                            15,
                                            1,
                                            1,
                                            i % 2,
                                            "M",
                                            "Warrior");
                Units[i] = M;
            }

            for (int j = numUnits / 2; j < numUnits; j++)
            {
                RangesUnit r = new RangesUnit(R.Next(0, maxx),
                                              R.Next(0, maxy),
                                              50,
                                              10,
                                              1,
                                              3,
                                              j % 2,
                                              "R",
                                              "Archer");
                Units[j] = r;
            }

            for (int m = 0; m < numUnits / 2; m++)
            {
                Grubs g = new Grubs(R.Next(0, maxx),
                                    R.Next(0, maxy),
                                    100,
                                    7,
                                    1,
                                    2,
                                    m % 2,
                                    "G",
                                    "grubs");
                Units[m] = g;
            }

            //for (int n = 0; n < numUnits / 2; n++)
            //{
            //    deadshot ds = new deadshot(R.Next(0, maxx),
            //                                  R.Next(0, maxy),
            //                                  15,
            //                                  25,
            //                                  1,
            //                                  4,
            //                                  n % 2,
            //                                  "DS",
            //                                  "DeadShot");
            //    Units[n] = ds;

            //}

            //for (int k = numBuilding / 2; k < numBuilding; k++)
            //{
            //    ResourceBuilding rb = new ResourceBuilding(R.Next(0, maxx),
            //                                  R.Next(0, maxy),
            //                                  1000,
            //                                  k % 2,
            //                                  "ResourceBuilding");
            //    building[k] = rb;
            //}

            //for (int l = numBuilding / 2; l < numBuilding; l++)
            //{
            //    FactoryBuilding fb = new FactoryBuilding(R.Next(0, maxx),
            //                                  R.Next(0, maxy),
            //                                  1000,
            //                                  l % 2,
            //                                  "FactoryBuilding");
            //    building[l] = fb;
            //}
        }
예제 #6
0
        private void DisplayMap()
        {
            GBMap.Controls.Clear();
            foreach (Unit u in map.Units)
            {
                if (u.GetType() == typeof(MeleeUnit))
                {
                    int begin_x, begin_y;
                    begin_x = GBMap.Location.X;
                    begin_y = GBMap.Location.Y;
                    MeleeUnit m = (MeleeUnit)u;
                    Button    b = new Button();
                    b.Size     = new Size(SIZE, SIZE);
                    b.Location = new Point(begin_x + (m.Xpos * SIZE), begin_y + (m.Ypos * SIZE));
                    b.Text     = m.Symbol;
                    if (m.Faction == 2)
                    {
                        b.ForeColor = Color.Silver;
                    }
                    else
                    {
                        b.ForeColor = Color.Orange;
                    }

                    if (m.Death())
                    {
                        b.ForeColor = Color.Black;
                    }
                    b.Click += new EventHandler(Button_Click);
                    GBMap.Controls.Add(b);
                }

                else if (u.GetType() == typeof(RangesUnit))
                {
                    int start_x, start_y;
                    start_x = GBMap.Location.X;
                    start_y = GBMap.Location.Y;
                    RangesUnit r = (RangesUnit)u;
                    Button     b = new Button();
                    b.Size     = new Size(SIZE, SIZE);
                    b.Location = new Point(start_x + (r.Xpos * SIZE), start_y + (r.Ypos * SIZE));
                    b.Text     = r.Symbol;
                    if (r.Faction == 3)
                    {
                        b.ForeColor = Color.Silver;
                    }
                    else
                    {
                        b.ForeColor = Color.Orange;
                    }

                    if (r.Death())
                    {
                        b.ForeColor = Color.Black;
                    }
                    b.Click += new EventHandler(Button_Click);
                    GBMap.Controls.Add(b);
                }

                else if (u.GetType() == typeof(Grubs))
                {
                    int begin_x, begin_y;
                    begin_x = GBMap.Location.X;
                    begin_y = GBMap.Location.Y;
                    Grubs  g = (Grubs)u;
                    Button b = new Button();
                    b.Size     = new Size(SIZE, SIZE);
                    b.Location = new Point(begin_x + (g.Xpos * SIZE), begin_y + (g.Ypos * SIZE));
                    b.Text     = g.Symbol;
                    if (g.Faction == 1)
                    {
                        b.ForeColor = Color.Green;
                    }

                    else if (g.Death())
                    {
                        b.ForeColor = Color.Black;
                    }
                    b.Click += new EventHandler(Button_Click);
                    GBMap.Controls.Add(b);
                }

                //else if (u.GetType() == typeof(deadshot))
                //{
                //    int begin_x, begin_y;
                //    begin_x = GBMap.Location.X;
                //    begin_y = GBMap.Location.Y;
                //    deadshot g = (deadshot)u;
                //    Button b = new Button();
                //    b.Size = new Size(SIZE, SIZE);
                //    b.Location = new Point(begin_x + (g.Xpos * SIZE), begin_y + (g.Ypos * SIZE));
                //    b.Text = g.Symbol;
                //    if (g.Faction == 4)
                //    {
                //        b.ForeColor = Color.LightBlue;
                //    }


                //    if (g.Death())
                //    {
                //        b.ForeColor = Color.Black;
                //    }
                //    b.Click += new EventHandler(Button_Click);
                //    GBMap.Controls.Add(b);
                //}

                //foreach (Building y in map.buildings)
                //{
                //    int begin_x, begin_y;
                //    begin_x = GBMap.Location.X;
                //    begin_y = GBMap.Location.Y;
                //    ResourceBuilding m = (ResourceBuilding)y;
                //    Button b = new Button();
                //    b.Size = new Size(SIZE, SIZE);
                //    b.Location = new Point(begin_x + (m.Xpos * SIZE), begin_y + (m.Ypos * SIZE));
                //    b.Text = m.Symbol;
                //    if (m.Faction == 2)
                //    {
                //        b.ForeColor = Color.Green;
                //    }
                //    else
                //    {
                //        b.ForeColor = Color.Orange;
                //    }

                //    if (m.isDestroyed())
                //    {
                //        b.ForeColor = Color.Black;
                //    }
                //    b.Click += new EventHandler(Button_Click);
                //    GBMap.Controls.Add(b);
                //}

                //else if (u.GetType() == typeof(FactoryBuilding))
                //{
                //    int start_x, start_y;
                //    start_x = GBMap.Location.X;
                //    start_y = GBMap.Location.Y;
                //    FactoryBuilding fb = (FactoryBuilding);
                //    Button b = new Button();
                //    b.Size = new Size(SIZE, SIZE);
                //    b.Location = new Point(start_x + (fb.Xpos * SIZE), start_y + (fb.Ypos * SIZE));
                //    b.Text = fb.Symbol;
                //    if (fb.Faction == 1)
                //    {
                //        b.ForeColor = Color.Green;
                //    }
                //    else
                //    {
                //        b.ForeColor = Color.Orange;
                //    }

                //    if (fb.isDestroyed())
                //    {
                //        b.ForeColor = Color.Black;
                //    }
                //    b.Click += new EventHandler(Button_Click);
                //    GBMap.Controls.Add(b);
                //}
            }
        }
예제 #7
0
        private void UpdateMap()
        {
            foreach (Unit u in map.Units)
            {
                if (u.GetType() == typeof(MeleeUnit))
                {
                    MeleeUnit m = (MeleeUnit)u;
                    if (m.Health < 5)
                    {
                        switch (R.Next(0, 5))
                        {
                        case 0: m.Move(Direction.North); break;

                        case 1: m.Move(Direction.West); break;

                        case 2: m.Move(Direction.South); break;

                        case 3: m.Move(Direction.East); break;
                        }
                    }
                    else
                    {
                        bool inCombat = false;
                        foreach (Unit e in map.Units)
                        {
                            if (u.Range(e))
                            {
                                u.Combat(e);
                                inCombat = true;
                            }
                        }
                        if (inCombat)
                        {
                            Unit c = m.Close(map.Units);
                            m.Move(m.Directionto(c));
                        }
                    }
                }
                else if (u.GetType() == typeof(RangesUnit))
                {
                    RangesUnit r = (RangesUnit)u;
                    if (r.Health < 20)
                    {
                        switch (R.Next(0, 4))
                        {
                        case 0: r.Move(Direction.North); break;

                        case 1: r.Move(Direction.West); break;

                        case 2: r.Move(Direction.South); break;

                        case 3: r.Move(Direction.East); break;
                        }
                    }
                    else
                    {
                        bool inCombat = false;
                        foreach (Unit e in map.Units)
                        {
                            if (u.Range(e))
                            {
                                u.Combat(e);
                                inCombat = true;
                            }
                        }
                        if (inCombat)
                        {
                            Unit c = r.Close(map.Units);
                            r.Move(r.Directionto(c));
                        }
                    }
                }
                else if (u.GetType() == typeof(Grubs))
                {
                    Grubs g = (Grubs)u;
                    if (g.Health < 20)
                    {
                        switch (R.Next(0, 4))
                        {
                        case 0: g.Move(Direction.North); break;

                        case 1: g.Move(Direction.West); break;

                        case 2: g.Move(Direction.South); break;

                        case 3: g.Move(Direction.East); break;
                        }
                    }
                    else
                    {
                        bool inCombat = false;
                        foreach (Unit e in map.Units)
                        {
                            if (u.Range(e))
                            {
                                u.Combat(e);
                                inCombat = true;
                            }
                        }
                        if (inCombat)
                        {
                            Unit c = g.Close(map.Units);
                            g.Move(g.Directionto(c));
                        }
                    }
                }

                //else if (u.GetType() == typeof(deadshot))
                //{
                //    deadshot ds = (deadshot)u;
                //    if (ds.Health < 20)
                //    {
                //        switch (R.Next(0, 4))
                //        {
                //            case 0: ds.Move(Direction.North); break;
                //            case 1: ds.Move(Direction.West); break;
                //            case 2: ds.Move(Direction.South); break;
                //            case 3: ds.Move(Direction.East); break;
                //        }
                //    }
                //    else
                //    {
                //        bool inCombat = false;
                //        foreach (Unit e in map.Units)
                //        {
                //            if (u.Range(e))
                //            {
                //                u.Combat(e);
                //                inCombat = true;

                //            }
                //        }
                //        if (inCombat)
                //        {
                //            Unit c = ds.Close(map.Units);
                //            ds.Move(ds.Directionto(c));
                //        }
                //    }

                //}
            }

            //foreach (Building y in map.buildings)
            //{
            //    if (y.GetType() == typeof(ResourceBuilding))
            //    {
            //        ResourceBuilding rb = (ResourceBuilding)y;


            //    }
            //}
        }