Example #1
0
 public static void save(gameshape gs, string file)
 {
     Stream f = File.Open(file,FileMode.Create);
     BinaryFormatter b = new BinaryFormatter();
     b.Serialize(f, gs);
     f.Close();
 }
Example #2
0
        public void movenum(int toadox, int toadoy)
        {
            try
            {

                int tang = (int)Math.Sqrt(m);
                int count = 0;
                int so1 = (toadoy * tang) + toadox;
                int toadoy1 = (int)(num[m - 1].postion / tang);
                int toadox1 = (int)num[m - 1].postion - (toadoy1 * tang);
                int so2 = num[m - 1].postion;

                if (toadoy1 == toadoy)
                {

                    if (so2 > so1)
                    {
                        moves += 1;
                        count = so2;
                        this.swap(count, count - 1);

                    }
                    if (so2 < so1)
                    {
                        moves += 1;
                        count = so2;
                        this.swap(count, count + 1);

                    }
                }
                if (toadox == toadox1)
                {

                    if (so2 > so1)
                    {
                        moves += 1;
                        count = so2;
                        this.swap(count, count - tang);
                    }
                    if (so2 < so1)
                    {
                        moves += 1;
                        count = so2;
                        this.swap(count, count + tang);

                    }
                }
                bool win = true;
                for (int i = 0; i < m; i++)
                {
                    if (num[i].postion != i)
                    {
                        win = false;
                        break;

                    }
                }
                if (win)
                {
                    MessageBox.Show(" Ban Da chien thang *-* ", "Winner");
                    timer1.Stop();
                    lbl1.Text = "Thanh Cong";
                    new Name().ShowDialog();

                }
                lbltool.Text = "Moves :" + moves;
                gshape = new gameshape(num, moves, gio, phut, giay,m);
            }
            catch (Exception ex)
            {
                MessageBox.Show("loi:" + ex.ToString());
            }
        }