// ------------------- 棋子操作 ------------------------ // 落子 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); }
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); }
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); }
// 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; }
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); }
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); }
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); }
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); }
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); }
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); }
private bool CheckBlock() { CellObjCtrl ctrl = GetComponentInParent <CellObjCtrl> (); return(ctrl.IsBlocked()); }
public void TurnSpriteOnBlockState() { SpriteRenderer sr = GetComponent <SpriteRenderer> (); sr.enabled = !_cellObjCtrl.IsBlocked(); }