Ejemplo n.º 1
0
 // Wir sammeln die Stein-Controls des Spielbretts ein,
 // um einfacher per Zeile/Spalte auf sie zugreifen zu können.
 void CollectStones()
 {
     _stones = new FlipControl[8, 8];
     foreach (var ch in GameGrid.Children)
     {
         Border field = ch as Border;
         if (field != null)
         {
             int         r     = Grid.GetRow(field) - 1;
             int         c     = Grid.GetColumn(field) - 1;
             FlipControl stone = field.Child as FlipControl;
             _stones[r, c] = stone;
             if ((r == 3 && c == 4) || (r == 4 && c == 3))
             {
                 stone.Flip(false);
             }
         }
     }
 }
Ejemplo n.º 2
0
        void DisplayMatch(bool animate = true)
        {
            for (int row = 0; row < 8; ++row)
            {
                for (int column = 0; column < 8; ++column)
                {
                    int         stone   = _match.Game.StoneAt(row, column);
                    FlipControl control = _stones[row, column];
                    switch (stone)
                    {
                    case -1:
                        control.Visibility = Visibility.Hidden;
                        break;

                    case 0:
                        if (control.Visibility == Visibility.Visible)
                        {
                            if (!control.IsFlipped)
                            {
                                control.Flip(animate);
                            }
                        }
                        else
                        {
                            if (!control.IsFlipped)
                            {
                                control.Flip(false);
                            }
                            control.Visibility = Visibility.Visible;
                        }
                        break;

                    case 1:
                        if (control.Visibility == Visibility.Visible)
                        {
                            if (control.IsFlipped)
                            {
                                control.Flip(animate);
                            }
                        }
                        else
                        {
                            if (control.IsFlipped)
                            {
                                control.Flip(false);
                            }
                            control.Visibility = Visibility.Visible;
                        }
                        break;
                    }
                }
            }
            tbLog.Text = _match.GetLog();
            tbLog.ScrollToEnd();
            tbScore.Text = string.Format("Schwarz: {0}\r\nWeiß: {1}", _match.Game.CountStonesFor(0), _match.Game.CountStonesFor(1));
            var player   = _match.NextPlayer;
            int playerId = _match.GetPlayerId(player);
            var panel    = playerId == 0 ? statusPlayer1 : statusPlayer2;

            if (player.IsInteractive)
            {
                panel.Text = "";
            }
            else
            {
                string stat = player.GetStatistics();
                if (!string.IsNullOrEmpty(stat))
                {
                    panel.Text = string.Format("{0}: {1}", playerId == 0 ? "Schwarz" : "Weiß", stat);
                }
                else
                {
                    panel.Text = "";
                }
            }
        }