示例#1
0
文件: Gobang.cs 项目: goodoycg/Gobang
        private void PrintScreen()
        {
            bool b = m_BDisplayStep;

            m_BDisplayStep = true;
            this.Refresh();

            Bitmap bmp = new Bitmap(this.Width, this.Height);

            this.DrawToBitmap(bmp, new Rectangle(0, 0, this.Width, this.Height));
            string strPath = Const.Runpath() + @"Screen\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".JPG";

            bmp.Save(strPath);

            m_BDisplayStep = b;
            this.Refresh();
        }
示例#2
0
文件: Gobang.cs 项目: goodoycg/Gobang
        private void buttonSave_Click(object sender, EventArgs e)
        {
            this.saveFileDialog1.Title = "保存棋局";
            this.saveFileDialog1.SupportMultiDottedExtensions = true;
            this.saveFileDialog1.OverwritePrompt  = true;
            this.saveFileDialog1.FileName         = "棋局";
            this.saveFileDialog1.InitialDirectory = System.Environment.SpecialFolder.DesktopDirectory.ToString();
            this.saveFileDialog1.Filter           = "文本文件(*.txt)|*.txt";
            this.saveFileDialog1.DefaultExt       = "txt";
            if (this.saveFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            try
            {
                System.IO.File.Copy(Const.Runpath() + "save.dll", this.saveFileDialog1.FileName, true);
                System.IO.StreamWriter w = System.IO.File.AppendText(this.saveFileDialog1.FileName);
                string strText           = string.Empty;

                object[] m_Text = lstHistory.DataSource as object[];
                for (int i = 0; i < m_Text.Length; i++)
                {
                    strText += m_Text[i].ToString().Replace("● ", string.Empty).Replace("○ ", string.Empty) + "-";
                }
                strText = strText.Substring(0, strText.Length - 1);
                w.Write(strText);
                w.Flush();
                w.Close();
                MessageBoxEx.Show(this, "保存成功!", Const.SystemTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (System.Exception err)
            {
                MessageBoxEx.Show(this, err.Message + err.StackTrace + "保存失败!", Const.SystemTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#3
0
文件: Gobang.cs 项目: goodoycg/Gobang
        private void PrintScreen2()
        {
            bool b = m_BDisplayStep;

            m_BDisplayStep = true;
            this.Refresh();
            try
            {
                SendKeys.SendWait("%{PRTSC}");
                // 模拟按键,将当前窗口图像截取到剪贴板   Alt+PrtSc,
                //如果要截取整个屏幕,把   Alt   (%)   去掉
                object o         = Clipboard.GetDataObject().GetData(DataFormats.Bitmap);//为null
                Bitmap myCapture = o as Bitmap;
                string strPath   = Const.Runpath() + @"Screen\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".JPG";
                myCapture.Save(@strPath, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            catch (System.Exception err)
            {
                Console.Write(err.Message + err.StackTrace);
                MessageBox.Show(err.Message + err.StackTrace);
            }
            m_BDisplayStep = b;
            this.Refresh();
        }
示例#4
0
        /// <summary>
        /// 当前棋子(m,n)落下,是已分胜负还是继续对局 (确定位置后,人和电脑是一样的下棋)
        /// </summary>
        /// <param name="m"></param>
        /// <param name="n"></param>
        private void PlayChess(int m, int n, bool displaystep, Graphics mGraphics)
        {
            if (Const.bGameOver)
            {
                return;
            }
            int lm = -1, ln = -1;               //上一落子点

            if ((CurrChessColor == ChessColor.Black))
            {//记录下棋情况和历史记录
                arrchessboard[m, n] = 1;
                mStarckHistory.Push("● " + m.ToString() + "," + n.ToString());
            }
            else
            {
                arrchessboard[m, n] = 2;
                mStarckHistory.Push("○ " + m.ToString() + "," + n.ToString());
            }
            //先记录再分析最后下棋位置
            if (mStarckHistory.Count > 0)
            {//分解最后下棋位置
                string   lstr = mStarckHistory.Peek().ToString().Replace("● ", string.Empty).Replace("○ ", string.Empty);
                string[] arr  = lstr.Split(',');
                lm = Convert.ToInt32(arr[0]);
                ln = Convert.ToInt32(arr[1]);
            }
            //判断结果返回结果(0:胜利  1:平局   2:继续)
            Const.iPlayedChessCount++;
            ArrayStep[m, n] = Const.iPlayedChessCount;

            #region 更新虚构棋盘大小
            Const.Xmax = m + Const.ChessBoardCellCount > Const.Xmax ? m + Const.ChessBoardCellCount : Const.Xmax;
            Const.Xmax = Const.Xmax > 14 ? 14 : Const.Xmax;

            Const.Xmin = m - Const.ChessBoardCellCount < Const.Xmin ? m - Const.ChessBoardCellCount : Const.Xmin;
            Const.Xmin = Const.Xmin < 0 ? 0 : Const.Xmin;

            Const.Ymax = n + Const.ChessBoardCellCount > Const.Ymax ? n + Const.ChessBoardCellCount : Const.Ymax;
            Const.Ymax = Const.Ymax > 14 ? 14 : Const.Ymax;

            Const.Ymin = n - Const.ChessBoardCellCount < Const.Ymin ? n - Const.ChessBoardCellCount : Const.Ymin;
            Const.Ymin = Const.Ymin < 0 ? 0 : Const.Ymin;
            #endregion
            //"1黑棋胜利!"  "2白棋胜利!" "3平局!"
            Const.Result = ChessRule.Result(m, n, arrchessboard);
            if (Const.Result == CurrChessBoardState.ContinuePlayChess)
            {
                if (CurrChessColor == ChessColor.Black)
                {
                    CurrChessColor = ChessColor.White;
                }
                else
                {
                    CurrChessColor = ChessColor.Black;
                }
            }
            else
            {
                switch (Const.Result)
                {
                case CurrChessBoardState.GameOver:
                    if ((CurrChessColor == ChessColor.Black))
                    {
                        Const.GameOverResult = GameResult.BlackVictory;
                    }
                    else
                    {
                        Const.GameOverResult = GameResult.WhiteVictory;
                    }

                    if (CurrChessColor == ChessColor.Black)
                    {
                        CurrChessColor = ChessColor.White;
                    }
                    else
                    {
                        CurrChessColor = ChessColor.Black;
                    }

                    Const.Result = CurrChessBoardState.None;
                    break;

                case CurrChessBoardState.Dogfall:
                    Const.GameOverResult = GameResult.Nogfall;

                    if (CurrChessColor == ChessColor.Black)
                    {
                        CurrChessColor = ChessColor.White;
                    }
                    else
                    {
                        CurrChessColor = ChessColor.Black;
                    }

                    Const.Result = CurrChessBoardState.None;
                    break;
                }
                GameOverEventArgs game = new GameOverEventArgs();
                game.Result         = Const.Result;
                game.ChessColorFlag = CurrChessColor;
                this.OnGameOver(null, game);
                //重新开始!
                new SoundPlayer(Const.Runpath() + "Sound\\GameOver.wav").Play();
                Const.bGameOver = true;
            }
        }