Ejemplo n.º 1
0
        public void ClickButton(object sender, RoutedEventArgs e)
        {
            Button button = (Button)sender;
            var    coords = new ButtonCoords(button);

            LblScoreToReceive.Content = null;
            if (this.PopFieldInstance.IsGroupSelected(coords))
            {
                int n = this.PopFieldInstance.GetTotalSelecetedItems();
                this.ScoreInstance.SetNewScore(n);
                WowLevelItem wowLevelItem = this.ScoreInstance.GetWowLevel(n);
                if (wowLevelItem != null)
                {
                    var splashWin = new Window1()
                    {
                        Top  = (this.Height - 100) / 2 + this.Top,
                        Left = (this.Width - 200) / 2 + this.Left
                    };
                    splashWin.SplashWinLabel.Content = wowLevelItem.Message;
                    splashWin.Show();
                    Task.Delay(TimeSpan.FromSeconds(1))
                    .ContinueWith((t) => splashWin.Close(), TaskScheduler.FromCurrentSynchronizationContext());
                    SoundPlayer player = new SoundPlayer(wowLevelItem.Message + ".wav");
                    player.Play();
                }
                this.PopFieldInstance.DestroySelected();
                if (this.PopFieldInstance.IsLevelEnded())
                {
                    this.ScoreInstance.SetReceivedBonus(this.PopFieldInstance.GetVisibleItemsCount());
                    TxtBonus.Text      = this.ScoreInstance.GetLastLevelBonus().ToString();
                    TxtTotalBonus.Text = this.ScoreInstance.GetTotalBonus().ToString();
                    if (ScoreInstance.IsGameOver())
                    {
                        LblGameOver.Visibility     = Visibility.Visible;
                        BtnStartNewGame.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        if (!ScoreInstance.SetNextLevel())
                        {
                            LblHighestScore.Visibility = Visibility.Visible;
                            BtnStartNewGame.Visibility = Visibility.Visible;
                        }
                        this.GenerateNewRandomField();
                    }
                }
            }
            else
            {
                this.PopFieldInstance.SetSelectedGroup(coords);
                var scoreToReceive = this.PopFieldInstance.GetTotalSelecetedItems();
                if (scoreToReceive != 0)
                {
                    LblScoreToReceive.Content = scoreToReceive.ToString() + " tiles reward score " + this.ScoreInstance.GetNewScore(scoreToReceive).ToString();
                }
            }

            this.SyncWithDisplay();
        }
Ejemplo n.º 2
0
            private bool GetAdjacentItems(ButtonCoords coords, bool isTestMode = false)
            {
                int x  = coords.X;
                int y  = coords.Y;
                int x1 = coords.X - 1;
                int x2 = coords.X + 1;
                int y1 = coords.Y - 1;
                int y2 = coords.Y + 1;

                if (x1 >= 0 && FieldArray[x1, y].IsVisible == true && FieldArray[x1, y].IsSelected != true && FieldArray[x1, y].Color == FieldArray[x, y].Color)
                {
                    if (isTestMode)
                    {
                        return(true);
                    }
                    var tempCoord = new ButtonCoords(x1, y);
                    FieldArray[x1, y].IsSelected = true;
                    LstSelectedItems.Add(tempCoord);
                    this.GetAdjacentItems(tempCoord);
                }
                if (x2 < MaxX && FieldArray[x2, y].IsVisible == true && FieldArray[x2, y].IsSelected != true && FieldArray[x2, y].Color == FieldArray[x, y].Color)
                {
                    if (isTestMode)
                    {
                        return(true);
                    }
                    var tempCoord = new ButtonCoords(x2, y);
                    FieldArray[x2, y].IsSelected = true;
                    LstSelectedItems.Add(tempCoord);
                    this.GetAdjacentItems(tempCoord);
                }
                if (y1 >= 0 && FieldArray[x, y1].IsVisible == true && FieldArray[x, y1].IsSelected != true && FieldArray[x, y1].Color == FieldArray[x, y].Color)
                {
                    if (isTestMode)
                    {
                        return(true);
                    }
                    var tempCoord = new ButtonCoords(x, y1);
                    FieldArray[x, y1].IsSelected = true;
                    LstSelectedItems.Add(tempCoord);
                    this.GetAdjacentItems(tempCoord);
                }
                if (y2 < MaxY && FieldArray[x, y2].IsVisible == true && FieldArray[x, y2].IsSelected != true && FieldArray[x, y2].Color == FieldArray[x, y].Color)
                {
                    if (isTestMode)
                    {
                        return(true);
                    }
                    var tempCoord = new ButtonCoords(x, y2);
                    FieldArray[x, y2].IsSelected = true;
                    LstSelectedItems.Add(tempCoord);
                    this.GetAdjacentItems(tempCoord);
                }
                return(false);
            }
Ejemplo n.º 3
0
 private void GenerateButtons()
 {
     for (int i = 0; i < MaxX; ++i)
     {
         for (int j = 0; j < MaxY; ++j)
         {
             Button button = new Button();
             button.SetValue(Grid.ColumnProperty, i);
             button.SetValue(Grid.RowProperty, j);
             ButtonCoords.SetCoords(button, i, j);
             button.Style  = (Style)FindResource("NoHoverButton");
             button.Click += ClickButton;
             MainGrid.Children.Add(button);
         }
     }
 }
Ejemplo n.º 4
0
 public void SetSelectedGroup(ButtonCoords coords)
 {
     for (int i = 0; i < MaxX; ++i)
     {
         for (int j = 0; j < MaxY; ++j)
         {
             FieldArray[i, j].IsSelected = false;
         }
     }
     FieldArray[coords.X, coords.Y].IsSelected = true;
     LstSelectedItems.Clear();
     LstSelectedItems.Add(coords);
     this.GetAdjacentItems(coords);
     if (LstSelectedItems.Count == 1)
     {
         LstSelectedItems.Clear();
     }
 }
Ejemplo n.º 5
0
 private void SyncWithDisplay()
 {
     foreach (Button button in MainGrid.Children.Cast <UIElement>().ToList())
     {
         var coords     = new ButtonCoords((Button)button);
         var popItem    = PopFieldInstance.GetPopItem(coords);
         var isSelected = PopFieldInstance.LstSelectedItems.Contains(coords);
         button.Visibility      = popItem.IsVisible ? Visibility.Visible : Visibility.Hidden;
         button.Background      = colorsArr[popItem.Color];
         button.BorderThickness = new Thickness(1);
         button.BorderBrush     = Brushes.Transparent;
         button.FontWeight      = FontWeights.Bold;
         button.FontSize        = 16;
         button.Content         = isSelected ? "X" : "";
     }
     LblLevel.Content     = ScoreInstance.GetLevelString();
     TxtCurrentScore.Text = ScoreInstance.CurrentScore.ToString();
     TxtTargetScore.Text  = ScoreInstance.TargetScore.ToString();
     TxtBonus.Text        = this.ScoreInstance.LstBonus.LastOrDefault().ToString();
     TxtTotalBonus.Text   = this.ScoreInstance.LstBonus.Sum().ToString();
 }
Ejemplo n.º 6
0
 public bool IsGroupSelected(ButtonCoords coords)
 {
     return(this.LstSelectedItems.Contains(coords));
 }
Ejemplo n.º 7
0
 public PopItem GetPopItem(ButtonCoords coords)
 {
     return(FieldArray[coords.X, coords.Y]);
 }