示例#1
0
        /// <summary>
        /// S'exécute lorsque l'on clique sur le bouton « Aléatoire ».
        /// </summary>
        /// <param name="sender">Objet appelant</param>
        /// <param name="e">Arguments</param>
        private void btnAleatoire_Click(object sender, RoutedEventArgs e)
        {
            btnAleatoire.IsEnabled = false;
            for (int x = 0; x < GrilleJeu.TAILLE_GRILLE_JEU; x++)
            {
                for (int y = 0; y < HAUTEUR_GRILLE_DISPONIBLE; y++)
                {
                    if (pieces[x, y] == null) // On ajoute une pièce aléatoire à chaque case vide
                    {
                        ReponseGenerateurPiece piece = selectionneurPieces.GenererPieceAleatoire(ParametresCouleursJoueurs.CouleurJoueur);

                        EstSelection = false;
                        selectionneurPieces.CacherInterface();

                        pieces[x, y] = new PieceAffichable(piece.Piece, piece.Affichage, piece.Nom);
                        pieces[x, y].Modifier((Piece Piece, Rectangle Affichage, string Nom) =>
                        {
                            Affichage.MouseLeftButtonUp += (object pieceAffichable, MouseButtonEventArgs evenement) =>
                            {
                                selectionneurPieces.RedonnerPiece(Nom);
                                grdPlateauJeu.Children.Remove(Affichage);

                                pieces[Grid.GetColumn((Rectangle)pieceAffichable),
                                       Grid.GetRow((Rectangle)pieceAffichable)] = null;
                                btnJouer.IsEnabled = false;
                                if (selectionneurPieces.NombresTypesPiecesRestants() == SelectionneurPieces.NB_TYPES_PIECES)
                                {
                                    btnVider.IsEnabled = false;
                                }
                                btnAleatoire.IsEnabled = true;
                            };
                        });

                        Grid.SetColumn(pieces[x, y].Affichage, x);
                        Grid.SetRow(pieces[x, y].Affichage, y);

                        grdPlateauJeu.Children.Add(pieces[x, y].Affichage);
                    }
                }
            }

            btnJouer.IsEnabled = true;
            btnVider.IsEnabled = true;
        }
示例#2
0
        /// <summary>
        /// Crée et insère les cases avec les textures
        /// </summary>
        private void InsererCasesGrille()
        {
            for (int x = 0; x < GrilleJeu.TAILLE_GRILLE_JEU; x++)
            {
                for (int y = 0; y < HAUTEUR_GRILLE_DISPONIBLE; y++)
                {
                    Rectangle caseGrille = new Rectangle();
                    caseGrille.Fill = new ImageBrush(new BitmapImage(new Uri("textures/terrain.png", UriKind.Relative)));

                    caseGrille.MouseEnter += (object sender, MouseEventArgs e) =>
                    {
                        selection.Fill   = new ImageBrush(new BitmapImage(new Uri("textures/preSelector.png", UriKind.Relative)));
                        selection.Cursor = Cursors.Hand;

                        selection.MouseUp += (object casePreselectionnee, MouseButtonEventArgs arguments) =>
                        {
                            EstSelection = true;
                            selectionneurPieces.DemanderPiece((piece, affichage, nom) =>
                            {
                                EstSelection = false;
                                int X        = Grid.GetColumn((Rectangle)sender);
                                int Y        = Grid.GetRow((Rectangle)sender);

                                pieces[X, Y] = new PieceAffichable(piece, affichage, nom);
                                pieces[X, Y].Modifier((Piece Piece, Rectangle Affichage, string Nom) =>
                                {
                                    // Évènement du clic du sélectionneur
                                    Affichage.MouseLeftButtonUp += (object pieceAffichable, MouseButtonEventArgs evenement) =>
                                    {
                                        selectionneurPieces.RedonnerPiece(Nom);
                                        grdPlateauJeu.Children.Remove(Affichage);

                                        pieces[Grid.GetColumn((Rectangle)pieceAffichable),
                                               Grid.GetRow((Rectangle)pieceAffichable)] = null;
                                        btnJouer.IsEnabled = false;
                                        if (selectionneurPieces.NombresTypesPiecesRestants() == SelectionneurPieces.NB_TYPES_PIECES)
                                        {
                                            btnVider.IsEnabled = false;
                                        }
                                        btnAleatoire.IsEnabled = true;
                                    };
                                });

                                Grid.SetColumn(pieces[X, Y].Affichage, X);
                                Grid.SetRow(pieces[X, Y].Affichage, Y);

                                grdPlateauJeu.Children.Add(pieces[X, Y].Affichage);

                                if (selectionneurPieces.NombresTypesPiecesRestants() == 1)
                                {
                                    btnJouer.IsEnabled     = true;
                                    btnAleatoire.IsEnabled = false;
                                }
                                btnVider.IsEnabled = true;
                            });
                        };

                        Grid.SetColumn(selection, Grid.GetColumn((Rectangle)sender));
                        Grid.SetRow(selection, Grid.GetRow((Rectangle)sender));
                        if (!EstSelection)
                        {
                            selection.Visibility = Visibility.Visible;
                        }
                    };

                    Grid.SetColumn(caseGrille, x);
                    Grid.SetRow(caseGrille, y);

                    grdPlateauJeu.Children.Add(caseGrille);
                }
            }

            // Lorsque l'on quitte la zone des pièces, on cache le sélecteur
            grdPlateauJeu.MouseLeave += (object sender, MouseEventArgs e) =>
            {
                if (!EstSelection)
                {
                    selection.Visibility = Visibility.Collapsed;
                }
            };
        }