示例#1
0
        // ------------------- 棋子操作 ------------------------
        // 落子
        public bool TryPlaceChessAt(int campId, int dir, Hex coord)
        {
            CellObjCtrl cctrl = _GridCtrl.GetCellCtrlAt(coord);

            if (cctrl == null)
            {
                return(false);
            }
            if (cctrl.IsBlocked())
            {
                return(false);
            }
            if (cctrl._TgtObj != null)
            {
                return(false);
            }

            cctrl.SetDir(dir);
            _MiroMgr.SetMiroPrefabID(campId);

            _MiroMgr.SpawnAtCellCtrl(cctrl);
            cctrl.SetDir(dir);
            cctrl.PointToCurrentDir();

            //int direction = cctrl.GetDir ();
            return(true);
        }
示例#2
0
        public List <CellObjCtrl> GetEmptyPlacableCellObjCtrls()
        {
            List <CellObjCtrl> epCtrls = new List <CellObjCtrl> ();

            foreach (GameObject ctrlObj in _Cells)
            {
                CellObjCtrl cctrl = ctrlObj.GetComponent <CellObjCtrl> ();
                if (cctrl._TgtObj == null && !cctrl.IsBlocked())
                {
                    epCtrls.Add(cctrl);
                }
            }

            return(epCtrls);
        }
示例#3
0
        public List <Hex> GetAllPlacableHexes()
        {
            List <Hex> lstHexes = new List <Hex> ();

            foreach (KeyValuePair <Hex, GameObject> item in _HexToCells)
            {
                CellObjCtrl ctrl =
                    item.Value.GetComponent <CellObjCtrl> ();
                bool bBlocked = ctrl.IsBlocked();
                if (!bBlocked)
                {
                    lstHexes.Add(item.Key);
                }
            }
            return(lstHexes);
        }
示例#4
0
        // Update is called once per frame
        void Update()
        {
            CellObjCtrl ctrlA =
                _TwoObj._A.GetComponent <CellObjCtrl> ();
            CellObjCtrl ctrlB =
                _TwoObj._B.GetComponent <CellObjCtrl> ();
            bool bBlockA = ctrlA.IsBlocked();
            bool bBlockB = ctrlB.IsBlocked();
            bool bBlock  = bBlockA || bBlockB;

            LineRenderer lr      = GetComponent <LineRenderer> ();
            Color        startCr = GetColorWithBlockState(bBlock);
            Color        endCr   = GetColorWithBlockState(bBlock);

            lr.startColor = startCr;
            lr.endColor   = endCr;
        }
示例#5
0
        public bool IsBlockedAtHex(Hex h)
        {
            if (!_HexToCells.ContainsKey(h))
            {
                return(true);
            }
            var cellObj = _HexToCells[h];

            if (cellObj == null)
            {
                return(true);
            }

            CellObjCtrl cctrl   = cellObj.GetComponent <CellObjCtrl> ();
            bool        blocked = cctrl.IsBlocked();

            return(blocked);
        }
示例#6
0
        private bool GetCellObjCtrlPair(out CellObjCtrl ctrlA, out CellObjCtrl ctrlB)
        {
            ctrlA = null;
            ctrlB = null;
            int cellCnt =
                _gridCtrl._Cells.Count;

            int rId = (int)Random.Range(0, (float)cellCnt - 1.0f);

            GameObject gb = _gridCtrl._Cells [rId];

            ctrlA = gb.GetComponent <CellObjCtrl> ();
            bool bPlacableA = !ctrlA.IsBlocked();
            bool bOccupiedA = CellObjCtrlUtils.IsControllingObj(ctrlA) && bPlacableA;

            if (bOccupiedA)
            {
                return(false);
            }

            HexCoord hc = gb.GetComponent <HexCoord> ();

            if (hc._hex.q == 0 && hc._hex.r == 0 && hc._hex.s == 0)
            {
                return(false);
            }

            Hex hA = hc._hex;
            Hex h0 = new Hex(0, 0, 0);
            Hex hB = Hex.Subtract(h0, hA);

            ctrlB = _gridCtrl.GetCellCtrlAt(hB);
            bool bPlacableB = !ctrlB.IsBlocked();
            bool bOccupiedB = CellObjCtrlUtils.IsControllingObj(ctrlB) && bPlacableB;

            if (bOccupiedB)
            {
                return(false);
            }

            return(true);
        }
示例#7
0
        public bool SetDirAt(Hex coord, int dir)
        {
            CellObjCtrl cctrl = _GridCtrl.GetCellCtrlAt(coord);

            if (cctrl == null)
            {
                return(false);
            }
            if (cctrl.IsBlocked())
            {
                return(false);
            }
            if (cctrl._TgtObj == null)
            {
                return(false);
            }

            cctrl.SetDir(dir);
            return(true);
        }
示例#8
0
        public bool TurnDirAt(Hex coord, int DirChange = 1)
        {
            CellObjCtrl cctrl = _GridCtrl.GetCellCtrlAt(coord);

            if (cctrl == null)
            {
                return(false);
            }
            if (cctrl.IsBlocked())
            {
                return(false);
            }
            if (cctrl._TgtObj == null)
            {
                return(false);
            }

            cctrl.TurnToDir(cctrl.GetDir() + DirChange);
            return(true);
        }
示例#9
0
        public bool TryMoveAlongDirAt(Hex coord, int dir = -1)
        {
            CellObjCtrl cctrl = _GridCtrl.GetCellCtrlAt(coord);

            if (cctrl == null)
            {
                return(false);
            }
            if (cctrl.IsBlocked())
            {
                return(false);
            }
            if (cctrl._TgtObj == null)
            {
                return(false);
            }

            if (dir >= 0 && dir <= 5)
            {
                cctrl.TurnToDir(dir);
            }

            CellObjCtrl fwdCCtrl = CellObjCtrlUtils.GetFwdCellObjCtrl(cctrl);

            if (fwdCCtrl == null)
            {
                return(false);
            }
            if (fwdCCtrl.IsBlocked())
            {
                return(false);
            }
            if (fwdCCtrl._TgtObj != null)
            {
                return(false);
            }

            _MiroMgr.MoveFwdInTF(cctrl.transform);

            return(false);
        }
示例#10
0
        private bool GetRandomEmptyCellObjCtrl(
            List <CellObjCtrl> epCtrls, out CellObjCtrl ctrlA)
        {
            ctrlA = null;

            int cellCnt =
                epCtrls.Count;

            int rId = (int)Random.Range(0, (float)cellCnt - 1.0f);

            ctrlA = epCtrls [rId];
            bool bPlacableA = !ctrlA.IsBlocked();
            bool bOccupiedA = CellObjCtrlUtils.IsControllingObj(ctrlA) && bPlacableA;

            if (bOccupiedA)
            {
                return(false);
            }

            return(true);
        }
示例#11
0
        private bool CheckBlock()
        {
            CellObjCtrl ctrl = GetComponentInParent <CellObjCtrl> ();

            return(ctrl.IsBlocked());
        }
示例#12
0
        public void TurnSpriteOnBlockState()
        {
            SpriteRenderer sr = GetComponent <SpriteRenderer> ();

            sr.enabled = !_cellObjCtrl.IsBlocked();
        }