Exemple #1
0
        public void SetCurrentObject(GameObject currentObject)
        {
            if (currentObject.CompareTag(DataManager.Tag.chessPiece))
            {
                if (this.currentObject?.name != currentObject.name)
                {
                    RemoveAllPositions();
                    this.currentObject = currentObject;

                    ChessPieceState pieceState        = currentObject.GetComponent <ChessPieceState>();
                    List <Vector2>  availablePosition = algorithmManager.GetList(pieceState, DataManager.MyTeam);


                    ShowAvailablePositions(availablePosition);
                }
            }
            else if (currentObject.CompareTag(DataManager.Tag.positionParticle))
            {
                Debug.Log(currentObject.transform.position);
                RemoveAllPositions();
                this.currentObject = null;
            }
            else
            {
                RemoveAllPositions();
                this.currentObject = null;
            }
        }
        public List <GameObject> InstantiateWhite()
        {
            List <GameObject> myPieces = new List <GameObject>();

            try
            {
                int i = 0;
                for (int z = 7; z > 5; z--)
                {
                    for (int x = 0; x < 8; x++)
                    {
                        float                 distance  = DataManager.ChessPieceInfo.distance;
                        Quaternion            rot       = DataManager.ChessPieceInfo.whiteRotation;
                        DataManager.Team      team      = board[x, z].Team;
                        DataManager.PieceName pieceName = board[x, z].PieceName;
                        GameObject            obj       = PhotonNetwork.Instantiate
                                                          (
                            FindObjectNameByEnum(team, pieceName),
                            new Vector3(x * distance, chessBoardStartHeight, z * distance),
                            rot,
                            (byte)0
                                                          );
                        obj.name = board[x, z].PieceName.ToString();
                        obj.AddComponent <InputSender_PC>(); // todo
                        ChessPieceState state = obj.GetComponent <ChessPieceState>();
                        state.Initialize(new Vector3(x * distance, 0, z * distance), (Utility.DataManager.Team)team, (Utility.DataManager.PieceName)pieceName, Utility.DataManager.WhitePiece[i++]);
                        myPieces.Add(obj);
                    }
                }
            }
            catch (ArgumentException) { DoNothing(); }
            return(myPieces);
        }
Exemple #3
0
        private GameObject OnDown()
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit rayHit;

            if (Physics.Raycast(ray, out rayHit, rayLength))
            {
                if (rayHit.collider.gameObject.tag == DataManager.Tag.chessPiece)
                {
                    currentObject = rayHit.collider.gameObject.GetComponent <ChessPieceState>();
                }

                if (rayHit.collider.gameObject.tag == DataManager.Tag.ground)
                {
                    Debug.Log("ground");
                }

                return(rayHit.transform.gameObject);
            }
            else
            {
                return(null);
                // do nothing
            }
        }
        public List <Vector2> GetList(ChessPieceState state, DataManager.Team team)
        {
            this.currentTeam = team;
            this.pieceState  = state;
            DataManager.PieceName name = pieceState.PieceName;
            Vector3 position           = pieceState.Position;
            int     x = (int)(position.x / distance);
            int     z = (int)(position.z / distance);

            if (position.x % distance >= 0.03f)
            {
                x++;
            }
            if (position.z % distance >= 0.03f)
            {
                z++;
            }

            List <Vector2> result = new List <Vector2>();

            switch (name)
            {
            case DataManager.PieceName.King:
                result = King(x, z);
                break;

            case DataManager.PieceName.Queen:
                result = Queen(x, z);
                break;

            case DataManager.PieceName.Rook:
                result = Rook(x, z);
                break;

            case DataManager.PieceName.Bishop:
                result = Bishop(x, z);
                break;

            case DataManager.PieceName.Knight:
                result = Knight(x, z);
                break;

            case DataManager.PieceName.Pawn:
                result = Pawn(x, z);
                break;
            }
            #region debugging codes

            /*
             * if (result.Count != 0)
             *  Debug.Log("Exist");
             * else
             *  Debug.Log("GetList : No Place available");
             * int i = 0;
             * foreach (Vector2 elem in result)
             * {
             *  Debug.Log($"{++i} : x = {elem.x}, z = {elem.y}");
             * }
             */
            #endregion
            return(result);
        }