Exemplo n.º 1
0
Arquivo: Tank.cs Projeto: AJMuller/POE
    }     //works out if an object is out of health

    private int DistanceTo(Unit u)
    {
        if (u.GetType() == typeof(Melee_Unit))
        {
            Melee_Unit m = (Melee_Unit)u;
            int        d = Math.Abs(XPos - m.XPos) + Math.Abs(YPos - m.YPos);
            return(d);
        }    //end if
        else if (u.GetType() == typeof(Ranged_Unit))
        {
            Ranged_Unit m = (Ranged_Unit)u;
            int         d = Math.Abs(XPos - m.XPos) + Math.Abs(YPos - m.YPos);
            return(d);
        }    //end else if
        else if (u.GetType() == typeof(Tank))
        {
            Tank m = (Tank)u;
            int  d = Math.Abs(XPos - m.XPos) + Math.Abs(YPos - m.YPos);
            return(d);
        }    //end else
        else if (u.GetType() == typeof(Helicopter))
        {
            Helicopter m = (Helicopter)u;
            int        d = Math.Abs(XPos - m.XPos) + Math.Abs(YPos - m.YPos);
            return(d);
        }    //end else
        else
        {
            Fighter_Jets m = (Fighter_Jets)u;
            int          d = Math.Abs(XPos - m.XPos) + Math.Abs(YPos - m.YPos);
            return(d);
        } //end else
    }     //works out distance from one unit to another
Exemplo n.º 2
0
Arquivo: Tank.cs Projeto: AJMuller/POE
    }    // to string

    public Direction DirectionTo(Unit u)
    {
        if (u.GetType() == typeof(Melee_Unit))
        {
            Melee_Unit m = (Melee_Unit)u;
            if (m.XPos < XPos)
            {
                return(Direction.North);
            }    //end if
            else if (m.XPos > XPos)
            {
                return(Direction.South);
            }    //end else if
            else if (m.YPos < YPos)
            {
                return(Direction.West);
            }    //end else if
            else
            {
                return(Direction.East);
            } //end else
        }     //end if

        else if (u.GetType() == typeof(Ranged_Unit))
        {
            Ranged_Unit m = (Ranged_Unit)u;
            if (m.XPos < XPos)
            {
                return(Direction.North);
            }    //end if
            else if (m.XPos > XPos)
            {
                return(Direction.South);
            }    //end else if
            else if (m.YPos < YPos)
            {
                return(Direction.West);
            }    //end else if
            else
            {
                return(Direction.East);
            } //end else
        }     //end else if
        else if (u.GetType() == typeof(Tank))
        {
            Tank m = (Tank)u;
            if (m.XPos < XPos)
            {
                return(Direction.North);
            }    //end if
            else if (m.XPos > XPos)
            {
                return(Direction.South);
            }    //end else if
            else if (m.YPos < YPos)
            {
                return(Direction.West);
            }    //end else if
            else
            {
                return(Direction.East);
            } //end else
        }     //end else if
        else if (u.GetType() == typeof(Fighter_Jets))
        {
            Fighter_Jets m = (Fighter_Jets)u;
            if (m.XPos < XPos)
            {
                return(Direction.North);
            }    //end if
            else if (m.XPos > XPos)
            {
                return(Direction.South);
            }    //end else if
            else if (m.YPos < YPos)
            {
                return(Direction.West);
            }    //end else if
            else
            {
                return(Direction.East);
            } //end else
        }     //end else if
        else
        {
            Helicopter m = (Helicopter)u;
            if (m.XPos < XPos)
            {
                return(Direction.North);
            }    //end if
            else if (m.XPos > XPos)
            {
                return(Direction.South);
            }    //end else if
            else if (m.YPos < YPos)
            {
                return(Direction.West);
            }    //end else if
            else
            {
                return(Direction.East);
            } //end else
        }     //end else if
    }         // works out direction of movement
Exemplo n.º 3
0
Arquivo: Map.cs Projeto: AJMuller/POE
    public Map(int maxX, int maxY, int numUnits, int numBuildings)
    {
        units = new Unit[numUnits];
        int count = 0;

        for (int i = 0; i < numUnits / 5; i++)     // creates
        {
            Melee_Unit m = new Melee_Unit("knight", r.Next(0, maxX),
                                          r.Next(0, maxY),
                                          100,
                                          r.Next(5, 10),
                                          1,
                                          1,
                                          i % 2,
                                          "M");
            units[count] = m;
            count++;

            Ranged_Unit ranged = new Ranged_Unit("knight", r.Next(0, maxX),
                                                 r.Next(0, maxY),
                                                 100,
                                                 r.Next(5, 10),
                                                 1,
                                                 1,
                                                 i % 2,
                                                 "R");
            units[count] = ranged;
            count++;

            Tank t = new Tank("Cruiser", r.Next(0, maxX),
                              r.Next(0, maxY),
                              100,
                              r.Next(10, 20),
                              1,
                              1,
                              i % 2,
                              "T");
            units[count] = t;
            count++;

            Helicopter h = new Helicopter("Boeing", r.Next(0, maxX),
                                          r.Next(0, maxY),
                                          100,
                                          r.Next(10, 20),
                                          1,
                                          1,
                                          i % 2,
                                          "H");
            units[count] = h;
            count++;

            Fighter_Jets f = new Fighter_Jets("Boeing", r.Next(0, maxX),
                                              r.Next(0, maxY),
                                              100,
                                              r.Next(10, 20),
                                              1,
                                              1,
                                              i % 2,
                                              "J");
            units[count] = f;
            count++;
        }    //end for

        count     = 0;
        buildings = new Building[numBuildings];
        for (int i = 0; i < numBuildings / 4; i++)
        {
            FactoryBuilding fb = new FactoryBuilding
                                     (100, r.Next(0, maxX), r.Next(0, maxY), i % 2, "F");

            buildings[count] = fb;
            count++;

            ResourceBuilding rb = new ResourceBuilding
                                      (100, r.Next(0, maxX), r.Next(0, maxY), i % 2, "S");

            buildings[count] = rb;
            count++;

            Field_Hospital fh = new Field_Hospital
                                    (100, r.Next(0, maxX), r.Next(0, maxY), i % 2, "+");

            buildings[count] = fh;
            count++;

            Weapon_Upgrade wu = new Weapon_Upgrade
                                    (100, r.Next(0, maxX), r.Next(0, maxY), i % 2, "^^");

            buildings[count] = wu;
            count++;
        } //end for
    }     //makes objects and generates values for these objects
Exemplo n.º 4
0
Arquivo: Map.cs Projeto: AJMuller/POE
    }     //makes objects and generates values for these objects

    public void Read(int numUnits, int numBuildings)
    {
        int counter = 0;



        string[] stringArray = File.ReadAllLines("MeleeUnit.txt");
        units = new Unit[numUnits];

        foreach (string line in stringArray)
        {
            if (line != "")
            {
                Melee_Unit m = new Melee_Unit(line.Split(',')[0], Convert.ToInt32(line.Split(',')[2]),
                                              Convert.ToInt32(line.Split(',')[1]),
                                              Convert.ToInt32(line.Split(',')[3]),
                                              Convert.ToInt32(line.Split(',')[6]),
                                              Convert.ToInt32(line.Split(',')[5]),
                                              Convert.ToInt32(line.Split(',')[4]),
                                              Convert.ToInt32(line.Split(',')[7]),
                                              line.Split(',')[8]);
                counter++;
                units[counter - 1] = m;
            } //end if
        }     //end foreach


        string[] rstringArray = File.ReadAllLines("RangedUnit.txt");

        foreach (string line in rstringArray)
        {
            if (line != "")
            {
                Ranged_Unit m = new Ranged_Unit(line.Split(',')[0], Convert.ToInt32(line.Split(',')[2]),
                                                Convert.ToInt32(line.Split(',')[1]),
                                                Convert.ToInt32(line.Split(',')[3]),
                                                Convert.ToInt32(line.Split(',')[6]),
                                                Convert.ToInt32(line.Split(',')[5]),
                                                Convert.ToInt32(line.Split(',')[4]),
                                                Convert.ToInt32(line.Split(',')[7]),
                                                line.Split(',')[8]);
                counter++;
                units[counter - 1] = m;
            } //end if
        }     // end foreach

        string[] TtringArray = File.ReadAllLines("Tank.txt");

        foreach (string line in TtringArray)
        {
            if (line != "")
            {
                Tank m = new Tank(line.Split(',')[0], Convert.ToInt32(line.Split(',')[2]),
                                  Convert.ToInt32(line.Split(',')[1]),
                                  Convert.ToInt32(line.Split(',')[3]),
                                  Convert.ToInt32(line.Split(',')[6]),
                                  Convert.ToInt32(line.Split(',')[5]),
                                  Convert.ToInt32(line.Split(',')[4]),
                                  Convert.ToInt32(line.Split(',')[7]),
                                  line.Split(',')[8]);
                counter++;
                units[counter - 1] = m;
            } //end if
        }     // end foreach

        string[] hstringArray = File.ReadAllLines("Helicopter.txt");

        foreach (string line in hstringArray)
        {
            if (line != "")
            {
                Helicopter m = new Helicopter(line.Split(',')[0], Convert.ToInt32(line.Split(',')[2]),
                                              Convert.ToInt32(line.Split(',')[1]),
                                              Convert.ToInt32(line.Split(',')[3]),
                                              Convert.ToInt32(line.Split(',')[6]),
                                              Convert.ToInt32(line.Split(',')[5]),
                                              Convert.ToInt32(line.Split(',')[4]),
                                              Convert.ToInt32(line.Split(',')[7]),
                                              line.Split(',')[8]);
                counter++;
                units[counter - 1] = m;
            } //end if
        }     // end foreach

        string[] fjstringArray = File.ReadAllLines("Fighter_Jets.txt");

        foreach (string line in fjstringArray)
        {
            if (line != "")
            {
                Fighter_Jets m = new Fighter_Jets(line.Split(',')[0], Convert.ToInt32(line.Split(',')[2]),
                                                  Convert.ToInt32(line.Split(',')[1]),
                                                  Convert.ToInt32(line.Split(',')[3]),
                                                  Convert.ToInt32(line.Split(',')[6]),
                                                  Convert.ToInt32(line.Split(',')[5]),
                                                  Convert.ToInt32(line.Split(',')[4]),
                                                  Convert.ToInt32(line.Split(',')[7]),
                                                  line.Split(',')[8]);
                counter++;
                units[counter - 1] = m;
            } //end if
        }     // end foreach



        int bcounter = 0;

        string[] fbstringArray = File.ReadAllLines("FactoryBuilding.txt");
        buildings = new Building[numBuildings];
        foreach (string line in fbstringArray)
        {
            if (line != "")
            {
                FactoryBuilding m = new FactoryBuilding(Convert.ToInt32(line.Split(',')[1]),
                                                        Convert.ToInt32(line.Split(',')[2]),
                                                        Convert.ToInt32(line.Split(',')[3]),
                                                        Convert.ToInt32(line.Split(',')[4]),
                                                        line.Split(',')[5]);

                bcounter++;
                buildings[bcounter - 1] = m;
            } //end if
        }     //end foreach


        string[] rbstringArray = File.ReadAllLines("ResourceBuilding.txt");


        foreach (string line in rbstringArray)
        {
            if (line != "")
            {
                ResourceBuilding m = new ResourceBuilding(Convert.ToInt32(line.Split(',')[1]),
                                                          Convert.ToInt32(line.Split(',')[2]),
                                                          Convert.ToInt32(line.Split(',')[3]),
                                                          Convert.ToInt32(line.Split(',')[4]),
                                                          line.Split(',')[5]);

                bcounter++;
                buildings[bcounter - 1] = m;
            } //end if
        }     //end foreach

        string[] fhstringArray = File.ReadAllLines("Field_Hospital.txt");


        foreach (string line in fhstringArray)
        {
            if (line != "")
            {
                Field_Hospital m = new Field_Hospital(Convert.ToInt32(line.Split(',')[1]),
                                                      Convert.ToInt32(line.Split(',')[2]),
                                                      Convert.ToInt32(line.Split(',')[3]),
                                                      Convert.ToInt32(line.Split(',')[4]),
                                                      line.Split(',')[5]);

                bcounter++;
                buildings[bcounter - 1] = m;
            } //end if
        }     //end foreach

        string[] wustringArray = File.ReadAllLines("Weapon_Upgrade.txt");


        foreach (string line in wustringArray)
        {
            if (line != "")
            {
                Weapon_Upgrade m = new Weapon_Upgrade(Convert.ToInt32(line.Split(',')[1]),
                                                      Convert.ToInt32(line.Split(',')[2]),
                                                      Convert.ToInt32(line.Split(',')[3]),
                                                      Convert.ToInt32(line.Split(',')[4]),
                                                      line.Split(',')[5]);

                bcounter++;
                buildings[bcounter - 1] = m;
            } //end if
        }     //end foreach
    }         // reads from textfile and creates objects with the values from the textfile
Exemplo n.º 5
0
    public void SaveAll()
    {
        StreamWriter rstrm = File.CreateText("RangedUnit.txt");

        rstrm.Flush();
        rstrm.Close();
        StreamWriter mstrm = File.CreateText("MeleeUnit.txt");

        mstrm.Flush();
        mstrm.Close();
        StreamWriter ttrm = File.CreateText("Tank.txt");

        ttrm.Flush();
        ttrm.Close();
        StreamWriter htrm = File.CreateText("Helicopter.txt");

        htrm.Flush();
        htrm.Close();
        StreamWriter fjrm = File.CreateText("Fighter_Jets.txt");

        fjrm.Flush();
        fjrm.Close();
        StreamWriter fbstrm = File.CreateText("FactoryBuilding.txt");

        fbstrm.Flush();
        fbstrm.Close();
        StreamWriter rbstrm = File.CreateText("ResourceBuilding.txt");

        rbstrm.Flush();
        rbstrm.Close();
        StreamWriter fhstrm = File.CreateText("Field_Hospital.txt");

        fhstrm.Flush();
        fhstrm.Close();
        StreamWriter wustrm = File.CreateText("Weapon_Upgrade.txt");

        wustrm.Flush();
        wustrm.Close();

        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(Melee_Unit))
            {
                Melee_Unit m = (Melee_Unit)u;

                m.Save();
            }//end if
            else if (u.GetType() == typeof(Ranged_Unit))
            {
                Ranged_Unit m = (Ranged_Unit)u;

                m.Save();
            }//end else
            else if (u.GetType() == typeof(Tank))
            {
                Tank m = (Tank)u;

                m.Save();
            }//end else
            else if (u.GetType() == typeof(Helicopter))
            {
                Helicopter m = (Helicopter)u;

                m.Save();
            }//end else
            else if (u.GetType() == typeof(Fighter_Jets))
            {
                Fighter_Jets m = (Fighter_Jets)u;

                m.Save();
            } //end else
        }     //end foreach
        foreach (Building b in map.Buildings)
        {
            if (b.GetType() == typeof(FactoryBuilding))
            {
                FactoryBuilding f = (FactoryBuilding)b;

                f.Save();
            }//end if
            else if (b.GetType() == typeof(ResourceBuilding))
            {
                ResourceBuilding r = (ResourceBuilding)b;

                r.Save();
            }//end else
            else if (b.GetType() == typeof(Field_Hospital))
            {
                Field_Hospital r = (Field_Hospital)b;

                r.Save();
            }//end else
            else if (b.GetType() == typeof(Weapon_Upgrade))
            {
                Weapon_Upgrade r = (Weapon_Upgrade)b;

                r.Save();
            } //end else
        }     //end foreach
    }
Exemplo n.º 6
0
    private void DisplayMap()
    {
        GameObject[] unitList = GameObject.FindGameObjectsWithTag("unit");

        foreach (GameObject g in unitList)
        {
            Destroy(g);
        }

        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(Melee_Unit))
            {
                Melee_Unit m = (Melee_Unit)u;

                if (m.Faction == 1)
                {
                    Instantiate(redMelee, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                }//end if
                else
                {
                    Instantiate(blueMelee, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                }//end else
                if (m.IsDeath())
                {
                    Instantiate(death, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                } //end if
            }     //end if
            else if (u.GetType() == typeof(Ranged_Unit))
            {
                Ranged_Unit m = (Ranged_Unit)u;

                if (m.Faction == 1)
                {
                    Instantiate(redRanged, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                }//end if
                else
                {
                    Instantiate(blueRanged, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                }//end else
                if (m.IsDeath())
                {
                    Instantiate(death, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                } //end if
            }     //end else if
            else if (u.GetType() == typeof(Tank))
            {
                Tank m = (Tank)u;

                if (m.Faction == 1)
                {
                    Instantiate(redTank, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                }//end if
                else
                {
                    Instantiate(blueTank, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                }//end else
                if (m.IsDeath())
                {
                    Instantiate(death, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                } //end if
            }     //end else if
            else if (u.GetType() == typeof(Helicopter))
            {
                Helicopter m = (Helicopter)u;

                if (m.Faction == 1)
                {
                    Instantiate(redHeli, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                }//end if
                else
                {
                    Instantiate(blueHeli, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                }//end else
                if (m.IsDeath())
                {
                    Instantiate(death, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                } //end if
            }     //else if
            else if (u.GetType() == typeof(Fighter_Jets))
            {
                Fighter_Jets m = (Fighter_Jets)u;

                if (m.Faction == 1)
                {
                    Instantiate(redFighterJet, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                }//end if
                else
                {
                    Instantiate(blueFighterJet, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                }//end else
                if (m.IsDeath())
                {
                    Instantiate(death, new Vector2(m.XPos, m.YPos), Quaternion.identity);
                } //end if
            }     //end else if
        }         //end for each

        foreach (Building b in map.Buildings)
        {
            if (b.GetType() == typeof(FactoryBuilding))
            {
                FactoryBuilding fb = (FactoryBuilding)b;

                if (fb.Faction == 1)
                {
                    Instantiate(redFactory, new Vector2(fb.XPos, fb.YPos), Quaternion.identity);
                }//end if
                else
                {
                    Instantiate(blueFactory, new Vector2(fb.XPos, fb.YPos), Quaternion.identity);
                }//end else
                if (fb.IsDestroyed())
                {
                    Instantiate(death, new Vector2(fb.XPos, fb.YPos), Quaternion.identity);
                } //end if
            }     //end if
            else if (b.GetType() == typeof(ResourceBuilding))
            {
                ResourceBuilding rb = (ResourceBuilding)b;

                if (rb.Faction == 1)
                {
                    Instantiate(redSource, new Vector2(rb.XPos, rb.YPos), Quaternion.identity);
                }//end if
                else
                {
                    Instantiate(bluesource, new Vector2(rb.XPos, rb.YPos), Quaternion.identity);
                }//end else
                if (rb.IsDestroyed())
                {
                    Instantiate(death, new Vector2(rb.XPos, rb.YPos), Quaternion.identity);
                }
            }//end else if
            else if (b.GetType() == typeof(Field_Hospital))
            {
                Field_Hospital fh = (Field_Hospital)b;

                if (fh.Faction == 1)
                {
                    Instantiate(redHospital, new Vector2(fh.XPos, fh.YPos), Quaternion.identity);
                }//end if
                else
                {
                    Instantiate(blueHospital, new Vector2(fh.XPos, fh.YPos), Quaternion.identity);
                }//end else
                if (fh.IsDestroyed())
                {
                    Instantiate(death, new Vector2(fh.XPos, fh.YPos), Quaternion.identity);
                }
            }//end else if
            else if (b.GetType() == typeof(Weapon_Upgrade))
            {
                Weapon_Upgrade wu = (Weapon_Upgrade)b;

                if (wu.Faction == 1)
                {
                    Instantiate(redUpgrade, new Vector2(wu.XPos, wu.YPos), Quaternion.identity);
                }//end if
                else
                {
                    Instantiate(blueUpgrade, new Vector2(wu.XPos, wu.YPos), Quaternion.identity);
                }//end else
                if (wu.IsDestroyed())
                {
                    Instantiate(death, new Vector2(wu.XPos, wu.YPos), Quaternion.identity);
                } //end if
            }     //end else if
        }         //end foreach
    }             // creates new buttons for every unit and building saved in the arrays. each button is made to match the type of unit or building it is by changing colours and letters displayed on it.
Exemplo n.º 7
0
    }             // creates new buttons for every unit and building saved in the arrays. each button is made to match the type of unit or building it is by changing colours and letters displayed on it.

    private void UpdateMap()
    {
        int distancebuild;

        foreach (Building b in map.Buildings)
        {
            if (b.GetType() == typeof(ResourceBuilding))
            {
                ResourceBuilding rb = (ResourceBuilding)b;
                foreach (Unit e in map.Units)
                {
                    if (e.GetType() == typeof(Melee_Unit))
                    {
                        Melee_Unit m = (Melee_Unit)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Ranged_Unit))
                    {
                        Ranged_Unit m = (Ranged_Unit)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Fighter_Jets))
                    {
                        Fighter_Jets m = (Fighter_Jets)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Helicopter))
                    {
                        Helicopter m = (Helicopter)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Tank))
                    {
                        Tank m = (Tank)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                }
            }
            else if (b.GetType() == typeof(FactoryBuilding))
            {
                FactoryBuilding rb = (FactoryBuilding)b;
                foreach (Unit e in map.Units)
                {
                    if (e.GetType() == typeof(Melee_Unit))
                    {
                        Melee_Unit m = (Melee_Unit)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Ranged_Unit))
                    {
                        Ranged_Unit m = (Ranged_Unit)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Fighter_Jets))
                    {
                        Fighter_Jets m = (Fighter_Jets)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Helicopter))
                    {
                        Helicopter m = (Helicopter)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Tank))
                    {
                        Tank m = (Tank)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                }
            }
            if (b.GetType() == typeof(Field_Hospital))
            {
                Field_Hospital rb = (Field_Hospital)b;
                foreach (Unit e in map.Units)
                {
                    if (e.GetType() == typeof(Melee_Unit))
                    {
                        Melee_Unit m = (Melee_Unit)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Ranged_Unit))
                    {
                        Ranged_Unit m = (Ranged_Unit)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Fighter_Jets))
                    {
                        Fighter_Jets m = (Fighter_Jets)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Helicopter))
                    {
                        Helicopter m = (Helicopter)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Tank))
                    {
                        Tank m = (Tank)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                }
            }
            if (b.GetType() == typeof(Weapon_Upgrade))
            {
                Weapon_Upgrade rb = (Weapon_Upgrade)b;
                foreach (Unit e in map.Units)
                {
                    if (e.GetType() == typeof(Melee_Unit))
                    {
                        Melee_Unit m = (Melee_Unit)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Ranged_Unit))
                    {
                        Ranged_Unit m = (Ranged_Unit)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Fighter_Jets))
                    {
                        Fighter_Jets m = (Fighter_Jets)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Helicopter))
                    {
                        Helicopter m = (Helicopter)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                    else if (e.GetType() == typeof(Tank))
                    {
                        Tank m = (Tank)e;


                        distancebuild = Math.Abs(rb.XPos - m.XPos) + Math.Abs(rb.YPos - m.YPos);

                        if (distancebuild <= m.AttackRange)
                        {
                            rb.Fight(m.Attack);
                        }
                    }
                }
            }
        }

        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(Melee_Unit))
            {
                Melee_Unit m = (Melee_Unit)u;

                if (m.Health < 25)
                {
                    switch (r.Next(0, 4))
                    {
                    case 0: m.MovePos(Direction.North); break;

                    case 1: m.MovePos(Direction.East); break;

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

                    case 3: m.MovePos(Direction.West); break;
                    } //end switch
                }     //end if
                else
                {
                    bool inCombat = false;
                    foreach (Unit e in map.Units)
                    {
                        if (m.WithinRange(e))
                        {
                            m.Fight(e);
                            inCombat = true;
                        } //end if
                    }     //end foreach
                    if (!inCombat)
                    {
                        Unit c = m.NearestUnit(map.Units);
                        m.MovePos(m.DirectionTo(c));
                    } //end if
                }     //end else
            }         //end if
            else if (u.GetType() == typeof(Ranged_Unit))
            {
                Ranged_Unit m = (Ranged_Unit)u;
                if (m.IsDeath())
                {
                    m.Symbol = "D";
                }//end if
                if (m.Health < 25)
                {
                    switch (r.Next(0, 4))
                    {
                    case 0: m.MovePos(Direction.North); break;

                    case 1: m.MovePos(Direction.East); break;

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

                    case 3: m.MovePos(Direction.West); break;
                    } //end switch
                }     //end if
                else
                {
                    bool inCombat = false;
                    foreach (Unit e in map.Units)
                    {
                        if (m.WithinRange(e))
                        {
                            m.Fight(e);
                            inCombat = true;
                        } //end if
                    }     //end foreach
                    if (!inCombat)
                    {
                        Unit c = m.NearestUnit(map.Units);
                        m.MovePos(m.DirectionTo(c));
                    } //end if
                }     //end else
            }         //end else if
            else if (u.GetType() == typeof(Tank))
            {
                Tank m = (Tank)u;
                if (m.IsDeath())
                {
                    m.Symbol = "D";
                }//end if
                if (m.Health < 25)
                {
                    switch (r.Next(0, 4))
                    {
                    case 0: m.MovePos(Direction.North); break;

                    case 1: m.MovePos(Direction.East); break;

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

                    case 3: m.MovePos(Direction.West); break;
                    } //end switch
                }     //end if
                else
                {
                    bool inCombat = false;
                    foreach (Unit e in map.Units)
                    {
                        if (m.WithinRange(e))
                        {
                            m.Fight(e);
                            inCombat = true;
                        } //end if
                    }     //end foreach
                    if (!inCombat)
                    {
                        Unit c = m.NearestUnit(map.Units);
                        m.MovePos(m.DirectionTo(c));
                    } //end if
                }     //end else
            }         //end else if
            else if (u.GetType() == typeof(Fighter_Jets))
            {
                Fighter_Jets m = (Fighter_Jets)u;
                if (m.IsDeath())
                {
                    m.Symbol = "D";
                }//end if
                if (m.Health < 25)
                {
                    switch (r.Next(0, 4))
                    {
                    case 0: m.MovePos(Direction.North); break;

                    case 1: m.MovePos(Direction.East); break;

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

                    case 3: m.MovePos(Direction.West); break;
                    } //end switch
                }     //end if
                else
                {
                    bool inCombat = false;
                    foreach (Unit e in map.Units)
                    {
                        if (m.WithinRange(e))
                        {
                            m.Fight(e);
                            inCombat = true;
                        } //end if
                    }     //end foreach
                    if (!inCombat)
                    {
                        Unit c = m.NearestUnit(map.Units);
                        m.MovePos(m.DirectionTo(c));
                    } //end if
                }     //end else
            }         //end else if
            else if (u.GetType() == typeof(Helicopter))
            {
                Helicopter m = (Helicopter)u;
                if (m.IsDeath())
                {
                    m.Symbol = "D";
                }//end if
                if (m.Health < 25)
                {
                    switch (r.Next(0, 4))
                    {
                    case 0: m.MovePos(Direction.North); break;

                    case 1: m.MovePos(Direction.East); break;

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

                    case 3: m.MovePos(Direction.West); break;
                    } //end switch
                }     //end if
                else
                {
                    bool inCombat = false;
                    foreach (Unit e in map.Units)
                    {
                        if (m.WithinRange(e))
                        {
                            m.Fight(e);
                            inCombat = true;
                        } //end if
                    }     //end foreach
                    if (!inCombat)
                    {
                        Unit c = m.NearestUnit(map.Units);
                        m.MovePos(m.DirectionTo(c));
                    } //end if
                }     //end else
            }         //end else if
        }             //end foreach
    }                 // updates the map by chaging values of units. calls movement methods and fight methods to change values in order for the map to change.
Exemplo n.º 8
0
    private void OnMouseDown()
    {
        //bool Found = false;
        string information = "";

        int x = (int)this.transform.position.x;
        int y = (int)this.transform.position.y;

        foreach (Unit u in poe_rts.map.Units)
        {
            if (u.GetType() == typeof(Melee_Unit))
            {
                Melee_Unit m = (Melee_Unit)u;

                if ((m.XPos == x) && (m.YPos == y))
                {
                    //Found = true;
                    information = m.ToString();
                }
            }
            else if (u.GetType() == typeof(Ranged_Unit))
            {
                Ranged_Unit m = (Ranged_Unit)u;

                if ((m.XPos == x) && (m.YPos == y))
                {
                    //Found = true;
                    information = m.ToString();
                }
            }
            else if (u.GetType() == typeof(Fighter_Jets))
            {
                Fighter_Jets m = (Fighter_Jets)u;

                if ((m.XPos == x) && (m.YPos == y))
                {
                    //Found = true;
                    information = m.ToString();
                }
            }
            else if (u.GetType() == typeof(Tank))
            {
                Tank m = (Tank)u;

                if ((m.XPos == x) && (m.YPos == y))
                {
                    //Found = true;
                    information = m.ToString();
                }
            }
            else if (u.GetType() == typeof(Helicopter))
            {
                Helicopter m = (Helicopter)u;

                if ((m.XPos == x) && (m.YPos == y))
                {
                    //Found = true;
                    information = m.ToString();
                }
            }
        }

        foreach (Building b in poe_rts.map.Buildings)
        {
            if (b.GetType() == typeof(FactoryBuilding))
            {
                FactoryBuilding m = (FactoryBuilding)b;

                if ((m.XPos == x) && (m.YPos == y))
                {
                    information = m.ToString();
                }
            }
            else if (b.GetType() == typeof(ResourceBuilding))
            {
                ResourceBuilding m = (ResourceBuilding)b;

                if ((m.XPos == x) && (m.YPos == y))
                {
                    information = m.ToString();
                }
            }
            else if (b.GetType() == typeof(Field_Hospital))
            {
                Field_Hospital m = (Field_Hospital)b;

                if ((m.XPos == x) && (m.YPos == y))
                {
                    information = m.ToString();
                }
            }
            else if (b.GetType() == typeof(Weapon_Upgrade))
            {
                Weapon_Upgrade m = (Weapon_Upgrade)b;

                if ((m.XPos == x) && (m.YPos == y))
                {
                    information = m.ToString();
                }
            }
        }



        healthText.text = information;
    }