Beispiel #1
0
        // Makes class construction more simple and flexable
        public void AddSubmodel(IBsSubModel subModel)
        {
            if (subModel is IBsHealth)
            {
                _health = (IBsHealth)subModel;
            }

            if (subModel is IBsHealer)
            {
                _healer = (IBsHealer)subModel;
            }

            if (subModel is IBsAttacker)
            {
                _attacker = (IBsAttacker)subModel;
            }

            if (subModel is IBsBoard2D)
            {
                _board = (IBsBoard2D)subModel;
            }

            if (subModel is IBsLevels)
            {
                _levels = (IBsLevels)subModel;
            }

            if (subModel is IBsFactions)
            {
                _factions = (IBsFactions)subModel;
            }

            if (subModel is IBsFactioner)
            {
                _factioner = (IBsFactioner)subModel;
            }

            if (subModel is IBsRange)
            {
                _range = (IBsRange)subModel;
            }

            if (subModel is IMover)
            {
                _mover = (IMover)subModel;
            }
        }
Beispiel #2
0
        public void SetBoard(IBsBoard2D board)
        {
            Clear();
            _actors.Clear();
            _tileViews.Clear();
            _actors.Clear();
            _board = board;
            if (board.Width() == 0)
            {
                throw new Exception("Board width should be greater than 0");
            }

            var slotId = 0;

            for (int y = 0; y < board.Height(); y++)
            {
                for (int x = 0; x < board.Width(); x++)
                {
                    var view = Instantiate <SpriteRenderer>(TilePref, new Vector3(x, y, 0), Quaternion.identity);
                    view.transform.SetParent(TilesContainer, false);
                    _tileViews.Add(view);

                    var actor = board.Actor(slotId);
                    if (actor != null)
                    {
                        var actorView = Instantiate <SpriteRenderer>(ActorPref, ActorsContainer);
                        actorView.transform.position = view.transform.position;
                        _actors[actor] = new ActorsData {
                            View = actorView, SlotId = slotId
                        };
                    }

                    slotId++;
                }
            }
        }