Beispiel #1
0
    void GenerateBoard()
    {
        //sets board
        for (int i = 0; i < 8; i++)
        {
            for (int j = 0; j < 8; j++)
            {
                if (i % 2 == j % 2)
                {
                    Spaces[i, j] = (GameObject)Instantiate(Resources.Load("BrownSpace"));
                }
                else
                {
                    Spaces[i, j] = (GameObject)Instantiate(Resources.Load("TanSpace"));
                }
                Spaces[i, j].transform.position = new Vector3(
                    Spaces[i, j].transform.position.x + j, Spaces[i, j].transform.position.y, Spaces[i, j].transform.position.z + i
                    );
            }
        }
        //sets Players pieces
        GameObject newPiece;

        for (int i = 0; i < 2; i++) //Player1
        {
            for (int j = 0; j < 8; j++)
            {
                if (i == 0)
                {
                    switch (j)
                    {
                    case 0:
                        Player1.AddPiece((GameObject)Instantiate(Resources.Load("P1Rook")), "rook", new int[] { i, j });
                        break;

                    case 1:
                        Player1.AddPiece((GameObject)Instantiate(Resources.Load("P1Knight")), "knight", new int[] { i, j });
                        break;

                    case 2:
                        Player1.AddPiece((GameObject)Instantiate(Resources.Load("P1Bishop")), "bishop", new int[] { i, j });
                        break;

                    case 3:
                        Player1.AddPiece((GameObject)Instantiate(Resources.Load("P1Queen")), "queen", new int[] { i, j });
                        break;

                    case 4:
                        Player1.AddPiece((GameObject)Instantiate(Resources.Load("P1King")), "king", new int[] { i, j });
                        break;

                    case 5:
                        newPiece = (GameObject)Instantiate(Resources.Load("P1Bishop"));
                        newPiece.transform.position = new Vector3(
                            -newPiece.transform.position.x, newPiece.transform.position.y, newPiece.transform.position.z
                            );
                        Player1.AddPiece(newPiece, "bishop", new int[] { i, j });
                        break;

                    case 6:
                        newPiece = (GameObject)Instantiate(Resources.Load("P1Knight"));
                        newPiece.transform.position = new Vector3(
                            -newPiece.transform.position.x, newPiece.transform.position.y, newPiece.transform.position.z
                            );
                        Player1.AddPiece(newPiece, "knight", new int[] { i, j });
                        break;

                    case 7:
                        newPiece = (GameObject)Instantiate(Resources.Load("P1Rook"));
                        newPiece.transform.position = new Vector3(
                            -newPiece.transform.position.x, newPiece.transform.position.y, newPiece.transform.position.z
                            );
                        Player1.AddPiece(newPiece, "rook", new int[] { i, j });
                        break;
                    }
                }
                else
                {
                    newPiece = (GameObject)Instantiate(Resources.Load("P1Pawn"));
                    newPiece.transform.position = new Vector3(
                        newPiece.transform.position.x + j, newPiece.transform.position.y, newPiece.transform.position.z
                        );
                    Player1.AddPiece(newPiece, "pawn", new int[] { i, j });
                }
            }
        }

        for (int i = 6; i < 8; i++) //Player2
        {
            for (int j = 0; j < 8; j++)
            {
                if (i == 7)
                {
                    switch (j)
                    {
                    case 0:
                        Player2.AddPiece((GameObject)Instantiate(Resources.Load("P2Rook")), "rook", new int[] { i, j });
                        break;

                    case 1:
                        Player2.AddPiece((GameObject)Instantiate(Resources.Load("P2Knight")), "knight", new int[] { i, j });
                        break;

                    case 2:
                        Player2.AddPiece((GameObject)Instantiate(Resources.Load("P2Bishop")), "bishop", new int[] { i, j });
                        break;

                    case 3:
                        Player2.AddPiece((GameObject)Instantiate(Resources.Load("P2Queen")), "queen", new int[] { i, j });
                        break;

                    case 4:
                        Player2.AddPiece((GameObject)Instantiate(Resources.Load("P2King")), "king", new int[] { i, j });
                        break;

                    case 5:
                        newPiece = (GameObject)Instantiate(Resources.Load("P2Bishop"));
                        newPiece.transform.position = new Vector3(
                            -newPiece.transform.position.x, newPiece.transform.position.y, newPiece.transform.position.z
                            );
                        Player2.AddPiece(newPiece, "bishop", new int[] { i, j });
                        break;

                    case 6:
                        newPiece = (GameObject)Instantiate(Resources.Load("P2Knight"));
                        newPiece.transform.position = new Vector3(
                            -newPiece.transform.position.x, newPiece.transform.position.y, newPiece.transform.position.z
                            );
                        Player2.AddPiece(newPiece, "knight", new int[] { i, j });
                        break;

                    case 7:
                        newPiece = (GameObject)Instantiate(Resources.Load("P2Rook"));
                        newPiece.transform.position = new Vector3(
                            -newPiece.transform.position.x, newPiece.transform.position.y, newPiece.transform.position.z
                            );
                        Player2.AddPiece(newPiece, "rook", new int[] { i, j });
                        break;
                    }
                }
                else
                {
                    newPiece = (GameObject)Instantiate(Resources.Load("P2Pawn"));
                    newPiece.transform.position = new Vector3(
                        newPiece.transform.position.x + j, newPiece.transform.position.y, newPiece.transform.position.z
                        );
                    Player2.AddPiece(newPiece, "pawn", new int[] { i, j });
                }
            }
        }
    }