public Piece(Control parent, PieceId id, bool inverted) { this.inverted = inverted; Name = (Id = id).ToString(); ui.Load(fol + (id.Black ? "b" : "w") + id.Who.ToString() + "46.gif"); parent.Controls.Add(ui); ui.BringToFront(); ui.MouseDown += new MouseEventHandler(ui_MouseDown); ui.MouseUp += new MouseEventHandler(ui_MouseUp); ui.MouseMove += new MouseEventHandler(ui_MouseMove); }
/// <summary> /// /// </summary> /// <param name="allPieces"></param> /// <param name="id"></param> /// <returns>null when not found</returns> public static Piece Item(List <Piece> allPieces, PieceId id) { foreach (var item in allPieces) { if (item.Id.Equals(id)) { return(item); } } return(null); }
private bool TryAddSquare(Square s, int x, int y, PieceId piece, bool pawnForward, bool pawnSide) { int newX = s.X + x, newY = s.Y + y; if (newX > 8 || newX < 1 || newY > 8 || newY < 1) { return(false); } Square sq = squares[newX, newY]; if (pawnSide && (sq.Piece.HasValue == false || sq.Piece.Value.Black == piece.Black)) { return(false); //if pawn & sideways, should not be blank or same color } if (sq.Piece.HasValue && (pawnForward || sq.Piece.Value.Black == piece.Black)) { return(false); //blocked by same color / any is pawn going forward } o.Add(sq); return(true); }