Example #1
0
        public static int TileWidth = 64;         // 64 laugeur et hauteur d'une tile

        //en fonction des parametre d'une tuile, il cree un bitmap 64x64 qui contien les nombre de la tuile avec les bonne couleur
        public static Bitmap GetBitmapForTile(oTile TheTile)
        {
            int      twidth = oTile.TileWidth;
            Bitmap   img    = new Bitmap(twidth, twidth);
            Graphics g      = Graphics.FromImage(img);

            g.Clear(Color.White);

            Bitmap imgUp    = oTile.GetBitmapForTriangle(TheTile.TriUp);
            Bitmap imgDown  = oTile.GetBitmapForTriangle(TheTile.TriDown);
            Bitmap imgRight = oTile.GetBitmapForTriangle(TheTile.TriRight);
            Bitmap imgLeft  = oTile.GetBitmapForTriangle(TheTile.TriLeft);

            g.DrawImage(imgUp, 0, 0);
            g.DrawImage(imgDown, 0, 0);
            g.DrawImage(imgRight, 0, 0);
            g.DrawImage(imgLeft, 0, 0);


            Pen DiagoPen = new Pen(Color.Black, 2f);

            g.DrawLine(DiagoPen, 0, 0, twidth, twidth);
            g.DrawLine(DiagoPen, 0, twidth, twidth, 0);

            Pen BorderPen = new Pen(Color.Black, 1f);

            g.DrawRectangle(BorderPen, 0, 0, twidth - 1, twidth - 1);


            g.Dispose();
            return(img);
        }
Example #2
0
        private oTile GetTheMovingTile()
        {
            oTile rep = null;

            foreach (oTile ActualTile in this.AllTile)
            {
                if (ActualTile.IsMoving)
                {
                    rep = ActualTile;
                    break;
                }
            }
            return(rep);
        }
Example #3
0
        private oTile GetTileAtPos(oTile.TilePos ThePos)
        {
            oTile rep = null;

            foreach (oTile ActualTile in this.AllTile)
            {
                if (ActualTile.pos.x == ThePos.x && ActualTile.pos.y == ThePos.y && ActualTile.pos.parent == ThePos.parent)
                {
                    rep = ActualTile;
                    break;
                }
            }
            return(rep);
        }
Example #4
0
        public static List <oTile> GetRandom3x3Grid()
        {
            oTile[,] TileGrid = new oTile[3, 3];
            for (int y = 0; y <= 2; y++)
            {
                for (int x = 0; x <= 2; x++)
                {
                    TileGrid[x, y] = new oTile();

                    //la position n'est pas defini car elle doit etre defini aleatoirement

                    ////test
                    //TileGrid[x, y].pos = new oTile.TilePos(x, y, oTile.GridParent.gStart);
                }
            }

            //generation aleatoire des arrete interieur
            //verticale
            for (int y = 0; y <= 2; y++)
            {
                for (int x = 0; x <= 1; x++)
                {
                    int newn = oGridGenerator.GetRandomTriNumber();
                    TileGrid[x, y].TriRight.TheNumber    = newn;
                    TileGrid[x + 1, y].TriLeft.TheNumber = newn;
                }
            }
            //horizontale
            for (int y = 0; y <= 1; y++)
            {
                for (int x = 0; x <= 2; x++)
                {
                    int newn = oGridGenerator.GetRandomTriNumber();
                    TileGrid[x, y].TriDown.TheNumber   = newn;
                    TileGrid[x, y + 1].TriUp.TheNumber = newn;
                }
            }

            //generation aleatoire des bordule
            //verticale
            for (int y = 0; y <= 2; y++)
            {
                TileGrid[0, y].TriLeft.TheNumber  = oGridGenerator.GetRandomTriNumber();
                TileGrid[2, y].TriRight.TheNumber = oGridGenerator.GetRandomTriNumber();
            }
            //horizontale
            for (int x = 0; x <= 2; x++)
            {
                TileGrid[x, 0].TriUp.TheNumber   = oGridGenerator.GetRandomTriNumber();
                TileGrid[x, 2].TriDown.TheNumber = oGridGenerator.GetRandomTriNumber();
            }


            //definition aleatoire de la position des case
            List <oTile.TilePos> AllTilePos = new List <oTile.TilePos>();

            for (int y = 0; y <= 2; y++)
            {
                for (int x = 0; x <= 2; x++)
                {
                    oTile.TilePos newtilepos = new oTile.TilePos(x, y, oTile.GridParent.gStart);
                    AllTilePos.Add(newtilepos);
                }
            }

            Random rnd = module.rnd;

            for (int y = 0; y <= 2; y++)
            {
                for (int x = 0; x <= 2; x++)
                {
                    //optien un index aleatoire
                    int rndindex = 0;
                    rndindex = rnd.Next(0, AllTilePos.Count - 1);

                    oTile.TilePos tp = AllTilePos[rndindex];
                    AllTilePos.RemoveAt(rndindex);

                    TileGrid[x, y].pos = tp;
                }
            }



            //end
            List <oTile> rep = new List <oTile>();

            for (int y = 0; y <= 2; y++)
            {
                for (int x = 0; x <= 2; x++)
                {
                    TileGrid[x, y].RefreshImage();
                    rep.Add(TileGrid[x, y]);
                }
            }
            return(rep);
        }
Example #5
0
        private void ImageBox_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Point mpos = this.MousePos;
                int   w2   = this.ImgWidth / 2;             //pour savoir quelle grille il faut chercker

                //======== si aucune tile est en deplacement
                if (this.ActualGameStade == GameStade.sNothingHappening)
                {
                    if (mpos.X < w2)
                    {
                        oVirtualGrid.CasePos CaseUnderM = this.GridRep.GetCaseUnderPoint(mpos.X, mpos.Y);
                        if (CaseUnderM.Exist && CaseUnderM.x <= 2 && CaseUnderM.y <= 2)
                        {
                            oTile.TilePos tp = new oTile.TilePos(CaseUnderM.x, CaseUnderM.y, oTile.GridParent.gRep);
                            //check s'il y a une tile a cette case
                            if (this.IsAnyTileAtPos(tp))
                            {
                                oTile TheClickedTile = this.GetTileAtPos(tp);
                                TheClickedTile.SavePos();
                                TheClickedTile.IsMoving = true;
                                //ce changement de coordonner sert a degager la tile des grille au cas ou le joueur la remet a la meme place
                                TheClickedTile.pos.x = -1;
                                TheClickedTile.pos.y = -1;
                                this.ActualGameStade = GameStade.sTileMoving;
                            }
                        }
                    }
                    if (mpos.X > w2)
                    {
                        oVirtualGrid.CasePos CaseUnderM = this.GridStart.GetCaseUnderPoint(mpos.X, mpos.Y);
                        if (CaseUnderM.Exist && CaseUnderM.x <= 2 && CaseUnderM.y <= 2)
                        {
                            oTile.TilePos tp = new oTile.TilePos(CaseUnderM.x, CaseUnderM.y, oTile.GridParent.gStart);
                            //check s'il y a une tile a cette case
                            if (this.IsAnyTileAtPos(tp))
                            {
                                oTile TheClickedTile = this.GetTileAtPos(tp);
                                TheClickedTile.SavePos();
                                TheClickedTile.IsMoving = true;
                                //ce changement de coordonner sert a degager la tile des grille au cas ou le joueur la remet a la meme place
                                TheClickedTile.pos.x = -1;
                                TheClickedTile.pos.y = -1;
                                this.ActualGameStade = GameStade.sTileMoving;
                            }
                        }
                    }
                }
                // /!\ /!\ /!\ IL EST TRES IMPORTANT QUE CE SOIT UN ELSE car lorsqu'une case est clicker pour commencer un deplacement, this.ActualGameStade devien sTileMoving et il ne faut pas que le code de relachement de la tile s'execute immediatement apres
                else                 //========= si une tile est en deplacement
                {
                    oTile TheMovingTile = this.GetTheMovingTile();

                    if (mpos.X < w2)
                    {
                        oVirtualGrid.CasePos cp = this.GridRep.GetCaseUnderPoint(mpos.X, mpos.Y);
                        if (cp.Exist && cp.x <= 2 && cp.y <= 2)
                        {
                            oTile.TilePos tp = new oTile.TilePos(cp.x, cp.y, oTile.GridParent.gRep);
                            //check s'il y a deja une tile en dessous
                            bool  IsAnyTile    = this.IsAnyTileAtPos(tp);
                            oTile TheTileUnder = this.GetTileAtPos(tp);
                            if (!IsAnyTile)
                            {
                                TheMovingTile.pos.x      = tp.x;
                                TheMovingTile.pos.y      = tp.y;
                                TheMovingTile.pos.parent = tp.parent;
                                TheMovingTile.IsMoving   = false;
                                this.ActualGameStade     = GameStade.sNothingHappening;
                                this.EasyResetGameIfOk();
                            }
                            else
                            {
                                //oTile.TilePos temppos = TheMovingTile.pos;
                                TheMovingTile.pos      = TheTileUnder.pos;
                                TheTileUnder.pos       = TheMovingTile.savedpos;
                                TheMovingTile.IsMoving = false;
                                this.ActualGameStade   = GameStade.sNothingHappening;
                                this.EasyResetGameIfOk();
                            }
                        }
                    }
                    if (mpos.X > w2)
                    {
                        oVirtualGrid.CasePos cp = this.GridStart.GetCaseUnderPoint(mpos.X, mpos.Y);
                        if (cp.Exist && cp.x <= 2 && cp.y <= 2)
                        {
                            oTile.TilePos tp = new oTile.TilePos(cp.x, cp.y, oTile.GridParent.gStart);
                            //check s'il y a deja une tile en dessous
                            bool  IsAnyTile    = this.IsAnyTileAtPos(tp);
                            oTile TheTileUnder = this.GetTileAtPos(tp);
                            if (!IsAnyTile)
                            {
                                TheMovingTile.pos.x      = tp.x;
                                TheMovingTile.pos.y      = tp.y;
                                TheMovingTile.pos.parent = tp.parent;
                                TheMovingTile.IsMoving   = false;
                                this.ActualGameStade     = GameStade.sNothingHappening;
                                this.EasyResetGameIfOk();
                            }
                            else
                            {
                                TheMovingTile.pos      = TheTileUnder.pos;
                                TheTileUnder.pos       = TheMovingTile.savedpos;
                                TheMovingTile.IsMoving = false;
                                this.ActualGameStade   = GameStade.sNothingHappening;
                                this.EasyResetGameIfOk();
                            }
                        }
                    }
                }
            }
            this.Refresh();

            ////aucune tile ne doit etre en deplacement car les coordonner negative des tile en movement vont generer des erreur
            //if (this.ActualGameStade != GameStade.sTileMoving)
            //{
            //	this.EasyResetGameIfOk();
            //}
        }
Example #6
0
        public void Refresh()
        {
            Bitmap   img = new Bitmap(this.ImgWidth, this.ImgHeight);
            Graphics g   = Graphics.FromImage(img);

            g.Clear(Color.Gray);

            //dessine les grille
            for (int y = 0; y <= 2; y++)
            {
                for (int x = 0; x <= 2; x++)
                {
                    Rectangle ActualCaseRep   = this.GridRep.GetCasePosition(x, y);
                    Rectangle ActualCaseStart = this.GridStart.GetCasePosition(x, y);
                    g.FillRectangle(Brushes.Gainsboro, ActualCaseRep);
                    g.FillRectangle(Brushes.Gainsboro, ActualCaseStart);
                }
            }



            //lorsqu'une tile est en mouvement, il aparait dans la case sous la tile un petit rectangle foncer. il doit etre dessiner avant toute les tile pour qu'il soit dessous
            if (this.ActualGameStade == GameStade.sTileMoving)
            {
                Point mpos = this.MousePos;
                int   w2   = this.ImgWidth / 2;
                if (mpos.X < w2)
                {
                    oVirtualGrid.CasePos cp = this.GridRep.GetCaseUnderPoint(mpos.X, mpos.Y);
                    if (cp.Exist && cp.x <= 2 && cp.y <= 2)
                    {
                        Rectangle TheZone = this.GridRep.GetCasePosition(cp.x, cp.y);
                        TheZone.Width  -= 1;
                        TheZone.Height -= 1;
                        TheZone.Inflate(-5, -5);
                        g.DrawRectangle(Pens.DimGray, TheZone);
                        TheZone.Inflate(-1, -1);
                        g.DrawRectangle(Pens.DimGray, TheZone);
                    }
                }
                if (mpos.X > w2)
                {
                    oVirtualGrid.CasePos cp = this.GridStart.GetCaseUnderPoint(mpos.X, mpos.Y);
                    if (cp.Exist && cp.x <= 2 && cp.y <= 2)
                    {
                        Rectangle TheZone = this.GridStart.GetCasePosition(cp.x, cp.y);
                        TheZone.Width  -= 1;
                        TheZone.Height -= 1;
                        TheZone.Inflate(-5, -5);
                        g.DrawRectangle(Pens.DimGray, TheZone);
                        TheZone.Inflate(-1, -1);
                        g.DrawRectangle(Pens.DimGray, TheZone);
                    }
                }
            }

            //dessine les tuile
            //cette gestion de la tile en movement est obligatoire pour qu'elle soit dessiner par dessus toute les autre
            oTile TheMovingTile = null;
            bool  IsAMovingTile = false;

            foreach (oTile ActualTile in this.AllTile)
            {
                if (!ActualTile.IsMoving)
                {
                    if (ActualTile.pos.parent == oTile.GridParent.gRep)
                    {
                        Rectangle ActualTilePos = this.GridRep.GetCasePosition(ActualTile.pos.x, ActualTile.pos.y);
                        g.DrawImage(ActualTile.ActualImage, ActualTilePos.Location);
                    }
                    if (ActualTile.pos.parent == oTile.GridParent.gStart)
                    {
                        Rectangle ActualTilePos = this.GridStart.GetCasePosition(ActualTile.pos.x, ActualTile.pos.y);
                        g.DrawImage(ActualTile.ActualImage, ActualTilePos.Location);
                    }
                }
                else
                {
                    TheMovingTile = ActualTile;
                    IsAMovingTile = true;
                }
            }
            if (IsAMovingTile)
            {
                Point mpos      = this.MousePos;
                int   demiwidth = oTile.TileWidth / 2;
                Point tilepos   = new Point(mpos.X - demiwidth, mpos.Y - demiwidth);
                g.DrawImage(TheMovingTile.ActualImage, tilepos);
            }



            g.Dispose();
            if (this.ImageBox.Image != null)
            {
                this.ImageBox.Image.Dispose();
            }
            this.ImageBox.Image  = img;
            this.ImageBox.Width  = this.ImgWidth;
            this.ImageBox.Height = this.ImgHeight;
            GC.Collect();
        }
Example #7
0
        //check si le joueur a terminer le jeu
        private bool IsGameCleared()
        {
            bool rep = true;

            foreach (oTile t in this.AllTile)
            {
                if (t.pos.parent == oTile.GridParent.gStart)
                {
                    rep = false;
                    break;
                }
            }

            if (rep)
            {
                //transfere toute les tile dans une grille pour l'analyse des arrete
                oTile[,] TileGrid = new oTile[3, 3];
                foreach (oTile t in this.AllTile)
                {
                    TileGrid[t.pos.x, t.pos.y] = t;
                }

                //analyse si les arrete corresponde
                //horizontale
                for (int y = 0; y <= 2; y++)
                {
                    for (int x = 0; x <= 1; x++)
                    {
                        if (TileGrid[x, y].TriRight.TheNumber != TileGrid[x + 1, y].TriLeft.TheNumber)
                        {
                            rep = false;
                            break;
                        }
                    }
                    if (!rep)
                    {
                        break;
                    }
                }
                if (rep)
                {
                    //verticale
                    for (int y = 0; y <= 1; y++)
                    {
                        for (int x = 0; x <= 2; x++)
                        {
                            if (TileGrid[x, y].TriDown.TheNumber != TileGrid[x, y + 1].TriUp.TheNumber)
                            {
                                rep = false;
                                break;
                            }
                        }
                        if (!rep)
                        {
                            break;
                        }
                    }
                }
            }

            return(rep);
        }