コード例 #1
0
 private void CibleSup(monBouton b, Cavalier p)
 {
     for (int i = 0; i < p.GetDepi().GetLength(0); ++i)
     {
         DD.UnSetButtonCible(b, piece.GetDepi()[i], piece.GetDepj()[i]);
     }
 }
コード例 #2
0
        public FormeCavalier_Simulation(int depLig, int depCol, int choixCav, int choixCombiColor)
        {
            InitializeComponent();
            FormeCavalier_Simulation_Load(null, null);
            aleatoire = new Random();
            //constante A NE PAS CHANGER
            cpClic           = 0;
            rang             = 0;
            pause            = false;
            stopSimulation   = false;
            simulationLancee = false;
            demo             = true;

            //VARIABLE A CHANGER AVEC AUTRE FORME
            //choix du cavalier
            fmpca         = new FormeMenu_Parametre_Cavalier(choixCav);
            this.choixCav = fmpca.GetCcDef();

            // choixCav = FormeMenu_Parametre_Cavalier.GetCcDef();
            // choix du damier
            fmpco = new FormeMenu_Parametre_Couleur(choixCombiColor);
            cc    = fmpco.GetCcDef();
            cf    = fmpco.GetCfDef();
            ColorerMesBoutons();

            //obliger user a choisir nbrpas et duree
            NbrPas     = (5);
            ChoixDuree = (2);

            monBouton b = DD.GetMonBouton(depLig, depCol);

            Buttons_Click(b, null);
        }
コード例 #3
0
        // ******************** BOUTON PANNEAU DEPART **********************
        private void boutonDepart_Click(object sender, EventArgs e)
        {
            if (sender is Button && (cpClic == 0) && !pause)
            {
                ////// ESSAI NICO ADRI
                cpClic           = 0;
                rang             = 0;
                pause            = false;
                stopSimulation   = false;
                simulationLancee = false;
                //////
                ///
                ++cpClic;
                boutonPause.Visible = true;

                boutonDepart.Visible      = false;
                boutonRecommencer.Visible = false;

                label1.Visible         = false;
                ListChoixDuree.Visible = false;
                ListNbrPas.Visible     = false;

                depLig = aleatoire.Next(GetNbrCaseCoteDamier()) + GetNbrCaseMarge();
                depCol = aleatoire.Next(GetNbrCaseCoteDamier()) + GetNbrCaseMarge();

                monBouton bdest = DD.GetMonBouton(depLig, depCol);
                piece = new Cavalier(bdest, choixCav);
                IAchoixRemplissage(bdest);
                LancerSimulation();
            }
        }
コード例 #4
0
        public Cavalier(monBouton b, int cavalierSwitch)
        {
            posLig = b.getNumLigne();
            posCol = b.getNumCol();

            switch (cavalierSwitch)
            {
            case 1:
                img  = Image.FromFile("images/cheval.png");
                depi = new int[] { 2, 1, -1, -2, -2, -1, 1, 2 };
                depj = new int[] { 1, 2, 2, 1, -1, -2, -2, -1 };
                break;

            case 2:
                img  = Image.FromFile("images/cheval2.png");
                depi = new int[] { 2, 1, -1, -2, -2, -1, 1, 2 };
                depj = new int[] { 1, 2, 2, 1, -1, -2, -2, -1 };
                break;

            case 3:
                img  = Image.FromFile("images/cheval3.png");
                depi = new int[] { 1, 0, 1, -1, 0, -1, 1, -1 };
                depj = new int[] { 0, 1, 1, 0, -1, -1, -1, 1 };
                break;

            default:
                img  = Image.FromFile("images/cheval.png");
                depi = new int[] { 2, 1, -1, -2, -2, -1, 1, 2 };
                depj = new int[] { 1, 2, 2, 1, -1, -2, -2, -1 };
                break;
            }
        }
コード例 #5
0
        private void Buttons_Click(object sender, EventArgs e)
        {
            if (sender is monBouton && (cpClic == 0) && !pause)
            {
                if (NbrPas == (-1) || ChoixDuree == (-1))
                {
                    DialogResult reponse = MessageBox.Show(
                        "La sélection du nombre de pas et de la durée de la pause est incorrecte." +
                        "Veuillez recommencer la partie avec des sélections correctes.",
                        "Erreur de saisie",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error,
                        MessageBoxDefaultButton.Button3,
                        MessageBoxOptions.RightAlign);
                }
                else
                {
                    monBouton b = sender as monBouton;

                    ++cpClic;

                    // b.Enabled = false;
                    depLig = b.getNumLigne();
                    depCol = b.getNumCol();
                    if (demo)
                    {
                        boutonPause.Visible = false;

                        boutonDepart.Visible      = false;
                        boutonRecommencer.Visible = false;

                        label1.Visible         = false;
                        ListChoixDuree.Visible = false;
                        ListNbrPas.Visible     = false;
                    }
                    else
                    {
                        boutonPause.Visible = true;

                        boutonDepart.Visible      = false;
                        boutonRecommencer.Visible = false;

                        label1.Visible         = false;
                        ListChoixDuree.Visible = false;
                        ListNbrPas.Visible     = false;
                    }


                    piece = new Cavalier(b, choixCav);
                    IAchoixRemplissage(b);
                    LancerSimulation();
                }
            }
        }
コード例 #6
0
 private bool IsRestCibleDispo(monBouton bori, Cavalier p)
 {
     for (int i = 0; i < p.GetDepi().GetLength(0); ++i)
     {
         if (DD.IsDispoCible(bori, p.GetDepi()[i], p.GetDepj()[i]))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #7
0
        private void PremierDeplacerPiece(monBouton bdest)
        {
            if (DD.IsDispo(bdest.getNumLigne(), bdest.getNumCol()))
            {
                depLig = bdest.getNumLigne();
                depCol = bdest.getNumCol();

                piece = new Cavalier(bdest, choixCav);

                bdest.ImageAj(piece.GetImg());

                DD.FermerDispo(depLig, depCol);

                //CibleAj(bdest, piece);
            }
        }
コード例 #8
0
        // ************************* DEPLACEMENT PIECE **************************

        private void DeplacerPiece(monBouton bori, monBouton bdest)
        {
            if ((piece.IsAtteignable(bdest.getNumLigne(), bdest.getNumCol())))
            {
                bori.ImageSupp();
                bori.Assombrir();
                //CibleSup(bori, piece);

                piece.Deplacer(bdest.getNumLigne(), bdest.getNumCol());
                bdest.ImageAj(piece.GetImg());
                DD.FermerDispo(bdest.getNumLigne(), bdest.getNumCol());



                //CibleAj(bdest, piece);
            }
        }
コード例 #9
0
        private void Buttons_Click(object sender, EventArgs e) //Evenement "cliquer sur bouton"
        {
            //Les victoires, les défaites, sont liées à l'événement "click" de boutons.
            //Ainsi les conditions de victoire/défaite devront être ici.

            if (sender is monBouton)
            {
                monBouton bdest;
                bdest = sender as monBouton;

                if (DD.IsDispo(bdest.getNumLigne(), bdest.getNumCol()))
                {
                    if (cpClic == 0 && !entamer)
                    {
                        boutonDepart.Visible      = false;
                        boutonRecommencer.Visible = true;
                        monBoutonDep = bdest;
                        PremierDeplacerPiece(bdest);
                        entamer = true;
                    }
                    else
                    {
                        if (piece.IsAtteignable(bdest.getNumLigne(), bdest.getNumCol()))
                        {
                            //deplacement piece
                            monBouton bori = DD.GetMonBouton(jouLig, jouCol);
                            DeplacerPiece(bori, bdest);

                            //boutonRetour
                            if (cpClic > rtClic)
                            {
                                boutonRetour.Visible = true;
                            }
                            else
                            {
                                boutonRetour.Visible = false;
                            }

                            //labelVictoire
                            LabelVict(bdest, piece);
                        }
                    }
                    // labelTest.Text = "CPT=" + cpClic;
                }
            }
        }
コード例 #10
0
        // ******************** BOUTON PANNEAU DEPART **********************
        private void boutonDepart_Click(object sender, EventArgs e)
        {
            if (sender is Button && (cpClic == 0))
            {
                boutonDepart.Visible      = false;
                boutonRecommencer.Visible = true;
                labelVict.Visible         = false;
                victoire = false;
                boutonSolution.Visible = false;

                entamer = true;

                depLig = aleatoire.Next(GetNbrCaseCoteDamier()) + GetNbrCaseMarge();
                depCol = aleatoire.Next(GetNbrCaseCoteDamier()) + GetNbrCaseMarge();

                monBouton bdest = DD.GetMonBouton(depLig, depCol);
                monBoutonDep = bdest;
                PremierDeplacerPiece(bdest);
            }
        }
コード例 #11
0
        private void LabelVict(monBouton b, Cavalier p)
        {
            labelVict.Text = "";
            if (IsRestCibleDispo(b, p))
            {
                labelVict.Text = "";
            }
            else
            {
                if (DD.IsToutOccupe())
                {
                    labelVict.Text = "VICTOIRE !";
                    victoire       = true;
                }
                else
                {
                    labelVict.Text = "DEFAITE...";
                    victoire       = false;
                }
                switch (cpRtClic)
                {
                case 0:
                    labelVict.Text += "\n(avec aucun retour)";
                    break;

                case 1:
                    labelVict.Text += "\n(avec un seul retour)";
                    break;

                default:
                    labelVict.Text += "\n(avec " + cpRtClic + " retours)";
                    break;
                }
                labelVict.Text   += "\nScore = " + cpClic + " pas.";
                labelVict.Visible = true;
                if (!victoire)
                {
                    boutonSolution.Visible = true;
                }
            }
        }
コード例 #12
0
        // ******************** MOUVEMENT JOUER **********************

        private void DeplacerPiece(monBouton bori, monBouton bdest)
        {
            if ((piece.IsAtteignable(bdest.getNumLigne(), bdest.getNumCol())))
            {
                bori.ImageSupp();
                bori.Assombrir();
                CibleSup(bori, piece);

                piece.Deplacer(bdest.getNumLigne(), bdest.getNumCol());

                bdest.ImageAj(piece.GetImg());
                DD.FermerDispo(bdest.getNumLigne(), bdest.getNumCol());

                jouLig = bdest.getNumLigne();
                jouCol = bdest.getNumCol();

                dpl[cpClic] = bdest;
                ++cpClic;

                CibleAj(bdest, this.piece);
            }
        }
コード例 #13
0
        private void PremierDeplacerPiece(monBouton bdest)
        {
            if (DD.IsDispo(bdest.getNumLigne(), bdest.getNumCol()))
            {
                depLig = bdest.getNumLigne();
                depCol = bdest.getNumCol();

                this.piece = new Cavalier(bdest, choixCav);

                bdest.ImageAj(piece.GetImg());

                DD.FermerDispo(depLig, depCol);

                jouLig = depLig;
                jouCol = depCol;

                dpl[cpClic] = bdest;
                ++cpClic;

                CibleAj(bdest, this.piece);
            }
        }
コード例 #14
0
        //  Parcours de la piece (cavalier) sur l'échiquier à partir d une case donnee
        private void IAchoixRemplissage(monBouton b)
        {
            //initialisation
            InitialisationIAChoix();
            InitialisationDamierNum();

            //simulation
            int ii = b.getNumLigne() - 1;
            int jj = b.getNumCol() - 1;

            piece = new Cavalier(b, choixCav);
            int[]  depi  = piece.GetDepi();
            int [] depj  = piece.GetDepj();
            Euler  euler = new Euler(depi, depj);

            damierNum = euler.getEchec(ii, jj);

            int       rangBouton;
            monBouton btmp;

            for (int i = 0; i < damierNum.GetLength(0); ++i)
            {
                for (int j = 0; j < damierNum.GetLength(1); ++j)
                {
                    // on ne veut pas certaines des 12*12 cases ( 0 et -1)
                    if (damierNum[i, j] >= 1)
                    {
                        //extraction
                        rangBouton = damierNum[i, j]; //rang allant de 1 à 64
                        btmp       = DD.GetMonBouton(i, j);
                        //assignation
                        IAchoix[rangBouton - 1]        = btmp; //(rang-1) allant de 0 à 63
                        IAchoixLigne[rangBouton - 1]   = btmp.getNumLigne();
                        IAchoixColonne[rangBouton - 1] = btmp.getNumCol();
                    }
                }
            }
        }
コード例 #15
0
        // ******************** BOUTON PANNEAU RECOMMENCER **********************
        private void boutonRecommencer_Click(object sender, EventArgs e)
        {
            if (sender is Button)
            {
                boutonDepart.Visible   = true;
                boutonRetour.Visible   = false;
                labelVict.Visible      = false;
                victoire               = false;
                boutonSolution.Visible = false;

                cpClic   = 0;
                cpRtClic = 0;
                entamer  = false;
                DD.ReinitialiserDamier();
                InitialiserBouton();

                //reinitialiser bouton de depart
                depCol       = -1;
                depLig       = -1;
                monBoutonDep = null;

                boutonRecommencer.Visible = false;
            }
        }
コード例 #16
0
 public bool IsDispoCible(monBouton bDepart, int depi, int depj)
 {
     return(IsDispo(bDepart.getNumLigne() + depi, bDepart.getNumCol() + depj));
 }
コード例 #17
0
ファイル: Damier.cs プロジェクト: Naedri/IHM-Cavalier
        public void MonBouton_Assombrir(int ligne, int colonne)
        {
            monBouton btmp = GetMonBouton(ligne, colonne);

            btmp.Assombrir();
        }
コード例 #18
0
ファイル: Damier.cs プロジェクト: Naedri/IHM-Cavalier
        public void MonBouton_ImageSupp(int ligne, int colonne)
        {
            monBouton btmp = GetMonBouton(ligne, colonne);

            btmp.ImageSupp();
        }
コード例 #19
0
ファイル: Damier.cs プロジェクト: Naedri/IHM-Cavalier
        public Damier(int nbrCaseCoteDamier, int tailleBoutonPX, int nbrCaseMarge, int posX, int posY, Color colorChoixCF, Color colorChoixCC)
        {
            //definition de la COULEUR du damier
            this.colorChoixCF = colorChoixCF;
            this.colorChoixCC = colorChoixCC;
            {
                // definition de TAILLE du damier
                tailleLig    = nbrCaseCoteDamier; //8 nbr de ligne
                tailleCol    = nbrCaseCoteDamier; //8 nbr de colonnes
                tailleBouton = tailleBoutonPX;    //bouton de 50 px
                tailleLabel  = tailleBoutonPX / 2;
                tailleMarge  = nbrCaseMarge;      //2 bouton de marge par cote

                //definition de POSITION du damier
                this.posY = posY;
                this.posX = posX;

                //Definition de la taille de la grille contenant bouton
                grille = new monBouton[tailleLig + (tailleMarge * 2), tailleCol + (tailleMarge * 2)];

                //Definition de la taille de la table labels contenant les labels
                labels = new Label[tailleLig + tailleCol];
                int il = 0; //indice pour inserrer un label

                //Création du damier. On remplit de boutons la grille de boutons.
                for (int ligne = 0; ligne < grille.GetLength(0); ++ligne)
                {
                    for (int colonne = 0; colonne < grille.GetLength(1); ++colonne)
                    {
                        // ********** BOUTON ************

                        monBouton b = new monBouton(ligne, colonne, colorChoixCF, colorChoixCC);  //j'enregistre un numéro de colonne et de ligne pour chacun de mes boutons

                        if (ligne >= tailleMarge && ligne < (tailleMarge + tailleLig))

                        {
                            if (colonne >= tailleMarge && colonne < (tailleMarge + tailleCol))
                            {
                                b.Size     = new Size(tailleBouton, tailleBouton);                                                                          //Je fais des boutons carrés
                                b.Visible  = true;
                                b.Location = new Point(1 + (colonne - tailleMarge) * tailleBouton + posX, 1 + (ligne - tailleMarge) * tailleBouton + posY); //1 pour avoir un peu d'espace

                                // ******** Background couleur des cellule *******
                                b.Colorer();
                            }
                            else
                            {
                                b.Size    = new Size(0, 0); //si le bouton est en dehors du damier
                                b.Visible = false;
                                //b.Text = "dehors";
                            }
                        }
                        else
                        {
                            b.Size    = new Size(0, 0); //si le bouton est en dehors du damier
                            b.Visible = false;
                            //b.Text = "dehors";
                        }

                        //b.Text = "l" + b.getNumLigne() + 'c' + b.getNumCol(); //identification des boutons
                        grille[ligne, colonne] = b; //On remplit la grille de boutons
                    }
                }

                // ********** LABEL ************
                for (int ligne = 0; ligne < grille.GetLength(0); ++ligne)
                {
                    if (ligne >= tailleMarge && ligne < (tailleMarge + tailleLig))
                    {
                        //ligne
                        Label labelLigne = new Label();
                        labelLigne.Location = new Point(tailleCol * tailleBouton + 1 + posX, 20 + tailleBouton * (ligne - tailleMarge) + posY);
                        labelLigne.Size     = new Size(tailleLabel, tailleLabel);
                        labelLigne.Text     = "" + (ligne - tailleMarge + 1);
                        //ajout dans la table labels
                        labels[il] = labelLigne;
                        ++il;
                    }
                }
                for (int colonne = 0; colonne < grille.GetLength(1); ++colonne)
                {
                    if (colonne >= tailleMarge && colonne < (tailleMarge + tailleCol))
                    {
                        //colonne
                        Label labelColonne = new Label();
                        labelColonne.Location = new Point(20 + tailleBouton * (colonne - tailleMarge) + posX, tailleLig * tailleBouton + 1 + posY);
                        labelColonne.Size     = new Size(tailleLabel, tailleLabel); //ATTENTION les labels peuvent ne pas apparaitre à cause de leur taille par défaut et des distances mises entre ceux-ci
                        labelColonne.Text     = "" + (colonne - tailleMarge + 1);
                        //ajout dans la table labels
                        labels[il] = labelColonne;
                        ++il;
                    }
                }
            }
        }
コード例 #20
0
ファイル: Damier.cs プロジェクト: Naedri/IHM-Cavalier
        public void MonBouton_ImageAj(int ligne, int colonne, Image img)
        {
            monBouton btmp = GetMonBouton(ligne, colonne);

            btmp.ImageAj(img);
        }
コード例 #21
0
ファイル: Damier.cs プロジェクト: Naedri/IHM-Cavalier
 internal void UnSetButtonCible(monBouton bDepart, int depi, int depj)
 {
     grille[bDepart.getNumLigne() + depi, bDepart.getNumCol() + depj].Text = "";
 }
コード例 #22
0
 private void ReduireActionBouton(monBouton b)
 {
     //b.MouseEnter -= new System.EventHandler(this.Buttons_MouseEnter);
     //b.MouseLeave -= new System.EventHandler(this.Buttons_MouseLeave);
 }
コード例 #23
0
 private void SuppActionBouton(monBouton b)
 {
     b.Click -= new System.EventHandler(this.Buttons_Click);
     //b.MouseEnter -= new System.EventHandler(this.Buttons_MouseEnter);
     //b.MouseLeave -= new System.EventHandler(this.Buttons_MouseLeave);
 }
コード例 #24
0
 // ******************** BOUTON GRILLE ACTION **********************
 private void InitialiserBouton(monBouton b)
 {
     b.Click += new System.EventHandler(this.Buttons_Click); //Associe le bouton b à l'évenement "buttons_click" définit ci-dessous
     //b.MouseEnter += new System.EventHandler(this.Buttons_MouseEnter);
     //b.MouseLeave += new System.EventHandler(this.Buttons_MouseLeave);
 }