From kde-commits Wed Sep 22 19:57:35 2004 From: Inge Wallin Date: Wed, 22 Sep 2004 19:57:35 +0000 To: kde-commits Subject: kdegames/kreversi Message-Id: <20040922195735.D6D92126DC () office ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=109588306528966 CVS commit by ingwa: Fix bug 89829: KReversi: When you save a game, the color for Human and Computer is not saved This fix reverses a previous fix by Anne-Marie Mahfouf, that had some issues. See the discussion at the KDE bugzilla (http://bugs.kde.org/show_bug.cgi?id=89829) for details. I will backport this one to KDE_3_3_BRANCH. M +22 -0 ChangeLog 1.34 M +18 -2 TODO 1.19 M +20 -11 board.cpp 1.43 R prefs_addons.h 1.1 --- kdegames/kreversi/ChangeLog #1.33:1.34 @@ -1,2 +1,24 @@ +2004-09-22 Inge Wallin + + Fix bug 89829: "KReversi: When you save a game, the color for + Human and Computer is not saved" again. See the discussion on the + KDE bugzilla for details + (http://bugs.kde.org/show_bug.cgi?id=89829). + * board.cpp (Board::saveGame): Save m_humanColor as HumanColor. + * Remove saving of the side to move since this is implicit + anyway. + * (Board::loadGame): Fix loading of m_humanColor and + m_competitiveGame + * Fix emit of signal turn, and the condition to call + computerMakeMove(). + * prefs_addons.h: Removed + + +2004-09-18 Anne-Marie Mahfouf (ChangeLog entry by Inge Wallin) + + Fix bug 89829. (See above, though) + * prefs_addons.h: New file + * board.cpp (saveGame): Some changes + 2004-09-18 Inge Wallin --- kdegames/kreversi/TODO #1.18:1.19 @@ -7,8 +7,24 @@ * Convert KReversi to use KGame / KPlayer I. Convert KReversi to a proper Model/View program. - 1. Make Game the Model. + 1. Fix a ReversiGame (formerly known as Game) - Clean it up. (Only store the moves). - Add a few necessary methods. - II. Introduce a class Player + 2. Create a new class KReversiGame, that stores a ReversiGame and + sends a lot of signals. + - Split out a lot of methods from the current class Board. + 3. Create KReversiBoard from the rest of the current Board + 4. Create a new class KReversiGameView, that will be the main view. + - Store a KReversiGame, a KReversiBoard and some other widgets. + + II. Introduce a class ReversiPlayer + + III. Convert everything to KGame + 1. Let KReversiGame inherit from KGame + 2. Let ReversiPlayer inherit from KPlayer. + + IV. ... + + V. Profit! + Later --- kdegames/kreversi/board.cpp #1.42:1.43 @@ -602,5 +602,7 @@ void Board::setColor(const QColor &c) -// Saves the game. Only one game at a time can be saved. +// Saves the game in the config file. +// +// Only one game at a time can be saved. // @@ -615,5 +617,7 @@ void Board::saveGame(KConfig *config) config->writeEntry("Strength", strength()); - // Write the game itself to the file. + // Write the moves of the game to the config object. This object + // saves itself all at once so we don't have to write the moves + // to the file ourselves. for (uint i = moveNumber(); i > 0; i--) { Move move = m_game->lastMove(); @@ -626,7 +630,7 @@ void Board::saveGame(KConfig *config) } - // save whose turn it is and if the game is casual. - config->writeEntry("WhoseTurn", (int) m_humanColor); + // Save whose turn it is and if the game is competitive. config->writeEntry("Competitive", (int) m_competitiveGame); + config->writeEntry("HumanColor", (int) m_humanColor); config->sync(); @@ -666,21 +670,26 @@ bool Board::loadGame(KConfig *config, bo } + m_humanColor = (Color) config->readNumEntry("HumanColor"); + m_competitiveGame = (bool) config->readNumEntry("Competitive"); + if (noupdate) return true; - m_humanColor = (Color)config->readNumEntry("WhoseTurn"); - Prefs::setHumanColor((int) m_humanColor); - Prefs::setComputerColor((int) opponent(m_humanColor)); - Prefs::writeConfig(); updateBoard(TRUE); setState(State(config->readNumEntry("State"))); setStrength(config->readNumEntry("Strength", 1)); - m_competitiveGame = (bool) config->readNumEntry("Competitive"); //kdDebug() << "Competitive set to: " << m_competitiveGame << endl; if (interrupted()) doContinue(); - //it's always the human's turn to play in a load game as you cannot save a game while playing - emit turn(m_humanColor); + else { + // Make the view show who is to move. + emit turn(m_game->toMove()); + + // Computer makes first move. + if (m_humanColor != m_game->toMove()) + computerMakeMove(); + } + return true; }