internal Puckman() { _defaultSpeed = 1.0 / 200; _newHorisontalDirection = HorisontalDirection.Stay; _newVerticalDirection = VerticalDirection.Stay; Name = "Puckman"; Width = BattlefieldCircumstantials.Squaresize; Height = BattlefieldCircumstantials.Squaresize; SnapsToDevicePixels = true; LayoutRoot.Children.Add(new Ellipse { Fill = new SolidColorBrush(BattlefieldCircumstantials.YellowColor) }); ChawAnimation(); }
internal new void MoveDecision() { if (double.IsNaN(Canvas.GetLeft(this)) || double.IsNaN(Canvas.GetTop(this))) return; var currentCoordinates = BattlefieldCircumstantials.GetCoordinates(this); var coordX = (int)currentCoordinates.X; var coordY = (int)currentCoordinates.Y; var thisSquareType = DefineTargetType(coordX, coordY); if (thisSquareType == TargetType.Exit) { MainWindow.Wm.PlayWin(); return; } if (thisSquareType == TargetType.Entrance) { if (_newHorisontalDirection == _currentHorisontalDirection && _newVerticalDirection == _currentVerticalDirection) { CreatureMovement(currentCoordinates, currentCoordinates); return; } } var newCoordX = (int)currentCoordinates.X + (int)_newHorisontalDirection; var newCoordY = (int)currentCoordinates.Y + (int)_newVerticalDirection; var unPredictibleTargetType = DefineTargetType(newCoordX, newCoordY); var oldCoordX = (int)currentCoordinates.X + (int)_currentHorisontalDirection; var oldCoordY = (int)currentCoordinates.Y + (int)_currentVerticalDirection; var predictibleTargetType = DefineTargetType(oldCoordX, oldCoordY); if (unPredictibleTargetType == TargetType.Null || unPredictibleTargetType == TargetType.Entrance || unPredictibleTargetType == TargetType.Exit) { _currentHorisontalDirection = _newHorisontalDirection; _currentVerticalDirection = _newVerticalDirection; CreatureMovement(currentCoordinates, new Point(newCoordX, newCoordY)); return; } if (unPredictibleTargetType == TargetType.Cherry) { _currentHorisontalDirection = _newHorisontalDirection; _currentVerticalDirection = _newVerticalDirection; ApplyBoost((ushort)newCoordX, (ushort)newCoordY); CreatureMovement(currentCoordinates, new Point(newCoordX, newCoordY)); return; } if (predictibleTargetType == TargetType.Null || predictibleTargetType == TargetType.Entrance || predictibleTargetType == TargetType.Exit) { CreatureMovement(currentCoordinates, new Point(oldCoordX, oldCoordY)); return; } if (predictibleTargetType == TargetType.Cherry) { ApplyBoost((ushort)oldCoordX, (ushort)oldCoordY); CreatureMovement(currentCoordinates, new Point(newCoordX, newCoordY)); return; } CreatureMovement(currentCoordinates, currentCoordinates); }
internal void MoveDefine(KeyEventArgs args) { switch (args.Key) { case Key.Up: _newVerticalDirection = VerticalDirection.Up; _newHorisontalDirection = HorisontalDirection.Stay; Log.AddLog("Pressed UP"); break; case Key.Down: _newVerticalDirection = VerticalDirection.Down; _newHorisontalDirection = HorisontalDirection.Stay; Log.AddLog("Pressed Down"); break; case Key.Left: _newVerticalDirection = VerticalDirection.Stay; _newHorisontalDirection = HorisontalDirection.Left; Log.AddLog("Pressed Left"); break; case Key.Right: _newVerticalDirection = VerticalDirection.Stay; _newHorisontalDirection = HorisontalDirection.Right; Log.AddLog("Pressed Right"); break; } }