camino-devel
[Top][All Lists]
Advanced

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

[Camino-devel] camino/src/client BoardCanvas.h BoardCanvas.cpp


From: Pascal Audoux
Subject: [Camino-devel] camino/src/client BoardCanvas.h BoardCanvas.cpp
Date: Sun, 09 Mar 2003 08:50:09 -0500

CVSROOT:        /cvsroot/camino
Module name:    camino
Changes by:     Pascal Audoux <address@hidden>  03/03/09 08:50:08

Modified files:
        src/client     : BoardCanvas.h BoardCanvas.cpp 

Log message:
        add methods for displaying or not 'playable' tiles

Patches:
Index: camino/src/client/BoardCanvas.cpp
diff -u camino/src/client/BoardCanvas.cpp:1.11 
camino/src/client/BoardCanvas.cpp:1.12
--- camino/src/client/BoardCanvas.cpp:1.11      Tue Mar  4 15:56:31 2003
+++ camino/src/client/BoardCanvas.cpp   Sun Mar  9 08:50:07 2003
@@ -2,7 +2,7 @@
 **
 ** Camino
 **
-** Version : $Id: BoardCanvas.cpp,v 1.11 2003/03/04 20:56:31 Audoux Exp $
+** Version : $Id: BoardCanvas.cpp,v 1.12 2003/03/09 13:50:07 Audoux Exp $
 **
 ** Author(s) : Philippe Fremy, Pascal Audoux
 ** Creation : 22/01/2003
@@ -26,8 +26,10 @@
 // include files for QT
 #include <qpainter.h>
 // application specific include files
+#include "common/Board.h"
 #include "common/const.h"
 #include "common/Tile.h"
+
 #include "client/Theme.h"
 #include "client/TileSprite.h"
 
@@ -41,9 +43,11 @@
                        (Theme::getTheme()->getTileSize() * Camino::nbRow) + ( 
2 * _margin ) );
        setBackgroundColor( Qt::black );
 
+       _board = new Board();
+
        for( int i = 0; i < Camino::nbRow; i++ ) {
                for( int j = 0; j < Camino::nbCol; j++ ) {
-                       _board[i][j] = new TileSprite( this, i, j );
+                       _tiles[i][j] = new TileSprite( this, i, j );
                }
        }
 }
@@ -52,8 +56,8 @@
 {
        for( int i = 0; i < Camino::nbRow; i++ ) {
                for( int j = 0; j < Camino::nbCol; j++ ) {
-                       delete _board[i][j];
-                       _board[i][j] = 0;
+                       delete _tiles[i][j];
+                       _tiles[i][j] = 0;
                }
        }
 }
@@ -62,17 +66,19 @@
 {
        int row = tile->getRow();
        int col = tile->getCol();
-       _board[row][col]->setType( tile->getType() );
-       _board[row][col]->setRotation( tile->getRotation() );
+       _tiles[row][col]->setType( tile->getType() );
+       _tiles[row][col]->setRotation( tile->getRotation() );
+       _board->setTile( row, col, tile );
        update();
 }
 
 void BoardCanvas::removeTile( Tile * tile )
 {
+/// XXX: manage board
        int row = tile->getRow();
        int col = tile->getCol();
-       _board[row][col]->cancelRotation();
-       _board[row][col]->setType( Tile::TILE_UNKNOWN );
+       _tiles[row][col]->cancelRotation();
+       _tiles[row][col]->setType( Tile::TILE_UNKNOWN );
        update();
 }
 
@@ -80,8 +86,8 @@
 {
        for( int i = 0; i < Camino::nbRow; i++ ) {
                for( int j = 0; j < Camino::nbCol; j++ ) {
-                       _board[i][j]->cancelRotation();
-                       _board[i][j]->setType( Tile::TILE_UNKNOWN );
+                       _tiles[i][j]->cancelRotation();
+                       _tiles[i][j]->setType( Tile::TILE_UNKNOWN );
                }
        }
 }
@@ -119,3 +125,53 @@
        *col = (x - _margin) / Theme::getTheme()->getTileSize();
        *row = (y - _margin) / Theme::getTheme()->getTileSize();
 }
+
+QPtrList<TileSprite> BoardCanvas::computePlayableArea()
+{
+       QPtrList<TileSprite> ret;
+
+       if( _board->getMoveCount() == 0 ) {
+               ret.append( _tiles[0][0] );
+               ret.append( _tiles[nbRow-1][0] );
+               ret.append( _tiles[0][nbCol-1] );
+               ret.append( _tiles[nbRow-1][nbCol-1] );
+       } else if( _board->getMoveCount() == 1 ) {
+               Tile * tile = _board->getLastPlayedTile();
+               if( ( ( tile->getRow() == 0 ) && ( tile->getCol() == 0 ) )
+               || ( ( tile->getRow() == (nbRow - 1) ) && ( tile->getCol() == 
(nbCol - 1) ) ) ) {
+                       ret.append( _tiles[nbRow-1][0] );
+                       ret.append( _tiles[0][nbCol-1] );
+               } else {
+                       ret.append( _tiles[0][0] );
+                       ret.append( _tiles[nbRow-1][nbCol-1] );
+               }
+       } else {
+               for( int i = 0; i < nbRow; i++ ) {
+                       for( int j = 0; j < nbCol; j++ ) {
+                               if( _tiles[i][j]->getType() == 
Tile::TILE_UNKNOWN ) {
+                                       if( _board->hasNeighbour( i, j ) ) {
+                                               ret.append( _tiles[i][j] );
+                                       }
+                               }
+                       }
+               }
+       }
+
+       return ret;
+}
+
+void BoardCanvas::displayPlayable( bool state )
+{
+       QPtrList<TileSprite> list = computePlayableArea();
+       for( int i = 0; i < list.count(); i++ ) {
+               TileSprite * tile = list.at(i);
+               if( state ) {
+                       tile->setRotation( 1 );
+               } else {
+                       tile->setRotation( 0 );
+               }
+       }
+       update();
+}
+
+
Index: camino/src/client/BoardCanvas.h
diff -u camino/src/client/BoardCanvas.h:1.7 camino/src/client/BoardCanvas.h:1.8
--- camino/src/client/BoardCanvas.h:1.7 Tue Mar  4 15:56:31 2003
+++ camino/src/client/BoardCanvas.h     Sun Mar  9 08:50:07 2003
@@ -5,7 +5,7 @@
 ** BoardCanvas.h
 ** Canvas for the board view
 **
-** Version : $Id: BoardCanvas.h,v 1.7 2003/03/04 20:56:31 Audoux Exp $
+** Version : $Id: BoardCanvas.h,v 1.8 2003/03/09 13:50:07 Audoux Exp $
 ** Author(s) : Philippe Fremy, Pascal Audoux
 ** Creation : 22/01/2003
 ** Copyright: Pascal Audoux, Philippe Fremy 2003
@@ -34,6 +34,7 @@
 // application specific include files
 #include "common/const.h"
 
+class Board;
 class Tile;
 class TileSprite;
 
@@ -65,11 +66,16 @@
        //! tranform x,y into row,col : to use all the time
        void xy2rowCol( int x, int y, int * row, int * col );
 
+       void displayPlayable( bool state );
+
+       QPtrList<TileSprite> computePlayableArea();
+
 protected:
        virtual void drawBackground ( QPainter & painter, const QRect & clip );
 
        int _margin;
-       TileSprite * _board[Camino::nbRow][Camino::nbCol];
+       TileSprite * _tiles[Camino::nbRow][Camino::nbCol];
+       Board * _board;
 
 friend class BoardView;
 };




reply via email to

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