Пример #1
0
 /// <summary>
 /// 更新棋盘上的落子
 /// </summary>
 /// <param name="point"></param>
 public static void UpdateStones(StonePoint point)
 {
     foreach (var item in Stones)
     {
         if (item.PointX == point.PointX && item.PointY == point.PointY)
         {
             item.Type    = point.Type;
             item.StepNum = point.StepNum;
         }
     }
 }
Пример #2
0
        private bool DownStone(StonePoint point)
        {
            #region 人机对弈,下子

            if (point.Type == StoneType.未落子)
            {
                return(false);
            }

            var arr = Chessboard.StonesArray;
            arr[(int)point.PointX, (int)point.PointY] = (int)point.Type;
            var jingShou = Rule.IsJinShou(arr, point.PointX, point.PointY);
            if (point.Type == StoneType.黑子 && jingShou == JinShou.双三禁手)
            {
                MessageBox.Show("黑子双三禁手!", "温馨提示", MessageBoxButtons.OK);
            }
            else if (point.Type == StoneType.黑子 && jingShou == JinShou.双四禁手)
            {
                MessageBox.Show("黑子双四禁手!", "温馨提示", MessageBoxButtons.OK);
            }
            else if (point.Type == StoneType.黑子 && jingShou == JinShou.长联禁手)
            {
                MessageBox.Show("黑子长联禁手!", "温馨提示", MessageBoxButtons.OK);
            }
            else
            {
                Chessboard.UpdateStones(point); //更新Stones
                stone.DrawStone(point);
                Common.MakeStoneSound();

                var txt = point.StepNum.ToString() + " " + point.Type.ToString() + " 横:" + point.PointXValue + " - " + "纵:" + point.PointYValue.Replace("No", "");
                ChessRecord.StackHistory.Push(txt); //StackHistory为了保存棋谱
                shower.DataSource = ChessRecord.StackHistory.ToArray();
                shower.Update();

                if (Rule.IsPing() && MessageBox.Show("平局!", "重新开始", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    Chessboard.Clear();
                    ChessRecord.StackHistory.Clear();
                    Draw();                                      //重绘清除落子
                    Start();                                     //开新一局
                }
                else if (Rule.IsWin(point.PointX, point.PointY)) //在该位置落子胜
                {
                    string txtStone = point.Type == StoneType.黑子 ? "黑子胜利" : "白子胜利";
                    if (MessageBox.Show(txtStone, "是否保存棋谱", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        ChessRecord.SaveQP();
                    }

                    Chessboard.Clear();
                    ChessRecord.StackHistory.Clear();
                    Draw();  //重绘清除落子
                    Start(); //开新一局
                }
                else
                {
                    return(true); //可以走下一步
                }
            }

            #endregion

            return(false);
        }
Пример #3
0
 /// <summary>
 /// 该落子点位置上4个方向的连续子统计
 /// </summary>
 /// <param name="stonePoint"></param>
 /// <returns></returns>
 public static List<StoneDirect> GetDirect4Num(this StonePoint stonePoint)
 {
     return Rule.GetDirect4Num(Chessboard.StonesArray, stonePoint.PointX, stonePoint.PointY);
 }