Example #1
0
        private void GameStart()
        {
            listBox1.Items.Clear();
            _DBData = DBLite.GetData(Application.StartupPath + "\\data.db");

            lastX           = -1;
            lastY           = -1;
            flag_BOMB       = false;
            flag_IsGameOver = false;
            _Minwper.Init(16, 16, 40);
            Draw(flag_BOMB);
        }
Example #2
0
 public Form1()
 {
     InitializeComponent();
     _Me = this;
     DBLite.Create(Application.StartupPath + "\\data.db");
 }
Example #3
0
        private void doloop()
        {
            Random crandom = new Random();

            crandom.Next();

            int    x         = crandom.Next() % (16);
            int    y         = crandom.Next() % (16);
            int    index     = -1;
            String key       = "";
            double dirCost   = -1;
            double totalCost = -1;


            while (flag_IsGameOver == false)
            {
                DataInfo info_safe = SafeNext();
                DataInfo info      = GetNextDataInfo();
                if (info_safe != null)
                {
                    x = info_safe.Row;
                    y = info_safe.Col;
                    Console.WriteLine("Safe ({0}, {1})", x, y);
                    info = null;
                }
                else if (info != null)
                {
                    Point point = info.GetSmartPoint();
                    x         = point.X;
                    y         = point.Y;
                    index     = info.SelectIndex;
                    key       = info.Key;;
                    dirCost   = info.GetFailRatio(index);
                    totalCost = info.GetFailRatio();
                }
                else
                {
                    crandom.Next();
                    x = crandom.Next() % (16);
                    y = crandom.Next() % (16);
                }


                if (_Minwper.GetStep() == 0)
                {
                    if (_Minwper.IsBomb(x, y))
                    {
                        _Minwper.FirstChange(x, y);
                    }
                }

                if (_Minwper.Progress() == 100)
                {
                    String tmp = "{\"Step" + (_Minwper.GetStep() + 1).ToString();
                    tmp += " Winner";
                    tmp += "\": {\"Key\":\"" + key + "\", ";
                    tmp += "\"Dir\":\"" + index + "\", ";
                    tmp += "\"DirCost\":\"" + dirCost + "\", ";
                    tmp += "\"TolCost\":\"" + totalCost + "\"";
                    tmp += "}}";
                    Form1.Run(_Me, new Action(() => AddList(tmp)));

                    tmp = "[";
                    for (int i = 0; i < listBox1.Items.Count; i++)
                    {
                        if (i == 0)
                        {
                            tmp += listBox1.Items[i];
                        }
                        else
                        {
                            tmp += "," + listBox1.Items[i];
                        }
                    }

                    tmp += "]";
                    DBLite.SaveStep(_Minwper.GetStep() + 1, _DBData.Count, _Minwper.Progress(), tmp);
                    flag_IsGameOver = true;
                    break;
                }

                if (_Minwper.IsBomb(x, y))
                {
                    flag_BOMB       = true;
                    flag_IsGameOver = true;
                    DBLite.SaveData(info, false);

                    if (_DBData.ContainsKey(key))
                    {
                        _DBData[key].Total[index]++;
                        _DBData[key].Fail[index]++;
                    }

                    String tmp = "{\"Step" + (_Minwper.GetStep() + 1).ToString();
                    tmp += " GamvOver";
                    tmp += "\": {\"Key\":\"" + key + "\", ";
                    tmp += "\"Dir\":\"" + index + "\", ";
                    tmp += "\"DirCost\":\"" + dirCost + "\", ";
                    tmp += "\"TolCost\":\"" + totalCost + "\"";
                    tmp += "}}";
                    Form1.Run(_Me, new Action(() => AddList(tmp)));

                    //Form1.Run(_Me, new Action(() => AddList(String.Format("{\"Step{0} GameOver\":{\"Key\":\"{1}\", \"Dir:\":{2}, \"DirCost\":{3}, \"TolCost\":{4}}}", _Minwper.GetStep() + 1, key, index, dirCost, totalCost))));

                    tmp = "[";
                    for (int i = 0; i < listBox1.Items.Count; i++)
                    {
                        if (i == 0)
                        {
                            tmp += listBox1.Items[i];
                        }
                        else
                        {
                            tmp += "," + listBox1.Items[i];
                        }
                    }

                    tmp += "]";
                    //tmp = tmp.Replace("\"", "\\\"");
                    DBLite.SaveStep(_Minwper.GetStep() + 1, _DBData.Count, _Minwper.Progress(), tmp);
                }
                else
                {
                    _Minwper.StepOn(x, y);
                    DBLite.SaveData(info, true);
                    if (_DBData.ContainsKey(key))
                    {
                        _DBData[key].Total[index]++;
                    }

                    String tmp = "{\"Step" + (_Minwper.GetStep()).ToString();
                    //tmp += " GamvOver";
                    tmp += "\": {\"Key\":\"" + key + "\", ";
                    tmp += "\"Dir\":\"" + index + "\", ";
                    tmp += "\"DirCost\":\"" + dirCost + "\", ";
                    tmp += "\"TolCost\":\"" + totalCost + "\"";
                    tmp += "}}";
                    Form1.Run(_Me, new Action(() => AddList(tmp)));
                    //Form1.Run(_Me, new Action(() => AddList(String.Format("{\"Step{0}\":{\"Key\":\"{1}\", \"Dir:\":{2}, \"DirCost\":{3}, \"TolCost\":{4}}}", _Minwper.GetStep() + 1, key, index, dirCost, totalCost))));
                }

                AutoMark();
                Form1.Run(_Me, new Action(() => Draw(flag_BOMB)));

                Thread.Sleep(5);
                //Console.WriteLine(String.Format("Step:{0} X:{1} Y:{2}", _Minwper.GetStep(), x, y));
            }

            //Console.WriteLine(String.Format("Step:{0} X:{1} Y:{2} GameOver", _Minwper.GetStep(), x, y));
        }