Ejemplo n.º 1
0
        /// <summary>
        /// static load chess pieces
        /// </summary>
        private void loadChessPieces()
        {
            #region 放置棋子,红方
            for (int i = 0; i <= 8; i += 8)
            {
                Rook ju1 = new Rook();
                ju1.Type          = ChessType.Red;
                ju1.GridX         = i;
                ju1.GridY         = 0;
                ju1.PreviousGridX = i;
                ju1.PreviousGridY = 0;
                ju1.Text          = "车";
                ju1.InitChess();
                this.panel1.Controls.Add(ju1);
                ju1.MouseClick  += new MouseEventHandler(chessItem_MouseClick);
                chessArray[0, i] = (byte)ju1.PieceType;
            }

            for (int i = 1; i <= 7; i += 6)
            {
                Knight ma = new Knight();
                ma.Type          = ChessType.Red;
                ma.GridX         = i;
                ma.GridY         = 0;
                ma.PreviousGridX = i;
                ma.PreviousGridY = 0;
                ma.Text          = "马";
                ma.InitChess();
                this.panel1.Controls.Add(ma);
                ma.MouseClick   += new MouseEventHandler(chessItem_MouseClick);
                chessArray[0, i] = (byte)ma.PieceType;
                //因为“炮”与“马”的位置都类似,循环次数也一样
                Cannon pao = new Cannon();
                pao.Type          = ChessType.Red;
                pao.GridX         = i;
                pao.GridY         = 2;
                pao.PreviousGridX = i;
                pao.PreviousGridY = 2;
                pao.Text          = "炮";
                pao.InitChess();
                this.panel1.Controls.Add(pao);
                pao.MouseClick  += new MouseEventHandler(chessItem_MouseClick);
                chessArray[2, i] = (byte)pao.PieceType;
            }

            for (int i = 2; i <= 6; i += 4)
            {
                Bishop xiang = new Bishop();
                xiang.Type          = ChessType.Red;
                xiang.GridX         = i;
                xiang.GridY         = 0;
                xiang.PreviousGridX = i;
                xiang.PreviousGridY = 0;
                xiang.Text          = "相";
                xiang.InitChess();
                this.panel1.Controls.Add(xiang);
                xiang.MouseClick += new MouseEventHandler(chessItem_MouseClick);
                chessArray[0, i]  = (byte)xiang.PieceType;
            }

            for (int i = 3; i <= 6; i += 2)
            {
                Advisor shi = new Advisor();
                shi.Type          = ChessType.Red;
                shi.GridX         = i;
                shi.GridY         = 0;
                shi.PreviousGridX = i;
                shi.PreviousGridY = 0;
                shi.Text          = "士";
                shi.InitChess();
                this.panel1.Controls.Add(shi);
                shi.MouseClick  += new MouseEventHandler(chessItem_MouseClick);
                chessArray[0, i] = (byte)shi.PieceType;
            }

            jiang               = new King();
            jiang.Type          = ChessType.Red;
            jiang.GridX         = 4;
            jiang.GridY         = 0;
            jiang.PreviousGridX = 4;
            jiang.PreviousGridY = 0;
            jiang.Text          = "将";
            jiang.InitChess();
            this.panel1.Controls.Add(jiang);
            jiang.MouseClick += new MouseEventHandler(chessItem_MouseClick);
            jiang.BeRemoved  += new EventHandler(_beRemovedEventHandler);
            //jiang.IsMoved += new EventHandler(checkKingFaceToFace);
            chessArray[0, 4] = (byte)jiang.PieceType;

            for (int i = 0; i <= 8; i += 2)
            {
                Pawn bing = new Pawn();
                bing.Type          = ChessType.Red;
                bing.GridX         = i;
                bing.GridY         = 3;
                bing.PreviousGridX = i;
                bing.PreviousGridY = 3;
                bing.Text          = "兵";
                bing.InitChess();
                this.panel1.Controls.Add(bing);
                bing.MouseClick += new MouseEventHandler(chessItem_MouseClick);
                chessArray[3, i] = (byte)bing.PieceType;
            }
            #endregion

            #region 放置棋子,黑方
            for (int i = 0; i <= 8; i += 8)
            {
                Rook ju1 = new Rook();
                ju1.Type          = ChessType.Black;
                ju1.GridX         = i;
                ju1.GridY         = 9;
                ju1.PreviousGridX = i;
                ju1.PreviousGridY = 9;
                ju1.Text          = "車";
                ju1.InitChess();
                this.panel1.Controls.Add(ju1);
                ju1.MouseClick  += new MouseEventHandler(chessItem_MouseClick);
                chessArray[9, i] = (byte)ju1.PieceType;
            }

            for (int i = 1; i <= 7; i += 6)
            {
                Knight ma = new Knight();
                ma.Type          = ChessType.Black;
                ma.GridX         = i;
                ma.GridY         = 9;
                ma.PreviousGridX = i;
                ma.PreviousGridY = 9;
                ma.Text          = "馬";
                ma.InitChess();
                this.panel1.Controls.Add(ma);
                ma.MouseClick   += new MouseEventHandler(chessItem_MouseClick);
                chessArray[9, i] = (byte)ma.PieceType;

                //因为“炮”与“马”的位置都类似,循环次数也一样
                Cannon pao = new Cannon();
                pao.Type          = ChessType.Black;
                pao.GridX         = i;
                pao.GridY         = 7;
                pao.PreviousGridX = i;
                pao.PreviousGridY = 7;
                pao.Text          = "炮";
                pao.InitChess();
                this.panel1.Controls.Add(pao);
                pao.MouseClick  += new MouseEventHandler(chessItem_MouseClick);
                chessArray[7, i] = (byte)pao.PieceType;
            }

            for (int i = 2; i <= 6; i += 4)
            {
                Bishop xiang = new Bishop();
                xiang.Type          = ChessType.Black;
                xiang.GridX         = i;
                xiang.GridY         = 9;
                xiang.PreviousGridX = i;
                xiang.PreviousGridY = 9;
                xiang.Text          = "象";
                xiang.InitChess();
                this.panel1.Controls.Add(xiang);
                xiang.MouseClick += new MouseEventHandler(chessItem_MouseClick);
                chessArray[9, i]  = (byte)xiang.PieceType;
            }

            for (int i = 3; i <= 6; i += 2)
            {
                Advisor shi = new Advisor();
                shi.Type          = ChessType.Black;
                shi.GridX         = i;
                shi.GridY         = 9;
                shi.PreviousGridX = i;
                shi.PreviousGridY = 9;
                shi.Text          = "仕";
                shi.InitChess();
                this.panel1.Controls.Add(shi);
                shi.MouseClick  += new MouseEventHandler(chessItem_MouseClick);
                chessArray[9, i] = (byte)shi.PieceType;
            }

            shuai               = new King();
            shuai.Type          = ChessType.Black;
            shuai.GridX         = 4;
            shuai.GridY         = 9;
            shuai.PreviousGridX = 4;
            shuai.PreviousGridY = 9;
            shuai.Text          = "帅";
            shuai.InitChess();
            this.panel1.Controls.Add(shuai);
            shuai.MouseClick += new MouseEventHandler(chessItem_MouseClick);
            shuai.BeRemoved  += new EventHandler(_beRemovedEventHandler);
            //shuai.IsMoved += new EventHandler(checkKingFaceToFace);
            chessArray[9, 4] = (byte)shuai.PieceType;

            for (int i = 0; i <= 8; i += 2)
            {
                Pawn bing = new Pawn();
                bing.Type          = ChessType.Black;
                bing.GridX         = i;
                bing.GridY         = 6;
                bing.PreviousGridX = i;
                bing.PreviousGridY = 6;
                bing.Text          = "卒";
                bing.InitChess();
                this.panel1.Controls.Add(bing);
                bing.MouseClick += new MouseEventHandler(chessItem_MouseClick);
                chessArray[6, i] = (byte)bing.PieceType;
            }
            #endregion
        }
Ejemplo n.º 2
0
        /// <summary>
        /// the chess type
        /// r/R:Rook
        /// n/N:Knight
        /// b/B:Bishop
        /// a/A:Advisor
        /// k/K:King
        /// c/C:Cannon
        /// p/P:Pawn
        /// </summary>
        private void createPiece(byte theChessType)
        {
            switch (theChessType)
            {
            case 82:
            case 114:
                //车
                Rook ju1 = new Rook(theChessType);

                ju1.GridX         = m_IndexX;
                ju1.GridY         = m_IndexY;
                ju1.PreviousGridX = m_IndexX;
                ju1.PreviousGridY = m_IndexY;
                ju1.InitChess();
                this.panel1.Controls.Add(ju1);
                ju1.MouseClick += new MouseEventHandler(chessItem_MouseClick);
                chessArray[m_IndexY, m_IndexX] = (byte)ju1.PieceType;
                break;

            case 78:
            case 110:
                //马
                Knight ma = new Knight(theChessType);
                ma.GridX         = m_IndexX;
                ma.GridY         = m_IndexY;
                ma.PreviousGridX = m_IndexX;
                ma.PreviousGridY = m_IndexY;
                ma.InitChess();
                this.panel1.Controls.Add(ma);
                ma.MouseClick += new MouseEventHandler(chessItem_MouseClick);
                chessArray[m_IndexY, m_IndexX] = (byte)ma.PieceType;
                break;

            case 66:
            case 98:
                //象
                Bishop xiang = new Bishop(theChessType);
                xiang.GridX         = m_IndexX;
                xiang.GridY         = m_IndexY;
                xiang.PreviousGridX = m_IndexX;
                xiang.PreviousGridY = m_IndexY;

                xiang.InitChess();
                this.panel1.Controls.Add(xiang);
                xiang.MouseClick += new MouseEventHandler(chessItem_MouseClick);
                chessArray[m_IndexY, m_IndexX] = (byte)xiang.PieceType;
                break;

            case 65:
            case 97:
                //士
                Advisor shi = new Advisor(theChessType);
                shi.GridX         = m_IndexX;
                shi.GridY         = m_IndexY;
                shi.PreviousGridX = m_IndexX;
                shi.PreviousGridY = m_IndexY;
                shi.InitChess();
                this.panel1.Controls.Add(shi);
                shi.MouseClick += new MouseEventHandler(chessItem_MouseClick);
                chessArray[m_IndexY, m_IndexX] = (byte)shi.PieceType;
                break;

            case 75:
                //将
                jiang = new King(theChessType);

                jiang.GridX         = m_IndexX;
                jiang.GridY         = m_IndexY;
                jiang.PreviousGridX = m_IndexX;
                jiang.PreviousGridY = m_IndexY;

                jiang.InitChess();
                this.panel1.Controls.Add(jiang);
                jiang.MouseClick += new MouseEventHandler(chessItem_MouseClick);
                jiang.BeRemoved  += new EventHandler(_beRemovedEventHandler);
                //jiang.IsMoved += new EventHandler(checkKingFaceToFace);
                chessArray[m_IndexY, m_IndexX] = (byte)jiang.PieceType;
                break;

            case 107:
                //帅
                shuai = new King(theChessType);

                shuai.GridX         = m_IndexX;
                shuai.GridY         = m_IndexY;
                shuai.PreviousGridX = m_IndexX;
                shuai.PreviousGridY = m_IndexY;
                shuai.InitChess();
                this.panel1.Controls.Add(shuai);
                shuai.MouseClick += new MouseEventHandler(chessItem_MouseClick);
                shuai.BeRemoved  += new EventHandler(_beRemovedEventHandler);
                //shuai.IsMoved += new EventHandler(checkKingFaceToFace);
                chessArray[m_IndexY, m_IndexX] = (byte)shuai.PieceType;
                break;

            case 67:
            case 99:
                //炮
                Cannon pao = new Cannon(theChessType);

                pao.GridX         = m_IndexX;
                pao.GridY         = m_IndexY;
                pao.PreviousGridX = m_IndexX;
                pao.PreviousGridY = m_IndexY;

                pao.InitChess();
                this.panel1.Controls.Add(pao);
                pao.MouseClick += new MouseEventHandler(chessItem_MouseClick);
                chessArray[m_IndexY, m_IndexX] = (byte)pao.PieceType;
                break;

            case 80:
            case 112:
                //兵
                Pawn bing = new Pawn(theChessType);

                bing.GridX         = m_IndexX;
                bing.GridY         = m_IndexY;
                bing.PreviousGridX = m_IndexX;
                bing.PreviousGridY = m_IndexY;
                bing.InitChess();
                this.panel1.Controls.Add(bing);
                bing.MouseClick += new MouseEventHandler(chessItem_MouseClick);
                chessArray[m_IndexY, m_IndexX] = (byte)bing.PieceType;
                break;
            }
            m_IndexX++;
        }