Beispiel #1
0
        /*---------------------------Fonctions Diverses----------------------------------*/

        void DeplacementPiece()
        {
            PictureBox pic = toutesImagesVisuelles[_yPosition, _xPosition];

            TypeBloc[,] grilleAvecBloc = ChoixPiece(pieceGenerer);
            for (int iPos = 0; iPos < grilleJeu.GetLength(0); iPos++)
            {
                for (int jPos = 0; jPos < grilleJeu.GetLength(1); jPos++)
                {
                    if (grilleJeu[_yPosition + iPos - 1, _xPosition + jPos - 1] != TypeBloc.None)
                    {
                        grilleJeu[_yPosition + iPos - 1, _xPosition + jPos - 1] = TypeBloc.None;
                        pic           = toutesImagesVisuelles[_yPosition + iPos - 1, _xPosition + jPos - 1];
                        pic.BackColor = Color.Black;
                    }
                }
            }

            for (int iPos = 0; iPos < grilleAvecBloc.GetLength(0); iPos++)
            {
                for (int jPos = 0; jPos < grilleAvecBloc.GetLength(1); jPos++)
                {
                    if (_yPosition + iPos < 20 && grilleAvecBloc[iPos, jPos] != TypeBloc.None)
                    {
                        grilleJeu[_yPosition + iPos, _xPosition + jPos] = pieceGenerer;
                        pic           = toutesImagesVisuelles[_yPosition + iPos, _xPosition + jPos];
                        pic.BackColor = Color.Green;
                    }
                }
            }
        }
Beispiel #2
0
        TypeBloc[,] PositionnerBlocSurGrille(TypeBloc pieceChoisis)
        {
            PictureBox pic = toutesImagesVisuelles[_yPosition, _xPosition];

            TypeBloc[,] grilleJeu      = InitialiserSurfaceDeJeu();
            TypeBloc[,] grilleAvecBloc = ChoixPiece(pieceChoisis);
            _xPosition = _xPosition - grilleAvecBloc.GetLength(1) / 2 - 1;
            if (grilleAvecBloc.GetLength(1) == 2)
            {
                _xPosition++;
            }
            for (int iPos = 0; iPos < grilleAvecBloc.GetLength(0); iPos++)
            {
                for (int jPos = 0; jPos < grilleAvecBloc.GetLength(1); jPos++)
                {
                    if (grilleAvecBloc[iPos, jPos] != TypeBloc.None)
                    {
                        grilleJeu[_yPosition + iPos, _xPosition + jPos] = pieceChoisis;
                        pic           = toutesImagesVisuelles[_yPosition + iPos, _xPosition + jPos];
                        pic.BackColor = Color.Green;
                    }
                }
            }
            return(grilleJeu);
        }
        //L.Kevin R.
        #endregion

        #region Boutons
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //L.Kevin R.
        private void paramètresToolStripMenuItem_Click(object sender, EventArgs e)
        {
            timerBlocDescente.Enabled = false;
            frmParametre parametre = new frmParametre();

            parametre.ShowDialog();
            DialogResult resultat = frmParametre.resultat;

            if (resultat == DialogResult.OK)
            {
                nbLignesJeu   = frmParametre.nbLignes;
                nbColonnesJeu = frmParametre.nbColonnes;
                tableauDeJeu  = new TypeBloc[nbLignesJeu, nbColonnesJeu];
                InitialiserSurfaceDeJeu(nbLignesJeu, nbColonnesJeu);
                ReinitialiserJeu();
            }
            if (resultat == DialogResult.Cancel)
            {
                timerBlocDescente.Enabled = true;
            }
            if (frmParametre.musiqueEstCheck == false)
            {
                music.Stop();
            }
            else
            {
                music.Play();
            }
        }
Beispiel #4
0
 private void Form1_Load(object sender, EventArgs e)
 {
     InitialiserSurfaceVisuelle(nbLignesJeu, nbColonnesJeu);
     grilleJeu    = InitialiserSurfaceDeJeu();
     pieceGenerer = GenererPieceAJouer();
     TypeBloc[,] TabChoixPiece = ChoixPiece(pieceGenerer);
     PositionnerBlocSurGrille(pieceGenerer);
 }
Beispiel #5
0
        /// <summary>
        /// Place bloc dans le tableau
        /// </summary>
        /// <param name="BlocChoisis"></param>
        /// <returns></returns>
        TypeBloc[,] ChoixPiece(TypeBloc BlocChoisis)
        {
            TypeBloc[,] tabRotationVide = CreationTableauRotation(BlocChoisis);
            switch (BlocChoisis)
            {
            case TypeBloc.Carré:
                tabRotationVide[0, 0] = TypeBloc.Carré;
                tabRotationVide[0, 1] = TypeBloc.Carré;
                tabRotationVide[1, 0] = TypeBloc.Carré;
                tabRotationVide[1, 1] = TypeBloc.Carré;

                break;

            case TypeBloc.J:
                tabRotationVide[0, 1] = TypeBloc.J;
                tabRotationVide[1, 1] = TypeBloc.J;
                tabRotationVide[2, 1] = TypeBloc.J;
                tabRotationVide[0, 2] = TypeBloc.J;
                break;

            case TypeBloc.L:
                tabRotationVide[0, 1] = TypeBloc.L;
                tabRotationVide[1, 1] = TypeBloc.L;
                tabRotationVide[2, 1] = TypeBloc.L;
                tabRotationVide[2, 2] = TypeBloc.L;
                break;

            case TypeBloc.Ligne:
                tabRotationVide[0, 0] = TypeBloc.Ligne;
                tabRotationVide[1, 0] = TypeBloc.Ligne;
                tabRotationVide[2, 0] = TypeBloc.Ligne;
                tabRotationVide[3, 0] = TypeBloc.Ligne;
                break;

            case TypeBloc.S:
                tabRotationVide[0, 2] = TypeBloc.S;
                tabRotationVide[1, 1] = TypeBloc.S;
                tabRotationVide[1, 2] = TypeBloc.S;
                tabRotationVide[2, 1] = TypeBloc.S;
                break;

            case TypeBloc.T:
                tabRotationVide[0, 1] = TypeBloc.T;
                tabRotationVide[1, 1] = TypeBloc.T;
                tabRotationVide[1, 2] = TypeBloc.T;
                tabRotationVide[2, 1] = TypeBloc.T;
                break;

            case TypeBloc.Z:
                tabRotationVide[0, 0] = TypeBloc.Z;
                tabRotationVide[0, 1] = TypeBloc.Z;
                tabRotationVide[1, 1] = TypeBloc.Z;
                tabRotationVide[1, 2] = TypeBloc.Z;
                break;
            }
            return(tabRotationVide);
        }
Beispiel #6
0
        //ARoy-Lachance
        //Rôle : Initialiser le tableau de jeu à zéro, c'est-à-dire rendre tous les blocs noirs.
        //Paramètre : Aucun
        //Retour : Aucun
        void InitialiserTableauDeJeu()
        {
            tableauDeJeu = new TypeBloc[nbLignesJeu, nbColonnesJeu];

            for (int i = 0; i < nbLignesJeu; i++)
            {
                for (int j = 0; j < nbColonnesJeu; j++)
                {
                    tableauDeJeu[i, j] = TypeBloc.None;
                }
            }
        }
Beispiel #7
0
 //Sam v.
 /// <summary>
 /// Initialise la surface de jeu avec les paramètres que le joueur a choisi
 /// </summary>
 void InitialiserJeu()
 {
     tableauDeJeu = new TypeBloc[nbLignes, nbColones];
     blocActifX   = new int[4];
     blocActifY   = new int[4];
     for (int i = 0; i < tableauDeJeu.GetLength(0); i++)
     {
         for (int j = 0; j < tableauDeJeu.GetLength(1); j++)
         {
             tableauDeJeu[i, j] = TypeBloc.NONE;
         }
     }
 }
Beispiel #8
0
        /// <summary>
        /// Crée un tableau de la meme grandeur que le nombre de picturebox et initialise au valeur 0 = libre, 1 = occupé par une piece gelée.
        /// </summary>
        TypeBloc[,] InitialiserSurfaceDeJeu()
        {
            grilleJeu = new TypeBloc[nbLignesJeu, nbColonnesJeu];
            int iPos;
            int jPos;

            for (iPos = 0; iPos < nbLignesJeu; iPos++)
            {
                for (jPos = 0; jPos < nbColonnesJeu; jPos++)
                {
                    grilleJeu[iPos, jPos] = TypeBloc.None;
                }
            }
            return(grilleJeu);
        }
Beispiel #9
0
 /// <summary>
 /// Fonction qui prend comme input ASD / gauche bas droit pour bouger le bloc.
 /// </summary>
 /// <param name="e"></param>
 /// <param name="grilleJeu"></param>
 void DeplacementWASD(KeyPressEventArgs e, TypeBloc[,] grilleJeu)
 {
     TypeBloc[,] grilleAvecBloc = ChoixPiece(pieceGenerer);
     // UP
     if (e.KeyChar == 'w')
     {
         if (_yPosition - 1 != 0)
         {
             _yPosition--;
         }
     }
     // Down
     if (e.KeyChar == 's')
     {
         if (_yPosition + 1 < grilleJeu.GetLength(0))
         {
             if (grilleJeu[_yPosition + 1, _xPosition] != TypeBloc.Gelé)
             {
                 _yPosition++;
                 DeplacementPiece();
             }
         }
     }
     // Right
     else if (e.KeyChar == 'd')
     {
         int iPos = grilleAvecBloc.GetLength(1);
         if (_xPosition + iPos < grilleJeu.GetLength(1) && grilleJeu[_yPosition, _xPosition + 1] != TypeBloc.Gelé)
         {
             _xPosition++;
             DeplacementPiece();
         }
     }
     // Left
     else if (e.KeyChar == 'a')
     {
         int iPos = grilleAvecBloc.GetLength(0);
         if (_xPosition != 0)
         {
             if (grilleJeu[_yPosition, _xPosition - 1] != TypeBloc.Gelé)
             {
                 _xPosition--;
                 DeplacementPiece();
             }
         }
     }
 }
Beispiel #10
0
        //A.Roy-Lachance


        //Acusteau
        ///Rôle : Recommencer la partie lorsqu'elle est terminée.
        ///Paramètre : Aucun
        ///Retour : Aucun
        void RecommencerPartie()
        {
            tableauDeJeu = new TypeBloc[nbLignesJeu, nbColonnesJeu];

            //Réinitialise le tableau de jeu
            for (int i = 0; i < nbLignesJeu - 1; i++)
            {
                for (int j = 0; j < nbColonnesJeu - 1; j++)
                {
                    tableauDeJeu[i, j] = TypeBloc.None;
                }
            }
            pointDepartY = 0;
            pointDepartX = 4;
            InitialiserSurfaceDeJeu(nbLignesJeu, nbColonnesJeu);
            AfficherJeu();
        }
Beispiel #11
0
        //Déplacement

        /// <summary>
        /// Fait descendre la piece à chaque tick (1000 millisecondes)
        /// </summary>
        void BougerPieceSurLaSurface()
        {
            bool     peutDescendre = true;
            TypeBloc pieceChoisis  = GenererPieceAJouer();

            TypeBloc[,] grilleAvecBloc = ChoixPiece(pieceChoisis);
            PictureBox pic = toutesImagesVisuelles[_yPosition, _xPosition];

            if (_yPosition < grilleJeu.GetLength(0))
            {
                if (_yPosition == grilleJeu.GetLength(0) - 1)
                {
                    //pic.BackColor = Color.White;
                    grilleJeu[_yPosition, _xPosition] = TypeBloc.Gelé;
                    _yPosition = 0;
                }
                else if (grilleJeu[_yPosition + 1, _xPosition] == TypeBloc.Gelé)
                {
                    //pic.BackColor = Color.DarkGoldenrod;
                    grilleJeu[_yPosition, _xPosition] = TypeBloc.Gelé;
                    _yPosition = 0;
                }
                else
                {
                    for (int iPos = 0; iPos < grilleAvecBloc.GetLength(0); iPos++)
                    {
                        for (int jPos = 0; jPos < grilleAvecBloc.GetLength(1); jPos++)
                        {
                            if (_yPosition > 19 && grilleJeu[_yPosition + iPos, _xPosition + jPos] != TypeBloc.None && _yPosition + iPos == nbLignesJeu - 1)
                            {
                                peutDescendre = false;
                                _yPosition    = 0;
                            }
                        }
                    }
                    if (peutDescendre == true)
                    {
                        _yPosition++;
                    }
                    DeplacementPiece();
                }
            }
        }
Beispiel #12
0
        /// <summary>
        /// Innitialise le tableau de jeu au début d'une partie
        /// </summary>
        /// <param name="nbLignes"></param>
        /// <param name="nbCols"></param>
        private void InitialiserSurfaceDeJeu(int nbLignes, int nbCols)
        {
            // Création d'une surface de jeu x colonnes par y lignes
            toutesImagesVisuelles = new PictureBox[nbLignes, nbCols];
            //Jade
            tableauEtats = new TypeBloc[nbLignes, nbCols];
            //Jade
            tableauJeu.Controls.Clear();
            tableauJeu.ColumnCount = toutesImagesVisuelles.GetLength(1);
            tableauJeu.RowCount    = toutesImagesVisuelles.GetLength(0);
            for (int i = 0; i < tableauJeu.RowCount; i++)
            {
                tableauJeu.RowStyles[i].Height = tableauJeu.Height / tableauJeu.RowCount;
                for (int j = 0; j < tableauJeu.ColumnCount; j++)
                {
                    tableauJeu.ColumnStyles[j].Width = tableauJeu.Width / tableauJeu.ColumnCount;
                    // Création dynamique des PictureBox qui contiendront les pièces de jeu
                    PictureBox newPictureBox = new PictureBox();
                    newPictureBox.Width       = tableauJeu.Width / tableauJeu.ColumnCount;
                    newPictureBox.Height      = tableauJeu.Height / tableauJeu.RowCount;
                    newPictureBox.BackColor   = Color.Black;
                    newPictureBox.Margin      = new Padding(0, 0, 0, 0);
                    newPictureBox.BorderStyle = BorderStyle.FixedSingle;
                    newPictureBox.Dock        = DockStyle.Fill;

                    // Assignation de la représentation visuelle.
                    toutesImagesVisuelles[i, j] = newPictureBox;
                    // Ajout dynamique du PictureBox créé dans la grille de mise en forme.
                    // A noter que l' "origine" du repère dans le tableau est en haut à gauche. // Modifier l'origine pour la génération des pièces lors de la partie?y
                    tableauJeu.Controls.Add(newPictureBox, j, i);
                    //Initialisation du tableau des états
                    //Jade
                    tableauEtats[i, j] = TypeBloc.None;
                    //Jade
                }
            }
        }
Beispiel #13
0
 /*------------------------Déplacement piece-----------------------*/
 /// <summary>
 /// Permet de déplacer le bloc sur la grille de jeu.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Form1_KeyPress(object sender, KeyPressEventArgs e)
 {
     grilleJeu = InitialiserSurfaceDeJeu();
     DeplacementWASD(e, grilleJeu);
 }