Exemplo n.º 1
0
        public GameView()
        {
            GameInfo.p = pass;
            int i;
            int j;

            InitializeComponent();
            for (int k = 1; k <= 81; k++)
            {
                i         = (k - 1) / 9;
                j         = (k - 1) % 9;
                bts[i, j] = getButton(k);
            }
            CreateMap map = new CreateMap();

            maps = map.getmap();
            for (int m = 0; m < 9; m++)
            {
                for (int n = 0; n < 9; n++)
                {
                    if (passRole())
                    {
                        int z = maps[m, n];
                        bts[m, n].Text      = z.ToString();
                        bts[m, n].BackColor = getColor(z);
                        bts[m, n].Enabled   = false;
                    }
                    else
                    {
                        bts[m, n].Text      = "";
                        bts[m, n].BackColor = Color.FromArgb(255, 128, 0);
                        bts[m, n].ForeColor = Color.Red;
                        bts[m, n].Font      = new Font("宋体", 13);
                    }
                }
            }
            if (!new SqlHelper().isHaveBoard(GameInfo.p))
            {
                create_mapstring();   //保存记录
            }
            unlock();
            checkFinish();
        }
Exemplo n.º 2
0
        /**
         *
         */
        private void reload()
        {
            GameInfo.p = GameInfo.p + 1;
            new SqlHelper().saveRecord();
            CreateMap map = new CreateMap();

            maps = map.getmap(GameInfo.m, GameInfo.p);
            for (int m = 0; m < GameInfo.gnum; m++)
            {
                for (int n = 0; n < GameInfo.gnum; n++)
                {
                    if (maps[m, n] != -1)
                    {
                        int z = maps[m, n];
                        bts[m, n].Text      = z.ToString();
                        bts[m, n].BackColor = getColor(z);
                        bts[m, n].Enabled   = false;
                    }
                    else
                    {
                        bts[m, n].Text      = "";
                        bts[m, n].BackColor = Color.FromArgb(255, 128, 0);
                        bts[m, n].ForeColor = Color.Red;
                        bts[m, n].Font      = new Font("宋体", 13 * (3 - GameInfo.m));
                        bts[m, n].Enabled   = true;
                    }
                }
            }
            starttime   = DateTime.Now.Ticks;
            pass       += 1;
            label3.Text = pass.ToString();
            showTop();   //显示排名区
            if (GameInfo.m == 1)
            {
                unlock1();
            }
            else
            {
                unlock();
            }
            checkFinish();   //验证是否完成
        }
Exemplo n.º 3
0
        /**
         * 重新加载数独
         */
        private void reload()
        {
            CreateMap map = new CreateMap();

            maps = map.getmap();
            for (int m = 0; m < 9; m++)
            {
                for (int n = 0; n < 9; n++)
                {
                    if (passRole())
                    {
                        int z = maps[m, n];
                        bts[m, n].Text      = z.ToString();
                        bts[m, n].BackColor = getColor(z);
                        bts[m, n].Enabled   = false;
                    }
                    else
                    {
                        bts[m, n].Text      = "";
                        bts[m, n].BackColor = Color.FromArgb(255, 128, 0);
                        bts[m, n].ForeColor = Color.Red;
                        bts[m, n].Font      = new Font("宋体", 13);
                        bts[m, n].Enabled   = true; //必须,避免第一次设置按钮时设置为false
                    }
                }
            }
            pass       += 1;
            GameInfo.p  = pass;
            label3.Text = pass.ToString();
            if (!new SqlHelper().isHaveBoard(GameInfo.p))
            {
                create_mapstring();   //保存记录
            }
            unlock();
            checkFinish();
        }
Exemplo n.º 4
0
        public Random random = new Random();                              //随机数
        public GamePanel()
        {
            pass = GameInfo.p;
            int i;
            int j;

            InitializeComponent();
            int width = 40 * 9 / GameInfo.gnum;
            int height = 40 * 9 / GameInfo.gnum;
            int paddingx = 0, paddingy = 0;
            int q;

            if (GameInfo.gnum == 4 || GameInfo.gnum == 6)
            {
                q = 2;
            }
            else
            {
                q = 3;
            }
            int[] w = { 0, 8, 16, 24 };    //宫格间隙
            for (int k = 1; k <= GameInfo.gnum * GameInfo.gnum; k++)
            {
                i                = (k - 1) / GameInfo.gnum; //按钮横坐标
                j                = (k - 1) % GameInfo.gnum; //按钮竖坐标
                bts[i, j]        = new Button();
                bts[i, j].Text   = "";
                bts[i, j].Margin = new Padding(0, 0, 0, 0); //按钮间距离
                bts[i, j].Name   = "button" + k.ToString(); //按钮name属性
                if (i % q == 0)
                {
                    paddingx = w[i / q];
                }
                if (j % (GameInfo.gnum / q) == 0)
                {
                    paddingy = w[j / (GameInfo.gnum / q)];
                }
                bts[i, j].Location   = new Point(13 + j * height + paddingy, 36 + i * width + paddingx); //按钮在窗体中的位置
                bts[i, j].Size       = new Size(width, height);                                          //按钮大小
                bts[i, j].Font       = new System.Drawing.Font("宋体", 9 * (3 - GameInfo.m));
                bts[i, j].Click     += new EventHandler(choosemath);                                     //点击事件
                bts[i, j].MouseDown += new MouseEventHandler(mouse_right);                               //右击事件
                groupBox3.Controls.Add(bts[i, j]);
            }
            CreateMap map = new CreateMap();

            maps = map.getmap(GameInfo.m, GameInfo.p);  //获取数独内容
            for (int m = 0; m < GameInfo.gnum; m++)
            {
                for (int n = 0; n < GameInfo.gnum; n++)
                {
                    if (maps[m, n] != -1)         //固定区
                    {
                        int z = maps[m, n];
                        bts[m, n].Text      = z.ToString();
                        bts[m, n].BackColor = getColor(z);
                        bts[m, n].Enabled   = false;
                    }
                    else                          //填入区
                    {
                        bts[m, n].Text      = "";
                        bts[m, n].BackColor = Color.FromArgb(255, 128, 0);
                        bts[m, n].ForeColor = Color.Red;
                        bts[m, n].Font      = new Font("宋体", 13 * (3 - GameInfo.m));
                    }
                }
            }
            if (GameInfo.m == 1)
            {
                unlock1();
            }
            else
            {
                unlock();
            }
            showTop();       //显示排名区
            checkFinish();   //验证是否完成
        }