/// <summary> /// Второе нажатие на ту же кнопку /// </summary> private void SameClick() { GameField.UnselectCell(); GameField.IsSomeSelected = false; StopImageAnimation(AnimatedImage); AnimatedImage = null; }
/// <summary> /// Первый клик по ячейке /// </summary> private void FirstClick(int X, int Y) { //Логика GameField.SelectCell(X, Y); GameField.IsSomeSelected = true; //Анимация StartImageAnimation(Images[X, Y], Animations.Selection); AnimatedImage = Images[X, Y]; }
/// <summary> /// Второй клик по ячейке /// </summary> private async Task SecondClick(int X, int Y) { UpdatePointsLabel(); GameField.ResetCounter(); //Снятие выделения StopImageAnimation(AnimatedImage); GameField.IsSomeSelected = false; await SwapImages(Images[X, Y], AnimatedImage); //Проверка на ложное нажатие if (GameField.IsFalseMove()) { await SwapImages(Images[X, Y], AnimatedImage); StopImageAnimation(AnimatedImage); StopImageAnimation(Images[X, Y]); GameField.IsSomeSelected = false; AnimatedImage = null; return; } StopImageAnimation(AnimatedImage); StopImageAnimation(Images[X, Y]); GameField.CheckAllCells(); GameField.DeleteMarkedCells(); UpdatePointsLabel(); await PutDownFigures(); do { GameField.MakeNewFigures(); await DefineAllImagesAnim(); GameField.CheckAllCells(); GameField.DeleteMarkedCells(); UpdatePointsLabel(); await PutDownFigures(); }while (GameField.HaveEmptyFigeres()); await DefineAllImagesAnim(); UpdatePointsLabel(); GameField.ResetCounter(); ButtonController.UpdateStatus(GameField); Leaderboard.UpdateInfo(GameField.Points); AnimatedImage = null; }
/// <summary> /// Плавно меняет два изображение местами /// </summary> /// <param name="firstImage">Первое изображение</param> /// <param name="secondImage">Второе изображение</param> private async Task SwapImages(MTImage firstImage, MTImage secondImage) { StartImageAnimation(firstImage, Animations.Disappearance); StartImageAnimation(secondImage, Animations.Disappearance); await Task.Delay(500); int x1 = firstImage.X; int y1 = firstImage.Y; int x2 = secondImage.X; int y2 = secondImage.Y; GameField.SwapCells(GameField.cells[x1, y1], GameField.cells[x2, y2]); DefineImage(firstImage); DefineImage(secondImage); StartImageAnimation(firstImage, Animations.Appearance); StartImageAnimation(secondImage, Animations.Appearance); await Task.Delay(500); }
/// <summary> /// Анимированно меняет язображение на актуальное /// </summary> /// <param name="image">Изображение</param> private async void AnimatedDefineImage(MTImage image) { int X = image.X; int Y = image.Y; if (GameField.cells[X, Y].figure == Figure.Empty) { StartImageAnimation(image, Animations.QuickDisappearance); await Task.Delay(200); image.Source = null; ImageBehavior.SetAnimatedSource(image, null); StopImageAnimation(image); GameField.cells[X, Y].IsChanged = false; } else if (GameField.cells[X, Y].IsChanged) { StartImageAnimation(image, Animations.QuickDisappearance); await Task.Delay(200); BitmapImage BMI = new BitmapImage(); BMI.BeginInit(); BMI.UriSource = new Uri(GetFigurePath(GameField.cells[X, Y].figure), UriKind.Relative); BMI.EndInit(); image.Source = BMI; ImageBehavior.SetAnimatedSource(image, BMI); ImageBehavior.SetAnimationSpeedRatio(image, 0.2); StartImageAnimation(image, Animations.QuickAppearance); await Task.Delay(200); GameField.cells[X, Y].IsChanged = false; } else { } }
/// <summary> /// Конструктор /// </summary> /// <param name="FieldGrid">Игровое поле</param> /// <param name="size">Размер игрового поля</param> public Visualizer(Grid FieldGrid, int size, Label pointsLabel, Label pointsCounterLabel) { GameFieldControl = FieldGrid; GameField = new GameField(size); Points = pointsLabel; PointsCounter = pointsCounterLabel; ChosenSpell = Spells.None; Images = new MTImage[size, size]; Buttons = new Button[size, size]; ButtonController = new ButtonsController(); Leaderboard = new VisualLeaderboard(); for (int x = 0; x < size; x++) { for (int y = 0; y < size; y++) { Images[x, y] = new MTImage() { X = x, Y = y, figure = GameField.cells[x, y].figure }; Buttons[x, y] = new Button() { Background = Brushes.Transparent }; Buttons[x, y].Content = Images[x, y]; Buttons[x, y].Click += CellClick; } } DefineAllImages(); PrepareGrid(); }
/// <summary> /// Присвоение ячейки соответствующего изображения /// </summary> /// <param name="cell">Логическая ячейка</param> /// <param name="image">Графическая ячейка</param> private void DefineImage(MTImage image) { int X = image.X; int Y = image.Y; if (GameField.cells[X, Y].figure == Figure.Empty) { image.Source = null; ImageBehavior.SetAnimatedSource(image, null); } else { BitmapImage BMI = new BitmapImage(); BMI.BeginInit(); BMI.UriSource = new Uri(GetFigurePath(GameField.cells[X, Y].figure), UriKind.Relative); BMI.EndInit(); image.Source = BMI; ImageBehavior.SetAnimatedSource(image, BMI); ImageBehavior.SetAnimationSpeedRatio(image, 0.2); } GameField.cells[X, Y].IsChanged = false; }