Пример #1
0
        private void picPuzzle_MouseDown(object sender, MouseEventArgs e)
        {
            MovingPeice = null;
            foreach (Peice peice in Peices)
            {
                if (!peice.IsHome() && peice.Contains(e.Location))
                {
                    MovingPeice = peice;
                }
            }
            if (MovingPeice == null)
            {
                return;
            }

            // Bu orunni saqlash
            MovingPoint = e.Location;

            // Move it to the top of the stack.
            Peices.Remove(MovingPeice);
            Peices.Add(MovingPeice);

            // yotkiliwatqan parchilarning teglikini qayta sizish
            Rectangle rect = MovingPeice.CurrentLocation;

            rect.Inflate(4, 4);
            MakeBackground(rect);
            DrawBoard();
        }
Пример #2
0
        // Yengi oyunni bashlash
        private void StartGame()
        {
            if (FullPicture == null)
            {
                return;
            }
            GameOver = false;
            // Herbir parchining chongluqini hisablash
            NumRows = FullPicture.Height / TargetSize;
            RowHgt  = FullPicture.Height / NumRows;
            NumCols = FullPicture.Width / TargetSize;
            ColWid  = FullPicture.Width / NumCols;
            // Yukligen resimni parchilargha aylandurush
            Random rand = new Random();

            Peices = new List <Peice>();
            for (int row = 0; row < NumRows; row++)
            {
                int hgt = RowHgt;
                if (row == NumRows - 1)
                {
                    hgt = FullPicture.Height - row * RowHgt;
                }
                for (int col = 0; col < NumCols; col++)
                {
                    int wid = ColWid;
                    if (col == NumCols - 1)
                    {
                        wid = FullPicture.Width - col * ColWid;
                    }
                    Rectangle rect      = new Rectangle(col * ColWid, row * RowHgt, wid, hgt);
                    Peice     new_peice = new Peice(FullPicture, rect);
                    // parchilarning deslepki ornini ixtiyariy belgilesh
                    new_peice.CurrentLocation = new Rectangle(
                        rand.Next(0, FullPicture.Width - wid), rand.Next(0, FullPicture.Height - hgt), wid, hgt
                        );
                    Peices.Add(new_peice);
                }
            }
            //Teglik sizish
            MakeBackground();
            // Doskini hasillash
            DrawBoard();
        }
Пример #3
0
        private void picPuzzle_MouseUp(object sender, MouseEventArgs e)
        {
            if (MovingPeice == null)
            {
                return;
            }
            // parchilar toghra ornidimu yoq?
            if (MovingPeice.SnapToHome())
            {
                Peices.Remove(MovingPeice);
                Peices.Reverse();
                Peices.Add(MovingPeice);
                Peices.Reverse();
                // oyun ayaghlashtim yoq?
                GameOver = true;
                foreach (Peice peice in Peices)
                {
                    if (!peice.IsHome())
                    {
                        GameOver = false;
                        break;
                    }
                }
            }
            // yotkleme parchilarning ornini elish
            Rectangle rect = MovingPeice.CurrentLocation;

            rect.Inflate(4, 4);
            //parchini yotkeshni toxtitish
            MovingPeice = null;
            // yotkelgen parche teglikini qayta sisizish
            if (GameOver)
            {
                MakeBackground();
            }
            else
            {
                MakeBackground(rect);
            }
            DrawBoard();
        }