예제 #1
0
파일: POE_RTS.cs 프로젝트: AJMuller/POE
    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.
예제 #2
0
파일: POE_RTS.cs 프로젝트: AJMuller/POE
    }             // 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.