Exemplo n.º 1
0
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                if (hit.transform.gameObject.GetComponent <Piece>())
                {
                    if ((local || whiteTurn == white))
                    {
                        if (hit.transform.gameObject.GetComponent <Piece>().white == whiteTurn && !hit.transform.gameObject.GetComponent <Piece>().isGhost)
                        {
                            Deselect();
                            currentPiece    = hit.transform.gameObject.GetComponent <Piece>();
                            currentMaterial = currentPiece.GetComponentInChildren <MeshRenderer>().material;
                            currentPiece.GetComponentInChildren <MeshRenderer>().material = selectedMaterial;
                            Board.deleteGhosts();
                            Board.placeGhostPiece(currentPiece);
                            Debug.Log("selected " + HighMath.mathPosToString(currentPiece.getPos()));
                        }
                    }
                }
            }
        }
        else if (Input.GetMouseButtonUp(0))
        {
            if (currentPiece != null)
            {
                if (!canceling)
                {
                    RaycastHit hit;
                    Ray        ray = cam.ScreenPointToRay(Input.mousePosition);

                    if (Physics.Raycast(ray, out hit))
                    {
                        // TODO: if hit is ghost piece or enemy within legal distance

                        /*if (!hit.transform.gameObject.GetComponent<Piece>())
                         * {
                         *  //currentPiece.transform.position = new Vector3(hit.transform.position.x, currentPiece.transform.position.y, hit.transform.position.z);
                         *  Board.GetComponent<Board>().move(currentPiece, new Vector3(hit.transform.position.x, currentPiece.transform.position.y, hit.transform.position.z));
                         *  Deselect();
                         *  whiteTurn = !whiteTurn;
                         * }
                         * else
                         * {
                         *  if (hit.transform.gameObject.GetComponent<Piece>().white != whiteTurn)
                         *  {
                         *      //currentPiece.transform.position = new Vector3(hit.transform.position.x, currentPiece.transform.position.y, hit.transform.position.z);
                         *      Board.GetComponent<Board>().move(currentPiece, new Vector3(hit.transform.position.x, currentPiece.transform.position.y, hit.transform.position.z));
                         *      Deselect();
                         *      Destroy(hit.transform.gameObject);
                         *      whiteTurn = !whiteTurn;
                         *  }
                         * }*/

                        int[] startMathPos = HighMath.getPieceMathPos(currentPiece);
                        int[] endMathPos   = new int[3];

                        if (hit.transform.gameObject.GetComponent <Piece>())
                        {
                            if (hit.transform.gameObject.GetComponent <Piece>().isGhost)
                            {
                                //endMathPos[0] = hit.transform.gameObject.GetComponent<Piece>().mathPos[0];
                                //endMathPos[1] = hit.transform.gameObject.GetComponent<Piece>().mathPos[1];
                                //endMathPos[2] = 0;

                                endMathPos = HighMath.getPieceMathPos(hit.transform.gameObject.GetComponent <Piece>());

                                if (move(startMathPos, endMathPos))
                                {
                                    if (!local)
                                    {
                                        network.SendMove(startMathPos, endMathPos);
                                    }
                                    Deselect();
                                    whiteTurn = !whiteTurn;
                                    Board.deleteGhosts();
                                }
                            }
                            else
                            {
                                /*endMathPos[0] = (int)(Mathf.Floor(hit.transform.localPosition.x));
                                 * endMathPos[1] = (int)(Mathf.Floor(hit.transform.localPosition.z));
                                 * endMathPos[2] = 0;*/
                            }
                        }
                        else
                        {
                            /*endMathPos[0] = (int)(Mathf.Floor(hit.transform.localPosition.x));
                             * endMathPos[1] = (int)(Mathf.Floor(hit.transform.localPosition.z));
                             * endMathPos[2] = 0;*/
                        }


                        //Board.deleteGhosts();
                    }
                    else
                    {
                        Deselect();
                    }
                }
                else
                {
                    canceling = false;
                }
            }
        }
    }
Exemplo n.º 2
0
 public int[] getPos()
 {
     return(HighMath.CombineDimention(mathPos, HighMath.removeLowerDimention(getPlane().originMathPos)));
 }
Exemplo n.º 3
0
    public void initializeBoard()
    {
        int planeAmount = size[2] * size[3] * size[4] * size[5] * size[6] * size[7] * size[8] * size[9];

        for (int n3 = 0; n3 < size[2]; n3++)
        {
            for (int n4 = 0; n4 < size[3]; n4++)
            {
                for (int n5 = 0; n5 < size[4]; n5++)
                {
                    for (int n6 = 0; n6 < size[5]; n6++)
                    {
                        for (int n7 = 0; n7 < size[6]; n7++)
                        {
                            for (int n8 = 0; n8 < size[7]; n8++)
                            {
                                for (int n9 = 0; n9 < size[8]; n9++)
                                {
                                    for (int n10 = 0; n10 < size[9]; n10++)
                                    {
                                        Vector3 pos = new Vector3(n3 * 10
                                                                  + ((n5 == 0) ? 0 : 1) * n5 * size[2] * 10 + n5 * 1.5f
                                                                  + ((n7 == 0) ? 0 : 1) * n7 * size[2] * size[4] * 10 + n7 * 10
                                                                  + ((n9 == 0) ? 0 : 1) * n9 * size[2] * size[4] * size[6] * 10 + n9 * 20
                                                                  , 0,
                                                                  n4 * 10
                                                                  + ((n6 == 0) ? 0 : 1) * n6 * size[3] * 10 + n6 * 1.5f
                                                                  + ((n8 == 0) ? 0 : 1) * n8 * size[3] * size[5] * 10 + n8 * 10
                                                                  + ((n10 == 0) ? 0 : 1) * n10 * size[3] * size[5] * size[7] * 10 + n10 * 20
                                                                  );
                                        GameObject plane         = Instantiate(planePrefSetUp, pos, Quaternion.identity, this.transform);
                                        int[]      originMathPos = { 0, 0, n3, n4, n5, n6, n7, n8, n9, n10 };
                                        plane.GetComponent <Plane>().originMathPos = originMathPos;

                                        GameObject decorOfPlane = Instantiate(defDecorPref, pos, Quaternion.identity, Decor.transform);


                                        decorOfPlane.transform.GetChild(0).GetComponent <TextMesh>().text = HighMath.mathPosToString(originMathPos);


                                        GameObject Piece = Instantiate(Knight, pos + new Vector3(1 + 0.5f, 0.5f, 2 + 0.5f), Quaternion.identity, plane.transform);
                                        //GameObject Piece2 = Instantiate(Pawn, pos+ new Vector3(0.5f,0.5f,0.5f)*2, Quaternion.identity, plane.transform);
                                        //Instantiate(Knight, pos + new Vector3(1.5f, 0.5f, 1.5f) * 2, Quaternion.identity, plane.transform);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }



        /*
         * Vector3 pos = new Vector3(n3 * 10 + ((n5==0)?0:1)*size[2]*10+ n5* 1.5f, 0, n4 * 10 + ((n6 == 0) ? 0 : 1) * size[3] * 10 + n6 * 1.5f);
         *              GameObject plane = Instantiate(planePref, pos, Quaternion.identity, this.transform);
         *              int[] originMathPos = { 0, 0, n3, n4, n5, n6, 0, 0, 0, 0 };
         *              plane.GetComponent<Plane>().originMathPos = originMathPos;
         *
         *              GameObject decorOfPlane = Instantiate(defDecorPref, pos, Quaternion.identity, Decor.transform);
         *
         * */
    }