📄 myframe.h
字号:
/****************************************************
Author: S. Senthil kumar
Class Name: myframe
Purpose: Main GUI as well as encapsulates the Chess Board
******************************************************/
class myframe:public CFrameWnd
{
/*Structure which represents Game Data
Used for opening and saving the game
*/
struct Game
{
int Board[8][8]; //The Board
int WhoseTurn; //The player to start playing
int movecount; //Total No. of Moves
int Base; //Position of White pieces (top or bottom of the board)
int computer_color; //Which color the computer is playing
/*Structure encapsulating castling information
*/
struct CastlingInfoStruct
{
int kingmoved;
int kingrookmoved;
int queenrookmoved;
}CastlingInfo;
};
int playing; //Whether game is being played
CFont chessfont; //Font to display chess pieces
CMenu menu; //Menu Display
int board[8][8]; //The Main Chess Board
int piece; //The Current piece selected
int destpiece; //Piece which might have been cut by the current piece
CListBox movelist; //Listbox to display moves in Algebraic Notation
CEdit whitepieces; //EditBox to display Cut White pieces
CEdit blackpieces; //EditBox to display Cut Black pieces
CEdit help; //EditBox to display Help on Castling
int blackkingmoved; //Boolean variable to check if black king has been moved
int whitekingmoved; //Boolean variable to check if white king has been moved
int king_blackrook; //Boolean variable to check if black rook on King side has been moved
int queen_blackrook; //Boolean variable to check if black rook on Queen side has been moved
int king_whiterook; //Boolean variable to check if white rook on King side has been moved
int queen_whiterook; //Boolean variable to check if white rook on Queen side has been moved
int x; //Multi use variable
LastMove undo; //Structure which stores the last move. Used by unmakemove()
int count;
int style; //Internal variable to display chess squares in correct color
int startsquare[2],endsquare[2]; //Used to store starting and ending positions of a chess move.
int lastmoved; //Used to store who moved last. (White or Black).
int white_cutpiece; //Used to store white piece which has been cut
int black_cutpiece; //Used to store black piece which has been cut
int castling_move; //Whether last move was a castling move.
int enable_menus; //Boolean variable to enable or disable menus while computer is thinking
int music_play; //Boolean variable To start or stop background music
CString castlecondition; //Internal variable to identify whether castling can be done
public:
myframe(); //Constructor
void StartGame(); //Starts a new Game
void SaveGame(); //Saves current Game
void OpenGame(); //Opens a game from Disk
void Exit(); //To exit to Windows
DECLARE_MESSAGE_MAP();
void OnCreate(LPCREATESTRUCT l); //Message Handler
void OnPaint(); //Message Handler
void OnLButtonDown(UINT nflags,CPoint point); //Message Handler
void OnLButtonUp(UINT nflags,CPoint point); //Message Handler
void OnMouseMove(UINT flags,CPoint point); //Message Handler
void myframe::OnDrawItem(int nid,LPDRAWITEMSTRUCT s);
void about(); //Displays about dialog box
/*Initialize board arrangement and display board.
Arguments:
count: Variable which indicates whether this is the first OnPaint message or just refreshing messages
*/
void initializeBoard(int count,CDC *p);
//Moves piece in board array
void movePieceInRealBoard();
/*Moves piece in Display
Arguments:
undercheck: Indicates whether user's King is under check.
x,y,a,b : Used only when undercheck=1. Used for returning piece back to original position.(because king is still under check)
*/
void movePieceInViewBoard(int undercheck,int x=0,int y=0,int a=0,int b=0);
//Returns character corresponding to piece. Used for displaying the pieces using Chess font
char *pieceName(int piece);
/*Arranges pieces other than the pawn.
Arguments:
p: ClientDC for displaying the pieces on board
color: Color to display pieces
*/
void ArrangeOtherPieces(CDC *p,int color);
/*Checks whether move made is valid. Master function
Arguments: None
*/
int validmove();
/*Undoes a move
Arguments: None
*/
void unmakemove();
/*Returns piece at destination
Arguments: x and y of destination square
*/
int NoOtherPiece(int destx,int desty);
/*Finds max and min of two numbers*/
int Max(int x,int y);
int Min(int x,int y);
//int CheckMate();
//void CheckForCheckMate(int board[8][8]);
//int CheckCheck(int target);
/*ValidMove_xxx Functions which check the validity of moves of each piece
Arguments:
startx,starty:Starting square
destx,desty, :Ending square
*/
int ValidMove_Pawn(int startx,int starty,int destx,int desty);
int ValidMove_King(int startx,int starty,int destx,int desty);
int ValidMove_Queen(int startx,int starty,int destx,int desty);
int ValidMove_Bishop(int startx,int starty,int destx,int desty);
int ValidMove_Knight(int startx,int starty,int destx,int desty);
int ValidMove_Rook(int startx,int starty,int destx,int desty);
/*Displays piece cut in the edit box
Arguments:
piece: Id of the piece cut
*/
void DisplayCutPiece(int piece);
//int GenerateAllMoves(int color);
//Starts the thinking of the computer. Driver function
void ComputerPlay();
//int InPieceRange(int target);
//void ProtectKing();
/*Reverses Move if found illegal. (Moving illegal piece when castling).
Arguments: None
*/
void ReverseMove();
/*Redraws the board.
Arguments:
CDC *p: Optional. Uses it if given.
*/
void Refresh(CDC *p=NULL);
//int IsTimeOver();
//Thread which starts the computer thinking
friend UINT StartSearch(LPVOID param);
//Thread which starts the pondering
friend UINT Ponder(LPVOID param);
/*Checks the appropriate menu item in the Level menu
Arguments:None
*/
void SetCheck(CCmdUI *item);
/*Actually sets the level of play. Changes search_depth;
Arguments:
id: Resource id of menu item clicked
*/
void SetLevel(int id);
/*Shows help*/
void debug_show();
/*Rotates board consecutively
Arguments: None
*/
void RotateBoard();
/*Disables or enables menu item according to enable_menus*/
void disenable(CCmdUI *item);
/*Function which displays Options Dialog box*/
void ShowOptions();
/*Actual Function which starts or stops music*/
void ControlMusic();
/*Function which shows stop or play music as appropriate*/
void ShowHideMusicPlay(CCmdUI *item);
/*Castle the king. Only implements the castling
Arguments:
x: piece Id
startx,starty: starting square
destx,desty :destination square
*/
int Castle(int x,int startx,int starty,int destx,int desty);
/*Checks whether Castling is possible. Only implements the checking part
Arguments:
startx,starty: starting square
destx,desty :destination square
*/
int CanCastle(int startx,int starty,int destx,int desty);
/*Function which checks appropriate board size menu item */
void SetSelectedSize(CCmdUI *item);
/*Actually sets the board size and refreshes the whole screen.*/
void SetBoardSize(int id);
/*Saves castling information in the game structure*/
int CanCastle_Save(Game *game);
/*Displays the help edit box on clicking How to castle*/
void ShowCastleHelp();
/*Starts the computer thinking on proposal of draw*/
void ConsiderDraw();
/*Handles resignation*/
void OpponentResigned();
/*Responds to Refresh menu item by calling Refresh(NULL)*/
void RefreshBoard();
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -