コード例 #1
0
ファイル: Form1.cs プロジェクト: maxzhx/ChineseChess
        private void Form1_Load(object sender, EventArgs e)
        {
            if (isload)//是否为载入游戏
            {
                #region 初始化棋盘
                stackPoint = new Stack<Point>();
                stackPictureBox = new Stack<string>();
                r_count = 0; b_count = 0;
                lab_bCount.Text = b_count.ToString();
                lab_rCount.Text = r_count.ToString();
                pic_chessboard.Enabled = true;
                btn_TakeBack.Enabled = false;
                悔棋ToolStripMenuItem.Enabled = false;
                whichside = 1;
                pic_whichside.Image = Image.FromFile(@"img\whichside_red.png");
                r_mint = 0;
                b_mint = 0;
                lab_rTime.Text = "00:00:00";
                lab_bTime.Text = "00:00:00";
                p_array = new PictureBox[2, 16] { { pic_Bzu1, pic_Bzu2, pic_Bzu3, pic_Bzu4, pic_Bzu5, pic_Bpao1, pic_Bpao2, pic_Bju1, pic_Bju2, pic_Bma1, pic_Bma2, pic_Bxiang1, pic_Bxiang2, pic_Bshi1, pic_Bshi2, pic_Bjiang },
            { pic_Rzu1, pic_Rzu2, pic_Rzu3, pic_Rzu4, pic_Rzu5, pic_Rpao1, pic_Rpao2, pic_Rju1, pic_Rju2, pic_Rma1, pic_Rma2, pic_Rxiang1, pic_Rxiang2, pic_Rshi1, pic_Rshi2, pic_Rjiang } };
                //此数组纪录下所有棋,用于判断坐标 p_array[0,x]为黑棋 p_array[1,x]为红棋
                /*
                ChessPieces[,] cp_array = new ChessPieces[2, 16] { { bzu1, bzu2, bzu3, bzu4, bzu5, bpao1, bpao2, bju1, bju2, bma1, bma2, bxiang1, bxiang2, bshi1, bshi2, bjiang },
                { rzu1, rzu2, rzu3, rzu4, rzu5, rpao1, rpao2, rju1, rju2, rma1, rma2, rxiang1, rxiang2, rshi1, rshi2, rjiang } };
                //此数组纪录下所有棋,用于判断坐标 cp_array[0,x]为黑棋 cp_array[1,x]为红棋
                */
                for (int i = 0; i != 2; i++)//将所有棋子的picturebox变为圆形
                {
                    for (int j = 0; j != 16; j++)
                    { makePicRound(p_array[i, j]); }
                }
                //初始化黑棋,创建父类
                bzu1 = new BZu(pic_Bzu1, pic_chessboard, p_array, pnl_RedDied, 43, 205, stackPoint, stackPictureBox);
                bzu2 = new BZu(pic_Bzu2, pic_chessboard, p_array, pnl_RedDied, 151, 205, stackPoint, stackPictureBox);
                bzu3 = new BZu(pic_Bzu3, pic_chessboard, p_array, pnl_RedDied, 259, 205, stackPoint, stackPictureBox);
                bzu4 = new BZu(pic_Bzu4, pic_chessboard, p_array, pnl_RedDied, 367, 205, stackPoint, stackPictureBox);
                bzu5 = new BZu(pic_Bzu5, pic_chessboard, p_array, pnl_RedDied, 475, 205, stackPoint, stackPictureBox);
                bpao1 = new BPao(pic_Bpao1, pic_chessboard, p_array, pnl_RedDied, 97, 151, stackPoint, stackPictureBox);
                bpao2 = new BPao(pic_Bpao2, pic_chessboard, p_array, pnl_RedDied, 421, 151, stackPoint, stackPictureBox);
                bju1 = new BJu(pic_Bju1, pic_chessboard, p_array, pnl_RedDied, 43, 43, stackPoint, stackPictureBox);
                bju2 = new BJu(pic_Bju2, pic_chessboard, p_array, pnl_RedDied, 475, 43, stackPoint, stackPictureBox);
                bma1 = new BMa(pic_Bma1, pic_chessboard, p_array, pnl_RedDied, 97, 43, stackPoint, stackPictureBox);
                bma2 = new BMa(pic_Bma2, pic_chessboard, p_array, pnl_RedDied, 421, 43, stackPoint, stackPictureBox);
                bxiang1 = new BXiang(pic_Bxiang1, pic_chessboard, p_array, pnl_RedDied, 151, 43, stackPoint, stackPictureBox);
                bxiang2 = new BXiang(pic_Bxiang2, pic_chessboard, p_array, pnl_RedDied, 367, 43, stackPoint, stackPictureBox);
                bshi1 = new BShi(pic_Bshi1, pic_chessboard, p_array, pnl_RedDied, 205, 43, stackPoint, stackPictureBox);
                bshi2 = new BShi(pic_Bshi2, pic_chessboard, p_array, pnl_RedDied, 313, 43, stackPoint, stackPictureBox);
                bjiang = new BJiang(pic_Bjiang, pic_chessboard, p_array, pnl_RedDied, 259, 43, stackPoint, stackPictureBox);

                //初始化红棋,创建父类
                rzu1 = new RZu(pic_Rzu1, pic_chessboard, p_array, pnl_BlackDied, 43, 367, stackPoint, stackPictureBox);
                rzu2 = new RZu(pic_Rzu2, pic_chessboard, p_array, pnl_BlackDied, 151, 367, stackPoint, stackPictureBox);
                rzu3 = new RZu(pic_Rzu3, pic_chessboard, p_array, pnl_BlackDied, 259, 367, stackPoint, stackPictureBox);
                rzu4 = new RZu(pic_Rzu4, pic_chessboard, p_array, pnl_BlackDied, 367, 367, stackPoint, stackPictureBox);
                rzu5 = new RZu(pic_Rzu5, pic_chessboard, p_array, pnl_BlackDied, 475, 367, stackPoint, stackPictureBox);
                rpao1 = new RPao(pic_Rpao1, pic_chessboard, p_array, pnl_BlackDied, 97, 421, stackPoint, stackPictureBox);
                rpao2 = new RPao(pic_Rpao2, pic_chessboard, p_array, pnl_BlackDied, 421, 421, stackPoint, stackPictureBox);
                rju1 = new RJu(pic_Rju1, pic_chessboard, p_array, pnl_BlackDied, 43, 529, stackPoint, stackPictureBox);
                rju2 = new RJu(pic_Rju2, pic_chessboard, p_array, pnl_BlackDied, 475, 529, stackPoint, stackPictureBox);
                rma1 = new RMa(pic_Rma1, pic_chessboard, p_array, pnl_BlackDied, 97, 529, stackPoint, stackPictureBox);
                rma2 = new RMa(pic_Rma2, pic_chessboard, p_array, pnl_BlackDied, 421, 529, stackPoint, stackPictureBox);
                rxiang1 = new RXiang(pic_Rxiang1, pic_chessboard, p_array, pnl_BlackDied, 151, 529, stackPoint, stackPictureBox);
                rxiang2 = new RXiang(pic_Rxiang2, pic_chessboard, p_array, pnl_BlackDied, 367, 529, stackPoint, stackPictureBox);
                rshi1 = new RShi(pic_Rshi1, pic_chessboard, p_array, pnl_BlackDied, 205, 529, stackPoint, stackPictureBox);
                rshi2 = new RShi(pic_Rshi2, pic_chessboard, p_array, pnl_BlackDied, 313, 529, stackPoint, stackPictureBox);
                rjiang = new RJiang(pic_Rjiang, pic_chessboard, p_array, pnl_BlackDied, 259, 529, stackPoint, stackPictureBox);

                //s = new System.Media.SoundPlayer(@"sound\begin.WAV");
               // s.Play();
                tmr1.Start();
                #endregion

                #region  重构棋盘
                formatter = new BinaryFormatter();
                stream = new FileStream(this.openFileName, FileMode.Open, FileAccess.Read, FileShare.Read);

                bzu1 = new BZu(pic_Bzu1, pic_chessboard, p_array, pnl_RedDied, 43, 205, stackPoint, stackPictureBox);
                bzu2 = new BZu(pic_Bzu2, pic_chessboard, p_array, pnl_RedDied, 151, 205, stackPoint, stackPictureBox);
                bzu3 = new BZu(pic_Bzu3, pic_chessboard, p_array, pnl_RedDied, 259, 205, stackPoint, stackPictureBox);
                bzu4 = new BZu(pic_Bzu4, pic_chessboard, p_array, pnl_RedDied, 367, 205, stackPoint, stackPictureBox);
                bzu5 = new BZu(pic_Bzu5, pic_chessboard, p_array, pnl_RedDied, 475, 205, stackPoint, stackPictureBox);
                bpao1 = new BPao(pic_Bpao1, pic_chessboard, p_array, pnl_RedDied, 97, 151, stackPoint, stackPictureBox);
                bpao2 = new BPao(pic_Bpao2, pic_chessboard, p_array, pnl_RedDied, 421, 151, stackPoint, stackPictureBox);
                bju1 = new BJu(pic_Bju1, pic_chessboard, p_array, pnl_RedDied, 43, 43, stackPoint, stackPictureBox);
                bju2 = new BJu(pic_Bju2, pic_chessboard, p_array, pnl_RedDied, 475, 43, stackPoint, stackPictureBox);
                bma1 = new BMa(pic_Bma1, pic_chessboard, p_array, pnl_RedDied, 97, 43, stackPoint, stackPictureBox);
                bma2 = new BMa(pic_Bma2, pic_chessboard, p_array, pnl_RedDied, 421, 43, stackPoint, stackPictureBox);
                bxiang1 = new BXiang(pic_Bxiang1, pic_chessboard, p_array, pnl_RedDied, 151, 43, stackPoint, stackPictureBox);
                bxiang2 = new BXiang(pic_Bxiang2, pic_chessboard, p_array, pnl_RedDied, 367, 43, stackPoint, stackPictureBox);
                bshi1 = new BShi(pic_Bshi1, pic_chessboard, p_array, pnl_RedDied, 205, 43, stackPoint, stackPictureBox);
                bshi2 = new BShi(pic_Bshi2, pic_chessboard, p_array, pnl_RedDied, 313, 43, stackPoint, stackPictureBox);
                bjiang = new BJiang(pic_Bjiang, pic_chessboard, p_array, pnl_RedDied, 259, 43, stackPoint, stackPictureBox);

                //初始化红棋,创建父类
                rzu1 = new RZu(pic_Rzu1, pic_chessboard, p_array, pnl_BlackDied, 43, 367, stackPoint, stackPictureBox);
                rzu2 = new RZu(pic_Rzu2, pic_chessboard, p_array, pnl_BlackDied, 151, 367, stackPoint, stackPictureBox);
                rzu3 = new RZu(pic_Rzu3, pic_chessboard, p_array, pnl_BlackDied, 259, 367, stackPoint, stackPictureBox);
                rzu4 = new RZu(pic_Rzu4, pic_chessboard, p_array, pnl_BlackDied, 367, 367, stackPoint, stackPictureBox);
                rzu5 = new RZu(pic_Rzu5, pic_chessboard, p_array, pnl_BlackDied, 475, 367, stackPoint, stackPictureBox);
                rpao1 = new RPao(pic_Rpao1, pic_chessboard, p_array, pnl_BlackDied, 97, 421, stackPoint, stackPictureBox);
                rpao2 = new RPao(pic_Rpao2, pic_chessboard, p_array, pnl_BlackDied, 421, 421, stackPoint, stackPictureBox);
                rju1 = new RJu(pic_Rju1, pic_chessboard, p_array, pnl_BlackDied, 43, 529, stackPoint, stackPictureBox);
                rju2 = new RJu(pic_Rju2, pic_chessboard, p_array, pnl_BlackDied, 475, 529, stackPoint, stackPictureBox);
                rma1 = new RMa(pic_Rma1, pic_chessboard, p_array, pnl_BlackDied, 97, 529, stackPoint, stackPictureBox);
                rma2 = new RMa(pic_Rma2, pic_chessboard, p_array, pnl_BlackDied, 421, 529, stackPoint, stackPictureBox);
                rxiang1 = new RXiang(pic_Rxiang1, pic_chessboard, p_array, pnl_BlackDied, 151, 529, stackPoint, stackPictureBox);
                rxiang2 = new RXiang(pic_Rxiang2, pic_chessboard, p_array, pnl_BlackDied, 367, 529, stackPoint, stackPictureBox);
                rshi1 = new RShi(pic_Rshi1, pic_chessboard, p_array, pnl_BlackDied, 205, 529, stackPoint, stackPictureBox);
                rshi2 = new RShi(pic_Rshi2, pic_chessboard, p_array, pnl_BlackDied, 313, 529, stackPoint, stackPictureBox);
                rjiang = new RJiang(pic_Rjiang, pic_chessboard, p_array, pnl_BlackDied, 259, 529, stackPoint, stackPictureBox);

                r_count = (int)formatter.Deserialize(stream); b_count = (int)formatter.Deserialize(stream);
                lab_bCount.Text = b_count.ToString();
                lab_rCount.Text = r_count.ToString();
                pic_chessboard.Enabled = (bool)formatter.Deserialize(stream);
                whichside = (int)formatter.Deserialize(stream);
                if (whichside == 1)
                {
                    pic_whichside.Image = Image.FromFile(@"img\whichside_red.png");
                }
                else
                {
                    pic_whichside.Image = Image.FromFile(@"img\whichside_black.png");
                }
                r_mint = (int)formatter.Deserialize(stream);
                b_mint = (int)formatter.Deserialize(stream);
                //计时器重写
                int h, m, s;
                string time;
                s = r_mint % 60;
                m = (int)r_mint / 60 % 60;
                h = (int)r_mint / 60 / 60;
                time = string.Format("{0:D2}:{1:D2}:{2:D2}", h, m, s);
                lab_rTime.Text = time;

                s = b_mint % 60;
                m = (int)b_mint / 60 % 60;
                h = (int)b_mint / 60 / 60;
                time = string.Format("{0:D2}:{1:D2}:{2:D2}", h, m, s);

                lab_bTime.Text = time;

                p_array = new PictureBox[2, 16] { { pic_Bzu1, pic_Bzu2, pic_Bzu3, pic_Bzu4, pic_Bzu5, pic_Bpao1, pic_Bpao2, pic_Bju1, pic_Bju2, pic_Bma1, pic_Bma2, pic_Bxiang1, pic_Bxiang2, pic_Bshi1, pic_Bshi2, pic_Bjiang },
            { pic_Rzu1, pic_Rzu2, pic_Rzu3, pic_Rzu4, pic_Rzu5, pic_Rpao1, pic_Rpao2, pic_Rju1, pic_Rju2, pic_Rma1, pic_Rma2, pic_Rxiang1, pic_Rxiang2, pic_Rshi1, pic_Rshi2, pic_Rjiang } };
                //此数组纪录下所有棋,用于判断坐标 p_array[0,x]为黑棋 p_array[1,x]为红棋
                /*
                ChessPieces[,] cp_array = new ChessPieces[2, 16] { { bzu1, bzu2, bzu3, bzu4, bzu5, bpao1, bpao2, bju1, bju2, bma1, bma2, bxiang1, bxiang2, bshi1, bshi2, bjiang },
                { rzu1, rzu2, rzu3, rzu4, rzu5, rpao1, rpao2, rju1, rju2, rma1, rma2, rxiang1, rxiang2, rshi1, rshi2, rjiang } };
                //此数组纪录下所有棋,用于判断坐标 cp_array[0,x]为黑棋 cp_array[1,x]为红棋
                */

                for (int i = 0; i != 2; i++)//将所有棋子的picturebox变为圆形
                {
                    for (int j = 0; j != 16; j++)
                    { makePicRound(p_array[i, j]); }
                }

                int ind;
                for (int i = 0; i != 2; i++)
                {
                    for (int j = 0; j != 16; j++)
                    {
                        ind = (int)formatter.Deserialize(stream);
                        if (ind == 1) { p_array[i, j].Parent = pic_chessboard; }
                        else
                        {
                            string sn = p_array[i, j].Name;
                            if (sn[4] == 'B')
                                p_array[i, j].Parent = pnl_BlackDied;
                            else
                                p_array[i, j].Parent = pnl_RedDied;
                        }
                        p_array[i, j].Location = (Point)formatter.Deserialize(stream);
                    }
                }
                stream.Close();
                tmr1.Start();
                stackPoint.Clear();
                stackPictureBox.Clear();
                btn_TakeBack.Enabled = false;
                悔棋ToolStripMenuItem.Enabled = false;
                #endregion
            }
            else
            {
                #region 初始化棋盘
                stackPoint = new Stack<Point>();
                stackPictureBox = new Stack<string>();
                r_count = 0; b_count = 0;
                lab_bCount.Text = b_count.ToString();
                lab_rCount.Text = r_count.ToString();
                pic_chessboard.Enabled = true;
                btn_TakeBack.Enabled = false;
                悔棋ToolStripMenuItem.Enabled = false;
                whichside = 1;
                pic_whichside.Image = Image.FromFile(@"img\whichside_red.png");
                r_mint = 0;
                b_mint = 0;
                lab_rTime.Text = "00:00:00";
                lab_bTime.Text = "00:00:00";
                p_array = new PictureBox[2, 16] { { pic_Bzu1, pic_Bzu2, pic_Bzu3, pic_Bzu4, pic_Bzu5, pic_Bpao1, pic_Bpao2, pic_Bju1, pic_Bju2, pic_Bma1, pic_Bma2, pic_Bxiang1, pic_Bxiang2, pic_Bshi1, pic_Bshi2, pic_Bjiang },
            { pic_Rzu1, pic_Rzu2, pic_Rzu3, pic_Rzu4, pic_Rzu5, pic_Rpao1, pic_Rpao2, pic_Rju1, pic_Rju2, pic_Rma1, pic_Rma2, pic_Rxiang1, pic_Rxiang2, pic_Rshi1, pic_Rshi2, pic_Rjiang } };
                //此数组纪录下所有棋,用于判断坐标 p_array[0,x]为黑棋 p_array[1,x]为红棋
                /*
                ChessPieces[,] cp_array = new ChessPieces[2, 16] { { bzu1, bzu2, bzu3, bzu4, bzu5, bpao1, bpao2, bju1, bju2, bma1, bma2, bxiang1, bxiang2, bshi1, bshi2, bjiang },
                { rzu1, rzu2, rzu3, rzu4, rzu5, rpao1, rpao2, rju1, rju2, rma1, rma2, rxiang1, rxiang2, rshi1, rshi2, rjiang } };
                //此数组纪录下所有棋,用于判断坐标 cp_array[0,x]为黑棋 cp_array[1,x]为红棋
                */
                for (int i = 0; i != 2; i++)//将所有棋子的picturebox变为圆形
                {
                    for (int j = 0; j != 16; j++)
                    { makePicRound(p_array[i, j]); }
                }
                //初始化黑棋,创建父类
                bzu1 = new BZu(pic_Bzu1, pic_chessboard, p_array, pnl_RedDied, 43, 205, stackPoint, stackPictureBox);
                bzu2 = new BZu(pic_Bzu2, pic_chessboard, p_array, pnl_RedDied, 151, 205, stackPoint, stackPictureBox);
                bzu3 = new BZu(pic_Bzu3, pic_chessboard, p_array, pnl_RedDied, 259, 205, stackPoint, stackPictureBox);
                bzu4 = new BZu(pic_Bzu4, pic_chessboard, p_array, pnl_RedDied, 367, 205, stackPoint, stackPictureBox);
                bzu5 = new BZu(pic_Bzu5, pic_chessboard, p_array, pnl_RedDied, 475, 205, stackPoint, stackPictureBox);
                bpao1 = new BPao(pic_Bpao1, pic_chessboard, p_array, pnl_RedDied, 97, 151, stackPoint, stackPictureBox);
                bpao2 = new BPao(pic_Bpao2, pic_chessboard, p_array, pnl_RedDied, 421, 151, stackPoint, stackPictureBox);
                bju1 = new BJu(pic_Bju1, pic_chessboard, p_array, pnl_RedDied, 43, 43, stackPoint, stackPictureBox);
                bju2 = new BJu(pic_Bju2, pic_chessboard, p_array, pnl_RedDied, 475, 43, stackPoint, stackPictureBox);
                bma1 = new BMa(pic_Bma1, pic_chessboard, p_array, pnl_RedDied, 97, 43, stackPoint, stackPictureBox);
                bma2 = new BMa(pic_Bma2, pic_chessboard, p_array, pnl_RedDied, 421, 43, stackPoint, stackPictureBox);
                bxiang1 = new BXiang(pic_Bxiang1, pic_chessboard, p_array, pnl_RedDied, 151, 43, stackPoint, stackPictureBox);
                bxiang2 = new BXiang(pic_Bxiang2, pic_chessboard, p_array, pnl_RedDied, 367, 43, stackPoint, stackPictureBox);
                bshi1 = new BShi(pic_Bshi1, pic_chessboard, p_array, pnl_RedDied, 205, 43, stackPoint, stackPictureBox);
                bshi2 = new BShi(pic_Bshi2, pic_chessboard, p_array, pnl_RedDied, 313, 43, stackPoint, stackPictureBox);
                bjiang = new BJiang(pic_Bjiang, pic_chessboard, p_array, pnl_RedDied, 259, 43, stackPoint, stackPictureBox);

                //初始化红棋,创建父类
                rzu1 = new RZu(pic_Rzu1, pic_chessboard, p_array, pnl_BlackDied, 43, 367, stackPoint, stackPictureBox);
                rzu2 = new RZu(pic_Rzu2, pic_chessboard, p_array, pnl_BlackDied, 151, 367, stackPoint, stackPictureBox);
                rzu3 = new RZu(pic_Rzu3, pic_chessboard, p_array, pnl_BlackDied, 259, 367, stackPoint, stackPictureBox);
                rzu4 = new RZu(pic_Rzu4, pic_chessboard, p_array, pnl_BlackDied, 367, 367, stackPoint, stackPictureBox);
                rzu5 = new RZu(pic_Rzu5, pic_chessboard, p_array, pnl_BlackDied, 475, 367, stackPoint, stackPictureBox);
                rpao1 = new RPao(pic_Rpao1, pic_chessboard, p_array, pnl_BlackDied, 97, 421, stackPoint, stackPictureBox);
                rpao2 = new RPao(pic_Rpao2, pic_chessboard, p_array, pnl_BlackDied, 421, 421, stackPoint, stackPictureBox);
                rju1 = new RJu(pic_Rju1, pic_chessboard, p_array, pnl_BlackDied, 43, 529, stackPoint, stackPictureBox);
                rju2 = new RJu(pic_Rju2, pic_chessboard, p_array, pnl_BlackDied, 475, 529, stackPoint, stackPictureBox);
                rma1 = new RMa(pic_Rma1, pic_chessboard, p_array, pnl_BlackDied, 97, 529, stackPoint, stackPictureBox);
                rma2 = new RMa(pic_Rma2, pic_chessboard, p_array, pnl_BlackDied, 421, 529, stackPoint, stackPictureBox);
                rxiang1 = new RXiang(pic_Rxiang1, pic_chessboard, p_array, pnl_BlackDied, 151, 529, stackPoint, stackPictureBox);
                rxiang2 = new RXiang(pic_Rxiang2, pic_chessboard, p_array, pnl_BlackDied, 367, 529, stackPoint, stackPictureBox);
                rshi1 = new RShi(pic_Rshi1, pic_chessboard, p_array, pnl_BlackDied, 205, 529, stackPoint, stackPictureBox);
                rshi2 = new RShi(pic_Rshi2, pic_chessboard, p_array, pnl_BlackDied, 313, 529, stackPoint, stackPictureBox);
                rjiang = new RJiang(pic_Rjiang, pic_chessboard, p_array, pnl_BlackDied, 259, 529, stackPoint, stackPictureBox);

                s = new System.Media.SoundPlayer(@"sound\begin.WAV");
                s.Play();
                tmr1.Start();
                #endregion
            }

            #region 初始化背景音乐
            wmp_background.currentPlaylist.appendItem(wmp_background.newMedia(@"sound\background\2.mp3"));
            wmp_background.currentPlaylist.appendItem(wmp_background.newMedia(@"sound\background\3.mp3"));
            wmp_background.currentPlaylist.appendItem(wmp_background.newMedia(@"sound\background\4.mp3"));
            wmp_background.currentPlaylist.appendItem(wmp_background.newMedia(@"sound\background\5.mp3"));
            wmp_background.currentPlaylist.appendItem(wmp_background.newMedia(@"sound\background\6.mp3"));
            wmp_background.settings.volume = 30;
            wmp_background.settings.playCount = 99;
            wmp_background.Ctlcontrols.play();
            #endregion
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: maxzhx/ChineseChess
        private void btn_load_Click(object sender, EventArgs e)
        {
            if (ofd1.ShowDialog() == DialogResult.OK)
            {
                openFileName = ofd1.FileName;
                formatter = new BinaryFormatter();
                stream = new FileStream(this.openFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                #region  重构棋盘
                //初始化黑棋,创建父类

                bzu1 = new BZu(pic_Bzu1, pic_chessboard, p_array, pnl_RedDied, 43, 205, stackPoint, stackPictureBox);
                bzu2 = new BZu(pic_Bzu2, pic_chessboard, p_array, pnl_RedDied, 151, 205, stackPoint, stackPictureBox);
                bzu3 = new BZu(pic_Bzu3, pic_chessboard, p_array, pnl_RedDied, 259, 205, stackPoint, stackPictureBox);
                bzu4 = new BZu(pic_Bzu4, pic_chessboard, p_array, pnl_RedDied, 367, 205, stackPoint, stackPictureBox);
                bzu5 = new BZu(pic_Bzu5, pic_chessboard, p_array, pnl_RedDied, 475, 205, stackPoint, stackPictureBox);
                bpao1 = new BPao(pic_Bpao1, pic_chessboard, p_array, pnl_RedDied, 97, 151, stackPoint, stackPictureBox);
                bpao2 = new BPao(pic_Bpao2, pic_chessboard, p_array, pnl_RedDied, 421, 151, stackPoint, stackPictureBox);
                bju1 = new BJu(pic_Bju1, pic_chessboard, p_array, pnl_RedDied, 43, 43, stackPoint, stackPictureBox);
                bju2 = new BJu(pic_Bju2, pic_chessboard, p_array, pnl_RedDied, 475, 43, stackPoint, stackPictureBox);
                bma1 = new BMa(pic_Bma1, pic_chessboard, p_array, pnl_RedDied, 97, 43, stackPoint, stackPictureBox);
                bma2 = new BMa(pic_Bma2, pic_chessboard, p_array, pnl_RedDied, 421, 43, stackPoint, stackPictureBox);
                bxiang1 = new BXiang(pic_Bxiang1, pic_chessboard, p_array, pnl_RedDied, 151, 43, stackPoint, stackPictureBox);
                bxiang2 = new BXiang(pic_Bxiang2, pic_chessboard, p_array, pnl_RedDied, 367, 43, stackPoint, stackPictureBox);
                bshi1 = new BShi(pic_Bshi1, pic_chessboard, p_array, pnl_RedDied, 205, 43, stackPoint, stackPictureBox);
                bshi2 = new BShi(pic_Bshi2, pic_chessboard, p_array, pnl_RedDied, 313, 43, stackPoint, stackPictureBox);
                bjiang = new BJiang(pic_Bjiang, pic_chessboard, p_array, pnl_RedDied, 259, 43, stackPoint, stackPictureBox);

                //初始化红棋,创建父类
                rzu1 = new RZu(pic_Rzu1, pic_chessboard, p_array, pnl_BlackDied, 43, 367, stackPoint, stackPictureBox);
                rzu2 = new RZu(pic_Rzu2, pic_chessboard, p_array, pnl_BlackDied, 151, 367, stackPoint, stackPictureBox);
                rzu3 = new RZu(pic_Rzu3, pic_chessboard, p_array, pnl_BlackDied, 259, 367, stackPoint, stackPictureBox);
                rzu4 = new RZu(pic_Rzu4, pic_chessboard, p_array, pnl_BlackDied, 367, 367, stackPoint, stackPictureBox);
                rzu5 = new RZu(pic_Rzu5, pic_chessboard, p_array, pnl_BlackDied, 475, 367, stackPoint, stackPictureBox);
                rpao1 = new RPao(pic_Rpao1, pic_chessboard, p_array, pnl_BlackDied, 97, 421, stackPoint, stackPictureBox);
                rpao2 = new RPao(pic_Rpao2, pic_chessboard, p_array, pnl_BlackDied, 421, 421, stackPoint, stackPictureBox);
                rju1 = new RJu(pic_Rju1, pic_chessboard, p_array, pnl_BlackDied, 43, 529, stackPoint, stackPictureBox);
                rju2 = new RJu(pic_Rju2, pic_chessboard, p_array, pnl_BlackDied, 475, 529, stackPoint, stackPictureBox);
                rma1 = new RMa(pic_Rma1, pic_chessboard, p_array, pnl_BlackDied, 97, 529, stackPoint, stackPictureBox);
                rma2 = new RMa(pic_Rma2, pic_chessboard, p_array, pnl_BlackDied, 421, 529, stackPoint, stackPictureBox);
                rxiang1 = new RXiang(pic_Rxiang1, pic_chessboard, p_array, pnl_BlackDied, 151, 529, stackPoint, stackPictureBox);
                rxiang2 = new RXiang(pic_Rxiang2, pic_chessboard, p_array, pnl_BlackDied, 367, 529, stackPoint, stackPictureBox);
                rshi1 = new RShi(pic_Rshi1, pic_chessboard, p_array, pnl_BlackDied, 205, 529, stackPoint, stackPictureBox);
                rshi2 = new RShi(pic_Rshi2, pic_chessboard, p_array, pnl_BlackDied, 313, 529, stackPoint, stackPictureBox);
                rjiang = new RJiang(pic_Rjiang, pic_chessboard, p_array, pnl_BlackDied, 259, 529, stackPoint, stackPictureBox);

                r_count = (int)formatter.Deserialize(stream); b_count = (int)formatter.Deserialize(stream);
                lab_bCount.Text = b_count.ToString();
                lab_rCount.Text = r_count.ToString();
                pic_chessboard.Enabled = (bool)formatter.Deserialize(stream);
                whichside = (int)formatter.Deserialize(stream);
                if (whichside == 1)
                {
                    pic_whichside.Image = Image.FromFile(@"img\whichside_red.png");
                }
                else
                {
                    pic_whichside.Image = Image.FromFile(@"img\whichside_black.png");
                }
                r_mint = (int)formatter.Deserialize(stream);
                b_mint = (int)formatter.Deserialize(stream);
                //计时器重写
                int h, m, s;
                string time;
                s = r_mint % 60;
                m = (int)r_mint / 60 % 60;
                h = (int)r_mint / 60 / 60;
                time = string.Format("{0:D2}:{1:D2}:{2:D2}", h, m, s);
                lab_rTime.Text = time;

                s = b_mint % 60;
                m = (int)b_mint / 60 % 60;
                h = (int)b_mint / 60 / 60;
                time = string.Format("{0:D2}:{1:D2}:{2:D2}", h, m, s);

                lab_bTime.Text = time;

                p_array = new PictureBox[2, 16] { { pic_Bzu1, pic_Bzu2, pic_Bzu3, pic_Bzu4, pic_Bzu5, pic_Bpao1, pic_Bpao2, pic_Bju1, pic_Bju2, pic_Bma1, pic_Bma2, pic_Bxiang1, pic_Bxiang2, pic_Bshi1, pic_Bshi2, pic_Bjiang },
            { pic_Rzu1, pic_Rzu2, pic_Rzu3, pic_Rzu4, pic_Rzu5, pic_Rpao1, pic_Rpao2, pic_Rju1, pic_Rju2, pic_Rma1, pic_Rma2, pic_Rxiang1, pic_Rxiang2, pic_Rshi1, pic_Rshi2, pic_Rjiang } };
                //此数组纪录下所有棋,用于判断坐标 p_array[0,x]为黑棋 p_array[1,x]为红棋
                /*
                ChessPieces[,] cp_array = new ChessPieces[2, 16] { { bzu1, bzu2, bzu3, bzu4, bzu5, bpao1, bpao2, bju1, bju2, bma1, bma2, bxiang1, bxiang2, bshi1, bshi2, bjiang },
                { rzu1, rzu2, rzu3, rzu4, rzu5, rpao1, rpao2, rju1, rju2, rma1, rma2, rxiang1, rxiang2, rshi1, rshi2, rjiang } };
                //此数组纪录下所有棋,用于判断坐标 cp_array[0,x]为黑棋 cp_array[1,x]为红棋
                */

                for (int i = 0; i != 2; i++)//将所有棋子的picturebox变为圆形
                {
                    for (int j = 0; j != 16; j++)
                    { makePicRound(p_array[i, j]); }
                }

                int ind;
                for (int i = 0; i != 2; i++)
                {
                    for (int j = 0; j != 16; j++)
                    {
                        ind = (int)formatter.Deserialize(stream);
                        if (ind == 1) { p_array[i, j].Parent = pic_chessboard; }
                        else
                        {
                            string sn = p_array[i, j].Name;
                            if (sn[4] == 'B')
                                p_array[i, j].Parent = pnl_BlackDied;
                            else
                                p_array[i, j].Parent = pnl_RedDied;
                        }
                        p_array[i, j].Location = (Point)formatter.Deserialize(stream);
                    }
                }
                stream.Close();
                tmr1.Start();
                stackPoint.Clear();
                stackPictureBox.Clear();
                btn_TakeBack.Enabled = false;
                悔棋ToolStripMenuItem.Enabled = false;

                #endregion
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: maxzhx/ChineseChess
        private void btn_newgame_Click(object sender, EventArgs e)
        {
            #region 初始化棋盘
            stackPoint = new Stack<Point>();
            stackPictureBox = new Stack<string>();
            r_count = 0; b_count = 0;
            lab_bCount.Text = b_count.ToString();
            lab_rCount.Text = r_count.ToString();
            pic_chessboard.Enabled = true;
            btn_TakeBack.Enabled = false;
            悔棋ToolStripMenuItem.Enabled = false;
            whichside = 1;
            pic_whichside.Image = Image.FromFile(@"img\whichside_red.png");
            r_mint = 0;
            b_mint = 0;
            lab_rTime.Text = "00:00:00";
            lab_bTime.Text = "00:00:00";
            p_array = new PictureBox[2, 16] { { pic_Bzu1, pic_Bzu2, pic_Bzu3, pic_Bzu4, pic_Bzu5, pic_Bpao1, pic_Bpao2, pic_Bju1, pic_Bju2, pic_Bma1, pic_Bma2, pic_Bxiang1, pic_Bxiang2, pic_Bshi1, pic_Bshi2, pic_Bjiang },
            { pic_Rzu1, pic_Rzu2, pic_Rzu3, pic_Rzu4, pic_Rzu5, pic_Rpao1, pic_Rpao2, pic_Rju1, pic_Rju2, pic_Rma1, pic_Rma2, pic_Rxiang1, pic_Rxiang2, pic_Rshi1, pic_Rshi2, pic_Rjiang } };
            //此数组纪录下所有棋,用于判断坐标 p_array[0,x]为黑棋 p_array[1,x]为红棋
            /*
            ChessPieces[,] cp_array = new ChessPieces[2, 16] { { bzu1, bzu2, bzu3, bzu4, bzu5, bpao1, bpao2, bju1, bju2, bma1, bma2, bxiang1, bxiang2, bshi1, bshi2, bjiang },
            { rzu1, rzu2, rzu3, rzu4, rzu5, rpao1, rpao2, rju1, rju2, rma1, rma2, rxiang1, rxiang2, rshi1, rshi2, rjiang } };
            //此数组纪录下所有棋,用于判断坐标 cp_array[0,x]为黑棋 cp_array[1,x]为红棋
            */
            for (int i = 0; i != 2; i++)//将所有棋子的picturebox变为圆形
            {
                for (int j = 0; j != 16; j++)
                { makePicRound(p_array[i, j]); }
            }
            //初始化黑棋,创建父类
            bzu1 = new BZu(pic_Bzu1, pic_chessboard, p_array, pnl_RedDied, 43, 205, stackPoint, stackPictureBox);
            bzu2 = new BZu(pic_Bzu2, pic_chessboard, p_array, pnl_RedDied, 151, 205, stackPoint, stackPictureBox);
            bzu3 = new BZu(pic_Bzu3, pic_chessboard, p_array, pnl_RedDied, 259, 205, stackPoint, stackPictureBox);
            bzu4 = new BZu(pic_Bzu4, pic_chessboard, p_array, pnl_RedDied, 367, 205, stackPoint, stackPictureBox);
            bzu5 = new BZu(pic_Bzu5, pic_chessboard, p_array, pnl_RedDied, 475, 205, stackPoint, stackPictureBox);
            bpao1 = new BPao(pic_Bpao1, pic_chessboard, p_array, pnl_RedDied, 97, 151, stackPoint, stackPictureBox);
            bpao2 = new BPao(pic_Bpao2, pic_chessboard, p_array, pnl_RedDied, 421, 151, stackPoint, stackPictureBox);
            bju1 = new BJu(pic_Bju1, pic_chessboard, p_array, pnl_RedDied, 43, 43, stackPoint, stackPictureBox);
            bju2 = new BJu(pic_Bju2, pic_chessboard, p_array, pnl_RedDied, 475, 43, stackPoint, stackPictureBox);
            bma1 = new BMa(pic_Bma1, pic_chessboard, p_array, pnl_RedDied, 97, 43, stackPoint, stackPictureBox);
            bma2 = new BMa(pic_Bma2, pic_chessboard, p_array, pnl_RedDied, 421, 43, stackPoint, stackPictureBox);
            bxiang1 = new BXiang(pic_Bxiang1, pic_chessboard, p_array, pnl_RedDied, 151, 43, stackPoint, stackPictureBox);
            bxiang2 = new BXiang(pic_Bxiang2, pic_chessboard, p_array, pnl_RedDied, 367, 43, stackPoint, stackPictureBox);
            bshi1 = new BShi(pic_Bshi1, pic_chessboard, p_array, pnl_RedDied, 205, 43, stackPoint, stackPictureBox);
            bshi2 = new BShi(pic_Bshi2, pic_chessboard, p_array, pnl_RedDied, 313, 43, stackPoint, stackPictureBox);
            bjiang = new BJiang(pic_Bjiang, pic_chessboard, p_array, pnl_RedDied, 259, 43, stackPoint, stackPictureBox);

            //初始化红棋,创建父类
            rzu1 = new RZu(pic_Rzu1, pic_chessboard, p_array, pnl_BlackDied, 43, 367, stackPoint, stackPictureBox);
            rzu2 = new RZu(pic_Rzu2, pic_chessboard, p_array, pnl_BlackDied, 151, 367, stackPoint, stackPictureBox);
            rzu3 = new RZu(pic_Rzu3, pic_chessboard, p_array, pnl_BlackDied, 259, 367, stackPoint, stackPictureBox);
            rzu4 = new RZu(pic_Rzu4, pic_chessboard, p_array, pnl_BlackDied, 367, 367, stackPoint, stackPictureBox);
            rzu5 = new RZu(pic_Rzu5, pic_chessboard, p_array, pnl_BlackDied, 475, 367, stackPoint, stackPictureBox);
            rpao1 = new RPao(pic_Rpao1, pic_chessboard, p_array, pnl_BlackDied, 97, 421, stackPoint, stackPictureBox);
            rpao2 = new RPao(pic_Rpao2, pic_chessboard, p_array, pnl_BlackDied, 421, 421, stackPoint, stackPictureBox);
            rju1 = new RJu(pic_Rju1, pic_chessboard, p_array, pnl_BlackDied, 43, 529, stackPoint, stackPictureBox);
            rju2 = new RJu(pic_Rju2, pic_chessboard, p_array, pnl_BlackDied, 475, 529, stackPoint, stackPictureBox);
            rma1 = new RMa(pic_Rma1, pic_chessboard, p_array, pnl_BlackDied, 97, 529, stackPoint, stackPictureBox);
            rma2 = new RMa(pic_Rma2, pic_chessboard, p_array, pnl_BlackDied, 421, 529, stackPoint, stackPictureBox);
            rxiang1 = new RXiang(pic_Rxiang1, pic_chessboard, p_array, pnl_BlackDied, 151, 529, stackPoint, stackPictureBox);
            rxiang2 = new RXiang(pic_Rxiang2, pic_chessboard, p_array, pnl_BlackDied, 367, 529, stackPoint, stackPictureBox);
            rshi1 = new RShi(pic_Rshi1, pic_chessboard, p_array, pnl_BlackDied, 205, 529, stackPoint, stackPictureBox);
            rshi2 = new RShi(pic_Rshi2, pic_chessboard, p_array, pnl_BlackDied, 313, 529, stackPoint, stackPictureBox);
            rjiang = new RJiang(pic_Rjiang, pic_chessboard, p_array, pnl_BlackDied, 259, 529, stackPoint, stackPictureBox);

            s = new System.Media.SoundPlayer(@"sound\begin.WAV");
            s.Play();
            tmr1.Start();
            #endregion
        }