예제 #1
0
    public void PlacePieces(List <string> pieces)
    {
        mPieceManager.KillAllPieces();
        mPieceManager.mWhitePieces.Clear();
        mPieceManager.mBlackPieces.Clear();
        int  count         = 0;
        int  kingCount     = 0;
        bool whiteKingDead = true;
        bool blackKingDead = true;

        for (int i = 0; i < 8; i++)
        {
            for (int j = 0; j < 8; j++)
            {
                if (!pieces[count].Equals("empty"))
                {
                    string[] s = pieces[count].Split('|');

                    string key   = s[0];
                    string color = s[1];
                    if (color.Equals("RGBA(1.000, 1.000, 1.000, 1.000)"))
                    {
                        color = "White";
                    }
                    else
                    {
                        color = "Black";
                    }
                    Type      pieceType = mPieceLibrary[key];
                    BasePiece bp        = mPieceManager.CreatePiece(pieceType);
                    Color32   spriteColor;
                    if (key.Equals("Pawn"))
                    {
                        if (color.Equals("Black") && j != 6)
                        {
                            bp.mIsFirstMove = false;
                        }
                        else if (color.Equals("White") && j != 1)
                        {
                            bp.mIsFirstMove = false;
                        }
                    }
                    if (key.Equals("King"))
                    {
                        kingCount++;
                        if (color.Equals("Black"))
                        {
                            blackKingDead = false;
                        }
                        else if (color.Equals("White"))
                        {
                            whiteKingDead = false;
                        }
                    }
                    if (color.Equals("Black"))
                    {
                        spriteColor = new Color32(0, 0, 0, 255);
                        bp.Setup(Color.black, spriteColor, mPieceManager);
                        mPieceManager.mBlackPieces.Add(bp);
                    }
                    else
                    {
                        spriteColor = new Color32(255, 255, 255, 255);
                        bp.Setup(Color.white, spriteColor, mPieceManager);
                        mPieceManager.mWhitePieces.Add(bp);
                    }
                    bp.mCurrentCell  = mBoard.mAllCells[i, j];
                    bp.mOriginalCell = mBoard.mAllCells[i, j];
                    bp.mCurrentCell.mCurrentPiece = bp;
                    bp.transform.position         = mBoard.mAllCells[i, j].transform.position;
                    bp.gameObject.SetActive(true);
                    //mBoard.mAllCells[i, j].transform.position = bp.transform.position;
                }
                else
                {
                    mBoard.mAllCells[i, j].mCurrentPiece = null;
                }
                count++;
            }
        }
        if (kingCount < 2)
        {
            if (whiteKingDead)
            {
                info.text = "Black wins!";
            }
            else if (blackKingDead)
            {
                info.text = "White wins!";
            }
            p = "CLIENTSEND";
            if (IsHost())
            {
                cs.SendMessage();
            }
            else
            {
                cc.SendMessage();
            }
        }
    }