Beispiel #1
0
 private void UpdateSnake(SnakeChangedEventArgs e)
 {
     if (!e.Killed)
     {
         var snakePart = e.SnakeUpdated;
         if (!_snakeBodies.ContainsKey(snakePart))
         {
             FrameworkElement snakeControl = CanvasHelper.SnakeControlFactory(snakePart,
                                                                              _scale);
             _snakeBodies[snakePart] = snakeControl;
             _sprites.Add(snakeControl);
         }
         else
         {
             FrameworkElement snakeControl = _snakeBodies[snakePart];
             CanvasHelper.ResizeElement(snakeControl, snakePart.Size.Width * _scale, snakePart.Size.Height * _scale);
             CanvasHelper.MoveElementOnCanvas(snakeControl, snakePart.Location.X * _scale, snakePart.Location.Y * _scale);
         }
     }
 }
Beispiel #2
0
        private void pageRoot_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            var gameViewModel = DataContext as GameViewModel;

            newPlayAreaSize         = e.NewSize;
            newPlayAreaSize.Width  -= 208;     // odejmuje wielkosci kolumn + grubosc ramki
            newPlayAreaSize.Height -= 152 + 8; // odjemuje wielkosci wierszy + grubosc ramki

            if (gameViewModel != null)
            {
                _scale = (newPlayAreaSize.Height / 300 + newPlayAreaSize.Width / 300) / 2;
                SnakeBody.PlayAreaSize = newPlayAreaSize;
                SnakeBody.Scale        = _scale;
                GameViewModel.Scale    = _scale;
                if (this._fruit != null && this._fruitFrameworkElement != null)
                {
                    CanvasHelper.MoveElementOnCanvas(_fruitFrameworkElement, _fruit.Location.X * _scale, _fruit.Location.Y * _scale);
                    CanvasHelper.ResizeElement(_fruitFrameworkElement, _fruit.Size.Width * _scale, _fruit.Size.Height * _scale);
                }
            }
        }