Exemplo n.º 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);
        }
Exemplo n.º 2
0
        private void HandleMovement(ArenaPlayer player, Vector2 target)
        {
            Vector2 destination = player.Position + target;

            if (!(GameLogic.IsValidMovement(destination, _map.Grid)))
            {
                throw new Exception("Invalid movement");
            }

            if (IsLighthouse(destination))
            {
                player.Keys.Add(destination);
            }

            player.Position = destination;
        }
Exemplo n.º 3
0
        private void Turn(ArenaPlayer player)
        {
            ITurnState state = new TurnState()
            {
                Energy      = player.Energy,
                Lighthouses = this._lighthouses,
                Position    = player.Position
            };

            Stopwatch decisionTime = new Stopwatch();

            decisionTime.Restart();
            IDecision decision = player.Play(state);

            decisionTime.Stop();

            player.OperationTime.Add(decisionTime.ElapsedMilliseconds);


            switch (decision.Action)
            {
            case PlayerActions.Move:
                HandleMovement(player, decision.Target);
                break;

            case PlayerActions.Attack:
                HandleAttack(player, decision.Energy.Value);
                break;

            //case PlayerActions.Connect:
            //    HandleConnect(player, decision.Target);
            //    break;
            case PlayerActions.Pass:
                HandlePass(player);
                break;
            }

            Renderer.Render(this._map, this._players, this._lighthouses);
        }
Exemplo n.º 4
0
        private void SetupPlayers(IEnumerable <IPlayer> players)
        {
            List <ArenaPlayer> playerList = new List <ArenaPlayer>();

            int counter = 0;

            foreach (IPlayer player in players)
            {
                ArenaPlayer arenaPlayer = new ArenaPlayer(player.Name);

                PlayerConfig playerConfig = CreatePlayerConfig(counter, player, players.Count());

                arenaPlayer.Setup(playerConfig);
                arenaPlayer.PlayerDCI = playerConfig.PlayerDCI;

                player.Setup(playerConfig);

                playerList.Add(arenaPlayer);
                counter++;
            }

            this._players = playerList;
        }
Exemplo n.º 5
0
 private void HandlePass(ArenaPlayer player)
 {
     //Nothing changes, for now...
 }