[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Camino-devel] camino/src client/ClientEngine.cpp client/Clien...
From: |
Philippe Fremy |
Subject: |
[Camino-devel] camino/src client/ClientEngine.cpp client/Clien... |
Date: |
Mon, 17 Feb 2003 19:11:51 -0500 |
CVSROOT: /cvsroot/camino
Module name: camino
Changes by: Philippe Fremy <address@hidden> 03/02/17 19:11:50
Modified files:
src/client : ClientEngine.cpp ClientEngine.h
src/common : MsgCoder.cpp MsgCoder.h MsgDecoder.cpp
MsgDecoder.h TileStack.cpp TileStack.h
src/server : CaminoServer.cpp CaminoServer.h Player.h
ServerEngine.cpp
Log message:
un debut de debut d implementation de distribution des tile
Patches:
Index: camino/src/client/ClientEngine.cpp
diff -u camino/src/client/ClientEngine.cpp:1.9
camino/src/client/ClientEngine.cpp:1.10
--- camino/src/client/ClientEngine.cpp:1.9 Mon Feb 17 17:03:41 2003
+++ camino/src/client/ClientEngine.cpp Mon Feb 17 19:11:50 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: ClientEngine.cpp,v 1.9 2003/02/17 22:03:41 pfremy Exp $
+** Version : $Id: ClientEngine.cpp,v 1.10 2003/02/18 00:11:50 pfremy Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 14/01/2003
@@ -124,4 +124,7 @@
}
}
-
+void ClientEngine::recvTile( Tile::TileType tile )
+{
+ qDebug( "ClientEngine::recvTile - %d", ( int )tile );
+}
Index: camino/src/client/ClientEngine.h
diff -u camino/src/client/ClientEngine.h:1.8
camino/src/client/ClientEngine.h:1.9
--- camino/src/client/ClientEngine.h:1.8 Mon Feb 17 17:03:41 2003
+++ camino/src/client/ClientEngine.h Mon Feb 17 19:11:50 2003
@@ -5,7 +5,7 @@
** ClientEngine.h
** The intelligence of the client is here
**
-** Version : $Id: ClientEngine.h,v 1.8 2003/02/17 22:03:41 pfremy Exp $
+** Version : $Id: ClientEngine.h,v 1.9 2003/02/18 00:11:50 pfremy Exp $
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 14/01/2003
** Copyright: Pascal Audoux, Philippe Fremy 2003
@@ -57,6 +57,7 @@
bool isConnected();
void recvMsg( QString source, QString msg );
+ void recvTile( Tile::TileType tile );
void sendMessage( NetMsgSubtype msgLevel, const QString & msg );
Index: camino/src/common/MsgCoder.cpp
diff -u camino/src/common/MsgCoder.cpp:1.6 camino/src/common/MsgCoder.cpp:1.7
--- camino/src/common/MsgCoder.cpp:1.6 Wed Jan 29 17:20:11 2003
+++ camino/src/common/MsgCoder.cpp Mon Feb 17 19:11:50 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: MsgCoder.cpp,v 1.6 2003/01/29 22:20:11 Audoux Exp $
+** Version : $Id: MsgCoder.cpp,v 1.7 2003/02/18 00:11:50 pfremy Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 14/01/2003
@@ -60,4 +60,8 @@
device()->flush();
}
-
+void MsgCoder::sendTile( Tile::TileType tile )
+{
+ *this << TilesForYou << ( int ) tile ;
+ device()->flush();
+}
Index: camino/src/common/MsgCoder.h
diff -u camino/src/common/MsgCoder.h:1.7 camino/src/common/MsgCoder.h:1.8
--- camino/src/common/MsgCoder.h:1.7 Wed Jan 29 17:20:11 2003
+++ camino/src/common/MsgCoder.h Mon Feb 17 19:11:50 2003
@@ -3,7 +3,7 @@
** Camino
**
**
-** Version : $Id: MsgCoder.h,v 1.7 2003/01/29 22:20:11 Audoux Exp $
+** Version : $Id: MsgCoder.h,v 1.8 2003/02/18 00:11:50 pfremy Exp $
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 14/01/2003
** Copyright: Pascal Audoux, Philippe Fremy 2003
@@ -32,6 +32,7 @@
#include <qtextstream.h>
#include <qdatastream.h>
// application specific include files
+#include "common/Tile.h"
/* ------------------------------
@@ -52,36 +53,36 @@
enum NetMsgType {
FirstMsg = 0,
- ConnectServer, //! Client connects to server
- ServerInformation, //! Server returns the information about the
waiting party (nb of players, version, type of party)
- PlayerConnected, //! Server informs clients that a new player has
connected
- TeamIsBeingChosen, //! 4 players game, servers is currentely
choosing the team composition
- TeamsComposition, //! 4 players game, servers informs client
about the team composition
-
- Msg, //! Client/Server sends message, subtype is
(Chat, Info, Debug)
- TilesForYou, //! Server distributes one or many tiles to a
client
- ActivePlayer, //! Server informs all client which player is
active
- PlayerPlaysAMove, //! Client informs server about its move
- MoveRejected, //! Server refuses the last move of the client
- UpdateBoard, //! Server notifies a new tile on the board
-
- UndoRequest, //! Client request an undo
- UndoAccepted, //! Client/Server accepts the undo
- UndoRejected, //! Client/Server rejects the undo
- UndoUpdateBoard, //! Server updates the board
-
- EndOfGameRequest, //! Client request end of game
- EndOfGameAccepted, //! Client/Server accepts end of game
- EndOfGameRejected, //! Client/Server rejects end of game
-
- PleaseFinishTheBoard, //! Server asks client to fill-in the board at
the end of the game
- FinishBoardMove, //! Client sets/removes a tile
- BoardsCompleted, //! Client thinks the board is finished
-
- WinnerInformation, //! Server sends winner information
- AnotherGameRequest, //! Client ask for another game
- AnotherGameAccept, //! Server accepts the other game
-
+ ConnectServer, //! Client connects to server
+ ServerInformation, //! Server returns the information about the
waiting party (nb of players, version, type of party)
+ PlayerConnected, //! Server informs clients that a new player has
connected
+ TeamIsBeingChosen, //! 4 players game, servers is currentely
choosing the team composition
+ TeamsComposition, //! 4 players game, servers informs client
about the team composition
+
+ Msg, //! Client/Server sends message, subtype is
(Chat, Info, Debug)
+ TilesForYou, //! Server distributes one or many tiles to a
client
+ ActivePlayer, //! Server informs all client which player is
active
+ PlayerPlaysAMove, //! Client informs server about its move
+ MoveRejected, //! Server refuses the last move of the client
+ UpdateBoard, //! Server notifies a new tile on the board
+
+ UndoRequest, //! Client request an undo
+ UndoAccepted, //! Client/Server accepts the undo
+ UndoRejected, //! Client/Server rejects the undo
+ UndoUpdateBoard, //! Server updates the board
+
+ EndOfGameRequest, //! Client request end of game
+ EndOfGameAccepted, //! Client/Server accepts end of game
+ EndOfGameRejected, //! Client/Server rejects end of game
+
+ PleaseFinishTheBoard, //! Server asks client to fill-in the board at
the end of the game
+ FinishBoardMove, //! Client sets/removes a tile
+ BoardsCompleted, //! Client thinks the board is finished
+
+ WinnerInformation, //! Server sends winner information
+ AnotherGameRequest, //! Client ask for another game
+ AnotherGameAccept, //! Server accepts the other game
+
LastMsg
};
@@ -108,6 +109,7 @@
void connectServer( QString playerName );
void sendMsg( NetMsgSubtype msgLevel, const QString & source, const
QString & msg );
void sendUndo();
+ void sendTile( Tile::TileType tile );
private:
MsgCoder( MsgCoder & );
Index: camino/src/common/MsgDecoder.cpp
diff -u camino/src/common/MsgDecoder.cpp:1.6
camino/src/common/MsgDecoder.cpp:1.7
--- camino/src/common/MsgDecoder.cpp:1.6 Sun Jan 26 16:55:54 2003
+++ camino/src/common/MsgDecoder.cpp Mon Feb 17 19:11:50 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: MsgDecoder.cpp,v 1.6 2003/01/26 21:55:54 pfremy Exp $
+** Version : $Id: MsgDecoder.cpp,v 1.7 2003/02/18 00:11:50 pfremy Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 15/01/2003
@@ -67,6 +67,35 @@
case Msg:
decodeMsg();
break;
+
+ case UndoRequest:
+ decodeUndo();
+ break;
+
+ case TilesForYou:
+ decodeRecvTile();
+ break;
+
+ case ServerInformation:
+ case PlayerConnected:
+ case TeamIsBeingChosen:
+ case TeamsComposition:
+ case ActivePlayer:
+ case PlayerPlaysAMove:
+ case MoveRejected:
+ case UpdateBoard:
+ case UndoAccepted:
+ case UndoRejected:
+ case UndoUpdateBoard:
+ case EndOfGameRequest:
+ case EndOfGameAccepted:
+ case EndOfGameRejected:
+ case PleaseFinishTheBoard:
+ case FinishBoardMove:
+ case BoardsCompleted:
+ case WinnerInformation:
+ case AnotherGameRequest:
+ case AnotherGameAccept:
default:
qWarning( "MsgDecoder::slotDecode() - Unknown NetMsg
type received : %d", _type );
};
@@ -74,16 +103,40 @@
void MsgDecoder::decodeServerConnect()
{
- qDebug( "MsgDecoder::decodeServerConnect()");
+ // qDebug( "MsgDecoder::decodeServerConnect()");
QString playerName;
_ts >> playerName;
recvServerConnect( playerName );
}
+void MsgDecoder::decodeUndo()
+{
+ // qDebug( "MsgDecoder::decodeUndo()");
+ recvUndo();
+}
+
+void MsgDecoder::recvUndo()
+{
+ qDebug( "MsgDecoder::recvUndo()");
+}
+
void MsgDecoder::decodeMsg()
{
- qDebug( "MsgDecoder::decodeMsg()");
+// qDebug( "MsgDecoder::decodeMsg()");
QString source, msg;
_ts >> source >> msg;
recvMsg( source , msg );
+}
+
+void MsgDecoder::decodeRecvTile()
+{
+ int tt;
+ _ts >> tt;
+ recvTile( ( Tile::TileType ) tt );
+}
+
+
+void MsgDecoder::recvTile( Tile::TileType /* tile */ )
+{
+ qDebug( "MsgDecoder::decodeRecvTile" );
}
Index: camino/src/common/MsgDecoder.h
diff -u camino/src/common/MsgDecoder.h:1.8 camino/src/common/MsgDecoder.h:1.9
--- camino/src/common/MsgDecoder.h:1.8 Sun Jan 26 16:55:54 2003
+++ camino/src/common/MsgDecoder.h Mon Feb 17 19:11:50 2003
@@ -5,7 +5,7 @@
** MsgDecoder.h
** Decoder for socket msg
**
-** Version : $Id: MsgDecoder.h,v 1.8 2003/01/26 21:55:54 pfremy Exp $
+** Version : $Id: MsgDecoder.h,v 1.9 2003/02/18 00:11:50 pfremy Exp $
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 14/01/2003
** Copyright: Pascal Audoux, Philippe Fremy 2003
@@ -58,6 +58,8 @@
virtual void recvServerConnect( QString /* playerName */ ) {}
virtual void recvMsg( QString /* source */ , QString /* msg */ ) {}
+ virtual void recvTile( Tile::TileType /* tile */ );
+ virtual void recvUndo();
public slots:
/** call this to tell the Decoder that there is some data to decode
@@ -78,6 +80,8 @@
//QString decodeString( int minimumLen );
void decodeServerConnect();
void decodeMsg();
+ void decodeUndo();
+ void decodeRecvTile();
QIODevice * _socket;
QDataStream _ts;
Index: camino/src/common/TileStack.cpp
diff -u camino/src/common/TileStack.cpp:1.2 camino/src/common/TileStack.cpp:1.3
--- camino/src/common/TileStack.cpp:1.2 Sat Jan 25 16:50:47 2003
+++ camino/src/common/TileStack.cpp Mon Feb 17 19:11:50 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: TileStack.cpp,v 1.2 2003/01/25 21:50:47 Audoux Exp $
+** Version : $Id: TileStack.cpp,v 1.3 2003/02/18 00:11:50 pfremy Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 25/01/2003
@@ -73,12 +73,12 @@
init();
}
-Tile * TileStack::PickTile()
+Tile * TileStack::pickTile()
{
Tile * ret = 0;
uint len = _stack.count();
- uint num = rand() / len;
+ uint num = rand() % len;
ret = _stack.take( num );
Index: camino/src/common/TileStack.h
diff -u camino/src/common/TileStack.h:1.1 camino/src/common/TileStack.h:1.2
--- camino/src/common/TileStack.h:1.1 Sat Jan 25 13:44:32 2003
+++ camino/src/common/TileStack.h Mon Feb 17 19:11:50 2003
@@ -5,7 +5,7 @@
** TileStack.h
** Manage the stack of tiles of a game
**
-** Version : $Id: TileStack.h,v 1.1 2003/01/25 18:44:32 Audoux Exp $
+** Version : $Id: TileStack.h,v 1.2 2003/02/18 00:11:50 pfremy Exp $
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 25/01/2003
** Copyright: Pascal Audoux, Philippe Fremy 2003
@@ -51,12 +51,13 @@
void clear();
+ /** Create a tile stack with the right number of standard tiles */
void init();
void reinit();
/** Randomly picks a card in the stack and returns it */
- Tile * PickTile();
+ Tile * pickTile();
protected:
void addTile( Tile::TileType type, uint num );
Index: camino/src/server/CaminoServer.cpp
diff -u camino/src/server/CaminoServer.cpp:1.9
camino/src/server/CaminoServer.cpp:1.10
--- camino/src/server/CaminoServer.cpp:1.9 Mon Feb 17 16:33:50 2003
+++ camino/src/server/CaminoServer.cpp Mon Feb 17 19:11:50 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: CaminoServer.cpp,v 1.9 2003/02/17 21:33:50 pfremy Exp $
+** Version : $Id: CaminoServer.cpp,v 1.10 2003/02/18 00:11:50 pfremy Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 19/01/2003
@@ -30,12 +30,14 @@
// application specific include files
#include "common/log.h"
+#include "common/TileStack.h"
#include "server/Player.h"
CaminoServer::CaminoServer( int port, int playerNb )
: QServerSocket( port )
{
+ _tileStack = new TileStack();
_playerList.setAutoDelete( true );
_playerNb = playerNb;
_state = WaitingForConnection;
@@ -94,11 +96,50 @@
return;
}
- qDebug( "Begin Party" );
+ qDebug( "CaminoServer - Begin Party" );
serverBroadcastMsg( InfoMsg, "Begin Party" );
_state = BeginParty;
- // ...
+ _tileStack->init();
+
+ distributeTiles();
+ // check that every player can play with its tiles
+ sendDistributedTiles();
+ // activate current player
+ // change to playgame
}
+void CaminoServer::distributeTiles()
+{
+ qDebug( "CaminoServer::distributeTiles() " );
+ int tilesPerPlayer = 6;
+
+ if ( _playerNb > 2 ) {
+ tilesPerPlayer--;
+ }
+
+ for ( int i=0; i < tilesPerPlayer; i++ ) {
+ QPtrListIterator<Player> it( _playerList );
+ while( it.current() ) {
+ it.current()->_tileList.append( _tileStack->pickTile()
);
+ ++it;
+ }
+ }
+}
+
+void CaminoServer::sendDistributedTiles()
+{
+ qDebug( "CaminoServer::sendTiles() " );
+ Player * player;
+ QPtrListIterator<Player> it( _playerList );
+ while( ( player = it.current() ) ) {
+ QPtrListIterator<Tile> tileIt( player->_tileList );
+ for( ; tileIt.current(); ++tileIt ) {
+ player->sendTile( tileIt.current()->getType() );
+ }
+ ++it;
+ }
+ qDebug( "Tiles distributed!" );
+ serverBroadcastMsg( InfoMsg, "Tiles distributed!" );
+}
Index: camino/src/server/CaminoServer.h
diff -u camino/src/server/CaminoServer.h:1.7
camino/src/server/CaminoServer.h:1.8
--- camino/src/server/CaminoServer.h:1.7 Tue Jan 28 16:54:27 2003
+++ camino/src/server/CaminoServer.h Mon Feb 17 19:11:50 2003
@@ -5,7 +5,7 @@
** CaminoServer.h
** Server for the game
**
-** Version : $Id: CaminoServer.h,v 1.7 2003/01/28 21:54:27 pfremy Exp $
+** Version : $Id: CaminoServer.h,v 1.8 2003/02/18 00:11:50 pfremy Exp $
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 19/01/2003
** Copyright: Pascal Audoux, Philippe Fremy 2003
@@ -39,6 +39,7 @@
class QSignalMapper;
class Player;
+class TileStack;
/* ------------------------------
* CaminoServer
@@ -80,6 +81,9 @@
void setTeamConfiguration( int teamConfiguration );
void beginParty();
+ void distributeTiles();
+ void sendDistributedTiles();
+
signals:
void sig_newConnection( QSocket * );
void sig_endConnection( QString name );
@@ -90,6 +94,7 @@
protected:
QPtrList<Player> _playerList;
+ TileStack * _tileStack;
int _playerNb;
ServerState _state;
Index: camino/src/server/Player.h
diff -u camino/src/server/Player.h:1.6 camino/src/server/Player.h:1.7
--- camino/src/server/Player.h:1.6 Mon Feb 17 16:33:50 2003
+++ camino/src/server/Player.h Mon Feb 17 19:11:50 2003
@@ -5,7 +5,7 @@
** Player.h
** this is a template for all .h files
**
-** Version : $Id: Player.h,v 1.6 2003/02/17 21:33:50 pfremy Exp $
+** Version : $Id: Player.h,v 1.7 2003/02/18 00:11:50 pfremy Exp $
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 14/01/2003
** Copyright: Pascal Audoux, Philippe Fremy 2003
@@ -30,6 +30,7 @@
// generic include files
// include files for QT
+#include <qptrlist.h>
// application specific include files
#include "common/MsgDecoder.h"
@@ -42,6 +43,7 @@
class CaminoServer;
class QSocket;
+class Tile;
/** comment for the class */
class Player : public MsgCoder, public MsgDecoder
@@ -63,6 +65,7 @@
CaminoServer * _server;
QString _playerName;
QSocket * _socket;
+ QPtrList<Tile> _tileList;
friend class CaminoServer;
};
Index: camino/src/server/ServerEngine.cpp
diff -u camino/src/server/ServerEngine.cpp:1.1
camino/src/server/ServerEngine.cpp:1.2
--- camino/src/server/ServerEngine.cpp:1.1 Sun Jan 26 09:03:00 2003
+++ camino/src/server/ServerEngine.cpp Mon Feb 17 19:11:50 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: ServerEngine.cpp,v 1.1 2003/01/26 14:03:00 Audoux Exp $
+** Version : $Id: ServerEngine.cpp,v 1.2 2003/02/18 00:11:50 pfremy Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 26/01/2003
@@ -32,7 +32,6 @@
/** add comments here */
ServerEngine::ServerEngine()
{
-
}