Пример #1
0
        private void HandleAttack(ArenaPlayer player, int energy)
        {
            Vector2 target = player.Position;

            if (!IsLighthouse(target))
            {
                throw new Exception("Invalid target");
            }

            if (player.Energy < energy)
            {
                energy = player.Energy;
            }

            Lighthouse lighthouse = this._lighthouses.Where(x => x.Position == target).Single();

            if (energy > lighthouse.Energy)
            {
                if (_players.Where(x => x.Lighthouses.Contains(lighthouse)).Any())
                {
                    ArenaPlayer oldOwner = _players.Where(x => x.Lighthouses.Contains(lighthouse)).Single();
                    oldOwner.Lighthouses.Remove(lighthouse);
                }
                player.Lighthouses.Add(lighthouse);
                lighthouse.Owner = player;
            }

            player.Energy     = player.Energy - energy;
            lighthouse.Energy = Math.Abs(lighthouse.Energy - energy);
        }
Пример #2
0
        private void SetupLighthouses(List <Vector2> lighthousePositions)
        {
            this._lighthouses = new List <Lighthouse>();

            foreach (Vector2 lighthousePosition in lighthousePositions)
            {
                Lighthouse lighthouse = new Lighthouse()
                {
                    Position = lighthousePosition,
                };

                _lighthouses.Add(lighthouse);
            }
        }