eliot-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Eliot-dev] eliot/game Makefile.am freegame.cpp player_poin...


From: Olivier Teulière
Subject: [Eliot-dev] eliot/game Makefile.am freegame.cpp player_poin...
Date: Sun, 30 Nov 2008 21:10:26 +0000

CVSROOT:        /cvsroot/eliot
Module name:    eliot
Changes by:     Olivier Teulière <ipkiss>      08/11/30 21:10:26

Modified files:
        game           : Makefile.am freegame.cpp 
Added files:
        game           : player_points_cmd.cpp player_points_cmd.h 

Log message:
        New command to handle the player points, useful to handle the end of a 
free game

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/game/Makefile.am?cvsroot=eliot&r1=1.22&r2=1.23
http://cvs.savannah.gnu.org/viewcvs/eliot/game/freegame.cpp?cvsroot=eliot&r1=1.30&r2=1.31
http://cvs.savannah.gnu.org/viewcvs/eliot/game/player_points_cmd.cpp?cvsroot=eliot&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/eliot/game/player_points_cmd.h?cvsroot=eliot&rev=1.1

Patches:
Index: Makefile.am
===================================================================
RCS file: /cvsroot/eliot/eliot/game/Makefile.am,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- Makefile.am 30 Nov 2008 20:53:44 -0000      1.22
+++ Makefile.am 30 Nov 2008 21:10:25 -0000      1.23
@@ -33,6 +33,7 @@
     turn.cpp turn.h \
     history.cpp history.h \
     player.cpp player.h \
+    player_points_cmd.cpp player_points_cmd.h \
     player_move_cmd.cpp player_move_cmd.h \
     player_rack_cmd.cpp player_rack_cmd.h \
     ai_player.h \

Index: freegame.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/freegame.cpp,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -b -r1.30 -r1.31
--- freegame.cpp        30 Nov 2008 20:55:46 -0000      1.30
+++ freegame.cpp        30 Nov 2008 21:10:26 -0000      1.31
@@ -33,6 +33,7 @@
 #include "pldrack.h"
 #include "results.h"
 #include "player.h"
+#include "player_points_cmd.h"
 #include "player_move_cmd.h"
 #include "player_rack_cmd.h"
 #include "game_move_cmd.h"
@@ -209,11 +210,17 @@
         {
             const PlayedRack &pld = m_players[i]->getCurrentRack();
             pld.getAllTiles(tiles);
+            int points = 0;
             BOOST_FOREACH(const Tile &tile, tiles)
             {
-                m_players[i]->addPoints(- tile.getPoints());
-                m_players[m_currPlayer]->addPoints(tile.getPoints());
+                points += tile.getPoints();
             }
+            // Add the points to the current player...
+            Command *pCmd = new PlayerPointsCmd(*m_players[m_currPlayer], 
points);
+            accessNavigation().addAndExecute(pCmd);
+            // ... and remove them from the other player
+            Command *pCmd2 = new PlayerPointsCmd(*m_players[i], -points);
+            accessNavigation().addAndExecute(pCmd2);
         }
     }
 

Index: player_points_cmd.cpp
===================================================================
RCS file: player_points_cmd.cpp
diff -N player_points_cmd.cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ player_points_cmd.cpp       30 Nov 2008 21:10:26 -0000      1.1
@@ -0,0 +1,52 @@
+/*******************************************************************
+ * Eliot
+ * Copyright (C) 2008 Olivier Teulière
+ * Authors: Olivier Teulière <ipkiss @@ gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *****************************************************************************/
+
+#include <sstream>
+
+#include "player_points_cmd.h"
+#include "player.h"
+
+
+PlayerPointsCmd::PlayerPointsCmd(Player &ioPlayer, int iPoints)
+    : m_player(ioPlayer), m_points(iPoints)
+{
+}
+
+
+void PlayerPointsCmd::doExecute()
+{
+    m_player.addPoints(m_points);
+}
+
+
+void PlayerPointsCmd::doUndo()
+{
+    m_player.addPoints(-m_points);
+}
+
+
+wstring PlayerPointsCmd::toString() const
+{
+    wostringstream oss;
+    oss << L"PlayerPointsCmd (player " << m_player.getId() << L"): "
+        << "adding " << m_points << " points";
+    return oss.str();
+}
+

Index: player_points_cmd.h
===================================================================
RCS file: player_points_cmd.h
diff -N player_points_cmd.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ player_points_cmd.h 30 Nov 2008 21:10:26 -0000      1.1
@@ -0,0 +1,50 @@
+/*******************************************************************
+ * Eliot
+ * Copyright (C) 2008 Olivier Teulière
+ * Authors: Olivier Teulière <ipkiss @@ gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *****************************************************************************/
+
+#ifndef _PLAYER_POINTS_CMD_H
+#define _PLAYER_POINTS_CMD_H
+
+#include "command.h"
+
+class Player;
+
+
+/**
+ * This class implements the Command design pattern.
+ * It encapsulates the logic to add points to a player score.
+ */
+class PlayerPointsCmd: public Command
+{
+    public:
+        PlayerPointsCmd(Player &ioPlayer, int iPoints);
+
+        virtual wstring toString() const;
+
+    protected:
+        virtual void doExecute();
+        virtual void doUndo();
+
+    private:
+        Player &m_player;
+        int m_points;
+};
+
+#endif
+




reply via email to

[Prev in Thread] Current Thread [Next in Thread]