27 files changed, 2978 insertions, 0 deletions
diff --git a/noncore/games/solitaire/.cvsignore b/noncore/games/solitaire/.cvsignore new file mode 100644 index 0000000..edfa921 --- a/dev/null +++ b/noncore/games/solitaire/.cvsignore | |||
@@ -0,0 +1,3 @@ | |||
1 | moc_* | ||
2 | *.moc | ||
3 | Makefile | ||
diff --git a/noncore/games/solitaire/Makefile.in b/noncore/games/solitaire/Makefile.in new file mode 100644 index 0000000..3c50345 --- a/dev/null +++ b/noncore/games/solitaire/Makefile.in | |||
@@ -0,0 +1,235 @@ | |||
1 | ############################################################################# | ||
2 | |||
3 | ####### Compiler, tools and options | ||
4 | |||
5 | CXX =$(SYSCONF_CXX) $(QT_CXX_MT) | ||
6 | CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS) | ||
7 | CC =$(SYSCONF_CC) $(QT_C_MT) | ||
8 | CFLAGS =$(SYSCONF_CFLAGS) | ||
9 | INCPATH =-I$(QPEDIR)/include | ||
10 | LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT) | ||
11 | LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP) | ||
12 | MOC =$(SYSCONF_MOC) | ||
13 | UIC =$(SYSCONF_UIC) | ||
14 | |||
15 | ####### Target | ||
16 | |||
17 | DESTDIR = $(QPEDIR)/bin/ | ||
18 | VER_MAJ = 1 | ||
19 | VER_MIN = 0 | ||
20 | VER_PATCH = 0 | ||
21 | TARGET= patience | ||
22 | TARGET1 = lib$(TARGET).so.$(VER_MAJ) | ||
23 | |||
24 | ####### Files | ||
25 | |||
26 | HEADERS =canvascard.h \ | ||
27 | canvasshapes.h \ | ||
28 | cardgame.h \ | ||
29 | cardgamelayout.h \ | ||
30 | cardpile.h \ | ||
31 | card.h \ | ||
32 | carddeck.h \ | ||
33 | canvascardgame.h \ | ||
34 | freecellcardgame.h \ | ||
35 | patiencecardgame.h \ | ||
36 | canvascardwindow.h | ||
37 | SOURCES =canvascard.cpp \ | ||
38 | canvasshapes.cpp \ | ||
39 | cardgame.cpp \ | ||
40 | cardgamelayout.cpp \ | ||
41 | cardpile.cpp \ | ||
42 | card.cpp \ | ||
43 | carddeck.cpp \ | ||
44 | canvascardgame.cpp \ | ||
45 | freecellcardgame.cpp \ | ||
46 | patiencecardgame.cpp \ | ||
47 | canvascardwindow.cpp \ | ||
48 | main.cpp | ||
49 | OBJECTS =canvascard.o \ | ||
50 | canvasshapes.o \ | ||
51 | cardgame.o \ | ||
52 | cardgamelayout.o \ | ||
53 | cardpile.o \ | ||
54 | card.o \ | ||
55 | carddeck.o \ | ||
56 | canvascardgame.o \ | ||
57 | freecellcardgame.o \ | ||
58 | patiencecardgame.o \ | ||
59 | canvascardwindow.o \ | ||
60 | main.o | ||
61 | INTERFACES = | ||
62 | UICDECLS = | ||
63 | UICIMPLS = | ||
64 | SRCMOC =moc_canvascardwindow.cpp | ||
65 | OBJMOC =moc_canvascardwindow.o | ||
66 | |||
67 | |||
68 | ####### Implicit rules | ||
69 | |||
70 | .SUFFIXES: .cpp .cxx .cc .C .c | ||
71 | |||
72 | .cpp.o: | ||
73 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< | ||
74 | |||
75 | .cxx.o: | ||
76 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< | ||
77 | |||
78 | .cc.o: | ||
79 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< | ||
80 | |||
81 | .C.o: | ||
82 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< | ||
83 | |||
84 | .c.o: | ||
85 | $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $< | ||
86 | |||
87 | ####### Build rules | ||
88 | |||
89 | |||
90 | all: $(DESTDIR)$(TARGET) | ||
91 | |||
92 | $(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS) | ||
93 | $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS) | ||
94 | |||
95 | moc: $(SRCMOC) | ||
96 | |||
97 | tmake: | ||
98 | tmake solitaire.pro | ||
99 | |||
100 | clean: | ||
101 | -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS) | ||
102 | -rm -f *~ core | ||
103 | -rm -f allmoc.cpp | ||
104 | |||
105 | ####### Extension Modules | ||
106 | |||
107 | listpromodules: | ||
108 | @echo | ||
109 | |||
110 | listallmodules: | ||
111 | @echo | ||
112 | |||
113 | listaddonpromodules: | ||
114 | @echo | ||
115 | |||
116 | listaddonentmodules: | ||
117 | @echo | ||
118 | |||
119 | |||
120 | REQUIRES=patience | ||
121 | |||
122 | ####### Sub-libraries | ||
123 | |||
124 | |||
125 | ###### Combined headers | ||
126 | |||
127 | |||
128 | |||
129 | ####### Compile | ||
130 | |||
131 | canvascard.o: canvascard.cpp \ | ||
132 | cardgame.h \ | ||
133 | card.h \ | ||
134 | cardpile.h \ | ||
135 | carddeck.h \ | ||
136 | cardgamelayout.h \ | ||
137 | canvascard.h \ | ||
138 | $(QPEDIR)/include/qpe/resource.h | ||
139 | |||
140 | canvasshapes.o: canvasshapes.cpp \ | ||
141 | canvasshapes.h | ||
142 | |||
143 | cardgame.o: cardgame.cpp \ | ||
144 | cardgame.h \ | ||
145 | card.h \ | ||
146 | cardpile.h \ | ||
147 | carddeck.h \ | ||
148 | cardgamelayout.h | ||
149 | |||
150 | cardgamelayout.o: cardgamelayout.cpp \ | ||
151 | cardgamelayout.h \ | ||
152 | cardpile.h | ||
153 | |||
154 | cardpile.o: cardpile.cpp \ | ||
155 | cardpile.h \ | ||
156 | card.h \ | ||
157 | $(QPEDIR)/include/qpe/config.h | ||
158 | |||
159 | card.o: card.cpp \ | ||
160 | card.h \ | ||
161 | $(QPEDIR)/include/qpe/config.h | ||
162 | |||
163 | carddeck.o: carddeck.cpp \ | ||
164 | card.h \ | ||
165 | carddeck.h | ||
166 | |||
167 | canvascardgame.o: canvascardgame.cpp \ | ||
168 | cardgame.h \ | ||
169 | card.h \ | ||
170 | cardpile.h \ | ||
171 | carddeck.h \ | ||
172 | cardgamelayout.h \ | ||
173 | canvasshapes.h \ | ||
174 | canvascard.h \ | ||
175 | canvascardgame.h \ | ||
176 | $(QPEDIR)/include/qpe/resource.h \ | ||
177 | $(QPEDIR)/include/qpe/config.h \ | ||
178 | $(QPEDIR)/include/qpe/qpemenubar.h | ||
179 | |||
180 | freecellcardgame.o: freecellcardgame.cpp \ | ||
181 | freecellcardgame.h \ | ||
182 | patiencecardgame.h \ | ||
183 | canvascardgame.h \ | ||
184 | cardgame.h \ | ||
185 | card.h \ | ||
186 | cardpile.h \ | ||
187 | carddeck.h \ | ||
188 | cardgamelayout.h \ | ||
189 | canvasshapes.h \ | ||
190 | canvascard.h \ | ||
191 | $(QPEDIR)/include/qpe/resource.h \ | ||
192 | $(QPEDIR)/include/qpe/config.h \ | ||
193 | $(QPEDIR)/include/qpe/qpemenubar.h | ||
194 | |||
195 | patiencecardgame.o: patiencecardgame.cpp \ | ||
196 | patiencecardgame.h \ | ||
197 | canvascardgame.h \ | ||
198 | cardgame.h \ | ||
199 | card.h \ | ||
200 | cardpile.h \ | ||
201 | carddeck.h \ | ||
202 | cardgamelayout.h \ | ||
203 | canvasshapes.h \ | ||
204 | canvascard.h \ | ||
205 | $(QPEDIR)/include/qpe/resource.h \ | ||
206 | $(QPEDIR)/include/qpe/config.h \ | ||
207 | $(QPEDIR)/include/qpe/qpemenubar.h | ||
208 | |||
209 | canvascardwindow.o: canvascardwindow.cpp \ | ||
210 | canvascardwindow.h \ | ||
211 | patiencecardgame.h \ | ||
212 | canvascardgame.h \ | ||
213 | cardgame.h \ | ||
214 | card.h \ | ||
215 | cardpile.h \ | ||
216 | carddeck.h \ | ||
217 | cardgamelayout.h \ | ||
218 | canvasshapes.h \ | ||
219 | canvascard.h \ | ||
220 | $(QPEDIR)/include/qpe/resource.h \ | ||
221 | $(QPEDIR)/include/qpe/config.h \ | ||
222 | $(QPEDIR)/include/qpe/qpemenubar.h \ | ||
223 | freecellcardgame.h | ||
224 | |||
225 | main.o: main.cpp \ | ||
226 | canvascardwindow.h \ | ||
227 | $(QPEDIR)/include/qpe/qpeapplication.h | ||
228 | |||
229 | moc_canvascardwindow.o: moc_canvascardwindow.cpp \ | ||
230 | canvascardwindow.h | ||
231 | |||
232 | moc_canvascardwindow.cpp: canvascardwindow.h | ||
233 | $(MOC) canvascardwindow.h -o moc_canvascardwindow.cpp | ||
234 | |||
235 | |||
diff --git a/noncore/games/solitaire/canvascard.cpp b/noncore/games/solitaire/canvascard.cpp new file mode 100644 index 0000000..ae3c859 --- a/dev/null +++ b/noncore/games/solitaire/canvascard.cpp | |||
@@ -0,0 +1,282 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include "cardgame.h" | ||
22 | #include "canvascard.h" | ||
23 | |||
24 | #include <qpe/resource.h> | ||
25 | |||
26 | #include <qpainter.h> | ||
27 | #include <qimage.h> | ||
28 | #include <qpaintdevice.h> | ||
29 | #include <qbitmap.h> | ||
30 | |||
31 | #include <math.h> | ||
32 | |||
33 | #if defined( QT_QWS_CASSIOPEIA ) | ||
34 | #define SLOW_HARDWARE | ||
35 | #endif | ||
36 | |||
37 | // Seems to be fast enough to me even without Transformations in the library | ||
38 | //#if defined( QT_NO_TRANSFORMATIONS ) && defined( QT_QWS_IPAQ ) | ||
39 | //#define SLOW_HARDWARE | ||
40 | //#endif | ||
41 | |||
42 | |||
43 | QBitmap *Create180RotatedBitmap(QBitmap *srcBitmap) | ||
44 | { | ||
45 | #ifdef QT_NO_TRANSFORMATIONS | ||
46 | int w = srcBitmap->width(); | ||
47 | int h = srcBitmap->height(); | ||
48 | QBitmap *dstBitmap = new QBitmap( w, h ); | ||
49 | // ### this is very poorly implemented and probably could be much faster | ||
50 | for (int i = 0; i < w; i++) | ||
51 | for (int j = 0; j < h; j++) | ||
52 | bitBlt( dstBitmap, i, j, srcBitmap, w - i - 1, h - j - 1, 1, 1 ); | ||
53 | return dstBitmap; | ||
54 | #else | ||
55 | QWMatrix m; | ||
56 | m.rotate( 180.0 ); | ||
57 | return new QBitmap( srcBitmap->xForm( m ) ); | ||
58 | #endif | ||
59 | } | ||
60 | |||
61 | |||
62 | QPixmap *CreateScaledPixmap(QPixmap *srcPixmap, double scaleX, double scaleY) | ||
63 | { | ||
64 | #ifdef QT_NO_TRANSFORMATIONS | ||
65 | int w = srcPixmap->width(); | ||
66 | int h = srcPixmap->height(); | ||
67 | int newW = (int)(w * scaleX); | ||
68 | int newH = (int)(h * scaleY); | ||
69 | QPixmap *dstPixmap = new QPixmap( newW, newH ); | ||
70 | // ### this is very poorly implemented and probably could be much faster | ||
71 | for (int i = 0; i < newW; i++) { | ||
72 | int srcX = w * i / newW; | ||
73 | if (newH == h) { | ||
74 | // Optimise for scaleing in the X-axis only | ||
75 | bitBlt( dstPixmap, i, 0, srcPixmap, srcX, 0, 1, h ); | ||
76 | } else { | ||
77 | for (int j = 0; j < newH; j++) { | ||
78 | int srcY = h * j / newH; | ||
79 | bitBlt( dstPixmap, i, j, srcPixmap, srcX, srcY, 1, 1 ); | ||
80 | } | ||
81 | } | ||
82 | } | ||
83 | return dstPixmap; | ||
84 | #else | ||
85 | QWMatrix s; | ||
86 | s.scale( scaleX, scaleY ); | ||
87 | return new QPixmap( srcPixmap->xForm( s ) ); | ||
88 | #endif | ||
89 | } | ||
90 | |||
91 | |||
92 | // Initialise static member variables to NULL | ||
93 | QPixmap *CanvasCard::cardsFaces = NULL; | ||
94 | QPixmap *CanvasCard::cardsBacks = NULL; | ||
95 | QBitmap *CanvasCard::cardsChars = NULL; | ||
96 | QBitmap *CanvasCard::cardsSuits = NULL; | ||
97 | QBitmap *CanvasCard::cardsCharsUpsideDown = NULL; | ||
98 | QBitmap *CanvasCard::cardsSuitsUpsideDown = NULL; | ||
99 | |||
100 | |||
101 | 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 | { | ||
104 | if ( !cardsFaces ) { | ||
105 | cardsFaces = new QPixmap( Resource::loadPixmap( "cards/card_face" ) ); | ||
106 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001" ) ); | ||
107 | cardsChars = new QBitmap( Resource::loadBitmap( "cards/card_chars" ) ); | ||
108 | cardsSuits = new QBitmap( Resource::loadBitmap( "cards/card_suits" ) ); | ||
109 | cardsCharsUpsideDown = Create180RotatedBitmap( cardsChars ); | ||
110 | cardsSuitsUpsideDown = Create180RotatedBitmap( cardsSuits ); | ||
111 | } | ||
112 | xOff = cardsFaces->width() / 2; | ||
113 | yOff = cardsFaces->height() / 2; | ||
114 | setSize( cardsFaces->width(), cardsFaces->height() ); | ||
115 | setPen( NoPen ); | ||
116 | flipping = FALSE; | ||
117 | } | ||
118 | |||
119 | |||
120 | void CanvasCard::setCardBack(int b) | ||
121 | { | ||
122 | if ( cardBack != b ) { | ||
123 | |||
124 | cardBack = b; | ||
125 | |||
126 | if ( cardsBacks ) | ||
127 | delete cardsBacks; | ||
128 | |||
129 | switch (cardBack) { | ||
130 | case 0: | ||
131 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001" ) ); break; | ||
132 | case 1: | ||
133 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0002" ) ); break; | ||
134 | case 2: | ||
135 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0003" ) ); break; | ||
136 | case 3: | ||
137 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0004" ) ); break; | ||
138 | case 4: | ||
139 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0005" ) ); break; | ||
140 | } | ||
141 | |||
142 | if ( !isFacing() ) | ||
143 | redraw(); | ||
144 | } | ||
145 | } | ||
146 | |||
147 | |||
148 | void CanvasCard::draw(QPainter &painter) | ||
149 | { | ||
150 | int ix = (int)x(), iy = (int)y(); | ||
151 | |||
152 | QPainter *p = &painter; | ||
153 | QPixmap *unscaledCard = NULL; | ||
154 | |||
155 | if ((scaleX <= 0.98) || (scaleY <= 0.98)) | ||
156 | { | ||
157 | p = new QPainter(); | ||
158 | unscaledCard = new QPixmap( cardsFaces->width(), cardsFaces->height() ); | ||
159 | p->begin(unscaledCard); | ||
160 | ix = 0; | ||
161 | iy = 0; | ||
162 | } | ||
163 | |||
164 | if ( isFacing() ) { | ||
165 | |||
166 | /* | ||
167 | // Now add the joker and card backs to the list of pixmaps | ||
168 | QPixmap *CardsBack = new QPixmap( Resource::loadPixmap( "cards/card_joker.png" ) ); | ||
169 | QPoint *newBackHotspot = new QPoint( 0, 0 ); | ||
170 | pixmaps->append((const QPixmap *)CardsBack); | ||
171 | hotspots->append((const QPoint *)newBackHotspot); | ||
172 | */ | ||
173 | |||
174 | int w = cardsFaces->width(), h = cardsFaces->height(); | ||
175 | |||
176 | //p->setBrush( NoBrush ); | ||
177 | p->setBrush( QColor( 0xFF, 0xFF, 0xFF ) ); | ||
178 | |||
179 | if ( isRed() == TRUE ) | ||
180 | p->setPen( QColor( 0xFF, 0, 0 ) ); | ||
181 | else | ||
182 | p->setPen( QColor( 0, 0, 0 ) ); | ||
183 | |||
184 | p->drawPixmap( ix + 0, iy + 0, *cardsFaces ); | ||
185 | p->drawPixmap( ix + 4, iy + 4, *cardsChars, 7*(getValue()-1), 0, 7, 7 ); | ||
186 | p->drawPixmap( ix + 12, iy + 4, *cardsSuits, 7*(getSuit()-1), 0, 7, 8 ); | ||
187 | p->drawPixmap( ix + w-4-7, iy + h-4-7, *cardsCharsUpsideDown, 7*(12-getValue()+1), 0, 7, 7 ); | ||
188 | p->drawPixmap( ix + w-12-7, iy + h-5-7, *cardsSuitsUpsideDown, 7*(3-getSuit()+1), 0, 7, 8 ); | ||
189 | |||
190 | } else { | ||
191 | |||
192 | p->drawPixmap( ix, iy, *cardsBacks ); | ||
193 | |||
194 | } | ||
195 | |||
196 | if (p != &painter) | ||
197 | { | ||
198 | p->end(); | ||
199 | QPixmap *scaledCard = CreateScaledPixmap( unscaledCard, scaleX, scaleY ); | ||
200 | int xoff = scaledCard->width() / 2; | ||
201 | int yoff = scaledCard->height() / 2; | ||
202 | painter.drawPixmap( (int)x() + xOff - xoff, (int)y() + yOff - yoff, *scaledCard ); | ||
203 | delete p; | ||
204 | delete unscaledCard; | ||
205 | delete scaledCard; | ||
206 | } | ||
207 | } | ||
208 | |||
209 | |||
210 | static const double flipLift = 1.5; | ||
211 | |||
212 | |||
213 | void CanvasCard::flipTo(int x2, int y2, int steps) | ||
214 | { | ||
215 | flipSteps = steps; | ||
216 | |||
217 | #ifdef SLOW_HARDWARE | ||
218 | move(x2,y2); | ||
219 | Card::flipTo(x2,y2,steps); | ||
220 | #else | ||
221 | int x1 = (int)x(); | ||
222 | int y1 = (int)y(); | ||
223 | double dx = x2 - x1; | ||
224 | double dy = y2 - y1; | ||
225 | |||
226 | flipping = TRUE; | ||
227 | destX = x2; | ||
228 | destY = y2; | ||
229 | animSteps = flipSteps; | ||
230 | setVelocity(dx/animSteps, dy/animSteps-flipLift); | ||
231 | setAnimated(TRUE); | ||
232 | #endif | ||
233 | } | ||
234 | |||
235 | |||
236 | void CanvasCard::advance(int stage) | ||
237 | { | ||
238 | if ( stage==1 ) { | ||
239 | if ( animSteps-- <= 0 ) { | ||
240 | scaleX = 1.0; | ||
241 | scaleY = 1.0; | ||
242 | flipping = FALSE; | ||
243 | setVelocity(0,0); | ||
244 | setAnimated(FALSE); | ||
245 | move(destX,destY); // exact | ||
246 | } else { | ||
247 | if ( flipping ) { | ||
248 | if ( animSteps > flipSteps / 2 ) { | ||
249 | // animSteps = flipSteps .. flipSteps/2 (flip up) -> 1..0 | ||
250 | scaleX = ((double)animSteps/flipSteps-0.5)*2; | ||
251 | } else { | ||
252 | // animSteps = flipSteps/2 .. 0 (flip down) -> 0..1 | ||
253 | scaleX = 1-((double)animSteps/flipSteps)*2; | ||
254 | } | ||
255 | if ( animSteps == flipSteps / 2-1 ) { | ||
256 | setYVelocity(yVelocity()+flipLift*2); | ||
257 | setFace( !isFacing() ); | ||
258 | } | ||
259 | } | ||
260 | } | ||
261 | } | ||
262 | QCanvasRectangle::advance(stage); | ||
263 | } | ||
264 | |||
265 | |||
266 | void CanvasCard::animatedMove(int x2, int y2, int steps) | ||
267 | { | ||
268 | destX = x2; | ||
269 | destY = y2; | ||
270 | |||
271 | double x1 = x(), y1 = y(), dx = x2 - x1, dy = y2 - y1; | ||
272 | |||
273 | // Ensure a good speed | ||
274 | while ( fabs(dx/steps)+fabs(dy/steps) < 5.0 && steps > 4 ) | ||
275 | steps--; | ||
276 | |||
277 | setAnimated(TRUE); | ||
278 | setVelocity(dx/steps, dy/steps); | ||
279 | |||
280 | animSteps = steps; | ||
281 | } | ||
282 | |||
diff --git a/noncore/games/solitaire/canvascard.h b/noncore/games/solitaire/canvascard.h new file mode 100644 index 0000000..cd9691f --- a/dev/null +++ b/noncore/games/solitaire/canvascard.h | |||
@@ -0,0 +1,82 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #ifndef CANVAS_CARD_H | ||
21 | #define CANVAS_CARD_H | ||
22 | |||
23 | |||
24 | #include <qpainter.h> | ||
25 | #include <qbitmap.h> | ||
26 | #include <qpixmap.h> | ||
27 | #include <qpoint.h> | ||
28 | #include <qcanvas.h> | ||
29 | #include "cardgame.h" | ||
30 | |||
31 | |||
32 | // ### Just made the number up, is that what you do??? | ||
33 | static const int canvasCardId = 2434321; | ||
34 | |||
35 | |||
36 | class CanvasCard : public Card, public QCanvasRectangle | ||
37 | { | ||
38 | public: | ||
39 | CanvasCard( eValue v, eSuit s, bool f, QCanvas *canvas ); | ||
40 | virtual ~CanvasCard() { canvas()->removeItem(this); } | ||
41 | |||
42 | int rtti () const { return canvasCardId; } | ||
43 | void move(QPoint p) { QCanvasItem::move( p.x(), p.y() ); } | ||
44 | void move(int x, int y) { QCanvasItem::move( x, y ); } | ||
45 | void animatedMove(int x, int y, int steps = 10); | ||
46 | void animatedMove() { animatedMove(savedX, savedY); } | ||
47 | void savePos(void) { savedX = (int)x(); savedY = (int)y(); } | ||
48 | void moveToPile(int p) { Q_UNUSED(p); } | ||
49 | void setCardBack(int b); | ||
50 | |||
51 | /*virtual*/ void flipTo(int x, int y, int steps = 8); | ||
52 | /*virtual*/ void setPos( int x, int y, int z ) { setX( x ); setY( y ); setZ( z ); } | ||
53 | /*virtual*/ void showCard(void) { show(); } | ||
54 | /*virtual*/ void redraw(void) { hide(); show(); } | ||
55 | /*virtual*/ void draw(QPainter &p); | ||
56 | |||
57 | void advance(int stage); | ||
58 | |||
59 | protected: | ||
60 | /*virtual*/ void flip(void) { redraw(); } | ||
61 | |||
62 | private: | ||
63 | int destX, destY; | ||
64 | int animSteps; | ||
65 | int flipSteps; | ||
66 | bool flipping; | ||
67 | int savedX, savedY; | ||
68 | int cardBack; | ||
69 | int oldCardBack; | ||
70 | double scaleX, scaleY; | ||
71 | int xOff, yOff; | ||
72 | static QPixmap *cardsFaces; | ||
73 | static QPixmap *cardsBacks; | ||
74 | static QBitmap *cardsChars; | ||
75 | static QBitmap *cardsSuits; | ||
76 | static QBitmap *cardsCharsUpsideDown; | ||
77 | static QBitmap *cardsSuitsUpsideDown; | ||
78 | }; | ||
79 | |||
80 | |||
81 | #endif | ||
82 | |||
diff --git a/noncore/games/solitaire/canvascardgame.cpp b/noncore/games/solitaire/canvascardgame.cpp new file mode 100644 index 0000000..32635a0 --- a/dev/null +++ b/noncore/games/solitaire/canvascardgame.cpp | |||
@@ -0,0 +1,380 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include "cardgame.h" | ||
22 | #include "canvasshapes.h" | ||
23 | #include "canvascard.h" | ||
24 | #include "canvascardgame.h" | ||
25 | |||
26 | #include <qpe/resource.h> | ||
27 | #include <qpe/config.h> | ||
28 | |||
29 | #include <qmainwindow.h> | ||
30 | #include <qpe/qpemenubar.h> | ||
31 | #include <qpainter.h> | ||
32 | |||
33 | #include <stdlib.h> | ||
34 | #include <limits.h> | ||
35 | #include <time.h> | ||
36 | #include <math.h> | ||
37 | |||
38 | |||
39 | extern int highestZ; | ||
40 | |||
41 | |||
42 | class CanvasCardPile : public QCanvasRectangle | ||
43 | { | ||
44 | public: | ||
45 | CanvasCardPile( CanvasCardGame *ccg, QCanvas *canvas ) : QCanvasRectangle( canvas ), parent( ccg ) { | ||
46 | pile = new QPixmap( 0, 0 ); | ||
47 | pileHeight = 0; | ||
48 | firstCard = NULL; | ||
49 | } | ||
50 | |||
51 | void addCard( CanvasCard *card ); | ||
52 | void advance(int stage); | ||
53 | void animatedMove() { animatedMove(savedX, savedY); } | ||
54 | void savePos(void) { savedX = (int)x(); savedY = (int)y(); } | ||
55 | void animatedMove(int x2, int y2, int steps = 7 ); | ||
56 | |||
57 | protected: | ||
58 | virtual void draw( QPainter& p ); | ||
59 | |||
60 | private: | ||
61 | CanvasCardGame *parent; | ||
62 | QPixmap *pile; | ||
63 | QImage tempImage32; | ||
64 | CanvasCard *firstCard; | ||
65 | int pileHeight; | ||
66 | int destX, destY; | ||
67 | int savedX, savedY; | ||
68 | int animSteps; | ||
69 | }; | ||
70 | |||
71 | |||
72 | void CanvasCardPile::addCard( CanvasCard *card ) | ||
73 | { | ||
74 | if ( !firstCard ) | ||
75 | firstCard = card; | ||
76 | |||
77 | int height = 36 + pileHeight * 13; | ||
78 | setSize( 23, height ); | ||
79 | pile->resize( 23, height ); | ||
80 | QPainter p( pile ); | ||
81 | p.translate( -card->x(), -card->y() + pileHeight * 13 ); | ||
82 | card->draw( p ); | ||
83 | pileHeight++; | ||
84 | |||
85 | QImage tempImage; | ||
86 | tempImage = *pile; | ||
87 | tempImage32 = tempImage.convertDepth( 32 ); | ||
88 | tempImage32.setAlphaBuffer( TRUE ); | ||
89 | for ( int i = 0; i < tempImage32.width(); i++ ) | ||
90 | for ( int j = 0; j < tempImage32.height(); j++ ) { | ||
91 | QRgb col = tempImage32.pixel( i, j ); | ||
92 | int a = 255-j*220/tempImage32.height(); | ||
93 | QRgb alpha = qRgba( qRed( col ), qGreen( col ), qBlue( col ), a ); | ||
94 | tempImage32.setPixel( i, j, alpha ); | ||
95 | } | ||
96 | |||
97 | QRgb alpha = qRgba( 0, 0, 0, 0 ); | ||
98 | tempImage32.setPixel( 1, 0, alpha ); | ||
99 | tempImage32.setPixel( 0, 0, alpha ); | ||
100 | tempImage32.setPixel( 0, 1, alpha ); | ||
101 | |||
102 | tempImage32.setPixel( 21, 0, alpha ); | ||
103 | tempImage32.setPixel( 22, 0, alpha ); | ||
104 | tempImage32.setPixel( 22, 1, alpha ); | ||
105 | height--; | ||
106 | tempImage32.setPixel( 1, height, alpha ); | ||
107 | tempImage32.setPixel( 0, height - 1, alpha ); | ||
108 | tempImage32.setPixel( 0, height, alpha ); | ||
109 | |||
110 | tempImage32.setPixel( 21, height, alpha ); | ||
111 | tempImage32.setPixel( 22, height, alpha ); | ||
112 | tempImage32.setPixel( 22, height - 1, alpha ); | ||
113 | } | ||
114 | |||
115 | |||
116 | void CanvasCardPile::advance(int stage) | ||
117 | { | ||
118 | if ( stage==1 ) { | ||
119 | if ( animSteps-- <= 0 ) { | ||
120 | CanvasCard *item = firstCard; | ||
121 | while (item) { | ||
122 | item->show(); | ||
123 | item = (CanvasCard *)item->getCardPile()->cardInfront(item); | ||
124 | } | ||
125 | setVelocity(0,0); | ||
126 | setAnimated(FALSE); | ||
127 | parent->cancelMoving(); | ||
128 | hide(); | ||
129 | move(destX,destY); // exact | ||
130 | } | ||
131 | } | ||
132 | QCanvasRectangle::advance(stage); | ||
133 | } | ||
134 | |||
135 | |||
136 | void CanvasCardPile::animatedMove(int x2, int y2, int steps = 7 ) | ||
137 | { | ||
138 | destX = x2; | ||
139 | destY = y2; | ||
140 | |||
141 | double x1 = x(), y1 = y(), dx = x2 - x1, dy = y2 - y1; | ||
142 | |||
143 | // Ensure a good speed | ||
144 | while ( fabs(dx/steps)+fabs(dy/steps) < 5.0 && steps > 4 ) | ||
145 | steps--; | ||
146 | |||
147 | setAnimated(TRUE); | ||
148 | setVelocity(dx/steps, dy/steps); | ||
149 | |||
150 | animSteps = steps; | ||
151 | } | ||
152 | |||
153 | |||
154 | void CanvasCardPile::draw( QPainter& p ) | ||
155 | { | ||
156 | int ix = (int)x(), iy = (int)y(); | ||
157 | p.drawImage( ix, iy, tempImage32 ); | ||
158 | } | ||
159 | |||
160 | |||
161 | CanvasCardGame::~CanvasCardGame() { | ||
162 | // the deletion stuff should be fixed now and only deletes | ||
163 | // items created by this CardGame. I haven't verified there are zero | ||
164 | // memory leaks yet | ||
165 | if ( alphaCardPile ) | ||
166 | delete alphaCardPile; | ||
167 | } | ||
168 | |||
169 | |||
170 | void CanvasCardGame::gameWon() { | ||
171 | |||
172 | srand(time(NULL)); | ||
173 | |||
174 | QCanvasItemList list = canvas()->allItems(); | ||
175 | QCanvasItemList::Iterator it = list.begin(); | ||
176 | |||
177 | for (; it != list.end(); ++it) { | ||
178 | if ( (*it)->rtti() == canvasCardId ) { | ||
179 | // disperse the cards everywhere | ||
180 | int x = 300 - rand() % 1000; | ||
181 | int y = 300 + rand() % 200; | ||
182 | ((CanvasCard *)*it)->animatedMove( x, y, 50 ); | ||
183 | } | ||
184 | } | ||
185 | } | ||
186 | |||
187 | |||
188 | void CanvasCardGame::contentsMousePressEvent(QMouseEvent *e) { | ||
189 | |||
190 | if ( moving ) | ||
191 | return; | ||
192 | |||
193 | QCanvasItemList l = canvas()->collisions( e->pos() ); | ||
194 | |||
195 | for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) { | ||
196 | |||
197 | if ( (*it)->rtti() == canvasCardId ) { | ||
198 | |||
199 | moving = (CanvasCard *)*it; | ||
200 | |||
201 | if ( moving->animated() ) | ||
202 | return; | ||
203 | |||
204 | cardXOff = (int)(e->pos().x() - moving->x()); | ||
205 | cardYOff = (int)(e->pos().y() - moving->y()); | ||
206 | |||
207 | if ( !mousePressCard( moving, e->pos() ) ) { | ||
208 | CanvasCard *card = moving; | ||
209 | |||
210 | if ( alphaCardPile ) | ||
211 | delete alphaCardPile; | ||
212 | |||
213 | alphaCardPile = new CanvasCardPile( this, canvas() ); | ||
214 | alphaCardPile->move( card->x(), card->y() ); | ||
215 | alphaCardPile->savePos(); | ||
216 | alphaCardPile->show(); | ||
217 | |||
218 | while (card) { | ||
219 | alphaCardPile->addCard( card ); | ||
220 | card->hide(); | ||
221 | card = (CanvasCard *)card->getCardPile()->cardInfront(card); | ||
222 | } | ||
223 | |||
224 | alphaCardPile->setZ( INT_MAX ); | ||
225 | |||
226 | moved = TRUE; | ||
227 | } else { | ||
228 | if ( alphaCardPile ) | ||
229 | alphaCardPile->hide(); | ||
230 | } | ||
231 | return; | ||
232 | } | ||
233 | } | ||
234 | |||
235 | mousePress( e->pos() ); | ||
236 | } | ||
237 | |||
238 | /* | ||
239 | // | ||
240 | // Should have some intelligent way to make double clicking on a | ||
241 | // card send it to the most appropriate pile | ||
242 | // | ||
243 | void CanvasCardGame::contentsMouseDoubleClickEvent(QMouseEvent *e) { | ||
244 | QCanvasItemList l = canvas()->collisions( e->pos() ); | ||
245 | for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) { | ||
246 | if ( (*it)->rtti() == canvasCardId ) { | ||
247 | CanvasCard *card = (CanvasCard *)*it; | ||
248 | |||
249 | if ( card->animated() ) | ||
250 | return; | ||
251 | |||
252 | if ( card->getCardPile()->isAllowedToBeMoved(card) ) { | ||
253 | if (card->getCardPile()->cardInfront(card) == NULL) { | ||
254 | CardPile *pile = first(); | ||
255 | if (pile && pile->isAllowedOnTop(card)) { | ||
256 | // move card to this pile | ||
257 | return; | ||
258 | } | ||
259 | } | ||
260 | } | ||
261 | } | ||
262 | } | ||
263 | } | ||
264 | */ | ||
265 | |||
266 | void CanvasCardGame::contentsMouseMoveEvent(QMouseEvent *e) { | ||
267 | |||
268 | QPoint p = e->pos(); | ||
269 | |||
270 | if ( moving ) { | ||
271 | |||
272 | moved = TRUE; | ||
273 | |||
274 | if (moving->isFacing() != TRUE) | ||
275 | return; | ||
276 | |||
277 | int tx = (int)p.x() - cardXOff; | ||
278 | int ty = (int)p.y() - cardYOff; | ||
279 | |||
280 | if (snapOn == TRUE) { | ||
281 | CardPile *pile = closestPile( tx, ty, 50 ); | ||
282 | if ( pile && pile->isAllowedOnTop( moving ) ) { | ||
283 | QPoint p = pile->getHypertheticalNextCardPos(); | ||
284 | if ( alphaCardPile ) | ||
285 | alphaCardPile->move( p.x(), p.y() ); | ||
286 | return; | ||
287 | } | ||
288 | } | ||
289 | |||
290 | if ( alphaCardPile ) | ||
291 | alphaCardPile->move( tx, ty ); | ||
292 | } | ||
293 | |||
294 | } | ||
295 | |||
296 | |||
297 | void CanvasCardGame::contentsMouseReleaseEvent(QMouseEvent *e) | ||
298 | { | ||
299 | QPoint p = e->pos(); | ||
300 | |||
301 | Q_UNUSED(p); | ||
302 | |||
303 | if ( moving ) { | ||
304 | |||
305 | CanvasCard *item = moving; | ||
306 | |||
307 | if ( item->animated() ) | ||
308 | return; | ||
309 | |||
310 | if ( alphaCardPile ) | ||
311 | if ( moved ) { | ||
312 | |||
313 | CardPile *pile = closestPile((int)alphaCardPile->x(), (int)alphaCardPile->y(), 30); | ||
314 | |||
315 | if (pile && pile->isAllowedOnTop(item)) { | ||
316 | CardPile *oldPile = item->getCardPile(); | ||
317 | Card *c = NULL; | ||
318 | if ( oldPile != pile) { | ||
319 | while ( item ) { | ||
320 | item->show(); | ||
321 | if ( oldPile ) { | ||
322 | c = oldPile->cardInfront(item); | ||
323 | oldPile->removeCard(item); | ||
324 | } | ||
325 | pile->addCardToTop(item); | ||
326 | item->setCardPile(pile); | ||
327 | //item->move( pile->getCardPos(item) ); | ||
328 | QPoint p = pile->getCardPos(item); | ||
329 | item->setPos( p.x(), p.y(), highestZ ); | ||
330 | highestZ++; | ||
331 | |||
332 | if (item->getValue() == king && haveWeWon()) { | ||
333 | alphaCardPile->hide(); | ||
334 | gameWon(); | ||
335 | moving = NULL; | ||
336 | return; | ||
337 | } | ||
338 | |||
339 | if (oldPile) { | ||
340 | item = (CanvasCard *)c; | ||
341 | } else { | ||
342 | item = NULL; | ||
343 | } | ||
344 | } | ||
345 | alphaCardPile->hide(); | ||
346 | moving = NULL; | ||
347 | return; | ||
348 | } | ||
349 | } | ||
350 | |||
351 | alphaCardPile->animatedMove(); | ||
352 | } | ||
353 | } | ||
354 | |||
355 | moved = FALSE; | ||
356 | } | ||
357 | |||
358 | |||
359 | void CanvasCardGame::readPile( Config& cfg, CardPile *pile, QString name, int& highestZ ) | ||
360 | { | ||
361 | cfg.setGroup( name ); | ||
362 | int numberOfCards = cfg.readNumEntry("NumberOfCards", 0); | ||
363 | Card *card = NULL; | ||
364 | for ( int i = 0; i < numberOfCards; i++ ) { | ||
365 | QString cardStr; | ||
366 | cardStr.sprintf( "%i", i ); | ||
367 | int val = cfg.readNumEntry( "Card" + cardStr ); | ||
368 | bool facing = cfg.readBoolEntry( "CardFacing" + cardStr ); | ||
369 | card = cards[ val ]; | ||
370 | card->setFace(facing); | ||
371 | pile->addCardToTop(card); | ||
372 | card->setCardPile(pile); | ||
373 | QPoint p = pile->getCardPos( card ); | ||
374 | card->setPos( p.x(), p.y(), highestZ ); | ||
375 | card->showCard(); | ||
376 | highestZ++; | ||
377 | } | ||
378 | } | ||
379 | |||
380 | |||
diff --git a/noncore/games/solitaire/canvascardgame.h b/noncore/games/solitaire/canvascardgame.h new file mode 100644 index 0000000..4d32014 --- a/dev/null +++ b/noncore/games/solitaire/canvascardgame.h | |||
@@ -0,0 +1,95 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #ifndef CANVAS_CARD_GAME_H | ||
21 | #define CANVAS_CARD_GAME_H | ||
22 | |||
23 | #include "cardgame.h" | ||
24 | #include "canvasshapes.h" | ||
25 | #include "canvascard.h" | ||
26 | |||
27 | #include <qpe/resource.h> | ||
28 | #include <qpe/config.h> | ||
29 | |||
30 | #include <qmainwindow.h> | ||
31 | #include <qpe/qpemenubar.h> | ||
32 | #include <qpainter.h> | ||
33 | |||
34 | #include <stdlib.h> | ||
35 | #include <time.h> | ||
36 | |||
37 | |||
38 | class CanvasCardPile; | ||
39 | |||
40 | |||
41 | class CanvasCardGame : public QCanvasView, public CardGame | ||
42 | { | ||
43 | public: | ||
44 | CanvasCardGame(QCanvas &c, bool snap, QWidget *parent = 0, const char *name = 0, WFlags f = 0) : | ||
45 | QCanvasView( &c, parent, name, f ), | ||
46 | moved(FALSE), | ||
47 | moving(NULL), | ||
48 | alphaCardPile( NULL ), | ||
49 | cardXOff(0), cardYOff(0), | ||
50 | snapOn(snap), | ||
51 | numberToDraw(1) { } | ||
52 | |||
53 | virtual ~CanvasCardGame(); | ||
54 | |||
55 | virtual Card *newCard( eValue v, eSuit s, bool f ) { | ||
56 | return new CanvasCard( v, s, f, canvas() ); | ||
57 | } | ||
58 | |||
59 | virtual void readConfig( Config& cfg ) { Q_UNUSED( cfg ); } | ||
60 | virtual void writeConfig( Config& cfg ) { Q_UNUSED( cfg ); } | ||
61 | |||
62 | virtual void gameWon(); | ||
63 | virtual bool haveWeWon() { return FALSE; } | ||
64 | |||
65 | virtual bool mousePressCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); return FALSE; } | ||
66 | virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } | ||
67 | |||
68 | void cancelMoving() { moving = NULL; } | ||
69 | void toggleSnap() { snapOn = (snapOn == TRUE) ? FALSE : TRUE; } | ||
70 | void toggleCardsDrawn() { numberToDraw = (numberToDraw == 1) ? 3 : 1; } | ||
71 | int cardsDrawn() { return numberToDraw; } | ||
72 | void setNumberToDraw(int numToDraw) { this->numberToDraw = numToDraw; } | ||
73 | |||
74 | void readPile( Config& cfg, CardPile *pile, QString name, int& highestZ ); | ||
75 | |||
76 | protected: | ||
77 | void contentsMousePressEvent(QMouseEvent *e); | ||
78 | void contentsMouseReleaseEvent(QMouseEvent *e); | ||
79 | void contentsMouseMoveEvent(QMouseEvent *e); | ||
80 | |||
81 | protected: | ||
82 | // Mouse event state variables | ||
83 | bool moved; | ||
84 | CanvasCard *moving; | ||
85 | CanvasCardPile *alphaCardPile; | ||
86 | int cardXOff, cardYOff; | ||
87 | |||
88 | private: | ||
89 | bool snapOn; | ||
90 | int numberToDraw; | ||
91 | }; | ||
92 | |||
93 | |||
94 | #endif | ||
95 | |||
diff --git a/noncore/games/solitaire/canvascardwindow.cpp b/noncore/games/solitaire/canvascardwindow.cpp new file mode 100644 index 0000000..4c365a5 --- a/dev/null +++ b/noncore/games/solitaire/canvascardwindow.cpp | |||
@@ -0,0 +1,227 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include "canvascardwindow.h" | ||
22 | #include "patiencecardgame.h" | ||
23 | #include "freecellcardgame.h" | ||
24 | |||
25 | #include <qpe/resource.h> | ||
26 | |||
27 | #include <qmainwindow.h> | ||
28 | #include <qpopupmenu.h> | ||
29 | #include <qstyle.h> | ||
30 | |||
31 | |||
32 | CanvasCardWindow::CanvasCardWindow(QWidget* parent, const char* name, WFlags f) : | ||
33 | QMainWindow(parent, name, f), canvas(230, 260), snapOn(TRUE), cardBack(4), gameType(0), | ||
34 | cardGame(NULL) | ||
35 | { | ||
36 | setIcon( Resource::loadPixmap( "cards" ) ); | ||
37 | |||
38 | // Create Playing Area for Games | ||
39 | if ( QPixmap::defaultDepth() < 12 ) { | ||
40 | // canvas.setBackgroundColor(QColor(0x51, 0x74, 0x6B)); | ||
41 | //canvas.setBackgroundColor(QColor(0x20, 0xb0, 0x50)); | ||
42 | canvas.setBackgroundColor(QColor(0x08, 0x98, 0x2D)); | ||
43 | } else { | ||
44 | QPixmap bg; | ||
45 | bg.convertFromImage( Resource::loadImage( "table_pattern" ), ThresholdDither ); | ||
46 | canvas.setBackgroundPixmap(bg); | ||
47 | } | ||
48 | |||
49 | #if defined( QT_QWS_CASSIOPEIA ) | ||
50 | canvas.setAdvancePeriod(70); | ||
51 | #else | ||
52 | canvas.setAdvancePeriod(30); | ||
53 | #endif | ||
54 | |||
55 | |||
56 | #ifdef _PATIENCE_USE_ACCELS_ | ||
57 | QPEMenuBar* menu = menuBar(); | ||
58 | |||
59 | QPopupMenu* file = new QPopupMenu; | ||
60 | file->insertItem(tr("Patience"), this, SLOT(initPatience()), CTRL+Key_F); | ||
61 | file->insertItem(tr("Freecell"), this, SLOT(initFreecell()), CTRL+Key_F); | ||
62 | menu->insertItem(tr("&Game"), file); | ||
63 | |||
64 | menu->insertSeparator(); | ||
65 | |||
66 | settings = new QPopupMenu; | ||
67 | settings->insertItem(tr("&Change Card Backs"), this, SLOT(changeCardBacks()), Key_F2); | ||
68 | snap_id = settings->insertItem(tr("&Snap To Position"), this, SLOT(snapToggle()), Key_F3); | ||
69 | settings->setCheckable(TRUE); | ||
70 | menu->insertItem(tr("&Settings"),settings); | ||
71 | |||
72 | menu->insertSeparator(); | ||
73 | |||
74 | QPopupMenu* help = new QPopupMenu; | ||
75 | help->insertItem(tr("&About"), this, SLOT(help()), Key_F1); | ||
76 | help->setItemChecked(dbf_id, TRUE); | ||
77 | menu->insertItem(tr("&Help"),help); | ||
78 | #else | ||
79 | QMenuBar* menu = menuBar(); | ||
80 | |||
81 | QPopupMenu* file = new QPopupMenu; | ||
82 | file->insertItem(tr("Patience"), this, SLOT(initPatience())); | ||
83 | file->insertItem(tr("Freecell"), this, SLOT(initFreecell())); | ||
84 | menu->insertItem(tr("Play"), file); | ||
85 | |||
86 | menu->insertSeparator(); | ||
87 | |||
88 | settings = new QPopupMenu; | ||
89 | settings->setCheckable(TRUE); | ||
90 | settings->insertItem(tr("Change Card Backs"), this, SLOT(changeCardBacks())); | ||
91 | snap_id = settings->insertItem(tr("Snap To Position"), this, SLOT(snapToggle())); | ||
92 | QString m; | ||
93 | |||
94 | drawId = settings->insertItem(tr("Turn One Card"), this, SLOT(drawnToggle())); | ||
95 | menu->insertItem(tr("Settings"),settings); | ||
96 | |||
97 | #endif | ||
98 | |||
99 | menu->show(); | ||
100 | |||
101 | Config cfg( "Patience" ); | ||
102 | cfg.setGroup( "GlobalSettings" ); | ||
103 | snapOn = cfg.readBoolEntry( "SnapOn", TRUE); | ||
104 | settings->setItemChecked(snap_id, snapOn); | ||
105 | gameType = cfg.readNumEntry( "GameType", -1 ); | ||
106 | drawThree = cfg.readBoolEntry( "DrawThree", TRUE); | ||
107 | if ( gameType == 0 ) { | ||
108 | cardGame = new PatienceCardGame( &canvas, snapOn, this ); | ||
109 | cardGame->setNumberToDraw(drawThree ? 3 : 1); | ||
110 | setCaption(tr("Patience")); | ||
111 | setCentralWidget(cardGame); | ||
112 | cardGame->readConfig( cfg ); | ||
113 | setCardBacks(); | ||
114 | } else if ( gameType == 1 ) { | ||
115 | cardGame = new FreecellCardGame( &canvas, snapOn, this ); | ||
116 | setCaption(tr("Freecell")); | ||
117 | setCentralWidget(cardGame); | ||
118 | //cardGame->newGame(); // Until we know how to handle reading freecell config | ||
119 | cardGame->readConfig( cfg ); | ||
120 | setCardBacks(); | ||
121 | } else { | ||
122 | // Probably there isn't a config file or it is broken | ||
123 | // Start a new game | ||
124 | initPatience(); | ||
125 | } | ||
126 | |||
127 | updateDraw(); | ||
128 | } | ||
129 | |||
130 | |||
131 | CanvasCardWindow::~CanvasCardWindow() | ||
132 | { | ||
133 | if (cardGame) { | ||
134 | Config cfg("Patience"); | ||
135 | cfg.setGroup( "GlobalSettings" ); | ||
136 | cfg.writeEntry( "GameType", gameType ); | ||
137 | cfg.writeEntry( "SnapOn", snapOn ); | ||
138 | cfg.writeEntry( "DrawThree", drawThree); | ||
139 | cardGame->writeConfig( cfg ); | ||
140 | delete cardGame; | ||
141 | } | ||
142 | } | ||
143 | |||
144 | |||
145 | void CanvasCardWindow::resizeEvent(QResizeEvent *) | ||
146 | { | ||
147 | QSize s = centralWidget()->size(); | ||
148 | int fw = style().defaultFrameWidth(); | ||
149 | canvas.resize( s.width() - fw - 2, s.height() - fw - 2); | ||
150 | } | ||
151 | |||
152 | |||
153 | void CanvasCardWindow::initPatience() | ||
154 | { | ||
155 | // Create New Game | ||
156 | if ( cardGame ) | ||
157 | delete cardGame; | ||
158 | cardGame = new PatienceCardGame( &canvas, snapOn, this ); | ||
159 | cardGame->setNumberToDraw(drawThree ? 3 : 1); | ||
160 | gameType = 0; | ||
161 | setCaption(tr("Patience")); | ||
162 | setCentralWidget(cardGame); | ||
163 | cardGame->newGame(); | ||
164 | setCardBacks(); | ||
165 | updateDraw(); | ||
166 | } | ||
167 | |||
168 | |||
169 | void CanvasCardWindow::initFreecell() | ||
170 | { | ||
171 | // Create New Game | ||
172 | if ( cardGame ) { | ||
173 | delete cardGame; | ||
174 | } | ||
175 | cardGame = new FreecellCardGame( &canvas, snapOn, this ); | ||
176 | gameType = 1; | ||
177 | setCaption(tr("Freecell")); | ||
178 | setCentralWidget(cardGame); | ||
179 | cardGame->newGame(); | ||
180 | setCardBacks(); | ||
181 | } | ||
182 | |||
183 | |||
184 | void CanvasCardWindow::snapToggle() | ||
185 | { | ||
186 | snapOn = !snapOn; | ||
187 | settings->setItemChecked(snap_id, snapOn); | ||
188 | cardGame->toggleSnap(); | ||
189 | } | ||
190 | |||
191 | |||
192 | void CanvasCardWindow::drawnToggle() | ||
193 | { | ||
194 | cardGame->toggleCardsDrawn(); | ||
195 | updateDraw(); | ||
196 | } | ||
197 | |||
198 | void CanvasCardWindow::updateDraw() { | ||
199 | if(cardGame->cardsDrawn() == 3) | ||
200 | settings->changeItem(drawId, tr("Turn One Card")); | ||
201 | else | ||
202 | settings->changeItem(drawId, tr("Turn Three Cards")); | ||
203 | } | ||
204 | |||
205 | |||
206 | void CanvasCardWindow::setCardBacks() | ||
207 | { | ||
208 | QCanvasItemList l = canvas.allItems(); | ||
209 | |||
210 | for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) { | ||
211 | if ( (*it)->rtti() == canvasCardId ) | ||
212 | ((CanvasCard *)(*it))->setCardBack( cardBack ); | ||
213 | } | ||
214 | } | ||
215 | |||
216 | |||
217 | void CanvasCardWindow::changeCardBacks() | ||
218 | { | ||
219 | cardBack++; | ||
220 | |||
221 | if (cardBack == 5) | ||
222 | cardBack = 0; | ||
223 | |||
224 | setCardBacks(); | ||
225 | } | ||
226 | |||
227 | |||
diff --git a/noncore/games/solitaire/canvascardwindow.h b/noncore/games/solitaire/canvascardwindow.h new file mode 100644 index 0000000..b75d40a --- a/dev/null +++ b/noncore/games/solitaire/canvascardwindow.h | |||
@@ -0,0 +1,70 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #ifndef CANVAS_CARD_WINDOW_H | ||
21 | #define CANVAS_CARD_WINDOW_H | ||
22 | |||
23 | |||
24 | #include <qmainwindow.h> | ||
25 | #include <qcanvas.h> | ||
26 | |||
27 | |||
28 | class CanvasCardGame; | ||
29 | class QPopupMenu; | ||
30 | |||
31 | |||
32 | class CanvasCardWindow : public QMainWindow { | ||
33 | Q_OBJECT | ||
34 | |||
35 | public: | ||
36 | CanvasCardWindow(QWidget* parent=0, const char* name=0, WFlags f=0); | ||
37 | virtual ~CanvasCardWindow(); | ||
38 | |||
39 | public slots: | ||
40 | void setCardBacks(); | ||
41 | void changeCardBacks(); | ||
42 | void snapToggle(); | ||
43 | void drawnToggle(); | ||
44 | |||
45 | private slots: | ||
46 | void initFreecell(); | ||
47 | void initPatience(); | ||
48 | |||
49 | protected: | ||
50 | virtual void resizeEvent(QResizeEvent *e); | ||
51 | |||
52 | void updateDraw(); | ||
53 | private: | ||
54 | QCanvas canvas; | ||
55 | bool snapOn; | ||
56 | bool drawThree; | ||
57 | int drawId; | ||
58 | int cardBack; | ||
59 | int gameType; | ||
60 | CanvasCardGame *cardGame; | ||
61 | |||
62 | QPopupMenu* options; | ||
63 | QPopupMenu* settings; | ||
64 | int dbf_id; | ||
65 | int snap_id; | ||
66 | }; | ||
67 | |||
68 | |||
69 | #endif | ||
70 | |||
diff --git a/noncore/games/solitaire/canvasshapes.cpp b/noncore/games/solitaire/canvasshapes.cpp new file mode 100644 index 0000000..28d0b4e --- a/dev/null +++ b/noncore/games/solitaire/canvasshapes.cpp | |||
@@ -0,0 +1,92 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #include <qpainter.h> | ||
21 | #include <qcanvas.h> | ||
22 | #include "canvasshapes.h" | ||
23 | |||
24 | |||
25 | CanvasRoundRect::CanvasRoundRect(int x, int y, QCanvas *canvas) : | ||
26 | QCanvasRectangle( x, y, 23, 36, canvas) | ||
27 | { | ||
28 | setZ(0); | ||
29 | show(); | ||
30 | } | ||
31 | |||
32 | |||
33 | void CanvasRoundRect::redraw() | ||
34 | { | ||
35 | hide(); | ||
36 | show(); | ||
37 | } | ||
38 | |||
39 | |||
40 | void CanvasRoundRect::drawShape(QPainter &p) | ||
41 | { | ||
42 | p.drawRoundRect( (int)x(), (int)y(), 23, 36); | ||
43 | } | ||
44 | |||
45 | |||
46 | CanvasCircleOrCross::CanvasCircleOrCross(int x, int y, QCanvas *canvas) : | ||
47 | QCanvasRectangle( x, y, 21, 21, canvas), circleShape(TRUE) | ||
48 | { | ||
49 | show(); | ||
50 | } | ||
51 | |||
52 | |||
53 | void CanvasCircleOrCross::redraw() | ||
54 | { | ||
55 | hide(); | ||
56 | show(); | ||
57 | } | ||
58 | |||
59 | |||
60 | void CanvasCircleOrCross::setCircle() | ||
61 | { | ||
62 | circleShape = TRUE; | ||
63 | redraw(); | ||
64 | } | ||
65 | |||
66 | |||
67 | void CanvasCircleOrCross::setCross() | ||
68 | { | ||
69 | circleShape = FALSE; | ||
70 | redraw(); | ||
71 | } | ||
72 | |||
73 | |||
74 | void CanvasCircleOrCross::drawShape(QPainter &p) | ||
75 | { | ||
76 | int x1 = (int)x(), y1 = (int)y(); | ||
77 | // Green circle | ||
78 | if (circleShape == TRUE) { | ||
79 | p.setPen( QPen( QColor(0x10, 0xE0, 0x10), 1 ) ); | ||
80 | p.drawEllipse( x1 - 1, y1 - 1, 21, 21); | ||
81 | p.drawEllipse( x1 - 1, y1 - 0, 21, 19); | ||
82 | p.drawEllipse( x1 + 0, y1 + 0, 19, 19); | ||
83 | p.drawEllipse( x1 + 1, y1 + 0, 17, 19); | ||
84 | p.drawEllipse( x1 + 1, y1 + 1, 17, 17); | ||
85 | // Red cross | ||
86 | } else { | ||
87 | p.setPen( QPen( QColor(0xE0, 0x10, 0x10), 5 ) ); | ||
88 | p.drawLine( x1, y1, x1 + 20, y1 + 20); | ||
89 | p.drawLine( x1 + 20, y1, x1, y1 + 20); | ||
90 | } | ||
91 | } | ||
92 | |||
diff --git a/noncore/games/solitaire/canvasshapes.h b/noncore/games/solitaire/canvasshapes.h new file mode 100644 index 0000000..72acf6b --- a/dev/null +++ b/noncore/games/solitaire/canvasshapes.h | |||
@@ -0,0 +1,55 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #ifndef CANVAS_SHAPES_H | ||
21 | #define CANVAS_SHAPES_H | ||
22 | |||
23 | |||
24 | #include <qcanvas.h> | ||
25 | |||
26 | |||
27 | class QPainter; | ||
28 | |||
29 | |||
30 | class CanvasRoundRect : QCanvasRectangle | ||
31 | { | ||
32 | public: | ||
33 | CanvasRoundRect(int x, int y, QCanvas *canvas); | ||
34 | void redraw(); | ||
35 | protected: | ||
36 | void drawShape(QPainter &p); | ||
37 | }; | ||
38 | |||
39 | |||
40 | class CanvasCircleOrCross : QCanvasRectangle | ||
41 | { | ||
42 | public: | ||
43 | CanvasCircleOrCross(int x, int y, QCanvas *canvas); | ||
44 | void redraw(); | ||
45 | void setCircle(); | ||
46 | void setCross(); | ||
47 | protected: | ||
48 | void drawShape(QPainter &p); | ||
49 | private: | ||
50 | bool circleShape; | ||
51 | }; | ||
52 | |||
53 | |||
54 | #endif | ||
55 | |||
diff --git a/noncore/games/solitaire/card.cpp b/noncore/games/solitaire/card.cpp new file mode 100644 index 0000000..609e280 --- a/dev/null +++ b/noncore/games/solitaire/card.cpp | |||
@@ -0,0 +1,53 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include "card.h" | ||
22 | |||
23 | #include <qpe/config.h> | ||
24 | |||
25 | #include <qpoint.h> | ||
26 | #include <qlist.h> | ||
27 | |||
28 | /* | ||
29 | Card( eValue v, eSuit s, bool f ) : | ||
30 | val(v), suit(s), faceUp(f), showing(FALSE), ix(0), iy(0), iz(0), cardPile(NULL) { } | ||
31 | virtual ~Card() { } | ||
32 | eValue getValue() { return val; } | ||
33 | eSuit getSuit() { return suit; } | ||
34 | CardPile *getCardPile() { return cardPile; } | ||
35 | bool isFacing() { return faceUp; } | ||
36 | bool isShowing() { return showing; } | ||
37 | bool isRed() { return ((suit == diamonds) || (suit == hearts)); } | ||
38 | int getX(void) { return ix; } | ||
39 | int getY(void) { return iy; } | ||
40 | int getZ(void) { return iz; } | ||
41 | void setCardPile(CardPile *p) { cardPile = p; } | ||
42 | void setFace(bool f) { faceUp = f; } | ||
43 | void flip(void) { flipTo(getX(), getY()); } | ||
44 | virtual void setPos(int x, int y, int z) { ix = x; iy = y; iz = z; } | ||
45 | virtual void move(int x, int y) { ix = x; iy = y; } | ||
46 | virtual void move(QPoint p) { ix = p.x(); iy = p.y(); } | ||
47 | virtual void flipTo(int x, int y, int steps = 8) { ix = x; iy = y; faceUp = !faceUp; redraw(); Q_UNUSED(steps); } | ||
48 | virtual void showCard(void) { showing = TRUE; } | ||
49 | virtual void hideCard(void) { showing = FALSE; } | ||
50 | virtual void redraw(void) { } | ||
51 | */ | ||
52 | |||
53 | |||
diff --git a/noncore/games/solitaire/card.h b/noncore/games/solitaire/card.h new file mode 100644 index 0000000..eb30d30 --- a/dev/null +++ b/noncore/games/solitaire/card.h | |||
@@ -0,0 +1,84 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #ifndef CARD_H | ||
21 | #define CARD_H | ||
22 | |||
23 | |||
24 | #include <qpoint.h> | ||
25 | |||
26 | |||
27 | class CardPile; | ||
28 | |||
29 | |||
30 | enum eSuit { | ||
31 | jokerSuit = 0, clubs, spades, diamonds, hearts | ||
32 | }; | ||
33 | |||
34 | |||
35 | enum eValue { | ||
36 | jokerVal = 0, ace, two, three, four, five, | ||
37 | six, seven, eight, nine, ten, jack, queen, king | ||
38 | }; | ||
39 | |||
40 | |||
41 | class Card | ||
42 | { | ||
43 | public: | ||
44 | Card( eValue v, eSuit s, bool f ) : | ||
45 | val(v), suit(s), faceUp(f), showing(FALSE), ix(0), iy(0), iz(0), cardPile(NULL) { } | ||
46 | virtual ~Card() { } | ||
47 | |||
48 | eValue getValue() { return val; } | ||
49 | eSuit getSuit() { return suit; } | ||
50 | |||
51 | void setCardPile(CardPile *p) { cardPile = p; } | ||
52 | CardPile *getCardPile() { return cardPile; } | ||
53 | |||
54 | void setFace(bool f) { faceUp = f; /* flip(); */ } | ||
55 | bool isFacing() { return faceUp; } | ||
56 | |||
57 | bool isShowing() { return showing; } | ||
58 | bool isRed() { return ((suit == diamonds) || (suit == hearts)); } | ||
59 | |||
60 | int getX(void) { return ix; } | ||
61 | int getY(void) { return iy; } | ||
62 | int getZ(void) { return iz; } | ||
63 | void flip(void) { flipTo(getX(), getY()); } | ||
64 | |||
65 | virtual void setPos(int x, int y, int z) { ix = x; iy = y; iz = z; } | ||
66 | virtual void move(int x, int y) { ix = x; iy = y; } | ||
67 | virtual void move(QPoint p) { ix = p.x(); iy = p.y(); } | ||
68 | virtual void flipTo(int x, int y, int steps = 8) { ix = x; iy = y; faceUp = !faceUp; redraw(); Q_UNUSED(steps); } | ||
69 | virtual void showCard(void) { showing = TRUE; } | ||
70 | virtual void hideCard(void) { showing = FALSE; } | ||
71 | protected: | ||
72 | virtual void redraw(void) { } | ||
73 | private: | ||
74 | eValue val; | ||
75 | eSuit suit; | ||
76 | bool faceUp; | ||
77 | bool showing; | ||
78 | int ix, iy, iz; | ||
79 | CardPile *cardPile; | ||
80 | }; | ||
81 | |||
82 | |||
83 | #endif | ||
84 | |||
diff --git a/noncore/games/solitaire/carddeck.cpp b/noncore/games/solitaire/carddeck.cpp new file mode 100644 index 0000000..87c043a --- a/dev/null +++ b/noncore/games/solitaire/carddeck.cpp | |||
@@ -0,0 +1,81 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #include <stdlib.h> | ||
21 | #include <time.h> | ||
22 | #include "card.h" | ||
23 | #include "carddeck.h" | ||
24 | |||
25 | |||
26 | CardDeck::CardDeck(int jokers) : numberOfJokers(jokers), deckCreated(FALSE) | ||
27 | { | ||
28 | cards = new (Card *)[getNumberOfCards()]; | ||
29 | } | ||
30 | |||
31 | |||
32 | CardDeck::~CardDeck() | ||
33 | { | ||
34 | for (int i = 0; i < getNumberOfCards(); i++) | ||
35 | delete cards[i]; | ||
36 | delete cards; | ||
37 | } | ||
38 | |||
39 | |||
40 | void CardDeck::createDeck() | ||
41 | { | ||
42 | if (!deckCreated) { | ||
43 | for (int i = 0; i < 52; i++) | ||
44 | cards[i] = newCard( (eValue)((i % 13) + 1), (eSuit)((i / 13) + 1), FALSE ); | ||
45 | for (int i = 0; i < getNumberOfJokers(); i++) | ||
46 | cards[52 + i] = newCard( jokerVal, jokerSuit, FALSE ); | ||
47 | deckCreated = TRUE; | ||
48 | } | ||
49 | } | ||
50 | |||
51 | |||
52 | void CardDeck::shuffle() | ||
53 | { | ||
54 | srand(time(NULL)); | ||
55 | for (int i = 0; i < getNumberOfCards(); i++) { | ||
56 | int index = rand() % getNumberOfCards(); | ||
57 | Card *tmpCard = cards[i]; | ||
58 | cards[i] = cards[index]; | ||
59 | cards[index] = tmpCard; | ||
60 | } | ||
61 | } | ||
62 | |||
63 | |||
64 | int CardDeck::getNumberOfCards() | ||
65 | { | ||
66 | return 52 + getNumberOfJokers(); | ||
67 | } | ||
68 | |||
69 | |||
70 | int CardDeck::getNumberOfJokers() | ||
71 | { | ||
72 | return numberOfJokers; | ||
73 | } | ||
74 | |||
75 | |||
76 | Card *CardDeck::newCard( eValue v, eSuit s, bool f ) | ||
77 | { | ||
78 | return new Card(v, s, f); | ||
79 | } | ||
80 | |||
81 | |||
diff --git a/noncore/games/solitaire/carddeck.h b/noncore/games/solitaire/carddeck.h new file mode 100644 index 0000000..9ad35a9 --- a/dev/null +++ b/noncore/games/solitaire/carddeck.h | |||
@@ -0,0 +1,49 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #ifndef CARD_DECK_H | ||
21 | #define CARD_DECK_H | ||
22 | |||
23 | |||
24 | class Card; | ||
25 | |||
26 | |||
27 | class CardDeck | ||
28 | { | ||
29 | public: | ||
30 | CardDeck(int jokers = 0); | ||
31 | virtual ~CardDeck(); | ||
32 | |||
33 | void createDeck(); | ||
34 | void shuffle(); | ||
35 | int getNumberOfCards(); | ||
36 | int getNumberOfJokers(); | ||
37 | |||
38 | virtual Card *newCard( eValue v, eSuit s, bool f ); | ||
39 | virtual void deal() { } | ||
40 | |||
41 | Card **cards; | ||
42 | private: | ||
43 | int numberOfJokers; | ||
44 | bool deckCreated; | ||
45 | }; | ||
46 | |||
47 | |||
48 | #endif | ||
49 | |||
diff --git a/noncore/games/solitaire/cardgame.cpp b/noncore/games/solitaire/cardgame.cpp new file mode 100644 index 0000000..b19aeef --- a/dev/null +++ b/noncore/games/solitaire/cardgame.cpp | |||
@@ -0,0 +1,35 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #include "cardgame.h" | ||
21 | |||
22 | |||
23 | void CardGame::newGame() | ||
24 | { | ||
25 | // Create Cards | ||
26 | createDeck(); | ||
27 | |||
28 | // Shuffle Cards | ||
29 | shuffle(); | ||
30 | |||
31 | // Deal Cards | ||
32 | deal(); | ||
33 | } | ||
34 | |||
35 | |||
diff --git a/noncore/games/solitaire/cardgame.h b/noncore/games/solitaire/cardgame.h new file mode 100644 index 0000000..dd7efab --- a/dev/null +++ b/noncore/games/solitaire/cardgame.h | |||
@@ -0,0 +1,45 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #ifndef CARD_GAME_H | ||
21 | #define CARD_GAME_H | ||
22 | |||
23 | |||
24 | #include <qpoint.h> | ||
25 | #include "card.h" | ||
26 | #include "cardpile.h" | ||
27 | #include "carddeck.h" | ||
28 | #include "cardgamelayout.h" | ||
29 | |||
30 | |||
31 | class CardGame : public CardGameLayout, public CardDeck | ||
32 | { | ||
33 | public: | ||
34 | CardGame(int numOfJokers = 0) : CardGameLayout(), CardDeck(numOfJokers) { } | ||
35 | virtual ~CardGame() { } | ||
36 | virtual void newGame(); | ||
37 | virtual void mousePress(QPoint p) { Q_UNUSED(p); } | ||
38 | virtual void mouseRelease(QPoint p) { Q_UNUSED(p); } | ||
39 | virtual void mouseMove(QPoint p) { Q_UNUSED(p); } | ||
40 | private: | ||
41 | }; | ||
42 | |||
43 | |||
44 | #endif | ||
45 | |||
diff --git a/noncore/games/solitaire/cardgamelayout.cpp b/noncore/games/solitaire/cardgamelayout.cpp new file mode 100644 index 0000000..1ceee8d --- a/dev/null +++ b/noncore/games/solitaire/cardgamelayout.cpp | |||
@@ -0,0 +1,61 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #include "cardgamelayout.h" | ||
21 | |||
22 | |||
23 | CardGameLayout::~CardGameLayout() | ||
24 | { | ||
25 | // Should I just do setAutoDelete( TRUE ); ? | ||
26 | for (CardPile *p = first(); p != NULL; p = next()) | ||
27 | delete p; | ||
28 | } | ||
29 | |||
30 | |||
31 | CardPile *CardGameLayout::closestPile(int x, int y, int maxDistance) | ||
32 | { | ||
33 | int closestDistance = maxDistance * maxDistance; | ||
34 | CardPile *closestPile = NULL; | ||
35 | |||
36 | for (CardPile *p = first(); p != NULL; p = next()) { | ||
37 | int d = p->distanceFromNextPos(x, y); | ||
38 | if (d < closestDistance) { | ||
39 | closestDistance = d; | ||
40 | closestPile = p; | ||
41 | } | ||
42 | } | ||
43 | |||
44 | return closestPile; | ||
45 | } | ||
46 | |||
47 | |||
48 | void CardGameLayout::beginDealing() | ||
49 | { | ||
50 | for (CardPile *p = first(); p != NULL; p = next()) | ||
51 | p->beginDealing(); | ||
52 | } | ||
53 | |||
54 | |||
55 | void CardGameLayout::endDealing() | ||
56 | { | ||
57 | for (CardPile *p = first(); p != NULL; p = next()) | ||
58 | p->endDealing(); | ||
59 | } | ||
60 | |||
61 | |||
diff --git a/noncore/games/solitaire/cardgamelayout.h b/noncore/games/solitaire/cardgamelayout.h new file mode 100644 index 0000000..bb36e6b --- a/dev/null +++ b/noncore/games/solitaire/cardgamelayout.h | |||
@@ -0,0 +1,42 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #ifndef CARD_GAME_LAYOUT_H | ||
21 | #define CARD_GAME_LAYOUT_H | ||
22 | |||
23 | |||
24 | #include <qlist.h> | ||
25 | #include "cardpile.h" | ||
26 | |||
27 | |||
28 | class CardGameLayout : public QList<CardPile> | ||
29 | { | ||
30 | public: | ||
31 | CardGameLayout() { } | ||
32 | virtual ~CardGameLayout(); | ||
33 | |||
34 | void addCardPile(CardPile *pile) { append((const CardPile *)pile); } | ||
35 | CardPile *closestPile(int x, int y, int maxDistance); | ||
36 | void beginDealing(); | ||
37 | void endDealing(); | ||
38 | }; | ||
39 | |||
40 | |||
41 | #endif | ||
42 | |||
diff --git a/noncore/games/solitaire/cardpile.cpp b/noncore/games/solitaire/cardpile.cpp new file mode 100644 index 0000000..0b738d2 --- a/dev/null +++ b/noncore/games/solitaire/cardpile.cpp | |||
@@ -0,0 +1,114 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include "cardpile.h" | ||
22 | #include "card.h" | ||
23 | |||
24 | #include <qpe/config.h> | ||
25 | #include <qpoint.h> | ||
26 | |||
27 | #include <qlist.h> | ||
28 | |||
29 | |||
30 | CardPile::CardPile(int x, int y) : pileX(x), pileY(y), dealing(FALSE) { | ||
31 | pileWidth = 0; | ||
32 | pileHeight = 0; | ||
33 | pileNextX = pileX; | ||
34 | pileNextY = pileY; | ||
35 | pileCenterX = x + pileWidth / 2; | ||
36 | pileCenterY = y + pileHeight / 2; | ||
37 | pileRadius = (pileWidth > pileHeight) ? pileWidth : pileHeight; | ||
38 | } | ||
39 | |||
40 | |||
41 | int CardPile::distanceFromPile(int x, int y) { | ||
42 | return (pileCenterX-x)*(pileCenterX-x)+(pileCenterY-y)*(pileCenterY-y); | ||
43 | } | ||
44 | |||
45 | |||
46 | int CardPile::distanceFromNextPos(int x, int y) { | ||
47 | return (pileNextX-x)*(pileNextX-x)+(pileNextY-y)*(pileNextY-y); | ||
48 | } | ||
49 | |||
50 | |||
51 | Card *CardPile::cardInfront(Card *c) { | ||
52 | CardPile *p = c->getCardPile(); | ||
53 | if (p) { | ||
54 | p->at(p->find(c)); | ||
55 | return p->next(); | ||
56 | } else { | ||
57 | return NULL; | ||
58 | } | ||
59 | } | ||
60 | |||
61 | |||
62 | bool CardPile::kingOnTop() { | ||
63 | Card *top = cardOnTop(); | ||
64 | return top && top->getValue() == king; | ||
65 | } | ||
66 | |||
67 | |||
68 | bool CardPile::addCardToTop(Card *c) { | ||
69 | if (dealing || isAllowedOnTop(c)) { | ||
70 | append((const Card *)c); | ||
71 | cardAddedToTop(c); | ||
72 | return TRUE; | ||
73 | } | ||
74 | return FALSE; | ||
75 | } | ||
76 | |||
77 | |||
78 | bool CardPile::addCardToBottom(Card *c) { | ||
79 | if (dealing || isAllowedOnBottom(c)) { | ||
80 | prepend((const Card *)c); | ||
81 | cardAddedToBottom(c); | ||
82 | return TRUE; | ||
83 | } | ||
84 | return FALSE; | ||
85 | } | ||
86 | |||
87 | |||
88 | bool CardPile::removeCard(Card *c) { | ||
89 | if (dealing || isAllowedToBeMoved(c)) { | ||
90 | take(find(c)); | ||
91 | cardRemoved(c); | ||
92 | return TRUE; | ||
93 | } | ||
94 | return FALSE; | ||
95 | } | ||
96 | |||
97 | |||
98 | void CardPile::writeConfig( Config& cfg, QString name ) { | ||
99 | int numberOfCards = 0; | ||
100 | cfg.setGroup( name ); | ||
101 | Card *card = cardOnBottom(); | ||
102 | while ( card ) { | ||
103 | QString cardStr; | ||
104 | cardStr.sprintf( "%i", numberOfCards ); | ||
105 | int val = (int)card->getValue() - 1 + ( (int)card->getSuit() - 1 ) * 13; | ||
106 | cfg.writeEntry( "Card" + cardStr, val ); | ||
107 | cfg.writeEntry( "CardFacing" + cardStr, card->isFacing() ); | ||
108 | card = cardInfront( card ); | ||
109 | numberOfCards++; | ||
110 | } | ||
111 | cfg.writeEntry("NumberOfCards", numberOfCards); | ||
112 | } | ||
113 | |||
114 | |||
diff --git a/noncore/games/solitaire/cardpile.h b/noncore/games/solitaire/cardpile.h new file mode 100644 index 0000000..c515bbc --- a/dev/null +++ b/noncore/games/solitaire/cardpile.h | |||
@@ -0,0 +1,101 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #ifndef CARD_PILE_H | ||
21 | #define CARD_PILE_H | ||
22 | |||
23 | |||
24 | #include <qpoint.h> | ||
25 | #include <qlist.h> | ||
26 | |||
27 | |||
28 | enum ePileStackingType { | ||
29 | pileCascades = 0, pileStacks, pileCascadesOrStacks | ||
30 | }; | ||
31 | |||
32 | |||
33 | enum ePileFaceingType { | ||
34 | pileFaceUp = 0, pileFaceDown, pileFaceUpOrDown | ||
35 | }; | ||
36 | |||
37 | |||
38 | class Card; | ||
39 | class Config; | ||
40 | |||
41 | |||
42 | class CardPile : public QList<Card> | ||
43 | { | ||
44 | public: | ||
45 | CardPile(int x, int y); | ||
46 | virtual ~CardPile() { } | ||
47 | |||
48 | int getX() { return pileX; } | ||
49 | int getY() { return pileY; } | ||
50 | int getNextX() { return pileNextX; } | ||
51 | int getNextY() { return pileNextY; } | ||
52 | int getWidth() { return pileWidth; } | ||
53 | int getHeight() { return pileHeight; } | ||
54 | |||
55 | void setX(int x) { pileX = x; } | ||
56 | void setY(int y) { pileY = y; } | ||
57 | void setNextX(int x) { pileNextX = x; } | ||
58 | void setNextY(int y) { pileNextY = y; } | ||
59 | void setWidth(int width) { pileWidth = width; } | ||
60 | void setHeight(int height) { pileHeight = height; } | ||
61 | |||
62 | void beginDealing() { dealing = TRUE; } | ||
63 | void endDealing() { dealing = FALSE; } | ||
64 | bool isDealing() { return dealing; } | ||
65 | |||
66 | int distanceFromPile(int x, int y); | ||
67 | int distanceFromNextPos(int x, int y); | ||
68 | |||
69 | Card *cardOnTop() { return getLast(); } | ||
70 | Card *cardOnBottom() { return getFirst(); } | ||
71 | Card *cardInfront(Card *c); | ||
72 | bool kingOnTop(); | ||
73 | |||
74 | bool addCardToTop(Card *c); | ||
75 | bool addCardToBottom(Card *c); | ||
76 | bool removeCard(Card *c); | ||
77 | |||
78 | virtual void cardAddedToTop(Card *) { } | ||
79 | virtual void cardAddedToBottom(Card *) { } | ||
80 | virtual void cardRemoved(Card *) { } | ||
81 | virtual bool isAllowedOnTop(Card *) { return FALSE; } | ||
82 | virtual bool isAllowedOnBottom(Card *) { return FALSE; } | ||
83 | virtual bool isAllowedToBeMoved(Card *) { return FALSE; } | ||
84 | virtual QPoint getCardPos(Card *) { return QPoint(pileX, pileY); } | ||
85 | virtual QPoint getHypertheticalNextCardPos() { return QPoint(pileX, pileY); } | ||
86 | |||
87 | void writeConfig( Config& cfg, QString name ); | ||
88 | |||
89 | protected: | ||
90 | int pileX, pileY; | ||
91 | int pileNextX, pileNextY; | ||
92 | int pileWidth, pileHeight; | ||
93 | int pileCenterX, pileCenterY; | ||
94 | int pileRadius; | ||
95 | private: | ||
96 | bool dealing; | ||
97 | }; | ||
98 | |||
99 | |||
100 | #endif | ||
101 | |||
diff --git a/noncore/games/solitaire/freecellcardgame.cpp b/noncore/games/solitaire/freecellcardgame.cpp new file mode 100644 index 0000000..e82afd4 --- a/dev/null +++ b/noncore/games/solitaire/freecellcardgame.cpp | |||
@@ -0,0 +1,137 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #include "freecellcardgame.h" | ||
21 | |||
22 | |||
23 | extern int highestZ; | ||
24 | int numberOfFreeCells = 4; | ||
25 | |||
26 | |||
27 | FreecellCardGame::FreecellCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent) | ||
28 | { | ||
29 | numberOfFreeCells = 4; | ||
30 | highestZ = 0; | ||
31 | |||
32 | for (int i = 0; i < 4; i++) { | ||
33 | freecellPiles[i] = new FreecellFreecellPile( 5 + i * 28, 10, canvas() ); | ||
34 | addCardPile(freecellPiles[i]); | ||
35 | } | ||
36 | for (int i = 0; i < 4; i++) { | ||
37 | discardPiles[i] = new FreecellDiscardPile( 125 + i * 28, 10, canvas() ); | ||
38 | addCardPile(discardPiles[i]); | ||
39 | } | ||
40 | for (int i = 0; i < 8; i++) { | ||
41 | workingPiles[i] = new FreecellWorkingPile( 10 + i * 28, 50, canvas() ); | ||
42 | addCardPile(workingPiles[i]); | ||
43 | } | ||
44 | } | ||
45 | |||
46 | |||
47 | void FreecellCardGame::deal(void) | ||
48 | { | ||
49 | highestZ = 1; | ||
50 | |||
51 | beginDealing(); | ||
52 | |||
53 | for (int i = 0; i < 52; i++) { | ||
54 | Card *card = cards[i]; | ||
55 | card->setFace( TRUE ); | ||
56 | card->setPos( 0, 0, highestZ ); | ||
57 | card->setCardPile( workingPiles[i%8] ); | ||
58 | workingPiles[i%8]->addCardToTop( card ); | ||
59 | card->move( workingPiles[i%8]->getCardPos( card ) ); | ||
60 | card->showCard(); | ||
61 | highestZ++; | ||
62 | } | ||
63 | |||
64 | endDealing(); | ||
65 | } | ||
66 | |||
67 | |||
68 | bool FreecellCardGame::mousePressCard( Card *c, QPoint p ) | ||
69 | { | ||
70 | Q_UNUSED(p); | ||
71 | |||
72 | if ( !c->getCardPile()->isAllowedToBeMoved(c) ) { | ||
73 | moving = NULL; | ||
74 | return TRUE; | ||
75 | } | ||
76 | |||
77 | return FALSE; | ||
78 | } | ||
79 | |||
80 | |||
81 | void FreecellCardGame::readConfig( Config& cfg ) | ||
82 | { | ||
83 | cfg.setGroup("GameState"); | ||
84 | |||
85 | // Create Cards, but don't shuffle or deal them yet | ||
86 | createDeck(); | ||
87 | |||
88 | // Move the cards to their piles (deal them to their previous places) | ||
89 | beginDealing(); | ||
90 | |||
91 | highestZ = 1; | ||
92 | |||
93 | for (int k = 0; k < 4; k++) { | ||
94 | QString pile; | ||
95 | pile.sprintf( "FreeCellPile%i", k ); | ||
96 | readPile( cfg, freecellPiles[k], pile, highestZ ); | ||
97 | } | ||
98 | |||
99 | for (int k = 0; k < 4; k++) { | ||
100 | QString pile; | ||
101 | pile.sprintf( "DiscardPile%i", k ); | ||
102 | readPile( cfg, discardPiles[k], pile, highestZ ); | ||
103 | } | ||
104 | |||
105 | for (int k = 0; k < 8; k++) { | ||
106 | QString pile; | ||
107 | pile.sprintf( "WorkingPile%i", k ); | ||
108 | readPile( cfg, workingPiles[k], pile, highestZ ); | ||
109 | } | ||
110 | |||
111 | highestZ++; | ||
112 | |||
113 | endDealing(); | ||
114 | } | ||
115 | |||
116 | |||
117 | void FreecellCardGame::writeConfig( Config& cfg ) | ||
118 | { | ||
119 | cfg.setGroup("GameState"); | ||
120 | for ( int i = 0; i < 4; i++ ) { | ||
121 | QString pile; | ||
122 | pile.sprintf( "FreeCellPile%i", i ); | ||
123 | freecellPiles[i]->writeConfig( cfg, pile ); | ||
124 | } | ||
125 | for ( int i = 0; i < 4; i++ ) { | ||
126 | QString pile; | ||
127 | pile.sprintf( "DiscardPile%i", i ); | ||
128 | discardPiles[i]->writeConfig( cfg, pile ); | ||
129 | } | ||
130 | for ( int i = 0; i < 8; i++ ) { | ||
131 | QString pile; | ||
132 | pile.sprintf( "WorkingPile%i", i ); | ||
133 | workingPiles[i]->writeConfig( cfg, pile ); | ||
134 | } | ||
135 | } | ||
136 | |||
137 | |||
diff --git a/noncore/games/solitaire/freecellcardgame.h b/noncore/games/solitaire/freecellcardgame.h new file mode 100644 index 0000000..f1b09ab --- a/dev/null +++ b/noncore/games/solitaire/freecellcardgame.h | |||
@@ -0,0 +1,152 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #ifndef FREECELL_CARD_GAME_H | ||
21 | #define FREECELL_CARD_GAME_H | ||
22 | |||
23 | |||
24 | #include "patiencecardgame.h" | ||
25 | |||
26 | |||
27 | extern int numberOfFreeCells; | ||
28 | |||
29 | |||
30 | class FreecellDiscardPile : public PatienceDiscardPile | ||
31 | { | ||
32 | public: | ||
33 | FreecellDiscardPile(int x, int y, QCanvas *canvas) : | ||
34 | PatienceDiscardPile(x, y, canvas) { } | ||
35 | |||
36 | }; | ||
37 | |||
38 | |||
39 | class FreecellWorkingPile : public PatienceWorkingPile | ||
40 | { | ||
41 | public: | ||
42 | FreecellWorkingPile(int x, int y, QCanvas *canvas) : | ||
43 | PatienceWorkingPile(x, y, canvas) { } | ||
44 | |||
45 | virtual bool isAllowedOnTop(Card *card) { | ||
46 | if ( cardOnBottom() == NULL ) { | ||
47 | int numberOfCardsBeingMoved = 0; | ||
48 | Card *tempCard = card; | ||
49 | |||
50 | while ((tempCard != NULL)) { | ||
51 | numberOfCardsBeingMoved++; | ||
52 | tempCard = cardInfront(tempCard); | ||
53 | } | ||
54 | |||
55 | if (numberOfCardsBeingMoved > numberOfFreeCells) | ||
56 | return FALSE; | ||
57 | } | ||
58 | |||
59 | if ( card->isFacing() && | ||
60 | cardOnTop() == NULL ) | ||
61 | return TRUE; | ||
62 | return PatienceWorkingPile::isAllowedOnTop( card ); | ||
63 | } | ||
64 | |||
65 | virtual bool isAllowedToBeMoved(Card *card) { | ||
66 | int nextExpectedValue = (int)card->getValue(); | ||
67 | bool nextExpectedColor = card->isRed(); | ||
68 | int numberOfCardsBeingMoved = 0; | ||
69 | |||
70 | while ((card != NULL)) { | ||
71 | numberOfCardsBeingMoved++; | ||
72 | if ( (int)card->getValue() != nextExpectedValue ) | ||
73 | return FALSE; | ||
74 | if ( card->isRed() != nextExpectedColor ) | ||
75 | return FALSE; | ||
76 | nextExpectedValue--;; | ||
77 | nextExpectedColor = !nextExpectedColor; | ||
78 | card = cardInfront(card); | ||
79 | } | ||
80 | |||
81 | if (numberOfCardsBeingMoved <= (numberOfFreeCells + 1)) | ||
82 | return TRUE; | ||
83 | |||
84 | return FALSE; | ||
85 | } | ||
86 | virtual void cardRemoved(Card *card) { | ||
87 | if ( !isDealing() && !cardOnTop() ) | ||
88 | numberOfFreeCells++; | ||
89 | PatienceWorkingPile::cardRemoved( card ); | ||
90 | } | ||
91 | virtual void cardAddedToTop(Card *card) { | ||
92 | if ( !isDealing() && cardOnBottom() == card ) | ||
93 | numberOfFreeCells--; | ||
94 | PatienceWorkingPile::cardAddedToTop( card ); | ||
95 | } | ||
96 | }; | ||
97 | |||
98 | |||
99 | class FreecellFreecellPile : public CardPile, public CanvasRoundRect | ||
100 | { | ||
101 | public: | ||
102 | FreecellFreecellPile(int x, int y, QCanvas *canvas) | ||
103 | : CardPile(x, y), CanvasRoundRect(x, y, canvas) { } | ||
104 | virtual bool isAllowedOnTop(Card *card) { | ||
105 | if ( ( cardOnTop() == NULL ) && ( card->getCardPile()->cardInfront(card) == NULL ) ) | ||
106 | return TRUE; | ||
107 | return FALSE; | ||
108 | } | ||
109 | virtual bool isAllowedToBeMoved(Card *card) { | ||
110 | Q_UNUSED(card); | ||
111 | return TRUE; | ||
112 | } | ||
113 | virtual void cardAddedToTop(Card *card) { | ||
114 | Q_UNUSED(card); | ||
115 | numberOfFreeCells--; | ||
116 | } | ||
117 | virtual void cardRemoved(Card *card) { | ||
118 | Q_UNUSED(card); | ||
119 | numberOfFreeCells++; | ||
120 | } | ||
121 | }; | ||
122 | |||
123 | |||
124 | class FreecellCardGame : public CanvasCardGame | ||
125 | { | ||
126 | public: | ||
127 | FreecellCardGame(QCanvas *c, bool snap, QWidget *parent = 0); | ||
128 | virtual void deal(void); | ||
129 | virtual bool haveWeWon() { | ||
130 | return ( discardPiles[0]->kingOnTop() && | ||
131 | discardPiles[1]->kingOnTop() && | ||
132 | discardPiles[2]->kingOnTop() && | ||
133 | discardPiles[3]->kingOnTop() ); | ||
134 | } | ||
135 | virtual void mousePress(QPoint p) { Q_UNUSED(p); } | ||
136 | virtual void mouseRelease(QPoint p) { Q_UNUSED(p); } | ||
137 | // virtual void mouseMove(QPoint p); | ||
138 | virtual bool mousePressCard(Card *card, QPoint p); | ||
139 | virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } | ||
140 | // virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } | ||
141 | void readConfig( Config& cfg ); | ||
142 | void writeConfig( Config& cfg ); | ||
143 | bool snapOn; | ||
144 | private: | ||
145 | FreecellFreecellPile *freecellPiles[8]; | ||
146 | FreecellWorkingPile *workingPiles[8]; | ||
147 | FreecellDiscardPile *discardPiles[4]; | ||
148 | }; | ||
149 | |||
150 | |||
151 | #endif | ||
152 | |||
diff --git a/noncore/games/solitaire/main.cpp b/noncore/games/solitaire/main.cpp new file mode 100644 index 0000000..f81aa3c --- a/dev/null +++ b/noncore/games/solitaire/main.cpp | |||
@@ -0,0 +1,36 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include "canvascardwindow.h" | ||
22 | |||
23 | #include <qpe/qpeapplication.h> | ||
24 | |||
25 | |||
26 | int main( int argc, char ** argv ) | ||
27 | { | ||
28 | QPEApplication a( argc, argv ); | ||
29 | |||
30 | CanvasCardWindow m; | ||
31 | m.setCaption( CanvasCardWindow::tr("Patience") ); | ||
32 | a.showMainWidget( &m ); | ||
33 | |||
34 | return a.exec(); | ||
35 | } | ||
36 | |||
diff --git a/noncore/games/solitaire/patiencecardgame.cpp b/noncore/games/solitaire/patiencecardgame.cpp new file mode 100644 index 0000000..5a9326a --- a/dev/null +++ b/noncore/games/solitaire/patiencecardgame.cpp | |||
@@ -0,0 +1,234 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #include "patiencecardgame.h" | ||
21 | |||
22 | |||
23 | int highestZ = 0; | ||
24 | |||
25 | |||
26 | PatienceCardGame::PatienceCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent) | ||
27 | { | ||
28 | numberOfTimesThroughDeck = 0; | ||
29 | highestZ = 0; | ||
30 | |||
31 | circleCross = new CanvasCircleOrCross( 7, 18, canvas() ); | ||
32 | rectangle = new CanvasRoundRect( 35, 10, canvas() ); | ||
33 | |||
34 | for (int i = 0; i < 4; i++) { | ||
35 | discardPiles[i] = new PatienceDiscardPile( 110 + i * 30, 10, canvas() ); | ||
36 | addCardPile(discardPiles[i]); | ||
37 | } | ||
38 | for (int i = 0; i < 7; i++) { | ||
39 | workingPiles[i] = new PatienceWorkingPile( 10 + i * 30, 50, canvas() ); | ||
40 | addCardPile(workingPiles[i]); | ||
41 | } | ||
42 | faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() ); | ||
43 | faceUpDealingPile = new PatienceFaceUpDeck( 35, 10, canvas() ); | ||
44 | } | ||
45 | |||
46 | |||
47 | PatienceCardGame::~PatienceCardGame() | ||
48 | { | ||
49 | delete circleCross; | ||
50 | delete rectangle; | ||
51 | delete faceDownDealingPile; | ||
52 | delete faceUpDealingPile; | ||
53 | } | ||
54 | |||
55 | |||
56 | void PatienceCardGame::deal(void) | ||
57 | { | ||
58 | highestZ = 1; | ||
59 | int t = 0; | ||
60 | |||
61 | beginDealing(); | ||
62 | |||
63 | for (int i = 0; i < 7; i++) { | ||
64 | cards[t]->setFace(TRUE); | ||
65 | for (int k = i; k < 7; k++, t++) { | ||
66 | Card *card = cards[t]; | ||
67 | workingPiles[k]->addCardToTop(card); | ||
68 | card->setCardPile( workingPiles[k] ); | ||
69 | QPoint p = workingPiles[k]->getCardPos( card ); | ||
70 | card->setPos( p.x(), p.y(), highestZ ); | ||
71 | card->showCard(); | ||
72 | highestZ++; | ||
73 | } | ||
74 | } | ||
75 | |||
76 | for ( ; t < 52; t++) { | ||
77 | Card *card = cards[t]; | ||
78 | faceDownDealingPile->addCardToTop(card); | ||
79 | card->setCardPile( faceDownDealingPile ); | ||
80 | QPoint p = faceDownDealingPile->getCardPos( card ); | ||
81 | card->setPos( p.x(), p.y(), highestZ ); | ||
82 | card->showCard(); | ||
83 | highestZ++; | ||
84 | } | ||
85 | |||
86 | endDealing(); | ||
87 | } | ||
88 | |||
89 | |||
90 | void PatienceCardGame::readConfig( Config& cfg ) | ||
91 | { | ||
92 | cfg.setGroup("GameState"); | ||
93 | |||
94 | // Do we have a config file to read in? | ||
95 | if ( !cfg.hasKey("numberOfTimesThroughDeck") ) { | ||
96 | // if not, create a new game | ||
97 | newGame(); | ||
98 | return; | ||
99 | } | ||
100 | // We have a config file, lets read it in and use it | ||
101 | |||
102 | // Create Cards, but don't shuffle or deal them yet | ||
103 | createDeck(); | ||
104 | |||
105 | // How many times through the deck have we been | ||
106 | numberOfTimesThroughDeck = cfg.readNumEntry("NumberOfTimesThroughDeck"); | ||
107 | |||
108 | // restore state to the circle/cross under the dealing pile | ||
109 | if ( canTurnOverDeck() ) | ||
110 | circleCross->setCircle(); | ||
111 | else | ||
112 | circleCross->setCross(); | ||
113 | |||
114 | // Move the cards to their piles (deal them to their previous places) | ||
115 | beginDealing(); | ||
116 | |||
117 | highestZ = 1; | ||
118 | |||
119 | for (int k = 0; k < 7; k++) { | ||
120 | QString pile; | ||
121 | pile.sprintf( "WorkingPile%i", k ); | ||
122 | readPile( cfg, workingPiles[k], pile, highestZ ); | ||
123 | } | ||
124 | |||
125 | for (int k = 0; k < 4; k++) { | ||
126 | QString pile; | ||
127 | pile.sprintf( "DiscardPile%i", k ); | ||
128 | readPile( cfg, discardPiles[k], pile, highestZ ); | ||
129 | } | ||
130 | |||
131 | readPile( cfg, faceDownDealingPile, "FaceDownDealingPile", highestZ ); | ||
132 | readPile( cfg, faceUpDealingPile, "FaceUpDealingPile", highestZ ); | ||
133 | |||
134 | highestZ++; | ||
135 | |||
136 | endDealing(); | ||
137 | } | ||
138 | |||
139 | |||
140 | void PatienceCardGame::writeConfig( Config& cfg ) | ||
141 | { | ||
142 | cfg.setGroup("GameState"); | ||
143 | cfg.writeEntry("numberOfTimesThroughDeck", numberOfTimesThroughDeck); | ||
144 | |||
145 | for ( int i = 0; i < 7; i++ ) { | ||
146 | QString pile; | ||
147 | pile.sprintf( "WorkingPile%i", i ); | ||
148 | workingPiles[i]->writeConfig( cfg, pile ); | ||
149 | } | ||
150 | for ( int i = 0; i < 4; i++ ) { | ||
151 | QString pile; | ||
152 | pile.sprintf( "DiscardPile%i", i ); | ||
153 | discardPiles[i]->writeConfig( cfg, pile ); | ||
154 | } | ||
155 | faceDownDealingPile->writeConfig( cfg, "FaceDownDealingPile" ); | ||
156 | faceUpDealingPile->writeConfig( cfg, "FaceUpDealingPile" ); | ||
157 | } | ||
158 | |||
159 | |||
160 | bool PatienceCardGame::mousePressCard( Card *card, QPoint p ) | ||
161 | { | ||
162 | Q_UNUSED(p); | ||
163 | |||
164 | CanvasCard *item = (CanvasCard *)card; | ||
165 | if (item->isFacing() != TRUE) { | ||
166 | // From facedown stack | ||
167 | if ((item->x() == 5) && ((int)item->y() == 10)) { | ||
168 | item->setZ(highestZ); | ||
169 | highestZ++; | ||
170 | |||
171 | // Added Code | ||
172 | faceDownDealingPile->removeCard(item); | ||
173 | faceUpDealingPile->addCardToTop(item); | ||
174 | item->setCardPile( faceUpDealingPile ); | ||
175 | |||
176 | item->flipTo( 35, (int)item->y() ); | ||
177 | } | ||
178 | moving = NULL; | ||
179 | moved = FALSE; | ||
180 | |||
181 | // move two other cards if we flip three at a time | ||
182 | int flipped = 1; | ||
183 | QCanvasItemList l = canvas()->collisions( p ); | ||
184 | for (QCanvasItemList::Iterator it = l.begin(); (it != l.end()) && (flipped != cardsDrawn()); ++it) { | ||
185 | if ( (*it)->rtti() == canvasCardId ) { | ||
186 | CanvasCard *item = (CanvasCard *)*it; | ||
187 | if (item->animated()) | ||
188 | continue; | ||
189 | item->setZ(highestZ); | ||
190 | highestZ++; | ||
191 | flipped++; | ||
192 | |||
193 | // Added Code | ||
194 | faceDownDealingPile->removeCard(item); | ||
195 | faceUpDealingPile->addCardToTop(item); | ||
196 | item->setCardPile( faceUpDealingPile ); | ||
197 | |||
198 | item->flipTo( 35, (int)item->y(), 8 * flipped ); | ||
199 | } | ||
200 | } | ||
201 | |||
202 | return TRUE; | ||
203 | } | ||
204 | |||
205 | return FALSE; | ||
206 | } | ||
207 | |||
208 | |||
209 | void PatienceCardGame::mousePress(QPoint p) | ||
210 | { | ||
211 | if ( canTurnOverDeck() && | ||
212 | (p.x() > 5) && (p.x() < 28) && | ||
213 | (p.y() > 10) && (p.y() < 46) ) { | ||
214 | |||
215 | beginDealing(); | ||
216 | Card *card = faceUpDealingPile->cardOnTop(); | ||
217 | while ( card ) { | ||
218 | card->setPos( 5, 10, highestZ ); | ||
219 | card->setFace( FALSE ); | ||
220 | faceUpDealingPile->removeCard( card ); | ||
221 | faceDownDealingPile->addCardToTop( card ); | ||
222 | card->setCardPile( faceDownDealingPile ); | ||
223 | card = faceUpDealingPile->cardOnTop(); | ||
224 | highestZ++; | ||
225 | } | ||
226 | endDealing(); | ||
227 | |||
228 | throughDeck(); | ||
229 | |||
230 | moved = TRUE; | ||
231 | } | ||
232 | } | ||
233 | |||
234 | |||
diff --git a/noncore/games/solitaire/patiencecardgame.h b/noncore/games/solitaire/patiencecardgame.h new file mode 100644 index 0000000..c4f6c48 --- a/dev/null +++ b/noncore/games/solitaire/patiencecardgame.h | |||
@@ -0,0 +1,206 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #ifndef PATIENCE_CARD_GAME_H | ||
21 | #define PATIENCE_CARD_GAME_H | ||
22 | |||
23 | |||
24 | #include <qpopupmenu.h> | ||
25 | #include <qmainwindow.h> | ||
26 | #include <qintdict.h> | ||
27 | #include <qcanvas.h> | ||
28 | // #include "canvascardshapes.h" | ||
29 | // #include "canvascard.h" | ||
30 | #include "canvascardgame.h" | ||
31 | |||
32 | |||
33 | class PatienceFaceDownDeck : public CardPile, public CanvasRoundRect | ||
34 | { | ||
35 | public: | ||
36 | PatienceFaceDownDeck(int x, int y, QCanvas *canvas) | ||
37 | : CardPile(x, y), CanvasRoundRect(x, y, canvas) { } | ||
38 | virtual bool isAllowedOnTop(Card *card) { | ||
39 | Q_UNUSED(card); | ||
40 | // Need to check it is from the faceUpDealingPile | ||
41 | return TRUE; | ||
42 | } | ||
43 | virtual bool isAllowedToBeMoved(Card *card) { | ||
44 | Q_UNUSED(card); | ||
45 | //if ( ( !card->isFacing() ) && ( card == cardOnTop() ) ) | ||
46 | if ( card == cardOnTop() ) | ||
47 | return TRUE; | ||
48 | return FALSE; | ||
49 | } | ||
50 | }; | ||
51 | |||
52 | |||
53 | class PatienceFaceUpDeck : public CardPile, public CanvasRoundRect | ||
54 | { | ||
55 | public: | ||
56 | PatienceFaceUpDeck(int x, int y, QCanvas *canvas) | ||
57 | : CardPile(x, y), CanvasRoundRect(x, y, canvas) { } | ||
58 | virtual bool isAllowedOnTop(Card *card) { | ||
59 | Q_UNUSED(card); | ||
60 | // Need to check it is from the faceDownDealingPile | ||
61 | return TRUE; | ||
62 | } | ||
63 | virtual bool isAllowedToBeMoved(Card *card) { | ||
64 | Q_UNUSED(card); | ||
65 | //if ( ( card->isFacing() ) && ( card == cardOnTop() ) ) | ||
66 | if ( card == cardOnTop() ) | ||
67 | return TRUE; | ||
68 | return FALSE; | ||
69 | } | ||
70 | }; | ||
71 | |||
72 | |||
73 | class PatienceDiscardPile : public CardPile, public CanvasRoundRect | ||
74 | { | ||
75 | public: | ||
76 | PatienceDiscardPile(int x, int y, QCanvas *canvas) | ||
77 | : CardPile(x, y), CanvasRoundRect(x, y, canvas) { } | ||
78 | virtual bool isAllowedOnTop(Card *card) { | ||
79 | if ( card->isFacing() && ( card->getCardPile()->cardInfront(card) == NULL ) && | ||
80 | ( ( ( cardOnTop() == NULL ) && ( card->getValue() == ace ) ) || | ||
81 | ( ( cardOnTop() != NULL ) && | ||
82 | ( (int)card->getValue() == (int)cardOnTop()->getValue() + 1 ) && | ||
83 | ( card->getSuit() == cardOnTop()->getSuit() ) ) ) ) | ||
84 | return TRUE; | ||
85 | return FALSE; | ||
86 | } | ||
87 | virtual bool isAllowedToBeMoved(Card *card) { | ||
88 | if ( card->isFacing() && ( card == cardOnTop() ) ) | ||
89 | return TRUE; | ||
90 | return FALSE; | ||
91 | } | ||
92 | }; | ||
93 | |||
94 | |||
95 | class PatienceWorkingPile : public CardPile, public CanvasRoundRect | ||
96 | { | ||
97 | public: | ||
98 | PatienceWorkingPile(int x, int y, QCanvas *canvas) | ||
99 | : CardPile(x, y), CanvasRoundRect(x, y, canvas), top(x, y) { } | ||
100 | virtual bool isAllowedOnTop(Card *card) { | ||
101 | if ( card->isFacing() && | ||
102 | ( ( ( cardOnTop() == NULL ) && (card->getValue() == king) ) || | ||
103 | ( ( cardOnTop() != NULL ) && | ||
104 | ( (int)card->getValue() + 1 == (int)cardOnTop()->getValue() ) && | ||
105 | ( card->isRed() != cardOnTop()->isRed() ) ) ) ) | ||
106 | return TRUE; | ||
107 | return FALSE; | ||
108 | } | ||
109 | virtual bool isAllowedToBeMoved(Card *card) { | ||
110 | if ( card->isFacing() ) | ||
111 | return TRUE; | ||
112 | return FALSE; | ||
113 | } | ||
114 | virtual void cardAddedToTop(Card *card) { | ||
115 | Q_UNUSED(card); | ||
116 | top = getCardPos(NULL); | ||
117 | setNextX( top.x() ); | ||
118 | setNextY( top.y() ); | ||
119 | } | ||
120 | virtual void cardRemoved(Card *card) { | ||
121 | Q_UNUSED(card); | ||
122 | |||
123 | Card *newTopCard = cardOnTop(); | ||
124 | |||
125 | if ( !newTopCard ) { | ||
126 | top = QPoint( pileX, pileY ); | ||
127 | setNextX( pileX ); | ||
128 | setNextY( pileY ); | ||
129 | return; | ||
130 | } else { | ||
131 | top = getCardPos(NULL); | ||
132 | if ( newTopCard->isFacing() == FALSE ) { | ||
133 | // correct the position taking in to account the card is not | ||
134 | // yet flipped, but will become flipped | ||
135 | top = QPoint( top.x() - 1, top.y() - 3 ); | ||
136 | newTopCard->flipTo( top.x(), top.y() ); | ||
137 | top = QPoint( top.x(), top.y() + 13 ); | ||
138 | } | ||
139 | setNextX( top.x() ); | ||
140 | setNextY( top.y() ); | ||
141 | } | ||
142 | } | ||
143 | virtual QPoint getCardPos(Card *c) { | ||
144 | int x = pileX, y = pileY; | ||
145 | Card *card = cardOnBottom(); | ||
146 | while ((card != c) && (card != NULL)) { | ||
147 | if (card->isFacing()) { | ||
148 | y += 13; | ||
149 | } else { | ||
150 | x += 1; | ||
151 | y += 3; | ||
152 | } | ||
153 | card = cardInfront(card); | ||
154 | } | ||
155 | return QPoint( x, y ); | ||
156 | } | ||
157 | virtual QPoint getHypertheticalNextCardPos(void) { | ||
158 | return top; | ||
159 | // return QPoint( getNextX(), getNextY() ); | ||
160 | } | ||
161 | private: | ||
162 | QPoint top; | ||
163 | |||
164 | }; | ||
165 | |||
166 | |||
167 | class PatienceCardGame : public CanvasCardGame | ||
168 | { | ||
169 | public: | ||
170 | PatienceCardGame(QCanvas *c, bool snap, QWidget *parent = 0); | ||
171 | virtual ~PatienceCardGame(); | ||
172 | virtual void deal(void); | ||
173 | virtual bool haveWeWon() { | ||
174 | return ( discardPiles[0]->kingOnTop() && | ||
175 | discardPiles[1]->kingOnTop() && | ||
176 | discardPiles[2]->kingOnTop() && | ||
177 | discardPiles[3]->kingOnTop() );; | ||
178 | } | ||
179 | virtual void mousePress(QPoint p); | ||
180 | virtual void mouseRelease(QPoint p) { Q_UNUSED(p); } | ||
181 | // virtual void mouseMove(QPoint p); | ||
182 | virtual bool mousePressCard(Card *card, QPoint p); | ||
183 | virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } | ||
184 | // virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } | ||
185 | bool canTurnOverDeck(void) { return (numberOfTimesThroughDeck != 3); } | ||
186 | void throughDeck(void) { | ||
187 | numberOfTimesThroughDeck++; | ||
188 | if (numberOfTimesThroughDeck == 3) | ||
189 | circleCross->setCross(); | ||
190 | } | ||
191 | bool snapOn; | ||
192 | virtual void writeConfig( Config& cfg ); | ||
193 | virtual void readConfig( Config& cfg ); | ||
194 | private: | ||
195 | CanvasCircleOrCross *circleCross; | ||
196 | CanvasRoundRect *rectangle; | ||
197 | PatienceWorkingPile *workingPiles[7]; | ||
198 | PatienceDiscardPile *discardPiles[4]; | ||
199 | PatienceFaceDownDeck *faceDownDealingPile; | ||
200 | PatienceFaceUpDeck *faceUpDealingPile; | ||
201 | int numberOfTimesThroughDeck; | ||
202 | }; | ||
203 | |||
204 | |||
205 | #endif | ||
206 | |||
diff --git a/noncore/games/solitaire/qpe-solitaire.control b/noncore/games/solitaire/qpe-solitaire.control new file mode 100644 index 0000000..71abb0c --- a/dev/null +++ b/noncore/games/solitaire/qpe-solitaire.control | |||
@@ -0,0 +1,9 @@ | |||
1 | Files: bin/patience apps/Games/patience.desktop pics/cards | ||
2 | Priority: optional | ||
3 | Section: qpe/games | ||
4 | Maintainer: Warwick Allison <warwick@trolltech.com> | ||
5 | Architecture: arm | ||
6 | Version: $QPE_VERSION-3 | ||
7 | Depends: qpe-base ($QPE_VERSION) | ||
8 | Description: Game: solitaire card games | ||
9 | A solitaire game for the Qtopia environment. | ||
diff --git a/noncore/games/solitaire/solitaire.pro b/noncore/games/solitaire/solitaire.pro new file mode 100755 index 0000000..8617cab --- a/dev/null +++ b/noncore/games/solitaire/solitaire.pro | |||
@@ -0,0 +1,18 @@ | |||
1 | TEMPLATE= app | ||
2 | |||
3 | CONFIG += qt warn_on release | ||
4 | DESTDIR = $(QPEDIR)/bin | ||
5 | |||
6 | HEADERS = canvascard.h canvasshapes.h cardgame.h cardgamelayout.h cardpile.h card.h carddeck.h canvascardgame.h freecellcardgame.h patiencecardgame.h canvascardwindow.h | ||
7 | |||
8 | SOURCES = canvascard.cpp canvasshapes.cpp cardgame.cpp cardgamelayout.cpp cardpile.cpp card.cpp carddeck.cpp canvascardgame.cpp freecellcardgame.cpp patiencecardgame.cpp canvascardwindow.cpp main.cpp | ||
9 | |||
10 | TARGET = patience | ||
11 | |||
12 | INCLUDEPATH += $(QPEDIR)/include | ||
13 | DEPENDPATH+= $(QPEDIR)/include | ||
14 | LIBS += -lqpe | ||
15 | |||
16 | REQUIRES= patience | ||
17 | |||
18 | TRANSLATIONS = ../i18n/de/patience.ts | ||