Exemplo n.º 1
0
        /// <summary>
        /// Construit une « pièce capturée »
        /// </summary>
        /// <param name="piece">Pièce capturée</param>
        /// <param name="stpParent">Stack panel dans lequel la pièce est mise</param>
        public PieceCapturee(Piece piece, StackPanel stpParent)
        {
            StpParent = stpParent;
            Piece     = piece;

            // On crée une grille, dans laquelle on met l'image de la pièce et un label (pour le nombre de pièces)

            GrdCellule = new Grid();
            GrdCellule.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(TAILLE_PIECES)
            });
            GrdCellule.ColumnDefinitions.Add(new ColumnDefinition());
            GrdCellule.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(TAILLE_PIECES)
            });

            GrdCellule.Children.Add(new Rectangle
            {
                Fill = new ImageBrush(new BitmapImage(new Uri(
                                                          "sprites/" + (piece.EstDeCouleur(Couleur.Rouge) ? "Rouge/" : "Bleu/") + piece.Nom + ".png",
                                                          UriKind.Relative)))
            });

            LabelNbPieces = new Label()
            {
                Content  = 1,
                FontSize = 12
            };
            Grid.SetColumn(LabelNbPieces, 1);
            GrdCellule.Children.Add(LabelNbPieces);

            stpParent.Children.Add(GrdCellule);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Calcule le nombre de pièces d'une couleur présentes dans la grille
        /// </summary>
        /// <param name="couleur">La couleur des pièces</param>
        /// <returns>Le nombre de pièces</returns>
        public int CalculerNombrePieces(Couleur couleur)
        {
            int nbPieces = 0;

            for (int x = 0; x < TAILLE_GRILLE_JEU; x++)
            {
                for (int y = 0; y < TAILLE_GRILLE_JEU; y++)
                {
                    Piece piece = ObtenirPiece(new Coordonnee(x, y));
                    if (piece != null && piece.EstDeCouleur(couleur))
                    {
                        nbPieces++;
                    }
                }
            }
            return(nbPieces);
        }