Пример #1
0
        private void HandleUnitMovement(GameTime gameTime)
        {
            if (_nextAlliedUnitToMove != null)
            {
                _timeSinceLastFlash += (float)gameTime.ElapsedGameTime.TotalSeconds;

                if (_timeSinceLastFlash > 0.2f)
                {
                    _unitFlash++;
                    _timeSinceLastFlash = 0;

                    if (_unitFlash > NumberOfFlashes * 2)
                    {
                        var lCoordinates = _nextAlliedUnitToMove.GetNextWaypoint(_nextAlliedUnitToMove.Col, _nextAlliedUnitToMove.Row);
                        if (lCoordinates == null)
                        {
                            // we are at the destination already
                            _nextAlliedUnitToMove = null;
                            return;
                        }

                        if (IsCellBlocked(_nextAlliedUnitToMove, lCoordinates.Col, lCoordinates.Row))
                        {
                            _units.PlayerCheckForPossibleAttack(_nextAlliedUnitToMove, _alliedEnemyMatrix);

                            _nextAlliedUnitToMove = null;
                            if (_nextAlliedUnitToMove != null)
                            {
                                _nextAlliedUnitToMove.ClearPath();                                 //TODO: for now, we don't want _units to continue automatically the next turn.
                            }
                            return;
                        }

                        //_log.Debug($"HandleUnitMovement() Unit:{_nextAlliedUnitToMove.UnitNumber} before:" + _nextAlliedUnitToMove.Col + "," + _nextAlliedUnitToMove.Row);

                        _nextAlliedUnitToMove.Movement -= _terrainMap[_nextAlliedUnitToMove.Col, _nextAlliedUnitToMove.Row].GroundUnitTerrainModifier;

                        // move to the next dest
                        PlayerMoveUnit(_nextAlliedUnitToMove, lCoordinates.Col, lCoordinates.Row);

                        //_log.Debug($"HandleUnitMovement() After:" + _nextAlliedUnitToMove.Col + "," + _nextAlliedUnitToMove.Row);

                        // ran out of moves this turn.  Stop.
                        if (_nextAlliedUnitToMove.Movement < 0.1)
                        {
                            _units.PlayerCheckForPossibleAttack(_nextAlliedUnitToMove, _alliedEnemyMatrix);

                            _nextAlliedUnitToMove = null;
                            if (_nextAlliedUnitToMove != null)
                            {
                                _nextAlliedUnitToMove.ClearPath();                                 //TODO: for now, we don't want _units to continue automatically the next turn.
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        private void HandleEnemyUnitMove(bool visible)
        {
            _log.Debug($"HandleEnemyUnitMove() set new coords from:{NextEnemyUnitToMove.Coordinates} movement={NextEnemyUnitToMove.Movement} [unit:{NextEnemyUnitToMove.UnitNumber}]");

            if (NextEnemyUnitMoveCoords != null)
            {
                if (_units.IsUnitWithinAttackRange(NextEnemyUnitToMove, _alliedEnemyMatrix))
                {
                    NextEnemyUnitToMove.ClearPath();
                    NextEnemyUnitToMove.Movement = 0;
                    NextEnemyUnitToMove.Flash    = null;
                    //_units.PlayerCheckForPossibleAttack(NextEnemyUnitToMove, _alliedEnemyMatrix);
                    //FindEnemyUnitToAttackFrom();
                }
                else if (IsCellBlocked(NextEnemyUnitToMove, NextEnemyUnitMoveCoords.Col, NextEnemyUnitMoveCoords.Row))
                {
                    NextEnemyUnitToMove.ClearPath();
                    NextEnemyUnitToMove.Movement = 0;
                }
                else
                {
                    NextEnemyUnitToMove.Col = NextEnemyUnitMoveCoords.Col;
                    NextEnemyUnitToMove.Row = NextEnemyUnitMoveCoords.Row;

                    NextEnemyUnitToMove.Movement -= _map[NextEnemyUnitToMove.Col, NextEnemyUnitToMove.Row].GroundUnitTerrainModifier;
                    NextEnemyUnitMoveCoords       = NextEnemyUnitToMove.GetNextWaypoint(NextEnemyUnitToMove.Col, NextEnemyUnitToMove.Row);

                    WakeAdjacentAlliedUnits();

                    _log.Debug($"HandleEnemyUnitMove() to:{NextEnemyUnitToMove.Coordinates} movement = {NextEnemyUnitToMove.Movement} [unit:{NextEnemyUnitToMove.UnitNumber}]");
                }

                _totalUnitsMovedOrAttacked++;
            }

            if (NextEnemyUnitToMove.IsAtDestination)
            {
                _log.Debug("HandleEnemyUnitMove() unit is at destination");
                _units.PlayerCheckForPossibleAttack(NextEnemyUnitToMove, _alliedEnemyMatrix);
                NextEnemyUnitToMove.Command = UNITCOMMAND.Destination;
                NextEnemyUnitToMove.Sleep   = true;               //TODO: if allied unit comes in range, then wake and attack
                EnemyUnitQueue.Dequeue();
                NextEnemyUnitToMove = null;
            }
            else
            {
                NextEnemyUnitToMove.Flash = new UnitFlash(2, 0.2f, new Color(100, 200, 100));
            }
        }