//棋子移動 private IEnumerator Cor_ChessMove() { //TODO:棋子移動特效 ChessBehavior originChess = ChessboardManager.Instance.playerMoveAction.OriginChess; //所選棋子 CellBehavior targetCell = ChessboardManager.Instance.playerMoveAction.TargetCell; //目標格 ChessboardManager.Instance.Move(originChess, targetCell, true); //棋子移動程序 if ((originChess.chessPlayer == Camps.正面方 && originChess.isKing && targetCell.cTag == CellTag.正面方升變棋盤格) || (originChess.chessPlayer == Camps.反面方 && originChess.isKing && targetCell.cTag == CellTag.反面方升變棋盤格)) { if (conquerPlayer == Camps.無) { conquerPlayer = nowPlayer; //若王走到底, 則記錄玩家陣營至下一回合判斷勝負 } } StartCoroutine(Cor_LevelUp(originChess, targetCell, ChessboardManager.Instance.playerMoveAction.moveMode)); //升變 StartCoroutine(Cor_Eat()); //吃子 yield return(new WaitUntil(() => (pcs_eat && pcs_levelUp))); //吃子與升變程序都完成時 pcs_eat = false; pcs_levelUp = false; StepEnd = true; //玩家下棋指令結束 }
override public void Interact() { player.targetCell = null; GameObject pointer = player.GetOnPointer(); if (pointer != null) { PointerController controller = pointer.GetComponent <PointerController>(); CellBehavior target = controller.Target; // delete the array (but not really) if (target != null && target.owningArray != null) { CellArray array = target.owningArray; for (int i = 0; i < array.Count; i++) { GameObject go = array.Get(i); go.SetActive(false); } player.levelController.OnFree(controller, player, true); controller.Target = null; } else if (target != null) { // delete just the single entity target.gameObject.SetActive(false); player.levelController.OnFree(controller, player, false); controller.Target = null; } } player.UnLock(); }
void Awake() { id = "O"; text = gameObject.transform.Find("mod/canvas/text").GetComponent <Text>(); offset = 0; originalTarget = null; }
public GameObject GetOnPointer(FootController test, int direction) { Collider2D[] hits = Physics2D.OverlapBoxAll(test.position, new Vector2(test.width, test.height), 0, Utilities.GROUND_MASK); foreach (Collider2D hit in hits) { if (hit != null && hit.gameObject.tag == "pointer") { CellBehavior cc = hit.gameObject.GetComponent <CellBehavior>(); if (!cc.IsBlocked(direction)) { return(hit.gameObject); } } } foreach (Collider2D hit in hits) { if (hit != null && hit.gameObject.tag == "cell") { // does it have a parent that is a linked cell? Transform parentTransform = hit.gameObject.transform.parent; if (parentTransform != null && parentTransform.gameObject.tag == "linkedCell") { return(parentTransform.GetComponentInChildren <PointerController>().gameObject); } else { return(null); } } } return(null); }
public void writeToNbt(NbtCompound tag) { // Write tiles: int[] idArray = new int[this.tiles.Length]; int[] rotationArray = new int[this.tiles.Length]; for (int i = 0; i < this.tiles.Length; i++) { CellState state = this.tiles[i]; idArray[i] = Main.instance.tileRegistry.getIdOfElement(state.data); if (state.rotation == null) { Debug.Log(state.data.name); } rotationArray[i] = state.rotation.id; } tag.setTag("tiles", idArray); tag.setTag("rotations", rotationArray); // Write tile meta: NbtList listTileMeta = new NbtList(NbtTagType.Compound); for (int x = 0; x < this.size; x++) { for (int y = 0; y < this.size; y++) { CellBehavior meta = this.getCellState(x, y).behavior; if (meta != null && meta is IHasData) { NbtCompound behaviorTag = new NbtCompound(); behaviorTag.setTag("xPos", x); behaviorTag.setTag("yPos", y); ((IHasData)meta).writeToNbt(behaviorTag); listTileMeta.Add(behaviorTag); } } } tag.setTag("meta", listTileMeta); // Write fog: if (this.hasFog()) { NbtCompound fogTag = new NbtCompound(); this.fog.writeToNbt(fogTag); tag.setTag("fog", fogTag); } // Write temperature: int[] tempArray = new int[this.temperatures.Length]; for (int i = 0; i < this.temperatures.Length; i++) { tempArray[i] = (int)(this.temperatures[i] * 1_000_000f); } tag.setTag("temperature", tempArray); // Write hardness: tag.setTag("hardness", this.hardness); }
//設置棋子於指定位置 //[input] name=棋子名稱 / pos=位置 / player=玩家陣營(True=正面方/False=反面方) / isKing=是否為王 public void CreateChess(AnimalChessName name, CellBehavior cell, Camps player, bool isKing) { GameObject chessGo = Instantiate(chessPrefab, cell.GetComponent <RectTransform>()); //創建指定的棋子物件 ChessBehavior ChessScript = chessGo.GetComponent <ChessBehavior>(); //取得棋子腳本 ChessScript.ChessInitialize(Dict_ChessAttribute[name], player, isKing); //套用棋子屬性設定 cell.chessScript = ChessScript; //將棋子腳本註冊至所在的棋格上 }
override public void InActive() { if (originalPointer != null) { originalPointer.Target = originalTarget; originalPointer.CurrentOffset = null; originalTarget = null; originalPointer = null; } }
//棋子移動(多載2/2) 指定棋子到格子 public void Move(ChessBehavior originChess, CellBehavior targetCell, bool clearOriginCell) { if (originChess.transform.parent == null) { _Move(null, originChess, targetCell, clearOriginCell); } else { _Move(originChess.transform.parent.GetComponent <CellBehavior>(), originChess, targetCell, clearOriginCell); } }
public CellBehavior MakeCell(CellTypeData type, int x, int y) { GameObject cell = (GameObject)Instantiate(cellPrefab); cell.transform.position = new Vector2(x, y); CellBehavior cb = cell.GetComponent <CellBehavior> (); cb.typeData = type; cb.Colorize(); cells.Add(cb); return(cb); }
/// <summary> /// Alerts neighbors of a lever being flipped. /// </summary> public static void alertNeighborsOfFlip(CellBehavior leverBehavior) { foreach (Rotation r in Rotation.ALL) { Position p1 = leverBehavior.pos + r; CellBehavior behavior = leverBehavior.world.getBehavior <CellBehavior>(p1); if (behavior is ILeverReciever) { ((ILeverReciever)behavior).onLeverFlip(leverBehavior); } } }
public void notifyOfInfectionChange(CellBehavior cell) { if (cell.IsInfected()) { cell.transform.SetAsLastSibling(); numberOfCellsInfected++; } else { cell.transform.SetAsFirstSibling(); numberOfCellsInfected--; } }
public T getBehavior <T>(Position pos) where T : CellBehavior { CellBehavior behavior = this.getBehavior(pos); if (behavior is T) { return((T)behavior); } else { return(null); } }
public void CheckReachable() { // mark all heap as unreachable foreach (GameObject go in heap.Values) { CellBehavior cb = go.GetComponent <CellBehavior>(); cb.reachable = false; } foreach (GameObject go in stack.Values) { CellBehavior cb = go.GetComponent <CellBehavior>(); if (cb.tag == "pointer") { PointerController pc = (PointerController)cb; if (pc.Target != null) { MarkReachable(pc.Target); } } } int reached = 1; while (reached > 0) { reached = 0; foreach (GameObject go in heap.Values) { CellBehavior cb = go.GetComponent <CellBehavior>(); if (cb.reachable) { if (cb.tag == "pointer") { PointerController pc = (PointerController)cb; if (pc.Target != null) { reached += MarkReachable(pc.Target); } } } } } foreach (GameObject go in heap.Values) { CellBehavior cb = go.GetComponent <CellBehavior>(); if (!cb.reachable) { cb.GetComponent <SpriteRenderer>().color = new Color(0, 0, 0, 1); } } }
override public void Exit(CellBehavior cell) { if (cell.GetType() == typeof(PointerController)) { if (originalPointer != null && originalTarget != null) { // Debug.Log("exited with original Pointer"); originalPointer.Target = originalTarget; originalPointer.CurrentOffset = null; originalPointer = null; originalTarget = null; } } }
int ReachArray(CellBehavior cb) { if (cb.owningArray != null) { int reached = 0; foreach (GameObject sibling in cb.owningArray.objects) { reached += MarkReachable(sibling.GetComponent <CellBehavior>()); } return(reached); } else { return(0); } }
//加入打入預備棋 public void AddDropPawnChess(ChessBehavior originChess, Camps changeTo) { GameObject cellGo = Instantiate(ChessboardManager.Instance.cellPrefab, this.transform); CellBehavior cell = cellGo.GetComponent <CellBehavior>(); dropPawnCells.Add(cell); //加入打入預備棋格物件 cell.cTag = CellTag.打入預備格; //設定格子類型 cell.pos = new Vector2(-100, -100); //設定格子位置 AutoLayout(); //自動調整尺寸 ChessboardManager.Instance.Move(originChess, cell, false); //將棋子移動到打入預備格 originChess.ChessInitialize(ChessboardManager.Instance.Dict_ChessAttribute[originChess.GetAttribure.dropPawnChess], changeTo, originChess.isKing); //若棋子被吃掉後會改變型態, 則更新棋子狀態 }
private static void UpdateAccessoryType(Cell element, UITableViewCell nativeView) { var accessoryType = CellBehavior.GetAccessory(element); switch (accessoryType) { case AccessoryType.HasChildView: nativeView.Accessory = UITableViewCellAccessory.DisclosureIndicator; nativeView.AccessoryView = new CellDisclosureAccessory(); break; default: nativeView.Accessory = UITableViewCellAccessory.None; break; } }
virtual public void Start() { rigidbody = GetComponent <Rigidbody2D>(); foot = transform.Find("foot").GetComponent <FootController>(); loot = transform.Find("loot/canvas/text").GetComponent <Text>(); loot.text = ""; lootSprite = transform.Find("loot").GetComponent <SpriteRenderer>(); levelController = GameObject.Find("/TheLevel").GetComponent <LevelController>(); head = transform.Find("head").GetComponent <FootController>(); targetCell = null; basePointer = null; isAirborne = false; isLocked = false; }
public void OnTransmit(CellBehavior cb, PointerController bp, PlayerController pc, bool read) { string player = pc.avatar; if (pc.CountTools() > 1) { player += pc.ActiveTool.id; } string variable = cb.variableName.ToString(); if (bp != null) { variable = bp.variableName.ToString(); cb = bp; } else if (cb.variableName == 0) { // might have come from permanent memory variable = "'" + cb.GetLoot() + "'"; } while (cb.gameObject.tag == "pointer") { PointerController pointer = (PointerController)cb; cb = pointer.Target; // was it an array access using an offset or a "direct" dereference? if (pointer.CurrentOffset == null) { variable = "*" + variable; } else { string offsetVariable = pointer.CurrentOffset.Player.avatar + pointer.CurrentOffset.id; variable = variable + "[" + offsetVariable + "]"; } } if (read) { consoleController.Status(player + " = " + variable + ";"); } else { consoleController.Status(variable + " = " + player + ";"); } CheckProgress(); }
public bool moveMode; //移動模式(true = 一般 / false = 打入) //建構子 public PlayerMoveAction(ChessBehavior origin, CellBehavior target, bool mode) { isSet = true; OriginChess = origin; TargetCell = target; moveMode = mode; //檢測目標格是否有對方棋子, 若有則設定為被吃掉的棋子 if (target.chessScript != null && target.chessScript.chessPlayer != GameController.Instance.nowPlayer) { EattedChess = target.chessScript; } else { EattedChess = null; } }
// Load data public void LoadData(Array array) { // this.array = array; behavior = new CellBehavior(array); // set column and row headers FixedRows = 1; FixedColumns = 1; // Redim the grid Redim(array.GetLength(0) + FixedRows, array.GetLength(1) + FixedColumns); // Header this[0, 0] = new Header( ); // Column headers for (int i = 1; i < this.ColumnsCount; i++) { ColumnHeader header = new ColumnHeader(i.ToString( )); header.EnableSort = false; this[0, i] = header; } // Row headers for (int i = 1; i < this.RowsCount; i++) { this[i, 0] = new RowHeader(i.ToString( )); } // Data cells Type type = array.GetValue(0, 0).GetType( ); for (int i = 1, ia = 0; i < this.RowsCount; i++, ia++) { for (int j = 1, ja = 0; j < this.ColumnsCount; j++, ja++) { Cell cell = new Cell(array.GetValue(ia, ja), type); cell.Behaviors.Add(behavior); this[i, j] = cell; } } Colorize( ); }
public void onLeverFlip(CellBehavior lever) { Rotation r = this.rotation; for (int i = 0; i < 3; i++) { r = r.clockwise(); // Make sure both sides of the curve point towards a rail if (this.isValidRail(r) && this.isValidRail(r.clockwise())) { this.state.rotation = r; this.dirty(); break; } } }
// Load data public void LoadData( Array array ) { // this.array = array; behavior = new CellBehavior( array ); // set column and row headers FixedRows = 1; FixedColumns = 1; // Redim the grid Redim( array.GetLength( 0 ) + FixedRows, array.GetLength( 1 ) + FixedColumns ); // Header this[0, 0] = new Header( ); // Column headers for ( int i = 1; i < this.ColumnsCount; i++ ) { ColumnHeader header = new ColumnHeader( i.ToString( ) ); header.EnableSort = false; this[0, i] = header; } // Row headers for ( int i = 1; i < this.RowsCount; i++ ) { this[i, 0] = new RowHeader( i.ToString( ) ); } // Data cells Type type = array.GetValue( 0, 0 ).GetType( ); for ( int i = 1, ia = 0; i < this.RowsCount; i++, ia++ ) { for ( int j = 1, ja = 0; j < this.ColumnsCount; j++, ja++ ) { Cell cell = new Cell( array.GetValue( ia, ja ), type ); cell.Behaviors.Add( behavior ); this[i, j] = cell; } } Colorize( ); }
void OnMouseDown() { TileQuery q = new TileQuery (); if (!q.CanBuildAt (x, y)) { return; } CellChoiceBehavior[] behaviors = FindObjectsOfType<CellChoiceBehavior> (); foreach (CellChoiceBehavior b in behaviors) { if (b.IsSelected) { ColonyBehavior colony = GameObject.Find ("colony").GetComponent<ColonyBehavior> (); cell = colony.MakeCell (b.CellType, x, y); } } // new cell was created if (cell != null) { Events.Trigger ("PlaceCell", cell); } }
int MarkReachable(CellBehavior cb) { if (!cb.reachable) { int reached = 1; cb.reachable = true; if (cb.tag == "pointer") { PointerController pc = (PointerController)cb; reached += MarkReachable(pc.Target); } return(reached + ReachArray(cb)); } else { return(0); } }
public ExerciseProgramCellView() { InitializeComponent(); // TODO: setting this from XAML is currently causing a compilation exception (last tried with XF 2.0.0) CellBehavior.SetAccessory(this, AccessoryType.HasChildView); this .WhenActivated( disposables => { this .OneWayBind(this.ViewModel, x => x.Name, x => x.Text) .AddTo(disposables); this .OneWayBind(this.ViewModel, x => x.Duration, x => x.Detail, x => x.ToString("mm\\:ss")) .AddTo(disposables); }); }
public void readFromNbt(NbtCompound tag) { this.aboveGroundMap = tag.getByteArray("aboveGroundMap"); this.workerSpawnPoint = tag.getPosition("workerSpawnPoint"); // Read Layers: NbtList layers = tag.getList("layers"); for (int i = 0; i < layers.Count; i++) { Layer layer = new Layer(this.world, i); NbtCompound layerCompound = layers.Get <NbtCompound>(i); layer.readFromNbt(layerCompound); this.layers[layer.depth] = layer; // Call onCreate method for all the behaviors, now that all Cell's // have been loaded. for (int x = 0; x < this.world.mapSize; x++) { for (int y = 0; y < this.world.mapSize; y++) { CellState state = layer.getCellState(x, y); if (state.behavior != null) { state.behavior.onCreate(this.world, state, new Position(x, y, layer.depth)); } } } // After onCreate is called for all of the behaviors, let them read their // state from NBT. NbtList listBehaviorTags = layerCompound.getList("meta"); foreach (NbtCompound behaviorTag in listBehaviorTags) { CellBehavior meta = layer.getCellState(behaviorTag.getInt("xPos"), behaviorTag.getInt("yPos")).behavior; if (meta != null && meta is IHasData) { ((IHasData)meta).readFromNbt(behaviorTag); } } } }
// When have a collision void OnCollisionEnter2D(Collision2D collision) { // Check if collider is a Virus if (collision.collider.tag == "Cell") { // Find the behavior script this.targetBehavior = collision.collider.gameObject.GetComponent<CellBehavior>(); // Check if not is already infected if (!this.targetBehavior.IsInfected()) { // Copy the cell position this.mover.MoveCopy(collision.collider.gameObject); // Start timer this.timer = Settings.TIME_TRASMISSIONINFECTION; } } }
int testForParent(CellBehavior g) // 0 - absolutely different; 128 - identical; { int ans = 0; for (int i = 0; i < behDNAsize; i++) { if (behDNA[i].ID == g.behDNA[i].ID) { ans++; } } for (int i = 0; i < propDNAsize; i++) { if (propDNA[i] == g.propDNA[i]) { ans++; } } return(ans); }
override public void Active() { originalTarget = null; originalPointer = null; GameObject pointer = player.GetOnPointer(); if (pointer != null) { PointerController controller = pointer.GetComponent <PointerController>(); CellBehavior target = controller.Target; // find the next object in the controller's array if (target != null && target.owningArray != null) { originalTarget = target; originalPointer = controller; originalPointer.CurrentOffset = this; ReTarget(); } } }
public void AddAt(int x, int y, GameObject go) { long key = Key(x, y); objects[key] = go; if (go.tag == "pointer" || go.tag == "cell") { CellBehavior cb = go.GetComponent <CellBehavior>(); if (y == 3) { cb.variableName = go.tag == "pointer" ? variablePointer++ : variableValue++; stack[cb.variableName] = go; cb.reachable = true; } else if (y > 3) { heap[key] = go; cb.heap = true; } } }
//棋子移動判斷 //originCell : 起點格 / targetCell : 目標格 public void ChessMoveTest(CellBehavior originCell, Vector2 targetPos) { List <CellBehavior> movementCellList = new List <CellBehavior>(); movementCellList = GetMovementPos(originCell); if (movementCellList == null || movementCellList.Count == 0) //無法移動至任何格子時, 直接結束程序 { Debug.Log("無法移動至任何格子"); return; } //for (int i = 0; i < movementCellList.Count; i++) //{ // Debug.Log(string.Format("[ {0} ] : ({1}, {2})", i, movementCellList[i].pos.x, movementCellList[i].pos.y)); //} //若可移動格子List中包含欲移動之位置 bool canMove = false; for (int i = 0; i < movementCellList.Count; i++) { if (movementCellList[i].pos == targetPos) { canMove = true; break; } } bool moveMode = (originCell.cTag == CellTag.打入預備格) ? false : true; if (canMove) { playerMoveAction = new PlayerMoveAction(originCell.chessScript, cellsBoard[(int)targetPos.x, (int)targetPos.y], moveMode); //設定玩家棋子移動命令 } else { Debug.Log("無法移動到指定位置"); } }
public static void HandleClick(CellBehavior clickedCell) { int clickedCellID = -1; // Find the cell for (int i = 0; i < instance.grid.Length; i++) { if (instance.grid[i].GetComponent <CellBehavior>() == clickedCell) { clickedCellID = i; break; } } instance.CalcAndFillSquare(clickedCellID); int horizontalOffset = clickedCellID % instance.gridSize; // Fill to the left if a cell exists to the left if (horizontalOffset > 0) { instance.CalcAndFillSquare(clickedCellID - 1); } // Fill to the right if a cell exists to the left if (horizontalOffset < instance.gridSize - 1) { instance.CalcAndFillSquare(clickedCellID + 1); } int verticalOffset = clickedCellID / instance.gridSize; // Fill above if a cell exists above if (verticalOffset > 0) { instance.CalcAndFillSquare(clickedCellID - instance.gridSize); } // Fill below if a cell below exists if (verticalOffset < instance.gridSize - 1) { instance.CalcAndFillSquare(clickedCellID + instance.gridSize); } }
public void RemoveCell(CellBehavior cell) { }
public void AddCell(CellBehavior cell) { cells.Add (cell); }