private void ResetForNewGame() { while (this.AllTile.Count > 0) { this.AllTile.RemoveAt(0); } this.ActualGameStade = GameStade.sNothingHappening; List <oTile> NewTile = oGridGenerator.GetRandom3x3Grid(); foreach (oTile t in NewTile) { this.AllTile.Add(t); } }
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(); //} }