From 0caf78ba9dfb7d1abb1b06335dc90ffc813f3fb0 Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Tue, 30 Aug 2011 15:17:58 +0000 Subject: [PATCH] fpchess: Improves some coordinates git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1876 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- applications/fpchess/chessgame.pas | 8 +++++++- applications/fpchess/mainform.pas | 7 ++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/applications/fpchess/chessgame.pas b/applications/fpchess/chessgame.pas index 30399da66..84563df85 100644 --- a/applications/fpchess/chessgame.pas +++ b/applications/fpchess/chessgame.pas @@ -114,6 +114,7 @@ type procedure StartNewGame(APlayAsWhite: Integer; AUseTimer: Boolean; APlayerTime: Integer); overload; function ClientToBoardCoords(AClientCoords: TPoint): TPoint; function BoardPosToChessCoords(APos: TPoint): string; + function ColumnNumToLetter(ACol: Integer): string; function CheckStartMove(AFrom: TPoint): Boolean; function CheckEndMove(ATo: TPoint): Boolean; function FindKing(): TPoint; @@ -722,10 +723,15 @@ function TChessGame.BoardPosToChessCoords(APos: TPoint): string; var lStr: string; begin - lStr := Char(APos.X + 96); + lStr := ColumnNumToLetter(APos.X); Result := Format('%s%d', [lStr, APos.Y]); end; +function TChessGame.ColumnNumToLetter(ACol: Integer): string; +begin + Result := Char(ACol + 96); +end; + // Check if we are moving to either an empty space or to an enemy piece function TChessGame.CheckEndMove(ATo: TPoint): Boolean; begin diff --git a/applications/fpchess/mainform.pas b/applications/fpchess/mainform.pas index 0a0ebb06e..88a587904 100644 --- a/applications/fpchess/mainform.pas +++ b/applications/fpchess/mainform.pas @@ -143,13 +143,14 @@ end; procedure TformChess.UpdateCaptions; var - lStr: string; + lStr, lStr2: string; begin if vChessGame.IsWhitePlayerTurn then lStr := 'White playing' else lStr := 'Black playing'; - lStr := lStr + Format(' X: %d Y: %d', - [vChessGame.MouseMovePos.X, vChessGame.MouseMovePos.Y]); + lStr2 := vChessGame.BoardPosToChessCoords(vChessGame.MouseMovePos); + lStr := lStr + Format(' X: %d Y: %d = %s', + [vChessGame.MouseMovePos.X, vChessGame.MouseMovePos.Y, lStr2]); formChess.labelPos.Caption := lStr;