Esempio n. 1
0
        public static bool OrientatesTop(this IFieldOccupant occupant, IField field = null)
        {
            var occupantAngle = occupant.OrientationAngle - (field != null ? field.OrientationAngle : 0);

            return(occupantAngle.BetweenAngle(leftBound: 360 - 45, rightBound: 360) ||
                   occupantAngle.BetweenAngle(leftBound: 0, rightBound: 0 + 45));
        }
Esempio n. 2
0
        private void Dispose(Schiffsposition except)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("Move");
            }
            disposed = true;

            foreach (var ziel in _Ziele)
            {
                ziel.Occupied -= ZielOccupied;
                if (ziel != except)
                {
                    _FieldsContainer.Children.Remove(ziel);
                    _Spielfeld.Unregister(ziel);
                }
            }
            _Ziele.Clear();

            MovedOrCanceled(_Von);

            _Spielfeld       = null;
            _FieldsContainer = null;
            _Von             = null;
            _Mover           = null;
            _Ziele           = null;
            _Moved           = null;
        }
Esempio n. 3
0
        public void Init(FieldsView spielfeld, Canvas fieldsContainer, Schiffsposition von, IFieldOccupant mover, object argument, Action <Schiffsposition, Schiffsposition> moved)
        {
            _Spielfeld       = spielfeld;
            _FieldsContainer = fieldsContainer;
            _Von             = von;
            _Mover           = mover;
            _Argument        = argument;

            _Ziele = new List <Schiffsposition>();
            _Moved = moved;
        }
Esempio n. 4
0
        public void Occupy(IFieldOccupant occupant)
        {
            ViewModel.FieldOccupants.TryAdd(occupant, byte.MinValue);
            ViewModel.UpdateState(this);
            LastOccupant = occupant;

            var h = Occupied;

            if (h != null)
            {
                h(this, occupant);
            }
        }
Esempio n. 5
0
        private void CancelMove(IField field, IFieldOccupant occupant = null)
        {
            var schiffsposition = (Schiffsposition)field;

            if (schiffsposition.Move != null)
            {
                if (occupant == null || schiffsposition.Move.Mover.Id == occupant.Id)
                {
                    schiffsposition.Move.Dispose();
                    schiffsposition.Move = null;
                    schiffsposition.ViewModel.CancelCancel();
                }
            }
        }
Esempio n. 6
0
        public void Yield(IFieldOccupant occupant)
        {
            var value = byte.MinValue;

            ViewModel.FieldOccupants.TryRemove(occupant, out value);
            ViewModel.UpdateState(this);

            var h = Yielded;

            if (h != null)
            {
                h(this, occupant);
            }
        }
Esempio n. 7
0
        private void ZielOccupied(IField field, IFieldOccupant occupant)
        {
            if (_Mover.Id == occupant.Id)
            {
                _FieldsContainer.Children.Remove(_Von);
                _Spielfeld.Unregister(_Von);

                var neueSchiffsposition = (Schiffsposition)field;
                neueSchiffsposition.SetValue(Canvas.ZIndexProperty, 1);

                var von   = _Von;
                var moved = _Moved;

                Dispose(except: neueSchiffsposition);

                if (occupant.OrientatesBottom(neueSchiffsposition))
                {
                    neueSchiffsposition.OrientationAngle = (neueSchiffsposition.OrientationAngle + 180) % 360;
                }

                if (occupant.OrientatesLeft(neueSchiffsposition))
                {
                    neueSchiffsposition.OrientationAngle = (neueSchiffsposition.OrientationAngle + 270) % 360;
                }

                if (occupant.OrientatesRight(neueSchiffsposition))
                {
                    neueSchiffsposition.OrientationAngle = (neueSchiffsposition.OrientationAngle + 90) % 360;
                }

                neueSchiffsposition.ViewModel.LetztePosition = new SchiffspositionModel.Position(von.Position, von.OrientationAngle);
                neueSchiffsposition.ViewModel.Label          = null;

                moved(von, neueSchiffsposition);
            }
        }
Esempio n. 8
0
 private void Move <TMove>(Schiffsposition schiffsposition, IFieldOccupant occupant, object argument) where TMove : Move, new()
 {
     if (schiffsposition.Move == null)
     {
         var move = new TMove();
         move.Init(_Spielfeld, _FieldsContainer, schiffsposition, occupant, argument, (von, nach) =>
         {
             von.Move       = null;
             von.Yielded   -= PrepareToMove;
             von.Occupied  -= CancelMove;
             nach.Yielded  += PrepareToMove;
             nach.Occupied += CancelMove;
             nach.Activate(
                 onForget: RemoveField,
                 onForward: Forward,
                 onBarrelRoll: BarrelRoll,
                 onSlide3: Slide3);
             ((Spielfeld)_Spielfeld).ZieleErfassen();
         });
         move.CreatePotenzielleZiele();
         schiffsposition.Move = move;
         schiffsposition.ViewModel.AllowCancel(() => CancelMove(schiffsposition, occupant));
     }
 }
Esempio n. 9
0
 private void PrepareToMove(IField field, IFieldOccupant occupant)
 {
     //Move<ForwardMove>((Schiffsposition)field, occupant);
 }
Esempio n. 10
0
 private Vector TopLeft(IFieldOccupant occupant)
 {
     return(occupant.Position.AsVector() - new Vector(43, 43));
 }
Esempio n. 11
0
 public void Stays(IFieldOccupant occupant)
 {
     ViewModel.UpdateState(this);
 }
Esempio n. 12
0
 public bool CanOccupy(IFieldOccupant occupant)
 {
     return(occupant.Id == AllowedOccupantId);
 }
Esempio n. 13
0
 public void AllowOccupant(IFieldOccupant occupant)
 {
     ViewModel.Tokens = ((TagVisual)occupant).ViewModel.Tokens;
 }
Esempio n. 14
0
 public bool IsOccupiedBy(IFieldOccupant occupant)
 {
     return(ViewModel.FieldOccupants.ContainsKey(occupant));
 }