public override void BeSelected() { List <CLocation> list = new List <CLocation>(); //8 ô xung quanh nó CLocation c; //0 +1 c = new CLocation(Location.X, Location.Y + 1); if (CHelper.CheckLocation(c)) { list.Add(c); } //0 -1 c = new CLocation(Location.X, Location.Y - 1); if (CHelper.CheckLocation(c)) { list.Add(c); } //+1 0 c = new CLocation(Location.X + 1, Location.Y); if (CHelper.CheckLocation(c)) { list.Add(c); } //-1 0 c = new CLocation(Location.X - 1, Location.Y); if (CHelper.CheckLocation(c)) { list.Add(c); } //+1 +1 c = new CLocation(Location.X + 1, Location.Y + 1); if (CHelper.CheckLocation(c)) { list.Add(c); } //+1 -1 c = new CLocation(Location.X + 1, Location.Y - 1); if (CHelper.CheckLocation(c)) { list.Add(c); } //-1 +1 c = new CLocation(Location.X - 1, Location.Y + 1); if (CHelper.CheckLocation(c)) { list.Add(c); } //-1 -1 c = new CLocation(Location.X - 1, Location.Y - 1); if (CHelper.CheckLocation(c)) { list.Add(c); } foreach (var item in list) { Cell cell = ChessBoard.Current.Cells[item.X][item.Y]; if (cell.CurrentPiece == null) { _targetedCells.Add(cell); } else if (cell.CurrentPiece.Player != BaseGameCTL.Current.CurrentPlayer) { _targetedCells.Add(cell); } } foreach (var item in _targetedCells) { item.SetCellState(ECellState.TARGETED); } }
public override void BeSelected() { ///Thực hiện kiểm tra 4 đường chéo, cho đến khi gặp điểm dừng //1. Phải trên : x++ y++ CLocation c; c = this.Location; while (true) { c = new CLocation(c.X + 1, c.Y + 1); if (CHelper.CheckLocation(c)) { Cell cell = ChessBoard.Current.Cells[c.X][c.Y]; if (cell.CurrentPiece != null) { if (cell.CurrentPiece.Player != BaseGameCTL.Current.CurrentPlayer) { _targetedCells.Add(cell); } break; } _targetedCells.Add(cell); } else { break; } } //2. Phải dưới : x++ y-- c = this.Location; while (true) { c = new CLocation(c.X + 1, c.Y - 1); if (CHelper.CheckLocation(c)) { Cell cell = ChessBoard.Current.Cells[c.X][c.Y]; if (cell.CurrentPiece != null) { if (cell.CurrentPiece.Player != BaseGameCTL.Current.CurrentPlayer) { _targetedCells.Add(cell); } break; } _targetedCells.Add(cell); } else { break; } } //3. Trái trên : x-- y++ c = this.Location; while (true) { c = new CLocation(c.X - 1, c.Y + 1); if (CHelper.CheckLocation(c)) { Cell cell = ChessBoard.Current.Cells[c.X][c.Y]; if (cell.CurrentPiece != null) { if (cell.CurrentPiece.Player != BaseGameCTL.Current.CurrentPlayer) { _targetedCells.Add(cell); } break; } _targetedCells.Add(cell); } else { break; } } //4. Trái dưới : x-- y-- c = this.Location; while (true) { c = new CLocation(c.X - 1, c.Y - 1); if (CHelper.CheckLocation(c)) { Cell cell = ChessBoard.Current.Cells[c.X][c.Y]; if (cell.CurrentPiece != null) { if (cell.CurrentPiece.Player != BaseGameCTL.Current.CurrentPlayer) { _targetedCells.Add(cell); } break; } _targetedCells.Add(cell); } else { break; } } foreach (var item in _targetedCells) { item.SetCellState(ECellState.TARGETED); } }
private List <CLocation> getTargetableLocation() { List <CLocation> list = new List <CLocation>(); CLocation c; //1 c = new CLocation(this.Location.X + 2, this.Location.Y - 1); if (CHelper.CheckLocation(c)) { list.Add(c); } //2 c = new CLocation(this.Location.X + 2, this.Location.Y + 1); if (CHelper.CheckLocation(c)) { list.Add(c); } //3 c = new CLocation(this.Location.X - 2, this.Location.Y - 1); if (CHelper.CheckLocation(c)) { list.Add(c); } //4 c = new CLocation(this.Location.X - 2, this.Location.Y + 1); if (CHelper.CheckLocation(c)) { list.Add(c); } //5 c = new CLocation(this.Location.X + 1, this.Location.Y + 2); if (CHelper.CheckLocation(c)) { list.Add(c); } //6 c = new CLocation(this.Location.X - 1, this.Location.Y + 2); if (CHelper.CheckLocation(c)) { list.Add(c); } //7 c = new CLocation(this.Location.X + 1, this.Location.Y - 2); if (CHelper.CheckLocation(c)) { list.Add(c); } //8 c = new CLocation(this.Location.X - 1, this.Location.Y - 2); if (CHelper.CheckLocation(c)) { list.Add(c); } return(list); }