[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Camino-devel] camino/src client/Game.cpp client/Theme.cpp cli...
From: |
Philippe Fremy |
Subject: |
[Camino-devel] camino/src client/Game.cpp client/Theme.cpp cli... |
Date: |
Thu, 27 Feb 2003 12:26:26 -0500 |
CVSROOT: /cvsroot/camino
Module name: camino
Changes by: Philippe Fremy <address@hidden> 03/02/27 12:26:26
Modified files:
src/client : Game.cpp Theme.cpp Theme.h TilePresentation.cpp
TilePresentation.h TileSprite.cpp
src/common : MsgCoder.cpp MsgCoder.h MsgDecoder.cpp
MsgDecoder.h
src/server : CaminoServer.cpp
Log message:
- add activeplayer bool
- beginning of the implementation to play
Patches:
Index: camino/src/client/Game.cpp
diff -u camino/src/client/Game.cpp:1.18 camino/src/client/Game.cpp:1.19
--- camino/src/client/Game.cpp:1.18 Thu Feb 27 08:37:30 2003
+++ camino/src/client/Game.cpp Thu Feb 27 12:26:25 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: Game.cpp,v 1.18 2003/02/27 13:37:30 pfremy Exp $
+** Version : $Id: Game.cpp,v 1.19 2003/02/27 17:26:25 pfremy Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 15/01/2003
@@ -42,6 +42,8 @@
Game::Game( QWidget * parent , const char * name )
: QWidget( parent, name, QWidget::WStyle_Customize |
QWidget::WStyle_DialogBorder )
{
+ _playerActive = false;
+
_socket = new QSocket( this );
_state = StateNotConnected;
MsgDecoder::setDevice( _socket );
@@ -144,10 +146,20 @@
void Game::slot_tileClickedInBoard( int row, int col )
{
+ qDebug("Game::tileClickedInBoard - %dx%d", row, col );
// check if we have one tile selected in tile presentation
- // check if it is our turn to play
- // check if there is no tile at this place
- // check if the rule allow to play here
+ if (_presentation->getSelected() == Tile::TILE_UNKNOWN) {
+ return;
+ }
+
+ // check if it is our turn to play: check state
+ if (_playerActive == false) {
+ return;
+ }
+
+ // check if there is no tile at this place: ask board to do that
+ // check if the rule allow to play here: ask board to do that
+
// if all the check pass, send the tile to the server
// if the server accepts the move, he will send us a message to add the
// tile to the board.
@@ -221,9 +233,9 @@
void Game::slotDecode()
{
// qDebug( "Game::slotDecode()" );
-// qDebug( "bytes available : %ld", _socket->bytesAvailable() );
while( _socket->bytesAvailable() ) {
MsgDecoder::slotDecode();
+// qDebug( "bytes available : %ld", _socket->bytesAvailable() );
}
}
Index: camino/src/client/Theme.cpp
diff -u camino/src/client/Theme.cpp:1.6 camino/src/client/Theme.cpp:1.7
--- camino/src/client/Theme.cpp:1.6 Thu Feb 27 08:32:10 2003
+++ camino/src/client/Theme.cpp Thu Feb 27 12:26:25 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: Theme.cpp,v 1.6 2003/02/27 13:32:10 pfremy Exp $
+** Version : $Id: Theme.cpp,v 1.7 2003/02/27 17:26:25 pfremy Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 22/01/2003
@@ -117,26 +117,6 @@
_tiles = 0;
}
-int Theme::getZoomSize()
-{
- int ret = 0;
-
- // XXX: should be read in theme data
- switch( _level ) {
- case 1:
- ret = 30;
- break;
- case 2:
- ret = 50;
- break;
- case 3:
- ret = 70;
- break;
- }
-
- return ret;
-}
-
QCanvasPixmapArray * Theme::getTileArray( int num, int side )
{
// XXX: add some checks...
@@ -223,7 +203,22 @@
int Theme::getTileSize()
{
- return 50;
+ int ret = 0;
+
+ // XXX: should be read in theme data
+ switch( _level ) {
+ case 1:
+ ret = 30;
+ break;
+ case 2:
+ ret = 50;
+ break;
+ case 3:
+ ret = 70;
+ break;
+ }
+
+ return ret;
}
Index: camino/src/client/Theme.h
diff -u camino/src/client/Theme.h:1.6 camino/src/client/Theme.h:1.7
--- camino/src/client/Theme.h:1.6 Thu Feb 27 08:32:10 2003
+++ camino/src/client/Theme.h Thu Feb 27 12:26:25 2003
@@ -5,7 +5,7 @@
** Theme.h
** Manage theme data and pictures
**
-** Version : $Id: Theme.h,v 1.6 2003/02/27 13:32:10 pfremy Exp $
+** Version : $Id: Theme.h,v 1.7 2003/02/27 17:26:25 pfremy Exp $
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 22/01/2003
** Copyright: Pascal Audoux, Philippe Fremy 2003
@@ -65,10 +65,7 @@
QCanvasPixmapArray * getTileArray( int num, int side );
void setZoomLevel( int level ) { _level = level; }
-
int getZoomLevel() { return _level; }
-
- int getZoomSize();
const QPixmap & getTilePixmap( int num, int side );
Index: camino/src/client/TilePresentation.cpp
diff -u camino/src/client/TilePresentation.cpp:1.6
camino/src/client/TilePresentation.cpp:1.7
--- camino/src/client/TilePresentation.cpp:1.6 Thu Feb 27 08:33:30 2003
+++ camino/src/client/TilePresentation.cpp Thu Feb 27 12:26:25 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: TilePresentation.cpp,v 1.6 2003/02/27 13:33:30 pfremy Exp $
+** Version : $Id: TilePresentation.cpp,v 1.7 2003/02/27 17:26:25 pfremy Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 28/01/2003
@@ -114,6 +114,10 @@
removeTile( _selectedTile->_type );
}
+Tile::TileType TilePresentation::getSelected()
+{
+ return _selectedTile->_type;
+}
//
// ----- TileButton -----
Index: camino/src/client/TilePresentation.h
diff -u camino/src/client/TilePresentation.h:1.6
camino/src/client/TilePresentation.h:1.7
--- camino/src/client/TilePresentation.h:1.6 Thu Feb 27 08:33:30 2003
+++ camino/src/client/TilePresentation.h Thu Feb 27 12:26:25 2003
@@ -5,7 +5,7 @@
** TilePresentation.h
** Displays tiles of the player
**
-** Version : $Id: TilePresentation.h,v 1.6 2003/02/27 13:33:30 pfremy Exp $
+** Version : $Id: TilePresentation.h,v 1.7 2003/02/27 17:26:25 pfremy Exp $
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 28/01/2003
** Copyright: Pascal Audoux, Philippe Fremy 2003
@@ -57,6 +57,7 @@
void addTile( Tile::TileType tile );
void removeTile( Tile::TileType tile );
void removeSelectedTile();
+ Tile::TileType getSelected();
public slots:
void slot_selectTile( int num );
Index: camino/src/client/TileSprite.cpp
diff -u camino/src/client/TileSprite.cpp:1.4
camino/src/client/TileSprite.cpp:1.5
--- camino/src/client/TileSprite.cpp:1.4 Thu Feb 27 05:22:57 2003
+++ camino/src/client/TileSprite.cpp Thu Feb 27 12:26:25 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: TileSprite.cpp,v 1.4 2003/02/27 10:22:57 pfremy Exp $
+** Version : $Id: TileSprite.cpp,v 1.5 2003/02/27 17:26:25 pfremy Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 22/01/2003
@@ -47,6 +47,7 @@
{
_row = row;
_col = col;
- move( (double)(col * Theme::getTheme()->getZoomSize()), (double)(row *
Theme::getTheme()->getZoomSize()) );
+ move( (double)(col * Theme::getTheme()->getTileSize()),
+ (double)(row * Theme::getTheme()->getTileSize()) );
}
Index: camino/src/common/MsgCoder.cpp
diff -u camino/src/common/MsgCoder.cpp:1.11 camino/src/common/MsgCoder.cpp:1.12
--- camino/src/common/MsgCoder.cpp:1.11 Thu Feb 27 05:23:30 2003
+++ camino/src/common/MsgCoder.cpp Thu Feb 27 12:26:25 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: MsgCoder.cpp,v 1.11 2003/02/27 10:23:30 pfremy Exp $
+** Version : $Id: MsgCoder.cpp,v 1.12 2003/02/27 17:26:25 pfremy Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 14/01/2003
@@ -54,14 +54,18 @@
device()->flush();
}
-void MsgCoder::sendTile( Tile::TileType tile )
+void MsgCoder::sendTile( Tile * tile )
{
- sendTilesForYou( tile );
+ *this << tile->getType()
+ << tile->getRotation()
+ << tile->getRow() << tile->getCol();
}
-void MsgCoder::sendTilesForYou( Tile::TileType tile )
+void MsgCoder::sendTilesForYou( Tile::TileType tiletype )
{
- *this << TilesForYou << 0 << ( int ) tile ;
+ Tile tile( tiletype );
+ *this << TilesForYou << 0;
+ sendTile( &tile );
device()->flush();
}
@@ -86,11 +90,6 @@
device()->flush();
}
-void MsgCoder::sendTilesForYou()
-{
- *this << TilesForYou << 0;
- device()->flush();
-}
void MsgCoder::sendActivePlayer()
{
*this << ActivePlayer << 0;
@@ -98,8 +97,9 @@
}
void MsgCoder::sendPlayerPlaysAMove( Tile * tile )
{
- *this << PlayerPlaysAMove << 0 << tile->getRotation()
- << tile->getRow() << tile->getCol();
+ *this << PlayerPlaysAMove << 0;
+ sendTile( tile );
+
device()->flush();
}
void MsgCoder::sendMoveRejected()
Index: camino/src/common/MsgCoder.h
diff -u camino/src/common/MsgCoder.h:1.11 camino/src/common/MsgCoder.h:1.12
--- camino/src/common/MsgCoder.h:1.11 Thu Feb 27 05:23:30 2003
+++ camino/src/common/MsgCoder.h Thu Feb 27 12:26:25 2003
@@ -3,7 +3,7 @@
** Camino
**
**
-** Version : $Id: MsgCoder.h,v 1.11 2003/02/27 10:23:30 pfremy Exp $
+** Version : $Id: MsgCoder.h,v 1.12 2003/02/27 17:26:25 pfremy Exp $
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 14/01/2003
** Copyright: Pascal Audoux, Philippe Fremy 2003
@@ -108,14 +108,12 @@
void sendPlayerInfo( QString playerName );
void sendMsg( NetMsgSubtype msgLevel, const QString & source, const
QString & msg );
- void sendTile( Tile::TileType tile );
void sendTilesForYou( Tile::TileType tile );
void sendServerInformation();
void sendPlayerConnected();
void sendTeamIsBeingChosen();
void sendTeamsComposition();
- void sendTilesForYou();
void sendActivePlayer();
void sendPlayerPlaysAMove( Tile * tile );
void sendMoveRejected();
@@ -138,6 +136,8 @@
void sendAnotherGameRequest();
void sendAnotherGameAccept();
+protected:
+ void sendTile( Tile * tile );
private:
MsgCoder( MsgCoder & );
Index: camino/src/common/MsgDecoder.cpp
diff -u camino/src/common/MsgDecoder.cpp:1.9
camino/src/common/MsgDecoder.cpp:1.10
--- camino/src/common/MsgDecoder.cpp:1.9 Thu Feb 27 05:23:31 2003
+++ camino/src/common/MsgDecoder.cpp Thu Feb 27 12:26:25 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: MsgDecoder.cpp,v 1.9 2003/02/27 10:23:31 pfremy Exp $
+** Version : $Id: MsgDecoder.cpp,v 1.10 2003/02/27 17:26:25 pfremy Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 15/01/2003
@@ -82,6 +82,9 @@
case TeamsComposition:
case ActivePlayer:
case PlayerPlaysAMove:
+ decodePlayerPlaysAMove();
+ break;
+
case MoveRejected:
case UpdateBoard:
case UndoAccepted:
@@ -131,9 +134,9 @@
void MsgDecoder::decodeTilesForYou()
{
- int tt;
- _ts >> tt;
- recvTilesForYou( ( Tile::TileType ) tt );
+ Tile * tile = decodeTile();
+ recvTilesForYou( tile->getType() );
+ delete tile;
}
@@ -193,14 +196,28 @@
recvActivePlayer();
}
-void MsgDecoder::recvPlayerPlaysAMove()
+void MsgDecoder::recvPlayerPlaysAMove( Tile * /* tile */ )
{
qDebug( "MsgDecoder::recvPlayerPlaysAMove()" );
}
void MsgDecoder::decodePlayerPlaysAMove()
{
- recvPlayerPlaysAMove();
+ Tile * tile = decodeTile();
+ recvPlayerPlaysAMove( tile );
+}
+
+Tile * MsgDecoder::decodeTile()
+{
+ int tiletype;
+ int rotation, row, col;
+
+ _ts >> tiletype >> rotation >> row >> col;
+
+ Tile * tile = new Tile( (Tile::TileType) tiletype );
+ tile->setRotation( rotation );
+ tile->setPosition( row, col );
+ return tile;
}
void MsgDecoder::recvMoveRejected()
Index: camino/src/common/MsgDecoder.h
diff -u camino/src/common/MsgDecoder.h:1.11 camino/src/common/MsgDecoder.h:1.12
--- camino/src/common/MsgDecoder.h:1.11 Thu Feb 27 05:23:30 2003
+++ camino/src/common/MsgDecoder.h Thu Feb 27 12:26:25 2003
@@ -5,7 +5,7 @@
** MsgDecoder.h
** Decoder for socket msg
**
-** Version : $Id: MsgDecoder.h,v 1.11 2003/02/27 10:23:30 pfremy Exp $
+** Version : $Id: MsgDecoder.h,v 1.12 2003/02/27 17:26:25 pfremy Exp $
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 14/01/2003
** Copyright: Pascal Audoux, Philippe Fremy 2003
@@ -64,7 +64,7 @@
virtual void recvTilesForYou( Tile::TileType /* tile */ );
virtual void recvActivePlayer();
- virtual void recvPlayerPlaysAMove();
+ virtual void recvPlayerPlaysAMove( Tile * tile );
virtual void recvMoveRejected();
virtual void recvUpdateBoard();
@@ -133,6 +133,8 @@
void decodeWinnerInformation();
void decodeAnotherGameRequest();
void decodeAnotherGameAccept();
+
+ Tile * decodeTile();
QIODevice * _socket;
QDataStream _ts;
Index: camino/src/server/CaminoServer.cpp
diff -u camino/src/server/CaminoServer.cpp:1.11
camino/src/server/CaminoServer.cpp:1.12
--- camino/src/server/CaminoServer.cpp:1.11 Tue Feb 18 18:15:44 2003
+++ camino/src/server/CaminoServer.cpp Thu Feb 27 12:26:25 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: CaminoServer.cpp,v 1.11 2003/02/18 23:15:44 pfremy Exp $
+** Version : $Id: CaminoServer.cpp,v 1.12 2003/02/27 17:26:25 pfremy Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 19/01/2003
@@ -137,7 +137,7 @@
while( ( player = it.current() ) ) {
QPtrListIterator<Tile> tileIt( player->_tileList );
for( ; tileIt.current(); ++tileIt ) {
- player->sendTile( tileIt.current()->getType() );
+ player->sendTilesForYou( tileIt.current()->getType() );
}
++it;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Camino-devel] camino/src client/Game.cpp client/Theme.cpp cli...,
Philippe Fremy <=