From: <pha...@us...> - 2007-08-04 07:03:04
|
Revision: 46 http://chessdrills.svn.sourceforge.net/chessdrills/?rev=46&view=rev Author: phantomfive Date: 2007-08-04 00:03:01 -0700 (Sat, 04 Aug 2007) Log Message: ----------- Fixed a seg fault (bugs already???) and some other minor issues Modified Paths: -------------- base/ChessBoard.cpp base/ChessDrill.cpp base/ChessDrill.h drills/DrillList.h drills/ExampleDrill.cpp gui/GuiControl.cpp gui/GuiControl.h gui/MainWindow.cpp Modified: base/ChessBoard.cpp =================================================================== --- base/ChessBoard.cpp 2007-08-02 07:40:05 UTC (rev 45) +++ base/ChessBoard.cpp 2007-08-04 07:03:01 UTC (rev 46) @@ -18,8 +18,7 @@ #define BOARD_HEIGHT 8 ChessPiece nopiece(CP_NOPIECE,CLR_DEFAULT); -ChessBoard::ChessBoard(){ - +ChessBoard::ChessBoard(){ Reset(); } @@ -71,7 +70,6 @@ //--------------------- // Clears the board //--------------------- -#include <stdio.h> void ChessBoard::Reset(){ int i,j; for(i=0; i<BOARD_WIDTH;i++) Modified: base/ChessDrill.cpp =================================================================== --- base/ChessDrill.cpp 2007-08-02 07:40:05 UTC (rev 45) +++ base/ChessDrill.cpp 2007-08-04 07:03:01 UTC (rev 46) @@ -69,10 +69,12 @@ gui->MovePiece(from, to, captured); } -void ChessDrill::SetSquare(const ChessPiece &piece, const ChessSquare &square){ - gui->SetSquare(piece, square); +void ChessDrill::SetSquare(const ChessColumn &col, const ChessRow &row, + const ChessSquare &square){ + gui->SetSquare(col, row, square); } + void ChessDrill::SetDescription(const std::string &description){ gui->SetDescription(description); } @@ -105,3 +107,6 @@ gui->SetUserColor(color); } +void ChessDrill::SetGuiControl( GuiControl *gui ){ + this->gui = gui; +} Modified: base/ChessDrill.h =================================================================== --- base/ChessDrill.h 2007-08-02 07:40:05 UTC (rev 45) +++ base/ChessDrill.h 2007-08-04 07:03:01 UTC (rev 46) @@ -103,9 +103,11 @@ //This allows you to set up a square any way you like, and erase what was //there before. - //PARAM piece - The square will now have this piece on it. - //PARAM square - The square to set. - void SetSquare(const ChessPiece &piece, const ChessSquare &square); + //PARAM col - the column of the square. + //PARAM row - the row of the square. + //PARAM square - The square to set. No need to set the column or row + void SetSquare(const ChessColumn &col, const ChessRow &row, + const ChessSquare &square); //Sets the description of the current drill void SetDescription(const std::string &description); @@ -155,6 +157,7 @@ void Enable(bool enable); //Pay o attention to the lines below this comment + void SetGuiControl( GuiControl *gui ); private: GuiControl *gui; }; Modified: drills/DrillList.h =================================================================== --- drills/DrillList.h 2007-08-02 07:40:05 UTC (rev 45) +++ drills/DrillList.h 2007-08-04 07:03:01 UTC (rev 46) @@ -1,6 +1,5 @@ /**************************************************************************** *A list for letting the program know what chess drills are available. - *This file should only be included by GuiControl.h * * To add your drill there are three things you must do: * 1. Add the header file for your drill @@ -9,6 +8,7 @@ * * Don't forget to add it to the makefile! * + *(This file should only be included by GuiControl.h) *Copyright 2007 Usable under the terms of the GPL ***************************************************************************/ #ifndef DRILL_LIST_H @@ -20,14 +20,14 @@ //When you write a new drill, include the correct header above, //and add your drill to this array. This name will appear in the //menu (the last element should be NULL). -const char *DrillName[2]={ +const char *DrillName[]={ "Example Drill", NULL }; //Here add an if statement that returns a new instance of your drill //when str is the same as the name above (it will be freed automatically) -ChessDrill *GetDrillByName( std::string &str ){ +ChessDrill *GetDrillByName( const std::string &str ){ if( str == "Example Drill" ) return (ChessDrill*)new ExampleDrill(); @@ -35,4 +35,6 @@ return NULL; } +#else +#error "Do not include DrillList.h!" #endif Modified: drills/ExampleDrill.cpp =================================================================== --- drills/ExampleDrill.cpp 2007-08-02 07:40:05 UTC (rev 45) +++ drills/ExampleDrill.cpp 2007-08-04 07:03:01 UTC (rev 46) @@ -18,7 +18,7 @@ //------------------------------------- bool ExampleDrill::Start(){ - ChessPiece tempPiece; + ChessSquare tempSquare; //first clear the board (not necessary, but just in case) ClearBoard(); @@ -26,16 +26,17 @@ //put my pawn on E5 myPawn.row = ROW_FIVE; myPawn.col = COL_A; - tempPiece.type = CP_PAWN; - tempPiece.color = CLR_BLACK; - SetSquare(tempPiece, myPawn); + tempSquare.piece.color = CLR_BLACK; + tempSquare.piece.type = CP_PAWN; + SetSquare(myPawn.col, myPawn.row, tempSquare); //put their pawn on A3 theirPawn.row = ROW_THREE; theirPawn.col = COL_A; - tempPiece.color = CLR_WHITE; - SetSquare(tempPiece,theirPawn); + tempSquare.piece.color = CLR_WHITE; + tempSquare.piece.type = CP_PAWN; + SetSquare(theirPawn.col, theirPawn.row, tempSquare ); //return true because we set up successfully return true; Modified: gui/GuiControl.cpp =================================================================== --- gui/GuiControl.cpp 2007-08-02 07:40:05 UTC (rev 45) +++ gui/GuiControl.cpp 2007-08-04 07:03:01 UTC (rev 46) @@ -14,7 +14,8 @@ // Constructor/Destructor //----------------------------------------------------------- GuiControl::GuiControl(){ - + currentDrill = NULL; + board.Reset(); } GuiControl::~GuiControl(){ @@ -34,8 +35,9 @@ board.MovePiece(from, to, captured); } -void GuiControl::SetSquare(const ChessPiece &piece, const ChessSquare &square){ - // board.SetSquare(square.col, square.row, piece); +void GuiControl::SetSquare(const ChessColumn &col, const ChessRow &row, + const ChessSquare &square){ + board.SetSquare(col, row, square); } void GuiControl::SetDescription(const std::string &description){ //Do nothing for now @@ -51,6 +53,7 @@ bool GuiControl::SendQueryAlert(const std::string &alertString){ //Do nothing for now + return false; } void GuiControl::DisplaySectionOfInstruction(const std::string &instructionString){ @@ -58,7 +61,7 @@ } void GuiControl::ClearBoard(){ - //Do nothing for now + board.Reset(); } void GuiControl::FinishDrill(){ @@ -76,8 +79,25 @@ return DrillName; } -void GuiControl::SwitchToDrill( std::string drill ){ - +void GuiControl::SwitchToDrill( const char *drill ){ + if( currentDrill != NULL ) + delete currentDrill; + std::string s(drill); + currentDrill = GetDrillByName( s ); + if( currentDrill == NULL ){ + printf("No drill for file name \"%s\". Please add it to ", + drill); + printf("DrillList.h,\n in the function GetDrillByName().\n"); + exit(-1); + } + currentDrill->SetGuiControl(this); + board.Reset(); + if( !currentDrill->Start() ){ + printf("Call to Drill Start returned false. Choose another drill\n"); + delete currentDrill; + currentDrill = NULL; + return; + } } ChessBoard *GuiControl::GetCurrentBoard(){ Modified: gui/GuiControl.h =================================================================== --- gui/GuiControl.h 2007-08-02 07:40:05 UTC (rev 45) +++ gui/GuiControl.h 2007-08-04 07:03:01 UTC (rev 46) @@ -19,6 +19,7 @@ class ChessSquare; class ChessPiece; +class ChessDrill; class GuiControl{ public: @@ -34,7 +35,8 @@ void MovePiece(const ChessSquare &from, const ChessSquare &to, ChessPiece &captured ); - void SetSquare(const ChessPiece &piece, const ChessSquare &square); + void SetSquare(const ChessColumn &col, const ChessRow &row, + const ChessSquare &square); void SetDescription(const std::string &description); @@ -60,7 +62,7 @@ const char** GetDrillList(); //Switches to the drill named by 'drill' - void SwitchToDrill( std::string drill ); + void SwitchToDrill( const char *drill ); //Returns the board to be used by the current drill, or an //empty board in case there is no drill in progress @@ -68,6 +70,7 @@ private: ChessBoard board; + ChessDrill *currentDrill; }; Modified: gui/MainWindow.cpp =================================================================== --- gui/MainWindow.cpp 2007-08-02 07:40:05 UTC (rev 45) +++ gui/MainWindow.cpp 2007-08-04 07:03:01 UTC (rev 46) @@ -132,6 +132,7 @@ for(int j=0;j<8;j++){ const ChessPiece *piece = board->GetPiece((ChessColumn)i,(ChessRow)j); ChessColor c = piece->color; + printf("[%d,%d], type %d\n",i,j,piece->type); //find which piece and color switch (piece->type){ case CP_PAWN: img = (c==CLR_WHITE)?&whitePawn: &blackPawn;break; @@ -177,9 +178,6 @@ { int id = event.GetId() - ID_SelectDrill1; const char ** menuList = ctl.GetDrillList(); - printf("in select drill\n"); - - printf("drill selected: %s\n",menuList[id]); ctl.SwitchToDrill( menuList[id] ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |