Ejemplo n.º 1
0
 void step_Click(object sender, RoutedEventArgs e)
 {
     if (shagNas.Count == 0)
     {
         MessageBox.Show("Игра в изначальном состоянии");
     }
     else
     {
         int[]         sn  = shagNas[shagNas.Count - 1];
         Puzzle_Button pb  = PB[sn[0]];
         Puzzle_Button pb2 = PB[sn[1]];
         int           c   = pb2.Col;
         int           r   = pb2.Row;
         pb2.Col = pb.Col;
         Grid.SetColumn(pb2, pb.Col);
         pb2.Row = pb.Row;
         Grid.SetRow(pb2, pb.Row);
         pb.Col = c;
         Grid.SetColumn(pb, c);
         pb.Row = r;
         Grid.SetRow(pb, r);
         pb2.naj        = false;
         pb2.Background = null;
         pb2.mest       = false;
         pb.naj         = false;
         pb.Background  = null;
         pb.mest        = false;
         shagNas.RemoveAt(shagNas.Count - 1);
     }
 }
Ejemplo n.º 2
0
        void Puz_Click(object sender, RoutedEventArgs e)
        {
            Puzzle_Button pb = (Puzzle_Button)sender;

            if (pb.mest == false)
            {
                if (pb.naj == true)
                {
                    pb.Background = null;
                    pb.naj        = false;
                }
                else
                {
                    Puzzle_Button pb2 = pb;
                    foreach (Puzzle_Button elem in PB)
                    {
                        if (elem.naj == true)
                        {
                            pb2 = elem;
                            break;
                        }
                    }
                    if (pb2 == pb)
                    {
                        pb.Background = new SolidColorBrush(Colors.Blue);
                        pb.naj        = true;
                    }
                    else
                    {
                        int c = pb2.Col;
                        int r = pb2.Row;
                        pb2.Col = pb.Col;
                        Grid.SetColumn(pb2, pb.Col);
                        pb2.Row = pb.Row;
                        Grid.SetRow(pb2, pb.Row);
                        pb.Col = c;
                        Grid.SetColumn(pb, c);
                        pb.Row = r;
                        Grid.SetRow(pb, r);
                        pb2.naj        = false;
                        pb2.Background = null;
                        if (pb.Col == pb.nCol && pb.Row == pb.nRow)
                        {
                            pb.mest       = true;
                            pb.Background = new SolidColorBrush(Colors.LightGreen);
                        }
                        if (pb2.Col == pb2.nCol && pb2.Row == pb2.nRow)
                        {
                            pb2.mest       = true;
                            pb2.Background = new SolidColorBrush(Colors.LightGreen);
                        }
                        int[] sn = new int[2];
                        sn[0] = pb.ind;
                        sn[1] = pb2.ind;
                        shagNas.Add(sn);
                        prov();
                    }
                }
            }
        }
Ejemplo n.º 3
0
        void fill_grid(int i, string pic)
        {
            int picnumber;
            int size = 0;

            if (i == 3)
            {
                size = 140;
            }
            if (i == 4)
            {
                size = 105;
            }
            if (i == 5)
            {
                size = 84;
            }
            for (int i2 = 0; i2 < i; i2++)
            {
                RowDefinition nrow = new RowDefinition();
                nrow.Height = new GridLength();
                GameGrid.RowDefinitions.Add(nrow);
                for (int j = 0; j < i; j++)
                {
                    picnumber = i * i2 + j + 1;
                    ColumnDefinition ncol = new ColumnDefinition();
                    ncol.Width = new GridLength();
                    GameGrid.ColumnDefinitions.Add(ncol);
                    string        fullpath = path + "/image/" + pic + "/" + Convert.ToString(i) + "/(" + Convert.ToString(picnumber) + ").jpg";
                    Puzzle_Button nBut     = new Puzzle_Button();
                    nBut.nRow     = i2;
                    nBut.nCol     = j;
                    nBut.Col      = j;
                    nBut.Row      = i2;
                    nBut.Width    = size;
                    nBut.Height   = size;
                    nBut.Click   += new RoutedEventHandler(Puz_Click);
                    nBut.img_path = fullpath;
                    nBut.ind      = picnumber - 1;
                    Image im = new Image();
                    System.Windows.Media.Imaging.BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage();
                    bi.BeginInit();
                    bi.UriSource = new Uri(fullpath);
                    bi.EndInit();
                    im.Source = bi;
                    im.Width  = size - 10;
                    im.Height = size - 10;
                    im.HorizontalAlignment = HorizontalAlignment.Center;
                    im.VerticalAlignment   = VerticalAlignment.Center;
                    nBut.Content           = im;
                    PB.Add(nBut);
                    GameGrid.Children.Add(nBut);
                }
            }
            perem(PB, i);
        }
Ejemplo n.º 4
0
        void Load_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.FileName   = "Save";
            dlg.DefaultExt = ".txt";
            dlg.Title      = "Загрузка сохранения";
            dlg.Filter     = "Text documents (.txt)|*.txt";
            dlg.ShowDialog();
            string path = dlg.FileName;

            if (dlg.FileName == "Save")
            {
                MessageBox.Show("Не выбрано сохранение");
            }
            else
            {
                GameGrid.Children.Clear();
                PB.Clear();
                shagNas.Clear();
                using (StreamReader sw = new StreamReader(path))
                {
                    shag        = Convert.ToInt32(sw.ReadLine());
                    shL.Content = "Количество шагов: " + Convert.ToString(shag);
                    int pbCount = Convert.ToInt32(sw.ReadLine());
                    for (int j = 0; j < pbCount; j++)
                    {
                        string   stpb = sw.ReadLine();
                        string[] mas  = stpb.Split('`');
                        int      size = 0;
                        if (pbCount == 9)
                        {
                            for (int i = 0; i < 3; i++)
                            {
                                ColumnDefinition ncol = new ColumnDefinition();
                                ncol.Width = new GridLength();
                                GameGrid.ColumnDefinitions.Add(ncol);
                                RowDefinition nrow = new RowDefinition();
                                nrow.Height = new GridLength();
                                GameGrid.RowDefinitions.Add(nrow);
                            }

                            size = 140;
                        }
                        if (pbCount == 16)
                        {
                            for (int i = 0; i < 4; i++)
                            {
                                ColumnDefinition ncol = new ColumnDefinition();
                                ncol.Width = new GridLength();
                                GameGrid.ColumnDefinitions.Add(ncol);
                                RowDefinition nrow = new RowDefinition();
                                nrow.Height = new GridLength();
                                GameGrid.RowDefinitions.Add(nrow);
                            }
                            size = 105;
                        }
                        if (pbCount == 25)
                        {
                            for (int i = 0; i < 5; i++)
                            {
                                ColumnDefinition ncol = new ColumnDefinition();
                                ncol.Width = new GridLength();
                                GameGrid.ColumnDefinitions.Add(ncol);
                                RowDefinition nrow = new RowDefinition();
                                nrow.Height = new GridLength();
                                GameGrid.RowDefinitions.Add(nrow);
                            }
                            size = 84;
                        }
                        Puzzle_Button nBut = new Puzzle_Button();
                        nBut.mest = Convert.ToBoolean(mas[0]);
                        if (nBut.mest)
                        {
                            nBut.Background = new SolidColorBrush(Colors.LightGreen);
                        }
                        nBut.naj = Convert.ToBoolean(mas[1]);
                        if (nBut.naj)
                        {
                            nBut.Background = new SolidColorBrush(Colors.Blue);
                        }
                        nBut.nRow     = Convert.ToInt32(mas[5]);
                        nBut.nCol     = Convert.ToInt32(mas[4]);
                        nBut.Col      = Convert.ToInt32(mas[2]);
                        nBut.Row      = Convert.ToInt32(mas[3]);
                        nBut.Width    = size;
                        nBut.Height   = size;
                        nBut.Click   += new RoutedEventHandler(Puz_Click);
                        nBut.img_path = mas[7];
                        nBut.ind      = Convert.ToInt32(mas[6]);
                        Image im = new Image();
                        System.Windows.Media.Imaging.BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage();
                        bi.BeginInit();
                        bi.UriSource = new Uri(mas[7]);
                        bi.EndInit();
                        im.Source = bi;
                        im.Width  = size - 10;
                        im.Height = size - 10;
                        im.HorizontalAlignment = HorizontalAlignment.Center;
                        im.VerticalAlignment   = VerticalAlignment.Center;
                        nBut.Content           = im;
                        PB.Add(nBut);
                        GameGrid.Children.Add(nBut);
                        Grid.SetColumn(nBut, nBut.Col);
                        Grid.SetRow(nBut, nBut.Row);
                    }
                    int shNcount = Convert.ToInt32(sw.ReadLine());
                    for (int j = 0; j < shNcount; j++)
                    {
                        string[] mas = sw.ReadLine().Split('`');
                        int[]    sn  = new int[2];
                        sn[0] = Convert.ToInt32(mas[0]);
                        sn[1] = Convert.ToInt32(mas[1]);
                        shagNas.Add(sn);
                    }
                    zi = Convert.ToInt32(sw.ReadLine());
                    zp = sw.ReadLine();
                    zp = zp;
                }
            }
        }