[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Camino-devel] camino/src/server CaminoServer.cpp CaminoServer...
From: |
Pascal Audoux |
Subject: |
[Camino-devel] camino/src/server CaminoServer.cpp CaminoServer... |
Date: |
Sat, 08 Mar 2003 15:22:00 -0500 |
CVSROOT: /cvsroot/camino
Module name: camino
Changes by: Pascal Audoux <address@hidden> 03/03/08 15:22:00
Modified files:
src/server : CaminoServer.cpp CaminoServer.h Player.cpp
Player.h
Log message:
manage UndoRequest
Patches:
Index: camino/src/server/CaminoServer.cpp
diff -u camino/src/server/CaminoServer.cpp:1.18
camino/src/server/CaminoServer.cpp:1.19
--- camino/src/server/CaminoServer.cpp:1.18 Sun Mar 2 19:12:04 2003
+++ camino/src/server/CaminoServer.cpp Sat Mar 8 15:22:00 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: CaminoServer.cpp,v 1.18 2003/03/03 00:12:04 pfremy Exp $
+** Version : $Id: CaminoServer.cpp,v 1.19 2003/03/08 20:22:00 Audoux Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 19/01/2003
@@ -142,7 +142,7 @@
return;
}
- qDebug("CaminoServer::sortPlayers - unknown team configuration : %d",
+ qDebug("CaminoServer::sortPlayers - unknown team configuration : %d",
_teamConfiguration );
}
@@ -152,7 +152,7 @@
int r = rand() % _playerNb;
qDebug("CaminoServer::activateNextPlayer - first player to play
: %d", r );
_activePlayer = _playerList.at( r );
-
+
} else if (_activePlayer == _playerList.getLast()) {
_activePlayer = _playerList.first();
} else {
@@ -174,7 +174,7 @@
qDebug( "CaminoServer::distributeTiles() " );
int tilesPerPlayer = 0;
- if ( _playerNb == 2 ) {
+ if ( _playerNb == 2 ) {
tilesPerPlayer = Camino::nbTiles2players;
} else {
tilesPerPlayer = Camino::nbTiles4players;
@@ -218,3 +218,47 @@
++it;
}
}
+
+void CaminoServer::undoRequested( Player * player )
+{
+ /// XXX: test correctness of state
+ _state = UndoRequested;
+ QPtrListIterator<Player> it( _playerList );
+ Player * current = 0;
+ while( current = it.current() ) {
+ if( current != player ) {
+ current->setUndoAccepted( false );
+ current->sendUndoRequest();
+ } else {
+ current->setUndoAccepted( true );
+ }
+ ++it;
+ }
+}
+
+void CaminoServer::undoAccepted( Player * player )
+{
+ if( _state == UndoRequested ) {
+ player->setUndoAccepted( true );
+ QPtrListIterator<Player> it( _playerList );
+ Player * current = 0;
+ bool ok = true;
+ while( current = it.current() ) {
+ ok = ok && current->isUndoAccepted();
+ ++it;
+ }
+ if( ok ) {
+ }
+ } else {
+ qDebug("CaminoServer::undoAccepted - Not in state
'UndoRequested'" );
+ }
+
+}
+
+void CaminoServer::undoRejected()
+{
+
+}
+
+
+
Index: camino/src/server/CaminoServer.h
diff -u camino/src/server/CaminoServer.h:1.14
camino/src/server/CaminoServer.h:1.15
--- camino/src/server/CaminoServer.h:1.14 Sun Mar 2 19:12:04 2003
+++ camino/src/server/CaminoServer.h Sat Mar 8 15:22:00 2003
@@ -5,7 +5,7 @@
** CaminoServer.h
** Server for the game
**
-** Version : $Id: CaminoServer.h,v 1.14 2003/03/03 00:12:04 pfremy Exp $
+** Version : $Id: CaminoServer.h,v 1.15 2003/03/08 20:22:00 Audoux Exp $
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 19/01/2003
** Copyright: Pascal Audoux, Philippe Fremy 2003
@@ -87,6 +87,10 @@
void sendDistributedTiles();
void activateNextPlayer();
void updateBoard( Tile * tile, bool removeIt = false );
+
+ void undoRequested( Player * player );
+ void undoAccepted( Player * player );
+ void undoRejected();
signals:
void sig_newConnection( QSocket * );
Index: camino/src/server/Player.cpp
diff -u camino/src/server/Player.cpp:1.15 camino/src/server/Player.cpp:1.16
--- camino/src/server/Player.cpp:1.15 Sun Mar 2 13:22:27 2003
+++ camino/src/server/Player.cpp Sat Mar 8 15:22:00 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: Player.cpp,v 1.15 2003/03/02 18:22:27 pfremy Exp $
+** Version : $Id: Player.cpp,v 1.16 2003/03/08 20:22:00 Audoux Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 14/01/2003
@@ -38,6 +38,7 @@
{
_server = caminoServer;
_socket = socket;
+ _undo = false;
connect( socket, SIGNAL( readyRead() ), SLOT( slotDecode() ) );
}
@@ -141,3 +142,21 @@
_tileList.append( tile );
sendTilesForYou( tile->getType() );
}
+
+void Player::recvUndoRequest()
+{
+ _server->undoRequested( this );
+}
+
+void Player::recvUndoAccepted()
+{
+ _server->undoAccepted( this );
+}
+
+void Player::recvUndoRejected()
+{
+ _server->undoRejected();
+}
+
+
+
Index: camino/src/server/Player.h
diff -u camino/src/server/Player.h:1.10 camino/src/server/Player.h:1.11
--- camino/src/server/Player.h:1.10 Sun Mar 2 13:22:27 2003
+++ camino/src/server/Player.h Sat Mar 8 15:22:00 2003
@@ -5,7 +5,7 @@
** Player.h
** this is a template for all .h files
**
-** Version : $Id: Player.h,v 1.10 2003/03/02 18:22:27 pfremy Exp $
+** Version : $Id: Player.h,v 1.11 2003/03/08 20:22:00 Audoux Exp $
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 14/01/2003
** Copyright: Pascal Audoux, Philippe Fremy 2003
@@ -60,10 +60,41 @@
void removeTile( Tile * tile );
void distributeAndSendOneTile();
+ bool isUndoAccepted() { return _undo; }
+
+ void setUndoAccepted( bool state ) { _undo = state; }
+
protected:
- virtual void recvPlayerInfo( QString playerName );
+ virtual void recvPlayerInfo( QString playerName );
virtual void recvMsg( QString source, QString msg );
- virtual void recvPlayerPlaysAMove( Tile * tile );
+ //virtual void recvServerInformation( QString serverInfo );
+
+ //virtual void recvPlayerConnected();
+ //virtual void recvTeamIsBeingChosen();
+ //virtual void recvTeamsComposition();
+
+ //virtual void recvTilesForYou( Tile::TileType /* tile */ );
+ //virtual void recvActivePlayer( QString playerName );
+ virtual void recvPlayerPlaysAMove( Tile * tile );
+ //virtual void recvMoveRejected( Tile * tile );
+ //virtual void recvUpdateBoard( Tile * tile, bool removeTile );
+
+ virtual void recvUndoRequest();
+ virtual void recvUndoAccepted();
+ virtual void recvUndoRejected();
+ //virtual void recvUndoUpdateBoard();
+
+ //virtual void recvEndOfGameRequest();
+ //virtual void recvEndOfGameAccepted();
+ //virtual void recvEndOfGameRejected();
+
+ //virtual void recvPleaseFinishTheBoard();
+ //virtual void recvFinishBoardMove();
+ //virtual void recvBoardsCompleted();
+
+ //virtual void recvWinnerInformation();
+ //virtual void recvAnotherGameRequest();
+ //virtual void recvAnotherGameAccept();
protected slots:
virtual void slotDecode();
@@ -73,8 +104,9 @@
QString _playerName;
QSocket * _socket;
QPtrList<Tile> _tileList;
+ bool _undo;
friend class CaminoServer;
};
-
-#endif // PLAYER_H
+
+#endif // PLAYER_H