-rw-r--r-- | noncore/games/go/gowidget.cpp | 15 | ||||
-rw-r--r-- | noncore/games/minesweep/minefield.h | 30 | ||||
-rw-r--r-- | noncore/games/minesweep/minesweep.cpp | 35 | ||||
-rw-r--r-- | noncore/games/snake/interface.h | 2 | ||||
-rw-r--r-- | noncore/games/snake/obstacle.cpp | 35 | ||||
-rw-r--r-- | noncore/games/snake/obstacle.h | 4 | ||||
-rw-r--r-- | noncore/games/solitaire/canvascard.cpp | 71 | ||||
-rw-r--r-- | noncore/games/solitaire/canvasshapes.cpp | 52 | ||||
-rw-r--r-- | noncore/games/solitaire/freecellcardgame.cpp | 11 | ||||
-rw-r--r-- | noncore/games/solitaire/patiencecardgame.cpp | 49 | ||||
-rw-r--r-- | noncore/games/solitaire/patiencecardgame.h | 7 | ||||
-rw-r--r-- | noncore/games/wordgame/wordgame.cpp | 71 | ||||
-rw-r--r-- | noncore/games/wordgame/wordgame.h | 6 |
13 files changed, 291 insertions, 97 deletions
diff --git a/noncore/games/go/gowidget.cpp b/noncore/games/go/gowidget.cpp index fca9797..8567b30 100644 --- a/noncore/games/go/gowidget.cpp +++ b/noncore/games/go/gowidget.cpp | |||
@@ -28,48 +28,50 @@ | |||
28 | #include <qpe/qpetoolbar.h> | 28 | #include <qpe/qpetoolbar.h> |
29 | #include <qpe/qpemenubar.h> | 29 | #include <qpe/qpemenubar.h> |
30 | #include <qpopupmenu.h> | 30 | #include <qpopupmenu.h> |
31 | #include <qaction.h> | 31 | #include <qaction.h> |
32 | #include <qapplication.h> //processEvents() | 32 | #include <qapplication.h> //processEvents() |
33 | #include <qlabel.h> | 33 | #include <qlabel.h> |
34 | 34 | ||
35 | //#include <stdio.h> | 35 | //#include <stdio.h> |
36 | 36 | ||
37 | #include "amigo.h" | 37 | #include "amigo.h" |
38 | #include "goplayutils.h" | 38 | #include "goplayutils.h" |
39 | 39 | ||
40 | static const enum bVal computer_color = BLACK; | 40 | static const enum bVal computer_color = BLACK; |
41 | 41 | ||
42 | static int current_handicap = 1; | 42 | static int current_handicap = 1; |
43 | 43 | ||
44 | static QBrush *goBrush; | 44 | static QBrush *goBrush; |
45 | //static QImage *newBlackStone; | 45 | //static QImage *newBlackStone; |
46 | //static QImage *blackStone; | 46 | //static QImage *blackStone; |
47 | //static QImage *whiteStone; | 47 | //static QImage *whiteStone; |
48 | static QPixmap *newBlackStone; | 48 | static QPixmap *newBlackStone; |
49 | static QPixmap *blackStone; | 49 | static QPixmap *blackStone; |
50 | static QPixmap *whiteStone; | 50 | static QPixmap *whiteStone; |
51 | 51 | ||
52 | static bool smallStones = FALSE; | ||
53 | |||
52 | GoMainWidget::GoMainWidget( QWidget *parent, const char* name) : | 54 | GoMainWidget::GoMainWidget( QWidget *parent, const char* name) : |
53 | QMainWindow( parent, name ) | 55 | QMainWindow( parent, name ) |
54 | { | 56 | { |
55 | setToolBarsMovable( FALSE ); | 57 | setToolBarsMovable( FALSE ); |
56 | GoWidget *go = new GoWidget(this); | 58 | GoWidget *go = new GoWidget(this); |
57 | 59 | ||
58 | setCentralWidget(go); | 60 | setCentralWidget(go); |
59 | toolbar = new QPEToolBar(this); | 61 | toolbar = new QPEToolBar(this); |
60 | toolbar->setHorizontalStretchable( TRUE ); | 62 | toolbar->setHorizontalStretchable( TRUE ); |
61 | addToolBar(toolbar); | 63 | addToolBar(toolbar); |
62 | 64 | ||
63 | QPEMenuBar *mb = new QPEMenuBar( toolbar ); | 65 | QPEMenuBar *mb = new QPEMenuBar( toolbar ); |
64 | mb->setMargin(0); | 66 | mb->setMargin(0); |
65 | QPopupMenu *file = new QPopupMenu( this ); | 67 | QPopupMenu *file = new QPopupMenu( this ); |
66 | 68 | ||
67 | QAction *a = new QAction( tr( "New Game" ), QString::null, 0, this, 0 ); | 69 | QAction *a = new QAction( tr( "New Game" ), QString::null, 0, this, 0 ); |
68 | connect( a, SIGNAL( activated() ), go, SLOT( newGame() ) ); | 70 | connect( a, SIGNAL( activated() ), go, SLOT( newGame() ) ); |
69 | a->addTo( file ); | 71 | a->addTo( file ); |
70 | 72 | ||
71 | a = new QAction( tr( "Pass" ), Resource::loadPixmap( "pass" ), QString::null, 0, this, 0 ); | 73 | a = new QAction( tr( "Pass" ), Resource::loadPixmap( "pass" ), QString::null, 0, this, 0 ); |
72 | connect( a, SIGNAL( activated() ), go, SLOT( pass() ) ); | 74 | connect( a, SIGNAL( activated() ), go, SLOT( pass() ) ); |
73 | a->addTo( file ); | 75 | a->addTo( file ); |
74 | a->addTo( toolbar ); | 76 | a->addTo( toolbar ); |
75 | 77 | ||
@@ -176,48 +178,61 @@ void GoWidget::readConfig() | |||
176 | nPassed = cfg.readNumEntry("NPassed",0); | 178 | nPassed = cfg.readNumEntry("NPassed",0); |
177 | QString b = cfg.readEntry("Board"); | 179 | QString b = cfg.readEntry("Board"); |
178 | if ( b.length() == 19*19 ) | 180 | if ( b.length() == 19*19 ) |
179 | for (int i=0; i<19; i++) | 181 | for (int i=0; i<19; i++) |
180 | for (int j=0; j<19; j++) { | 182 | for (int j=0; j<19; j++) { |
181 | QChar ch = b[j+19*i]; | 183 | QChar ch = b[j+19*i]; |
182 | if ( ch != '.' ) | 184 | if ( ch != '.' ) |
183 | GoPlaceStone( ch == 'B' ? BLACK : WHITE, i, j ); | 185 | GoPlaceStone( ch == 'B' ? BLACK : WHITE, i, j ); |
184 | } | 186 | } |
185 | lastX = cfg.readNumEntry("LastX"); | 187 | lastX = cfg.readNumEntry("LastX"); |
186 | lastY = cfg.readNumEntry("LastY"); | 188 | lastY = cfg.readNumEntry("LastY"); |
187 | extern int blackPrisoners, whitePrisoners; | 189 | extern int blackPrisoners, whitePrisoners; |
188 | blackPrisoners = cfg.readNumEntry("BlackPrisoners",0); | 190 | blackPrisoners = cfg.readNumEntry("BlackPrisoners",0); |
189 | whitePrisoners = cfg.readNumEntry("WhitePrisoners",0); | 191 | whitePrisoners = cfg.readNumEntry("WhitePrisoners",0); |
190 | reportPrisoners(blackPrisoners,whitePrisoners); | 192 | reportPrisoners(blackPrisoners,whitePrisoners); |
191 | emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone ); | 193 | emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone ); |
192 | } | 194 | } |
193 | 195 | ||
194 | void GoWidget::resizeEvent( QResizeEvent * ) | 196 | void GoWidget::resizeEvent( QResizeEvent * ) |
195 | { | 197 | { |
196 | d = QMIN(width(),height())/19; | 198 | d = QMIN(width(),height())/19; |
197 | // int r = (d/2-1); | 199 | // int r = (d/2-1); |
198 | bx = (width() - 18*d)/2 ; | 200 | bx = (width() - 18*d)/2 ; |
199 | by = (height() - 18*d)/2 ; | 201 | by = (height() - 18*d)/2 ; |
202 | |||
203 | if ( d < 10 && !smallStones ) { | ||
204 | blackStone->convertFromImage( blackStone->convertToImage().smoothScale(8,8) ); | ||
205 | whiteStone->convertFromImage( whiteStone->convertToImage().smoothScale(8,8) ); | ||
206 | newBlackStone->convertFromImage( newBlackStone->convertToImage().smoothScale(8,8) ); | ||
207 | |||
208 | smallStones = TRUE; | ||
209 | } else if ( d >= 10 && smallStones ) { | ||
210 | blackStone = new QPixmap(Resource::loadPixmap( "Go-black" )); | ||
211 | whiteStone = new QPixmap(Resource::loadPixmap( "Go-white" )); | ||
212 | newBlackStone = new QPixmap(Resource::loadPixmap( "Go-black-highlight" )); | ||
213 | smallStones = FALSE; | ||
214 | } | ||
200 | } | 215 | } |
201 | 216 | ||
202 | void GoWidget::init() | 217 | void GoWidget::init() |
203 | { | 218 | { |
204 | lastX = lastY = newX = newY = -1; | 219 | lastX = lastY = newX = newY = -1; |
205 | nPassed = 0; | 220 | nPassed = 0; |
206 | for ( int i = 0; i < 19; i++ ) | 221 | for ( int i = 0; i < 19; i++ ) |
207 | for ( int j = 0; j < 19; j++ ) | 222 | for ( int j = 0; j < 19; j++ ) |
208 | board[i][j]=-1; | 223 | board[i][j]=-1; |
209 | gameActive = TRUE; | 224 | gameActive = TRUE; |
210 | goRestart(current_handicap); | 225 | goRestart(current_handicap); |
211 | 226 | ||
212 | if ( twoplayer ) { | 227 | if ( twoplayer ) { |
213 | currentPlayer = BLACK; | 228 | currentPlayer = BLACK; |
214 | } else { | 229 | } else { |
215 | doComputerMove(); | 230 | doComputerMove(); |
216 | currentPlayer = WHITE; | 231 | currentPlayer = WHITE; |
217 | } | 232 | } |
218 | emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone ); | 233 | emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone ); |
219 | } | 234 | } |
220 | 235 | ||
221 | void GoWidget::paintEvent( QPaintEvent *e ) | 236 | void GoWidget::paintEvent( QPaintEvent *e ) |
222 | { | 237 | { |
223 | int i,j; | 238 | int i,j; |
diff --git a/noncore/games/minesweep/minefield.h b/noncore/games/minesweep/minefield.h index 4ede435..1349c35 100644 --- a/noncore/games/minesweep/minefield.h +++ b/noncore/games/minesweep/minefield.h | |||
@@ -1,87 +1,101 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #ifndef MINEFIELD_H | 20 | #ifndef MINEFIELD_H |
21 | #define MINEFIELD_H | 21 | #define MINEFIELD_H |
22 | 22 | ||
23 | #include <qtable.h> | 23 | #include <qscrollview.h> |
24 | 24 | ||
25 | class Mine; | 25 | class Mine; |
26 | class Config; | 26 | class Config; |
27 | 27 | ||
28 | class MineField : public QTable | 28 | class MineField : public QScrollView |
29 | { | 29 | { |
30 | Q_OBJECT | 30 | Q_OBJECT |
31 | public: | 31 | public: |
32 | MineField( QWidget* parent = 0, const char* name = 0 ); | 32 | MineField( QWidget* parent = 0, const char* name = 0 ); |
33 | ~MineField(); | 33 | ~MineField(); |
34 | 34 | ||
35 | enum State { Waiting, Playing, GameOver }; | 35 | enum State { Waiting, Playing, GameOver }; |
36 | 36 | ||
37 | State state() const { return stat; } | 37 | State state() const { return stat; } |
38 | 38 | ||
39 | void readConfig(Config&); | 39 | void readConfig(Config&); |
40 | void writeConfig(Config&) const; | 40 | void writeConfig(Config&) const; |
41 | 41 | ||
42 | int level() const { return lev; } | 42 | int level() const { return lev; } |
43 | 43 | ||
44 | void setAvailableRect( const QRect & ); | ||
44 | public slots: | 45 | public slots: |
45 | void setup( int level ); | 46 | void setup( int level ); |
46 | 47 | ||
47 | void showMines(); | 48 | void showMines(); |
48 | 49 | ||
49 | signals: | 50 | signals: |
50 | void gameOver( bool won ); | 51 | void gameOver( bool won ); |
51 | void gameStarted(); | 52 | void gameStarted(); |
52 | void mineCount( int ); | 53 | void mineCount( int ); |
53 | 54 | ||
54 | protected: | 55 | protected: |
55 | void paintFocus( QPainter*, const QRect& ); | 56 | |
56 | void viewportMousePressEvent( QMouseEvent* ); | 57 | void contentsMousePressEvent( QMouseEvent* ); |
57 | void viewportMouseReleaseEvent( QMouseEvent* ); | 58 | void contentsMouseReleaseEvent( QMouseEvent* ); |
58 | void keyPressEvent( QKeyEvent* ); | 59 | void keyPressEvent( QKeyEvent* ); |
59 | void keyReleaseEvent( QKeyEvent* ); | 60 | void keyReleaseEvent( QKeyEvent* ); |
60 | 61 | void drawContents( QPainter * p, int clipx, int clipy, int clipw, int cliph ); | |
62 | |||
61 | int getHint( int row, int col ); | 63 | int getHint( int row, int col ); |
62 | void setHint( Mine* ); | 64 | void setHint( int r, int c ); |
63 | void updateMine( int row, int col ); | 65 | void updateMine( int row, int col ); |
64 | void paletteChange( const QPalette & ); | 66 | void paletteChange( const QPalette & ); |
65 | 67 | void updateCell( int r, int c ); | |
68 | bool onBoard( int r, int c ) const { return r >= 0 && r < numRows && c >= 0 && c < numCols; } | ||
69 | Mine *mine( int row, int col ) { return onBoard(row, col ) ? mines[row+numCols*col] : 0; } | ||
70 | const Mine *mine( int row, int col ) const { return onBoard(row, col ) ? mines[row+numCols*col] : 0; } | ||
71 | |||
66 | protected slots: | 72 | protected slots: |
67 | void cellPressed( int row, int col ); | 73 | void cellPressed( int row, int col ); |
68 | void cellClicked( int row, int col ); | 74 | void cellClicked( int row, int col ); |
69 | void held(); | 75 | void held(); |
70 | 76 | ||
71 | private: | 77 | private: |
78 | int findCellSize(); | ||
79 | void setCellSize( int ); | ||
80 | |||
72 | State stat; | 81 | State stat; |
73 | void MineField::setState( State st ); | 82 | void MineField::setState( State st ); |
74 | void MineField::placeMines(); | 83 | void MineField::placeMines(); |
75 | enum FlagAction { NoAction, FlagOn, FlagNext }; | 84 | enum FlagAction { NoAction, FlagOn, FlagNext }; |
76 | FlagAction flagAction; | 85 | FlagAction flagAction; |
77 | bool ignoreClick; | 86 | bool ignoreClick; |
78 | int currRow; | 87 | int currRow; |
79 | int currCol; | 88 | int currCol; |
89 | int numRows, numCols; | ||
90 | |||
80 | int minecount; | 91 | int minecount; |
81 | int mineguess; | 92 | int mineguess; |
82 | int nonminecount; | 93 | int nonminecount; |
83 | int lev; | 94 | int lev; |
95 | QRect availableRect; | ||
96 | int cellSize; | ||
84 | QTimer *holdTimer; | 97 | QTimer *holdTimer; |
98 | Mine **mines; | ||
85 | }; | 99 | }; |
86 | 100 | ||
87 | #endif // MINEFIELD_H | 101 | #endif // MINEFIELD_H |
diff --git a/noncore/games/minesweep/minesweep.cpp b/noncore/games/minesweep/minesweep.cpp index 6492462..c84fe53 100644 --- a/noncore/games/minesweep/minesweep.cpp +++ b/noncore/games/minesweep/minesweep.cpp | |||
@@ -198,105 +198,120 @@ void ResultIndicator::center() | |||
198 | QPoint pp = w->mapToGlobal( QPoint(0,0) ); | 198 | QPoint pp = w->mapToGlobal( QPoint(0,0) ); |
199 | QSize s = sizeHint()*3; | 199 | QSize s = sizeHint()*3; |
200 | pp = QPoint( pp.x() + w->width()/2 - s.width()/2, | 200 | pp = QPoint( pp.x() + w->width()/2 - s.width()/2, |
201 | pp.y() + w->height()/ 2 - s.height()/2 ); | 201 | pp.y() + w->height()/ 2 - s.height()/2 ); |
202 | 202 | ||
203 | setGeometry( QRect(pp, s) ); | 203 | setGeometry( QRect(pp, s) ); |
204 | 204 | ||
205 | } | 205 | } |
206 | 206 | ||
207 | void ResultIndicator::timerEvent( QTimerEvent *te ) | 207 | void ResultIndicator::timerEvent( QTimerEvent *te ) |
208 | { | 208 | { |
209 | if ( te->timerId() != timerId ) | 209 | if ( te->timerId() != timerId ) |
210 | return; | 210 | return; |
211 | killTimer( timerId ); | 211 | killTimer( timerId ); |
212 | if ( twoStage ) { | 212 | if ( twoStage ) { |
213 | center(); | 213 | center(); |
214 | twoStage = FALSE; | 214 | twoStage = FALSE; |
215 | timerId = startTimer( 1000 ); | 215 | timerId = startTimer( 1000 ); |
216 | } else { | 216 | } else { |
217 | delete this; | 217 | delete this; |
218 | } | 218 | } |
219 | } | 219 | } |
220 | 220 | ||
221 | 221 | ||
222 | class MineFrame : public QFrame | ||
223 | { | ||
224 | public: | ||
225 | MineFrame( QWidget *parent, const char *name = 0 ) | ||
226 | :QFrame( parent, name ) {} | ||
227 | void setField( MineField *f ) { field = f; } | ||
228 | protected: | ||
229 | void resizeEvent( QResizeEvent *e ) { | ||
230 | field->setAvailableRect( contentsRect()); | ||
231 | QFrame::resizeEvent(e); | ||
232 | } | ||
233 | private: | ||
234 | MineField *field; | ||
235 | }; | ||
236 | |||
237 | |||
238 | |||
222 | MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f ) | 239 | MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f ) |
223 | : QMainWindow( parent, name, f ) | 240 | : QMainWindow( parent, name, f ) |
224 | { | 241 | { |
225 | srand(::time(0)); | 242 | srand(::time(0)); |
226 | setCaption( tr("Mine Hunt") ); | 243 | setCaption( tr("Mine Hunt") ); |
227 | setIcon( Resource::loadPixmap( "minesweep_icon" ) ); | 244 | setIcon( Resource::loadPixmap( "minesweep_icon" ) ); |
228 | 245 | ||
229 | QPEToolBar *menuToolBar = new QPEToolBar( this ); | 246 | QPEToolBar *toolBar = new QPEToolBar( this ); |
230 | QPEMenuBar *menuBar = new QPEMenuBar( menuToolBar ); | 247 | toolBar->setHorizontalStretchable( TRUE ); |
248 | |||
249 | QPEMenuBar *menuBar = new QPEMenuBar( toolBar ); | ||
231 | 250 | ||
232 | QPopupMenu *gameMenu = new QPopupMenu( this ); | 251 | QPopupMenu *gameMenu = new QPopupMenu( this ); |
233 | gameMenu->insertItem( tr("Beginner"), this, SLOT( beginner() ) ); | 252 | gameMenu->insertItem( tr("Beginner"), this, SLOT( beginner() ) ); |
234 | gameMenu->insertItem( tr("Advanced"), this, SLOT( advanced() ) ); | 253 | gameMenu->insertItem( tr("Advanced"), this, SLOT( advanced() ) ); |
235 | gameMenu->insertItem( tr("Expert"), this, SLOT( expert() ) ); | 254 | gameMenu->insertItem( tr("Expert"), this, SLOT( expert() ) ); |
236 | 255 | ||
237 | menuBar->insertItem( tr("Game"), gameMenu ); | 256 | menuBar->insertItem( tr("Game"), gameMenu ); |
238 | |||
239 | QPEToolBar *toolBar = new QPEToolBar( this ); | ||
240 | toolBar->setHorizontalStretchable( TRUE ); | ||
241 | 257 | ||
242 | guessLCD = new QLCDNumber( toolBar ); | 258 | guessLCD = new QLCDNumber( toolBar ); |
243 | toolBar->setStretchableWidget( guessLCD ); | 259 | toolBar->setStretchableWidget( guessLCD ); |
244 | 260 | ||
245 | QPalette lcdPal( red ); | 261 | QPalette lcdPal( red ); |
246 | lcdPal.setColor( QColorGroup::Background, QApplication::palette().active().background() ); | 262 | lcdPal.setColor( QColorGroup::Background, QApplication::palette().active().background() ); |
247 | lcdPal.setColor( QColorGroup::Button, QApplication::palette().active().button() ); | 263 | lcdPal.setColor( QColorGroup::Button, QApplication::palette().active().button() ); |
248 | 264 | ||
249 | // guessLCD->setPalette( lcdPal ); | 265 | // guessLCD->setPalette( lcdPal ); |
250 | guessLCD->setSegmentStyle( QLCDNumber::Flat ); | 266 | guessLCD->setSegmentStyle( QLCDNumber::Flat ); |
251 | guessLCD->setFrameStyle( QFrame::NoFrame ); | 267 | guessLCD->setFrameStyle( QFrame::NoFrame ); |
252 | guessLCD->setNumDigits( 2 ); | 268 | guessLCD->setNumDigits( 2 ); |
253 | guessLCD->setBackgroundMode( PaletteButton ); | 269 | guessLCD->setBackgroundMode( PaletteButton ); |
254 | newGameButton = new QPushButton( toolBar ); | 270 | newGameButton = new QPushButton( toolBar ); |
255 | newGameButton->setPixmap( QPixmap( pix_new ) ); | 271 | newGameButton->setPixmap( QPixmap( pix_new ) ); |
256 | newGameButton->setFocusPolicy(QWidget::NoFocus); | 272 | newGameButton->setFocusPolicy(QWidget::NoFocus); |
257 | connect( newGameButton, SIGNAL(clicked()), this, SLOT(newGame()) ); | 273 | connect( newGameButton, SIGNAL(clicked()), this, SLOT(newGame()) ); |
258 | 274 | ||
259 | timeLCD = new QLCDNumber( toolBar ); | 275 | timeLCD = new QLCDNumber( toolBar ); |
260 | // timeLCD->setPalette( lcdPal ); | 276 | // timeLCD->setPalette( lcdPal ); |
261 | timeLCD->setSegmentStyle( QLCDNumber::Flat ); | 277 | timeLCD->setSegmentStyle( QLCDNumber::Flat ); |
262 | timeLCD->setFrameStyle( QFrame::NoFrame ); | 278 | timeLCD->setFrameStyle( QFrame::NoFrame ); |
263 | timeLCD->setNumDigits( 5 ); // "mm:ss" | 279 | timeLCD->setNumDigits( 5 ); // "mm:ss" |
264 | timeLCD->setBackgroundMode( PaletteButton ); | 280 | timeLCD->setBackgroundMode( PaletteButton ); |
265 | 281 | ||
266 | setToolBarsMovable ( FALSE ); | 282 | setToolBarsMovable ( FALSE ); |
267 | 283 | ||
268 | addToolBar( menuToolBar ); | ||
269 | addToolBar( toolBar ); | 284 | addToolBar( toolBar ); |
270 | 285 | ||
271 | QFrame *mainframe = new QFrame( this ); | 286 | MineFrame *mainframe = new MineFrame( this ); |
272 | mainframe->setFrameShape( QFrame::Box ); | 287 | mainframe->setFrameShape( QFrame::Box ); |
273 | mainframe->setFrameShadow( QFrame::Raised ); | 288 | mainframe->setFrameShadow( QFrame::Raised ); |
274 | mainframe->setMargin(5); | 289 | |
275 | mainframe->setLineWidth(2); | 290 | mainframe->setLineWidth(2); |
276 | QBoxLayout *box = new QVBoxLayout( mainframe ); | 291 | |
277 | field = new MineField( mainframe ); | 292 | field = new MineField( mainframe ); |
278 | box->addWidget( field, 0, AlignCenter ); | 293 | mainframe->setField( field ); |
279 | QFont fnt = field->font(); | 294 | QFont fnt = field->font(); |
280 | fnt.setBold( TRUE ); | 295 | fnt.setBold( TRUE ); |
281 | field->setFont( QFont( fnt ) ); | 296 | field->setFont( QFont( fnt ) ); |
282 | field->setFocus(); | 297 | field->setFocus(); |
283 | setCentralWidget( mainframe ); | 298 | setCentralWidget( mainframe ); |
284 | 299 | ||
285 | connect( field, SIGNAL( gameOver( bool ) ), this, SLOT( gameOver( bool ) ) ); | 300 | connect( field, SIGNAL( gameOver( bool ) ), this, SLOT( gameOver( bool ) ) ); |
286 | connect( field, SIGNAL( mineCount( int ) ), this, SLOT( setCounter( int ) ) ); | 301 | connect( field, SIGNAL( mineCount( int ) ), this, SLOT( setCounter( int ) ) ); |
287 | connect( field, SIGNAL( gameStarted()), this, SLOT( startPlaying() ) ); | 302 | connect( field, SIGNAL( gameStarted()), this, SLOT( startPlaying() ) ); |
288 | 303 | ||
289 | timer = new QTimer( this ); | 304 | timer = new QTimer( this ); |
290 | 305 | ||
291 | connect( timer, SIGNAL( timeout() ), this, SLOT( updateTime() ) ); | 306 | connect( timer, SIGNAL( timeout() ), this, SLOT( updateTime() ) ); |
292 | 307 | ||
293 | readConfig(); | 308 | readConfig(); |
294 | } | 309 | } |
295 | 310 | ||
296 | MineSweep::~MineSweep() | 311 | MineSweep::~MineSweep() |
297 | { | 312 | { |
298 | writeConfig(); | 313 | writeConfig(); |
299 | } | 314 | } |
300 | 315 | ||
301 | void MineSweep::gameOver( bool won ) | 316 | void MineSweep::gameOver( bool won ) |
302 | { | 317 | { |
diff --git a/noncore/games/snake/interface.h b/noncore/games/snake/interface.h index 30c7f84..454d4ee 100644 --- a/noncore/games/snake/interface.h +++ b/noncore/games/snake/interface.h | |||
@@ -15,55 +15,55 @@ | |||
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include <qmainwindow.h> | 20 | #include <qmainwindow.h> |
21 | #include <qcanvas.h> | 21 | #include <qcanvas.h> |
22 | #include <qlabel.h> | 22 | #include <qlabel.h> |
23 | 23 | ||
24 | #include "snake.h" | 24 | #include "snake.h" |
25 | #include "target.h" | 25 | #include "target.h" |
26 | #include "obstacle.h" | 26 | #include "obstacle.h" |
27 | 27 | ||
28 | // class QCanvas; | 28 | // class QCanvas; |
29 | 29 | ||
30 | class SnakeGame : public QMainWindow { | 30 | class SnakeGame : public QMainWindow { |
31 | Q_OBJECT | 31 | Q_OBJECT |
32 | 32 | ||
33 | public: | 33 | public: |
34 | SnakeGame(QWidget* parent=0, const char* name=0, WFlags f=0); | 34 | SnakeGame(QWidget* parent=0, const char* name=0, WFlags f=0); |
35 | ~SnakeGame(); | 35 | ~SnakeGame(); |
36 | 36 | ||
37 | void clear(); | 37 | void clear(); |
38 | void createTargets(); | 38 | void createTargets(); |
39 | void welcomescreen(); | ||
40 | 39 | ||
41 | protected: | 40 | protected: |
42 | virtual void keyPressEvent(QKeyEvent*); | 41 | virtual void keyPressEvent(QKeyEvent*); |
43 | virtual void resizeEvent(QResizeEvent *e); | 42 | virtual void resizeEvent(QResizeEvent *e); |
44 | 43 | ||
45 | signals: | 44 | signals: |
46 | void moveFaster(); | 45 | void moveFaster(); |
47 | 46 | ||
48 | private slots: | 47 | private slots: |
49 | void newGame(); | 48 | void newGame(); |
50 | void gameOver(); | 49 | void gameOver(); |
51 | void wait(); | 50 | void wait(); |
52 | void levelUp(); | 51 | void levelUp(); |
53 | void scoreInc(); | 52 | void scoreInc(); |
53 | void welcomescreen(); | ||
54 | 54 | ||
55 | private: | 55 | private: |
56 | void showScore(int); | 56 | void showScore(int); |
57 | QCanvasView* cv; | 57 | QCanvasView* cv; |
58 | QLabel* scorelabel; | 58 | QLabel* scorelabel; |
59 | QCanvas canvas; | 59 | QCanvas canvas; |
60 | QTimer* pauseTimer; | 60 | QTimer* pauseTimer; |
61 | Snake* snake; | 61 | Snake* snake; |
62 | int last; | 62 | int last; |
63 | int level; | 63 | int level; |
64 | int stage; | 64 | int stage; |
65 | int targetamount; | 65 | int targetamount; |
66 | int notargets; | 66 | int notargets; |
67 | bool waitover; | 67 | bool waitover; |
68 | bool gamestopped; | 68 | bool gamestopped; |
69 | }; | 69 | }; |
diff --git a/noncore/games/snake/obstacle.cpp b/noncore/games/snake/obstacle.cpp index 2d07fe7..4bdefa5 100644 --- a/noncore/games/snake/obstacle.cpp +++ b/noncore/games/snake/obstacle.cpp | |||
@@ -2,50 +2,69 @@ | |||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "obstacle.h" | 21 | #include "obstacle.h" |
22 | #include "codes.h" | 22 | #include "codes.h" |
23 | 23 | ||
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | 25 | ||
26 | Obstacle::Obstacle(QCanvas* canvas, int x, int y) | 26 | |
27 | : QCanvasSprite(0, canvas) | 27 | |
28 | Obstacle::Obstacle(QCanvas* canvas, int y) | ||
29 | : QCanvasSprite(0,canvas) | ||
28 | { | 30 | { |
29 | newObstacle(x, y); | 31 | newObstacle(y); |
30 | } | 32 | } |
31 | 33 | ||
32 | void Obstacle::newObstacle(int x, int y) | 34 | void Obstacle::newObstacle(int y) |
33 | { | 35 | { |
34 | QCanvasPixmapArray* obstaclearray = new QCanvasPixmapArray(Resource::findPixmap("snake/wall.png")); | 36 | QPixmap obstaclePix( Resource::findPixmap("snake/wall.png") ); |
35 | 37 | ||
38 | if ( obstaclePix.width() > canvas()->width()*3/5 ) { | ||
39 | int w = canvas()->width()*3/5; | ||
40 | w = w - w % 16; | ||
41 | obstaclePix.resize( w, obstaclePix.height() ); | ||
42 | } | ||
43 | |||
44 | QList<QPixmap> pixl; | ||
45 | pixl.append( &obstaclePix ); | ||
46 | |||
47 | QPoint nullp; | ||
48 | QList<QPoint> pl; | ||
49 | pl.append( &nullp ); | ||
50 | |||
51 | QCanvasPixmapArray* obstaclearray = new QCanvasPixmapArray(pixl, pl); | ||
36 | setSequence(obstaclearray); | 52 | setSequence(obstaclearray); |
37 | 53 | ||
54 | int x = ( canvas()->width() - obstaclePix.width() )/2; | ||
55 | x = x - x % 16; | ||
56 | y = y - y % 16; | ||
38 | move(x, y); | 57 | move(x, y); |
39 | 58 | setZ( -100 ); | |
40 | show(); | 59 | show(); |
41 | canvas()->update(); | 60 | canvas()->update(); |
42 | } | 61 | } |
43 | 62 | ||
44 | int Obstacle::rtti() const | 63 | int Obstacle::rtti() const |
45 | { | 64 | { |
46 | return obstacle_rtti; | 65 | return obstacle_rtti; |
47 | } | 66 | } |
48 | 67 | ||
49 | Obstacle::~Obstacle() | 68 | Obstacle::~Obstacle() |
50 | { | 69 | { |
51 | } | 70 | } |
diff --git a/noncore/games/snake/obstacle.h b/noncore/games/snake/obstacle.h index 838917f..b3c7846 100644 --- a/noncore/games/snake/obstacle.h +++ b/noncore/games/snake/obstacle.h | |||
@@ -2,29 +2,29 @@ | |||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include <qcanvas.h> | 20 | #include <qcanvas.h> |
21 | 21 | ||
22 | class Obstacle : public QCanvasSprite | 22 | class Obstacle : public QCanvasSprite |
23 | { | 23 | { |
24 | 24 | ||
25 | public: | 25 | public: |
26 | Obstacle(QCanvas*, int x, int y); | 26 | Obstacle(QCanvas*, int y); |
27 | ~Obstacle(); | 27 | ~Obstacle(); |
28 | void newObstacle(int x, int y); | 28 | void newObstacle(int y); |
29 | int rtti() const; | 29 | int rtti() const; |
30 | }; | 30 | }; |
diff --git a/noncore/games/solitaire/canvascard.cpp b/noncore/games/solitaire/canvascard.cpp index ae3c859..7c4a5ba 100644 --- a/noncore/games/solitaire/canvascard.cpp +++ b/noncore/games/solitaire/canvascard.cpp | |||
@@ -6,48 +6,49 @@ | |||
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "cardgame.h" | 21 | #include "cardgame.h" |
22 | #include "canvascard.h" | 22 | #include "canvascard.h" |
23 | 23 | ||
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | 25 | ||
26 | #include <qpainter.h> | 26 | #include <qpainter.h> |
27 | #include <qimage.h> | 27 | #include <qimage.h> |
28 | #include <qpaintdevice.h> | 28 | #include <qpaintdevice.h> |
29 | #include <qbitmap.h> | 29 | #include <qbitmap.h> |
30 | #include <qgfx_qws.h> // Needed to get the device's width | ||
30 | 31 | ||
31 | #include <math.h> | 32 | #include <math.h> |
32 | 33 | ||
33 | #if defined( QT_QWS_CASSIOPEIA ) | 34 | #if defined( QT_QWS_CASSIOPEIA ) |
34 | #define SLOW_HARDWARE | 35 | #define SLOW_HARDWARE |
35 | #endif | 36 | #endif |
36 | 37 | ||
37 | // Seems to be fast enough to me even without Transformations in the library | 38 | // Seems to be fast enough to me even without Transformations in the library |
38 | //#if defined( QT_NO_TRANSFORMATIONS ) && defined( QT_QWS_IPAQ ) | 39 | //#if defined( QT_NO_TRANSFORMATIONS ) && defined( QT_QWS_IPAQ ) |
39 | //#define SLOW_HARDWARE | 40 | //#define SLOW_HARDWARE |
40 | //#endif | 41 | //#endif |
41 | 42 | ||
42 | 43 | ||
43 | QBitmap *Create180RotatedBitmap(QBitmap *srcBitmap) | 44 | QBitmap *Create180RotatedBitmap(QBitmap *srcBitmap) |
44 | { | 45 | { |
45 | #ifdef QT_NO_TRANSFORMATIONS | 46 | #ifdef QT_NO_TRANSFORMATIONS |
46 | int w = srcBitmap->width(); | 47 | int w = srcBitmap->width(); |
47 | int h = srcBitmap->height(); | 48 | int h = srcBitmap->height(); |
48 | QBitmap *dstBitmap = new QBitmap( w, h ); | 49 | QBitmap *dstBitmap = new QBitmap( w, h ); |
49 | // ### this is very poorly implemented and probably could be much faster | 50 | // ### this is very poorly implemented and probably could be much faster |
50 | for (int i = 0; i < w; i++) | 51 | for (int i = 0; i < w; i++) |
51 | for (int j = 0; j < h; j++) | 52 | for (int j = 0; j < h; j++) |
52 | bitBlt( dstBitmap, i, j, srcBitmap, w - i - 1, h - j - 1, 1, 1 ); | 53 | bitBlt( dstBitmap, i, j, srcBitmap, w - i - 1, h - j - 1, 1, 1 ); |
53 | return dstBitmap; | 54 | return dstBitmap; |
@@ -81,132 +82,162 @@ QPixmap *CreateScaledPixmap(QPixmap *srcPixmap, double scaleX, double scaleY) | |||
81 | } | 82 | } |
82 | } | 83 | } |
83 | return dstPixmap; | 84 | return dstPixmap; |
84 | #else | 85 | #else |
85 | QWMatrix s; | 86 | QWMatrix s; |
86 | s.scale( scaleX, scaleY ); | 87 | s.scale( scaleX, scaleY ); |
87 | return new QPixmap( srcPixmap->xForm( s ) ); | 88 | return new QPixmap( srcPixmap->xForm( s ) ); |
88 | #endif | 89 | #endif |
89 | } | 90 | } |
90 | 91 | ||
91 | 92 | ||
92 | // Initialise static member variables to NULL | 93 | // Initialise static member variables to NULL |
93 | QPixmap *CanvasCard::cardsFaces = NULL; | 94 | QPixmap *CanvasCard::cardsFaces = NULL; |
94 | QPixmap *CanvasCard::cardsBacks = NULL; | 95 | QPixmap *CanvasCard::cardsBacks = NULL; |
95 | QBitmap *CanvasCard::cardsChars = NULL; | 96 | QBitmap *CanvasCard::cardsChars = NULL; |
96 | QBitmap *CanvasCard::cardsSuits = NULL; | 97 | QBitmap *CanvasCard::cardsSuits = NULL; |
97 | QBitmap *CanvasCard::cardsCharsUpsideDown = NULL; | 98 | QBitmap *CanvasCard::cardsCharsUpsideDown = NULL; |
98 | QBitmap *CanvasCard::cardsSuitsUpsideDown = NULL; | 99 | QBitmap *CanvasCard::cardsSuitsUpsideDown = NULL; |
99 | 100 | ||
100 | 101 | ||
101 | CanvasCard::CanvasCard( eValue v, eSuit s, bool f, QCanvas *canvas ) : | 102 | CanvasCard::CanvasCard( eValue v, eSuit s, bool f, QCanvas *canvas ) : |
102 | Card(v, s, f), QCanvasRectangle( 0, 0, 1, 1, canvas ), cardBack(1), scaleX(1.0), scaleY(1.0) | 103 | Card(v, s, f), QCanvasRectangle( 0, 0, 1, 1, canvas ), cardBack(1), scaleX(1.0), scaleY(1.0) |
103 | { | 104 | { |
104 | if ( !cardsFaces ) { | 105 | if ( !cardsFaces ) { |
105 | cardsFaces = new QPixmap( Resource::loadPixmap( "cards/card_face" ) ); | 106 | if ( qt_screen->deviceWidth() < 200 ) { |
106 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001" ) ); | 107 | cardsFaces = new QPixmap( Resource::loadPixmap( "cards/card_face_small" ) ); |
107 | cardsChars = new QBitmap( Resource::loadBitmap( "cards/card_chars" ) ); | 108 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001_small" ) ); |
108 | cardsSuits = new QBitmap( Resource::loadBitmap( "cards/card_suits" ) ); | 109 | cardsChars = new QBitmap( Resource::loadBitmap( "cards/card_chars_small" ) ); |
110 | cardsSuits = new QBitmap( Resource::loadBitmap( "cards/card_suits_small" ) ); | ||
111 | } else { | ||
112 | cardsFaces = new QPixmap( Resource::loadPixmap( "cards/card_face" ) ); | ||
113 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001" ) ); | ||
114 | cardsChars = new QBitmap( Resource::loadBitmap( "cards/card_chars" ) ); | ||
115 | cardsSuits = new QBitmap( Resource::loadBitmap( "cards/card_suits" ) ); | ||
116 | } | ||
109 | cardsCharsUpsideDown = Create180RotatedBitmap( cardsChars ); | 117 | cardsCharsUpsideDown = Create180RotatedBitmap( cardsChars ); |
110 | cardsSuitsUpsideDown = Create180RotatedBitmap( cardsSuits ); | 118 | cardsSuitsUpsideDown = Create180RotatedBitmap( cardsSuits ); |
111 | } | 119 | } |
112 | xOff = cardsFaces->width() / 2; | 120 | xOff = cardsFaces->width() / 2; |
113 | yOff = cardsFaces->height() / 2; | 121 | yOff = cardsFaces->height() / 2; |
114 | setSize( cardsFaces->width(), cardsFaces->height() ); | 122 | setSize( cardsFaces->width(), cardsFaces->height() ); |
115 | setPen( NoPen ); | 123 | setPen( NoPen ); |
116 | flipping = FALSE; | 124 | flipping = FALSE; |
117 | } | 125 | } |
118 | 126 | ||
119 | 127 | ||
120 | void CanvasCard::setCardBack(int b) | 128 | void CanvasCard::setCardBack(int b) |
121 | { | 129 | { |
122 | if ( cardBack != b ) { | 130 | if ( cardBack != b ) { |
123 | 131 | ||
124 | cardBack = b; | 132 | cardBack = b; |
125 | 133 | ||
126 | if ( cardsBacks ) | 134 | if ( cardsBacks ) |
127 | delete cardsBacks; | 135 | delete cardsBacks; |
128 | 136 | ||
129 | switch (cardBack) { | 137 | if ( qt_screen->deviceWidth() < 200 ) { |
130 | case 0: | 138 | switch (cardBack) { |
131 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001" ) ); break; | 139 | case 0: |
132 | case 1: | 140 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001_small" ) ); break; |
133 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0002" ) ); break; | 141 | case 1: |
134 | case 2: | 142 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0002_small" ) ); break; |
135 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0003" ) ); break; | 143 | case 2: |
136 | case 3: | 144 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0003_small" ) ); break; |
137 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0004" ) ); break; | 145 | case 3: |
138 | case 4: | 146 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0004_small" ) ); break; |
139 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0005" ) ); break; | 147 | case 4: |
148 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0005_small" ) ); break; | ||
149 | } | ||
150 | } else { | ||
151 | switch (cardBack) { | ||
152 | case 0: | ||
153 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001" ) ); break; | ||
154 | case 1: | ||
155 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0002" ) ); break; | ||
156 | case 2: | ||
157 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0003" ) ); break; | ||
158 | case 3: | ||
159 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0004" ) ); break; | ||
160 | case 4: | ||
161 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0005" ) ); break; | ||
162 | } | ||
140 | } | 163 | } |
141 | 164 | ||
142 | if ( !isFacing() ) | 165 | if ( !isFacing() ) |
143 | redraw(); | 166 | redraw(); |
144 | } | 167 | } |
145 | } | 168 | } |
146 | 169 | ||
147 | 170 | ||
148 | void CanvasCard::draw(QPainter &painter) | 171 | void CanvasCard::draw(QPainter &painter) |
149 | { | 172 | { |
150 | int ix = (int)x(), iy = (int)y(); | 173 | int ix = (int)x(), iy = (int)y(); |
151 | 174 | ||
152 | QPainter *p = &painter; | 175 | QPainter *p = &painter; |
153 | QPixmap *unscaledCard = NULL; | 176 | QPixmap *unscaledCard = NULL; |
154 | 177 | ||
155 | if ((scaleX <= 0.98) || (scaleY <= 0.98)) | 178 | if ((scaleX <= 0.98) || (scaleY <= 0.98)) |
156 | { | 179 | { |
157 | p = new QPainter(); | 180 | p = new QPainter(); |
158 | unscaledCard = new QPixmap( cardsFaces->width(), cardsFaces->height() ); | 181 | unscaledCard = new QPixmap( cardsFaces->width(), cardsFaces->height() ); |
159 | p->begin(unscaledCard); | 182 | p->begin(unscaledCard); |
160 | ix = 0; | 183 | ix = 0; |
161 | iy = 0; | 184 | iy = 0; |
162 | } | 185 | } |
163 | 186 | ||
164 | if ( isFacing() ) { | 187 | if ( isFacing() ) { |
165 | 188 | ||
166 | /* | 189 | /* |
167 | // Now add the joker and card backs to the list of pixmaps | 190 | // Now add the joker and card backs to the list of pixmaps |
168 | QPixmap *CardsBack = new QPixmap( Resource::loadPixmap( "cards/card_joker.png" ) ); | 191 | QPixmap *CardsBack = new QPixmap( Resource::loadPixmap( "cards/card_joker.png" ) ); |
169 | QPoint *newBackHotspot = new QPoint( 0, 0 ); | 192 | QPoint *newBackHotspot = new QPoint( 0, 0 ); |
170 | pixmaps->append((const QPixmap *)CardsBack); | 193 | pixmaps->append((const QPixmap *)CardsBack); |
171 | hotspots->append((const QPoint *)newBackHotspot); | 194 | hotspots->append((const QPoint *)newBackHotspot); |
172 | */ | 195 | */ |
173 | 196 | ||
174 | int w = cardsFaces->width(), h = cardsFaces->height(); | 197 | int w = cardsFaces->width(), h = cardsFaces->height(); |
175 | 198 | ||
176 | //p->setBrush( NoBrush ); | 199 | //p->setBrush( NoBrush ); |
177 | p->setBrush( QColor( 0xFF, 0xFF, 0xFF ) ); | 200 | p->setBrush( QColor( 0xFF, 0xFF, 0xFF ) ); |
178 | 201 | ||
179 | if ( isRed() == TRUE ) | 202 | if ( isRed() == TRUE ) |
180 | p->setPen( QColor( 0xFF, 0, 0 ) ); | 203 | p->setPen( QColor( 0xFF, 0, 0 ) ); |
181 | else | 204 | else |
182 | p->setPen( QColor( 0, 0, 0 ) ); | 205 | p->setPen( QColor( 0, 0, 0 ) ); |
183 | 206 | ||
184 | p->drawPixmap( ix + 0, iy + 0, *cardsFaces ); | 207 | if ( qt_screen->deviceWidth() < 200 ) { |
185 | p->drawPixmap( ix + 4, iy + 4, *cardsChars, 7*(getValue()-1), 0, 7, 7 ); | 208 | p->drawPixmap( ix + 0, iy + 0, *cardsFaces ); |
186 | p->drawPixmap( ix + 12, iy + 4, *cardsSuits, 7*(getSuit()-1), 0, 7, 8 ); | 209 | p->drawPixmap( ix + 3, iy + 3, *cardsChars, 5*(getValue()-1), 0, 5, 6 ); |
187 | p->drawPixmap( ix + w-4-7, iy + h-4-7, *cardsCharsUpsideDown, 7*(12-getValue()+1), 0, 7, 7 ); | 210 | p->drawPixmap( ix + 11, iy + 3, *cardsSuits, 5*(getSuit()-1), 0, 5, 6 ); |
188 | p->drawPixmap( ix + w-12-7, iy + h-5-7, *cardsSuitsUpsideDown, 7*(3-getSuit()+1), 0, 7, 8 ); | 211 | p->drawPixmap( ix + w-3-5, iy + h-3-6, *cardsCharsUpsideDown, 5*(12-getValue()+1), 0, 5, 6 ); |
212 | p->drawPixmap( ix + w-11-5, iy + h-3-6, *cardsSuitsUpsideDown, 5*(3-getSuit()+1), 0, 5, 6 ); | ||
213 | } else { | ||
214 | p->drawPixmap( ix + 0, iy + 0, *cardsFaces ); | ||
215 | p->drawPixmap( ix + 4, iy + 4, *cardsChars, 7*(getValue()-1), 0, 7, 7 ); | ||
216 | p->drawPixmap( ix + 12, iy + 4, *cardsSuits, 7*(getSuit()-1), 0, 7, 8 ); | ||
217 | p->drawPixmap( ix + w-4-7, iy + h-4-7, *cardsCharsUpsideDown, 7*(12-getValue()+1), 0, 7, 7 ); | ||
218 | p->drawPixmap( ix + w-12-7, iy + h-5-7, *cardsSuitsUpsideDown, 7*(3-getSuit()+1), 0, 7, 8 ); | ||
219 | } | ||
189 | 220 | ||
190 | } else { | 221 | } else { |
191 | 222 | ||
192 | p->drawPixmap( ix, iy, *cardsBacks ); | 223 | p->drawPixmap( ix, iy, *cardsBacks ); |
193 | 224 | ||
194 | } | 225 | } |
195 | 226 | ||
196 | if (p != &painter) | 227 | if (p != &painter) |
197 | { | 228 | { |
198 | p->end(); | 229 | p->end(); |
199 | QPixmap *scaledCard = CreateScaledPixmap( unscaledCard, scaleX, scaleY ); | 230 | QPixmap *scaledCard = CreateScaledPixmap( unscaledCard, scaleX, scaleY ); |
200 | int xoff = scaledCard->width() / 2; | 231 | int xoff = scaledCard->width() / 2; |
201 | int yoff = scaledCard->height() / 2; | 232 | int yoff = scaledCard->height() / 2; |
202 | painter.drawPixmap( (int)x() + xOff - xoff, (int)y() + yOff - yoff, *scaledCard ); | 233 | painter.drawPixmap( (int)x() + xOff - xoff, (int)y() + yOff - yoff, *scaledCard ); |
203 | delete p; | 234 | delete p; |
204 | delete unscaledCard; | 235 | delete unscaledCard; |
205 | delete scaledCard; | 236 | delete scaledCard; |
206 | } | 237 | } |
207 | } | 238 | } |
208 | 239 | ||
209 | 240 | ||
210 | static const double flipLift = 1.5; | 241 | static const double flipLift = 1.5; |
211 | 242 | ||
212 | 243 | ||
diff --git a/noncore/games/solitaire/canvasshapes.cpp b/noncore/games/solitaire/canvasshapes.cpp index 28d0b4e..6ccd4a4 100644 --- a/noncore/games/solitaire/canvasshapes.cpp +++ b/noncore/games/solitaire/canvasshapes.cpp | |||
@@ -1,92 +1,114 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include <qpainter.h> | 20 | #include <qpainter.h> |
21 | #include <qcanvas.h> | 21 | #include <qcanvas.h> |
22 | #include <qgfx_qws.h> | ||
22 | #include "canvasshapes.h" | 23 | #include "canvasshapes.h" |
23 | 24 | ||
24 | 25 | ||
25 | CanvasRoundRect::CanvasRoundRect(int x, int y, QCanvas *canvas) : | 26 | CanvasRoundRect::CanvasRoundRect(int x, int y, QCanvas *canvas) : |
26 | QCanvasRectangle( x, y, 23, 36, canvas) | 27 | QCanvasRectangle( x, y, ( qt_screen->deviceWidth() < 200 ) ? 20 : 23, ( qt_screen->deviceWidth() < 200 ) ? 27 : 36, canvas) |
27 | { | 28 | { |
28 | setZ(0); | 29 | setZ(0); |
29 | show(); | 30 | show(); |
30 | } | 31 | } |
31 | 32 | ||
32 | 33 | ||
33 | void CanvasRoundRect::redraw() | 34 | void CanvasRoundRect::redraw() |
34 | { | 35 | { |
35 | hide(); | 36 | hide(); |
36 | show(); | 37 | show(); |
37 | } | 38 | } |
38 | 39 | ||
39 | 40 | ||
40 | void CanvasRoundRect::drawShape(QPainter &p) | 41 | void CanvasRoundRect::drawShape(QPainter &p) |
41 | { | 42 | { |
42 | p.drawRoundRect( (int)x(), (int)y(), 23, 36); | 43 | if ( qt_screen->deviceWidth() < 200 ) |
44 | p.drawRoundRect( (int)x() + 1, (int)y() + 1, 18, 25); | ||
45 | else | ||
46 | p.drawRoundRect( (int)x(), (int)y(), 23, 36); | ||
43 | } | 47 | } |
44 | 48 | ||
45 | 49 | ||
46 | CanvasCircleOrCross::CanvasCircleOrCross(int x, int y, QCanvas *canvas) : | 50 | CanvasCircleOrCross::CanvasCircleOrCross(int x, int y, QCanvas *canvas) : |
47 | QCanvasRectangle( x, y, 21, 21, canvas), circleShape(TRUE) | 51 | QCanvasRectangle( x, y, 21, 21, canvas), circleShape(TRUE) |
48 | { | 52 | { |
49 | show(); | 53 | show(); |
50 | } | 54 | } |
51 | 55 | ||
52 | 56 | ||
53 | void CanvasCircleOrCross::redraw() | 57 | void CanvasCircleOrCross::redraw() |
54 | { | 58 | { |
55 | hide(); | 59 | hide(); |
56 | show(); | 60 | show(); |
57 | } | 61 | } |
58 | 62 | ||
59 | 63 | ||
60 | void CanvasCircleOrCross::setCircle() | 64 | void CanvasCircleOrCross::setCircle() |
61 | { | 65 | { |
62 | circleShape = TRUE; | 66 | circleShape = TRUE; |
63 | redraw(); | 67 | redraw(); |
64 | } | 68 | } |
65 | 69 | ||
66 | 70 | ||
67 | void CanvasCircleOrCross::setCross() | 71 | void CanvasCircleOrCross::setCross() |
68 | { | 72 | { |
69 | circleShape = FALSE; | 73 | circleShape = FALSE; |
70 | redraw(); | 74 | redraw(); |
71 | } | 75 | } |
72 | 76 | ||
73 | 77 | ||
74 | void CanvasCircleOrCross::drawShape(QPainter &p) | 78 | void CanvasCircleOrCross::drawShape(QPainter &p) |
75 | { | 79 | { |
76 | int x1 = (int)x(), y1 = (int)y(); | 80 | if ( qt_screen->deviceWidth() < 200 ) { |
77 | // Green circle | 81 | int x1 = (int)x(), y1 = (int)y(); |
78 | if (circleShape == TRUE) { | 82 | // Green circle |
79 | p.setPen( QPen( QColor(0x10, 0xE0, 0x10), 1 ) ); | 83 | if (circleShape == TRUE) { |
80 | p.drawEllipse( x1 - 1, y1 - 1, 21, 21); | 84 | p.setPen( QPen( QColor(0x10, 0xE0, 0x10), 1 ) ); |
81 | p.drawEllipse( x1 - 1, y1 - 0, 21, 19); | 85 | p.drawEllipse( x1 - 1, y1 - 1, 17, 17); |
82 | p.drawEllipse( x1 + 0, y1 + 0, 19, 19); | 86 | p.drawEllipse( x1 - 1, y1 - 0, 17, 15); |
83 | p.drawEllipse( x1 + 1, y1 + 0, 17, 19); | 87 | p.drawEllipse( x1 + 0, y1 + 0, 15, 15); |
84 | p.drawEllipse( x1 + 1, y1 + 1, 17, 17); | 88 | p.drawEllipse( x1 + 1, y1 + 0, 13, 15); |
85 | // Red cross | 89 | p.drawEllipse( x1 + 1, y1 + 1, 13, 13); |
90 | // Red cross | ||
91 | } else { | ||
92 | p.setPen( QPen( QColor(0xE0, 0x10, 0x10), 4 ) ); | ||
93 | p.drawLine( x1, y1, x1 + 14, y1 + 14); | ||
94 | p.drawLine( x1 + 14, y1, x1, y1 + 14); | ||
95 | } | ||
86 | } else { | 96 | } else { |
87 | p.setPen( QPen( QColor(0xE0, 0x10, 0x10), 5 ) ); | 97 | int x1 = (int)x(), y1 = (int)y(); |
88 | p.drawLine( x1, y1, x1 + 20, y1 + 20); | 98 | // Green circle |
89 | p.drawLine( x1 + 20, y1, x1, y1 + 20); | 99 | if (circleShape == TRUE) { |
100 | p.setPen( QPen( QColor(0x10, 0xE0, 0x10), 1 ) ); | ||
101 | p.drawEllipse( x1 - 1, y1 - 1, 21, 21); | ||
102 | p.drawEllipse( x1 - 1, y1 - 0, 21, 19); | ||
103 | p.drawEllipse( x1 + 0, y1 + 0, 19, 19); | ||
104 | p.drawEllipse( x1 + 1, y1 + 0, 17, 19); | ||
105 | p.drawEllipse( x1 + 1, y1 + 1, 17, 17); | ||
106 | // Red cross | ||
107 | } else { | ||
108 | p.setPen( QPen( QColor(0xE0, 0x10, 0x10), 5 ) ); | ||
109 | p.drawLine( x1, y1, x1 + 20, y1 + 20); | ||
110 | p.drawLine( x1 + 20, y1, x1, y1 + 20); | ||
111 | } | ||
90 | } | 112 | } |
91 | } | 113 | } |
92 | 114 | ||
diff --git a/noncore/games/solitaire/freecellcardgame.cpp b/noncore/games/solitaire/freecellcardgame.cpp index e82afd4..98415aa 100644 --- a/noncore/games/solitaire/freecellcardgame.cpp +++ b/noncore/games/solitaire/freecellcardgame.cpp | |||
@@ -1,65 +1,70 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include <qgfx_qws.h> | ||
20 | #include "freecellcardgame.h" | 21 | #include "freecellcardgame.h" |
21 | 22 | ||
22 | 23 | ||
23 | extern int highestZ; | 24 | extern int highestZ; |
24 | int numberOfFreeCells = 4; | 25 | int numberOfFreeCells = 4; |
25 | 26 | ||
26 | 27 | ||
27 | FreecellCardGame::FreecellCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent) | 28 | FreecellCardGame::FreecellCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent) |
28 | { | 29 | { |
29 | numberOfFreeCells = 4; | 30 | numberOfFreeCells = 4; |
30 | highestZ = 0; | 31 | highestZ = 0; |
31 | 32 | ||
33 | int spaceBetweenPiles = ( qt_screen->deviceWidth() < 200 ) ? 21 : 28; | ||
34 | int xOrigin = ( qt_screen->deviceWidth() < 200 ) ? 0 : 5; | ||
35 | int spacing = ( qt_screen->deviceWidth() < 200 ) ? 0 : 0; | ||
36 | |||
32 | for (int i = 0; i < 4; i++) { | 37 | for (int i = 0; i < 4; i++) { |
33 | freecellPiles[i] = new FreecellFreecellPile( 5 + i * 28, 10, canvas() ); | 38 | freecellPiles[i] = new FreecellFreecellPile( xOrigin + i * spaceBetweenPiles, 10, canvas() ); |
34 | addCardPile(freecellPiles[i]); | 39 | addCardPile(freecellPiles[i]); |
35 | } | 40 | } |
36 | for (int i = 0; i < 4; i++) { | 41 | for (int i = 0; i < 4; i++) { |
37 | discardPiles[i] = new FreecellDiscardPile( 125 + i * 28, 10, canvas() ); | 42 | discardPiles[i] = new FreecellDiscardPile( xOrigin + spacing + 6 + (i + 4) * spaceBetweenPiles, 10, canvas() ); |
38 | addCardPile(discardPiles[i]); | 43 | addCardPile(discardPiles[i]); |
39 | } | 44 | } |
40 | for (int i = 0; i < 8; i++) { | 45 | for (int i = 0; i < 8; i++) { |
41 | workingPiles[i] = new FreecellWorkingPile( 10 + i * 28, 50, canvas() ); | 46 | workingPiles[i] = new FreecellWorkingPile( xOrigin + spacing + 2 + i * spaceBetweenPiles, 50, canvas() ); |
42 | addCardPile(workingPiles[i]); | 47 | addCardPile(workingPiles[i]); |
43 | } | 48 | } |
44 | } | 49 | } |
45 | 50 | ||
46 | 51 | ||
47 | void FreecellCardGame::deal(void) | 52 | void FreecellCardGame::deal(void) |
48 | { | 53 | { |
49 | highestZ = 1; | 54 | highestZ = 1; |
50 | 55 | ||
51 | beginDealing(); | 56 | beginDealing(); |
52 | 57 | ||
53 | for (int i = 0; i < 52; i++) { | 58 | for (int i = 0; i < 52; i++) { |
54 | Card *card = cards[i]; | 59 | Card *card = cards[i]; |
55 | card->setFace( TRUE ); | 60 | card->setFace( TRUE ); |
56 | card->setPos( 0, 0, highestZ ); | 61 | card->setPos( 0, 0, highestZ ); |
57 | card->setCardPile( workingPiles[i%8] ); | 62 | card->setCardPile( workingPiles[i%8] ); |
58 | workingPiles[i%8]->addCardToTop( card ); | 63 | workingPiles[i%8]->addCardToTop( card ); |
59 | card->move( workingPiles[i%8]->getCardPos( card ) ); | 64 | card->move( workingPiles[i%8]->getCardPos( card ) ); |
60 | card->showCard(); | 65 | card->showCard(); |
61 | highestZ++; | 66 | highestZ++; |
62 | } | 67 | } |
63 | 68 | ||
64 | endDealing(); | 69 | endDealing(); |
65 | } | 70 | } |
diff --git a/noncore/games/solitaire/patiencecardgame.cpp b/noncore/games/solitaire/patiencecardgame.cpp index 5a9326a..1501d2f 100644 --- a/noncore/games/solitaire/patiencecardgame.cpp +++ b/noncore/games/solitaire/patiencecardgame.cpp | |||
@@ -1,67 +1,84 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include <qgfx_qws.h> | ||
20 | #include "patiencecardgame.h" | 21 | #include "patiencecardgame.h" |
21 | 22 | ||
22 | 23 | ||
23 | int highestZ = 0; | 24 | int highestZ = 0; |
24 | 25 | ||
25 | 26 | ||
26 | PatienceCardGame::PatienceCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent) | 27 | PatienceCardGame::PatienceCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent) |
27 | { | 28 | { |
28 | numberOfTimesThroughDeck = 0; | 29 | numberOfTimesThroughDeck = 0; |
29 | highestZ = 0; | 30 | highestZ = 0; |
30 | 31 | ||
31 | circleCross = new CanvasCircleOrCross( 7, 18, canvas() ); | 32 | if ( qt_screen->deviceWidth() < 200 ) { |
32 | rectangle = new CanvasRoundRect( 35, 10, canvas() ); | 33 | circleCross = new CanvasCircleOrCross( 7, 16, canvas() ); |
34 | rectangle = new CanvasRoundRect( 30, 10, canvas() ); | ||
33 | 35 | ||
34 | for (int i = 0; i < 4; i++) { | 36 | for (int i = 0; i < 4; i++) { |
35 | discardPiles[i] = new PatienceDiscardPile( 110 + i * 30, 10, canvas() ); | 37 | discardPiles[i] = new PatienceDiscardPile( 78 + i * 23, 10, canvas() ); |
36 | addCardPile(discardPiles[i]); | 38 | addCardPile(discardPiles[i]); |
37 | } | 39 | } |
38 | for (int i = 0; i < 7; i++) { | 40 | for (int i = 0; i < 7; i++) { |
39 | workingPiles[i] = new PatienceWorkingPile( 10 + i * 30, 50, canvas() ); | 41 | workingPiles[i] = new PatienceWorkingPile( 5 + i * 23, 50, canvas() ); |
40 | addCardPile(workingPiles[i]); | 42 | addCardPile(workingPiles[i]); |
43 | } | ||
44 | faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() ); | ||
45 | faceUpDealingPile = new PatienceFaceUpDeck( 30, 10, canvas() ); | ||
46 | } else { | ||
47 | circleCross = new CanvasCircleOrCross( 7, 18, canvas() ); | ||
48 | rectangle = new CanvasRoundRect( 35, 10, canvas() ); | ||
49 | |||
50 | for (int i = 0; i < 4; i++) { | ||
51 | discardPiles[i] = new PatienceDiscardPile( 110 + i * 30, 10, canvas() ); | ||
52 | addCardPile(discardPiles[i]); | ||
53 | } | ||
54 | for (int i = 0; i < 7; i++) { | ||
55 | workingPiles[i] = new PatienceWorkingPile( 10 + i * 30, 50, canvas() ); | ||
56 | addCardPile(workingPiles[i]); | ||
57 | } | ||
58 | faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() ); | ||
59 | faceUpDealingPile = new PatienceFaceUpDeck( 35, 10, canvas() ); | ||
41 | } | 60 | } |
42 | faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() ); | ||
43 | faceUpDealingPile = new PatienceFaceUpDeck( 35, 10, canvas() ); | ||
44 | } | 61 | } |
45 | 62 | ||
46 | 63 | ||
47 | PatienceCardGame::~PatienceCardGame() | 64 | PatienceCardGame::~PatienceCardGame() |
48 | { | 65 | { |
49 | delete circleCross; | 66 | delete circleCross; |
50 | delete rectangle; | 67 | delete rectangle; |
51 | delete faceDownDealingPile; | 68 | delete faceDownDealingPile; |
52 | delete faceUpDealingPile; | 69 | delete faceUpDealingPile; |
53 | } | 70 | } |
54 | 71 | ||
55 | 72 | ||
56 | void PatienceCardGame::deal(void) | 73 | void PatienceCardGame::deal(void) |
57 | { | 74 | { |
58 | highestZ = 1; | 75 | highestZ = 1; |
59 | int t = 0; | 76 | int t = 0; |
60 | 77 | ||
61 | beginDealing(); | 78 | beginDealing(); |
62 | 79 | ||
63 | for (int i = 0; i < 7; i++) { | 80 | for (int i = 0; i < 7; i++) { |
64 | cards[t]->setFace(TRUE); | 81 | cards[t]->setFace(TRUE); |
65 | for (int k = i; k < 7; k++, t++) { | 82 | for (int k = i; k < 7; k++, t++) { |
66 | Card *card = cards[t]; | 83 | Card *card = cards[t]; |
67 | workingPiles[k]->addCardToTop(card); | 84 | workingPiles[k]->addCardToTop(card); |
@@ -152,71 +169,77 @@ void PatienceCardGame::writeConfig( Config& cfg ) | |||
152 | pile.sprintf( "DiscardPile%i", i ); | 169 | pile.sprintf( "DiscardPile%i", i ); |
153 | discardPiles[i]->writeConfig( cfg, pile ); | 170 | discardPiles[i]->writeConfig( cfg, pile ); |
154 | } | 171 | } |
155 | faceDownDealingPile->writeConfig( cfg, "FaceDownDealingPile" ); | 172 | faceDownDealingPile->writeConfig( cfg, "FaceDownDealingPile" ); |
156 | faceUpDealingPile->writeConfig( cfg, "FaceUpDealingPile" ); | 173 | faceUpDealingPile->writeConfig( cfg, "FaceUpDealingPile" ); |
157 | } | 174 | } |
158 | 175 | ||
159 | 176 | ||
160 | bool PatienceCardGame::mousePressCard( Card *card, QPoint p ) | 177 | bool PatienceCardGame::mousePressCard( Card *card, QPoint p ) |
161 | { | 178 | { |
162 | Q_UNUSED(p); | 179 | Q_UNUSED(p); |
163 | 180 | ||
164 | CanvasCard *item = (CanvasCard *)card; | 181 | CanvasCard *item = (CanvasCard *)card; |
165 | if (item->isFacing() != TRUE) { | 182 | if (item->isFacing() != TRUE) { |
166 | // From facedown stack | 183 | // From facedown stack |
167 | if ((item->x() == 5) && ((int)item->y() == 10)) { | 184 | if ((item->x() == 5) && ((int)item->y() == 10)) { |
168 | item->setZ(highestZ); | 185 | item->setZ(highestZ); |
169 | highestZ++; | 186 | highestZ++; |
170 | 187 | ||
171 | // Added Code | 188 | // Added Code |
172 | faceDownDealingPile->removeCard(item); | 189 | faceDownDealingPile->removeCard(item); |
173 | faceUpDealingPile->addCardToTop(item); | 190 | faceUpDealingPile->addCardToTop(item); |
174 | item->setCardPile( faceUpDealingPile ); | 191 | item->setCardPile( faceUpDealingPile ); |
175 | 192 | ||
176 | item->flipTo( 35, (int)item->y() ); | 193 | if ( qt_screen->deviceWidth() < 200 ) |
194 | item->flipTo( 30, (int)item->y() ); | ||
195 | else | ||
196 | item->flipTo( 35, (int)item->y() ); | ||
177 | } | 197 | } |
178 | moving = NULL; | 198 | moving = NULL; |
179 | moved = FALSE; | 199 | moved = FALSE; |
180 | 200 | ||
181 | // move two other cards if we flip three at a time | 201 | // move two other cards if we flip three at a time |
182 | int flipped = 1; | 202 | int flipped = 1; |
183 | QCanvasItemList l = canvas()->collisions( p ); | 203 | QCanvasItemList l = canvas()->collisions( p ); |
184 | for (QCanvasItemList::Iterator it = l.begin(); (it != l.end()) && (flipped != cardsDrawn()); ++it) { | 204 | for (QCanvasItemList::Iterator it = l.begin(); (it != l.end()) && (flipped != cardsDrawn()); ++it) { |
185 | if ( (*it)->rtti() == canvasCardId ) { | 205 | if ( (*it)->rtti() == canvasCardId ) { |
186 | CanvasCard *item = (CanvasCard *)*it; | 206 | CanvasCard *item = (CanvasCard *)*it; |
187 | if (item->animated()) | 207 | if (item->animated()) |
188 | continue; | 208 | continue; |
189 | item->setZ(highestZ); | 209 | item->setZ(highestZ); |
190 | highestZ++; | 210 | highestZ++; |
191 | flipped++; | 211 | flipped++; |
192 | 212 | ||
193 | // Added Code | 213 | // Added Code |
194 | faceDownDealingPile->removeCard(item); | 214 | faceDownDealingPile->removeCard(item); |
195 | faceUpDealingPile->addCardToTop(item); | 215 | faceUpDealingPile->addCardToTop(item); |
196 | item->setCardPile( faceUpDealingPile ); | 216 | item->setCardPile( faceUpDealingPile ); |
197 | 217 | ||
198 | item->flipTo( 35, (int)item->y(), 8 * flipped ); | 218 | if ( qt_screen->deviceWidth() < 200 ) |
219 | item->flipTo( 30, (int)item->y(), 8 * flipped ); | ||
220 | else | ||
221 | item->flipTo( 35, (int)item->y(), 8 * flipped ); | ||
199 | } | 222 | } |
200 | } | 223 | } |
201 | 224 | ||
202 | return TRUE; | 225 | return TRUE; |
203 | } | 226 | } |
204 | 227 | ||
205 | return FALSE; | 228 | return FALSE; |
206 | } | 229 | } |
207 | 230 | ||
208 | 231 | ||
209 | void PatienceCardGame::mousePress(QPoint p) | 232 | void PatienceCardGame::mousePress(QPoint p) |
210 | { | 233 | { |
211 | if ( canTurnOverDeck() && | 234 | if ( canTurnOverDeck() && |
212 | (p.x() > 5) && (p.x() < 28) && | 235 | (p.x() > 5) && (p.x() < 28) && |
213 | (p.y() > 10) && (p.y() < 46) ) { | 236 | (p.y() > 10) && (p.y() < 46) ) { |
214 | 237 | ||
215 | beginDealing(); | 238 | beginDealing(); |
216 | Card *card = faceUpDealingPile->cardOnTop(); | 239 | Card *card = faceUpDealingPile->cardOnTop(); |
217 | while ( card ) { | 240 | while ( card ) { |
218 | card->setPos( 5, 10, highestZ ); | 241 | card->setPos( 5, 10, highestZ ); |
219 | card->setFace( FALSE ); | 242 | card->setFace( FALSE ); |
220 | faceUpDealingPile->removeCard( card ); | 243 | faceUpDealingPile->removeCard( card ); |
221 | faceDownDealingPile->addCardToTop( card ); | 244 | faceDownDealingPile->addCardToTop( card ); |
222 | card->setCardPile( faceDownDealingPile ); | 245 | card->setCardPile( faceDownDealingPile ); |
diff --git a/noncore/games/solitaire/patiencecardgame.h b/noncore/games/solitaire/patiencecardgame.h index c4f6c48..0d0e3d5 100644 --- a/noncore/games/solitaire/patiencecardgame.h +++ b/noncore/games/solitaire/patiencecardgame.h | |||
@@ -4,48 +4,49 @@ | |||
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #ifndef PATIENCE_CARD_GAME_H | 20 | #ifndef PATIENCE_CARD_GAME_H |
21 | #define PATIENCE_CARD_GAME_H | 21 | #define PATIENCE_CARD_GAME_H |
22 | 22 | ||
23 | 23 | ||
24 | #include <qpopupmenu.h> | 24 | #include <qpopupmenu.h> |
25 | #include <qmainwindow.h> | 25 | #include <qmainwindow.h> |
26 | #include <qintdict.h> | 26 | #include <qintdict.h> |
27 | #include <qcanvas.h> | 27 | #include <qcanvas.h> |
28 | #include <qgfx_qws.h> | ||
28 | // #include "canvascardshapes.h" | 29 | // #include "canvascardshapes.h" |
29 | // #include "canvascard.h" | 30 | // #include "canvascard.h" |
30 | #include "canvascardgame.h" | 31 | #include "canvascardgame.h" |
31 | 32 | ||
32 | 33 | ||
33 | class PatienceFaceDownDeck : public CardPile, public CanvasRoundRect | 34 | class PatienceFaceDownDeck : public CardPile, public CanvasRoundRect |
34 | { | 35 | { |
35 | public: | 36 | public: |
36 | PatienceFaceDownDeck(int x, int y, QCanvas *canvas) | 37 | PatienceFaceDownDeck(int x, int y, QCanvas *canvas) |
37 | : CardPile(x, y), CanvasRoundRect(x, y, canvas) { } | 38 | : CardPile(x, y), CanvasRoundRect(x, y, canvas) { } |
38 | virtual bool isAllowedOnTop(Card *card) { | 39 | virtual bool isAllowedOnTop(Card *card) { |
39 | Q_UNUSED(card); | 40 | Q_UNUSED(card); |
40 | // Need to check it is from the faceUpDealingPile | 41 | // Need to check it is from the faceUpDealingPile |
41 | return TRUE; | 42 | return TRUE; |
42 | } | 43 | } |
43 | virtual bool isAllowedToBeMoved(Card *card) { | 44 | virtual bool isAllowedToBeMoved(Card *card) { |
44 | Q_UNUSED(card); | 45 | Q_UNUSED(card); |
45 | //if ( ( !card->isFacing() ) && ( card == cardOnTop() ) ) | 46 | //if ( ( !card->isFacing() ) && ( card == cardOnTop() ) ) |
46 | if ( card == cardOnTop() ) | 47 | if ( card == cardOnTop() ) |
47 | return TRUE; | 48 | return TRUE; |
48 | return FALSE; | 49 | return FALSE; |
49 | } | 50 | } |
50 | }; | 51 | }; |
51 | 52 | ||
@@ -109,64 +110,66 @@ public: | |||
109 | virtual bool isAllowedToBeMoved(Card *card) { | 110 | virtual bool isAllowedToBeMoved(Card *card) { |
110 | if ( card->isFacing() ) | 111 | if ( card->isFacing() ) |
111 | return TRUE; | 112 | return TRUE; |
112 | return FALSE; | 113 | return FALSE; |
113 | } | 114 | } |
114 | virtual void cardAddedToTop(Card *card) { | 115 | virtual void cardAddedToTop(Card *card) { |
115 | Q_UNUSED(card); | 116 | Q_UNUSED(card); |
116 | top = getCardPos(NULL); | 117 | top = getCardPos(NULL); |
117 | setNextX( top.x() ); | 118 | setNextX( top.x() ); |
118 | setNextY( top.y() ); | 119 | setNextY( top.y() ); |
119 | } | 120 | } |
120 | virtual void cardRemoved(Card *card) { | 121 | virtual void cardRemoved(Card *card) { |
121 | Q_UNUSED(card); | 122 | Q_UNUSED(card); |
122 | 123 | ||
123 | Card *newTopCard = cardOnTop(); | 124 | Card *newTopCard = cardOnTop(); |
124 | 125 | ||
125 | if ( !newTopCard ) { | 126 | if ( !newTopCard ) { |
126 | top = QPoint( pileX, pileY ); | 127 | top = QPoint( pileX, pileY ); |
127 | setNextX( pileX ); | 128 | setNextX( pileX ); |
128 | setNextY( pileY ); | 129 | setNextY( pileY ); |
129 | return; | 130 | return; |
130 | } else { | 131 | } else { |
131 | top = getCardPos(NULL); | 132 | top = getCardPos(NULL); |
132 | if ( newTopCard->isFacing() == FALSE ) { | 133 | if ( newTopCard->isFacing() == FALSE ) { |
134 | int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13; | ||
133 | // correct the position taking in to account the card is not | 135 | // correct the position taking in to account the card is not |
134 | // yet flipped, but will become flipped | 136 | // yet flipped, but will become flipped |
135 | top = QPoint( top.x() - 1, top.y() - 3 ); | 137 | top = QPoint( top.x() - 1, top.y() - 3 ); |
136 | newTopCard->flipTo( top.x(), top.y() ); | 138 | newTopCard->flipTo( top.x(), top.y() ); |
137 | top = QPoint( top.x(), top.y() + 13 ); | 139 | top = QPoint( top.x(), top.y() + offsetDown ); |
138 | } | 140 | } |
139 | setNextX( top.x() ); | 141 | setNextX( top.x() ); |
140 | setNextY( top.y() ); | 142 | setNextY( top.y() ); |
141 | } | 143 | } |
142 | } | 144 | } |
143 | virtual QPoint getCardPos(Card *c) { | 145 | virtual QPoint getCardPos(Card *c) { |
144 | int x = pileX, y = pileY; | 146 | int x = pileX, y = pileY; |
145 | Card *card = cardOnBottom(); | 147 | Card *card = cardOnBottom(); |
146 | while ((card != c) && (card != NULL)) { | 148 | while ((card != c) && (card != NULL)) { |
147 | if (card->isFacing()) { | 149 | if (card->isFacing()) { |
148 | y += 13; | 150 | int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13; |
151 | y += offsetDown; | ||
149 | } else { | 152 | } else { |
150 | x += 1; | 153 | x += 1; |
151 | y += 3; | 154 | y += 3; |
152 | } | 155 | } |
153 | card = cardInfront(card); | 156 | card = cardInfront(card); |
154 | } | 157 | } |
155 | return QPoint( x, y ); | 158 | return QPoint( x, y ); |
156 | } | 159 | } |
157 | virtual QPoint getHypertheticalNextCardPos(void) { | 160 | virtual QPoint getHypertheticalNextCardPos(void) { |
158 | return top; | 161 | return top; |
159 | // return QPoint( getNextX(), getNextY() ); | 162 | // return QPoint( getNextX(), getNextY() ); |
160 | } | 163 | } |
161 | private: | 164 | private: |
162 | QPoint top; | 165 | QPoint top; |
163 | 166 | ||
164 | }; | 167 | }; |
165 | 168 | ||
166 | 169 | ||
167 | class PatienceCardGame : public CanvasCardGame | 170 | class PatienceCardGame : public CanvasCardGame |
168 | { | 171 | { |
169 | public: | 172 | public: |
170 | PatienceCardGame(QCanvas *c, bool snap, QWidget *parent = 0); | 173 | PatienceCardGame(QCanvas *c, bool snap, QWidget *parent = 0); |
171 | virtual ~PatienceCardGame(); | 174 | virtual ~PatienceCardGame(); |
172 | virtual void deal(void); | 175 | virtual void deal(void); |
diff --git a/noncore/games/wordgame/wordgame.cpp b/noncore/games/wordgame/wordgame.cpp index ca4352d..16d37b3 100644 --- a/noncore/games/wordgame/wordgame.cpp +++ b/noncore/games/wordgame/wordgame.cpp | |||
@@ -38,48 +38,55 @@ | |||
38 | #include <qlabel.h> | 38 | #include <qlabel.h> |
39 | #include <qlineedit.h> | 39 | #include <qlineedit.h> |
40 | #include <qpushbutton.h> | 40 | #include <qpushbutton.h> |
41 | #include <qtextstream.h> | 41 | #include <qtextstream.h> |
42 | #include <qtimer.h> | 42 | #include <qtimer.h> |
43 | #include <qpe/qpetoolbar.h> | 43 | #include <qpe/qpetoolbar.h> |
44 | #include <qtoolbutton.h> | 44 | #include <qtoolbutton.h> |
45 | #include <qvbox.h> | 45 | #include <qvbox.h> |
46 | #include <qwidgetstack.h> | 46 | #include <qwidgetstack.h> |
47 | #include <qpainter.h> | 47 | #include <qpainter.h> |
48 | #include <qlayout.h> | 48 | #include <qlayout.h> |
49 | #include <qregexp.h> | 49 | #include <qregexp.h> |
50 | 50 | ||
51 | #include <stdlib.h> | 51 | #include <stdlib.h> |
52 | #include <unistd.h> | 52 | #include <unistd.h> |
53 | #include <pwd.h> | 53 | #include <pwd.h> |
54 | #include <sys/types.h> | 54 | #include <sys/types.h> |
55 | 55 | ||
56 | enum RuleEffects { | 56 | enum RuleEffects { |
57 | Multiplier=15, | 57 | Multiplier=15, |
58 | MultiplyAll=64, | 58 | MultiplyAll=64, |
59 | Start=128 | 59 | Start=128 |
60 | }; | 60 | }; |
61 | 61 | ||
62 | static int tile_smallw = 16; | ||
63 | static int tile_smallh = 16; | ||
64 | static int tile_bigw = 22; | ||
65 | static int tile_bigh = 22; | ||
66 | static int tile_stweak = -2; | ||
67 | static int tile_btweak = -1; | ||
68 | |||
62 | static const int rack_tiles=7; | 69 | static const int rack_tiles=7; |
63 | 70 | ||
64 | const char* sampleWGR= | 71 | const char* sampleWGR= |
65 | "wordgame_shapes\n" | 72 | "wordgame_shapes\n" |
66 | "15 15\n" | 73 | "15 15\n" |
67 | "400001040100004\n" | 74 | "400001040100004\n" |
68 | "030000000000030\n" | 75 | "030000000000030\n" |
69 | "002002000200200\n" | 76 | "002002000200200\n" |
70 | "000300020003000\n" | 77 | "000300020003000\n" |
71 | "000020000020000\n" | 78 | "000020000020000\n" |
72 | "102001000100201\n" | 79 | "102001000100201\n" |
73 | "000000202000000\n" | 80 | "000000202000000\n" |
74 | "400200050002004\n" | 81 | "400200050002004\n" |
75 | "000000202000000\n" | 82 | "000000202000000\n" |
76 | "102001000100201\n" | 83 | "102001000100201\n" |
77 | "000020000020000\n" | 84 | "000020000020000\n" |
78 | "000300020003000\n" | 85 | "000300020003000\n" |
79 | "002002000200200\n" | 86 | "002002000200200\n" |
80 | "030000000000030\n" | 87 | "030000000000030\n" |
81 | "400001040100004\n" | 88 | "400001040100004\n" |
82 | "1 2 3 66 67 194 100 0\n" | 89 | "1 2 3 66 67 194 100 0\n" |
83 | "1 j 8\n" | 90 | "1 j 8\n" |
84 | "1 q 7\n" | 91 | "1 q 7\n" |
85 | "1 x 6\n" | 92 | "1 x 6\n" |
@@ -90,48 +97,57 @@ const char* sampleWGR= | |||
90 | "1 f 3\n" | 97 | "1 f 3\n" |
91 | "2 y 3\n" | 98 | "2 y 3\n" |
92 | "2 h 2\n" | 99 | "2 h 2\n" |
93 | "2 b 2\n" | 100 | "2 b 2\n" |
94 | "2 m 2\n" | 101 | "2 m 2\n" |
95 | "3 p 2\n" | 102 | "3 p 2\n" |
96 | "3 g 2\n" | 103 | "3 g 2\n" |
97 | "3 u 2\n" | 104 | "3 u 2\n" |
98 | "4 d 2\n" | 105 | "4 d 2\n" |
99 | "4 c 2\n" | 106 | "4 c 2\n" |
100 | "5 l 1\n" | 107 | "5 l 1\n" |
101 | "5 o 1\n" | 108 | "5 o 1\n" |
102 | "7 t 1\n" | 109 | "7 t 1\n" |
103 | "7 n 1\n" | 110 | "7 n 1\n" |
104 | "7 a 1\n" | 111 | "7 a 1\n" |
105 | "7 r 1\n" | 112 | "7 r 1\n" |
106 | "8 s 1\n" | 113 | "8 s 1\n" |
107 | "8 i 1\n" | 114 | "8 i 1\n" |
108 | "11 e 1\n" | 115 | "11 e 1\n" |
109 | "0\n"; | 116 | "0\n"; |
110 | 117 | ||
111 | WordGame::WordGame( QWidget* parent, const char* name, WFlags fl ) : | 118 | WordGame::WordGame( QWidget* parent, const char* name, WFlags fl ) : |
112 | QMainWindow(parent, name, fl) | 119 | QMainWindow(parent, name, fl) |
113 | { | 120 | { |
121 | if ( qApp->desktop()->width() < 240 ) { | ||
122 | tile_smallw = 10; | ||
123 | tile_smallh = 10; | ||
124 | tile_bigw = 16; | ||
125 | tile_bigh = 16; | ||
126 | tile_stweak = 0; | ||
127 | tile_btweak = 0; | ||
128 | } | ||
129 | |||
114 | setIcon( Resource::loadPixmap( "wordgame" ) ); | 130 | setIcon( Resource::loadPixmap( "wordgame" ) ); |
115 | setCaption( tr("Word Game") ); | 131 | setCaption( tr("Word Game") ); |
116 | 132 | ||
117 | setToolBarsMovable( FALSE ); | 133 | setToolBarsMovable( FALSE ); |
118 | vbox = new QVBox(this); | 134 | vbox = new QVBox(this); |
119 | 135 | ||
120 | setCentralWidget(vbox); | 136 | setCentralWidget(vbox); |
121 | toolbar = new QPEToolBar(this); | 137 | toolbar = new QPEToolBar(this); |
122 | addToolBar(toolbar, Bottom); | 138 | addToolBar(toolbar, Bottom); |
123 | reset = new QToolButton(Resource::loadPixmap("back"), tr("Back"), "", this, SLOT(resetTurn()), toolbar); | 139 | reset = new QToolButton(Resource::loadPixmap("back"), tr("Back"), "", this, SLOT(resetTurn()), toolbar); |
124 | done = new QToolButton(Resource::loadPixmap("done"), tr("Done"), "", this, SLOT(endTurn()), toolbar); | 140 | done = new QToolButton(Resource::loadPixmap("done"), tr("Done"), "", this, SLOT(endTurn()), toolbar); |
125 | scoreinfo = new ScoreInfo(toolbar); | 141 | scoreinfo = new ScoreInfo(toolbar); |
126 | scoreinfo->setFont(QFont("Helvetica",10)); | 142 | scoreinfo->setFont(QFont("Helvetica",10)); |
127 | new QToolButton(Resource::loadPixmap("finish"), tr("Close"), "", this, SLOT(endGame()), toolbar); | 143 | new QToolButton(Resource::loadPixmap("finish"), tr("Close"), "", this, SLOT(endGame()), toolbar); |
128 | toolbar->setStretchableWidget(scoreinfo); | 144 | toolbar->setStretchableWidget(scoreinfo); |
129 | 145 | ||
130 | cpu = 0; | 146 | cpu = 0; |
131 | board = 0; | 147 | board = 0; |
132 | bag = 0; | 148 | bag = 0; |
133 | racks = 0; | 149 | racks = 0; |
134 | 150 | ||
135 | aiheart = new QTimer(this); | 151 | aiheart = new QTimer(this); |
136 | connect(aiheart, SIGNAL(timeout()), this, SLOT(think())); | 152 | connect(aiheart, SIGNAL(timeout()), this, SLOT(think())); |
137 | 153 | ||
@@ -226,98 +242,104 @@ void WordGame::openGameSelector(const QStringList& initnames) | |||
226 | void WordGame::startGame() | 242 | void WordGame::startGame() |
227 | { | 243 | { |
228 | rules = newgame->ruleslist[newgame->rules->currentItem()]; | 244 | rules = newgame->ruleslist[newgame->rules->currentItem()]; |
229 | if ( loadRules(rules) ) { | 245 | if ( loadRules(rules) ) { |
230 | QStringList names; | 246 | QStringList names; |
231 | names.append(newgame->player0->currentText()); | 247 | names.append(newgame->player0->currentText()); |
232 | names.append(newgame->player1->currentText()); | 248 | names.append(newgame->player1->currentText()); |
233 | names.append(newgame->player2->currentText()); | 249 | names.append(newgame->player2->currentText()); |
234 | names.append(newgame->player3->currentText()); | 250 | names.append(newgame->player3->currentText()); |
235 | names.append(newgame->player4->currentText()); | 251 | names.append(newgame->player4->currentText()); |
236 | names.append(newgame->player5->currentText()); | 252 | names.append(newgame->player5->currentText()); |
237 | delete newgame; | 253 | delete newgame; |
238 | startGame(names); | 254 | startGame(names); |
239 | } else { | 255 | } else { |
240 | // error... | 256 | // error... |
241 | delete newgame; | 257 | delete newgame; |
242 | close(); | 258 | close(); |
243 | } | 259 | } |
244 | } | 260 | } |
245 | 261 | ||
246 | void WordGame::startGame(const QStringList& playerlist) | 262 | void WordGame::startGame(const QStringList& playerlist) |
247 | { | 263 | { |
248 | toolbar->show(); | 264 | toolbar->show(); |
249 | racks = new QWidgetStack(vbox); | 265 | racks = new QWidgetStack(vbox); |
266 | racks->setFixedHeight(TileItem::bigHeight()+2); | ||
250 | namelist.clear(); | 267 | namelist.clear(); |
251 | nplayers=0; | 268 | nplayers=0; |
252 | for (QStringList::ConstIterator it=playerlist.begin(); it!=playerlist.end(); ++it) | 269 | for (QStringList::ConstIterator it=playerlist.begin(); it!=playerlist.end(); ++it) |
253 | addPlayer(*it); | 270 | addPlayer(*it); |
254 | scoreinfo->init(namelist); | 271 | scoreinfo->init(namelist); |
255 | 272 | ||
256 | if ( nplayers ) { | 273 | if ( nplayers ) { |
257 | player=0; | 274 | player=0; |
258 | readyRack(player); | 275 | readyRack(player); |
259 | } | 276 | } |
260 | 277 | ||
261 | board->show(); | 278 | board->show(); |
262 | racks->show(); | 279 | racks->show(); |
263 | } | 280 | } |
264 | 281 | ||
265 | bool WordGame::loadRules(const QString &name) | 282 | bool WordGame::loadRules(const QString &name) |
266 | { | 283 | { |
267 | QString filename = Global::applicationFileName( "wordgame", name ); | 284 | QString filename = Global::applicationFileName( "wordgame", name ); |
268 | QFile file( filename ); | 285 | QFile file( filename ); |
269 | if ( !file.open( IO_ReadOnly ) ) | 286 | if ( !file.open( IO_ReadOnly ) ) |
270 | return FALSE; | 287 | return FALSE; |
271 | 288 | ||
272 | QTextStream ts( &file ); | 289 | QTextStream ts( &file ); |
273 | 290 | ||
274 | QString title = name; | 291 | QString title = name; |
275 | title.truncate( title.length() - 6 ); | 292 | title.truncate( title.length() - 6 ); |
276 | setCaption( title ); | 293 | setCaption( title ); |
277 | 294 | ||
278 | QString shapepixmap; | 295 | QString shapepixmap; |
279 | ts >> shapepixmap; | 296 | ts >> shapepixmap; |
280 | int htiles,vtiles; | 297 | int htiles,vtiles; |
281 | ts >> htiles >> vtiles; | 298 | ts >> htiles >> vtiles; |
282 | 299 | ||
283 | if ( htiles < 3 || vtiles < 3 ) | 300 | if ( htiles < 3 || vtiles < 3 ) |
284 | return FALSE; | 301 | return FALSE; |
285 | 302 | ||
286 | QPixmap bgshapes = Resource::loadPixmap(shapepixmap); | ||
287 | QString rule_shapes; | 303 | QString rule_shapes; |
288 | for (int i=0; i<vtiles; i++) { | 304 | for (int i=0; i<vtiles; i++) { |
289 | QString line; | 305 | QString line; |
290 | ts >> line; | 306 | ts >> line; |
291 | rule_shapes += line; | 307 | rule_shapes += line; |
292 | } | 308 | } |
293 | static int rule_effects[12]; | 309 | static int rule_effects[12]; |
294 | int re=0,e; | 310 | int re=0,e; |
295 | ts >> e; | 311 | ts >> e; |
296 | while ( e && re < 10 ) { | 312 | while ( e && re < 10 ) { |
297 | rule_effects[re] = e; | 313 | rule_effects[re] = e; |
298 | if ( re++ < 10 ) ts >> e; | 314 | if ( re++ < 10 ) ts >> e; |
299 | } | 315 | } |
316 | |||
317 | QImage shim = Resource::loadImage(shapepixmap); | ||
318 | shim = shim.smoothScale((re-1)*TileItem::smallWidth(),TileItem::smallHeight()); | ||
319 | QPixmap bgshapes; | ||
320 | bgshapes.convertFromImage(shim); | ||
321 | |||
300 | rule_effects[re++] = 100; // default bonus | 322 | rule_effects[re++] = 100; // default bonus |
301 | board = new Board(bgshapes, htiles, vtiles, vbox); | 323 | board = new Board(bgshapes, htiles, vtiles, vbox); |
302 | board->setRules(rule_shapes, rule_effects); | 324 | board->setRules(rule_shapes, rule_effects); |
303 | connect(board, SIGNAL(temporaryScore(int)), scoreinfo, SLOT(showTemporaryScore(int))); | 325 | connect(board, SIGNAL(temporaryScore(int)), scoreinfo, SLOT(showTemporaryScore(int))); |
304 | 326 | ||
305 | bag = new Bag; | 327 | bag = new Bag; |
306 | 328 | ||
307 | int count; | 329 | int count; |
308 | ts >> count; | 330 | ts >> count; |
309 | while ( count ) { | 331 | while ( count ) { |
310 | QString text; | 332 | QString text; |
311 | int value; | 333 | int value; |
312 | ts >> text >> value; | 334 | ts >> text >> value; |
313 | if ( text == "_" ) | 335 | if ( text == "_" ) |
314 | text = ""; | 336 | text = ""; |
315 | 337 | ||
316 | Tile t(text, value); | 338 | Tile t(text, value); |
317 | for (int n=count; n--; ) | 339 | for (int n=count; n--; ) |
318 | bag->add(t); | 340 | bag->add(t); |
319 | 341 | ||
320 | ts >> count; | 342 | ts >> count; |
321 | } | 343 | } |
322 | 344 | ||
323 | return TRUE; | 345 | return TRUE; |
@@ -660,131 +682,147 @@ void ComputerPlayer::noteChoice(const Tile** tiles, int n, const QPoint& d, cons | |||
660 | /* | 682 | /* |
661 | if (s>0 || current==QPoint(5,1)){ | 683 | if (s>0 || current==QPoint(5,1)){ |
662 | QString st; | 684 | QString st; |
663 | for ( int i=0; i<n; i++ ) | 685 | for ( int i=0; i<n; i++ ) |
664 | st += tiles[i]->text(); | 686 | st += tiles[i]->text(); |
665 | qDebug("%d,%d: %s (%d) for %d",current.x(),current.y(),st.latin1(),n,s); | 687 | qDebug("%d,%d: %s (%d) for %d",current.x(),current.y(),st.latin1(),n,s); |
666 | } | 688 | } |
667 | */ | 689 | */ |
668 | if ( s > best_score ) { | 690 | if ( s > best_score ) { |
669 | int i; | 691 | int i; |
670 | for ( i=0; i<n; i++ ) | 692 | for ( i=0; i<n; i++ ) |
671 | best[i] = tiles[i]; | 693 | best[i] = tiles[i]; |
672 | for ( i=0; i<blused; i++ ) | 694 | for ( i=0; i<blused; i++ ) |
673 | best_blankvalues[i] = blankvalues[i]; | 695 | best_blankvalues[i] = blankvalues[i]; |
674 | best_n = n; | 696 | best_n = n; |
675 | best_blused = blused; | 697 | best_blused = blused; |
676 | best_score = s; | 698 | best_score = s; |
677 | best_dir = d; | 699 | best_dir = d; |
678 | best_start = current; | 700 | best_start = current; |
679 | } | 701 | } |
680 | } | 702 | } |
681 | 703 | ||
682 | int TileItem::smallWidth() | 704 | int TileItem::smallWidth() |
683 | { | 705 | { |
684 | return 16; | 706 | return tile_smallw; |
685 | } | 707 | } |
686 | 708 | ||
687 | int TileItem::smallHeight() | 709 | int TileItem::smallHeight() |
688 | { | 710 | { |
689 | return 16; | 711 | return tile_smallh; |
690 | } | 712 | } |
691 | 713 | ||
692 | int TileItem::bigWidth() | 714 | int TileItem::bigWidth() |
693 | { | 715 | { |
694 | return 22; | 716 | return tile_bigw; |
695 | } | 717 | } |
696 | 718 | ||
697 | int TileItem::bigHeight() | 719 | int TileItem::bigHeight() |
698 | { | 720 | { |
699 | return 22; | 721 | return tile_bigh; |
700 | } | 722 | } |
701 | 723 | ||
702 | void TileItem::setState( State state ) | 724 | void TileItem::setState( State state ) |
703 | { | 725 | { |
704 | hide(); | 726 | hide(); |
705 | s = state; | 727 | s = state; |
706 | show(); // ### use update() in Qt 3.0 | 728 | show(); // ### use update() in Qt 3.0 |
707 | } | 729 | } |
708 | 730 | ||
709 | void TileItem::setTile(const Tile& tile) | 731 | void TileItem::setTile(const Tile& tile) |
710 | { | 732 | { |
711 | hide(); | 733 | hide(); |
712 | t = tile; | 734 | t = tile; |
713 | show(); // ### use update() in Qt 3.0 | 735 | show(); // ### use update() in Qt 3.0 |
714 | } | 736 | } |
715 | 737 | ||
716 | void TileItem::setBig(bool b) | 738 | void TileItem::setBig(bool b) |
717 | { | 739 | { |
718 | big = b; | 740 | big = b; |
719 | } | 741 | } |
720 | 742 | ||
721 | void TileItem::drawShape(QPainter& p) | 743 | void TileItem::drawShape(QPainter& p) |
722 | { | 744 | { |
723 | static QFont value_font("heletica",8); | 745 | static QFont *value_font=0; |
724 | static QFont big_font("smoothtimes",17); | 746 | static QFont *big_font=0; |
725 | static QFont small_font("smoothtimes",10); | 747 | static QFont *small_font=0; |
748 | if ( !value_font ) { | ||
749 | value_font = new QFont("helvetica",8); | ||
750 | if ( TileItem::bigWidth() < 20 ) { | ||
751 | big_font = new QFont("helvetica",12); | ||
752 | small_font = new QFont("helvetica",8); | ||
753 | } else { | ||
754 | big_font = new QFont("smoothtimes",17); | ||
755 | small_font = new QFont("smoothtimes",10); | ||
756 | } | ||
757 | } | ||
726 | 758 | ||
727 | QRect area(x(),y(),width(),height()); | 759 | QRect area(x(),y(),width(),height()); |
728 | p.setBrush(s == Floating ? yellow/*lightGray*/ : white); | 760 | p.setBrush(s == Floating ? yellow/*lightGray*/ : white); |
729 | p.drawRect(area); | 761 | p.drawRect(area); |
730 | if ( big ) { | 762 | if ( big ) { |
731 | p.setFont(value_font); | 763 | p.setFont(*value_font); |
732 | QString n = QString::number(t.value()); | 764 | QString n = QString::number(t.value()); |
733 | int w = p.fontMetrics().width('1'); | 765 | int w = p.fontMetrics().width('1'); |
734 | int h = p.fontMetrics().height(); | 766 | int h = p.fontMetrics().height(); |
735 | w *= n.length(); | 767 | w *= n.length(); |
736 | QRect valuearea(x()+width()-w-2,y()+height()-h+1,w,h); | 768 | QRect valuearea(x()+width()-w-1,y()+height()-h,w,h); |
737 | p.drawText(valuearea,AlignCenter,n); | 769 | p.drawText(valuearea,AlignCenter,n); |
738 | p.setFont(big_font); | 770 | p.setFont(*big_font); |
739 | area = QRect(x(),y(),width()-2,height()-1); | 771 | area = QRect(x(),y()+tile_btweak,width()-4,height()-1); |
740 | } else { | 772 | } else { |
741 | p.setFont(small_font); | 773 | p.setFont(*small_font); |
742 | area = QRect(x(),y()+2,width(),height()-2); | 774 | area = QRect(x()+1+tile_stweak,y()+1,width(),height()-3); |
743 | } | 775 | } |
744 | if ( t.value() == 0 ) | 776 | if ( t.value() == 0 ) |
745 | p.setPen(darkGray); | 777 | p.setPen(darkGray); |
746 | p.drawText(area,AlignCenter,t.text().upper()); | 778 | p.drawText(area,AlignCenter,t.text().upper()); |
747 | } | 779 | } |
748 | 780 | ||
749 | Board::Board(QPixmap bgshapes, int w, int h, QWidget* parent) : | 781 | Board::Board(QPixmap bgshapes, int w, int h, QWidget* parent) : |
750 | QCanvasView(new QCanvas(bgshapes,w,h, TileItem::smallWidth(), TileItem::smallHeight()), | 782 | QCanvasView(new QCanvas(bgshapes,w,h, TileItem::smallWidth(), TileItem::smallHeight()), |
751 | parent) | 783 | parent) |
752 | { | 784 | { |
785 | setFixedSize(w*TileItem::smallWidth(),h*TileItem::smallHeight()); | ||
753 | grid = new TileItem*[w*h]; | 786 | grid = new TileItem*[w*h]; |
754 | memset(grid,0,w*h*sizeof(TileItem*)); | 787 | memset(grid,0,w*h*sizeof(TileItem*)); |
755 | setFrameStyle(0); | 788 | setFrameStyle(0); |
756 | setHScrollBarMode(AlwaysOff); | 789 | setHScrollBarMode(AlwaysOff); |
757 | setVScrollBarMode(AlwaysOff); | 790 | setVScrollBarMode(AlwaysOff); |
758 | current_rack = 0; | 791 | current_rack = 0; |
759 | shown_n = 0; | 792 | shown_n = 0; |
760 | } | 793 | } |
761 | 794 | ||
762 | Board::~Board() | 795 | Board::~Board() |
763 | { | 796 | { |
764 | delete canvas(); | 797 | delete canvas(); |
765 | } | 798 | } |
766 | 799 | ||
800 | QSize Board::sizeHint() const | ||
801 | { | ||
802 | return QSize(canvas()->width(),canvas()->height()); | ||
803 | } | ||
804 | |||
767 | void Board::writeConfig(Config& cfg) | 805 | void Board::writeConfig(Config& cfg) |
768 | { | 806 | { |
769 | QStringList t; | 807 | QStringList t; |
770 | int n=canvas()->tilesHorizontally()*canvas()->tilesVertically(); | 808 | int n=canvas()->tilesHorizontally()*canvas()->tilesVertically(); |
771 | for (int i=0; i<n; i++) | 809 | for (int i=0; i<n; i++) |
772 | t.append( grid[i] ? grid[i]->tile().key() : QString(".") ); | 810 | t.append( grid[i] ? grid[i]->tile().key() : QString(".") ); |
773 | cfg.writeEntry("Board",t,';'); | 811 | cfg.writeEntry("Board",t,';'); |
774 | } | 812 | } |
775 | 813 | ||
776 | void Board::readConfig(Config& cfg) | 814 | void Board::readConfig(Config& cfg) |
777 | { | 815 | { |
778 | clear(); | 816 | clear(); |
779 | QStringList t = cfg.readListEntry("Board",';'); | 817 | QStringList t = cfg.readListEntry("Board",';'); |
780 | int i=0; | 818 | int i=0; |
781 | int h=canvas()->tilesHorizontally(); | 819 | int h=canvas()->tilesHorizontally(); |
782 | for (QStringList::ConstIterator it=t.begin(); it!=t.end(); ++it) { | 820 | for (QStringList::ConstIterator it=t.begin(); it!=t.end(); ++it) { |
783 | if ( *it != "." ) { | 821 | if ( *it != "." ) { |
784 | QPoint p(i%h,i/h); | 822 | QPoint p(i%h,i/h); |
785 | setTile(p,Tile(*it)); | 823 | setTile(p,Tile(*it)); |
786 | } | 824 | } |
787 | i++; | 825 | i++; |
788 | } | 826 | } |
789 | canvas()->update(); | 827 | canvas()->update(); |
790 | } | 828 | } |
@@ -1160,48 +1198,53 @@ void Board::setTile(const QPoint& p, const Tile& t) | |||
1160 | } | 1198 | } |
1161 | 1199 | ||
1162 | Rack::Rack(int ntiles, QWidget* parent) : QCanvasView( | 1200 | Rack::Rack(int ntiles, QWidget* parent) : QCanvasView( |
1163 | new QCanvas(ntiles*TileItem::bigWidth(),TileItem::bigHeight()), | 1201 | new QCanvas(ntiles*TileItem::bigWidth(),TileItem::bigHeight()), |
1164 | parent), | 1202 | parent), |
1165 | item(ntiles) | 1203 | item(ntiles) |
1166 | { | 1204 | { |
1167 | setLineWidth(1); | 1205 | setLineWidth(1); |
1168 | setFixedHeight(sizeHint().height()); | 1206 | setFixedHeight(sizeHint().height()); |
1169 | n = 0; | 1207 | n = 0; |
1170 | for (int i=0; i<ntiles; i++) | 1208 | for (int i=0; i<ntiles; i++) |
1171 | item[i]=0; | 1209 | item[i]=0; |
1172 | setHScrollBarMode(AlwaysOff); | 1210 | setHScrollBarMode(AlwaysOff); |
1173 | setVScrollBarMode(AlwaysOff); | 1211 | setVScrollBarMode(AlwaysOff); |
1174 | canvas()->setBackgroundColor(gray); | 1212 | canvas()->setBackgroundColor(gray); |
1175 | dragging = 0; | 1213 | dragging = 0; |
1176 | } | 1214 | } |
1177 | 1215 | ||
1178 | Rack::~Rack() | 1216 | Rack::~Rack() |
1179 | { | 1217 | { |
1180 | clear(); | 1218 | clear(); |
1181 | delete canvas(); | 1219 | delete canvas(); |
1182 | } | 1220 | } |
1183 | 1221 | ||
1222 | QSize Rack::sizeHint() const | ||
1223 | { | ||
1224 | return QSize(-1,TileItem::bigHeight()+2); | ||
1225 | } | ||
1226 | |||
1184 | void Rack::clear() | 1227 | void Rack::clear() |
1185 | { | 1228 | { |
1186 | for (int i=0; i<n; i++) | 1229 | for (int i=0; i<n; i++) |
1187 | delete item[i]; | 1230 | delete item[i]; |
1188 | n=0; | 1231 | n=0; |
1189 | } | 1232 | } |
1190 | 1233 | ||
1191 | void Rack::writeConfig(Config& cfg) | 1234 | void Rack::writeConfig(Config& cfg) |
1192 | { | 1235 | { |
1193 | QStringList l; | 1236 | QStringList l; |
1194 | for (int i=0; i<n; i++) | 1237 | for (int i=0; i<n; i++) |
1195 | l.append(tile(i).key()); | 1238 | l.append(tile(i).key()); |
1196 | cfg.writeEntry("Tiles",l,';'); | 1239 | cfg.writeEntry("Tiles",l,';'); |
1197 | } | 1240 | } |
1198 | 1241 | ||
1199 | void Rack::readConfig(Config& cfg) | 1242 | void Rack::readConfig(Config& cfg) |
1200 | { | 1243 | { |
1201 | clear(); | 1244 | clear(); |
1202 | int x=0; | 1245 | int x=0; |
1203 | QStringList l = cfg.readListEntry("Tiles",';'); | 1246 | QStringList l = cfg.readListEntry("Tiles",';'); |
1204 | for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) { | 1247 | for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) { |
1205 | TileItem *i = new TileItem(Tile(*it),TRUE,canvas()); | 1248 | TileItem *i = new TileItem(Tile(*it),TRUE,canvas()); |
1206 | i->move(x++,0); | 1249 | i->move(x++,0); |
1207 | i->show(); | 1250 | i->show(); |
diff --git a/noncore/games/wordgame/wordgame.h b/noncore/games/wordgame/wordgame.h index 0ffa56a..f73c85a 100644 --- a/noncore/games/wordgame/wordgame.h +++ b/noncore/games/wordgame/wordgame.h | |||
@@ -127,48 +127,50 @@ private: | |||
127 | class Rack : public QCanvasView { | 127 | class Rack : public QCanvasView { |
128 | public: | 128 | public: |
129 | Rack(int ntiles, QWidget* parent); | 129 | Rack(int ntiles, QWidget* parent); |
130 | ~Rack(); | 130 | ~Rack(); |
131 | 131 | ||
132 | void readConfig(Config&); | 132 | void readConfig(Config&); |
133 | void writeConfig(Config&); | 133 | void writeConfig(Config&); |
134 | 134 | ||
135 | bool isFull() const { return count()==max(); } | 135 | bool isFull() const { return count()==max(); } |
136 | int max() const { return item.count(); } | 136 | int max() const { return item.count(); } |
137 | int count() const { return n; } | 137 | int count() const { return n; } |
138 | void addTile(const Tile& t); | 138 | void addTile(const Tile& t); |
139 | Tile tile(int i) const { return item[i]->tile(); } | 139 | Tile tile(int i) const { return item[i]->tile(); } |
140 | const Tile* tileRef(int i) const { return &item[i]->tile(); } | 140 | const Tile* tileRef(int i) const { return &item[i]->tile(); } |
141 | void remove(int i); | 141 | void remove(int i); |
142 | void remove(Tile); | 142 | void remove(Tile); |
143 | bool arrangeTiles(const Tile** s, int sn); | 143 | bool arrangeTiles(const Tile** s, int sn); |
144 | void setBlanks(const Tile*); | 144 | void setBlanks(const Tile*); |
145 | 145 | ||
146 | void setPlayerName(const QString& name) { nm = name; } | 146 | void setPlayerName(const QString& name) { nm = name; } |
147 | QString playerName() const { return nm; } | 147 | QString playerName() const { return nm; } |
148 | void setComputerization(int level) { cpu=level; } | 148 | void setComputerization(int level) { cpu=level; } |
149 | bool computerized() const { return cpu>0; } | 149 | bool computerized() const { return cpu>0; } |
150 | 150 | ||
151 | QSize sizeHint() const; | ||
152 | |||
151 | protected: | 153 | protected: |
152 | void resizeEvent(QResizeEvent*e); | 154 | void resizeEvent(QResizeEvent*e); |
153 | void contentsMousePressEvent(QMouseEvent*); | 155 | void contentsMousePressEvent(QMouseEvent*); |
154 | void contentsMouseMoveEvent(QMouseEvent*); | 156 | void contentsMouseMoveEvent(QMouseEvent*); |
155 | void contentsMouseReleaseEvent(QMouseEvent*); | 157 | void contentsMouseReleaseEvent(QMouseEvent*); |
156 | 158 | ||
157 | private: | 159 | private: |
158 | void clear(); | 160 | void clear(); |
159 | void layoutTiles(); | 161 | void layoutTiles(); |
160 | int n; | 162 | int n; |
161 | QArray<TileItem*> item; | 163 | QArray<TileItem*> item; |
162 | int dragging_adj; | 164 | int dragging_adj; |
163 | QPoint dragstart; | 165 | QPoint dragstart; |
164 | QCanvasItem* dragging; | 166 | QCanvasItem* dragging; |
165 | QString nm; | 167 | QString nm; |
166 | int cpu; | 168 | int cpu; |
167 | }; | 169 | }; |
168 | 170 | ||
169 | class Board : public QCanvasView { | 171 | class Board : public QCanvasView { |
170 | Q_OBJECT | 172 | Q_OBJECT |
171 | public: | 173 | public: |
172 | Board(QPixmap bgshapes, int w, int h, QWidget* parent); | 174 | Board(QPixmap bgshapes, int w, int h, QWidget* parent); |
173 | ~Board(); | 175 | ~Board(); |
174 | 176 | ||
@@ -190,48 +192,50 @@ public: | |||
190 | void clear(); | 192 | void clear(); |
191 | void unsetTile(const QPoint& p); | 193 | void unsetTile(const QPoint& p); |
192 | void setTile(const QPoint& p, const Tile& t); | 194 | void setTile(const QPoint& p, const Tile& t); |
193 | 195 | ||
194 | void setTileState(const QPoint& p, TileItem::State s) | 196 | void setTileState(const QPoint& p, TileItem::State s) |
195 | { | 197 | { |
196 | TileItem* it=item(p); | 198 | TileItem* it=item(p); |
197 | if (it) it->setState(s); | 199 | if (it) it->setState(s); |
198 | } | 200 | } |
199 | 201 | ||
200 | void setCurrentRack(Rack*); | 202 | void setCurrentRack(Rack*); |
201 | void resetRack(); | 203 | void resetRack(); |
202 | void finalizeTurn(); | 204 | void finalizeTurn(); |
203 | void showTurn(); | 205 | void showTurn(); |
204 | void scoreTurn(const QPoint& at, int n, const QPoint& d); | 206 | void scoreTurn(const QPoint& at, int n, const QPoint& d); |
205 | bool checkTurn(); | 207 | bool checkTurn(); |
206 | int score(QPoint at, const Tile** tiles, int n, | 208 | int score(QPoint at, const Tile** tiles, int n, |
207 | const Tile* blankvalue, | 209 | const Tile* blankvalue, |
208 | const QPoint& d, bool ignoredict, QStringList* words) const; | 210 | const QPoint& d, bool ignoredict, QStringList* words) const; |
209 | int bonussedValue(const QPoint& at, int base, int& all_mult) const; | 211 | int bonussedValue(const QPoint& at, int base, int& all_mult) const; |
210 | bool isStart(const QPoint& at) const; | 212 | bool isStart(const QPoint& at) const; |
211 | 213 | ||
212 | int turnScore() const { return turn_score; } | 214 | int turnScore() const { return turn_score; } |
213 | 215 | ||
216 | QSize sizeHint() const; | ||
217 | |||
214 | signals: | 218 | signals: |
215 | void temporaryScore(int); | 219 | void temporaryScore(int); |
216 | 220 | ||
217 | protected: | 221 | protected: |
218 | void contentsMousePressEvent(QMouseEvent*); | 222 | void contentsMousePressEvent(QMouseEvent*); |
219 | void contentsMouseMoveEvent(QMouseEvent*); | 223 | void contentsMouseMoveEvent(QMouseEvent*); |
220 | void contentsMouseReleaseEvent(QMouseEvent*); | 224 | void contentsMouseReleaseEvent(QMouseEvent*); |
221 | 225 | ||
222 | private: | 226 | private: |
223 | int idx(const QPoint& p) const | 227 | int idx(const QPoint& p) const |
224 | { return p.x()+p.y()*canvas()->tilesHorizontally(); } | 228 | { return p.x()+p.y()*canvas()->tilesHorizontally(); } |
225 | TileItem*& item(const QPoint& p) const | 229 | TileItem*& item(const QPoint& p) const |
226 | { return grid[idx(p)]; } | 230 | { return grid[idx(p)]; } |
227 | TileItem **grid; | 231 | TileItem **grid; |
228 | QString rule_shape; | 232 | QString rule_shape; |
229 | const int* rule_effect; | 233 | const int* rule_effect; |
230 | int rack_tiles_bonus; | 234 | int rack_tiles_bonus; |
231 | Rack* current_rack; | 235 | Rack* current_rack; |
232 | QPoint boardPos(const QPoint&) const; | 236 | QPoint boardPos(const QPoint&) const; |
233 | QPoint dragstart; | 237 | QPoint dragstart; |
234 | QPoint shown_at; | 238 | QPoint shown_at; |
235 | int shown_n; | 239 | int shown_n; |
236 | QPoint shown_step; | 240 | QPoint shown_step; |
237 | void unshowTurn(); | 241 | void unshowTurn(); |
@@ -310,49 +314,49 @@ private slots: | |||
310 | void endTurn(); | 314 | void endTurn(); |
311 | void resetTurn(); | 315 | void resetTurn(); |
312 | void passTurn(); | 316 | void passTurn(); |
313 | void think(); | 317 | void think(); |
314 | void endGame(); | 318 | void endGame(); |
315 | void startGame(); | 319 | void startGame(); |
316 | 320 | ||
317 | private: | 321 | private: |
318 | void writeConfig(); | 322 | void writeConfig(); |
319 | void readConfig(); | 323 | void readConfig(); |
320 | 324 | ||
321 | void startGame(const QStringList& pnames); | 325 | void startGame(const QStringList& pnames); |
322 | bool mayEndGame(); | 326 | bool mayEndGame(); |
323 | void openGameSelector(const QStringList& initnames); | 327 | void openGameSelector(const QStringList& initnames); |
324 | bool loadRules(const QString& filename); | 328 | bool loadRules(const QString& filename); |
325 | void addPlayer(const QString& name); | 329 | void addPlayer(const QString& name); |
326 | void addPlayer(const QString& name, int cpu); | 330 | void addPlayer(const QString& name, int cpu); |
327 | void nextPlayer(); | 331 | void nextPlayer(); |
328 | bool refillRack(int i); | 332 | bool refillRack(int i); |
329 | void readyRack(int i); | 333 | void readyRack(int i); |
330 | Rack* rack(int i) const; | 334 | Rack* rack(int i) const; |
331 | 335 | ||
332 | QWidgetStack *racks; | 336 | QWidgetStack *racks; |
333 | QToolBar* toolbar; | 337 | QToolBar* toolbar; |
334 | QVBox *vbox; | 338 | QWidget *vbox; |
335 | Board *board; | 339 | Board *board; |
336 | Bag *bag; | 340 | Bag *bag; |
337 | ScoreInfo *scoreinfo; | 341 | ScoreInfo *scoreinfo; |
338 | QToolButton *done; | 342 | QToolButton *done; |
339 | QToolButton *reset; | 343 | QToolButton *reset; |
340 | QTimer* aiheart; | 344 | QTimer* aiheart; |
341 | ComputerPlayer *cpu; | 345 | ComputerPlayer *cpu; |
342 | int player; | 346 | int player; |
343 | int nplayers; | 347 | int nplayers; |
344 | QStringList namelist; | 348 | QStringList namelist; |
345 | bool gameover; | 349 | bool gameover; |
346 | QString rules; | 350 | QString rules; |
347 | NewGame* newgame; | 351 | NewGame* newgame; |
348 | }; | 352 | }; |
349 | 353 | ||
350 | class NewGame : public NewGameBase { | 354 | class NewGame : public NewGameBase { |
351 | Q_OBJECT | 355 | Q_OBJECT |
352 | public: | 356 | public: |
353 | NewGame(QWidget* parent); | 357 | NewGame(QWidget* parent); |
354 | QStringList ruleslist; | 358 | QStringList ruleslist; |
355 | 359 | ||
356 | public slots: | 360 | public slots: |
357 | void updateRuleSets(); | 361 | void updateRuleSets(); |
358 | }; | 362 | }; |