Пример #1
0
 public void SimulateOneTick()
 {
     foreach (var unit in AllUnits.ToArray())// makes copy
     {
         unit.SimulateOneTick();
     }
 }
Пример #2
0
    private void Start()
    {
        velocity = new Vector2(Random.Range(0.01f, 0.1f), Random.Range(0.01f, 0.1f));
        location = new Vector2(this.gameObject.transform.position.x, this.gameObject.transform.position.y);

        unitMgr = manager.GetComponent <AllUnits>();
    }
Пример #3
0
 public static void RemoveUnit(UnitTypesEnum unitTypesEnum, UnitBase unit)
 {
     if (UnitsDictionary.TryGetValue(unitTypesEnum, out List <UnitBase> items))
     {
         items.Remove(unit);
     }
     AllUnits.Remove(unit);
 }
Пример #4
0
        /// <summary>
        /// Commands a unit
        /// </summary>
        /// <param name="cmd"></param>
        public void CommandUnit(UnitCommand cmd)
        {
            ConsoleManager.Instance.WriteLine($"Commanded {AllUnits.Find(u => u.InstanceID == cmd.UnitInstanceID).Name} - {cmd.CommandID}");
            Packet p = new Packet((int)PacketHeader.UnitCommand, cmd);

            SelectedCommand = UnitCommandID.UNITCMD_NULL;
            client.SendData(p);
        }
Пример #5
0
        // parses a packet with the header UnitRemoved
        private void ParseUnitRemoved(Packet p)
        {
            int          unitInstanceID = (int)p.Item;
            UnitInstance unit           = AllUnits.Find(u => u.InstanceID == unitInstanceID);

            AllUnits.Remove(unit);
            UpdateCache();
            ConsoleManager.Instance.WriteLine($"Removed unit {unit.InstanceID}:{unit.UnitID}:{unit.Name}");
            OnUnitsUpdated(new UnitListEventArgs(AllUnits));
        }
Пример #6
0
        // parses a packet with the header UnitAdded
        private void ParseUnitAdded(Packet p)
        {
            UnitInstance unit = (UnitInstance)p.Item;

            DataManager.Unit.Reconstruct(unit);
            AllUnits.Add(unit);
            UpdateCache();
            ConsoleManager.Instance.WriteLine($"Added a unit {unit.InstanceID}:{unit.UnitID}:{unit.Name}");
            OnUnitsUpdated(new UnitListEventArgs(AllUnits));
        }
Пример #7
0
 public UnitDefinition Resolve(UnitReference unitReference)
 {
     try
     {
         return(AllUnits.Single(unit => unit == unitReference));
     }
     catch (InvalidOperationException)
     {
         throw new UnitNotFoundException(this, unitReference);
     }
 }
Пример #8
0
 public void AddUnit(UnitTypesEnum unitTypesEnum, UnitBase unit)
 {
     if (UnitsDictionary.TryGetValue(unitTypesEnum, out List <UnitBase> items))
     {
         items.Add(unit);
     }
     else
     {
         items = new List <UnitBase>();
         UnitsDictionary[unitTypesEnum] = items;
         items.Add(unit);
     }
     AllUnits.Add(unit);
 }
Пример #9
0
        public static (int fullyFinishedRounds, int totalHitpoints, bool anyElfDied) ProcessGame(string pathToInputFile, int elvesAttackPower = 3)
        {
            var      lines = File.ReadAllLines(pathToInputFile);
            Day15Map game  = new Day15Map(lines[0].Length, lines.Length);

            for (int y = 0; y < lines.Length; y++)
            {
                var line = lines[y];
                for (int x = 0; x < line.Length; x++)
                {
                    switch (line[x])
                    {
                    case '#':
                        game.Set(x, y);
                        break;

                    case 'G':
                        game.AddUnit(new Day15Unit(Day15UnitType.Goblin, new Point(x, y), 3));
                        break;

                    case 'E':
                        game.AddUnit(new Day15Unit(Day15UnitType.Elf, new Point(x, y), elvesAttackPower));
                        break;
                    }
                }
            }

            int elvesonTheBattleField = game.AllUnits.Where(x => x.Type == Day15UnitType.Elf).Count();

            int roundCounter = 0;

            PrintAndWait();
            while (!game.MakeARound())
            {
                roundCounter++;
                PrintAndWait();
            }

            PrintAndWait();

            void PrintAndWait()
            {
                //game.Print();
                //Console.WriteLine(roundCounter);
                //Console.ReadLine();
            }

            return(roundCounter, game.AllUnits.Sum(x => x.hitPoints), elvesonTheBattleField != game.AllUnits.Where(x => x.Type == Day15UnitType.Elf).Count());
        }
Пример #10
0
        // parses a packet with the header UnitUpdate
        private void ParseUnitUpdate(Packet p)
        {
            UnitInstance unit    = (UnitInstance)p.Item;
            UnitInstance oldUnit = AllUnits.Find(u => u.InstanceID == unit.InstanceID);

            if (!AllUnits.Remove(oldUnit))
            {
                return;
            }
            DataManager.Unit.Reconstruct(unit);
            AllUnits.Add(unit);
            UpdateCache();
            ConsoleManager.Instance.WriteLine($"Updated unit {unit.InstanceID}:{unit.UnitID}:{unit.Name}");
            OnUnitsUpdated(new UnitListEventArgs(AllUnits));
        }
Пример #11
0
    // Use this for initialization
    void Start()
    {
        collider   = GetComponent <Collider2D>();
        canJump    = true;
        allUnits   = FindObjectOfType <AllUnits>();
        unitConfig = FindObjectOfType <UnitConfig>();
        unitHolder = FindObjectOfType <UnitHolder>();

        rigidbody2D = GetComponent <Rigidbody2D>();

        gravity = unitConfig.gravity;

        position = transform.position;
        velocity = new Vector2(Random.Range(-1, 1), Random.Range(-1, 1));
    }
Пример #12
0
    public void saveGameData()
    {
        // Fill in allUnits class using data from unitManagerScript
        GameObject unitsData = GameObject.Find("UnitsData");
        UnitManager unitManagerScript = unitsData.GetComponent<UnitManager>();
        TileManager tileManagerScript = unitsData.GetComponent<TileManager>();
        AllUnits allUnits = new AllUnits();
        allUnits.allPlayerUnits = unitManagerScript.allPlayerUnits;
        allUnits.allEnemyUnits = unitManagerScript.allEnemyUnits;
        allUnits.allMapTiles = VectorToCustom(tileManagerScript.MapTiles);

        BinaryFormatter bf = new BinaryFormatter();
        FileStream file = File.Create(Application.persistentDataPath + "/gamesave.dat");
        bf.Serialize(file, allUnits);
        file.Close();

        // Set PlayerPrefs saved flag to enable continue button on start menu
        PlayerPrefs.SetInt("saves", 1);
        print("Saved data.");
    }
Пример #13
0
    private void Start()
    {
        unitManager = FindObjectOfType <AllUnits>();
        if (unitManager == null)
        {
            Debug.LogWarning("AllUnits 컴포넌트를 가진 오브젝트가 없습니다.");
        }
        else
        {
            isStarted = true;
        }

        if (isStarted)
        {
            for (int i = 0; i < unitGenDescs.Length; i++)
            {
                unitGenDescs[i].elapsedTime = 0;
                unitGenDescs[i].isStarted   = false;
            }
        }
    }
Пример #14
0
        // parses a packet with the header LobbyStartGame
        private void ParseLobbyStartGame(Packet p)
        {
            int i = 0;

            Board = (Board)p.Items[i++];

            CachedBoard = new Tile[Board.DimY][];
            for (int y = 0; y < CachedBoard.Length; y++)
            {
                CachedBoard[y] = new Tile[Board.DimX];
            }

            Player              = (Player)p.Items[i++];
            Cities              = (List <City>)p.Items[i++];
            AllUnits            = (List <UnitInstance>)p.Items[i++];
            _selectedCityID     = -1;
            _selectedUnitID     = AllUnits.Find(u => u.PlayerID == Player.InstanceID).InstanceID;
            _lastSelectedUnitID = _selectedUnitID;
            TurnState           = TurnState.Begin;
            ConsoleManager.Instance.WriteLine("The host has started the game");
            SceneManager.Instance.ChangeScene((int)Scene.Game);
        }
Пример #15
0
    public Fleet CreateFleet(List <Unit> _Units, string _Owner, string _Name)
    {
        var obj    = new GameObject();
        var _fleet = obj.AddComponent <Fleet> ();

        _fleet.Owner           = _Owner;
        _fleet.Name            = _Name;
        _fleet.gameObject.name = "[Fleet] " + _Name;


        foreach (var unit in _Units)
        {
            var newUnit = Instantiate(unit);
            newUnit.gameObject.SetActive(false);
            newUnit.gameObject.transform.SetParent(_fleet.transform);
            newUnit.state = new UnitState(newUnit, _Owner);
            _fleet.Units.Add(newUnit);
            AllUnits.Add(newUnit);
            VisibleUnits.Add(newUnit);
        }
        _fleet.SortBySize();

        return(_fleet);
    }
Пример #16
0
 public void Compile()
 {
     AllUnits.ForEach(unit => unit.Stage1RoutineStubs());
     AllUnits.ForEach(unit => unit.Stage2RoutineBody());
 }
Пример #17
0
 private void Awake()
 {
     Instance = this;
 }
Пример #18
0
 /// <summary>
 /// Returns a list of all the units this client controls
 /// </summary>
 /// <returns></returns>
 public List <UnitInstance> GetMyUnits()
 {
     return(AllUnits.FindAll(u => u.PlayerID == Player.InstanceID));
 }
Пример #19
0
        /// <summary>
        /// OnGUI is called for rendering and handling GUI events.
        /// This means that your OnGUI implementation might be called several times per frame (one call per event).
        /// For more information on GUI events see the Event reference. If the MonoBehaviour's enabled property is
        /// set to false, OnGUI() will not be called.
        /// </summary>
        public void OnGUI()
        {
            GUI.skin = guiSkin;

            if (useOldUI == true)
            {
                // Build a list of buttons for the units selected for battle
                for (indexA = 0; indexA < buildList.Length; indexA++)
                {
                    if (indexA < maxUnits)
                    {
                        if (!buildList[indexA])
                        {
                            // If there is no unit at this tile, keep it empty
                            GUI.Box(new Rect(indexA * buttonSize.x, 0, buttonSize.x, buttonSize.y), string.Empty);
                        }
                        else if (GUI.Button(new Rect(indexA * buttonSize.x, 0, buttonSize.x, buttonSize.y), buildList[indexA].GetComponent <Building>().icon))
                        {
                            AllUnits unit = allUnits[buildList[indexA].GetComponent <Building>().listIndex];

                            // If there is a unit on this tile, and it's not essential, remove it from the list of units to be used in this battle
                            if (unit.essential == false)
                            {
                                if (GetComponent <AudioSource>())
                                {
                                    GetComponent <AudioSource>().Play();
                                }

                                // Assign the unit from the unit battle list back to the unit selection grid
                                unit.unit = buildList[indexA];

                                // Clear the unit from the unit battle list
                                buildList[indexA] = null;

                                selectedUnits--;
                            }
                        }
                    }
                }

                GUI.Label(new Rect((Screen.width - 400) * 0.5f, positionAndSize.y - 30, 400, 50), Application.loadedLevelName + " - SELECT YOUR UNITS");

                // Build a grid of buttons for the selectable units
                for (indexA = 0; indexA < grid.y; indexA++)
                {
                    for (indexB = 0; indexB < grid.x; indexB++)
                    {
                        if (indexC < allUnits.Length)
                        {
                            if (allUnits[indexC].unit)
                            {
                                // If there is a unit on this tile, add it to the list of units to be used in this battle
                                if (GUI.Button(new Rect(positionAndSize.x + indexB * tileSize.x, positionAndSize.y + indexA * tileSize.y, tileSize.x, tileSize.y), allUnits[indexC].unit.GetComponent <Building>().icon))
                                {
                                    // Go through the tiles in the unit list, and add the selected unit to the next empty slot
                                    for (int unitIndex = 0; unitIndex < buildList.Length; unitIndex++)
                                    {
                                        if (buildList[unitIndex] == null && allUnits[indexC].unit)
                                        {
                                            if (GetComponent <AudioSource>())
                                            {
                                                GetComponent <AudioSource>().Play();
                                            }

                                            AddUnit(indexC);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                // If there is no unit in this slot, keep it empty
                                GUI.Box(new Rect(positionAndSize.x + indexB * tileSize.x, positionAndSize.y + indexA * tileSize.y, tileSize.x, tileSize.y), string.Empty);
                            }
                        }
                        else
                        {
                            // If there is no unit in this slot, keep it empty
                            GUI.Box(new Rect(positionAndSize.x + indexB * tileSize.x, positionAndSize.y + indexA * tileSize.y, tileSize.x, tileSize.y), string.Empty);
                        }

                        indexC++;
                    }
                }

                indexC = 0;

                //A "ready to begin" button
                if (GUI.Button(new Rect((Screen.width - 300) * 0.5f, positionAndSize.y + indexA * tileSize.y, 300, 50), "Ready To Begin!"))
                {
                    StartGame();
                }

                //This button returns to the main menu
                if (GUI.Button(new Rect((Screen.width - 300) * 0.5f, Screen.height - 60, 300, 50), "Back To Menu"))
                {
                    if (GetComponent <AudioSource>())
                    {
                        GetComponent <AudioSource>().Play();
                    }

                    Application.LoadLevel("StartMenu");
                }
            }
        }