[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Eliot-dev] eliot/game duplicate.cpp duplicate.h game.h
From: |
Olivier Teulière |
Subject: |
[Eliot-dev] eliot/game duplicate.cpp duplicate.h game.h |
Date: |
Sun, 23 Nov 2008 17:06:45 +0000 |
CVSROOT: /cvsroot/eliot
Module name: eliot
Changes by: Olivier Teulière <ipkiss> 08/11/23 17:06:44
Modified files:
game : duplicate.cpp duplicate.h game.h
Log message:
New Duplicate::MarkPlayedCmd command to change the "hasPlayed" status
of a player, in duplicate mode
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/game/duplicate.cpp?cvsroot=eliot&r1=1.26&r2=1.27
http://cvs.savannah.gnu.org/viewcvs/eliot/game/duplicate.h?cvsroot=eliot&r1=1.17&r2=1.18
http://cvs.savannah.gnu.org/viewcvs/eliot/game/game.h?cvsroot=eliot&r1=1.42&r2=1.43
Patches:
Index: duplicate.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/duplicate.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- duplicate.cpp 23 Nov 2008 17:05:13 -0000 1.26
+++ duplicate.cpp 23 Nov 2008 17:06:44 -0000 1.27
@@ -19,6 +19,7 @@
*****************************************************************************/
#include <boost/foreach.hpp>
+#include <sstream>
#include "duplicate.h"
#include "game_exception.h"
@@ -109,12 +110,13 @@
const PlayedRack &newRack =
helperSetRackRandom(getCurrentPlayer().getCurrentRack(), true,
RACK_NEW);
// All the players have the same rack
- for (unsigned int i = 0; i < getNPlayers(); i++)
+ BOOST_FOREACH(Player *player, m_players)
{
- Command *pCmd = new PlayerRackCmd(*m_players[i], newRack);
+ Command *pCmd = new PlayerRackCmd(*player, newRack);
accessNavigation().addAndExecute(pCmd);
// Nobody has played yet in this round
- m_hasPlayed[i] = false;
+ Command *pCmd2 = new MarkPlayedCmd(*this, player->getId(), false);
+ accessNavigation().addAndExecute(pCmd2);
}
// Change the turn _after_ setting the new rack, so that when going
// back in the history the rack is already there. The turn boundaries
@@ -167,7 +169,8 @@
Command *pCmd = new PlayerMoveCmd(ioPlayer, iMove);
accessNavigation().addAndExecute(pCmd);
- m_hasPlayed[ioPlayer.getId()] = true;
+ Command *pCmd2 = new MarkPlayedCmd(*this, ioPlayer.getId(), true);
+ accessNavigation().addAndExecute(pCmd2);
}
@@ -315,3 +318,43 @@
return it != m_hasPlayed.end() && it->second;
}
+
+void Duplicate::setPlayedFlag(unsigned int iPlayerId, bool iNewFlag)
+{
+ ASSERT(iPlayerId < getNPlayers(), "Wrong player number");
+
+ m_hasPlayed[iPlayerId] = iNewFlag;
+}
+
+
+Duplicate::MarkPlayedCmd::MarkPlayedCmd(Duplicate &ioDuplicate,
+ unsigned int iPlayerId,
+ bool iPlayedFlag)
+ : m_duplicateGame(ioDuplicate), m_playerId(iPlayerId),
+ m_newPlayedFlag(iPlayedFlag)
+{
+}
+
+
+void Duplicate::MarkPlayedCmd::doExecute()
+{
+ m_oldPlayedFlag = m_duplicateGame.hasPlayed(m_playerId);
+ m_duplicateGame.setPlayedFlag(m_playerId, m_newPlayedFlag);
+}
+
+
+void Duplicate::MarkPlayedCmd::doUndo()
+{
+ m_duplicateGame.setPlayedFlag(m_playerId, m_oldPlayedFlag);
+}
+
+
+wstring Duplicate::MarkPlayedCmd::toString() const
+{
+ wostringstream oss;
+ oss << L"MarkPlayedCmd (player " << m_playerId
+ << L" marked " << m_newPlayedFlag << L")";
+ return oss.str();
+}
+
+
Index: duplicate.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/duplicate.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- duplicate.h 23 Nov 2008 17:04:40 -0000 1.17
+++ duplicate.h 23 Nov 2008 17:06:44 -0000 1.18
@@ -22,6 +22,7 @@
#define _DUPLICATE_H_
#include "game.h"
+#include "command.h"
class Player;
@@ -93,8 +94,7 @@
void nextHumanPlayer();
/// Return true if the player has played for the current turn
- // XXX: not very nice API, should be a player property...
- virtual bool hasPlayed(unsigned int player) const;
+ virtual bool hasPlayed(unsigned int iPlayerId) const;
private:
// Private constructor to force using the GameFactory class
@@ -106,6 +106,9 @@
/// Make the AI player whose ID is p play its turn
void playAI(unsigned int p);
+ /// Change the "has played" status of the given player to the given status
+ void setPlayedFlag(unsigned int iPlayerId, bool iNewFlag);
+
/**
* This function does not terminate the turn itself, but performs some
* checks to know whether or not it should be terminated (with a call to
@@ -133,8 +136,29 @@
/// Finish the game
void endGame();
- // m_hasPlayed[p] is true iff player p has played for this turn
+ /// m_hasPlayed[p] is true iff player p has played for this turn
map<unsigned int, bool> m_hasPlayed;
+
+ /// Command used internally to change the "has played" flag of a player
+ class MarkPlayedCmd: public Command
+ {
+ public:
+ MarkPlayedCmd(Duplicate &ioDuplicate,
+ unsigned int iPlayerId,
+ bool iPlayedFlag);
+
+ virtual wstring toString() const;
+
+ protected:
+ virtual void doExecute();
+ virtual void doUndo();
+
+ private:
+ Duplicate &m_duplicateGame;
+ unsigned int m_playerId;
+ bool m_newPlayedFlag;
+ bool m_oldPlayedFlag;
+ };
};
#endif /* _DUPLICATE_H_ */
Index: game.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/game.h,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -b -r1.42 -r1.43
--- game.h 23 Nov 2008 17:04:40 -0000 1.42
+++ game.h 23 Nov 2008 17:06:44 -0000 1.43
@@ -321,7 +321,7 @@
/**
* load games from File using advanced format (since Eliot 1.5)
- * This format is used for Duplicate, Freegame, ...
+ * This format is used for Duplicate, FreeGame, ...
*/
static Game* gameLoadFormat_15(FILE *fin, const Dictionary& iDic);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Eliot-dev] eliot/game duplicate.cpp duplicate.h game.h,
Olivier Teulière <=