77 files changed, 2 insertions, 223 deletions
diff --git a/noncore/games/backgammon/backgammon.cpp b/noncore/games/backgammon/backgammon.cpp index e9e5467..51020a0 100644 --- a/noncore/games/backgammon/backgammon.cpp +++ b/noncore/games/backgammon/backgammon.cpp | |||
@@ -1,527 +1,524 @@ | |||
1 | #include "backgammon.h" | 1 | #include "backgammon.h" |
2 | 2 | ||
3 | #include "aidialog.h" | 3 | #include "aidialog.h" |
4 | #include "filedialog.h" | 4 | #include "filedialog.h" |
5 | #include "playerdialog.h" | 5 | #include "playerdialog.h" |
6 | #include "rulesdialog.h" | 6 | #include "rulesdialog.h" |
7 | #include "themedialog.h" | 7 | #include "themedialog.h" |
8 | 8 | ||
9 | #include <qdatetime.h> | ||
10 | #include <qfile.h> | 9 | #include <qfile.h> |
11 | #include <qlayout.h> | 10 | #include <qlayout.h> |
12 | #include <qmessagebox.h> | 11 | #include <qmessagebox.h> |
13 | #include <qstring.h> | ||
14 | #include <qtimer.h> | 12 | #include <qtimer.h> |
15 | #include <qmainwindow.h> | ||
16 | #include <qpe/qpeapplication.h> | 13 | #include <qpe/qpeapplication.h> |
17 | #include <qpe/config.h> | 14 | #include <qpe/config.h> |
18 | #include <qmenubar.h> | 15 | #include <qmenubar.h> |
19 | #include <qpe/resource.h> | 16 | #include <qpe/resource.h> |
20 | 17 | ||
21 | #include <stdlib.h> | 18 | #include <stdlib.h> |
22 | 19 | ||
23 | 20 | ||
24 | BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl) | 21 | BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl) |
25 | : QMainWindow(parent, name, fl) | 22 | : QMainWindow(parent, name, fl) |
26 | { | 23 | { |
27 | if (!name) setName("BackGammon"); | 24 | if (!name) setName("BackGammon"); |
28 | setCaption(tr( "Backgammon") ); | 25 | setCaption(tr( "Backgammon") ); |
29 | setIcon( Resource::loadPixmap( "backgammon" ) ); | 26 | setIcon( Resource::loadPixmap( "backgammon" ) ); |
30 | //general counter varaible | 27 | //general counter varaible |
31 | int a=0; | 28 | int a=0; |
32 | //the game engine | 29 | //the game engine |
33 | move=new MoveEngine(); | 30 | move=new MoveEngine(); |
34 | 31 | ||
35 | //load the default theme | 32 | //load the default theme |
36 | Config conf("backgammon"); | 33 | Config conf("backgammon"); |
37 | if(!conf.isValid()) | 34 | if(!conf.isValid()) |
38 | { | 35 | { |
39 | qDebug("config file does not exist"); | 36 | qDebug("config file does not exist"); |
40 | conf.setGroup("general"); | 37 | conf.setGroup("general"); |
41 | conf.writeEntry("theme","default"); | 38 | conf.writeEntry("theme","default"); |
42 | conf.setGroup("rules"); | 39 | conf.setGroup("rules"); |
43 | conf.writeEntry("move_with_pieces_out",false); | 40 | conf.writeEntry("move_with_pieces_out",false); |
44 | conf.writeEntry("nice_dice",false); | 41 | conf.writeEntry("nice_dice",false); |
45 | conf.setGroup("display"); | 42 | conf.setGroup("display"); |
46 | conf.writeEntry("small",false); | 43 | conf.writeEntry("small",false); |
47 | conf.writeEntry("warning",true); | 44 | conf.writeEntry("warning",true); |
48 | conf.setGroup("ai"); | 45 | conf.setGroup("ai"); |
49 | conf.writeEntry("rescue",6); | 46 | conf.writeEntry("rescue",6); |
50 | conf.writeEntry("eliminate",4); | 47 | conf.writeEntry("eliminate",4); |
51 | conf.writeEntry("expose",1); | 48 | conf.writeEntry("expose",1); |
52 | conf.writeEntry("protect",5); | 49 | conf.writeEntry("protect",5); |
53 | conf.writeEntry("safe",3); | 50 | conf.writeEntry("safe",3); |
54 | conf.writeEntry("empty",2); | 51 | conf.writeEntry("empty",2); |
55 | 52 | ||
56 | } | 53 | } |
57 | conf.setGroup("general"); | 54 | conf.setGroup("general"); |
58 | theme_name=conf.readEntry("theme","default"); | 55 | theme_name=conf.readEntry("theme","default"); |
59 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; | 56 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; |
60 | 57 | ||
61 | //the rules | 58 | //the rules |
62 | conf.setGroup("rules"); | 59 | conf.setGroup("rules"); |
63 | rules.move_with_pieces_out=conf.readBoolEntry("move_with_pieces_out",false); | 60 | rules.move_with_pieces_out=conf.readBoolEntry("move_with_pieces_out",false); |
64 | rules.generous_dice=conf.readBoolEntry("nice_dice",false); | 61 | rules.generous_dice=conf.readBoolEntry("nice_dice",false); |
65 | 62 | ||
66 | move->setRules(rules); | 63 | move->setRules(rules); |
67 | 64 | ||
68 | //get the AI settings | 65 | //get the AI settings |
69 | AISettings ai; | 66 | AISettings ai; |
70 | conf.setGroup("ai"); | 67 | conf.setGroup("ai"); |
71 | ai.rescue=conf.readNumEntry("rescue",6); | 68 | ai.rescue=conf.readNumEntry("rescue",6); |
72 | ai.eliminate=conf.readNumEntry("eliminate",4); | 69 | ai.eliminate=conf.readNumEntry("eliminate",4); |
73 | ai.expose=conf.readNumEntry("expose",1); | 70 | ai.expose=conf.readNumEntry("expose",1); |
74 | ai.protect=conf.readNumEntry("protect",5); | 71 | ai.protect=conf.readNumEntry("protect",5); |
75 | ai.safe=conf.readNumEntry("safe",3); | 72 | ai.safe=conf.readNumEntry("safe",3); |
76 | ai.empty=conf.readNumEntry("empty",2); | 73 | ai.empty=conf.readNumEntry("empty",2); |
77 | move->setAISettings(ai); | 74 | move->setAISettings(ai); |
78 | 75 | ||
79 | 76 | ||
80 | //get the theme component names | 77 | //get the theme component names |
81 | Config theme(theme_file,Config::File); | 78 | Config theme(theme_file,Config::File); |
82 | if(!theme.isValid()) | 79 | if(!theme.isValid()) |
83 | { | 80 | { |
84 | qDebug("theme file does not exist"); | 81 | qDebug("theme file does not exist"); |
85 | theme.setGroup("theme"); | 82 | theme.setGroup("theme"); |
86 | theme.writeEntry("board","casino_board_1"); | 83 | theme.writeEntry("board","casino_board_1"); |
87 | theme.writeEntry("pieces1","casino_pieces_blue"); | 84 | theme.writeEntry("pieces1","casino_pieces_blue"); |
88 | theme.writeEntry("pieces2","casino_pieces_white"); | 85 | theme.writeEntry("pieces2","casino_pieces_white"); |
89 | theme.writeEntry("dice1","casino_dice"); | 86 | theme.writeEntry("dice1","casino_dice"); |
90 | theme.writeEntry("dice2","casino_dice"); | 87 | theme.writeEntry("dice2","casino_dice"); |
91 | theme.writeEntry("table","casino_table_green"); | 88 | theme.writeEntry("table","casino_table_green"); |
92 | theme.writeEntry("odds","casino_odds"); | 89 | theme.writeEntry("odds","casino_odds"); |
93 | } | 90 | } |
94 | theme.setGroup("theme"); | 91 | theme.setGroup("theme"); |
95 | board_name=theme.readEntry("board","casino_board_1"); | 92 | board_name=theme.readEntry("board","casino_board_1"); |
96 | piecesA_name=theme.readEntry("pieces1","casino_pieces_blue"); | 93 | piecesA_name=theme.readEntry("pieces1","casino_pieces_blue"); |
97 | piecesB_name=theme.readEntry("pieces2","casino_pieces_white"); | 94 | piecesB_name=theme.readEntry("pieces2","casino_pieces_white"); |
98 | diceA_name=theme.readEntry("dice1","casino_dice"); | 95 | diceA_name=theme.readEntry("dice1","casino_dice"); |
99 | diceB_name=theme.readEntry("dice2","casino_dice"); | 96 | diceB_name=theme.readEntry("dice2","casino_dice"); |
100 | table_name=theme.readEntry("table","casino_table_green"); | 97 | table_name=theme.readEntry("table","casino_table_green"); |
101 | odds_name=theme.readEntry("odds","casino_odds"); | 98 | odds_name=theme.readEntry("odds","casino_odds"); |
102 | 99 | ||
103 | 100 | ||
104 | //the menu | 101 | //the menu |
105 | QMenuBar* menuBar = new QMenuBar(this); | 102 | QMenuBar* menuBar = new QMenuBar(this); |
106 | 103 | ||
107 | QPopupMenu* gamemenu= new QPopupMenu(this); | 104 | QPopupMenu* gamemenu= new QPopupMenu(this); |
108 | gamemenu->insertItem(tr( "New" ),this,SLOT(newgame())); | 105 | gamemenu->insertItem(tr( "New" ),this,SLOT(newgame())); |
109 | gamemenu->insertSeparator(); | 106 | gamemenu->insertSeparator(); |
110 | gamemenu->insertItem(tr( "Load" ),this,SLOT(loadgame())); | 107 | gamemenu->insertItem(tr( "Load" ),this,SLOT(loadgame())); |
111 | gamemenu->insertItem(tr( "Save" ),this,SLOT(savegame())); | 108 | gamemenu->insertItem(tr( "Save" ),this,SLOT(savegame())); |
112 | gamemenu->insertSeparator(); | 109 | gamemenu->insertSeparator(); |
113 | gamemenu->insertItem(tr( "Delete" ),this,SLOT(deletegame())); | 110 | gamemenu->insertItem(tr( "Delete" ),this,SLOT(deletegame())); |
114 | menuBar->insertItem(tr( "Game" ),gamemenu); | 111 | menuBar->insertItem(tr( "Game" ),gamemenu); |
115 | 112 | ||
116 | QPopupMenu* thememenu= new QPopupMenu(this); | 113 | QPopupMenu* thememenu= new QPopupMenu(this); |
117 | thememenu->insertItem(tr( "New" ),this,SLOT(newtheme())); | 114 | thememenu->insertItem(tr( "New" ),this,SLOT(newtheme())); |
118 | thememenu->insertSeparator(); | 115 | thememenu->insertSeparator(); |
119 | thememenu->insertItem(tr( "Load"),this,SLOT(loadtheme())); | 116 | thememenu->insertItem(tr( "Load"),this,SLOT(loadtheme())); |
120 | thememenu->insertItem(tr( "Save" ),this,SLOT(savetheme())); | 117 | thememenu->insertItem(tr( "Save" ),this,SLOT(savetheme())); |
121 | thememenu->insertSeparator(); | 118 | thememenu->insertSeparator(); |
122 | thememenu->insertItem(tr( "Default"),this,SLOT(themedefault())); | 119 | thememenu->insertItem(tr( "Default"),this,SLOT(themedefault())); |
123 | thememenu->insertItem(tr( "Delete" ),this,SLOT(deletetheme())); | 120 | thememenu->insertItem(tr( "Delete" ),this,SLOT(deletetheme())); |
124 | menuBar->insertItem(tr( "Theme" ),thememenu); | 121 | menuBar->insertItem(tr( "Theme" ),thememenu); |
125 | 122 | ||
126 | QPopupMenu* optionmenu=new QPopupMenu(this); | 123 | QPopupMenu* optionmenu=new QPopupMenu(this); |
127 | optionmenu->insertItem(tr( "Player" ),this,SLOT(playerselect())); | 124 | optionmenu->insertItem(tr( "Player" ),this,SLOT(playerselect())); |
128 | optionmenu->insertSeparator(); | 125 | optionmenu->insertSeparator(); |
129 | optionmenu->insertItem(tr( "AI" ),this,SLOT(modify_AI())); | 126 | optionmenu->insertItem(tr( "AI" ),this,SLOT(modify_AI())); |
130 | optionmenu->insertItem(tr( "Rules" ),this,SLOT(setrules())); | 127 | optionmenu->insertItem(tr( "Rules" ),this,SLOT(setrules())); |
131 | menuBar->insertItem(tr( "Options"),optionmenu); | 128 | menuBar->insertItem(tr( "Options"),optionmenu); |
132 | 129 | ||
133 | QWidget* mainarea=new QWidget(this); | 130 | QWidget* mainarea=new QWidget(this); |
134 | setCentralWidget(mainarea); | 131 | setCentralWidget(mainarea); |
135 | //the main area | 132 | //the main area |
136 | QBoxLayout* layout=new QBoxLayout(mainarea,QBoxLayout::TopToBottom); | 133 | QBoxLayout* layout=new QBoxLayout(mainarea,QBoxLayout::TopToBottom); |
137 | area=new QCanvas(235,235); | 134 | area=new QCanvas(235,235); |
138 | boardview=new BackGammonView(area,mainarea); | 135 | boardview=new BackGammonView(area,mainarea); |
139 | boardview->setMaximumHeight(240); | 136 | boardview->setMaximumHeight(240); |
140 | layout->addWidget(boardview); | 137 | layout->addWidget(boardview); |
141 | connect(boardview,SIGNAL(mouse(int,int)),this,SLOT(mouse(int,int))); | 138 | connect(boardview,SIGNAL(mouse(int,int)),this,SLOT(mouse(int,int))); |
142 | //status bar | 139 | //status bar |
143 | message=new QLabel("<b>Backgammon</b>",mainarea); | 140 | message=new QLabel("<b>Backgammon</b>",mainarea); |
144 | message->setAlignment(AlignHCenter); | 141 | message->setAlignment(AlignHCenter); |
145 | layout->addWidget(message); | 142 | layout->addWidget(message); |
146 | 143 | ||
147 | //the marker | 144 | //the marker |
148 | marker_current=new QCanvasRectangle(area); | 145 | marker_current=new QCanvasRectangle(area); |
149 | marker_current->setBrush(QColor(0,0,255)); | 146 | marker_current->setBrush(QColor(0,0,255)); |
150 | marker_current->setSize(15,5); | 147 | marker_current->setSize(15,5); |
151 | marker_current->setZ(1); | 148 | marker_current->setZ(1); |
152 | 149 | ||
153 | for(a=0;a<4;a++) | 150 | for(a=0;a<4;a++) |
154 | { | 151 | { |
155 | marker_next[a]=new QCanvasRectangle(area); | 152 | marker_next[a]=new QCanvasRectangle(area); |
156 | marker_next[a]->setBrush(QColor(0,255,0)); | 153 | marker_next[a]->setBrush(QColor(0,255,0)); |
157 | marker_next[a]->setSize(15,5); | 154 | marker_next[a]->setSize(15,5); |
158 | marker_next[a]->setZ(1); | 155 | marker_next[a]->setZ(1); |
159 | } | 156 | } |
160 | 157 | ||
161 | connect(move,SIGNAL(done_dice1()),this,SLOT(done_dice1())); | 158 | connect(move,SIGNAL(done_dice1()),this,SLOT(done_dice1())); |
162 | connect(move,SIGNAL(done_dice2()),this,SLOT(done_dice2())); | 159 | connect(move,SIGNAL(done_dice2()),this,SLOT(done_dice2())); |
163 | connect(move,SIGNAL(done_dice3()),this,SLOT(done_dice3())); | 160 | connect(move,SIGNAL(done_dice3()),this,SLOT(done_dice3())); |
164 | connect(move,SIGNAL(done_dice4()),this,SLOT(done_dice4())); | 161 | connect(move,SIGNAL(done_dice4()),this,SLOT(done_dice4())); |
165 | connect(move,SIGNAL(nomove()),this,SLOT(nomove())); | 162 | connect(move,SIGNAL(nomove()),this,SLOT(nomove())); |
166 | connect(move,SIGNAL(player_finished(int)),this,SLOT(finished(int))); | 163 | connect(move,SIGNAL(player_finished(int)),this,SLOT(finished(int))); |
167 | 164 | ||
168 | //the pieces | 165 | //the pieces |
169 | p1=new CanvasImageItem*[15]; | 166 | p1=new CanvasImageItem*[15]; |
170 | p1_side=new CanvasImageItem*[15]; | 167 | p1_side=new CanvasImageItem*[15]; |
171 | QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name)); | 168 | QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name)); |
172 | QImage piece_1_front=piece_1_all.copy(0,0,15,15); | 169 | QImage piece_1_front=piece_1_all.copy(0,0,15,15); |
173 | QImage piece_1_side=piece_1_all.copy(0,15,15,5); | 170 | QImage piece_1_side=piece_1_all.copy(0,15,15,5); |
174 | 171 | ||
175 | p2=new CanvasImageItem*[15]; | 172 | p2=new CanvasImageItem*[15]; |
176 | p2_side=new CanvasImageItem*[15]; | 173 | p2_side=new CanvasImageItem*[15]; |
177 | QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name)); | 174 | QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name)); |
178 | QImage piece_2_front=piece_2_all.copy(0,0,15,15); | 175 | QImage piece_2_front=piece_2_all.copy(0,0,15,15); |
179 | QImage piece_2_side=piece_2_all.copy(0,15,15,5); | 176 | QImage piece_2_side=piece_2_all.copy(0,15,15,5); |
180 | 177 | ||
181 | 178 | ||
182 | for(a=0;a<15;a++) | 179 | for(a=0;a<15;a++) |
183 | { | 180 | { |
184 | p1[a]=new CanvasImageItem(piece_1_front,area); | 181 | p1[a]=new CanvasImageItem(piece_1_front,area); |
185 | p1[a]->setSize(15,15); | 182 | p1[a]->setSize(15,15); |
186 | p1_side[a]=new CanvasImageItem(piece_1_side,area); | 183 | p1_side[a]=new CanvasImageItem(piece_1_side,area); |
187 | p1_side[a]->setSize(15,5); | 184 | p1_side[a]->setSize(15,5); |
188 | 185 | ||
189 | p2[a]=new CanvasImageItem(piece_2_front,area); | 186 | p2[a]=new CanvasImageItem(piece_2_front,area); |
190 | p2[a]->setSize(15,15); | 187 | p2[a]->setSize(15,15); |
191 | p2_side[a]=new CanvasImageItem(piece_2_side,area); | 188 | p2_side[a]=new CanvasImageItem(piece_2_side,area); |
192 | p2_side[a]->setSize(15,5); | 189 | p2_side[a]->setSize(15,5); |
193 | } | 190 | } |
194 | draw(); | 191 | draw(); |
195 | 192 | ||
196 | //the dice | 193 | //the dice |
197 | QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name)); | 194 | QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name)); |
198 | diceA1=new CanvasImageItem*[7]; | 195 | diceA1=new CanvasImageItem*[7]; |
199 | diceA2=new CanvasImageItem*[7]; | 196 | diceA2=new CanvasImageItem*[7]; |
200 | QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name)); | 197 | QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name)); |
201 | diceB1=new CanvasImageItem*[7]; | 198 | diceB1=new CanvasImageItem*[7]; |
202 | diceB2=new CanvasImageItem*[7]; | 199 | diceB2=new CanvasImageItem*[7]; |
203 | QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name)); | 200 | QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name)); |
204 | //oddsDice=new CanvasImageItem*[6]; | 201 | //oddsDice=new CanvasImageItem*[6]; |
205 | 202 | ||
206 | 203 | ||
207 | for(a=0;a<7;a++) | 204 | for(a=0;a<7;a++) |
208 | { | 205 | { |
209 | QImage dicebgA=dicebgA_all.copy(a*25,0,25,25); | 206 | QImage dicebgA=dicebgA_all.copy(a*25,0,25,25); |
210 | diceA1[a]=new CanvasImageItem(dicebgA,area); | 207 | diceA1[a]=new CanvasImageItem(dicebgA,area); |
211 | diceA1[a]->setX(5); | 208 | diceA1[a]->setX(5); |
212 | diceA1[a]->setY(205-2); | 209 | diceA1[a]->setY(205-2); |
213 | diceA1[a]->setZ(1); | 210 | diceA1[a]->setZ(1); |
214 | diceA1[a]->setSize(25,25); | 211 | diceA1[a]->setSize(25,25); |
215 | diceA2[a]=new CanvasImageItem(dicebgA,area); | 212 | diceA2[a]=new CanvasImageItem(dicebgA,area); |
216 | diceA2[a]->setX(35); | 213 | diceA2[a]->setX(35); |
217 | diceA2[a]->setY(205-2); | 214 | diceA2[a]->setY(205-2); |
218 | diceA2[a]->setZ(1); | 215 | diceA2[a]->setZ(1); |
219 | diceA2[a]->setSize(25,25); | 216 | diceA2[a]->setSize(25,25); |
220 | 217 | ||
221 | QImage dicebgB=dicebgB_all.copy(a*25,0,25,25); | 218 | QImage dicebgB=dicebgB_all.copy(a*25,0,25,25); |
222 | diceB1[a]=new CanvasImageItem(dicebgB,area); | 219 | diceB1[a]=new CanvasImageItem(dicebgB,area); |
223 | diceB1[a]->setX(175); | 220 | diceB1[a]->setX(175); |
224 | diceB1[a]->setY(205-2); | 221 | diceB1[a]->setY(205-2); |
225 | diceB1[a]->setZ(1); | 222 | diceB1[a]->setZ(1); |
226 | diceB1[a]->setSize(25,25); | 223 | diceB1[a]->setSize(25,25); |
227 | diceB2[a]=new CanvasImageItem(dicebgB,area); | 224 | diceB2[a]=new CanvasImageItem(dicebgB,area); |
228 | diceB2[a]->setX(205); | 225 | diceB2[a]->setX(205); |
229 | diceB2[a]->setY(205-2); | 226 | diceB2[a]->setY(205-2); |
230 | diceB2[a]->setZ(1); | 227 | diceB2[a]->setZ(1); |
231 | diceB2[a]->setSize(25,25); | 228 | diceB2[a]->setSize(25,25); |
232 | 229 | ||
233 | /* | 230 | /* |
234 | if(a<6) | 231 | if(a<6) |
235 | { | 232 | { |
236 | QImage oddsbg=oddsbg_all.copy(a*15,0,15,15); | 233 | QImage oddsbg=oddsbg_all.copy(a*15,0,15,15); |
237 | oddsDice[a]=new CanvasImageItem(oddsbg,area); | 234 | oddsDice[a]=new CanvasImageItem(oddsbg,area); |
238 | oddsDice[a]->setX(110); | 235 | oddsDice[a]->setX(110); |
239 | oddsDice[a]->setY(210-2); | 236 | oddsDice[a]->setY(210-2); |
240 | oddsDice[a]->setZ(1); | 237 | oddsDice[a]->setZ(1); |
241 | oddsDice[a]->setSize(15,15); | 238 | oddsDice[a]->setSize(15,15); |
242 | oddsDice[a]->hide(); | 239 | oddsDice[a]->hide(); |
243 | } | 240 | } |
244 | */ | 241 | */ |
245 | } | 242 | } |
246 | //oddsDice[0]->show(); | 243 | //oddsDice[0]->show(); |
247 | 244 | ||
248 | //set the board | 245 | //set the board |
249 | QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name)); | 246 | QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name)); |
250 | board=new CanvasImageItem(boardbg,area); | 247 | board=new CanvasImageItem(boardbg,area); |
251 | board->setX(0); | 248 | board->setX(0); |
252 | board->setY(0); | 249 | board->setY(0); |
253 | board->setZ(0); | 250 | board->setZ(0); |
254 | board->setSize(235-2,200-2); | 251 | board->setSize(235-2,200-2); |
255 | board->show(); | 252 | board->show(); |
256 | 253 | ||
257 | //the table | 254 | //the table |
258 | QImage tablebg(Resource::loadImage("backgammon/table/"+table_name)); | 255 | QImage tablebg(Resource::loadImage("backgammon/table/"+table_name)); |
259 | table=new CanvasImageItem(tablebg,area); | 256 | table=new CanvasImageItem(tablebg,area); |
260 | table->setX(0); | 257 | table->setX(0); |
261 | table->setY(200-2); | 258 | table->setY(200-2); |
262 | table->setZ(0); | 259 | table->setZ(0); |
263 | table->setSize(235-2,20); | 260 | table->setSize(235-2,20); |
264 | table->show(); | 261 | table->show(); |
265 | 262 | ||
266 | //the no move marker | 263 | //the no move marker |
267 | QImage nomovebg(Resource::loadImage("backgammon/no_move")); | 264 | QImage nomovebg(Resource::loadImage("backgammon/no_move")); |
268 | nomove_marker=new CanvasImageItem(nomovebg,area); | 265 | nomove_marker=new CanvasImageItem(nomovebg,area); |
269 | nomove_marker->setX(0); | 266 | nomove_marker->setX(0); |
270 | nomove_marker->setY(200); | 267 | nomove_marker->setY(200); |
271 | nomove_marker->setZ(2); | 268 | nomove_marker->setZ(2); |
272 | nomove_marker->hide(); | 269 | nomove_marker->hide(); |
273 | 270 | ||
274 | //default human against computer | 271 | //default human against computer |
275 | player1_auto=false; | 272 | player1_auto=false; |
276 | player2_auto=true; | 273 | player2_auto=true; |
277 | //start new game | 274 | //start new game |
278 | newgame(); | 275 | newgame(); |
279 | } | 276 | } |
280 | 277 | ||
281 | BackGammon::~BackGammon() | 278 | BackGammon::~BackGammon() |
282 | { | 279 | { |
283 | //DESTRUCTOR | 280 | //DESTRUCTOR |
284 | } | 281 | } |
285 | 282 | ||
286 | void BackGammon::newgame() | 283 | void BackGammon::newgame() |
287 | { | 284 | { |
288 | gameFinished=false; | 285 | gameFinished=false; |
289 | QDateTime now=QDateTime::currentDateTime(); | 286 | QDateTime now=QDateTime::currentDateTime(); |
290 | game_name=now.date().toString()+"_"+now.time().toString(); | 287 | game_name=now.date().toString()+"_"+now.time().toString(); |
291 | move->reset(); | 288 | move->reset(); |
292 | draw(); | 289 | draw(); |
293 | diceA1_value=7; | 290 | diceA1_value=7; |
294 | diceA2_value=7; | 291 | diceA2_value=7; |
295 | diceA3_value=7; | 292 | diceA3_value=7; |
296 | diceA4_value=7; | 293 | diceA4_value=7; |
297 | diceB1_value=7; | 294 | diceB1_value=7; |
298 | diceB2_value=7; | 295 | diceB2_value=7; |
299 | diceB3_value=7; | 296 | diceB3_value=7; |
300 | diceB4_value=7; | 297 | diceB4_value=7; |
301 | showdice(); | 298 | showdice(); |
302 | player=2; | 299 | player=2; |
303 | dice1_played=true; | 300 | dice1_played=true; |
304 | dice2_played=true; | 301 | dice2_played=true; |
305 | dice3_played=true; | 302 | dice3_played=true; |
306 | dice4_played=true; | 303 | dice4_played=true; |
307 | dice_rolled=false; | 304 | dice_rolled=false; |
308 | setplayer(); | 305 | setplayer(); |
309 | area->update(); | 306 | area->update(); |
310 | } | 307 | } |
311 | 308 | ||
312 | void BackGammon::playerselect() | 309 | void BackGammon::playerselect() |
313 | { | 310 | { |
314 | PlayerDialog* playerdialog=new PlayerDialog(this); | 311 | PlayerDialog* playerdialog=new PlayerDialog(this); |
315 | playerdialog->setAuto1(player1_auto); | 312 | playerdialog->setAuto1(player1_auto); |
316 | playerdialog->setAuto2(player2_auto); | 313 | playerdialog->setAuto2(player2_auto); |
317 | if(!playerdialog->exec()) | 314 | if(!playerdialog->exec()) |
318 | return; | 315 | return; |
319 | player1_auto=playerdialog->getAuto1(); | 316 | player1_auto=playerdialog->getAuto1(); |
320 | player2_auto=playerdialog->getAuto2(); | 317 | player2_auto=playerdialog->getAuto2(); |
321 | } | 318 | } |
322 | 319 | ||
323 | void BackGammon::loadgame() | 320 | void BackGammon::loadgame() |
324 | { | 321 | { |
325 | FileDialog* file=new FileDialog(this,"Load Game",".game"); | 322 | FileDialog* file=new FileDialog(this,"Load Game",".game"); |
326 | if(!file->exec()) | 323 | if(!file->exec()) |
327 | return; | 324 | return; |
328 | 325 | ||
329 | game_name=file->filename(); | 326 | game_name=file->filename(); |
330 | QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; | 327 | QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; |
331 | 328 | ||
332 | Config game(game_file,Config::File); | 329 | Config game(game_file,Config::File); |
333 | game.setGroup("dice"); | 330 | game.setGroup("dice"); |
334 | diceA1_value=game.readNumEntry("diceA1_value"); | 331 | diceA1_value=game.readNumEntry("diceA1_value"); |
335 | diceA2_value=game.readNumEntry("diceA2_value"); | 332 | diceA2_value=game.readNumEntry("diceA2_value"); |
336 | diceA3_value=game.readNumEntry("diceA3_value"); | 333 | diceA3_value=game.readNumEntry("diceA3_value"); |
337 | diceA4_value=game.readNumEntry("diceA4_value"); | 334 | diceA4_value=game.readNumEntry("diceA4_value"); |
338 | diceB1_value=game.readNumEntry("diceB1_value"); | 335 | diceB1_value=game.readNumEntry("diceB1_value"); |
339 | diceB2_value=game.readNumEntry("diceB2_value"); | 336 | diceB2_value=game.readNumEntry("diceB2_value"); |
340 | diceB3_value=game.readNumEntry("diceB3_value"); | 337 | diceB3_value=game.readNumEntry("diceB3_value"); |
341 | diceB4_value=game.readNumEntry("diceB4_value"); | 338 | diceB4_value=game.readNumEntry("diceB4_value"); |
342 | player=game.readNumEntry("player"); | 339 | player=game.readNumEntry("player"); |
343 | dice1_played=game.readBoolEntry("dice1_played"); | 340 | dice1_played=game.readBoolEntry("dice1_played"); |
344 | dice2_played=game.readBoolEntry("dice2_played"); | 341 | dice2_played=game.readBoolEntry("dice2_played"); |
345 | dice3_played=game.readBoolEntry("dice3_played"); | 342 | dice3_played=game.readBoolEntry("dice3_played"); |
346 | dice4_played=game.readBoolEntry("dice4_played"); | 343 | dice4_played=game.readBoolEntry("dice4_played"); |
347 | dice_rolled=game.readBoolEntry("dice_rolled"); | 344 | dice_rolled=game.readBoolEntry("dice_rolled"); |
348 | player1_auto=game.readBoolEntry("player1_auto"); | 345 | player1_auto=game.readBoolEntry("player1_auto"); |
349 | player2_auto=game.readBoolEntry("player2_auto"); | 346 | player2_auto=game.readBoolEntry("player2_auto"); |
350 | 347 | ||
351 | game.setGroup("pieces"); | 348 | game.setGroup("pieces"); |
352 | QString label; | 349 | QString label; |
353 | LoadSave load; | 350 | LoadSave load; |
354 | for(int a=0;a<28;a++) | 351 | for(int a=0;a<28;a++) |
355 | { | 352 | { |
356 | label.setNum(a); | 353 | label.setNum(a); |
357 | load.pop[a].total = game.readNumEntry(label,0); | 354 | load.pop[a].total = game.readNumEntry(label,0); |
358 | } | 355 | } |
359 | 356 | ||
360 | move->loadGame(load); | 357 | move->loadGame(load); |
361 | setplayer(); | 358 | setplayer(); |
362 | showdice(); | 359 | showdice(); |
363 | draw(); | 360 | draw(); |
364 | area->update(); | 361 | area->update(); |
365 | } | 362 | } |
366 | 363 | ||
367 | void BackGammon::savegame() | 364 | void BackGammon::savegame() |
368 | { | 365 | { |
369 | QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; | 366 | QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; |
370 | 367 | ||
371 | Config game(game_file,Config::File); | 368 | Config game(game_file,Config::File); |
372 | game.setGroup("dice"); | 369 | game.setGroup("dice"); |
373 | game.writeEntry("diceA1_value",diceA1_value); | 370 | game.writeEntry("diceA1_value",diceA1_value); |
374 | game.writeEntry("diceA2_value",diceA2_value); | 371 | game.writeEntry("diceA2_value",diceA2_value); |
375 | game.writeEntry("diceA3_value",diceA3_value); | 372 | game.writeEntry("diceA3_value",diceA3_value); |
376 | game.writeEntry("diceA4_value",diceA4_value); | 373 | game.writeEntry("diceA4_value",diceA4_value); |
377 | game.writeEntry("diceB1_value",diceB1_value); | 374 | game.writeEntry("diceB1_value",diceB1_value); |
378 | game.writeEntry("diceB2_value",diceB3_value); | 375 | game.writeEntry("diceB2_value",diceB3_value); |
379 | game.writeEntry("diceB3_value",diceB4_value); | 376 | game.writeEntry("diceB3_value",diceB4_value); |
380 | game.writeEntry("diceB4_value",diceB4_value); | 377 | game.writeEntry("diceB4_value",diceB4_value); |
381 | game.writeEntry("player",player); | 378 | game.writeEntry("player",player); |
382 | game.writeEntry("dice1_played",dice1_played); | 379 | game.writeEntry("dice1_played",dice1_played); |
383 | game.writeEntry("dice2_played",dice2_played); | 380 | game.writeEntry("dice2_played",dice2_played); |
384 | game.writeEntry("dice3_played",dice3_played); | 381 | game.writeEntry("dice3_played",dice3_played); |
385 | game.writeEntry("dice4_played",dice4_played); | 382 | game.writeEntry("dice4_played",dice4_played); |
386 | game.writeEntry("dice_rolled",dice_rolled); | 383 | game.writeEntry("dice_rolled",dice_rolled); |
387 | game.writeEntry("player1_auto",player1_auto); | 384 | game.writeEntry("player1_auto",player1_auto); |
388 | game.writeEntry("player2_auto",player2_auto); | 385 | game.writeEntry("player2_auto",player2_auto); |
389 | 386 | ||
390 | game.setGroup("pieces"); | 387 | game.setGroup("pieces"); |
391 | QString label; | 388 | QString label; |
392 | LoadSave save=move->saveGame(); | 389 | LoadSave save=move->saveGame(); |
393 | for(int a=0;a<28;a++) | 390 | for(int a=0;a<28;a++) |
394 | { | 391 | { |
395 | label.setNum(a); | 392 | label.setNum(a); |
396 | game.writeEntry(label,save.pop[a].total); | 393 | game.writeEntry(label,save.pop[a].total); |
397 | } | 394 | } |
398 | QMessageBox::information(this,"Backgammon","Game saved","OK"); | 395 | QMessageBox::information(this,"Backgammon","Game saved","OK"); |
399 | } | 396 | } |
400 | 397 | ||
401 | void BackGammon::deletegame() | 398 | void BackGammon::deletegame() |
402 | { | 399 | { |
403 | FileDialog* file=new FileDialog(this,"Delete Game",".game"); | 400 | FileDialog* file=new FileDialog(this,"Delete Game",".game"); |
404 | if(!file->exec()) | 401 | if(!file->exec()) |
405 | return; | 402 | return; |
406 | 403 | ||
407 | game_name=file->filename(); | 404 | game_name=file->filename(); |
408 | QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; | 405 | QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; |
409 | 406 | ||
410 | if(!QMessageBox::warning(this,"Backgammon","deleted game\n"+game_name+" ?","OK","Cancel")) | 407 | if(!QMessageBox::warning(this,"Backgammon","deleted game\n"+game_name+" ?","OK","Cancel")) |
411 | { | 408 | { |
412 | QFile(game_file).remove(); | 409 | QFile(game_file).remove(); |
413 | } | 410 | } |
414 | } | 411 | } |
415 | 412 | ||
416 | 413 | ||
417 | void BackGammon::newtheme() | 414 | void BackGammon::newtheme() |
418 | { | 415 | { |
419 | ThemeDialog* theme=new ThemeDialog(this); | 416 | ThemeDialog* theme=new ThemeDialog(this); |
420 | 417 | ||
421 | ImageNames names; | 418 | ImageNames names; |
422 | names.theme=theme_name; | 419 | names.theme=theme_name; |
423 | names.board=board_name; | 420 | names.board=board_name; |
424 | names.pieces1=piecesA_name; | 421 | names.pieces1=piecesA_name; |
425 | names.pieces2=piecesB_name; | 422 | names.pieces2=piecesB_name; |
426 | names.dice1=diceA_name; | 423 | names.dice1=diceA_name; |
427 | names.dice2=diceB_name; | 424 | names.dice2=diceB_name; |
428 | names.odds=odds_name; | 425 | names.odds=odds_name; |
429 | names.table=table_name; | 426 | names.table=table_name; |
430 | 427 | ||
431 | theme->setCurrent(names); | 428 | theme->setCurrent(names); |
432 | if(!theme->exec()) | 429 | if(!theme->exec()) |
433 | return; | 430 | return; |
434 | 431 | ||
435 | names=theme->getNames(); | 432 | names=theme->getNames(); |
436 | theme_name=names.theme; | 433 | theme_name=names.theme; |
437 | board_name=names.board; | 434 | board_name=names.board; |
438 | piecesA_name=names.pieces1; | 435 | piecesA_name=names.pieces1; |
439 | piecesB_name=names.pieces2; | 436 | piecesB_name=names.pieces2; |
440 | diceA_name=names.dice1; | 437 | diceA_name=names.dice1; |
441 | diceB_name=names.dice2; | 438 | diceB_name=names.dice2; |
442 | odds_name=names.odds; | 439 | odds_name=names.odds; |
443 | table_name=names.table; | 440 | table_name=names.table; |
444 | 441 | ||
445 | applytheme(); | 442 | applytheme(); |
446 | } | 443 | } |
447 | 444 | ||
448 | void BackGammon::loadtheme() | 445 | void BackGammon::loadtheme() |
449 | { | 446 | { |
450 | FileDialog* file=new FileDialog(this,"Load Theme",".theme"); | 447 | FileDialog* file=new FileDialog(this,"Load Theme",".theme"); |
451 | if(!file->exec()) | 448 | if(!file->exec()) |
452 | return; | 449 | return; |
453 | 450 | ||
454 | theme_name=file->filename(); | 451 | theme_name=file->filename(); |
455 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; | 452 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; |
456 | 453 | ||
457 | Config theme(theme_file,Config::File); | 454 | Config theme(theme_file,Config::File); |
458 | theme.setGroup("theme"); | 455 | theme.setGroup("theme"); |
459 | board_name=theme.readEntry("board","board_1"); | 456 | board_name=theme.readEntry("board","board_1"); |
460 | piecesA_name=theme.readEntry("pieces1","pieces_1"); | 457 | piecesA_name=theme.readEntry("pieces1","pieces_1"); |
461 | piecesB_name=theme.readEntry("pieces2","pieces_2"); | 458 | piecesB_name=theme.readEntry("pieces2","pieces_2"); |
462 | diceA_name=theme.readEntry("dice1","dice_1"); | 459 | diceA_name=theme.readEntry("dice1","dice_1"); |
463 | diceB_name=theme.readEntry("dice2","dice_2"); | 460 | diceB_name=theme.readEntry("dice2","dice_2"); |
464 | table_name=theme.readEntry("table","table_1"); | 461 | table_name=theme.readEntry("table","table_1"); |
465 | odds_name=theme.readEntry("odds","odds_1"); | 462 | odds_name=theme.readEntry("odds","odds_1"); |
466 | 463 | ||
467 | applytheme(); | 464 | applytheme(); |
468 | 465 | ||
469 | } | 466 | } |
470 | 467 | ||
471 | void BackGammon::savetheme() | 468 | void BackGammon::savetheme() |
472 | { | 469 | { |
473 | if(theme_name=="default") | 470 | if(theme_name=="default") |
474 | { | 471 | { |
475 | QMessageBox::information(this,"Backgammon","Sorry\nCannot overwrite default.theme","OK"); | 472 | QMessageBox::information(this,"Backgammon","Sorry\nCannot overwrite default.theme","OK"); |
476 | return; | 473 | return; |
477 | } | 474 | } |
478 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; | 475 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; |
479 | if(QMessageBox::information(this,"Backgammon","Save Theme\n"+theme_name,"Yes","No")) | 476 | if(QMessageBox::information(this,"Backgammon","Save Theme\n"+theme_name,"Yes","No")) |
480 | return; | 477 | return; |
481 | 478 | ||
482 | Config theme(theme_file,Config::File); | 479 | Config theme(theme_file,Config::File); |
483 | theme.setGroup("theme"); | 480 | theme.setGroup("theme"); |
484 | theme.writeEntry("board",board_name); | 481 | theme.writeEntry("board",board_name); |
485 | theme.writeEntry("pieces1",piecesA_name); | 482 | theme.writeEntry("pieces1",piecesA_name); |
486 | theme.writeEntry("pieces2",piecesB_name); | 483 | theme.writeEntry("pieces2",piecesB_name); |
487 | theme.writeEntry("dice1",diceA_name); | 484 | theme.writeEntry("dice1",diceA_name); |
488 | theme.writeEntry("dice2",diceB_name); | 485 | theme.writeEntry("dice2",diceB_name); |
489 | theme.writeEntry("table",table_name); | 486 | theme.writeEntry("table",table_name); |
490 | theme.writeEntry("odds",odds_name); | 487 | theme.writeEntry("odds",odds_name); |
491 | 488 | ||
492 | } | 489 | } |
493 | 490 | ||
494 | void BackGammon::themedefault() | 491 | void BackGammon::themedefault() |
495 | { | 492 | { |
496 | if(QMessageBox::information(this,"Backgammon","Make Theme\n"+theme_name+"\nthe default theme","Yes","No")) | 493 | if(QMessageBox::information(this,"Backgammon","Make Theme\n"+theme_name+"\nthe default theme","Yes","No")) |
497 | return; | 494 | return; |
498 | 495 | ||
499 | Config conf("backgammon"); | 496 | Config conf("backgammon"); |
500 | conf.setGroup("general"); | 497 | conf.setGroup("general"); |
501 | conf.writeEntry("theme",theme_name); | 498 | conf.writeEntry("theme",theme_name); |
502 | } | 499 | } |
503 | 500 | ||
504 | void BackGammon::deletetheme() | 501 | void BackGammon::deletetheme() |
505 | { | 502 | { |
506 | FileDialog* file=new FileDialog(this,"Delete Theme",".theme"); | 503 | FileDialog* file=new FileDialog(this,"Delete Theme",".theme"); |
507 | if(!file->exec()) | 504 | if(!file->exec()) |
508 | return; | 505 | return; |
509 | 506 | ||
510 | theme_name=file->filename(); | 507 | theme_name=file->filename(); |
511 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; | 508 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; |
512 | 509 | ||
513 | if(!QMessageBox::warning(this,tr( "Backgammon" ),tr( "deleted theme %1?").arg(theme_name),tr( "OK" ),tr( "Cancel" ))) | 510 | if(!QMessageBox::warning(this,tr( "Backgammon" ),tr( "deleted theme %1?").arg(theme_name),tr( "OK" ),tr( "Cancel" ))) |
514 | { | 511 | { |
515 | QFile(theme_file).remove(); | 512 | QFile(theme_file).remove(); |
516 | } | 513 | } |
517 | } | 514 | } |
518 | 515 | ||
519 | void BackGammon::modify_AI() | 516 | void BackGammon::modify_AI() |
520 | { | 517 | { |
521 | AI_Dialog* ai_mod=new AI_Dialog(this,tr( "Load Theme" ),".theme"); | 518 | AI_Dialog* ai_mod=new AI_Dialog(this,tr( "Load Theme" ),".theme"); |
522 | ai_mod->setAISettings(move->getAISettings()); | 519 | ai_mod->setAISettings(move->getAISettings()); |
523 | if(!ai_mod->exec()) | 520 | if(!ai_mod->exec()) |
524 | return; | 521 | return; |
525 | 522 | ||
526 | //get the AI settings | 523 | //get the AI settings |
527 | AISettings ai=ai_mod->getAISettings(); | 524 | AISettings ai=ai_mod->getAISettings(); |
diff --git a/noncore/games/backgammon/filedialog.cpp b/noncore/games/backgammon/filedialog.cpp index a5e71c9..e0a2914 100644 --- a/noncore/games/backgammon/filedialog.cpp +++ b/noncore/games/backgammon/filedialog.cpp | |||
@@ -1,65 +1,61 @@ | |||
1 | #include "filedialog.h" | 1 | #include "filedialog.h" |
2 | 2 | ||
3 | #include <qdir.h> | 3 | #include <qdir.h> |
4 | #include <qfileinfo.h> | ||
5 | #include <qmessagebox.h> | ||
6 | #include <qpixmap.h> | ||
7 | #include <qpushbutton.h> | ||
8 | #include <qpe/qpeapplication.h> | 4 | #include <qpe/qpeapplication.h> |
9 | 5 | ||
10 | FileDialog::FileDialog(QWidget* parent,QString header,QString extension,const char* name,bool modal,WFlags f) | 6 | FileDialog::FileDialog(QWidget* parent,QString header,QString extension,const char* name,bool modal,WFlags f) |
11 | :QDialog(parent,name,modal,f) | 7 | :QDialog(parent,name,modal,f) |
12 | { | 8 | { |
13 | setCaption(header); | 9 | setCaption(header); |
14 | ext=extension; | 10 | ext=extension; |
15 | dirselector=new QListView(this); | 11 | dirselector=new QListView(this); |
16 | dirselector->setGeometry(1,10,235,200); | 12 | dirselector->setGeometry(1,10,235,200); |
17 | dirselector->addColumn("Files"); | 13 | dirselector->addColumn("Files"); |
18 | connect(dirselector,SIGNAL(clicked(QListViewItem*)),this,SLOT(selectorclicked(QListViewItem*))); | 14 | connect(dirselector,SIGNAL(clicked(QListViewItem*)),this,SLOT(selectorclicked(QListViewItem*))); |
19 | 15 | ||
20 | getCurrentDir(); | 16 | getCurrentDir(); |
21 | 17 | ||
22 | file_name="user"; | 18 | file_name="user"; |
23 | fileinput=new QLineEdit(file_name,this); | 19 | fileinput=new QLineEdit(file_name,this); |
24 | fileinput->setGeometry(1,220,235,20); | 20 | fileinput->setGeometry(1,220,235,20); |
25 | 21 | ||
26 | QPEApplication::showDialog( this ); | 22 | QPEApplication::showDialog( this ); |
27 | } | 23 | } |
28 | 24 | ||
29 | FileDialog::~FileDialog() | 25 | FileDialog::~FileDialog() |
30 | {} | 26 | {} |
31 | 27 | ||
32 | 28 | ||
33 | void FileDialog::selectorclicked(QListViewItem* entry) | 29 | void FileDialog::selectorclicked(QListViewItem* entry) |
34 | { | 30 | { |
35 | if(entry==NULL) | 31 | if(entry==NULL) |
36 | return; | 32 | return; |
37 | file_name=entry->text(0); | 33 | file_name=entry->text(0); |
38 | fileinput->setText(file_name); | 34 | fileinput->setText(file_name); |
39 | } | 35 | } |
40 | 36 | ||
41 | void FileDialog::getCurrentDir() | 37 | void FileDialog::getCurrentDir() |
42 | { | 38 | { |
43 | dirselector->clear(); | 39 | dirselector->clear(); |
44 | QDir dir(QPEApplication::qpeDir()+"/backgammon"); | 40 | QDir dir(QPEApplication::qpeDir()+"/backgammon"); |
45 | dir.setFilter(QDir::Files); | 41 | dir.setFilter(QDir::Files); |
46 | QFileInfoListIterator it(*(dir.entryInfoList())); | 42 | QFileInfoListIterator it(*(dir.entryInfoList())); |
47 | QFileInfo* fi; | 43 | QFileInfo* fi; |
48 | 44 | ||
49 | int ext_length=ext.length(); | 45 | int ext_length=ext.length(); |
50 | while((fi=it.current())) // go through all file and subdirs | 46 | while((fi=it.current())) // go through all file and subdirs |
51 | { | 47 | { |
52 | QString file=fi->fileName(); | 48 | QString file=fi->fileName(); |
53 | if(file.right(ext_length)==ext && file) | 49 | if(file.right(ext_length)==ext && file) |
54 | { | 50 | { |
55 | file=file.left(file.length()-ext_length); | 51 | file=file.left(file.length()-ext_length); |
56 | new QListViewItem(dirselector,file); | 52 | new QListViewItem(dirselector,file); |
57 | } | 53 | } |
58 | ++it; | 54 | ++it; |
59 | } | 55 | } |
60 | } | 56 | } |
61 | 57 | ||
62 | QString FileDialog::filename() | 58 | QString FileDialog::filename() |
63 | { | 59 | { |
64 | return file_name; | 60 | return file_name; |
65 | } | 61 | } |
diff --git a/noncore/games/backgammon/main.cpp b/noncore/games/backgammon/main.cpp index 58ced10..6316040 100644 --- a/noncore/games/backgammon/main.cpp +++ b/noncore/games/backgammon/main.cpp | |||
@@ -1,8 +1,7 @@ | |||
1 | #include <qpe/qpeapplication.h> | ||
2 | #include "backgammon.h" | 1 | #include "backgammon.h" |
3 | 2 | ||
4 | #include <opie/oapplicationfactory.h> | 3 | #include <opie/oapplicationfactory.h> |
5 | 4 | ||
6 | OPIE_EXPORT_APP( OApplicationFactory<BackGammon> ) | 5 | OPIE_EXPORT_APP( OApplicationFactory<BackGammon> ) |
7 | 6 | ||
8 | 7 | ||
diff --git a/noncore/games/backgammon/moveengine.cpp b/noncore/games/backgammon/moveengine.cpp index 37b73a6..7de7147 100644 --- a/noncore/games/backgammon/moveengine.cpp +++ b/noncore/games/backgammon/moveengine.cpp | |||
@@ -1,515 +1,514 @@ | |||
1 | #include "moveengine.h" | 1 | #include "moveengine.h" |
2 | 2 | ||
3 | #include <qmessagebox.h> | ||
4 | #include <qtimer.h> | 3 | #include <qtimer.h> |
5 | #include <stdlib.h> | 4 | #include <stdlib.h> |
6 | 5 | ||
7 | MoveEngine::MoveEngine() | 6 | MoveEngine::MoveEngine() |
8 | : QObject() | 7 | : QObject() |
9 | { | 8 | { |
10 | int offset=7; | 9 | int offset=7; |
11 | int a=0; //counter variable | 10 | int a=0; //counter variable |
12 | int xfill[]={210,185,170,155,140,125,110,85,70,55,40,25,10,10,25,40,55,70,85,110,125,140,155,170,185,210}; | 11 | int xfill[]={210,185,170,155,140,125,110,85,70,55,40,25,10,10,25,40,55,70,85,110,125,140,155,170,185,210}; |
13 | for(a=0;a<26;a++) | 12 | for(a=0;a<26;a++) |
14 | { | 13 | { |
15 | x_coord[a]=xfill[a]; | 14 | x_coord[a]=xfill[a]; |
16 | } | 15 | } |
17 | 16 | ||
18 | int yfill[]={10,25,40,55,70,10+offset,25+offset,40+offset,55+offset,25,40,55, 25+offset,40+offset,40}; | 17 | int yfill[]={10,25,40,55,70,10+offset,25+offset,40+offset,55+offset,25,40,55, 25+offset,40+offset,40}; |
19 | int zfill[]={1,1,1,1,1,2,2,2,2,3,3,3,4,4,5}; | 18 | int zfill[]={1,1,1,1,1,2,2,2,2,3,3,3,4,4,5}; |
20 | for(a=0;a<15;a++) | 19 | for(a=0;a<15;a++) |
21 | { | 20 | { |
22 | yup_coord[a]=yfill[a]; | 21 | yup_coord[a]=yfill[a]; |
23 | ylow_coord[a]=185-(yfill[a]); | 22 | ylow_coord[a]=185-(yfill[a]); |
24 | z_coord[a]=zfill[a]; | 23 | z_coord[a]=zfill[a]; |
25 | } | 24 | } |
26 | for(a=0;a<5;a++) | 25 | for(a=0;a<5;a++) |
27 | { | 26 | { |
28 | if(a<3) | 27 | if(a<3) |
29 | { | 28 | { |
30 | x_fin1[a]=65+a*15; | 29 | x_fin1[a]=65+a*15; |
31 | x_fin2[a]=155-a*15; | 30 | x_fin2[a]=155-a*15; |
32 | } | 31 | } |
33 | y_fin[a]=225-a*5; | 32 | y_fin[a]=225-a*5; |
34 | } | 33 | } |
35 | z_fin=1; | 34 | z_fin=1; |
36 | 35 | ||
37 | reset(); | 36 | reset(); |
38 | } | 37 | } |
39 | 38 | ||
40 | MoveEngine::~MoveEngine() | 39 | MoveEngine::~MoveEngine() |
41 | {} | 40 | {} |
42 | 41 | ||
43 | void MoveEngine::position(Pieces& pieces,bool non_qte) | 42 | void MoveEngine::position(Pieces& pieces,bool non_qte) |
44 | { | 43 | { |
45 | int player1_counter=0; | 44 | int player1_counter=0; |
46 | int player2_counter=0; | 45 | int player2_counter=0; |
47 | 46 | ||
48 | //non qte styles are smaller !! | 47 | //non qte styles are smaller !! |
49 | int offset=(non_qte) ? 5 : 0; | 48 | int offset=(non_qte) ? 5 : 0; |
50 | 49 | ||
51 | for(int a=0;a<28;a++) | 50 | for(int a=0;a<28;a++) |
52 | { | 51 | { |
53 | for(int b=0;b<abs(population[a].total);b++) | 52 | for(int b=0;b<abs(population[a].total);b++) |
54 | { | 53 | { |
55 | if(population[a].total>0) //player 1 pieces | 54 | if(population[a].total>0) //player 1 pieces |
56 | { | 55 | { |
57 | pieces.player1[player1_counter].x=x_coord[a]-offset; | 56 | pieces.player1[player1_counter].x=x_coord[a]-offset; |
58 | if(a>=0 && a<13) | 57 | if(a>=0 && a<13) |
59 | { | 58 | { |
60 | pieces.player1[player1_counter].y=yup_coord[b]-offset; | 59 | pieces.player1[player1_counter].y=yup_coord[b]-offset; |
61 | pieces.player1[player1_counter].z=z_coord[b]; | 60 | pieces.player1[player1_counter].z=z_coord[b]; |
62 | pieces.player1[player1_counter].side=false; | 61 | pieces.player1[player1_counter].side=false; |
63 | player1_counter++; | 62 | player1_counter++; |
64 | } | 63 | } |
65 | else if(a>12 && a<26) | 64 | else if(a>12 && a<26) |
66 | { | 65 | { |
67 | pieces.player1[player1_counter].y=ylow_coord[b]-offset; | 66 | pieces.player1[player1_counter].y=ylow_coord[b]-offset; |
68 | pieces.player1[player1_counter].z=z_coord[b]; | 67 | pieces.player1[player1_counter].z=z_coord[b]; |
69 | pieces.player1[player1_counter].side=false; | 68 | pieces.player1[player1_counter].side=false; |
70 | player1_counter++; | 69 | player1_counter++; |
71 | } | 70 | } |
72 | else if(a==26) | 71 | else if(a==26) |
73 | { | 72 | { |
74 | if(b<5) | 73 | if(b<5) |
75 | { | 74 | { |
76 | pieces.player1[player1_counter].x=x_fin1[0]-offset; | 75 | pieces.player1[player1_counter].x=x_fin1[0]-offset; |
77 | pieces.player1[player1_counter].y=y_fin[b]-offset; | 76 | pieces.player1[player1_counter].y=y_fin[b]-offset; |
78 | pieces.player1[player1_counter].z=z_fin; | 77 | pieces.player1[player1_counter].z=z_fin; |
79 | } | 78 | } |
80 | else if(b>=5 && b<10) | 79 | else if(b>=5 && b<10) |
81 | { | 80 | { |
82 | pieces.player1[player1_counter].x=x_fin1[1]-offset; | 81 | pieces.player1[player1_counter].x=x_fin1[1]-offset; |
83 | pieces.player1[player1_counter].y=y_fin[b-5]-offset; | 82 | pieces.player1[player1_counter].y=y_fin[b-5]-offset; |
84 | pieces.player1[player1_counter].z=z_fin; | 83 | pieces.player1[player1_counter].z=z_fin; |
85 | } | 84 | } |
86 | else | 85 | else |
87 | { | 86 | { |
88 | pieces.player1[player1_counter].x=x_fin1[2]-offset; | 87 | pieces.player1[player1_counter].x=x_fin1[2]-offset; |
89 | pieces.player1[player1_counter].y=y_fin[b-10]-offset; | 88 | pieces.player1[player1_counter].y=y_fin[b-10]-offset; |
90 | pieces.player1[player1_counter].z=z_fin; | 89 | pieces.player1[player1_counter].z=z_fin; |
91 | } | 90 | } |
92 | pieces.player1[player1_counter].side=true; | 91 | pieces.player1[player1_counter].side=true; |
93 | player1_counter++; | 92 | player1_counter++; |
94 | 93 | ||
95 | } | 94 | } |
96 | } | 95 | } |
97 | 96 | ||
98 | else if(population[a].total<0) //player 2 pieces | 97 | else if(population[a].total<0) //player 2 pieces |
99 | { | 98 | { |
100 | pieces.player2[player2_counter].x=x_coord[a]-offset; | 99 | pieces.player2[player2_counter].x=x_coord[a]-offset; |
101 | if(a>=0 && a<13) | 100 | if(a>=0 && a<13) |
102 | { | 101 | { |
103 | pieces.player2[player2_counter].y=yup_coord[b]-offset; | 102 | pieces.player2[player2_counter].y=yup_coord[b]-offset; |
104 | pieces.player2[player2_counter].z=z_coord[b]; | 103 | pieces.player2[player2_counter].z=z_coord[b]; |
105 | pieces.player2[player2_counter].side=false; | 104 | pieces.player2[player2_counter].side=false; |
106 | player2_counter++; | 105 | player2_counter++; |
107 | } | 106 | } |
108 | else if(a>12 && a<26) | 107 | else if(a>12 && a<26) |
109 | { | 108 | { |
110 | pieces.player2[player2_counter].y=ylow_coord[b]-offset; | 109 | pieces.player2[player2_counter].y=ylow_coord[b]-offset; |
111 | pieces.player2[player2_counter].z=z_coord[b]; | 110 | pieces.player2[player2_counter].z=z_coord[b]; |
112 | pieces.player2[player2_counter].side=false; | 111 | pieces.player2[player2_counter].side=false; |
113 | player2_counter++; | 112 | player2_counter++; |
114 | } | 113 | } |
115 | else if(a==27) | 114 | else if(a==27) |
116 | { | 115 | { |
117 | if(b<5) | 116 | if(b<5) |
118 | { | 117 | { |
119 | pieces.player2[player2_counter].x=x_fin2[0]-offset; | 118 | pieces.player2[player2_counter].x=x_fin2[0]-offset; |
120 | pieces.player2[player2_counter].y=y_fin[b]-offset; | 119 | pieces.player2[player2_counter].y=y_fin[b]-offset; |
121 | pieces.player2[player2_counter].z=z_fin; | 120 | pieces.player2[player2_counter].z=z_fin; |
122 | } | 121 | } |
123 | else if(b>=5 && b<10) | 122 | else if(b>=5 && b<10) |
124 | { | 123 | { |
125 | pieces.player2[player2_counter].x=x_fin2[1]-offset; | 124 | pieces.player2[player2_counter].x=x_fin2[1]-offset; |
126 | pieces.player2[player2_counter].y=y_fin[b-5]-offset; | 125 | pieces.player2[player2_counter].y=y_fin[b-5]-offset; |
127 | pieces.player2[player2_counter].z=z_fin; | 126 | pieces.player2[player2_counter].z=z_fin; |
128 | } | 127 | } |
129 | else | 128 | else |
130 | { | 129 | { |
131 | pieces.player2[player2_counter].x=x_fin2[2]-offset; | 130 | pieces.player2[player2_counter].x=x_fin2[2]-offset; |
132 | pieces.player2[player2_counter].y=y_fin[b-10]-offset; | 131 | pieces.player2[player2_counter].y=y_fin[b-10]-offset; |
133 | pieces.player2[player2_counter].z=z_fin; | 132 | pieces.player2[player2_counter].z=z_fin; |
134 | } | 133 | } |
135 | pieces.player2[player2_counter].side=true; | 134 | pieces.player2[player2_counter].side=true; |
136 | player2_counter++; | 135 | player2_counter++; |
137 | 136 | ||
138 | } | 137 | } |
139 | } | 138 | } |
140 | } | 139 | } |
141 | } | 140 | } |
142 | } | 141 | } |
143 | 142 | ||
144 | void MoveEngine::diceroll(const int& newplayer,const int& face1,const int& face2,const int& face3,const int& face4,bool computer) | 143 | void MoveEngine::diceroll(const int& newplayer,const int& face1,const int& face2,const int& face3,const int& face4,bool computer) |
145 | { | 144 | { |
146 | checkstate(); | 145 | checkstate(); |
147 | player=newplayer; | 146 | player=newplayer; |
148 | otherplayer=(player==1) ? 2 : 1; | 147 | otherplayer=(player==1) ? 2 : 1; |
149 | dice[0]=face1; | 148 | dice[0]=face1; |
150 | dice[1]=face2; | 149 | dice[1]=face2; |
151 | dice[2]=face3; | 150 | dice[2]=face3; |
152 | dice[3]=face4; | 151 | dice[3]=face4; |
153 | marker_current=-1; | 152 | marker_current=-1; |
154 | if(getPossibleMoves()==0) | 153 | if(getPossibleMoves()==0) |
155 | { | 154 | { |
156 | emit nomove(); | 155 | emit nomove(); |
157 | return; // player will be changed | 156 | return; // player will be changed |
158 | } | 157 | } |
159 | if(!computer) | 158 | if(!computer) |
160 | return; //human intervention required | 159 | return; //human intervention required |
161 | 160 | ||
162 | QTimer::singleShot(2000,this,SLOT(automove())); | 161 | QTimer::singleShot(2000,this,SLOT(automove())); |
163 | } | 162 | } |
164 | 163 | ||
165 | 164 | ||
166 | void MoveEngine::automove() | 165 | void MoveEngine::automove() |
167 | { | 166 | { |
168 | //the maximimum possibility | 167 | //the maximimum possibility |
169 | int maxpos=0; | 168 | int maxpos=0; |
170 | //the position in the moves array | 169 | //the position in the moves array |
171 | int from=-1; | 170 | int from=-1; |
172 | int to=-1; | 171 | int to=-1; |
173 | //dice1 or dice 2 ?? | 172 | //dice1 or dice 2 ?? |
174 | int index_dice=0; | 173 | int index_dice=0; |
175 | for(int counter=0;counter<26;counter++) | 174 | for(int counter=0;counter<26;counter++) |
176 | { | 175 | { |
177 | int a=(player==1) ? counter : 25-counter; | 176 | int a=(player==1) ? counter : 25-counter; |
178 | for(int b=0;b<4;b++) | 177 | for(int b=0;b<4;b++) |
179 | { | 178 | { |
180 | if(moves[a].weight[b]>maxpos) | 179 | if(moves[a].weight[b]>maxpos) |
181 | { | 180 | { |
182 | maxpos=moves[a].weight[b]; | 181 | maxpos=moves[a].weight[b]; |
183 | from=a; | 182 | from=a; |
184 | to=moves[a].to[b]; | 183 | to=moves[a].to[b]; |
185 | index_dice=b+1; | 184 | index_dice=b+1; |
186 | } | 185 | } |
187 | } | 186 | } |
188 | } | 187 | } |
189 | move(from,to,index_dice); | 188 | move(from,to,index_dice); |
190 | } | 189 | } |
191 | 190 | ||
192 | 191 | ||
193 | void MoveEngine::boardpressed(const int& x,const int& y,Marker& marker,bool non_qte) | 192 | void MoveEngine::boardpressed(const int& x,const int& y,Marker& marker,bool non_qte) |
194 | { | 193 | { |
195 | //get the position of the mouse click | 194 | //get the position of the mouse click |
196 | bool upper=true; | 195 | bool upper=true; |
197 | bool found=false; | 196 | bool found=false; |
198 | 197 | ||
199 | int offset=(non_qte) ? 5 : 0; | 198 | int offset=(non_qte) ? 5 : 0; |
200 | 199 | ||
201 | if(y<=85) // board slots 0 to 12 | 200 | if(y<=85) // board slots 0 to 12 |
202 | marker.y_current=0; | 201 | marker.y_current=0; |
203 | else if(y>=105) //board slots 13 to 25 | 202 | else if(y>=105) //board slots 13 to 25 |
204 | { | 203 | { |
205 | marker.y_current=195-2*offset; | 204 | marker.y_current=195-2*offset; |
206 | upper=false; | 205 | upper=false; |
207 | } | 206 | } |
208 | 207 | ||
209 | int index=13; // the clicked board slot | 208 | int index=13; // the clicked board slot |
210 | 209 | ||
211 | while(index<25 && !found) | 210 | while(index<25 && !found) |
212 | { | 211 | { |
213 | if(x>=x_coord[index] && x<x_coord[index+1]) | 212 | if(x>=x_coord[index] && x<x_coord[index+1]) |
214 | { | 213 | { |
215 | marker.x_current=x_coord[index]; | 214 | marker.x_current=x_coord[index]; |
216 | found=true; | 215 | found=true; |
217 | ; | 216 | ; |
218 | } | 217 | } |
219 | else | 218 | else |
220 | { | 219 | { |
221 | index++; | 220 | index++; |
222 | } | 221 | } |
223 | } | 222 | } |
224 | if(!found) | 223 | if(!found) |
225 | { | 224 | { |
226 | marker.x_current=x_coord[25]; | 225 | marker.x_current=x_coord[25]; |
227 | index=25; | 226 | index=25; |
228 | } | 227 | } |
229 | if(upper) | 228 | if(upper) |
230 | { | 229 | { |
231 | index=25-index; | 230 | index=25-index; |
232 | } | 231 | } |
233 | 232 | ||
234 | int a=0; | 233 | int a=0; |
235 | int usedice=-1; | 234 | int usedice=-1; |
236 | int dice_value=7; | 235 | int dice_value=7; |
237 | for(a=0;a<4;a++) | 236 | for(a=0;a<4;a++) |
238 | { | 237 | { |
239 | if(index==marker_next[a] && marker_next[a]!=-1 && dice_value>dice[a]) | 238 | if(index==marker_next[a] && marker_next[a]!=-1 && dice_value>dice[a]) |
240 | { | 239 | { |
241 | usedice=a; | 240 | usedice=a; |
242 | dice_value=dice[0]; | 241 | dice_value=dice[0]; |
243 | } | 242 | } |
244 | } | 243 | } |
245 | if(usedice!=-1) | 244 | if(usedice!=-1) |
246 | { | 245 | { |
247 | move(marker_current,marker_next[usedice],usedice+1); | 246 | move(marker_current,marker_next[usedice],usedice+1); |
248 | nomarker(marker); | 247 | nomarker(marker); |
249 | return; | 248 | return; |
250 | 249 | ||
251 | } | 250 | } |
252 | 251 | ||
253 | 252 | ||
254 | if(dice[0]==7 && dice[1]==7 && dice[2]==7 && dice[3]==7) //no dice rolled | 253 | if(dice[0]==7 && dice[1]==7 && dice[2]==7 && dice[3]==7) //no dice rolled |
255 | { | 254 | { |
256 | nomarker(marker); | 255 | nomarker(marker); |
257 | return; | 256 | return; |
258 | } | 257 | } |
259 | else if(fieldColor(index)==player) | 258 | else if(fieldColor(index)==player) |
260 | { | 259 | { |
261 | marker.visible_current=true; | 260 | marker.visible_current=true; |
262 | marker_current=index; | 261 | marker_current=index; |
263 | } | 262 | } |
264 | else | 263 | else |
265 | { | 264 | { |
266 | nomarker(marker); | 265 | nomarker(marker); |
267 | return; | 266 | return; |
268 | } | 267 | } |
269 | 268 | ||
270 | for(a=0;a<4;a++) | 269 | for(a=0;a<4;a++) |
271 | { | 270 | { |
272 | if(moves[index].weight[a]>0) | 271 | if(moves[index].weight[a]>0) |
273 | { | 272 | { |
274 | int nextfield=moves[index].to[a]; | 273 | int nextfield=moves[index].to[a]; |
275 | marker.x_next[a]=x_coord[nextfield]; | 274 | marker.x_next[a]=x_coord[nextfield]; |
276 | marker_next[a]=nextfield; | 275 | marker_next[a]=nextfield; |
277 | if(nextfield<13) //upper half | 276 | if(nextfield<13) //upper half |
278 | marker.y_next[a]=0; | 277 | marker.y_next[a]=0; |
279 | else //lower half | 278 | else //lower half |
280 | marker.y_next[a]=195-2*offset; | 279 | marker.y_next[a]=195-2*offset; |
281 | marker.visible_next[a]=true; | 280 | marker.visible_next[a]=true; |
282 | } | 281 | } |
283 | else | 282 | else |
284 | { | 283 | { |
285 | marker.x_next[a]=0; | 284 | marker.x_next[a]=0; |
286 | marker.y_next[a]=0; | 285 | marker.y_next[a]=0; |
287 | marker_next[a]=-1; | 286 | marker_next[a]=-1; |
288 | marker.visible_next[a]=false; | 287 | marker.visible_next[a]=false; |
289 | } | 288 | } |
290 | } | 289 | } |
291 | return; | 290 | return; |
292 | } | 291 | } |
293 | 292 | ||
294 | void MoveEngine::reset() | 293 | void MoveEngine::reset() |
295 | { | 294 | { |
296 | int a=0; | 295 | int a=0; |
297 | for(a=0;a<28;a++) | 296 | for(a=0;a<28;a++) |
298 | { | 297 | { |
299 | population[a].total=0; | 298 | population[a].total=0; |
300 | } | 299 | } |
301 | 300 | ||
302 | int p1_index[]={1,1,12,12,12,12,12,17,17,17,19,19,19,19,19}; | 301 | int p1_index[]={1,1,12,12,12,12,12,17,17,17,19,19,19,19,19}; |
303 | int p2_index[]={24,24,13,13,13,13,13,8,8,8,6,6,6,6,6}; | 302 | int p2_index[]={24,24,13,13,13,13,13,8,8,8,6,6,6,6,6}; |
304 | //int p1_index[]={19,20,21,22,22,23,23,18,18,23,24,24,24,24,24}; | 303 | //int p1_index[]={19,20,21,22,22,23,23,18,18,23,24,24,24,24,24}; |
305 | //int p2_index[]={6,5,4,3,3,2,2,2,2,2,1,7,7,1,1}; | 304 | //int p2_index[]={6,5,4,3,3,2,2,2,2,2,1,7,7,1,1}; |
306 | for(a=0;a<15;a++) | 305 | for(a=0;a<15;a++) |
307 | { | 306 | { |
308 | population[p1_index[a]].total++; | 307 | population[p1_index[a]].total++; |
309 | population[p2_index[a]].total--; | 308 | population[p2_index[a]].total--; |
310 | } | 309 | } |
311 | 310 | ||
312 | player=0; | 311 | player=0; |
313 | dice[0]=7; | 312 | dice[0]=7; |
314 | dice[1]=7; | 313 | dice[1]=7; |
315 | dice[2]=7; | 314 | dice[2]=7; |
316 | dice[3]=7; | 315 | dice[3]=7; |
317 | 316 | ||
318 | marker_current=-1; | 317 | marker_current=-1; |
319 | marker_next[0]=-1; | 318 | marker_next[0]=-1; |
320 | marker_next[1]=-1; | 319 | marker_next[1]=-1; |
321 | marker_next[2]=-1; | 320 | marker_next[2]=-1; |
322 | marker_next[3]=-1; | 321 | marker_next[3]=-1; |
323 | //allclear[0]==false; | 322 | //allclear[0]==false; |
324 | allclear[1]=false; | 323 | allclear[1]=false; |
325 | allclear[2]=false; | 324 | allclear[2]=false; |
326 | last_piece[1]=0; | 325 | last_piece[1]=0; |
327 | last_piece[2]=25; | 326 | last_piece[2]=25; |
328 | } | 327 | } |
329 | 328 | ||
330 | void MoveEngine::loadGame(const LoadSave& load) | 329 | void MoveEngine::loadGame(const LoadSave& load) |
331 | { | 330 | { |
332 | for(int a=0;a<28;a++) | 331 | for(int a=0;a<28;a++) |
333 | { | 332 | { |
334 | population[a].total=load.pop[a].total; | 333 | population[a].total=load.pop[a].total; |
335 | } | 334 | } |
336 | checkstate(); | 335 | checkstate(); |
337 | } | 336 | } |
338 | 337 | ||
339 | LoadSave MoveEngine::saveGame() | 338 | LoadSave MoveEngine::saveGame() |
340 | { | 339 | { |
341 | LoadSave save; | 340 | LoadSave save; |
342 | for(int a=0;a<28;a++) | 341 | for(int a=0;a<28;a++) |
343 | { | 342 | { |
344 | save.pop[a].total=population[a].total; | 343 | save.pop[a].total=population[a].total; |
345 | } | 344 | } |
346 | return save; | 345 | return save; |
347 | } | 346 | } |
348 | 347 | ||
349 | AISettings MoveEngine::getAISettings() | 348 | AISettings MoveEngine::getAISettings() |
350 | { | 349 | { |
351 | return ai; | 350 | return ai; |
352 | } | 351 | } |
353 | 352 | ||
354 | void MoveEngine::setAISettings(const AISettings& new_ai) | 353 | void MoveEngine::setAISettings(const AISettings& new_ai) |
355 | { | 354 | { |
356 | ai=new_ai; | 355 | ai=new_ai; |
357 | } | 356 | } |
358 | 357 | ||
359 | void MoveEngine::setRules(Rules rules) | 358 | void MoveEngine::setRules(Rules rules) |
360 | { | 359 | { |
361 | move_with_pieces_out=rules.move_with_pieces_out; | 360 | move_with_pieces_out=rules.move_with_pieces_out; |
362 | nice_dice=rules.generous_dice; | 361 | nice_dice=rules.generous_dice; |
363 | } | 362 | } |
364 | 363 | ||
365 | 364 | ||
366 | int MoveEngine::getPossibleMoves() | 365 | int MoveEngine::getPossibleMoves() |
367 | { | 366 | { |
368 | int homezone[]={0,25,0}; | 367 | int homezone[]={0,25,0}; |
369 | int lastToHomeZone=abs(last_piece[player]-homezone[player]); | 368 | int lastToHomeZone=abs(last_piece[player]-homezone[player]); |
370 | for(int field=0;field<26;field++) | 369 | for(int field=0;field<26;field++) |
371 | { | 370 | { |
372 | 371 | ||
373 | for(int b=0;b<4;b++) | 372 | for(int b=0;b<4;b++) |
374 | { | 373 | { |
375 | int dice_tmp=dice[b]; | 374 | int dice_tmp=dice[b]; |
376 | if(dice[b]!=7 && dice[b]> lastToHomeZone) | 375 | if(dice[b]!=7 && dice[b]> lastToHomeZone) |
377 | dice_tmp=lastToHomeZone; | 376 | dice_tmp=lastToHomeZone; |
378 | 377 | ||
379 | int nextfield=(player==1) ? field+dice_tmp : field-dice_tmp; | 378 | int nextfield=(player==1) ? field+dice_tmp : field-dice_tmp; |
380 | 379 | ||
381 | if(nice_dice) | 380 | if(nice_dice) |
382 | { | 381 | { |
383 | if(player==1 && nextfield>homezone[1]) | 382 | if(player==1 && nextfield>homezone[1]) |
384 | nextfield=homezone[1]; | 383 | nextfield=homezone[1]; |
385 | else if(player==2 && nextfield<homezone[2]) | 384 | else if(player==2 && nextfield<homezone[2]) |
386 | nextfield=homezone[2]; | 385 | nextfield=homezone[2]; |
387 | } | 386 | } |
388 | 387 | ||
389 | moves[field].weight[b]=0; | 388 | moves[field].weight[b]=0; |
390 | moves[field].to[b]=nextfield; | 389 | moves[field].to[b]=nextfield; |
391 | 390 | ||
392 | int out_of_board[]={-1,0,25}; | 391 | int out_of_board[]={-1,0,25}; |
393 | if(!move_with_pieces_out && field!=out_of_board[player] && pieces_out[player]) | 392 | if(!move_with_pieces_out && field!=out_of_board[player] && pieces_out[player]) |
394 | { | 393 | { |
395 | continue; | 394 | continue; |
396 | } | 395 | } |
397 | 396 | ||
398 | 397 | ||
399 | 398 | ||
400 | if(dice[b]!=7 && fieldColor(field)==player ) //player can only move his own pieces | 399 | if(dice[b]!=7 && fieldColor(field)==player ) //player can only move his own pieces |
401 | { | 400 | { |
402 | if((player==1 && nextfield > homezone[1]) || (player==2 && nextfield < homezone[2])) | 401 | if((player==1 && nextfield > homezone[1]) || (player==2 && nextfield < homezone[2])) |
403 | { | 402 | { |
404 | moves[field].weight[b]=0; //movement would be far out of board | 403 | moves[field].weight[b]=0; //movement would be far out of board |
405 | } | 404 | } |
406 | else if(nextfield==homezone[player] && !allclear[player]) | 405 | else if(nextfield==homezone[player] && !allclear[player]) |
407 | { | 406 | { |
408 | moves[field].weight[b]=0; //can not rescue pieces until all are in the endzone | 407 | moves[field].weight[b]=0; //can not rescue pieces until all are in the endzone |
409 | } | 408 | } |
410 | else if(nextfield==homezone[player] && allclear[player]) | 409 | else if(nextfield==homezone[player] && allclear[player]) |
411 | { | 410 | { |
412 | moves[field].weight[b]=ai.rescue; //rescue your pieces : nuff said ;-) | 411 | moves[field].weight[b]=ai.rescue; //rescue your pieces : nuff said ;-) |
413 | } | 412 | } |
414 | else if(fieldColor(nextfield)==otherplayer) | 413 | else if(fieldColor(nextfield)==otherplayer) |
415 | { | 414 | { |
416 | if(abs(population[nextfield].total)>1) //can not move to this field | 415 | if(abs(population[nextfield].total)>1) //can not move to this field |
417 | moves[field].weight[b]=0; | 416 | moves[field].weight[b]=0; |
418 | else if(abs(population[nextfield].total)==1) //eliminate opponent : very nice | 417 | else if(abs(population[nextfield].total)==1) //eliminate opponent : very nice |
419 | moves[field].weight[b]=ai.eliminate; | 418 | moves[field].weight[b]=ai.eliminate; |
420 | } | 419 | } |
421 | else if(fieldColor(nextfield)==player) //nextfield already occupied by player | 420 | else if(fieldColor(nextfield)==player) //nextfield already occupied by player |
422 | { | 421 | { |
423 | if(abs(population[field].total)==2) //expose own piece : not diserable | 422 | if(abs(population[field].total)==2) //expose own piece : not diserable |
424 | moves[field].weight[b]=ai.expose; | 423 | moves[field].weight[b]=ai.expose; |
425 | else if(abs(population[nextfield].total)>1) //own pices already there : safe | 424 | else if(abs(population[nextfield].total)>1) //own pices already there : safe |
426 | moves[field].weight[b]=ai.safe; | 425 | moves[field].weight[b]=ai.safe; |
427 | else if(abs(population[nextfield].total)==1) //protect own piece : most importatnt | 426 | else if(abs(population[nextfield].total)==1) //protect own piece : most importatnt |
428 | moves[field].weight[b]=ai.protect; | 427 | moves[field].weight[b]=ai.protect; |
429 | } | 428 | } |
430 | else if(population[nextfield].total==0) //nextfield empty | 429 | else if(population[nextfield].total==0) //nextfield empty |
431 | { | 430 | { |
432 | if(abs(population[field].total)==2) //expose own piece : not diserable | 431 | if(abs(population[field].total)==2) //expose own piece : not diserable |
433 | moves[field].weight[b]=ai.expose; | 432 | moves[field].weight[b]=ai.expose; |
434 | else | 433 | else |
435 | moves[field].weight[b]=ai.empty; | 434 | moves[field].weight[b]=ai.empty; |
436 | } | 435 | } |
437 | else | 436 | else |
438 | moves[field].weight[b]=0; //default. | 437 | moves[field].weight[b]=0; //default. |
439 | } | 438 | } |
440 | 439 | ||
441 | 440 | ||
442 | 441 | ||
443 | else | 442 | else |
444 | moves[field].weight[b]=0; //dice already used or field not used by player | 443 | moves[field].weight[b]=0; //dice already used or field not used by player |
445 | } | 444 | } |
446 | 445 | ||
447 | 446 | ||
448 | 447 | ||
449 | } | 448 | } |
450 | 449 | ||
451 | int total=0; | 450 | int total=0; |
452 | for(int field=0;field<26;field++) | 451 | for(int field=0;field<26;field++) |
453 | { | 452 | { |
454 | total+=moves[field].weight[0]+moves[field].weight[1]+moves[field].weight[2]+moves[field].weight[3]; | 453 | total+=moves[field].weight[0]+moves[field].weight[1]+moves[field].weight[2]+moves[field].weight[3]; |
455 | } | 454 | } |
456 | return total; | 455 | return total; |
457 | } | 456 | } |
458 | 457 | ||
459 | void MoveEngine::move(const int& from, int to, const int& dice) | 458 | void MoveEngine::move(const int& from, int to, const int& dice) |
460 | { | 459 | { |
461 | //qDebug("%d moves from %d to %d (%d) with dice %d",player,from,to,to-from,dice); | 460 | //qDebug("%d moves from %d to %d (%d) with dice %d",player,from,to,to-from,dice); |
462 | 461 | ||
463 | if(player==1 && to==25) | 462 | if(player==1 && to==25) |
464 | to=26; | 463 | to=26; |
465 | if(player==2 && to==0) | 464 | if(player==2 && to==0) |
466 | to=27; | 465 | to=27; |
467 | 466 | ||
468 | //if space is occupied by enemy move pieces to startzone | 467 | //if space is occupied by enemy move pieces to startzone |
469 | if(fieldColor(to)==otherplayer) | 468 | if(fieldColor(to)==otherplayer) |
470 | { | 469 | { |
471 | population[to].total=0; | 470 | population[to].total=0; |
472 | if(otherplayer==1) | 471 | if(otherplayer==1) |
473 | population[0].total++; | 472 | population[0].total++; |
474 | else | 473 | else |
475 | population[25].total--; | 474 | population[25].total--; |
476 | } | 475 | } |
477 | 476 | ||
478 | if(player==1) | 477 | if(player==1) |
479 | { | 478 | { |
480 | population[from].total--; | 479 | population[from].total--; |
481 | population[to].total++; | 480 | population[to].total++; |
482 | } | 481 | } |
483 | else //player=2 | 482 | else //player=2 |
484 | { | 483 | { |
485 | population[from].total++; | 484 | population[from].total++; |
486 | population[to].total--; | 485 | population[to].total--; |
487 | } | 486 | } |
488 | 487 | ||
489 | if(dice==1) | 488 | if(dice==1) |
490 | emit done_dice1(); | 489 | emit done_dice1(); |
491 | else if(dice==2) | 490 | else if(dice==2) |
492 | emit done_dice2(); | 491 | emit done_dice2(); |
493 | else if(dice==3) | 492 | else if(dice==3) |
494 | emit done_dice3(); | 493 | emit done_dice3(); |
495 | else | 494 | else |
496 | emit done_dice4(); | 495 | emit done_dice4(); |
497 | 496 | ||
498 | if(abs(population[26].total)==15) | 497 | if(abs(population[26].total)==15) |
499 | emit player_finished(1); | 498 | emit player_finished(1); |
500 | if(abs(population[27].total)==15) | 499 | if(abs(population[27].total)==15) |
501 | emit player_finished(2); | 500 | emit player_finished(2); |
502 | } | 501 | } |
503 | 502 | ||
504 | void MoveEngine::checkstate() | 503 | void MoveEngine::checkstate() |
505 | { | 504 | { |
506 | //check if pieces are out | 505 | //check if pieces are out |
507 | pieces_out[1]=(population[0].total>0) ? true : false; | 506 | pieces_out[1]=(population[0].total>0) ? true : false; |
508 | pieces_out[2]=(population[25].total<0) ? true : false; | 507 | pieces_out[2]=(population[25].total<0) ? true : false; |
509 | 508 | ||
510 | //check if all pieces are in the endzones | 509 | //check if all pieces are in the endzones |
511 | allclear[1]=true; | 510 | allclear[1]=true; |
512 | allclear[2]=true; | 511 | allclear[2]=true; |
513 | 512 | ||
514 | last_piece[1]=25; | 513 | last_piece[1]=25; |
515 | bool found_last_piece1=false; | 514 | bool found_last_piece1=false; |
diff --git a/noncore/games/backgammon/themedialog.cpp b/noncore/games/backgammon/themedialog.cpp index f342381..afd6a1b 100644 --- a/noncore/games/backgammon/themedialog.cpp +++ b/noncore/games/backgammon/themedialog.cpp | |||
@@ -1,163 +1,161 @@ | |||
1 | #include "themedialog.h" | 1 | #include "themedialog.h" |
2 | 2 | ||
3 | #include <qdir.h> | 3 | #include <qdir.h> |
4 | #include <qfileinfo.h> | ||
5 | #include <qlabel.h> | 4 | #include <qlabel.h> |
6 | #include <qpushbutton.h> | ||
7 | #include <qpe/qpeapplication.h> | 5 | #include <qpe/qpeapplication.h> |
8 | 6 | ||
9 | 7 | ||
10 | ThemeDialog::ThemeDialog(QWidget* parent,const char* name,bool modal,WFlags f) | 8 | ThemeDialog::ThemeDialog(QWidget* parent,const char* name,bool modal,WFlags f) |
11 | :QDialog(parent,name,modal,f) | 9 | :QDialog(parent,name,modal,f) |
12 | { | 10 | { |
13 | setCaption("Theme Dialog"); | 11 | setCaption("Theme Dialog"); |
14 | QLabel* labelname=new QLabel("name",this); | 12 | QLabel* labelname=new QLabel("name",this); |
15 | labelname->setGeometry(0,5,40,20); | 13 | labelname->setGeometry(0,5,40,20); |
16 | lineName=new QLineEdit("user",this); | 14 | lineName=new QLineEdit("user",this); |
17 | lineName->setGeometry(40,5,195,20); | 15 | lineName->setGeometry(40,5,195,20); |
18 | 16 | ||
19 | QLabel* labelboard=new QLabel("board",this); | 17 | QLabel* labelboard=new QLabel("board",this); |
20 | labelboard->setGeometry(0,30,40,20); | 18 | labelboard->setGeometry(0,30,40,20); |
21 | boxboard=new QComboBox(this,""); | 19 | boxboard=new QComboBox(this,""); |
22 | boxboard->setGeometry(40,30,195,20); | 20 | boxboard->setGeometry(40,30,195,20); |
23 | fillBox("boards",boxboard); | 21 | fillBox("boards",boxboard); |
24 | 22 | ||
25 | QLabel* labelpiecesA=new QLabel("pieces1",this); | 23 | QLabel* labelpiecesA=new QLabel("pieces1",this); |
26 | labelpiecesA->setGeometry(0,70,40,20); | 24 | labelpiecesA->setGeometry(0,70,40,20); |
27 | boxpiecesA=new QComboBox(this); | 25 | boxpiecesA=new QComboBox(this); |
28 | boxpiecesA->setGeometry(40,70,195,20); | 26 | boxpiecesA->setGeometry(40,70,195,20); |
29 | fillBox("pieces",boxpiecesA); | 27 | fillBox("pieces",boxpiecesA); |
30 | 28 | ||
31 | QLabel* labelpiecesB=new QLabel("pieces2",this); | 29 | QLabel* labelpiecesB=new QLabel("pieces2",this); |
32 | labelpiecesB->setGeometry(0,95,40,20); | 30 | labelpiecesB->setGeometry(0,95,40,20); |
33 | boxpiecesB=new QComboBox(this); | 31 | boxpiecesB=new QComboBox(this); |
34 | boxpiecesB->setGeometry(40,95,195,20); | 32 | boxpiecesB->setGeometry(40,95,195,20); |
35 | fillBox("pieces",boxpiecesB); | 33 | fillBox("pieces",boxpiecesB); |
36 | 34 | ||
37 | QLabel* labeldiceA=new QLabel("dice1",this); | 35 | QLabel* labeldiceA=new QLabel("dice1",this); |
38 | labeldiceA->setGeometry(0,135,40,20); | 36 | labeldiceA->setGeometry(0,135,40,20); |
39 | boxdiceA=new QComboBox(this); | 37 | boxdiceA=new QComboBox(this); |
40 | boxdiceA->setGeometry(40,135,195,20); | 38 | boxdiceA->setGeometry(40,135,195,20); |
41 | fillBox("dice",boxdiceA); | 39 | fillBox("dice",boxdiceA); |
42 | 40 | ||
43 | QLabel* labeldiceB=new QLabel("dice2",this); | 41 | QLabel* labeldiceB=new QLabel("dice2",this); |
44 | labeldiceB->setGeometry(0,160,40,20); | 42 | labeldiceB->setGeometry(0,160,40,20); |
45 | boxdiceB=new QComboBox(this); | 43 | boxdiceB=new QComboBox(this); |
46 | boxdiceB->setGeometry(40,160,195,20); | 44 | boxdiceB->setGeometry(40,160,195,20); |
47 | fillBox("dice",boxdiceB); | 45 | fillBox("dice",boxdiceB); |
48 | 46 | ||
49 | QLabel* labelodds=new QLabel("odds",this); | 47 | QLabel* labelodds=new QLabel("odds",this); |
50 | labelodds->setGeometry(0,200,40,20); | 48 | labelodds->setGeometry(0,200,40,20); |
51 | boxodds=new QComboBox(this); | 49 | boxodds=new QComboBox(this); |
52 | boxodds->setGeometry(40,200,195,20); | 50 | boxodds->setGeometry(40,200,195,20); |
53 | fillBox("odds",boxodds); | 51 | fillBox("odds",boxodds); |
54 | boxodds->setEnabled(false); | 52 | boxodds->setEnabled(false); |
55 | 53 | ||
56 | QLabel* labeltable=new QLabel("table",this); | 54 | QLabel* labeltable=new QLabel("table",this); |
57 | labeltable->setGeometry(0,225,40,20); | 55 | labeltable->setGeometry(0,225,40,20); |
58 | boxtable=new QComboBox(this); | 56 | boxtable=new QComboBox(this); |
59 | boxtable->setGeometry(40,225,195,20); | 57 | boxtable->setGeometry(40,225,195,20); |
60 | fillBox("table",boxtable); | 58 | fillBox("table",boxtable); |
61 | 59 | ||
62 | QPEApplication::showDialog( this ); | 60 | QPEApplication::showDialog( this ); |
63 | } | 61 | } |
64 | 62 | ||
65 | ThemeDialog::~ThemeDialog() | 63 | ThemeDialog::~ThemeDialog() |
66 | {} | 64 | {} |
67 | 65 | ||
68 | 66 | ||
69 | ImageNames ThemeDialog::getNames() | 67 | ImageNames ThemeDialog::getNames() |
70 | { | 68 | { |
71 | ImageNames names; | 69 | ImageNames names; |
72 | names.theme=lineName->text(); | 70 | names.theme=lineName->text(); |
73 | names.board=boxboard->currentText(); | 71 | names.board=boxboard->currentText(); |
74 | names.pieces1=boxpiecesA->currentText(); | 72 | names.pieces1=boxpiecesA->currentText(); |
75 | names.pieces2=boxpiecesB->currentText(); | 73 | names.pieces2=boxpiecesB->currentText(); |
76 | names.dice1=boxdiceA->currentText(); | 74 | names.dice1=boxdiceA->currentText(); |
77 | names.dice2=boxdiceB->currentText(); | 75 | names.dice2=boxdiceB->currentText(); |
78 | names.odds=boxodds->currentText(); | 76 | names.odds=boxodds->currentText(); |
79 | names.table=boxtable->currentText(); | 77 | names.table=boxtable->currentText(); |
80 | return names; | 78 | return names; |
81 | } | 79 | } |
82 | 80 | ||
83 | void ThemeDialog::setCurrent(const ImageNames& current) | 81 | void ThemeDialog::setCurrent(const ImageNames& current) |
84 | { | 82 | { |
85 | int a=0; | 83 | int a=0; |
86 | lineName->setText(current.theme); | 84 | lineName->setText(current.theme); |
87 | for(a=0;a<boxboard->count();a++) | 85 | for(a=0;a<boxboard->count();a++) |
88 | { | 86 | { |
89 | if(boxboard->text(a)==current.board) | 87 | if(boxboard->text(a)==current.board) |
90 | { | 88 | { |
91 | boxboard->setCurrentItem(a); | 89 | boxboard->setCurrentItem(a); |
92 | break; | 90 | break; |
93 | } | 91 | } |
94 | } | 92 | } |
95 | for(a=0;a<boxpiecesA->count();a++) | 93 | for(a=0;a<boxpiecesA->count();a++) |
96 | { | 94 | { |
97 | if(boxpiecesA->text(a)==current.pieces1) | 95 | if(boxpiecesA->text(a)==current.pieces1) |
98 | { | 96 | { |
99 | boxpiecesA->setCurrentItem(a); | 97 | boxpiecesA->setCurrentItem(a); |
100 | break; | 98 | break; |
101 | } | 99 | } |
102 | } | 100 | } |
103 | for(a=0;a<boxpiecesB->count();a++) | 101 | for(a=0;a<boxpiecesB->count();a++) |
104 | { | 102 | { |
105 | if(boxpiecesB->text(a)==current.pieces2) | 103 | if(boxpiecesB->text(a)==current.pieces2) |
106 | { | 104 | { |
107 | boxpiecesB->setCurrentItem(a); | 105 | boxpiecesB->setCurrentItem(a); |
108 | break; | 106 | break; |
109 | } | 107 | } |
110 | } | 108 | } |
111 | for(a=0;a<boxdiceA->count();a++) | 109 | for(a=0;a<boxdiceA->count();a++) |
112 | { | 110 | { |
113 | if(boxdiceA->text(a)==current.dice1) | 111 | if(boxdiceA->text(a)==current.dice1) |
114 | { | 112 | { |
115 | boxdiceA->setCurrentItem(a); | 113 | boxdiceA->setCurrentItem(a); |
116 | break; | 114 | break; |
117 | } | 115 | } |
118 | } | 116 | } |
119 | for(a=0;a<boxdiceB->count();a++) | 117 | for(a=0;a<boxdiceB->count();a++) |
120 | { | 118 | { |
121 | if(boxdiceB->text(a)==current.dice2) | 119 | if(boxdiceB->text(a)==current.dice2) |
122 | { | 120 | { |
123 | boxdiceB->setCurrentItem(a); | 121 | boxdiceB->setCurrentItem(a); |
124 | break; | 122 | break; |
125 | } | 123 | } |
126 | } | 124 | } |
127 | for(a=0;a<boxodds->count();a++) | 125 | for(a=0;a<boxodds->count();a++) |
128 | { | 126 | { |
129 | if(boxodds->text(a)==current.odds) | 127 | if(boxodds->text(a)==current.odds) |
130 | { | 128 | { |
131 | boxodds->setCurrentItem(a); | 129 | boxodds->setCurrentItem(a); |
132 | break; | 130 | break; |
133 | } | 131 | } |
134 | } | 132 | } |
135 | for(a=0;a<boxtable->count();a++) | 133 | for(a=0;a<boxtable->count();a++) |
136 | { | 134 | { |
137 | if(boxtable->text(a)==current.table) | 135 | if(boxtable->text(a)==current.table) |
138 | { | 136 | { |
139 | boxtable->setCurrentItem(a); | 137 | boxtable->setCurrentItem(a); |
140 | break; | 138 | break; |
141 | } | 139 | } |
142 | } | 140 | } |
143 | } | 141 | } |
144 | 142 | ||
145 | void ThemeDialog::fillBox(QString dirname,QComboBox* thebox) | 143 | void ThemeDialog::fillBox(QString dirname,QComboBox* thebox) |
146 | { | 144 | { |
147 | thebox->clear(); | 145 | thebox->clear(); |
148 | QDir dir(QPEApplication::qpeDir()+"/pics/backgammon/"+dirname); | 146 | QDir dir(QPEApplication::qpeDir()+"/pics/backgammon/"+dirname); |
149 | dir.setFilter(QDir::Dirs | QDir::Files); | 147 | dir.setFilter(QDir::Dirs | QDir::Files); |
150 | QFileInfoListIterator it(*(dir.entryInfoList())); | 148 | QFileInfoListIterator it(*(dir.entryInfoList())); |
151 | QFileInfo* fi; | 149 | QFileInfo* fi; |
152 | 150 | ||
153 | while((fi=it.current())) // go through all file and subdirs | 151 | while((fi=it.current())) // go through all file and subdirs |
154 | { | 152 | { |
155 | QString file=fi->fileName(); | 153 | QString file=fi->fileName(); |
156 | if(file.right(4)==".png") | 154 | if(file.right(4)==".png") |
157 | { | 155 | { |
158 | thebox->insertItem(file.left(file.find(".png"))); | 156 | thebox->insertItem(file.left(file.find(".png"))); |
159 | } | 157 | } |
160 | ++it; | 158 | ++it; |
161 | } | 159 | } |
162 | delete fi; | 160 | delete fi; |
163 | } | 161 | } |
diff --git a/noncore/games/bounce/game.cpp b/noncore/games/bounce/game.cpp index 6ded218..c07f453 100644 --- a/noncore/games/bounce/game.cpp +++ b/noncore/games/bounce/game.cpp | |||
@@ -1,535 +1,534 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2000 Stefan Schimanski <1Stein@gmx.de> | 2 | * Copyright (C) 2000 Stefan Schimanski <1Stein@gmx.de> |
3 | * | 3 | * |
4 | * This program is free software; you can redistribute it and/or | 4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Library General Public | 5 | * modify it under the terms of the GNU Library General Public |
6 | * License as published by the Free Software Foundation; either | 6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. | 7 | * version 2 of the License, or (at your option) any later version. |
8 | * | 8 | * |
9 | * This program is distributed in the hope that it will be useful, | 9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Library General Public License for more details. | 12 | * Library General Public License for more details. |
13 | * | 13 | * |
14 | * You should have received a copy of the GNU Library General Public | 14 | * You should have received a copy of the GNU Library General Public |
15 | * License along with this program; if not, write to the Free | 15 | * License along with this program; if not, write to the Free |
16 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 16 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
17 | */ | 17 | */ |
18 | 18 | ||
19 | 19 | ||
20 | #include <stdlib.h> | 20 | #include <stdlib.h> |
21 | #include <qtimer.h> | 21 | #include <qtimer.h> |
22 | #include <qpe/qpeapplication.h> | 22 | #include <qpe/qpeapplication.h> |
23 | #include <qimage.h> | ||
24 | 23 | ||
25 | #include "game.h" | 24 | #include "game.h" |
26 | 25 | ||
27 | #define TILE_SIZE 9 | 26 | #define TILE_SIZE 9 |
28 | 27 | ||
29 | #define TILE_FIRST ((FIELD_WIDTH-2)*(FIELD_HEIGHT-2)) | 28 | #define TILE_FIRST ((FIELD_WIDTH-2)*(FIELD_HEIGHT-2)) |
30 | #define TILE_FREE (TILE_FIRST + 0) | 29 | #define TILE_FREE (TILE_FIRST + 0) |
31 | #define TILE_BORDER (TILE_FIRST + 1) | 30 | #define TILE_BORDER (TILE_FIRST + 1) |
32 | #define TILE_WALLEND (TILE_FIRST + 2) | 31 | #define TILE_WALLEND (TILE_FIRST + 2) |
33 | #define TILE_WALLUP (TILE_FIRST + 3) | 32 | #define TILE_WALLUP (TILE_FIRST + 3) |
34 | #define TILE_WALLDOWN (TILE_FIRST + 4) | 33 | #define TILE_WALLDOWN (TILE_FIRST + 4) |
35 | #define TILE_WALLLEFT (TILE_FIRST + 5) | 34 | #define TILE_WALLLEFT (TILE_FIRST + 5) |
36 | #define TILE_WALLRIGHT (TILE_FIRST + 6) | 35 | #define TILE_WALLRIGHT (TILE_FIRST + 6) |
37 | 36 | ||
38 | #define GAME_DELAY 15 | 37 | #define GAME_DELAY 15 |
39 | #define BALL_ANIM_DELAY 60 | 38 | #define BALL_ANIM_DELAY 60 |
40 | #define WALL_DELAY 100 | 39 | #define WALL_DELAY 100 |
41 | 40 | ||
42 | #define MS2TICKS( ms ) ((ms)/GAME_DELAY) | 41 | #define MS2TICKS( ms ) ((ms)/GAME_DELAY) |
43 | 42 | ||
44 | Arrow::Arrow(QCanvasPixmapArray* array, QCanvas* canvas) | 43 | Arrow::Arrow(QCanvasPixmapArray* array, QCanvas* canvas) |
45 | : QCanvasSprite( array, canvas ) | 44 | : QCanvasSprite( array, canvas ) |
46 | { | 45 | { |
47 | m_vertical = true; | 46 | m_vertical = true; |
48 | move(3,3); | 47 | move(3,3); |
49 | } | 48 | } |
50 | 49 | ||
51 | void Arrow::update() | 50 | void Arrow::update() |
52 | { | 51 | { |
53 | if ( m_vertical ) | 52 | if ( m_vertical ) |
54 | setFrame( 0 ); | 53 | setFrame( 0 ); |
55 | else | 54 | else |
56 | setFrame( 1 ); | 55 | setFrame( 1 ); |
57 | } | 56 | } |
58 | 57 | ||
59 | void Arrow::changeDirection() | 58 | void Arrow::changeDirection() |
60 | { | 59 | { |
61 | m_vertical = ! m_vertical; | 60 | m_vertical = ! m_vertical; |
62 | update(); | 61 | update(); |
63 | } | 62 | } |
64 | 63 | ||
65 | 64 | ||
66 | Ball::Ball(QCanvasPixmapArray* array, QCanvas* canvas) | 65 | Ball::Ball(QCanvasPixmapArray* array, QCanvas* canvas) |
67 | : QCanvasSprite( array, canvas ), m_animDelay( 0 ), m_soundDelay( MS2TICKS(BALL_ANIM_DELAY)/2 ) | 66 | : QCanvasSprite( array, canvas ), m_animDelay( 0 ), m_soundDelay( MS2TICKS(BALL_ANIM_DELAY)/2 ) |
68 | { | 67 | { |
69 | } | 68 | } |
70 | 69 | ||
71 | void Ball::update() | 70 | void Ball::update() |
72 | { | 71 | { |
73 | m_animDelay--; | 72 | m_animDelay--; |
74 | if ( m_animDelay<=0 ) | 73 | if ( m_animDelay<=0 ) |
75 | { | 74 | { |
76 | m_animDelay = MS2TICKS(BALL_ANIM_DELAY); | 75 | m_animDelay = MS2TICKS(BALL_ANIM_DELAY); |
77 | int frameNum = frame(); | 76 | int frameNum = frame(); |
78 | frameNum++; | 77 | frameNum++; |
79 | if ( frameNum>=frameCount() ) | 78 | if ( frameNum>=frameCount() ) |
80 | frameNum = 0; | 79 | frameNum = 0; |
81 | setFrame( frameNum ); | 80 | setFrame( frameNum ); |
82 | } | 81 | } |
83 | } | 82 | } |
84 | 83 | ||
85 | void Ball::advance(int stage) | 84 | void Ball::advance(int stage) |
86 | { | 85 | { |
87 | bool reflectX = false; | 86 | bool reflectX = false; |
88 | bool reflectY = false; | 87 | bool reflectY = false; |
89 | 88 | ||
90 | // check for collisions | 89 | // check for collisions |
91 | if ( collide(xVelocity(), 0) ) reflectX = true; | 90 | if ( collide(xVelocity(), 0) ) reflectX = true; |
92 | if ( collide(0, yVelocity()) ) reflectY = true; | 91 | if ( collide(0, yVelocity()) ) reflectY = true; |
93 | if ( !reflectX && !reflectY && collide(xVelocity(), yVelocity()) ) reflectX = reflectY = true; | 92 | if ( !reflectX && !reflectY && collide(xVelocity(), yVelocity()) ) reflectX = reflectY = true; |
94 | 93 | ||
95 | // emit collision | 94 | // emit collision |
96 | QRect r = boundingRect(); | 95 | QRect r = boundingRect(); |
97 | r.moveBy( xVelocity(), yVelocity() ); | 96 | r.moveBy( xVelocity(), yVelocity() ); |
98 | JezzField* field = (JezzField *)canvas(); | 97 | JezzField* field = (JezzField *)canvas(); |
99 | 98 | ||
100 | int ul = field->tile( r.left() / TILE_SIZE, r.top() / TILE_SIZE ); | 99 | int ul = field->tile( r.left() / TILE_SIZE, r.top() / TILE_SIZE ); |
101 | int ur = field->tile( r.right() / TILE_SIZE, r.top() / TILE_SIZE ); | 100 | int ur = field->tile( r.right() / TILE_SIZE, r.top() / TILE_SIZE ); |
102 | int bl = field->tile( r.left() / TILE_SIZE, r.bottom() / TILE_SIZE ); | 101 | int bl = field->tile( r.left() / TILE_SIZE, r.bottom() / TILE_SIZE ); |
103 | int br = field->tile( r.right() / TILE_SIZE, r.bottom() / TILE_SIZE ); | 102 | int br = field->tile( r.right() / TILE_SIZE, r.bottom() / TILE_SIZE ); |
104 | 103 | ||
105 | if ( ul!=TILE_FREE ) field->emitBallCollisiton( this, r.left() / TILE_SIZE, r.top() / TILE_SIZE, ul ); else | 104 | if ( ul!=TILE_FREE ) field->emitBallCollisiton( this, r.left() / TILE_SIZE, r.top() / TILE_SIZE, ul ); else |
106 | if ( ur!=TILE_FREE ) field->emitBallCollisiton( this, r.right() / TILE_SIZE, r.top() / TILE_SIZE, ur ); else | 105 | if ( ur!=TILE_FREE ) field->emitBallCollisiton( this, r.right() / TILE_SIZE, r.top() / TILE_SIZE, ur ); else |
107 | if ( bl!=TILE_FREE ) field->emitBallCollisiton( this, r.left() / TILE_SIZE, r.bottom() / TILE_SIZE, bl ); else | 106 | if ( bl!=TILE_FREE ) field->emitBallCollisiton( this, r.left() / TILE_SIZE, r.bottom() / TILE_SIZE, bl ); else |
108 | if ( br!=TILE_FREE ) field->emitBallCollisiton( this, r.right() / TILE_SIZE, r.bottom() / TILE_SIZE, br ); | 107 | if ( br!=TILE_FREE ) field->emitBallCollisiton( this, r.right() / TILE_SIZE, r.bottom() / TILE_SIZE, br ); |
109 | 108 | ||
110 | // apply reflection | 109 | // apply reflection |
111 | if ( reflectX ) setXVelocity( -xVelocity() ); | 110 | if ( reflectX ) setXVelocity( -xVelocity() ); |
112 | if ( reflectY ) setYVelocity( -yVelocity() ); | 111 | if ( reflectY ) setYVelocity( -yVelocity() ); |
113 | 112 | ||
114 | // update field | 113 | // update field |
115 | update(); | 114 | update(); |
116 | QCanvasSprite::advance( stage ); | 115 | QCanvasSprite::advance( stage ); |
117 | } | 116 | } |
118 | 117 | ||
119 | bool Ball::collide( double dx, double dy ) | 118 | bool Ball::collide( double dx, double dy ) |
120 | { | 119 | { |
121 | QRect r = boundingRect(); | 120 | QRect r = boundingRect(); |
122 | r.moveBy( dx, dy ); | 121 | r.moveBy( dx, dy ); |
123 | JezzField* field = (JezzField *)canvas(); | 122 | JezzField* field = (JezzField *)canvas(); |
124 | 123 | ||
125 | int ul = field->tile( r.left() / TILE_SIZE, r.top() / TILE_SIZE ); | 124 | int ul = field->tile( r.left() / TILE_SIZE, r.top() / TILE_SIZE ); |
126 | int ur = field->tile( r.right() / TILE_SIZE, r.top() / TILE_SIZE ); | 125 | int ur = field->tile( r.right() / TILE_SIZE, r.top() / TILE_SIZE ); |
127 | int bl = field->tile( r.left() / TILE_SIZE, r.bottom() / TILE_SIZE ); | 126 | int bl = field->tile( r.left() / TILE_SIZE, r.bottom() / TILE_SIZE ); |
128 | int br = field->tile( r.right() / TILE_SIZE, r.bottom() / TILE_SIZE ); | 127 | int br = field->tile( r.right() / TILE_SIZE, r.bottom() / TILE_SIZE ); |
129 | 128 | ||
130 | return ( ul!=TILE_FREE || ur!=TILE_FREE || bl!=TILE_FREE || br!=TILE_FREE ); | 129 | return ( ul!=TILE_FREE || ur!=TILE_FREE || bl!=TILE_FREE || br!=TILE_FREE ); |
131 | } | 130 | } |
132 | 131 | ||
133 | /*************************************************************************/ | 132 | /*************************************************************************/ |
134 | 133 | ||
135 | Wall::Wall( JezzField *field, int x, int y, Direction dir, int tile, QObject *parent, const char *name ) | 134 | Wall::Wall( JezzField *field, int x, int y, Direction dir, int tile, QObject *parent, const char *name ) |
136 | : QObject( parent, name ), m_dir( dir ), m_field( field ), m_startX( x ), m_startY( y ), | 135 | : QObject( parent, name ), m_dir( dir ), m_field( field ), m_startX( x ), m_startY( y ), |
137 | m_tile( tile ), m_delay( MS2TICKS(WALL_DELAY)/2 ), m_active( true ) | 136 | m_tile( tile ), m_delay( MS2TICKS(WALL_DELAY)/2 ), m_active( true ) |
138 | { | 137 | { |
139 | // setup position and direction | 138 | // setup position and direction |
140 | m_dx = 0; | 139 | m_dx = 0; |
141 | m_dy = 0; | 140 | m_dy = 0; |
142 | switch ( m_dir ) | 141 | switch ( m_dir ) |
143 | { | 142 | { |
144 | case Up: m_dy = -1; break; | 143 | case Up: m_dy = -1; break; |
145 | case Down: m_dy = 1; break; | 144 | case Down: m_dy = 1; break; |
146 | case Left: m_dx = -1; break; | 145 | case Left: m_dx = -1; break; |
147 | case Right: m_dx = 1; break; | 146 | case Right: m_dx = 1; break; |
148 | } | 147 | } |
149 | 148 | ||
150 | m_x = m_startX; | 149 | m_x = m_startX; |
151 | m_y = m_startY; | 150 | m_y = m_startY; |
152 | 151 | ||
153 | m_field->setTile( m_x, m_y, m_tile ); | 152 | m_field->setTile( m_x, m_y, m_tile ); |
154 | } | 153 | } |
155 | 154 | ||
156 | void Wall::finish() | 155 | void Wall::finish() |
157 | { | 156 | { |
158 | m_active = false; | 157 | m_active = false; |
159 | } | 158 | } |
160 | 159 | ||
161 | bool Wall::isFree( int x, int y ) | 160 | bool Wall::isFree( int x, int y ) |
162 | { | 161 | { |
163 | if ( m_field->tile(x, y)==TILE_FREE ) | 162 | if ( m_field->tile(x, y)==TILE_FREE ) |
164 | { | 163 | { |
165 | // check whether there is a ball at the moment | 164 | // check whether there is a ball at the moment |
166 | QCanvasItemList cols = m_field->collisions( QRect(x*TILE_SIZE, y*TILE_SIZE, | 165 | QCanvasItemList cols = m_field->collisions( QRect(x*TILE_SIZE, y*TILE_SIZE, |
167 | TILE_SIZE, TILE_SIZE) ); | 166 | TILE_SIZE, TILE_SIZE) ); |
168 | if ( cols.count()==0 ) | 167 | if ( cols.count()==0 ) |
169 | return true; | 168 | return true; |
170 | } | 169 | } |
171 | 170 | ||
172 | return false; | 171 | return false; |
173 | } | 172 | } |
174 | 173 | ||
175 | void Wall::update() | 174 | void Wall::update() |
176 | { | 175 | { |
177 | } | 176 | } |
178 | 177 | ||
179 | void Wall::advance() | 178 | void Wall::advance() |
180 | { | 179 | { |
181 | update(); | 180 | update(); |
182 | 181 | ||
183 | // move wall | 182 | // move wall |
184 | if ( m_active ) | 183 | if ( m_active ) |
185 | { | 184 | { |
186 | m_delay--; | 185 | m_delay--; |
187 | if ( m_delay<=0 ) | 186 | if ( m_delay<=0 ) |
188 | { | 187 | { |
189 | m_delay = MS2TICKS(WALL_DELAY); | 188 | m_delay = MS2TICKS(WALL_DELAY); |
190 | 189 | ||
191 | // set previous tile | 190 | // set previous tile |
192 | m_field->setTile( m_x, m_y, m_tile ); | 191 | m_field->setTile( m_x, m_y, m_tile ); |
193 | 192 | ||
194 | // check whether next place is still free | 193 | // check whether next place is still free |
195 | if ( isFree(m_x+m_dx, m_y+m_dy) ) | 194 | if ( isFree(m_x+m_dx, m_y+m_dy) ) |
196 | { | 195 | { |
197 | // move ball | 196 | // move ball |
198 | m_x += m_dx; | 197 | m_x += m_dx; |
199 | m_y += m_dy; | 198 | m_y += m_dy; |
200 | 199 | ||
201 | // set tile | 200 | // set tile |
202 | m_field->setTile( m_x, m_y, TILE_WALLEND ); | 201 | m_field->setTile( m_x, m_y, TILE_WALLEND ); |
203 | } else | 202 | } else |
204 | { | 203 | { |
205 | finish(); | 204 | finish(); |
206 | emit finished( this, m_field->tile( m_x+m_dx, m_y+m_dy ) ); | 205 | emit finished( this, m_field->tile( m_x+m_dx, m_y+m_dy ) ); |
207 | } | 206 | } |
208 | } | 207 | } |
209 | } | 208 | } |
210 | } | 209 | } |
211 | 210 | ||
212 | void Wall::fill( bool black ) | 211 | void Wall::fill( bool black ) |
213 | { | 212 | { |
214 | if ( m_dx ) | 213 | if ( m_dx ) |
215 | { | 214 | { |
216 | for ( int x=m_startX ; x!=m_x; x+=m_dx ) | 215 | for ( int x=m_startX ; x!=m_x; x+=m_dx ) |
217 | if ( m_field->tile(x, m_startY)==m_tile ) | 216 | if ( m_field->tile(x, m_startY)==m_tile ) |
218 | m_field->setGameTile( x, m_startY, black ); | 217 | m_field->setGameTile( x, m_startY, black ); |
219 | 218 | ||
220 | m_field->setGameTile( m_x, m_startY, black ); | 219 | m_field->setGameTile( m_x, m_startY, black ); |
221 | } else | 220 | } else |
222 | { | 221 | { |
223 | for ( int y=m_startY ; y!=m_y; y+=m_dy ) | 222 | for ( int y=m_startY ; y!=m_y; y+=m_dy ) |
224 | if ( m_field->tile(m_startX, y)==m_tile ) | 223 | if ( m_field->tile(m_startX, y)==m_tile ) |
225 | m_field->setGameTile( m_startX, y, black ); | 224 | m_field->setGameTile( m_startX, y, black ); |
226 | 225 | ||
227 | m_field->setGameTile( m_startX, m_y, black ); | 226 | m_field->setGameTile( m_startX, m_y, black ); |
228 | } | 227 | } |
229 | } | 228 | } |
230 | 229 | ||
231 | /*************************************************************************/ | 230 | /*************************************************************************/ |
232 | 231 | ||
233 | JezzField::JezzField( QPixmap tiles, QObject* parent, const char* name ) | 232 | JezzField::JezzField( QPixmap tiles, QObject* parent, const char* name ) |
234 | : QCanvas( parent, name ), m_tiles( tiles ) | 233 | : QCanvas( parent, name ), m_tiles( tiles ) |
235 | { | 234 | { |
236 | setPixmaps( tiles ); | 235 | setPixmaps( tiles ); |
237 | } | 236 | } |
238 | 237 | ||
239 | void JezzField::setGameTile( int x, int y, bool black ) | 238 | void JezzField::setGameTile( int x, int y, bool black ) |
240 | { | 239 | { |
241 | setTile( x, y, black ? TILE_BORDER : TILE_FREE ); | 240 | setTile( x, y, black ? TILE_BORDER : TILE_FREE ); |
242 | } | 241 | } |
243 | 242 | ||
244 | void JezzField::setPixmaps( QPixmap tiles ) | 243 | void JezzField::setPixmaps( QPixmap tiles ) |
245 | { | 244 | { |
246 | // create new tiles | 245 | // create new tiles |
247 | QPixmap allTiles( TILE_SIZE*(FIELD_WIDTH-2), TILE_SIZE*(FIELD_HEIGHT-1) ); | 246 | QPixmap allTiles( TILE_SIZE*(FIELD_WIDTH-2), TILE_SIZE*(FIELD_HEIGHT-1) ); |
248 | 247 | ||
249 | // handle default tiles | 248 | // handle default tiles |
250 | bitBlt( &allTiles, 0, TILE_SIZE*(FIELD_HEIGHT-2), | 249 | bitBlt( &allTiles, 0, TILE_SIZE*(FIELD_HEIGHT-2), |
251 | &tiles, 0, 0, tiles.width(), tiles.height() ); | 250 | &tiles, 0, 0, tiles.width(), tiles.height() ); |
252 | 251 | ||
253 | // load tiles into canvas | 252 | // load tiles into canvas |
254 | setTiles( allTiles, FIELD_WIDTH, FIELD_HEIGHT, TILE_SIZE, TILE_SIZE ); | 253 | setTiles( allTiles, FIELD_WIDTH, FIELD_HEIGHT, TILE_SIZE, TILE_SIZE ); |
255 | } | 254 | } |
256 | 255 | ||
257 | /*************************************************************************/ | 256 | /*************************************************************************/ |
258 | 257 | ||
259 | JezzView::JezzView(QCanvas* viewing, QWidget* parent, const char* name, WFlags f) | 258 | JezzView::JezzView(QCanvas* viewing, QWidget* parent, const char* name, WFlags f) |
260 | : QCanvasView( viewing, parent, name, f ), m_vertical( false ) | 259 | : QCanvasView( viewing, parent, name, f ), m_vertical( false ) |
261 | { | 260 | { |
262 | setResizePolicy( AutoOne ); | 261 | setResizePolicy( AutoOne ); |
263 | setHScrollBarMode( AlwaysOff ); | 262 | setHScrollBarMode( AlwaysOff ); |
264 | setVScrollBarMode( AlwaysOff ); | 263 | setVScrollBarMode( AlwaysOff ); |
265 | 264 | ||
266 | setCursor( sizeHorCursor ); | 265 | setCursor( sizeHorCursor ); |
267 | } | 266 | } |
268 | 267 | ||
269 | void JezzView::viewportMouseReleaseEvent( QMouseEvent *ev ) | 268 | void JezzView::viewportMouseReleaseEvent( QMouseEvent *ev ) |
270 | { | 269 | { |
271 | if ( ev->button() & LeftButton ) | 270 | if ( ev->button() & LeftButton ) |
272 | { | 271 | { |
273 | emit buildWall( ev->x()/TILE_SIZE, ev->y()/TILE_SIZE, m_vertical ); | 272 | emit buildWall( ev->x()/TILE_SIZE, ev->y()/TILE_SIZE, m_vertical ); |
274 | } | 273 | } |
275 | } | 274 | } |
276 | 275 | ||
277 | void JezzView::changeCursor() | 276 | void JezzView::changeCursor() |
278 | { | 277 | { |
279 | m_vertical = !m_vertical; | 278 | m_vertical = !m_vertical; |
280 | if ( m_vertical ) | 279 | if ( m_vertical ) |
281 | { | 280 | { |
282 | setCursor( sizeVerCursor ); | 281 | setCursor( sizeVerCursor ); |
283 | } | 282 | } |
284 | else | 283 | else |
285 | { | 284 | { |
286 | setCursor( sizeHorCursor ); | 285 | setCursor( sizeHorCursor ); |
287 | } | 286 | } |
288 | } | 287 | } |
289 | 288 | ||
290 | /*************************************************************************/ | 289 | /*************************************************************************/ |
291 | 290 | ||
292 | JezzGame::JezzGame( int ballNum, QWidget *parent, const char *name ) | 291 | JezzGame::JezzGame( int ballNum, QWidget *parent, const char *name ) |
293 | : QWidget( parent, name ), m_wall1( 0 ), m_wall2( 0 ), | 292 | : QWidget( parent, name ), m_wall1( 0 ), m_wall2( 0 ), |
294 | m_text( 0 ), m_running( false ), m_percent( 0 ), m_pictured( false ) | 293 | m_text( 0 ), m_running( false ), m_percent( 0 ), m_pictured( false ) |
295 | { | 294 | { |
296 | QString path = QPEApplication::qpeDir()+"pics/bounce/"; | 295 | QString path = QPEApplication::qpeDir()+"pics/bounce/"; |
297 | 296 | ||
298 | // load gfx | 297 | // load gfx |
299 | m_ballPixmaps = new QCanvasPixmapArray( path + "ball%1.png", 25 ); | 298 | m_ballPixmaps = new QCanvasPixmapArray( path + "ball%1.png", 25 ); |
300 | for ( unsigned n=0; n < m_ballPixmaps->count(); n++ ) | 299 | for ( unsigned n=0; n < m_ballPixmaps->count(); n++ ) |
301 | m_ballPixmaps->image(n)->setOffset( 0, 0 ); | 300 | m_ballPixmaps->image(n)->setOffset( 0, 0 ); |
302 | 301 | ||
303 | m_arrowPixmaps = new QCanvasPixmapArray( path + "arrow%1.png", 2 ); | 302 | m_arrowPixmaps = new QCanvasPixmapArray( path + "arrow%1.png", 2 ); |
304 | for ( unsigned n=0; n < m_arrowPixmaps->count(); n++ ) | 303 | for ( unsigned n=0; n < m_arrowPixmaps->count(); n++ ) |
305 | m_arrowPixmaps->image(n)->setOffset( 0, 0 ); | 304 | m_arrowPixmaps->image(n)->setOffset( 0, 0 ); |
306 | 305 | ||
307 | QPixmap tiles( path + "tiles.png" ); | 306 | QPixmap tiles( path + "tiles.png" ); |
308 | 307 | ||
309 | // create field | 308 | // create field |
310 | m_field = new JezzField( tiles, this, "m_field" ); | 309 | m_field = new JezzField( tiles, this, "m_field" ); |
311 | m_field->resize( TILE_SIZE*FIELD_WIDTH, TILE_SIZE*FIELD_HEIGHT ); | 310 | m_field->resize( TILE_SIZE*FIELD_WIDTH, TILE_SIZE*FIELD_HEIGHT ); |
312 | 311 | ||
313 | for ( int x=0; x<FIELD_WIDTH; x++ ) | 312 | for ( int x=0; x<FIELD_WIDTH; x++ ) |
314 | m_field->setTile( x, 0, TILE_BORDER ); | 313 | m_field->setTile( x, 0, TILE_BORDER ); |
315 | for ( int y=1; y<FIELD_HEIGHT-1; y++ ) | 314 | for ( int y=1; y<FIELD_HEIGHT-1; y++ ) |
316 | { | 315 | { |
317 | m_field->setTile( 0, y, TILE_BORDER ); | 316 | m_field->setTile( 0, y, TILE_BORDER ); |
318 | for ( int x=1; x<FIELD_WIDTH-1; x++ ) | 317 | for ( int x=1; x<FIELD_WIDTH-1; x++ ) |
319 | m_field->setTile( x, y, TILE_FREE ); | 318 | m_field->setTile( x, y, TILE_FREE ); |
320 | m_field->setTile( FIELD_WIDTH-1, y, TILE_BORDER ); | 319 | m_field->setTile( FIELD_WIDTH-1, y, TILE_BORDER ); |
321 | } | 320 | } |
322 | for ( int x=0; x<FIELD_WIDTH; x++ ) | 321 | for ( int x=0; x<FIELD_WIDTH; x++ ) |
323 | m_field->setTile( x, FIELD_HEIGHT-1, TILE_BORDER ); | 322 | m_field->setTile( x, FIELD_HEIGHT-1, TILE_BORDER ); |
324 | 323 | ||
325 | connect( m_field, SIGNAL(ballCollision(Ball *, int, int, int)), this, SLOT(ballCollision(Ball *, int, int, int)) ); | 324 | connect( m_field, SIGNAL(ballCollision(Ball *, int, int, int)), this, SLOT(ballCollision(Ball *, int, int, int)) ); |
326 | 325 | ||
327 | // create view | 326 | // create view |
328 | m_view = new JezzView( m_field, this, "m_view" ); | 327 | m_view = new JezzView( m_field, this, "m_view" ); |
329 | m_view->move( 0, 0 ); | 328 | m_view->move( 0, 0 ); |
330 | m_view->adjustSize(); | 329 | m_view->adjustSize(); |
331 | connect( m_view, SIGNAL(buildWall(int, int, bool)), this, SLOT(buildWall(int, int, bool)) ); | 330 | connect( m_view, SIGNAL(buildWall(int, int, bool)), this, SLOT(buildWall(int, int, bool)) ); |
332 | 331 | ||
333 | // create balls | 332 | // create balls |
334 | for ( int n=0; n<ballNum; n++ ) | 333 | for ( int n=0; n<ballNum; n++ ) |
335 | { | 334 | { |
336 | Ball *ball = new Ball( m_ballPixmaps, m_field ); | 335 | Ball *ball = new Ball( m_ballPixmaps, m_field ); |
337 | m_balls.append( ball ); | 336 | m_balls.append( ball ); |
338 | ball->setVelocity( ((rand() & 1)*2-1)*2, ((rand() & 1)*2-1)*2 ); | 337 | ball->setVelocity( ((rand() & 1)*2-1)*2, ((rand() & 1)*2-1)*2 ); |
339 | ball->setFrame( rand() % 25 ); | 338 | ball->setFrame( rand() % 25 ); |
340 | ball->move( 4*TILE_SIZE + ( rand() - 50 ) % ( (FIELD_WIDTH-8)*TILE_SIZE ), | 339 | ball->move( 4*TILE_SIZE + ( rand() - 50 ) % ( (FIELD_WIDTH-8)*TILE_SIZE ), |
341 | 4*TILE_SIZE + rand() % ( (FIELD_HEIGHT-8)*TILE_SIZE ) ); | 340 | 4*TILE_SIZE + rand() % ( (FIELD_HEIGHT-8)*TILE_SIZE ) ); |
342 | ball->show(); | 341 | ball->show(); |
343 | } | 342 | } |
344 | 343 | ||
345 | // create arrow | 344 | // create arrow |
346 | arrow = new Arrow( m_arrowPixmaps, m_field ); | 345 | arrow = new Arrow( m_arrowPixmaps, m_field ); |
347 | arrow->show(); | 346 | arrow->show(); |
348 | 347 | ||
349 | // create text label | 348 | // create text label |
350 | m_text = new QCanvasText( m_field ); | 349 | m_text = new QCanvasText( m_field ); |
351 | 350 | ||
352 | // create game clock | 351 | // create game clock |
353 | m_clock = new QTimer( this ); | 352 | m_clock = new QTimer( this ); |
354 | connect( m_clock, SIGNAL(timeout()), this, SLOT(tick()) ); | 353 | connect( m_clock, SIGNAL(timeout()), this, SLOT(tick()) ); |
355 | m_clock->start( GAME_DELAY ); | 354 | m_clock->start( GAME_DELAY ); |
356 | 355 | ||
357 | // setup geometry | 356 | // setup geometry |
358 | setFixedSize( m_view->size() ); | 357 | setFixedSize( m_view->size() ); |
359 | } | 358 | } |
360 | 359 | ||
361 | JezzGame::~JezzGame() | 360 | JezzGame::~JezzGame() |
362 | { | 361 | { |
363 | m_balls.clear(); | 362 | m_balls.clear(); |
364 | delete m_view; | 363 | delete m_view; |
365 | delete m_field; | 364 | delete m_field; |
366 | delete m_ballPixmaps; | 365 | delete m_ballPixmaps; |
367 | } | 366 | } |
368 | 367 | ||
369 | void JezzGame::display( QString text, int size ) | 368 | void JezzGame::display( QString text, int size ) |
370 | { | 369 | { |
371 | qDebug("This function \"display\" shouldn't be called!!!"); | 370 | qDebug("This function \"display\" shouldn't be called!!!"); |
372 | if ( !text.isEmpty() ) | 371 | if ( !text.isEmpty() ) |
373 | { | 372 | { |
374 | QFont font( "Helvetica", size, QFont::Bold ); | 373 | QFont font( "Helvetica", size, QFont::Bold ); |
375 | font.setStyleHint( QFont::Helvetica ); | 374 | font.setStyleHint( QFont::Helvetica ); |
376 | m_text->setFont( font ); | 375 | m_text->setFont( font ); |
377 | m_text->setText( text ); | 376 | m_text->setText( text ); |
378 | 377 | ||
379 | QRect size = m_text->boundingRect(); | 378 | QRect size = m_text->boundingRect(); |
380 | m_text->move( ( FIELD_WIDTH*TILE_SIZE - size.width() ) / 2, | 379 | m_text->move( ( FIELD_WIDTH*TILE_SIZE - size.width() ) / 2, |
381 | ( FIELD_HEIGHT*TILE_SIZE - size.height() ) / 2 ); | 380 | ( FIELD_HEIGHT*TILE_SIZE - size.height() ) / 2 ); |
382 | 381 | ||
383 | m_text->show(); | 382 | m_text->show(); |
384 | } else | 383 | } else |
385 | { | 384 | { |
386 | m_text->hide(); | 385 | m_text->hide(); |
387 | } | 386 | } |
388 | } | 387 | } |
389 | 388 | ||
390 | void JezzGame::start() | 389 | void JezzGame::start() |
391 | { | 390 | { |
392 | m_running = true; | 391 | m_running = true; |
393 | } | 392 | } |
394 | 393 | ||
395 | void JezzGame::stop() | 394 | void JezzGame::stop() |
396 | { | 395 | { |
397 | m_running = false; | 396 | m_running = false; |
398 | } | 397 | } |
399 | 398 | ||
400 | 399 | ||
401 | void JezzGame::makeBlack() | 400 | void JezzGame::makeBlack() |
402 | { | 401 | { |
403 | // copy current field into buffer | 402 | // copy current field into buffer |
404 | for ( int y=0; y<FIELD_HEIGHT; y++ ) | 403 | for ( int y=0; y<FIELD_HEIGHT; y++ ) |
405 | for ( int x=0; x<FIELD_WIDTH; x++ ) | 404 | for ( int x=0; x<FIELD_WIDTH; x++ ) |
406 | m_buf[x][y] = m_field->tile( x, y ); | 405 | m_buf[x][y] = m_field->tile( x, y ); |
407 | 406 | ||
408 | // fill areas that contains a ball | 407 | // fill areas that contains a ball |
409 | for ( Ball *ball=m_balls.first(); ball!=0; ball=m_balls.next() ) | 408 | for ( Ball *ball=m_balls.first(); ball!=0; ball=m_balls.next() ) |
410 | fill( ball->x()/TILE_SIZE, ball->y()/TILE_SIZE ); | 409 | fill( ball->x()/TILE_SIZE, ball->y()/TILE_SIZE ); |
411 | 410 | ||
412 | // areas still free can be blacked now | 411 | // areas still free can be blacked now |
413 | for ( int y=0; y<FIELD_HEIGHT; y++ ) | 412 | for ( int y=0; y<FIELD_HEIGHT; y++ ) |
414 | for ( int x=0; x<FIELD_WIDTH; x++ ) | 413 | for ( int x=0; x<FIELD_WIDTH; x++ ) |
415 | { | 414 | { |
416 | if ( m_buf[x][y]==TILE_FREE ) | 415 | if ( m_buf[x][y]==TILE_FREE ) |
417 | m_field->setGameTile( x, y, true ); | 416 | m_field->setGameTile( x, y, true ); |
418 | } | 417 | } |
419 | 418 | ||
420 | m_field->update(); | 419 | m_field->update(); |
421 | m_view->repaint(); | 420 | m_view->repaint(); |
422 | 421 | ||
423 | // count percent value of occupied area | 422 | // count percent value of occupied area |
424 | int p = percent(); | 423 | int p = percent(); |
425 | if ( p!=m_percent ) | 424 | if ( p!=m_percent ) |
426 | { | 425 | { |
427 | m_percent = p; | 426 | m_percent = p; |
428 | emit newPercent( m_percent ); | 427 | emit newPercent( m_percent ); |
429 | } | 428 | } |
430 | } | 429 | } |
431 | 430 | ||
432 | int JezzGame::percent() | 431 | int JezzGame::percent() |
433 | { | 432 | { |
434 | int notFree = 0; | 433 | int notFree = 0; |
435 | for ( int y=1; y<FIELD_HEIGHT-1; y++ ) | 434 | for ( int y=1; y<FIELD_HEIGHT-1; y++ ) |
436 | for ( int x=1; x<FIELD_WIDTH-1; x++ ) | 435 | for ( int x=1; x<FIELD_WIDTH-1; x++ ) |
437 | { | 436 | { |
438 | if ( m_field->tile(x,y)!=TILE_FREE ) | 437 | if ( m_field->tile(x,y)!=TILE_FREE ) |
439 | notFree++; | 438 | notFree++; |
440 | } | 439 | } |
441 | 440 | ||
442 | return 100 * notFree / ( (FIELD_WIDTH-1) * (FIELD_HEIGHT-1) ); | 441 | return 100 * notFree / ( (FIELD_WIDTH-1) * (FIELD_HEIGHT-1) ); |
443 | } | 442 | } |
444 | 443 | ||
445 | void JezzGame::fill( int x, int y ) | 444 | void JezzGame::fill( int x, int y ) |
446 | { | 445 | { |
447 | if ( m_buf[x][y]!=TILE_FREE) return; | 446 | if ( m_buf[x][y]!=TILE_FREE) return; |
448 | 447 | ||
449 | // go left | 448 | // go left |
450 | int _x=x; | 449 | int _x=x; |
451 | for ( ; m_buf[_x][y]==TILE_FREE; _x-- ) | 450 | for ( ; m_buf[_x][y]==TILE_FREE; _x-- ) |
452 | m_buf[_x][y] = TILE_BORDER; | 451 | m_buf[_x][y] = TILE_BORDER; |
453 | int stopx = _x; | 452 | int stopx = _x; |
454 | 453 | ||
455 | // fill above | 454 | // fill above |
456 | for ( _x=x; _x>stopx; _x-- ) | 455 | for ( _x=x; _x>stopx; _x-- ) |
457 | if ( m_buf[_x][y-1]==TILE_FREE ) fill( _x, y-1 ); | 456 | if ( m_buf[_x][y-1]==TILE_FREE ) fill( _x, y-1 ); |
458 | 457 | ||
459 | // fill below | 458 | // fill below |
460 | for ( _x=x; _x>stopx; _x-- ) | 459 | for ( _x=x; _x>stopx; _x-- ) |
461 | if ( m_buf[_x][y+1]==TILE_FREE ) fill( _x, y+1 ); | 460 | if ( m_buf[_x][y+1]==TILE_FREE ) fill( _x, y+1 ); |
462 | 461 | ||
463 | // go right | 462 | // go right |
464 | for ( _x=x+1; m_buf[_x][y]==TILE_FREE; _x++ ) | 463 | for ( _x=x+1; m_buf[_x][y]==TILE_FREE; _x++ ) |
465 | m_buf[_x][y] = TILE_BORDER; | 464 | m_buf[_x][y] = TILE_BORDER; |
466 | stopx = _x; | 465 | stopx = _x; |
467 | 466 | ||
468 | // fill above | 467 | // fill above |
469 | for ( _x=x+1; _x<stopx; _x++ ) | 468 | for ( _x=x+1; _x<stopx; _x++ ) |
470 | if ( m_buf[_x][y-1]==TILE_FREE ) fill( _x, y-1 ); | 469 | if ( m_buf[_x][y-1]==TILE_FREE ) fill( _x, y-1 ); |
471 | 470 | ||
472 | // fill below; | 471 | // fill below; |
473 | for ( _x=x+1; _x<stopx; _x++ ) | 472 | for ( _x=x+1; _x<stopx; _x++ ) |
474 | if ( m_buf[_x][y+1]==TILE_FREE ) fill( _x, y+1 ); | 473 | if ( m_buf[_x][y+1]==TILE_FREE ) fill( _x, y+1 ); |
475 | } | 474 | } |
476 | 475 | ||
477 | void JezzGame::ballCollision( Ball*, int, int, int tile ) | 476 | void JezzGame::ballCollision( Ball*, int, int, int tile ) |
478 | { | 477 | { |
479 | if ( tile!=TILE_BORDER && tile>TILE_FREE && tile!=TILE_WALLEND ) | 478 | if ( tile!=TILE_BORDER && tile>TILE_FREE && tile!=TILE_WALLEND ) |
480 | { | 479 | { |
481 | // stop walls | 480 | // stop walls |
482 | if ( (tile==TILE_WALLUP || tile==TILE_WALLLEFT) && m_wall1 ) | 481 | if ( (tile==TILE_WALLUP || tile==TILE_WALLLEFT) && m_wall1 ) |
483 | { | 482 | { |
484 | m_wall1->finish(); | 483 | m_wall1->finish(); |
485 | m_wall1->fill( false ); | 484 | m_wall1->fill( false ); |
486 | delete m_wall1; | 485 | delete m_wall1; |
487 | m_wall1 = 0; | 486 | m_wall1 = 0; |
488 | } | 487 | } |
489 | 488 | ||
490 | if ( (tile==TILE_WALLDOWN || tile==TILE_WALLRIGHT) && m_wall2 ) | 489 | if ( (tile==TILE_WALLDOWN || tile==TILE_WALLRIGHT) && m_wall2 ) |
491 | { | 490 | { |
492 | m_wall2->finish(); | 491 | m_wall2->finish(); |
493 | m_wall2->fill( false ); | 492 | m_wall2->fill( false ); |
494 | delete m_wall2; | 493 | delete m_wall2; |
495 | m_wall2 = 0; | 494 | m_wall2 = 0; |
496 | } | 495 | } |
497 | 496 | ||
498 | // update view | 497 | // update view |
499 | m_field->update(); | 498 | m_field->update(); |
500 | m_view->repaint(); | 499 | m_view->repaint(); |
501 | 500 | ||
502 | // send death msg | 501 | // send death msg |
503 | emit died(); | 502 | emit died(); |
504 | } | 503 | } |
505 | } | 504 | } |
506 | 505 | ||
507 | void JezzGame::buildWall( int x, int y, bool vertical ) | 506 | void JezzGame::buildWall( int x, int y, bool vertical ) |
508 | { | 507 | { |
509 | if ( !m_running ) return; | 508 | if ( !m_running ) return; |
510 | 509 | ||
511 | if ( m_field->tile(x, y)==TILE_FREE ) | 510 | if ( m_field->tile(x, y)==TILE_FREE ) |
512 | { | 511 | { |
513 | // check whether there is a ball at the moment | 512 | // check whether there is a ball at the moment |
514 | QCanvasItemList cols = m_field->collisions( QRect(x*TILE_SIZE, y*TILE_SIZE, TILE_SIZE, TILE_SIZE) ); | 513 | QCanvasItemList cols = m_field->collisions( QRect(x*TILE_SIZE, y*TILE_SIZE, TILE_SIZE, TILE_SIZE) ); |
515 | if ( cols.count()>0 ) | 514 | if ( cols.count()>0 ) |
516 | { | 515 | { |
517 | //kdDebug() << "Direct collision" << endl; | 516 | //kdDebug() << "Direct collision" << endl; |
518 | emit ballCollision( (Ball*)cols.first(), x, y, TILE_WALLUP ); | 517 | emit ballCollision( (Ball*)cols.first(), x, y, TILE_WALLUP ); |
519 | return; | 518 | return; |
520 | } | 519 | } |
521 | 520 | ||
522 | // start walls | 521 | // start walls |
523 | if ( !m_wall1 ) | 522 | if ( !m_wall1 ) |
524 | { | 523 | { |
525 | m_wall1 = new Wall( m_field, x, y, | 524 | m_wall1 = new Wall( m_field, x, y, |
526 | vertical? Wall::Up : Wall::Left, | 525 | vertical? Wall::Up : Wall::Left, |
527 | vertical? TILE_WALLUP : TILE_WALLLEFT, | 526 | vertical? TILE_WALLUP : TILE_WALLLEFT, |
528 | this, "m_wall1" ); | 527 | this, "m_wall1" ); |
529 | connect( m_wall1, SIGNAL(finished(Wall *, int)), | 528 | connect( m_wall1, SIGNAL(finished(Wall *, int)), |
530 | this, SLOT(wallFinished(Wall *, int)) ); } | 529 | this, SLOT(wallFinished(Wall *, int)) ); } |
531 | 530 | ||
532 | if ( !m_wall2 ) | 531 | if ( !m_wall2 ) |
533 | { | 532 | { |
534 | m_wall2 = new Wall( m_field, x, y, | 533 | m_wall2 = new Wall( m_field, x, y, |
535 | vertical? Wall::Down: Wall::Right, | 534 | vertical? Wall::Down: Wall::Right, |
diff --git a/noncore/games/bounce/kbounce.cpp b/noncore/games/bounce/kbounce.cpp index 211f0ff..3b0cb6f 100644 --- a/noncore/games/bounce/kbounce.cpp +++ b/noncore/games/bounce/kbounce.cpp | |||
@@ -1,312 +1,308 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2000 Stefan Schimanski <1Stein@gmx.de> | 2 | * Copyright (C) 2000 Stefan Schimanski <1Stein@gmx.de> |
3 | * | 3 | * |
4 | * This program is free software; you can redistribute it and/or | 4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Library General Public | 5 | * modify it under the terms of the GNU Library General Public |
6 | * License as published by the Free Software Foundation; either | 6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License,Life or (at your option) any later version. | 7 | * version 2 of the License,Life or (at your option) any later version. |
8 | * | 8 | * |
9 | * This program is distributed in the hope that it will be useful, | 9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Library General Public License for more details. | 12 | * Library General Public License for more details. |
13 | * | 13 | * |
14 | * You should have received a copy of the GNU Library General Public | 14 | * You should have received a copy of the GNU Library General Public |
15 | * License along with this program; if not, write to the Free | 15 | * License along with this program; if not, write to the Free |
16 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 16 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
17 | */ | 17 | */ |
18 | 18 | ||
19 | #include <qlayout.h> | 19 | #include <qlayout.h> |
20 | #include <qtimer.h> | 20 | #include <qtimer.h> |
21 | #include <qlcdnumber.h> | ||
22 | #include <qmessagebox.h> | 21 | #include <qmessagebox.h> |
23 | #include <qmainwindow.h> | ||
24 | #include <qpe/qpeapplication.h> | ||
25 | 22 | ||
26 | #include "kbounce.h" | 23 | #include "kbounce.h" |
27 | #include "game.h" | 24 | #include "game.h" |
28 | #include <qlabel.h> | ||
29 | 25 | ||
30 | KJezzball::KJezzball(QWidget *p, const char* n, WFlags f) | 26 | KJezzball::KJezzball(QWidget *p, const char* n, WFlags f) |
31 | : QMainWindow(p,n,f), m_gameWidget( 0 ) | 27 | : QMainWindow(p,n,f), m_gameWidget( 0 ) |
32 | { | 28 | { |
33 | setCaption(tr("Bounce")); | 29 | setCaption(tr("Bounce")); |
34 | // setup variables | 30 | // setup variables |
35 | m_game.level = 1; | 31 | m_game.level = 1; |
36 | m_game.score = 0; | 32 | m_game.score = 0; |
37 | m_state = Idle; | 33 | m_state = Idle; |
38 | 34 | ||
39 | 35 | ||
40 | menu = menuBar(); | 36 | menu = menuBar(); |
41 | game = new QPopupMenu; | 37 | game = new QPopupMenu; |
42 | game->insertItem(tr("&New game"), this, SLOT(newGame()), Key_N ); | 38 | game->insertItem(tr("&New game"), this, SLOT(newGame()), Key_N ); |
43 | game->insertItem(tr("&Pause game"), this, SLOT(pauseGame()), Key_P ); | 39 | game->insertItem(tr("&Pause game"), this, SLOT(pauseGame()), Key_P ); |
44 | game->insertSeparator(); | 40 | game->insertSeparator(); |
45 | game->insertItem(tr("&About"), this, SLOT(about())); | 41 | game->insertItem(tr("&About"), this, SLOT(about())); |
46 | menu->insertItem( tr("&Game"), game ); | 42 | menu->insertItem( tr("&Game"), game ); |
47 | 43 | ||
48 | // create widgets | 44 | // create widgets |
49 | m_view = new QWidget( this, "m_view" ); | 45 | m_view = new QWidget( this, "m_view" ); |
50 | setCentralWidget( m_view ); | 46 | setCentralWidget( m_view ); |
51 | 47 | ||
52 | m_layout = new QGridLayout( m_view ); | 48 | m_layout = new QGridLayout( m_view ); |
53 | m_layout->setSpacing( 0 ); | 49 | m_layout->setSpacing( 0 ); |
54 | m_layout->setMargin( 0 ); | 50 | m_layout->setMargin( 0 ); |
55 | 51 | ||
56 | ScoreLabel = new QLabel( m_view, "ScoreLabel" ); | 52 | ScoreLabel = new QLabel( m_view, "ScoreLabel" ); |
57 | ScoreLabel->setText( tr( "Score: 00" ) ); | 53 | ScoreLabel->setText( tr( "Score: 00" ) ); |
58 | ScoreLabel->setAlignment( int( QLabel::AlignCenter ) ); | 54 | ScoreLabel->setAlignment( int( QLabel::AlignCenter ) ); |
59 | 55 | ||
60 | m_layout->addWidget( ScoreLabel, 1, 0 ); | 56 | m_layout->addWidget( ScoreLabel, 1, 0 ); |
61 | 57 | ||
62 | LivesLabel = new QLabel( m_view, "LivesLabel" ); | 58 | LivesLabel = new QLabel( m_view, "LivesLabel" ); |
63 | LivesLabel->setText( tr( "Lives: 0%" ) ); | 59 | LivesLabel->setText( tr( "Lives: 0%" ) ); |
64 | LivesLabel->setAlignment( int( QLabel::AlignCenter ) ); | 60 | LivesLabel->setAlignment( int( QLabel::AlignCenter ) ); |
65 | 61 | ||
66 | m_layout->addWidget( LivesLabel, 1, 2 ); | 62 | m_layout->addWidget( LivesLabel, 1, 2 ); |
67 | 63 | ||
68 | FilledLabel = new QLabel( m_view, "FilledLabel" ); | 64 | FilledLabel = new QLabel( m_view, "FilledLabel" ); |
69 | FilledLabel->setText( tr( "Filled: 00%" ) ); | 65 | FilledLabel->setText( tr( "Filled: 00%" ) ); |
70 | FilledLabel->setAlignment( int( QLabel::AlignCenter ) ); | 66 | FilledLabel->setAlignment( int( QLabel::AlignCenter ) ); |
71 | 67 | ||
72 | m_layout->addWidget( FilledLabel, 1, 1 ); | 68 | m_layout->addWidget( FilledLabel, 1, 1 ); |
73 | 69 | ||
74 | TimeLabel = new QLabel( m_view, "TimeLabel" ); | 70 | TimeLabel = new QLabel( m_view, "TimeLabel" ); |
75 | TimeLabel->setText( tr( "Time: 00" ) ); | 71 | TimeLabel->setText( tr( "Time: 00" ) ); |
76 | TimeLabel->setAlignment( int( QLabel::AlignCenter ) ); | 72 | TimeLabel->setAlignment( int( QLabel::AlignCenter ) ); |
77 | 73 | ||
78 | m_layout->addWidget( TimeLabel, 1, 3 ); | 74 | m_layout->addWidget( TimeLabel, 1, 3 ); |
79 | 75 | ||
80 | // create timers | 76 | // create timers |
81 | m_nextLevelTimer = new QTimer( this, "m_nextLevelTimer" ); | 77 | m_nextLevelTimer = new QTimer( this, "m_nextLevelTimer" ); |
82 | connect( m_nextLevelTimer, SIGNAL(timeout()), this, SLOT(switchLevel()) ); | 78 | connect( m_nextLevelTimer, SIGNAL(timeout()), this, SLOT(switchLevel()) ); |
83 | 79 | ||
84 | m_gameOverTimer = new QTimer( this, "m_gameOverTimer" ); | 80 | m_gameOverTimer = new QTimer( this, "m_gameOverTimer" ); |
85 | connect( m_gameOverTimer, SIGNAL(timeout()), this, SLOT(gameOverNow()) ); | 81 | connect( m_gameOverTimer, SIGNAL(timeout()), this, SLOT(gameOverNow()) ); |
86 | 82 | ||
87 | m_timer = new QTimer( this, "m_timer" ); | 83 | m_timer = new QTimer( this, "m_timer" ); |
88 | connect( m_timer, SIGNAL(timeout()), this, SLOT(second()) ); | 84 | connect( m_timer, SIGNAL(timeout()), this, SLOT(second()) ); |
89 | 85 | ||
90 | // create demo game | 86 | // create demo game |
91 | createLevel( 1 ); | 87 | createLevel( 1 ); |
92 | } | 88 | } |
93 | 89 | ||
94 | void KJezzball::newGame() | 90 | void KJezzball::newGame() |
95 | { | 91 | { |
96 | // Check for running game | 92 | // Check for running game |
97 | closeGame(); | 93 | closeGame(); |
98 | if ( m_state==Idle ) | 94 | if ( m_state==Idle ) |
99 | { | 95 | { |
100 | // update displays | 96 | // update displays |
101 | m_game.level = 1; | 97 | m_game.level = 1; |
102 | m_game.score = 0; | 98 | m_game.score = 0; |
103 | 99 | ||
104 | setCaption(tr("Bounce Level %1").arg(m_game.level)); | 100 | setCaption(tr("Bounce Level %1").arg(m_game.level)); |
105 | ScoreLabel->setText( tr( "Score: %1" ).arg(m_game.score) ); | 101 | ScoreLabel->setText( tr( "Score: %1" ).arg(m_game.score) ); |
106 | 102 | ||
107 | // start new game | 103 | // start new game |
108 | m_state = Running; | 104 | m_state = Running; |
109 | 105 | ||
110 | createLevel( m_game.level ); | 106 | createLevel( m_game.level ); |
111 | startLevel(); | 107 | startLevel(); |
112 | } | 108 | } |
113 | } | 109 | } |
114 | 110 | ||
115 | void KJezzball::about() | 111 | void KJezzball::about() |
116 | { | 112 | { |
117 | QMessageBox::information( this, tr("About"), | 113 | QMessageBox::information( this, tr("About"), |
118 | tr("Written by: Stefan Schimanski\n" | 114 | tr("Written by: Stefan Schimanski\n" |
119 | "Ported by: Martin Imobersteg\n" | 115 | "Ported by: Martin Imobersteg\n" |
120 | "\n" | 116 | "\n" |
121 | "Click to form walls.\n" | 117 | "Click to form walls.\n" |
122 | "Hit space to switch wall direction.\n" | 118 | "Hit space to switch wall direction.\n" |
123 | "Try to reduce total space by 75%.\n" | 119 | "Try to reduce total space by 75%.\n" |
124 | "\n" | 120 | "\n" |
125 | "This program is distributed under\n" | 121 | "This program is distributed under\n" |
126 | "the terms of the GPL v2.") ); | 122 | "the terms of the GPL v2.") ); |
127 | } | 123 | } |
128 | 124 | ||
129 | void KJezzball::closeGame() | 125 | void KJezzball::closeGame() |
130 | { | 126 | { |
131 | if ( m_state!=Idle ) | 127 | if ( m_state!=Idle ) |
132 | { | 128 | { |
133 | stopLevel(); | 129 | stopLevel(); |
134 | m_state = Idle; | 130 | m_state = Idle; |
135 | } | 131 | } |
136 | } | 132 | } |
137 | 133 | ||
138 | void KJezzball::pauseGame() | 134 | void KJezzball::pauseGame() |
139 | { | 135 | { |
140 | switch ( m_state ) | 136 | switch ( m_state ) |
141 | { | 137 | { |
142 | case Running: | 138 | case Running: |
143 | m_state = Paused; | 139 | m_state = Paused; |
144 | m_gameWidget->display( tr("Game paused.\nPress P to continue!") ); | 140 | m_gameWidget->display( tr("Game paused.\nPress P to continue!") ); |
145 | stopLevel(); | 141 | stopLevel(); |
146 | break; | 142 | break; |
147 | 143 | ||
148 | case Paused: | 144 | case Paused: |
149 | case Suspend: | 145 | case Suspend: |
150 | m_state = Running; | 146 | m_state = Running; |
151 | m_gameWidget->display( QString::null ); | 147 | m_gameWidget->display( QString::null ); |
152 | startLevel(); | 148 | startLevel(); |
153 | break; | 149 | break; |
154 | 150 | ||
155 | case Idle: | 151 | case Idle: |
156 | break; | 152 | break; |
157 | } | 153 | } |
158 | } | 154 | } |
159 | 155 | ||
160 | void KJezzball::gameOver() | 156 | void KJezzball::gameOver() |
161 | { | 157 | { |
162 | stopLevel(); | 158 | stopLevel(); |
163 | m_gameOverTimer->start( 100, TRUE ); | 159 | m_gameOverTimer->start( 100, TRUE ); |
164 | } | 160 | } |
165 | 161 | ||
166 | 162 | ||
167 | void KJezzball::gameOverNow() | 163 | void KJezzball::gameOverNow() |
168 | { | 164 | { |
169 | m_state = Idle; | 165 | m_state = Idle; |
170 | 166 | ||
171 | QString score; | 167 | QString score; |
172 | score.setNum( m_game.score ); | 168 | score.setNum( m_game.score ); |
173 | QMessageBox::information( this, "Game Over", tr("Game Over!\nScore: %1").arg(score) ); | 169 | QMessageBox::information( this, "Game Over", tr("Game Over!\nScore: %1").arg(score) ); |
174 | } | 170 | } |
175 | 171 | ||
176 | void KJezzball::focusOutEvent( QFocusEvent *ev ) | 172 | void KJezzball::focusOutEvent( QFocusEvent *ev ) |
177 | { | 173 | { |
178 | if ( m_state==Running ) | 174 | if ( m_state==Running ) |
179 | { | 175 | { |
180 | stopLevel(); | 176 | stopLevel(); |
181 | m_state = Suspend; | 177 | m_state = Suspend; |
182 | } | 178 | } |
183 | 179 | ||
184 | QMainWindow::focusOutEvent( ev ); | 180 | QMainWindow::focusOutEvent( ev ); |
185 | } | 181 | } |
186 | 182 | ||
187 | void KJezzball::focusInEvent ( QFocusEvent *ev ) | 183 | void KJezzball::focusInEvent ( QFocusEvent *ev ) |
188 | { | 184 | { |
189 | if ( m_state==Suspend ) | 185 | if ( m_state==Suspend ) |
190 | { | 186 | { |
191 | startLevel(); | 187 | startLevel(); |
192 | m_state = Running; | 188 | m_state = Running; |
193 | } | 189 | } |
194 | 190 | ||
195 | QMainWindow::focusInEvent( ev ); | 191 | QMainWindow::focusInEvent( ev ); |
196 | } | 192 | } |
197 | 193 | ||
198 | void KJezzball::second() | 194 | void KJezzball::second() |
199 | { | 195 | { |
200 | m_level.time--; | 196 | m_level.time--; |
201 | TimeLabel->setText( tr( "Time: %1" ).arg(m_level.time) ); | 197 | TimeLabel->setText( tr( "Time: %1" ).arg(m_level.time) ); |
202 | if ( m_level.time<=0 ) | 198 | if ( m_level.time<=0 ) |
203 | { | 199 | { |
204 | gameOver(); | 200 | gameOver(); |
205 | } | 201 | } |
206 | } | 202 | } |
207 | 203 | ||
208 | void KJezzball::died() | 204 | void KJezzball::died() |
209 | { | 205 | { |
210 | m_level.lifes--; | 206 | m_level.lifes--; |
211 | LivesLabel->setText( tr( "Lives: %1" ).arg(m_level.lifes) ); | 207 | LivesLabel->setText( tr( "Lives: %1" ).arg(m_level.lifes) ); |
212 | if ( m_level.lifes==0 ) gameOver(); | 208 | if ( m_level.lifes==0 ) gameOver(); |
213 | } | 209 | } |
214 | 210 | ||
215 | void KJezzball::newPercent( int percent ) | 211 | void KJezzball::newPercent( int percent ) |
216 | { | 212 | { |
217 | FilledLabel->setText( tr( "Filled: %1%" ).arg(percent) ); | 213 | FilledLabel->setText( tr( "Filled: %1%" ).arg(percent) ); |
218 | if ( percent>=75 ) | 214 | if ( percent>=75 ) |
219 | { | 215 | { |
220 | m_level.score = m_level.lifes*15 + (percent-75)*2*(m_game.level+5); | 216 | m_level.score = m_level.lifes*15 + (percent-75)*2*(m_game.level+5); |
221 | nextLevel(); | 217 | nextLevel(); |
222 | } | 218 | } |
223 | } | 219 | } |
224 | 220 | ||
225 | void KJezzball::createLevel( int level ) | 221 | void KJezzball::createLevel( int level ) |
226 | { | 222 | { |
227 | // destroy old game | 223 | // destroy old game |
228 | if ( m_gameWidget ) delete m_gameWidget; | 224 | if ( m_gameWidget ) delete m_gameWidget; |
229 | 225 | ||
230 | m_gameWidget = new JezzGame( level+1, m_view, "m_gameWidget" ); | 226 | m_gameWidget = new JezzGame( level+1, m_view, "m_gameWidget" ); |
231 | 227 | ||
232 | m_gameWidget->show(); | 228 | m_gameWidget->show(); |
233 | m_layout->addMultiCellWidget( m_gameWidget, 0, 0, 0, 3 ); | 229 | m_layout->addMultiCellWidget( m_gameWidget, 0, 0, 0, 3 ); |
234 | connect( m_gameWidget, SIGNAL(died()), this, SLOT(died()) ); | 230 | connect( m_gameWidget, SIGNAL(died()), this, SLOT(died()) ); |
235 | connect( m_gameWidget, SIGNAL(newPercent(int)), this, SLOT(newPercent(int)) ); | 231 | connect( m_gameWidget, SIGNAL(newPercent(int)), this, SLOT(newPercent(int)) ); |
236 | 232 | ||
237 | // update displays | 233 | // update displays |
238 | m_level.lifes = level+1; | 234 | m_level.lifes = level+1; |
239 | LivesLabel->setText( tr( "Lives: %1" ).arg(m_level.lifes) ); | 235 | LivesLabel->setText( tr( "Lives: %1" ).arg(m_level.lifes) ); |
240 | FilledLabel->setText( tr( "Filled: 0%" ) ); | 236 | FilledLabel->setText( tr( "Filled: 0%" ) ); |
241 | 237 | ||
242 | m_level.time = (level+2)*30; | 238 | m_level.time = (level+2)*30; |
243 | TimeLabel->setText( tr( "Time: %1" ).arg(m_level.time) ); | 239 | TimeLabel->setText( tr( "Time: %1" ).arg(m_level.time) ); |
244 | 240 | ||
245 | m_level.score = 0; | 241 | m_level.score = 0; |
246 | } | 242 | } |
247 | 243 | ||
248 | void KJezzball::startLevel() | 244 | void KJezzball::startLevel() |
249 | { | 245 | { |
250 | if ( m_gameWidget ) | 246 | if ( m_gameWidget ) |
251 | { | 247 | { |
252 | m_timer->start( 1000 ); | 248 | m_timer->start( 1000 ); |
253 | m_gameWidget->start(); | 249 | m_gameWidget->start(); |
254 | } | 250 | } |
255 | } | 251 | } |
256 | 252 | ||
257 | void KJezzball::stopLevel() | 253 | void KJezzball::stopLevel() |
258 | { | 254 | { |
259 | if ( m_gameWidget ) | 255 | if ( m_gameWidget ) |
260 | { | 256 | { |
261 | m_gameWidget->stop(); | 257 | m_gameWidget->stop(); |
262 | m_timer->stop(); | 258 | m_timer->stop(); |
263 | } | 259 | } |
264 | } | 260 | } |
265 | 261 | ||
266 | void KJezzball::nextLevel() | 262 | void KJezzball::nextLevel() |
267 | { | 263 | { |
268 | stopLevel(); | 264 | stopLevel(); |
269 | m_nextLevelTimer->start( 100, TRUE ); | 265 | m_nextLevelTimer->start( 100, TRUE ); |
270 | } | 266 | } |
271 | 267 | ||
272 | void KJezzball::switchLevel() | 268 | void KJezzball::switchLevel() |
273 | { | 269 | { |
274 | m_game.score += m_level.score; | 270 | m_game.score += m_level.score; |
275 | ScoreLabel->setText( tr( "Score: %1" ).arg(m_game.score) ); | 271 | ScoreLabel->setText( tr( "Score: %1" ).arg(m_game.score) ); |
276 | 272 | ||
277 | QString score; | 273 | QString score; |
278 | score.setNum( m_level.score ); | 274 | score.setNum( m_level.score ); |
279 | 275 | ||
280 | QString level; | 276 | QString level; |
281 | level.setNum( m_game.level ); | 277 | level.setNum( m_game.level ); |
282 | 278 | ||
283 | QString foo = QString( | 279 | QString foo = QString( |
284 | tr("Successfully cleared more than 75%.\n") + | 280 | tr("Successfully cleared more than 75%.\n") + |
285 | tr("%1 points: 15 points per life\n").arg(m_level.lifes*15) + | 281 | tr("%1 points: 15 points per life\n").arg(m_level.lifes*15) + |
286 | tr("%1 points: Bonus\n").arg((m_gameWidget->percent()-75)*2*(m_game.level+5)) + | 282 | tr("%1 points: Bonus\n").arg((m_gameWidget->percent()-75)*2*(m_game.level+5)) + |
287 | tr("%1 points: Total score\n").arg(score) + | 283 | tr("%1 points: Total score\n").arg(score) + |
288 | tr("On to level %1.\nYou get %2 lives this time!")).arg(m_game.level+1).arg(m_game.level+2); | 284 | tr("On to level %1.\nYou get %2 lives this time!")).arg(m_game.level+1).arg(m_game.level+2); |
289 | 285 | ||
290 | QMessageBox::information( this, "Success", foo ); | 286 | QMessageBox::information( this, "Success", foo ); |
291 | 287 | ||
292 | m_game.level++; | 288 | m_game.level++; |
293 | 289 | ||
294 | createLevel( m_game.level ); | 290 | createLevel( m_game.level ); |
295 | startLevel(); | 291 | startLevel(); |
296 | } | 292 | } |
297 | 293 | ||
298 | void KJezzball::keyPressEvent( QKeyEvent *ev ) | 294 | void KJezzball::keyPressEvent( QKeyEvent *ev ) |
299 | { | 295 | { |
300 | if ( ev->key() == Key_Space || | 296 | if ( ev->key() == Key_Space || |
301 | ev->key() == Key_Up || | 297 | ev->key() == Key_Up || |
302 | ev->key() == Key_Down || | 298 | ev->key() == Key_Down || |
303 | ev->key() == Key_Right || | 299 | ev->key() == Key_Right || |
304 | ev->key() == Key_Left ) | 300 | ev->key() == Key_Left ) |
305 | { | 301 | { |
306 | m_gameWidget->changeCursor(); | 302 | m_gameWidget->changeCursor(); |
307 | } | 303 | } |
308 | else | 304 | else |
309 | { | 305 | { |
310 | ev->ignore(); | 306 | ev->ignore(); |
311 | } | 307 | } |
312 | } | 308 | } |
diff --git a/noncore/games/bounce/main.cpp b/noncore/games/bounce/main.cpp index 9ea86a6..a070c4b 100644 --- a/noncore/games/bounce/main.cpp +++ b/noncore/games/bounce/main.cpp | |||
@@ -1,24 +1,23 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2000 Stefan Schimanski <schimmi@kde.org> | 2 | * Copyright (C) 2000 Stefan Schimanski <schimmi@kde.org> |
3 | * | 3 | * |
4 | * This program is free software; you can redistribute it and/or | 4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Library General Public | 5 | * modify it under the terms of the GNU Library General Public |
6 | * License as published by the Free Software Foundation; either | 6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. | 7 | * version 2 of the License, or (at your option) any later version. |
8 | * | 8 | * |
9 | * This program is distributed in the hope that it will be useful, | 9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Library General Public License for more details. | 12 | * Library General Public License for more details. |
13 | * | 13 | * |
14 | * You should have received a copy of the GNU Library General Public | 14 | * You should have received a copy of the GNU Library General Public |
15 | * License along with this program; if not, write to the Free | 15 | * License along with this program; if not, write to the Free |
16 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 16 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
17 | */ | 17 | */ |
18 | 18 | ||
19 | #include <qpe/qpeapplication.h> | ||
20 | #include "kbounce.h" | 19 | #include "kbounce.h" |
21 | #include <opie/oapplicationfactory.h> | 20 | #include <opie/oapplicationfactory.h> |
22 | 21 | ||
23 | OPIE_EXPORT_APP( OApplicationFactory<KJezzball> ) | 22 | OPIE_EXPORT_APP( OApplicationFactory<KJezzball> ) |
24 | 23 | ||
diff --git a/noncore/games/buzzword/buzzword.cpp b/noncore/games/buzzword/buzzword.cpp index f746065..13eb481 100644 --- a/noncore/games/buzzword/buzzword.cpp +++ b/noncore/games/buzzword/buzzword.cpp | |||
@@ -1,182 +1,181 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2002 Martin Imobersteg <imm@gmx.ch> | 2 | * Copyright (C) 2002 Martin Imobersteg <imm@gmx.ch> |
3 | * | 3 | * |
4 | * This program is free software; you can redistribute it and/or | 4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU General Public | 5 | * modify it under the terms of the GNU General Public |
6 | * License as published by the Free Software Foundation; either | 6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License,Life or (at your option) any later version. | 7 | * version 2 of the License,Life or (at your option) any later version. |
8 | * | 8 | * |
9 | * This program is distributed in the hope that it will be useful, | 9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Library General Public License for more details. | 12 | * Library General Public License for more details. |
13 | * | 13 | * |
14 | * You should have received a copy of the GNU Library General Public | 14 | * You should have received a copy of the GNU Library General Public |
15 | * License along with this program; if not, write to the Free | 15 | * License along with this program; if not, write to the Free |
16 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 16 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
17 | */ | 17 | */ |
18 | 18 | ||
19 | #include <qlayout.h> | 19 | #include <qlayout.h> |
20 | #include <qmessagebox.h> | ||
21 | #include <qmainwindow.h> | 20 | #include <qmainwindow.h> |
22 | #include <qlabel.h> | 21 | #include <qlabel.h> |
23 | #include <qgrid.h> | 22 | #include <qgrid.h> |
24 | #include <qcolor.h> | 23 | #include <qcolor.h> |
25 | #include <qbutton.h> | 24 | #include <qbutton.h> |
26 | #include <qfile.h> | 25 | #include <qfile.h> |
27 | #include <qtextstream.h> | 26 | #include <qtextstream.h> |
28 | #include <qstringlist.h> | 27 | #include <qstringlist.h> |
29 | #include <qmessagebox.h> | 28 | #include <qmessagebox.h> |
30 | #include <qdir.h> | 29 | #include <qdir.h> |
31 | 30 | ||
32 | #include <math.h> | 31 | #include <math.h> |
33 | #include <stdlib.h> | 32 | #include <stdlib.h> |
34 | 33 | ||
35 | #include <qpe/qpeapplication.h> | 34 | #include <qpe/qpeapplication.h> |
36 | 35 | ||
37 | #include "buzzword.h" | 36 | #include "buzzword.h" |
38 | 37 | ||
39 | BuzzLabel::BuzzLabel( QWidget *parent, const char *name ) | 38 | BuzzLabel::BuzzLabel( QWidget *parent, const char *name ) |
40 | : QLabel( parent, name ) | 39 | : QLabel( parent, name ) |
41 | { | 40 | { |
42 | } | 41 | } |
43 | 42 | ||
44 | void BuzzLabel::mousePressEvent(QMouseEvent *e) | 43 | void BuzzLabel::mousePressEvent(QMouseEvent *e) |
45 | { | 44 | { |
46 | if(e->button() == LeftButton) | 45 | if(e->button() == LeftButton) |
47 | { | 46 | { |
48 | emit clicked(); | 47 | emit clicked(); |
49 | } | 48 | } |
50 | } | 49 | } |
51 | 50 | ||
52 | BuzzItem::BuzzItem( int row, int column, QString text, QWidget *parent, const char *name ) | 51 | BuzzItem::BuzzItem( int row, int column, QString text, QWidget *parent, const char *name ) |
53 | : QVBox( parent, name ), _row(row), _column(column) | 52 | : QVBox( parent, name ), _row(row), _column(column) |
54 | { | 53 | { |
55 | setFrameStyle( QFrame::Panel | QFrame::Raised ); | 54 | setFrameStyle( QFrame::Panel | QFrame::Raised ); |
56 | setLineWidth( 1 ); | 55 | setLineWidth( 1 ); |
57 | label = new BuzzLabel(this, "label"); | 56 | label = new BuzzLabel(this, "label"); |
58 | label->setText(text); | 57 | label->setText(text); |
59 | label->setAlignment( int( QLabel::AlignCenter ) ); | 58 | label->setAlignment( int( QLabel::AlignCenter ) ); |
60 | 59 | ||
61 | connect( label, SIGNAL(clicked()), this, SLOT(flip()) ); | 60 | connect( label, SIGNAL(clicked()), this, SLOT(flip()) ); |
62 | } | 61 | } |
63 | 62 | ||
64 | void BuzzItem::flip() | 63 | void BuzzItem::flip() |
65 | { | 64 | { |
66 | setLineWidth( 1 ); | 65 | setLineWidth( 1 ); |
67 | label->setBackgroundColor(label->colorGroup().highlight()); | 66 | label->setBackgroundColor(label->colorGroup().highlight()); |
68 | emit clicked(_row, _column); | 67 | emit clicked(_row, _column); |
69 | } | 68 | } |
70 | 69 | ||
71 | BuzzWord::BuzzWord(QWidget* parent, const char* name, WFlags fl ) : QMainWindow( parent, name, fl ) | 70 | BuzzWord::BuzzWord(QWidget* parent, const char* name, WFlags fl ) : QMainWindow( parent, name, fl ) |
72 | { | 71 | { |
73 | setCaption(tr("buZzword")); | 72 | setCaption(tr("buZzword")); |
74 | 73 | ||
75 | menu = menuBar(); | 74 | menu = menuBar(); |
76 | game = new QPopupMenu; | 75 | game = new QPopupMenu; |
77 | game->insertItem(tr("&New game"), this, SLOT(newGame()), Key_N ); | 76 | game->insertItem(tr("&New game"), this, SLOT(newGame()), Key_N ); |
78 | menu->insertItem( tr("&Game"), game ); | 77 | menu->insertItem( tr("&Game"), game ); |
79 | 78 | ||
80 | gridVal = 4; | 79 | gridVal = 4; |
81 | grid = NULL; | 80 | grid = NULL; |
82 | gameOver = false; | 81 | gameOver = false; |
83 | newGame(); | 82 | newGame(); |
84 | } | 83 | } |
85 | 84 | ||
86 | void BuzzWord::drawGrid() | 85 | void BuzzWord::drawGrid() |
87 | { | 86 | { |
88 | QStringList l; | 87 | QStringList l; |
89 | 88 | ||
90 | QString path = QPEApplication::qpeDir()+"share/buzzword/"; | 89 | QString path = QPEApplication::qpeDir()+"share/buzzword/"; |
91 | QFile f( path + "buzzwords" ); | 90 | QFile f( path + "buzzwords" ); |
92 | if ( !f.open( IO_ReadOnly ) ) | 91 | if ( !f.open( IO_ReadOnly ) ) |
93 | return; | 92 | return; |
94 | 93 | ||
95 | QTextStream t( &f ); | 94 | QTextStream t( &f ); |
96 | 95 | ||
97 | while (!t.atEnd()) | 96 | while (!t.atEnd()) |
98 | { | 97 | { |
99 | l << t.readLine(); | 98 | l << t.readLine(); |
100 | } | 99 | } |
101 | 100 | ||
102 | f.close(); | 101 | f.close(); |
103 | 102 | ||
104 | grid = new QGrid(gridVal, this); | 103 | grid = new QGrid(gridVal, this); |
105 | //grid->setFixedSize( 480, 480 ); | 104 | //grid->setFixedSize( 480, 480 ); |
106 | 105 | ||
107 | for( int c = 0 ; c < gridVal ; c++ ) | 106 | for( int c = 0 ; c < gridVal ; c++ ) |
108 | { | 107 | { |
109 | for( int r = 0 ; r < gridVal ; r++ ) | 108 | for( int r = 0 ; r < gridVal ; r++ ) |
110 | { | 109 | { |
111 | uint pos = rand() % l. count(); | 110 | uint pos = rand() % l. count(); |
112 | 111 | ||
113 | QString word = QStringList::split(" ", l[pos]).join("\n"); | 112 | QString word = QStringList::split(" ", l[pos]).join("\n"); |
114 | BuzzItem* bi = new BuzzItem( c, r, word, grid ); | 113 | BuzzItem* bi = new BuzzItem( c, r, word, grid ); |
115 | connect( bi, SIGNAL(clicked(int, int)), this, SLOT(clicked(int,int)) ); | 114 | connect( bi, SIGNAL(clicked(int, int)), this, SLOT(clicked(int,int)) ); |
116 | map[c][r] = 0; | 115 | map[c][r] = 0; |
117 | 116 | ||
118 | l.remove( l.at( pos )); | 117 | l.remove( l.at( pos )); |
119 | } | 118 | } |
120 | } | 119 | } |
121 | } | 120 | } |
122 | 121 | ||
123 | void BuzzWord::clicked(int row, int column) | 122 | void BuzzWord::clicked(int row, int column) |
124 | { | 123 | { |
125 | if ( ! gameOver ) | 124 | if ( ! gameOver ) |
126 | { | 125 | { |
127 | int rowTotal = 0; | 126 | int rowTotal = 0; |
128 | int columnTotal = 0; | 127 | int columnTotal = 0; |
129 | 128 | ||
130 | map[column][row] = 1; | 129 | map[column][row] = 1; |
131 | 130 | ||
132 | for( int c = 0 ; c < gridVal ; c++ ) | 131 | for( int c = 0 ; c < gridVal ; c++ ) |
133 | { | 132 | { |
134 | for( int r = 0 ; r < gridVal ; r++ ) | 133 | for( int r = 0 ; r < gridVal ; r++ ) |
135 | { | 134 | { |
136 | if ( map[c][r] == 1 ) | 135 | if ( map[c][r] == 1 ) |
137 | rowTotal++; | 136 | rowTotal++; |
138 | 137 | ||
139 | if ( rowTotal == 4 ) | 138 | if ( rowTotal == 4 ) |
140 | { | 139 | { |
141 | bingo(); | 140 | bingo(); |
142 | } | 141 | } |
143 | } | 142 | } |
144 | rowTotal = 0; | 143 | rowTotal = 0; |
145 | } | 144 | } |
146 | 145 | ||
147 | for( int r = 0 ; r < gridVal ; r++ ) | 146 | for( int r = 0 ; r < gridVal ; r++ ) |
148 | { | 147 | { |
149 | for( int c = 0 ; c < gridVal ; c++ ) | 148 | for( int c = 0 ; c < gridVal ; c++ ) |
150 | { | 149 | { |
151 | if ( map[c][r] == 1 ) | 150 | if ( map[c][r] == 1 ) |
152 | columnTotal++; | 151 | columnTotal++; |
153 | 152 | ||
154 | if ( columnTotal == 4 ) | 153 | if ( columnTotal == 4 ) |
155 | { | 154 | { |
156 | bingo(); | 155 | bingo(); |
157 | } | 156 | } |
158 | } | 157 | } |
159 | columnTotal = 0; | 158 | columnTotal = 0; |
160 | } | 159 | } |
161 | 160 | ||
162 | if ( map[0][0] && map[1][1] && map[2][2] && map[3][3] ) | 161 | if ( map[0][0] && map[1][1] && map[2][2] && map[3][3] ) |
163 | bingo(); | 162 | bingo(); |
164 | 163 | ||
165 | if ( map[0][3] && map[1][2] && map[2][1] && map[3][0] ) | 164 | if ( map[0][3] && map[1][2] && map[2][1] && map[3][0] ) |
166 | bingo(); | 165 | bingo(); |
167 | } | 166 | } |
168 | } | 167 | } |
169 | 168 | ||
170 | void BuzzWord::bingo() | 169 | void BuzzWord::bingo() |
171 | { | 170 | { |
172 | gameOver = true; | 171 | gameOver = true; |
173 | QMessageBox::information( this, "BUZZWORD", tr("<h1><b>BINGO !</b></h1>")); | 172 | QMessageBox::information( this, "BUZZWORD", tr("<h1><b>BINGO !</b></h1>")); |
174 | } | 173 | } |
175 | 174 | ||
176 | void BuzzWord::newGame() | 175 | void BuzzWord::newGame() |
177 | { | 176 | { |
178 | gameOver = false; | 177 | gameOver = false; |
179 | delete grid; | 178 | delete grid; |
180 | drawGrid(); | 179 | drawGrid(); |
181 | setCentralWidget(grid); | 180 | setCentralWidget(grid); |
182 | } | 181 | } |
diff --git a/noncore/games/buzzword/main.cpp b/noncore/games/buzzword/main.cpp index 67f2c26..95b3176 100644 --- a/noncore/games/buzzword/main.cpp +++ b/noncore/games/buzzword/main.cpp | |||
@@ -1,24 +1,23 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2002 Martin Imobersteg <imm@gmx.ch> | 2 | * Copyright (C) 2002 Martin Imobersteg <imm@gmx.ch> |
3 | * | 3 | * |
4 | * This program is free software; you can redistribute it and/or | 4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU General Public | 5 | * modify it under the terms of the GNU General Public |
6 | * License as published by the Free Software Foundation; either | 6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License,Life or (at your option) any later version. | 7 | * version 2 of the License,Life or (at your option) any later version. |
8 | * | 8 | * |
9 | * This program is distributed in the hope that it will be useful, | 9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Library General Public License for more details. | 12 | * Library General Public License for more details. |
13 | * | 13 | * |
14 | * You should have received a copy of the GNU Library General Public | 14 | * You should have received a copy of the GNU Library General Public |
15 | * License along with this program; if not, write to the Free | 15 | * License along with this program; if not, write to the Free |
16 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 16 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
17 | */ | 17 | */ |
18 | 18 | ||
19 | #include <qpe/qpeapplication.h> | ||
20 | #include <opie/oapplicationfactory.h> | 19 | #include <opie/oapplicationfactory.h> |
21 | 20 | ||
22 | #include "buzzword.h" | 21 | #include "buzzword.h" |
23 | 22 | ||
24 | OPIE_EXPORT_APP( OApplicationFactory<BuzzWord> ) | 23 | OPIE_EXPORT_APP( OApplicationFactory<BuzzWord> ) |
diff --git a/noncore/games/fifteen/fifteen.cpp b/noncore/games/fifteen/fifteen.cpp index b4e0308..506e87a 100644 --- a/noncore/games/fifteen/fifteen.cpp +++ b/noncore/games/fifteen/fifteen.cpp | |||
@@ -1,391 +1,386 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "fifteen.h" | 21 | #include "fifteen.h" |
22 | 22 | ||
23 | #include <qtopia/resource.h> | 23 | #include <qtopia/resource.h> |
24 | #include <qtopia/config.h> | 24 | #include <qtopia/config.h> |
25 | 25 | ||
26 | #include <qvbox.h> | 26 | #include <qvbox.h> |
27 | #include <qaction.h> | 27 | #include <qaction.h> |
28 | #include <qlayout.h> | ||
29 | #include <qpainter.h> | 28 | #include <qpainter.h> |
30 | #include <qpopupmenu.h> | ||
31 | #include <qmessagebox.h> | 29 | #include <qmessagebox.h> |
32 | #include <qtoolbar.h> | 30 | #include <qtoolbar.h> |
33 | #include <qmenubar.h> | 31 | #include <qmenubar.h> |
34 | #include <qstringlist.h> | ||
35 | #include <qapplication.h> | ||
36 | #include <qtoolbutton.h> | ||
37 | 32 | ||
38 | #include <stdlib.h> | 33 | #include <stdlib.h> |
39 | #include <time.h> | 34 | #include <time.h> |
40 | 35 | ||
41 | FifteenMainWindow::FifteenMainWindow(QWidget *parent, const char* name, WFlags fl) | 36 | FifteenMainWindow::FifteenMainWindow(QWidget *parent, const char* name, WFlags fl) |
42 | : QMainWindow( parent, name, fl ) | 37 | : QMainWindow( parent, name, fl ) |
43 | { | 38 | { |
44 | // random seed | 39 | // random seed |
45 | srand(time(0)); | 40 | srand(time(0)); |
46 | setCaption( tr("Fifteen Pieces") ); | 41 | setCaption( tr("Fifteen Pieces") ); |
47 | 42 | ||
48 | QToolBar *toolbar = new QToolBar(this); | 43 | QToolBar *toolbar = new QToolBar(this); |
49 | toolbar->setHorizontalStretchable( FALSE ); | 44 | toolbar->setHorizontalStretchable( FALSE ); |
50 | QMenuBar *menubar = new QMenuBar( toolbar ); | 45 | QMenuBar *menubar = new QMenuBar( toolbar ); |
51 | menubar->setMargin(0); | 46 | menubar->setMargin(0); |
52 | QPopupMenu *game = new QPopupMenu( this ); | 47 | QPopupMenu *game = new QPopupMenu( this ); |
53 | 48 | ||
54 | QWidget *spacer = new QWidget( toolbar ); | 49 | QWidget *spacer = new QWidget( toolbar ); |
55 | spacer->setBackgroundMode( PaletteButton ); | 50 | spacer->setBackgroundMode( PaletteButton ); |
56 | toolbar->setStretchableWidget( spacer ); | 51 | toolbar->setStretchableWidget( spacer ); |
57 | 52 | ||
58 | 53 | ||
59 | setToolBarsMovable( FALSE ); | 54 | setToolBarsMovable( FALSE ); |
60 | QVBox *vbox = new QVBox( this ); | 55 | QVBox *vbox = new QVBox( this ); |
61 | PiecesTable *table = new PiecesTable( vbox ); | 56 | PiecesTable *table = new PiecesTable( vbox ); |
62 | setCentralWidget(vbox); | 57 | setCentralWidget(vbox); |
63 | 58 | ||
64 | 59 | ||
65 | 60 | ||
66 | QAction *a = new QAction( tr( "Randomize" ), Resource::loadPixmap( "new" ), | 61 | QAction *a = new QAction( tr( "Randomize" ), Resource::loadPixmap( "new" ), |
67 | QString::null, 0, this, 0 ); | 62 | QString::null, 0, this, 0 ); |
68 | connect( a, SIGNAL( activated() ), table, SLOT( slotRandomize() ) ); | 63 | connect( a, SIGNAL( activated() ), table, SLOT( slotRandomize() ) ); |
69 | a->addTo( game ); | 64 | a->addTo( game ); |
70 | a->addTo( toolbar ); | 65 | a->addTo( toolbar ); |
71 | 66 | ||
72 | /* This is pointless and confusing. | 67 | /* This is pointless and confusing. |
73 | a = new QAction( tr( "Solve" ), Resource::loadIconSet( "repeat" ), | 68 | a = new QAction( tr( "Solve" ), Resource::loadIconSet( "repeat" ), |
74 | QString::null, 0, this, 0 ); | 69 | QString::null, 0, this, 0 ); |
75 | connect( a, SIGNAL( activated() ), table, SLOT( slotReset() ) ); | 70 | connect( a, SIGNAL( activated() ), table, SLOT( slotReset() ) ); |
76 | a->addTo( game ); | 71 | a->addTo( game ); |
77 | a->addTo( toolbar ); | 72 | a->addTo( toolbar ); |
78 | */ | 73 | */ |
79 | menubar->insertItem( tr( "Game" ), game ); | 74 | menubar->insertItem( tr( "Game" ), game ); |
80 | } | 75 | } |
81 | 76 | ||
82 | PiecesTable::PiecesTable(QWidget* parent, const char* name ) | 77 | PiecesTable::PiecesTable(QWidget* parent, const char* name ) |
83 | : QTableView(parent, name), _menu(0), _randomized(false) | 78 | : QTableView(parent, name), _menu(0), _randomized(false) |
84 | { | 79 | { |
85 | // setup table view | 80 | // setup table view |
86 | setFrameStyle(StyledPanel | Sunken); | 81 | setFrameStyle(StyledPanel | Sunken); |
87 | setBackgroundMode(NoBackground); | 82 | setBackgroundMode(NoBackground); |
88 | setMouseTracking(true); | 83 | setMouseTracking(true); |
89 | 84 | ||
90 | setNumRows(4); | 85 | setNumRows(4); |
91 | setNumCols(4); | 86 | setNumCols(4); |
92 | 87 | ||
93 | // init arrays | 88 | // init arrays |
94 | initMap(); | 89 | initMap(); |
95 | readConfig(); | 90 | readConfig(); |
96 | initColors(); | 91 | initColors(); |
97 | 92 | ||
98 | // set font | 93 | // set font |
99 | QFont f = font(); | 94 | QFont f = font(); |
100 | f.setPixelSize(18); | 95 | f.setPixelSize(18); |
101 | f.setBold( TRUE ); | 96 | f.setBold( TRUE ); |
102 | setFont(f); | 97 | setFont(f); |
103 | } | 98 | } |
104 | 99 | ||
105 | PiecesTable::~PiecesTable() | 100 | PiecesTable::~PiecesTable() |
106 | { | 101 | { |
107 | writeConfig(); | 102 | writeConfig(); |
108 | } | 103 | } |
109 | 104 | ||
110 | void PiecesTable::writeConfig() | 105 | void PiecesTable::writeConfig() |
111 | { | 106 | { |
112 | Config cfg("Fifteen"); | 107 | Config cfg("Fifteen"); |
113 | cfg.setGroup("Game"); | 108 | cfg.setGroup("Game"); |
114 | QStringList map; | 109 | QStringList map; |
115 | for (int i = 0; i < 16; i++) | 110 | for (int i = 0; i < 16; i++) |
116 | map.append( QString::number( _map[i] ) ); | 111 | map.append( QString::number( _map[i] ) ); |
117 | cfg.writeEntry("Map", map, '-'); | 112 | cfg.writeEntry("Map", map, '-'); |
118 | cfg.writeEntry("Randomized", _randomized ); | 113 | cfg.writeEntry("Randomized", _randomized ); |
119 | } | 114 | } |
120 | 115 | ||
121 | void PiecesTable::readConfig() | 116 | void PiecesTable::readConfig() |
122 | { | 117 | { |
123 | Config cfg("Fifteen"); | 118 | Config cfg("Fifteen"); |
124 | cfg.setGroup("Game"); | 119 | cfg.setGroup("Game"); |
125 | QStringList map = cfg.readListEntry("Map", '-'); | 120 | QStringList map = cfg.readListEntry("Map", '-'); |
126 | _randomized = cfg.readBoolEntry( "Randomized", FALSE ); | 121 | _randomized = cfg.readBoolEntry( "Randomized", FALSE ); |
127 | int i = 0; | 122 | int i = 0; |
128 | for ( QStringList::Iterator it = map.begin(); it != map.end(); ++it ) { | 123 | for ( QStringList::Iterator it = map.begin(); it != map.end(); ++it ) { |
129 | _map[i] = (*it).toInt(); | 124 | _map[i] = (*it).toInt(); |
130 | i++; | 125 | i++; |
131 | if ( i > 15 ) break; | 126 | if ( i > 15 ) break; |
132 | } | 127 | } |
133 | } | 128 | } |
134 | 129 | ||
135 | void PiecesTable::paintCell(QPainter *p, int row, int col) | 130 | void PiecesTable::paintCell(QPainter *p, int row, int col) |
136 | { | 131 | { |
137 | int w = cellWidth(); | 132 | int w = cellWidth(); |
138 | int h = cellHeight(); | 133 | int h = cellHeight(); |
139 | int x2 = w - 1; | 134 | int x2 = w - 1; |
140 | int y2 = h - 1; | 135 | int y2 = h - 1; |
141 | 136 | ||
142 | int number = _map[col + row * numCols()] + 1; | 137 | int number = _map[col + row * numCols()] + 1; |
143 | 138 | ||
144 | // draw cell background | 139 | // draw cell background |
145 | if(number == 16) | 140 | if(number == 16) |
146 | p->setBrush(colorGroup().background()); | 141 | p->setBrush(colorGroup().background()); |
147 | else | 142 | else |
148 | p->setBrush(_colors[number-1]); | 143 | p->setBrush(_colors[number-1]); |
149 | p->setPen(NoPen); | 144 | p->setPen(NoPen); |
150 | p->drawRect(0, 0, w, h); | 145 | p->drawRect(0, 0, w, h); |
151 | 146 | ||
152 | if (number == 16) return; | 147 | if (number == 16) return; |
153 | 148 | ||
154 | // draw borders | 149 | // draw borders |
155 | if (height() > 40) { | 150 | if (height() > 40) { |
156 | p->setBrush(_colors[number-1].light(130)); | 151 | p->setBrush(_colors[number-1].light(130)); |
157 | p->drawPolygon(light_border); | 152 | p->drawPolygon(light_border); |
158 | 153 | ||
159 | p->setBrush(_colors[number-1].dark(130)); | 154 | p->setBrush(_colors[number-1].dark(130)); |
160 | p->drawPolygon(dark_border); | 155 | p->drawPolygon(dark_border); |
161 | } | 156 | } |
162 | 157 | ||
163 | // draw number | 158 | // draw number |
164 | p->setPen(black); | 159 | p->setPen(black); |
165 | p->drawText(0, 0, x2, y2, AlignHCenter | AlignVCenter, QString::number(number)); | 160 | p->drawText(0, 0, x2, y2, AlignHCenter | AlignVCenter, QString::number(number)); |
166 | } | 161 | } |
167 | 162 | ||
168 | void PiecesTable::resizeEvent(QResizeEvent *e) | 163 | void PiecesTable::resizeEvent(QResizeEvent *e) |
169 | { | 164 | { |
170 | QTableView::resizeEvent(e); | 165 | QTableView::resizeEvent(e); |
171 | 166 | ||
172 | setCellWidth(contentsRect().width()/ numRows()); | 167 | setCellWidth(contentsRect().width()/ numRows()); |
173 | setCellHeight(contentsRect().height() / numCols()); | 168 | setCellHeight(contentsRect().height() / numCols()); |
174 | 169 | ||
175 | // | 170 | // |
176 | // Calculate 3d-effect borders | 171 | // Calculate 3d-effect borders |
177 | // | 172 | // |
178 | intcell_w = cellWidth(); | 173 | intcell_w = cellWidth(); |
179 | intcell_h = cellHeight(); | 174 | intcell_h = cellHeight(); |
180 | int x_offset = cell_w - int(cell_w * 0.9);// 10% should be enough | 175 | int x_offset = cell_w - int(cell_w * 0.9);// 10% should be enough |
181 | inty_offset = cell_h - int(cell_h * 0.9); | 176 | inty_offset = cell_h - int(cell_h * 0.9); |
182 | 177 | ||
183 | light_border.setPoints(6, | 178 | light_border.setPoints(6, |
184 | 0, 0, | 179 | 0, 0, |
185 | cell_w, 0, | 180 | cell_w, 0, |
186 | cell_w - x_offset, y_offset, | 181 | cell_w - x_offset, y_offset, |
187 | x_offset, y_offset, | 182 | x_offset, y_offset, |
188 | x_offset, cell_h - y_offset, | 183 | x_offset, cell_h - y_offset, |
189 | 0, cell_h); | 184 | 0, cell_h); |
190 | 185 | ||
191 | dark_border.setPoints(6, | 186 | dark_border.setPoints(6, |
192 | cell_w, 0, | 187 | cell_w, 0, |
193 | cell_w, cell_h, | 188 | cell_w, cell_h, |
194 | 0, cell_h, | 189 | 0, cell_h, |
195 | x_offset, cell_h - y_offset, | 190 | x_offset, cell_h - y_offset, |
196 | cell_w - x_offset, cell_h - y_offset, | 191 | cell_w - x_offset, cell_h - y_offset, |
197 | cell_w - x_offset, y_offset); | 192 | cell_w - x_offset, y_offset); |
198 | } | 193 | } |
199 | 194 | ||
200 | void PiecesTable::initColors() | 195 | void PiecesTable::initColors() |
201 | { | 196 | { |
202 | _colors.resize(numRows() * numCols()); | 197 | _colors.resize(numRows() * numCols()); |
203 | for (int r = 0; r < numRows(); r++) | 198 | for (int r = 0; r < numRows(); r++) |
204 | for (int c = 0; c < numCols(); c++) | 199 | for (int c = 0; c < numCols(); c++) |
205 | _colors[c + r *numCols()] = QColor(255 - 70 * c,255 - 70 * r, 150); | 200 | _colors[c + r *numCols()] = QColor(255 - 70 * c,255 - 70 * r, 150); |
206 | } | 201 | } |
207 | 202 | ||
208 | void PiecesTable::initMap() | 203 | void PiecesTable::initMap() |
209 | { | 204 | { |
210 | _map.resize(16); | 205 | _map.resize(16); |
211 | for ( int i = 0; i < 16; i++) | 206 | for ( int i = 0; i < 16; i++) |
212 | _map[i] = i; | 207 | _map[i] = i; |
213 | 208 | ||
214 | _randomized = false; | 209 | _randomized = false; |
215 | } | 210 | } |
216 | 211 | ||
217 | void PiecesTable::randomizeMap() | 212 | void PiecesTable::randomizeMap() |
218 | { | 213 | { |
219 | initMap(); | 214 | initMap(); |
220 | _randomized = true; | 215 | _randomized = true; |
221 | // find the free position | 216 | // find the free position |
222 | int pos = _map.find(15); | 217 | int pos = _map.find(15); |
223 | 218 | ||
224 | int move = 0; | 219 | int move = 0; |
225 | while ( move < 333 ) { | 220 | while ( move < 333 ) { |
226 | 221 | ||
227 | int frow = pos / numCols(); | 222 | int frow = pos / numCols(); |
228 | int fcol = pos - frow * numCols(); | 223 | int fcol = pos - frow * numCols(); |
229 | 224 | ||
230 | // find click position | 225 | // find click position |
231 | int row = rand()%4; | 226 | int row = rand()%4; |
232 | int col = rand()%4; | 227 | int col = rand()%4; |
233 | 228 | ||
234 | // sanity check | 229 | // sanity check |
235 | if ( row < 0 || row >= numRows() ) continue; | 230 | if ( row < 0 || row >= numRows() ) continue; |
236 | if ( col < 0 || col >= numCols() ) continue; | 231 | if ( col < 0 || col >= numCols() ) continue; |
237 | if ( row != frow && col != fcol ) continue; | 232 | if ( row != frow && col != fcol ) continue; |
238 | 233 | ||
239 | move++; | 234 | move++; |
240 | 235 | ||
241 | // rows match -> shift pieces | 236 | // rows match -> shift pieces |
242 | if(row == frow) { | 237 | if(row == frow) { |
243 | 238 | ||
244 | if (col < fcol) { | 239 | if (col < fcol) { |
245 | for(int c = fcol; c > col; c--) { | 240 | for(int c = fcol; c > col; c--) { |
246 | _map[c + row * numCols()] = _map[ c-1 + row *numCols()]; | 241 | _map[c + row * numCols()] = _map[ c-1 + row *numCols()]; |
247 | } | 242 | } |
248 | } | 243 | } |
249 | else if (col > fcol) { | 244 | else if (col > fcol) { |
250 | for(int c = fcol; c < col; c++) { | 245 | for(int c = fcol; c < col; c++) { |
251 | _map[c + row * numCols()] = _map[ c+1 + row *numCols()]; | 246 | _map[c + row * numCols()] = _map[ c+1 + row *numCols()]; |
252 | } | 247 | } |
253 | } | 248 | } |
254 | } | 249 | } |
255 | // cols match -> shift pieces | 250 | // cols match -> shift pieces |
256 | else if (col == fcol) { | 251 | else if (col == fcol) { |
257 | 252 | ||
258 | if (row < frow) { | 253 | if (row < frow) { |
259 | for(int r = frow; r > row; r--) { | 254 | for(int r = frow; r > row; r--) { |
260 | _map[col + r * numCols()] = _map[ col + (r-1) *numCols()]; | 255 | _map[col + r * numCols()] = _map[ col + (r-1) *numCols()]; |
261 | } | 256 | } |
262 | } | 257 | } |
263 | else if (row > frow) { | 258 | else if (row > frow) { |
264 | for(int r = frow; r < row; r++) { | 259 | for(int r = frow; r < row; r++) { |
265 | _map[col + r * numCols()] = _map[ col + (r+1) *numCols()]; | 260 | _map[col + r * numCols()] = _map[ col + (r+1) *numCols()]; |
266 | } | 261 | } |
267 | } | 262 | } |
268 | } | 263 | } |
269 | // move free cell to click position | 264 | // move free cell to click position |
270 | _map[pos=(col + row * numCols())] = 15; | 265 | _map[pos=(col + row * numCols())] = 15; |
271 | } | 266 | } |
272 | repaint(); | 267 | repaint(); |
273 | } | 268 | } |
274 | 269 | ||
275 | void PiecesTable::checkwin() | 270 | void PiecesTable::checkwin() |
276 | { | 271 | { |
277 | if(!_randomized) return; | 272 | if(!_randomized) return; |
278 | 273 | ||
279 | int i; | 274 | int i; |
280 | for (i = 0; i < 16; i++) | 275 | for (i = 0; i < 16; i++) |
281 | if(i != _map[i]) | 276 | if(i != _map[i]) |
282 | break; | 277 | break; |
283 | 278 | ||
284 | if (i == 16) { | 279 | if (i == 16) { |
285 | QMessageBox::information(this, tr("Fifteen Pieces"), | 280 | QMessageBox::information(this, tr("Fifteen Pieces"), |
286 | tr("Congratulations!\nYou win the game!")); | 281 | tr("Congratulations!\nYou win the game!")); |
287 | _randomized = FALSE; | 282 | _randomized = FALSE; |
288 | } | 283 | } |
289 | 284 | ||
290 | } | 285 | } |
291 | 286 | ||
292 | void PiecesTable::slotRandomize() | 287 | void PiecesTable::slotRandomize() |
293 | { | 288 | { |
294 | randomizeMap(); | 289 | randomizeMap(); |
295 | } | 290 | } |
296 | 291 | ||
297 | void PiecesTable::slotReset() | 292 | void PiecesTable::slotReset() |
298 | { | 293 | { |
299 | initMap(); | 294 | initMap(); |
300 | repaint(); | 295 | repaint(); |
301 | } | 296 | } |
302 | 297 | ||
303 | void PiecesTable::mousePressEvent(QMouseEvent* e) | 298 | void PiecesTable::mousePressEvent(QMouseEvent* e) |
304 | { | 299 | { |
305 | QTableView::mousePressEvent(e); | 300 | QTableView::mousePressEvent(e); |
306 | 301 | ||
307 | if (e->button() == RightButton) { | 302 | if (e->button() == RightButton) { |
308 | 303 | ||
309 | // setup RMB pupup menu | 304 | // setup RMB pupup menu |
310 | if(!_menu) { | 305 | if(!_menu) { |
311 | _menu = new QPopupMenu(this); | 306 | _menu = new QPopupMenu(this); |
312 | _menu->insertItem(tr("R&andomize Pieces"), mRandomize); | 307 | _menu->insertItem(tr("R&andomize Pieces"), mRandomize); |
313 | _menu->insertItem(tr("&Reset Pieces"), mReset); | 308 | _menu->insertItem(tr("&Reset Pieces"), mReset); |
314 | _menu->adjustSize(); | 309 | _menu->adjustSize(); |
315 | } | 310 | } |
316 | 311 | ||
317 | // execute RMB popup and check result | 312 | // execute RMB popup and check result |
318 | switch(_menu->exec(mapToGlobal(e->pos()))) { | 313 | switch(_menu->exec(mapToGlobal(e->pos()))) { |
319 | case mRandomize: | 314 | case mRandomize: |
320 | randomizeMap(); | 315 | randomizeMap(); |
321 | break; | 316 | break; |
322 | case mReset: | 317 | case mReset: |
323 | initMap(); | 318 | initMap(); |
324 | repaint(); | 319 | repaint(); |
325 | break; | 320 | break; |
326 | default: | 321 | default: |
327 | break; | 322 | break; |
328 | } | 323 | } |
329 | } | 324 | } |
330 | else { | 325 | else { |
331 | // GAME LOGIC | 326 | // GAME LOGIC |
332 | 327 | ||
333 | // find the free position | 328 | // find the free position |
334 | int pos = _map.find(15); | 329 | int pos = _map.find(15); |
335 | if(pos < 0) return; | 330 | if(pos < 0) return; |
336 | 331 | ||
337 | int frow = pos / numCols(); | 332 | int frow = pos / numCols(); |
338 | int fcol = pos - frow * numCols(); | 333 | int fcol = pos - frow * numCols(); |
339 | 334 | ||
340 | // find click position | 335 | // find click position |
341 | int row = findRow(e->y()); | 336 | int row = findRow(e->y()); |
342 | int col = findCol(e->x()); | 337 | int col = findCol(e->x()); |
343 | 338 | ||
344 | // sanity check | 339 | // sanity check |
345 | if (row < 0 || row >= numRows()) return; | 340 | if (row < 0 || row >= numRows()) return; |
346 | if (col < 0 || col >= numCols()) return; | 341 | if (col < 0 || col >= numCols()) return; |
347 | if ( row != frow && col != fcol ) return; | 342 | if ( row != frow && col != fcol ) return; |
348 | 343 | ||
349 | // valid move? | 344 | // valid move? |
350 | if(row != frow && col != fcol) return; | 345 | if(row != frow && col != fcol) return; |
351 | 346 | ||
352 | // rows match -> shift pieces | 347 | // rows match -> shift pieces |
353 | if(row == frow) { | 348 | if(row == frow) { |
354 | 349 | ||
355 | if (col < fcol) { | 350 | if (col < fcol) { |
356 | for(int c = fcol; c > col; c--) { | 351 | for(int c = fcol; c > col; c--) { |
357 | _map[c + row * numCols()] = _map[ c-1 + row *numCols()]; | 352 | _map[c + row * numCols()] = _map[ c-1 + row *numCols()]; |
358 | updateCell(row, c, false); | 353 | updateCell(row, c, false); |
359 | } | 354 | } |
360 | } | 355 | } |
361 | else if (col > fcol) { | 356 | else if (col > fcol) { |
362 | for(int c = fcol; c < col; c++) { | 357 | for(int c = fcol; c < col; c++) { |
363 | _map[c + row * numCols()] = _map[ c+1 + row *numCols()]; | 358 | _map[c + row * numCols()] = _map[ c+1 + row *numCols()]; |
364 | updateCell(row, c, false); | 359 | updateCell(row, c, false); |
365 | } | 360 | } |
366 | } | 361 | } |
367 | } | 362 | } |
368 | // cols match -> shift pieces | 363 | // cols match -> shift pieces |
369 | else if (col == fcol) { | 364 | else if (col == fcol) { |
370 | 365 | ||
371 | if (row < frow) { | 366 | if (row < frow) { |
372 | for(int r = frow; r > row; r--) { | 367 | for(int r = frow; r > row; r--) { |
373 | _map[col + r * numCols()] = _map[ col + (r-1) *numCols()]; | 368 | _map[col + r * numCols()] = _map[ col + (r-1) *numCols()]; |
374 | updateCell(r, col, false); | 369 | updateCell(r, col, false); |
375 | } | 370 | } |
376 | } | 371 | } |
377 | else if (row > frow) { | 372 | else if (row > frow) { |
378 | for(int r = frow; r < row; r++) { | 373 | for(int r = frow; r < row; r++) { |
379 | _map[col + r * numCols()] = _map[ col + (r+1) *numCols()]; | 374 | _map[col + r * numCols()] = _map[ col + (r+1) *numCols()]; |
380 | updateCell(r, col, false); | 375 | updateCell(r, col, false); |
381 | } | 376 | } |
382 | } | 377 | } |
383 | } | 378 | } |
384 | // move free cell to click position | 379 | // move free cell to click position |
385 | _map[col + row * numCols()] = 15; | 380 | _map[col + row * numCols()] = 15; |
386 | updateCell(row, col, false); | 381 | updateCell(row, col, false); |
387 | 382 | ||
388 | // check if the player wins with this move | 383 | // check if the player wins with this move |
389 | checkwin(); | 384 | checkwin(); |
390 | } | 385 | } |
391 | } | 386 | } |
diff --git a/noncore/games/go/gowidget.cpp b/noncore/games/go/gowidget.cpp index cf89267..79820b1 100644 --- a/noncore/games/go/gowidget.cpp +++ b/noncore/games/go/gowidget.cpp | |||
@@ -1,464 +1,460 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "gowidget.h" | 21 | #include "gowidget.h" |
22 | 22 | ||
23 | #include <qpe/config.h> | 23 | #include <qpe/config.h> |
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | 25 | ||
26 | #include <qpainter.h> | 26 | #include <qpainter.h> |
27 | #include <qpixmap.h> | ||
28 | #include <qpe/qpetoolbar.h> | 27 | #include <qpe/qpetoolbar.h> |
29 | #include <qmenubar.h> | 28 | #include <qmenubar.h> |
30 | #include <qpopupmenu.h> | ||
31 | #include <qaction.h> | 29 | #include <qaction.h> |
32 | #include <qapplication.h> //processEvents() | 30 | #include <qapplication.h> //processEvents() |
33 | #include <qlabel.h> | 31 | #include <qlabel.h> |
34 | 32 | ||
35 | //#include <stdio.h> | 33 | //#include <stdio.h> |
36 | 34 | ||
37 | #include "amigo.h" | ||
38 | #include "goplayutils.h" | ||
39 | 35 | ||
40 | static const enum bVal computer_color = BLACK; | 36 | static const enum bVal computer_color = BLACK; |
41 | 37 | ||
42 | static int current_handicap = 1; | 38 | static int current_handicap = 1; |
43 | 39 | ||
44 | static QBrush *goBrush; | 40 | static QBrush *goBrush; |
45 | //static QImage *newBlackStone; | 41 | //static QImage *newBlackStone; |
46 | //static QImage *blackStone; | 42 | //static QImage *blackStone; |
47 | //static QImage *whiteStone; | 43 | //static QImage *whiteStone; |
48 | static QPixmap *newBlackStone; | 44 | static QPixmap *newBlackStone; |
49 | static QPixmap *blackStone; | 45 | static QPixmap *blackStone; |
50 | static QPixmap *whiteStone; | 46 | static QPixmap *whiteStone; |
51 | 47 | ||
52 | static bool smallStones = FALSE; | 48 | static bool smallStones = FALSE; |
53 | 49 | ||
54 | GoMainWidget::GoMainWidget( QWidget *parent, const char* name, WFlags fl) : | 50 | GoMainWidget::GoMainWidget( QWidget *parent, const char* name, WFlags fl) : |
55 | QMainWindow( parent, name, fl ) | 51 | QMainWindow( parent, name, fl ) |
56 | { | 52 | { |
57 | setToolBarsMovable( FALSE ); | 53 | setToolBarsMovable( FALSE ); |
58 | GoWidget *go = new GoWidget(this); | 54 | GoWidget *go = new GoWidget(this); |
59 | 55 | ||
60 | setCentralWidget(go); | 56 | setCentralWidget(go); |
61 | toolbar = new QToolBar(this); | 57 | toolbar = new QToolBar(this); |
62 | toolbar->setHorizontalStretchable( TRUE ); | 58 | toolbar->setHorizontalStretchable( TRUE ); |
63 | addToolBar(toolbar); | 59 | addToolBar(toolbar); |
64 | 60 | ||
65 | QMenuBar *mb = new QMenuBar( toolbar ); | 61 | QMenuBar *mb = new QMenuBar( toolbar ); |
66 | mb->setMargin(0); | 62 | mb->setMargin(0); |
67 | QPopupMenu *file = new QPopupMenu( this ); | 63 | QPopupMenu *file = new QPopupMenu( this ); |
68 | 64 | ||
69 | QAction *a = new QAction( tr( "New Game" ), QString::null, 0, this, 0 ); | 65 | QAction *a = new QAction( tr( "New Game" ), QString::null, 0, this, 0 ); |
70 | connect( a, SIGNAL( activated() ), go, SLOT( newGame() ) ); | 66 | connect( a, SIGNAL( activated() ), go, SLOT( newGame() ) ); |
71 | a->addTo( file ); | 67 | a->addTo( file ); |
72 | 68 | ||
73 | a = new QAction( tr( "Pass" ), Resource::loadPixmap( "pass" ), QString::null, 0, this, 0 ); | 69 | a = new QAction( tr( "Pass" ), Resource::loadPixmap( "pass" ), QString::null, 0, this, 0 ); |
74 | connect( a, SIGNAL( activated() ), go, SLOT( pass() ) ); | 70 | connect( a, SIGNAL( activated() ), go, SLOT( pass() ) ); |
75 | a->addTo( file ); | 71 | a->addTo( file ); |
76 | a->addTo( toolbar ); | 72 | a->addTo( toolbar ); |
77 | 73 | ||
78 | 74 | ||
79 | a = new QAction( tr( "Resign" ), Resource::loadPixmap( "reset" ), QString::null, 0, this, 0 ); | 75 | a = new QAction( tr( "Resign" ), Resource::loadPixmap( "reset" ), QString::null, 0, this, 0 ); |
80 | connect( a, SIGNAL( activated() ), go, SLOT( resign() ) ); | 76 | connect( a, SIGNAL( activated() ), go, SLOT( resign() ) ); |
81 | a->addTo( file ); | 77 | a->addTo( file ); |
82 | 78 | ||
83 | a = new QAction( tr( "Two player option" ), QString::null, 0, this, 0 ); | 79 | a = new QAction( tr( "Two player option" ), QString::null, 0, this, 0 ); |
84 | a->setToggleAction( TRUE ); | 80 | a->setToggleAction( TRUE ); |
85 | connect( a, SIGNAL( toggled(bool) ), go, SLOT( setTwoplayer(bool) ) ); | 81 | connect( a, SIGNAL( toggled(bool) ), go, SLOT( setTwoplayer(bool) ) ); |
86 | a->addTo( file ); | 82 | a->addTo( file ); |
87 | 83 | ||
88 | mb->insertItem( tr( "Game" ), file ); | 84 | mb->insertItem( tr( "Game" ), file ); |
89 | 85 | ||
90 | QLabel *turnLabel = new QLabel( toolbar ); | 86 | QLabel *turnLabel = new QLabel( toolbar ); |
91 | turnLabel->setBackgroundMode( PaletteButton ); | 87 | turnLabel->setBackgroundMode( PaletteButton ); |
92 | connect( go, SIGNAL(showTurn(const QPixmap&)), | 88 | connect( go, SIGNAL(showTurn(const QPixmap&)), |
93 | turnLabel, SLOT(setPixmap(const QPixmap&)) ); | 89 | turnLabel, SLOT(setPixmap(const QPixmap&)) ); |
94 | 90 | ||
95 | 91 | ||
96 | QLabel * scoreLabel = new QLabel( toolbar ); | 92 | QLabel * scoreLabel = new QLabel( toolbar ); |
97 | scoreLabel->setBackgroundMode( PaletteButton ); | 93 | scoreLabel->setBackgroundMode( PaletteButton ); |
98 | connect( go, SIGNAL(showScore(const QString&)), | 94 | connect( go, SIGNAL(showScore(const QString&)), |
99 | scoreLabel, SLOT(setText(const QString&)) ); | 95 | scoreLabel, SLOT(setText(const QString&)) ); |
100 | 96 | ||
101 | toolbar->setStretchableWidget( scoreLabel ); | 97 | toolbar->setStretchableWidget( scoreLabel ); |
102 | 98 | ||
103 | go->readConfig(); | 99 | go->readConfig(); |
104 | } | 100 | } |
105 | 101 | ||
106 | void GoMainWidget::resizeEvent( QResizeEvent * ) | 102 | void GoMainWidget::resizeEvent( QResizeEvent * ) |
107 | { | 103 | { |
108 | //### this won't work because of the text label... | 104 | //### this won't work because of the text label... |
109 | /* | 105 | /* |
110 | if ( width() > height() ) | 106 | if ( width() > height() ) |
111 | moveToolBar( toolbar, Left ); | 107 | moveToolBar( toolbar, Left ); |
112 | else | 108 | else |
113 | moveToolBar( toolbar, Top ); | 109 | moveToolBar( toolbar, Top ); |
114 | */ | 110 | */ |
115 | } | 111 | } |
116 | 112 | ||
117 | GoWidget *GoWidget::self = 0; | 113 | GoWidget *GoWidget::self = 0; |
118 | 114 | ||
119 | GoWidget::GoWidget( QWidget *parent, const char* name) : | 115 | GoWidget::GoWidget( QWidget *parent, const char* name) : |
120 | QWidget( parent, name ) | 116 | QWidget( parent, name ) |
121 | { | 117 | { |
122 | if ( self ) | 118 | if ( self ) |
123 | fatal( "Only one Go widget allowed" ); | 119 | fatal( "Only one Go widget allowed" ); |
124 | self = this; | 120 | self = this; |
125 | twoplayer = FALSE; | 121 | twoplayer = FALSE; |
126 | 122 | ||
127 | 123 | ||
128 | d = bx = by = 1; | 124 | d = bx = by = 1; |
129 | 125 | ||
130 | QPixmap pix = Resource::loadPixmap( "go/pine" ); | 126 | QPixmap pix = Resource::loadPixmap( "go/pine" ); |
131 | goBrush = new QBrush( black, pix ); | 127 | goBrush = new QBrush( black, pix ); |
132 | /* | 128 | /* |
133 | QString fn = Resource::findPixmap("Go-black"); | 129 | QString fn = Resource::findPixmap("Go-black"); |
134 | blackStone = new QImage( fn ); | 130 | blackStone = new QImage( fn ); |
135 | fn = Resource::findPixmap("Go-black-highlight"); | 131 | fn = Resource::findPixmap("Go-black-highlight"); |
136 | newBlackStone = new QImage( fn ); | 132 | newBlackStone = new QImage( fn ); |
137 | fn = Resource::findPixmap("Go-white"); | 133 | fn = Resource::findPixmap("Go-white"); |
138 | whiteStone = new QImage( fn ); | 134 | whiteStone = new QImage( fn ); |
139 | */ | 135 | */ |
140 | blackStone = new QPixmap(Resource::loadPixmap( "Go-black" )); | 136 | blackStone = new QPixmap(Resource::loadPixmap( "Go-black" )); |
141 | whiteStone = new QPixmap(Resource::loadPixmap( "Go-white" )); | 137 | whiteStone = new QPixmap(Resource::loadPixmap( "Go-white" )); |
142 | newBlackStone = new QPixmap(Resource::loadPixmap( "Go-black-highlight" )); | 138 | newBlackStone = new QPixmap(Resource::loadPixmap( "Go-black-highlight" )); |
143 | 139 | ||
144 | init(); | 140 | init(); |
145 | } | 141 | } |
146 | 142 | ||
147 | GoWidget::~GoWidget() | 143 | GoWidget::~GoWidget() |
148 | { | 144 | { |
149 | writeConfig(); | 145 | writeConfig(); |
150 | } | 146 | } |
151 | 147 | ||
152 | void GoWidget::writeConfig() | 148 | void GoWidget::writeConfig() |
153 | { | 149 | { |
154 | Config cfg("Go"); | 150 | Config cfg("Go"); |
155 | cfg.setGroup("Game"); | 151 | cfg.setGroup("Game"); |
156 | cfg.writeEntry("TwoPlayer", twoplayer); | 152 | cfg.writeEntry("TwoPlayer", twoplayer); |
157 | cfg.writeEntry("CurrentPlayer", currentPlayer); | 153 | cfg.writeEntry("CurrentPlayer", currentPlayer); |
158 | cfg.writeEntry("NPassed", nPassed); | 154 | cfg.writeEntry("NPassed", nPassed); |
159 | QString b; | 155 | QString b; |
160 | for (int i=0; i<19; i++) | 156 | for (int i=0; i<19; i++) |
161 | for (int j=0; j<19; j++) | 157 | for (int j=0; j<19; j++) |
162 | b += board[i][j] == BLACK ? 'B' : board[i][j] == WHITE ? 'W' : '.'; | 158 | b += board[i][j] == BLACK ? 'B' : board[i][j] == WHITE ? 'W' : '.'; |
163 | cfg.writeEntry("Board", b); | 159 | cfg.writeEntry("Board", b); |
164 | cfg.writeEntry("LastX", lastX); | 160 | cfg.writeEntry("LastX", lastX); |
165 | cfg.writeEntry("LastY", lastY); | 161 | cfg.writeEntry("LastY", lastY); |
166 | extern int blackPrisoners, whitePrisoners; | 162 | extern int blackPrisoners, whitePrisoners; |
167 | cfg.writeEntry("BlackPrisoners", blackPrisoners); | 163 | cfg.writeEntry("BlackPrisoners", blackPrisoners); |
168 | cfg.writeEntry("WhitePrisoners", whitePrisoners); | 164 | cfg.writeEntry("WhitePrisoners", whitePrisoners); |
169 | } | 165 | } |
170 | 166 | ||
171 | void GoWidget::readConfig() | 167 | void GoWidget::readConfig() |
172 | { | 168 | { |
173 | init(); | 169 | init(); |
174 | Config cfg("Go"); | 170 | Config cfg("Go"); |
175 | cfg.setGroup("Game"); | 171 | cfg.setGroup("Game"); |
176 | twoplayer = cfg.readBoolEntry("TwoPlayer"); | 172 | twoplayer = cfg.readBoolEntry("TwoPlayer"); |
177 | currentPlayer = (bVal)cfg.readNumEntry("CurrentPlayer",1); | 173 | currentPlayer = (bVal)cfg.readNumEntry("CurrentPlayer",1); |
178 | nPassed = cfg.readNumEntry("NPassed",0); | 174 | nPassed = cfg.readNumEntry("NPassed",0); |
179 | QString b = cfg.readEntry("Board"); | 175 | QString b = cfg.readEntry("Board"); |
180 | if ( b.length() == 19*19 ) | 176 | if ( b.length() == 19*19 ) |
181 | for (int i=0; i<19; i++) | 177 | for (int i=0; i<19; i++) |
182 | for (int j=0; j<19; j++) { | 178 | for (int j=0; j<19; j++) { |
183 | QChar ch = b[j+19*i]; | 179 | QChar ch = b[j+19*i]; |
184 | if ( ch != '.' ) | 180 | if ( ch != '.' ) |
185 | GoPlaceStone( ch == 'B' ? BLACK : WHITE, i, j ); | 181 | GoPlaceStone( ch == 'B' ? BLACK : WHITE, i, j ); |
186 | } | 182 | } |
187 | lastX = cfg.readNumEntry("LastX"); | 183 | lastX = cfg.readNumEntry("LastX"); |
188 | lastY = cfg.readNumEntry("LastY"); | 184 | lastY = cfg.readNumEntry("LastY"); |
189 | extern int blackPrisoners, whitePrisoners; | 185 | extern int blackPrisoners, whitePrisoners; |
190 | blackPrisoners = cfg.readNumEntry("BlackPrisoners",0); | 186 | blackPrisoners = cfg.readNumEntry("BlackPrisoners",0); |
191 | whitePrisoners = cfg.readNumEntry("WhitePrisoners",0); | 187 | whitePrisoners = cfg.readNumEntry("WhitePrisoners",0); |
192 | reportPrisoners(blackPrisoners,whitePrisoners); | 188 | reportPrisoners(blackPrisoners,whitePrisoners); |
193 | emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone ); | 189 | emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone ); |
194 | } | 190 | } |
195 | 191 | ||
196 | void GoWidget::resizeEvent( QResizeEvent * ) | 192 | void GoWidget::resizeEvent( QResizeEvent * ) |
197 | { | 193 | { |
198 | d = QMIN(width(),height())/19; | 194 | d = QMIN(width(),height())/19; |
199 | // int r = (d/2-1); | 195 | // int r = (d/2-1); |
200 | bx = (width() - 18*d)/2 ; | 196 | bx = (width() - 18*d)/2 ; |
201 | by = (height() - 18*d)/2 ; | 197 | by = (height() - 18*d)/2 ; |
202 | 198 | ||
203 | if ( d < 10 && !smallStones ) { | 199 | if ( d < 10 && !smallStones ) { |
204 | blackStone->convertFromImage( blackStone->convertToImage().smoothScale(8,8) ); | 200 | blackStone->convertFromImage( blackStone->convertToImage().smoothScale(8,8) ); |
205 | whiteStone->convertFromImage( whiteStone->convertToImage().smoothScale(8,8) ); | 201 | whiteStone->convertFromImage( whiteStone->convertToImage().smoothScale(8,8) ); |
206 | newBlackStone->convertFromImage( newBlackStone->convertToImage().smoothScale(8,8) ); | 202 | newBlackStone->convertFromImage( newBlackStone->convertToImage().smoothScale(8,8) ); |
207 | 203 | ||
208 | smallStones = TRUE; | 204 | smallStones = TRUE; |
209 | } else if ( d >= 10 && smallStones ) { | 205 | } else if ( d >= 10 && smallStones ) { |
210 | blackStone = new QPixmap(Resource::loadPixmap( "Go-black" )); | 206 | blackStone = new QPixmap(Resource::loadPixmap( "Go-black" )); |
211 | whiteStone = new QPixmap(Resource::loadPixmap( "Go-white" )); | 207 | whiteStone = new QPixmap(Resource::loadPixmap( "Go-white" )); |
212 | newBlackStone = new QPixmap(Resource::loadPixmap( "Go-black-highlight" )); | 208 | newBlackStone = new QPixmap(Resource::loadPixmap( "Go-black-highlight" )); |
213 | smallStones = FALSE; | 209 | smallStones = FALSE; |
214 | } | 210 | } |
215 | } | 211 | } |
216 | 212 | ||
217 | void GoWidget::init() | 213 | void GoWidget::init() |
218 | { | 214 | { |
219 | lastX = lastY = newX = newY = -1; | 215 | lastX = lastY = newX = newY = -1; |
220 | nPassed = 0; | 216 | nPassed = 0; |
221 | for ( int i = 0; i < 19; i++ ) | 217 | for ( int i = 0; i < 19; i++ ) |
222 | for ( int j = 0; j < 19; j++ ) | 218 | for ( int j = 0; j < 19; j++ ) |
223 | board[i][j]=-1; | 219 | board[i][j]=-1; |
224 | gameActive = TRUE; | 220 | gameActive = TRUE; |
225 | goRestart(current_handicap); | 221 | goRestart(current_handicap); |
226 | 222 | ||
227 | if ( twoplayer ) { | 223 | if ( twoplayer ) { |
228 | currentPlayer = BLACK; | 224 | currentPlayer = BLACK; |
229 | } else { | 225 | } else { |
230 | doComputerMove(); | 226 | doComputerMove(); |
231 | currentPlayer = WHITE; | 227 | currentPlayer = WHITE; |
232 | } | 228 | } |
233 | emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone ); | 229 | emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone ); |
234 | } | 230 | } |
235 | 231 | ||
236 | void GoWidget::paintEvent( QPaintEvent *e ) | 232 | void GoWidget::paintEvent( QPaintEvent *e ) |
237 | { | 233 | { |
238 | int i,j; | 234 | int i,j; |
239 | 235 | ||
240 | int r = whiteStone->width()/2; | 236 | int r = whiteStone->width()/2; |
241 | 237 | ||
242 | QPainter p(this); | 238 | QPainter p(this); |
243 | p.fillRect( bx - d/2, by - d/2, 19*d, 19*d, *goBrush ); | 239 | p.fillRect( bx - d/2, by - d/2, 19*d, 19*d, *goBrush ); |
244 | 240 | ||
245 | int xMin = QMAX( x2board(e->rect().left()), 0 ); | 241 | int xMin = QMAX( x2board(e->rect().left()), 0 ); |
246 | int xMax = QMIN( x2board(e->rect().right()), 18 ); | 242 | int xMax = QMIN( x2board(e->rect().right()), 18 ); |
247 | int yMin = QMAX( y2board(e->rect().top()), 0 ); | 243 | int yMin = QMAX( y2board(e->rect().top()), 0 ); |
248 | int yMax = QMIN( y2board(e->rect().bottom()), 18 ); | 244 | int yMax = QMIN( y2board(e->rect().bottom()), 18 ); |
249 | 245 | ||
250 | QColor pine( 255, 186, 89 ); | 246 | QColor pine( 255, 186, 89 ); |
251 | p.setPen( pine.dark() ); | 247 | p.setPen( pine.dark() ); |
252 | 248 | ||
253 | for ( i = xMin; i < xMax+1 ; i ++ ) { | 249 | for ( i = xMin; i < xMax+1 ; i ++ ) { |
254 | p.drawLine( bx+i*d, by, bx+i*d, by+18*d ); | 250 | p.drawLine( bx+i*d, by, bx+i*d, by+18*d ); |
255 | } | 251 | } |
256 | for ( j = yMin; j < yMax+1 ; j ++ ) { | 252 | for ( j = yMin; j < yMax+1 ; j ++ ) { |
257 | p.drawLine( bx, by+j*d, bx+18*d, by+j*d); | 253 | p.drawLine( bx, by+j*d, bx+18*d, by+j*d); |
258 | } | 254 | } |
259 | 255 | ||
260 | // dots are at (3,3), (3,9), (3,15) and so on | 256 | // dots are at (3,3), (3,9), (3,15) and so on |
261 | p.setBrush( black ); | 257 | p.setBrush( black ); |
262 | for ( i = 3; i < xMax+1; i+=6 ) | 258 | for ( i = 3; i < xMax+1; i+=6 ) |
263 | for ( j = 3; j < yMax+1; j+=6 ) | 259 | for ( j = 3; j < yMax+1; j+=6 ) |
264 | p.drawEllipse( bx+i*d-2, by+j*d-2, 5, 5 ); | 260 | p.drawEllipse( bx+i*d-2, by+j*d-2, 5, 5 ); |
265 | 261 | ||
266 | 262 | ||
267 | for ( i = xMin; i < xMax+1; i++ ) | 263 | for ( i = xMin; i < xMax+1; i++ ) |
268 | for ( j = yMin; j < yMax+1; j++ ) { | 264 | for ( j = yMin; j < yMax+1; j++ ) { |
269 | if ( board[i][j] == WHITE || | 265 | if ( board[i][j] == WHITE || |
270 | currentPlayer==WHITE && newX == i && newY == j ) | 266 | currentPlayer==WHITE && newX == i && newY == j ) |
271 | p.drawPixmap( bx+i*d - r, by+j*d - r, *whiteStone ); | 267 | p.drawPixmap( bx+i*d - r, by+j*d - r, *whiteStone ); |
272 | else if ( i == lastX && j == lastY ) | 268 | else if ( i == lastX && j == lastY ) |
273 | p.drawPixmap( bx+i*d - r, by+j*d - r, *newBlackStone ); | 269 | p.drawPixmap( bx+i*d - r, by+j*d - r, *newBlackStone ); |
274 | else if ( board[i][j] == BLACK || | 270 | else if ( board[i][j] == BLACK || |
275 | currentPlayer==BLACK && newX == i && newY == j) | 271 | currentPlayer==BLACK && newX == i && newY == j) |
276 | p.drawPixmap( bx+i*d - r, by+j*d - r, *blackStone ); | 272 | p.drawPixmap( bx+i*d - r, by+j*d - r, *blackStone ); |
277 | } | 273 | } |
278 | } | 274 | } |
279 | 275 | ||
280 | void GoWidget::doMove( int x, int y ) | 276 | void GoWidget::doMove( int x, int y ) |
281 | { | 277 | { |
282 | 278 | ||
283 | if ( !GoPlaceStone( currentPlayer, x, y ) ) { | 279 | if ( !GoPlaceStone( currentPlayer, x, y ) ) { |
284 | //printf( "Illegal move (%d,%d)\n", x, y ); | 280 | //printf( "Illegal move (%d,%d)\n", x, y ); |
285 | return; | 281 | return; |
286 | } | 282 | } |
287 | //printf( "you do (%d,%d)\n", x, y ); | 283 | //printf( "you do (%d,%d)\n", x, y ); |
288 | nPassed = 0; | 284 | nPassed = 0; |
289 | if ( twoplayer ) | 285 | if ( twoplayer ) |
290 | currentPlayer = (currentPlayer==WHITE) ? BLACK : WHITE; | 286 | currentPlayer = (currentPlayer==WHITE) ? BLACK : WHITE; |
291 | else | 287 | else |
292 | doComputerMove(); | 288 | doComputerMove(); |
293 | 289 | ||
294 | emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone ); | 290 | emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone ); |
295 | 291 | ||
296 | } | 292 | } |
297 | 293 | ||
298 | void GoWidget::pass() | 294 | void GoWidget::pass() |
299 | { | 295 | { |
300 | if ( !gameActive ) | 296 | if ( !gameActive ) |
301 | return; | 297 | return; |
302 | nPassed++; | 298 | nPassed++; |
303 | if ( nPassed >= 2 ) | 299 | if ( nPassed >= 2 ) |
304 | endGame(); | 300 | endGame(); |
305 | else if ( !twoplayer ) | 301 | else if ( !twoplayer ) |
306 | doComputerMove(); | 302 | doComputerMove(); |
307 | } | 303 | } |
308 | 304 | ||
309 | void GoWidget::resign() | 305 | void GoWidget::resign() |
310 | { | 306 | { |
311 | if ( gameActive ) | 307 | if ( gameActive ) |
312 | endGame(); | 308 | endGame(); |
313 | } | 309 | } |
314 | 310 | ||
315 | 311 | ||
316 | void GoWidget::newGame() | 312 | void GoWidget::newGame() |
317 | { | 313 | { |
318 | init(); | 314 | init(); |
319 | update(); | 315 | update(); |
320 | } | 316 | } |
321 | 317 | ||
322 | 318 | ||
323 | void GoWidget::endGame() | 319 | void GoWidget::endGame() |
324 | { | 320 | { |
325 | gameActive = FALSE; | 321 | gameActive = FALSE; |
326 | 322 | ||
327 | int w,b; | 323 | int w,b; |
328 | CountUp( &w, &b); | 324 | CountUp( &w, &b); |
329 | QString s = tr("White %1, Black %2. ").arg(w).arg(b); | 325 | QString s = tr("White %1, Black %2. ").arg(w).arg(b); |
330 | if ( w > b ) | 326 | if ( w > b ) |
331 | s += tr("White wins."); | 327 | s += tr("White wins."); |
332 | else if ( w < b ) | 328 | else if ( w < b ) |
333 | s += tr("Black wins."); | 329 | s += tr("Black wins."); |
334 | else | 330 | else |
335 | s += tr("A draw."); | 331 | s += tr("A draw."); |
336 | emit showScore( s ); | 332 | emit showScore( s ); |
337 | } | 333 | } |
338 | 334 | ||
339 | void GoWidget::doComputerMove() | 335 | void GoWidget::doComputerMove() |
340 | { | 336 | { |
341 | int ox = lastX; | 337 | int ox = lastX; |
342 | int oy = lastY; | 338 | int oy = lastY; |
343 | lastX = lastY = -1; | 339 | lastX = lastY = -1; |
344 | emit showTurn( *blackStone ); | 340 | emit showTurn( *blackStone ); |
345 | refresh( ox, oy); | 341 | refresh( ox, oy); |
346 | qApp->processEvents(); | 342 | qApp->processEvents(); |
347 | short int x,y; | 343 | short int x,y; |
348 | if ( genMove( computer_color, &x, &y ) ) { | 344 | if ( genMove( computer_color, &x, &y ) ) { |
349 | lastX = x; | 345 | lastX = x; |
350 | lastY = y; | 346 | lastY = y; |
351 | //printf( "I do (%d,%d)\n", x, y ); | 347 | //printf( "I do (%d,%d)\n", x, y ); |
352 | GoPlaceStone(computer_color,x,y); | 348 | GoPlaceStone(computer_color,x,y); |
353 | nPassed = 0; | 349 | nPassed = 0; |
354 | } else { | 350 | } else { |
355 | emit showScore( tr("I pass") ); | 351 | emit showScore( tr("I pass") ); |
356 | nPassed++; | 352 | nPassed++; |
357 | if ( nPassed >= 2 ) | 353 | if ( nPassed >= 2 ) |
358 | endGame(); | 354 | endGame(); |
359 | } | 355 | } |
360 | } | 356 | } |
361 | 357 | ||
362 | void GoWidget::mousePressEvent( QMouseEvent *me ) | 358 | void GoWidget::mousePressEvent( QMouseEvent *me ) |
363 | { | 359 | { |
364 | if ( !gameActive ) | 360 | if ( !gameActive ) |
365 | return; | 361 | return; |
366 | int x = x2board(me->x()); | 362 | int x = x2board(me->x()); |
367 | int y = y2board(me->y()); | 363 | int y = y2board(me->y()); |
368 | showStone(x,y,currentPlayer); | 364 | showStone(x,y,currentPlayer); |
369 | } | 365 | } |
370 | 366 | ||
371 | void GoWidget::mouseMoveEvent( QMouseEvent *me ) | 367 | void GoWidget::mouseMoveEvent( QMouseEvent *me ) |
372 | { | 368 | { |
373 | if ( !gameActive ) | 369 | if ( !gameActive ) |
374 | return; | 370 | return; |
375 | int x = x2board(me->x()); | 371 | int x = x2board(me->x()); |
376 | int y = y2board(me->y()); | 372 | int y = y2board(me->y()); |
377 | if ( x != newX || y != newY ) | 373 | if ( x != newX || y != newY ) |
378 | showStone(x,y,currentPlayer); | 374 | showStone(x,y,currentPlayer); |
379 | } | 375 | } |
380 | 376 | ||
381 | void GoWidget::showStone( int x, int y, enum bVal c ) | 377 | void GoWidget::showStone( int x, int y, enum bVal c ) |
382 | { | 378 | { |
383 | 379 | ||
384 | if ( newX > -1 ) { | 380 | if ( newX > -1 ) { |
385 | refresh( newX, newY ); | 381 | refresh( newX, newY ); |
386 | newY = newX = -1; | 382 | newY = newX = -1; |
387 | } | 383 | } |
388 | if ( x < 0 || x > 18 || y < 0 || y > 18 ) { | 384 | if ( x < 0 || x > 18 || y < 0 || y > 18 ) { |
389 | newX = newY = -1; | 385 | newX = newY = -1; |
390 | return; | 386 | return; |
391 | } | 387 | } |
392 | if ( board[x][y] == -1 && !Suicide( c, x, y ) ) { | 388 | if ( board[x][y] == -1 && !Suicide( c, x, y ) ) { |
393 | newX = x; | 389 | newX = x; |
394 | newY = y; | 390 | newY = y; |
395 | refresh(x,y); | 391 | refresh(x,y); |
396 | } | 392 | } |
397 | 393 | ||
398 | } | 394 | } |
399 | 395 | ||
400 | void GoWidget::mouseReleaseEvent( QMouseEvent * ) | 396 | void GoWidget::mouseReleaseEvent( QMouseEvent * ) |
401 | { | 397 | { |
402 | if ( gameActive && newX > -1 ) | 398 | if ( gameActive && newX > -1 ) |
403 | doMove( newX, newY ); | 399 | doMove( newX, newY ); |
404 | newX = newY = -1; | 400 | newX = newY = -1; |
405 | } | 401 | } |
406 | 402 | ||
407 | void GoWidget::refresh( int x, int y ) | 403 | void GoWidget::refresh( int x, int y ) |
408 | { | 404 | { |
409 | update( bx+d*x-d/2-1, by+d*y-d/2-1, d+2, d+2 ); | 405 | update( bx+d*x-d/2-1, by+d*y-d/2-1, d+2, d+2 ); |
410 | } | 406 | } |
411 | 407 | ||
412 | void GoWidget::removeStone(short x, short y) | 408 | void GoWidget::removeStone(short x, short y) |
413 | { | 409 | { |
414 | board[x][y]=-1; | 410 | board[x][y]=-1; |
415 | refresh( x, y ); | 411 | refresh( x, y ); |
416 | } | 412 | } |
417 | 413 | ||
418 | void GoWidget::placeStone (enum bVal c, short x, short y ) | 414 | void GoWidget::placeStone (enum bVal c, short x, short y ) |
419 | { | 415 | { |
420 | board[x][y]=c; | 416 | board[x][y]=c; |
421 | refresh( x, y ); | 417 | refresh( x, y ); |
422 | } | 418 | } |
423 | 419 | ||
424 | void GoWidget::reportPrisoners( int blackcnt, int whitecnt ) | 420 | void GoWidget::reportPrisoners( int blackcnt, int whitecnt ) |
425 | { | 421 | { |
426 | QString s = tr( "Prisoners: black %1, white %2" ).arg(blackcnt).arg(whitecnt); | 422 | QString s = tr( "Prisoners: black %1, white %2" ).arg(blackcnt).arg(whitecnt); |
427 | emit showScore( s ); | 423 | emit showScore( s ); |
428 | } | 424 | } |
429 | 425 | ||
430 | void GoWidget::setTwoplayer( bool b ) | 426 | void GoWidget::setTwoplayer( bool b ) |
431 | { | 427 | { |
432 | twoplayer = b; | 428 | twoplayer = b; |
433 | } | 429 | } |
434 | 430 | ||
435 | void GoWidget::setHandicap( int h ) | 431 | void GoWidget::setHandicap( int h ) |
436 | { | 432 | { |
437 | current_handicap = h; | 433 | current_handicap = h; |
438 | } | 434 | } |
439 | 435 | ||
440 | 436 | ||
441 | extern "C" { | 437 | extern "C" { |
442 | 438 | ||
443 | voidremovestone(short x, short y) | 439 | voidremovestone(short x, short y) |
444 | { | 440 | { |
445 | GoWidget::self->removeStone(x,y); | 441 | GoWidget::self->removeStone(x,y); |
446 | } | 442 | } |
447 | 443 | ||
448 | voidplacestone (enum bVal c, short x, short y ) | 444 | voidplacestone (enum bVal c, short x, short y ) |
449 | { | 445 | { |
450 | GoWidget::self->placeStone(c,x,y); | 446 | GoWidget::self->placeStone(c,x,y); |
451 | } | 447 | } |
452 | 448 | ||
453 | voidintrMoveReport(enum bVal c ,char *coord ,char *reason ) | 449 | voidintrMoveReport(enum bVal c ,char *coord ,char *reason ) |
454 | { | 450 | { |
455 | qDebug( "intrMoveReport colour %d, %s %s", c, coord, reason ); | 451 | qDebug( "intrMoveReport colour %d, %s %s", c, coord, reason ); |
456 | } | 452 | } |
457 | 453 | ||
458 | voidintrPrisonerReport( short blackcnt, short whitecnt ) | 454 | voidintrPrisonerReport( short blackcnt, short whitecnt ) |
459 | { | 455 | { |
460 | GoWidget::self->reportPrisoners(blackcnt,whitecnt); | 456 | GoWidget::self->reportPrisoners(blackcnt,whitecnt); |
461 | } | 457 | } |
462 | 458 | ||
463 | } | 459 | } |
464 | 460 | ||
diff --git a/noncore/games/go/main.cpp b/noncore/games/go/main.cpp index f24e3c3..66f34ab 100644 --- a/noncore/games/go/main.cpp +++ b/noncore/games/go/main.cpp | |||
@@ -1,28 +1,27 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "gowidget.h" | 21 | #include "gowidget.h" |
22 | 22 | ||
23 | #include <qpe/qpeapplication.h> | ||
24 | 23 | ||
25 | #include <opie/oapplicationfactory.h> | 24 | #include <opie/oapplicationfactory.h> |
26 | 25 | ||
27 | OPIE_EXPORT_APP( OApplicationFactory<GoMainWidget> ) | 26 | OPIE_EXPORT_APP( OApplicationFactory<GoMainWidget> ) |
28 | 27 | ||
diff --git a/noncore/games/kbill/MCursor.cc b/noncore/games/kbill/MCursor.cc index a3cb340..c581693 100644 --- a/noncore/games/kbill/MCursor.cc +++ b/noncore/games/kbill/MCursor.cc | |||
@@ -1,69 +1,64 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | MCursor.cc - description | 2 | MCursor.cc - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Thu Dec 30 1999 | 4 | begin : Thu Dec 30 1999 |
5 | copyright : (C) 1999 by Jurrien Loonstra | 5 | copyright : (C) 1999 by Jurrien Loonstra |
6 | email : j.h.loonstra@st.hanze.nl | 6 | email : j.h.loonstra@st.hanze.nl |
7 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | 8 | ||
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * | 11 | * This program is free software; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation; either version 2 of the License, or * | 13 | * the Free Software Foundation; either version 2 of the License, or * |
14 | * (at your option) any later version. * | 14 | * (at your option) any later version. * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | #include "MCursor.h" | 17 | #include "MCursor.h" |
18 | #include "objects.h" | ||
19 | 18 | ||
20 | #include <qcursor.h> | ||
21 | #include <qbitmap.h> | ||
22 | #include <qwidget.h> | ||
23 | #include <qstring.h> | ||
24 | #ifdef KDEVER | 19 | #ifdef KDEVER |
25 | #include <kapp.h> | 20 | #include <kapp.h> |
26 | #include <kstandarddirs.h> | 21 | #include <kstandarddirs.h> |
27 | #endif | 22 | #endif |
28 | #include <iostream> | 23 | #include <iostream> |
29 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
30 | MCursor::~MCursor() { | 25 | MCursor::~MCursor() { |
31 | delete cursor; | 26 | delete cursor; |
32 | } | 27 | } |
33 | 28 | ||
34 | void MCursor::load(const char *name, int masked) { | 29 | void MCursor::load(const char *name, int masked) { |
35 | 30 | ||
36 | #ifdef KDEVER | 31 | #ifdef KDEVER |
37 | QString file, mfile; | 32 | QString file, mfile; |
38 | KStandardDirs dirs; | 33 | KStandardDirs dirs; |
39 | 34 | ||
40 | 35 | ||
41 | file = dirs.findResource("data","kbill/bitmaps/" + QString::fromLocal8Bit(name) + ".xbm"); | 36 | file = dirs.findResource("data","kbill/bitmaps/" + QString::fromLocal8Bit(name) + ".xbm"); |
42 | 37 | ||
43 | QBitmap bitmap, mask; | 38 | QBitmap bitmap, mask; |
44 | if (bitmap.load(file) == FALSE) { | 39 | if (bitmap.load(file) == FALSE) { |
45 | std::cerr << "cannot open " << file << std::endl; | 40 | std::cerr << "cannot open " << file << std::endl; |
46 | exit(1); | 41 | exit(1); |
47 | } | 42 | } |
48 | if (masked == SEP_MASK) { | 43 | if (masked == SEP_MASK) { |
49 | // mfile.sprintf ("%sbitmaps/%s_mask.xbm", (const char*)dir, name); | 44 | // mfile.sprintf ("%sbitmaps/%s_mask.xbm", (const char*)dir, name); |
50 | mfile = file = dirs.findResource("data","kbill/bitmaps/" + QString::fromLocal8Bit(name) + "_mask.xbm"); | 45 | mfile = file = dirs.findResource("data","kbill/bitmaps/" + QString::fromLocal8Bit(name) + "_mask.xbm"); |
51 | if (mask.load(mfile) == FALSE) { | 46 | if (mask.load(mfile) == FALSE) { |
52 | std::cerr << "cannot open " << file << std::endl; | 47 | std::cerr << "cannot open " << file << std::endl; |
53 | exit(1); | 48 | exit(1); |
54 | } | 49 | } |
55 | } | 50 | } |
56 | else | 51 | else |
57 | mask = bitmap; | 52 | mask = bitmap; |
58 | #endif | 53 | #endif |
59 | 54 | ||
60 | QBitmap bitmap, mask; | 55 | QBitmap bitmap, mask; |
61 | bitmap = Resource::loadBitmap("kbill/bitmaps/" + QString::fromLocal8Bit(name)); | 56 | bitmap = Resource::loadBitmap("kbill/bitmaps/" + QString::fromLocal8Bit(name)); |
62 | 57 | ||
63 | if (masked == SEP_MASK) | 58 | if (masked == SEP_MASK) |
64 | mask = bitmap = Resource::loadBitmap("kbill/bitmaps/" + QString::fromLocal8Bit(name) + "_mask.xbm"); | 59 | mask = bitmap = Resource::loadBitmap("kbill/bitmaps/" + QString::fromLocal8Bit(name) + "_mask.xbm"); |
65 | else | 60 | else |
66 | mask = bitmap; | 61 | mask = bitmap; |
67 | cursor = new QCursor(bitmap, mask, bitmap.width() / 2, bitmap.height() / 2); | 62 | cursor = new QCursor(bitmap, mask, bitmap.width() / 2, bitmap.height() / 2); |
68 | } | 63 | } |
69 | 64 | ||
diff --git a/noncore/games/kbill/Picture.cc b/noncore/games/kbill/Picture.cc index fe0eff8..9d46257 100644 --- a/noncore/games/kbill/Picture.cc +++ b/noncore/games/kbill/Picture.cc | |||
@@ -1,72 +1,70 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | Picture.cc - description | 2 | Picture.cc - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Thu Dec 30 1999 | 4 | begin : Thu Dec 30 1999 |
5 | copyright : (C) 1999 by Jurrien Loonstra | 5 | copyright : (C) 1999 by Jurrien Loonstra |
6 | email : j.h.loonstra@st.hanze.nl | 6 | email : j.h.loonstra@st.hanze.nl |
7 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | 8 | ||
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * | 11 | * This program is free software; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation; either version 2 of the License, or * | 13 | * the Free Software Foundation; either version 2 of the License, or * |
14 | * (at your option) any later version. * | 14 | * (at your option) any later version. * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | #include "Picture.h" | 17 | #include "Picture.h" |
18 | #include "objects.h" | ||
19 | 18 | ||
20 | #include <iostream> | 19 | #include <iostream> |
21 | 20 | ||
22 | #include <qstring.h> | ||
23 | #include <qpe/resource.h> | 21 | #include <qpe/resource.h> |
24 | #ifdef KDEVER | 22 | #ifdef KDEVER |
25 | #include <kapp.h> | 23 | #include <kapp.h> |
26 | #include <kstandarddirs.h> | 24 | #include <kstandarddirs.h> |
27 | #include <kdebug.h> | 25 | #include <kdebug.h> |
28 | #endif | 26 | #endif |
29 | void Picture::load(const char *name, int index) { | 27 | void Picture::load(const char *name, int index) { |
30 | //QString dir = KApplication::kde_datadir(), file; | 28 | //QString dir = KApplication::kde_datadir(), file; |
31 | // QString dir = locate("data",""),file; | 29 | // QString dir = locate("data",""),file; |
32 | // dir += "/kbill/"; | 30 | // dir += "/kbill/"; |
33 | // if (index>=0) | 31 | // if (index>=0) |
34 | // file.sprintf ("%spixmaps/%s_%d.xpm", (const char *)dir, name, index); | 32 | // file.sprintf ("%spixmaps/%s_%d.xpm", (const char *)dir, name, index); |
35 | // else | 33 | // else |
36 | // file.sprintf("%spixmaps/%s.xpm", (const char *)dir, name); | 34 | // file.sprintf("%spixmaps/%s.xpm", (const char *)dir, name); |
37 | #ifdef KDEVER | 35 | #ifdef KDEVER |
38 | KStandardDirs dirs; | 36 | KStandardDirs dirs; |
39 | QString file; | 37 | QString file; |
40 | 38 | ||
41 | if (index>=0) { | 39 | if (index>=0) { |
42 | //kdDebug() << "Here"; | 40 | //kdDebug() << "Here"; |
43 | QString sindex; | 41 | QString sindex; |
44 | sindex.setNum(index); | 42 | sindex.setNum(index); |
45 | // kdDebug() << "kbill/pixmaps/" + QString::fromLocal8Bit(name) + "_" + sindex + ".xpm"; | 43 | // kdDebug() << "kbill/pixmaps/" + QString::fromLocal8Bit(name) + "_" + sindex + ".xpm"; |
46 | file = dirs.findResource("data","kbill/pixmaps/" + QString::fromLocal8Bit(name) + "_" + sindex + ".xpm"); | 44 | file = dirs.findResource("data","kbill/pixmaps/" + QString::fromLocal8Bit(name) + "_" + sindex + ".xpm"); |
47 | } else { | 45 | } else { |
48 | file = dirs.findResource("data","kbill/pixmaps/" + QString::fromLocal8Bit(name) + ".xpm"); | 46 | file = dirs.findResource("data","kbill/pixmaps/" + QString::fromLocal8Bit(name) + ".xpm"); |
49 | } | 47 | } |
50 | kdDebug() << file << std::endl; | 48 | kdDebug() << file << std::endl; |
51 | pix = new QPixmap(); | 49 | pix = new QPixmap(); |
52 | if (pix->load(file) == FALSE) | 50 | if (pix->load(file) == FALSE) |
53 | std::cerr << "cannot open " << file << std::endl; | 51 | std::cerr << "cannot open " << file << std::endl; |
54 | width = pix->width(); | 52 | width = pix->width(); |
55 | height = pix->height(); | 53 | height = pix->height(); |
56 | #endif | 54 | #endif |
57 | QString sindex; | 55 | QString sindex; |
58 | pix = new QPixmap(); | 56 | pix = new QPixmap(); |
59 | sindex.setNum(index); | 57 | sindex.setNum(index); |
60 | if (index>=0) | 58 | if (index>=0) |
61 | pix->load(Resource::findPixmap("kbill/pixmaps/" + QString::fromLocal8Bit(name) +"_"+ sindex)); | 59 | pix->load(Resource::findPixmap("kbill/pixmaps/" + QString::fromLocal8Bit(name) +"_"+ sindex)); |
62 | else | 60 | else |
63 | pix->load(Resource::findPixmap("kbill/pixmaps/" + QString::fromLocal8Bit(name))); | 61 | pix->load(Resource::findPixmap("kbill/pixmaps/" + QString::fromLocal8Bit(name))); |
64 | 62 | ||
65 | width = pix->width(); | 63 | width = pix->width(); |
66 | height = pix->height(); | 64 | height = pix->height(); |
67 | 65 | ||
68 | } | 66 | } |
69 | 67 | ||
70 | QPixmap* Picture::getPixmap() { | 68 | QPixmap* Picture::getPixmap() { |
71 | return pix; | 69 | return pix; |
72 | } | 70 | } |
diff --git a/noncore/games/kbill/UI.cpp b/noncore/games/kbill/UI.cpp index 2afaf9b..611cebf 100644 --- a/noncore/games/kbill/UI.cpp +++ b/noncore/games/kbill/UI.cpp | |||
@@ -1,175 +1,172 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | UI.cc - description | 2 | UI.cc - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Thu Dec 30 1999 | 4 | begin : Thu Dec 30 1999 |
5 | copyright : (C) 1999 by Jurrien Loonstra | 5 | copyright : (C) 1999 by Jurrien Loonstra |
6 | email : j.h.loonstra@st.hanze.nl | 6 | email : j.h.loonstra@st.hanze.nl |
7 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | 8 | ||
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * | 11 | * This program is free software; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation; either version 2 of the License, or * | 13 | * the Free Software Foundation; either version 2 of the License, or * |
14 | * (at your option) any later version. * | 14 | * (at your option) any later version. * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | #include "kbill.h" | ||
18 | #include "objects.h" | 17 | #include "objects.h" |
19 | #include "Strings.h" | 18 | #include "Strings.h" |
20 | #ifdef KDEVER | 19 | #ifdef KDEVER |
21 | #include <kapplication.h> | 20 | #include <kapplication.h> |
22 | #endif | 21 | #endif |
23 | #include <qpixmap.h> | ||
24 | #include <qmessagebox.h> | 22 | #include <qmessagebox.h> |
25 | #include <qnamespace.h> | ||
26 | 23 | ||
27 | #include "inputbox.h" | 24 | #include "inputbox.h" |
28 | 25 | ||
29 | /**************************/ | 26 | /**************************/ |
30 | /* Timer control routines */ | 27 | /* Timer control routines */ |
31 | /**************************/ | 28 | /**************************/ |
32 | 29 | ||
33 | UI::~UI() { | 30 | UI::~UI() { |
34 | paint.end(); | 31 | paint.end(); |
35 | delete pix; | 32 | delete pix; |
36 | } | 33 | } |
37 | 34 | ||
38 | void UI::restart_timer() { | 35 | void UI::restart_timer() { |
39 | field->startTimer(); | 36 | field->startTimer(); |
40 | } | 37 | } |
41 | 38 | ||
42 | void UI::kill_timer() { | 39 | void UI::kill_timer() { |
43 | field->stopTimer(); | 40 | field->stopTimer(); |
44 | } | 41 | } |
45 | 42 | ||
46 | /*******************/ | 43 | /*******************/ |
47 | /* Window routines */ | 44 | /* Window routines */ |
48 | /*******************/ | 45 | /*******************/ |
49 | 46 | ||
50 | void UI::initialize(int *argc, char **argv) { | 47 | void UI::initialize(int *argc, char **argv) { |
51 | #ifdef KDEVER | 48 | #ifdef KDEVER |
52 | app = new KApplication(*argc, argv, "kbill"); | 49 | app = new KApplication(*argc, argv, "kbill"); |
53 | #endif | 50 | #endif |
54 | app = new QPEApplication(*argc, argv); | 51 | app = new QPEApplication(*argc, argv); |
55 | } | 52 | } |
56 | 53 | ||
57 | void UI::graph_init() { | 54 | void UI::graph_init() { |
58 | pix = new QPixmap(Game::scrwidth, Game::scrheight); | 55 | pix = new QPixmap(Game::scrwidth, Game::scrheight); |
59 | paint.begin(pix, field); | 56 | paint.begin(pix, field); |
60 | paint.setPen(QPen(Qt::black, 3)); | 57 | paint.setPen(QPen(Qt::black, 3)); |
61 | } | 58 | } |
62 | 59 | ||
63 | void UI::make_mainwin() { | 60 | void UI::make_mainwin() { |
64 | main = new KBill(); | 61 | main = new KBill(); |
65 | app->showMainWidget(main,true); | 62 | app->showMainWidget(main,true); |
66 | main->showMaximized(); | 63 | main->showMaximized(); |
67 | field = main->getField(); | 64 | field = main->getField(); |
68 | } | 65 | } |
69 | 66 | ||
70 | void UI::popup_dialog (int dialog) { | 67 | void UI::popup_dialog (int dialog) { |
71 | kill_timer(); | 68 | kill_timer(); |
72 | switch (dialog) { | 69 | switch (dialog) { |
73 | case Game::ENDGAME: | 70 | case Game::ENDGAME: |
74 | QMessageBox::message(("Endgame"), QT_TR_NOOP(endgamestr)); | 71 | QMessageBox::message(("Endgame"), QT_TR_NOOP(endgamestr)); |
75 | break; | 72 | break; |
76 | case Game::HIGHSCORE: | 73 | case Game::HIGHSCORE: |
77 | //QMessageBox::message(("HighScore"), highscorestr); | 74 | //QMessageBox::message(("HighScore"), highscorestr); |
78 | break; | 75 | break; |
79 | case Game::ENTERNAME: { | 76 | case Game::ENTERNAME: { |
80 | InputBox b(main, 0, ("Enter Name"), QT_TR_NOOP(enternamestr)); | 77 | InputBox b(main, 0, ("Enter Name"), QT_TR_NOOP(enternamestr)); |
81 | bool state = b.exec() == 2; | 78 | bool state = b.exec() == 2; |
82 | char str[20], *nl; | 79 | char str[20], *nl; |
83 | strcpy(str, b.getText()); | 80 | strcpy(str, b.getText()); |
84 | if (!str[0] || state) | 81 | if (!str[0] || state) |
85 | strcpy(str, "Anonymous"); | 82 | strcpy(str, "Anonymous"); |
86 | else if ((nl = strchr(str, '\n'))) | 83 | else if ((nl = strchr(str, '\n'))) |
87 | *nl = '\0'; | 84 | *nl = '\0'; |
88 | if (strlen(str) > 20) | 85 | if (strlen(str) > 20) |
89 | str[20] = 0; /* truncate string if too long */ | 86 | str[20] = 0; /* truncate string if too long */ |
90 | // scores.recalc(str); | 87 | // scores.recalc(str); |
91 | } | 88 | } |
92 | break; | 89 | break; |
93 | case Game::SCORE: | 90 | case Game::SCORE: |
94 | QMessageBox::message(("Score"), scorestr); | 91 | QMessageBox::message(("Score"), scorestr); |
95 | break; | 92 | break; |
96 | } | 93 | } |
97 | restart_timer(); | 94 | restart_timer(); |
98 | } | 95 | } |
99 | 96 | ||
100 | /*********************/ | 97 | /*********************/ |
101 | /* Graphics routines */ | 98 | /* Graphics routines */ |
102 | /*********************/ | 99 | /*********************/ |
103 | 100 | ||
104 | void UI::set_cursor(int cursor) { | 101 | void UI::set_cursor(int cursor) { |
105 | QCursor *cur; | 102 | QCursor *cur; |
106 | switch (cursor) { | 103 | switch (cursor) { |
107 | case Game::BUCKETC: | 104 | case Game::BUCKETC: |
108 | cur = bucket.cursor.cursor; | 105 | cur = bucket.cursor.cursor; |
109 | break; | 106 | break; |
110 | case Game::DOWNC: | 107 | case Game::DOWNC: |
111 | cur = downcursor.cursor; | 108 | cur = downcursor.cursor; |
112 | break; | 109 | break; |
113 | case Game::DEFAULTC: | 110 | case Game::DEFAULTC: |
114 | cur = defaultcursor.cursor; | 111 | cur = defaultcursor.cursor; |
115 | break; | 112 | break; |
116 | default: | 113 | default: |
117 | cur = OS.cursor[cursor].cursor; | 114 | cur = OS.cursor[cursor].cursor; |
118 | } | 115 | } |
119 | field->setCursor(*cur); | 116 | field->setCursor(*cur); |
120 | } | 117 | } |
121 | 118 | ||
122 | void UI::load_cursors() { | 119 | void UI::load_cursors() { |
123 | defaultcursor.load("hand_up", MCursor::SEP_MASK); | 120 | defaultcursor.load("hand_up", MCursor::SEP_MASK); |
124 | field->setCursor(*defaultcursor.cursor); | 121 | field->setCursor(*defaultcursor.cursor); |
125 | downcursor.load("hand_down", MCursor::SEP_MASK); | 122 | downcursor.load("hand_down", MCursor::SEP_MASK); |
126 | } | 123 | } |
127 | 124 | ||
128 | void UI::clear() { | 125 | void UI::clear() { |
129 | paint.eraseRect(0, 0, field->width(), field->height()); | 126 | paint.eraseRect(0, 0, field->width(), field->height()); |
130 | } | 127 | } |
131 | 128 | ||
132 | void UI::refresh() { | 129 | void UI::refresh() { |
133 | paint.flush(); | 130 | paint.flush(); |
134 | field->setPixmap(pix); | 131 | field->setPixmap(pix); |
135 | field->repaint(FALSE); | 132 | field->repaint(FALSE); |
136 | } | 133 | } |
137 | 134 | ||
138 | void UI::draw (Picture pict, int x, int y) { | 135 | void UI::draw (Picture pict, int x, int y) { |
139 | paint.drawPixmap(x, y, *pict.pix); | 136 | paint.drawPixmap(x, y, *pict.pix); |
140 | } | 137 | } |
141 | 138 | ||
142 | void UI::draw_centered (Picture pict) { | 139 | void UI::draw_centered (Picture pict) { |
143 | draw(pict, (field->width() - pict.width) / 2, (field->height() - pict.height) / 2); | 140 | draw(pict, (field->width() - pict.width) / 2, (field->height() - pict.height) / 2); |
144 | } | 141 | } |
145 | 142 | ||
146 | void UI::draw_line(int x1, int y1, int x2, int y2) { | 143 | void UI::draw_line(int x1, int y1, int x2, int y2) { |
147 | paint.drawLine(x1, y1, x2, y2); | 144 | paint.drawLine(x1, y1, x2, y2); |
148 | 145 | ||
149 | } | 146 | } |
150 | 147 | ||
151 | void UI::draw_str(char *str, int x, int y) { | 148 | void UI::draw_str(char *str, int x, int y) { |
152 | paint.drawText(x, y, str); | 149 | paint.drawText(x, y, str); |
153 | } | 150 | } |
154 | 151 | ||
155 | 152 | ||
156 | /******************/ | 153 | /******************/ |
157 | /* Other routines */ | 154 | /* Other routines */ |
158 | /******************/ | 155 | /******************/ |
159 | 156 | ||
160 | void UI::set_pausebutton (int action) { | 157 | void UI::set_pausebutton (int action) { |
161 | main->file->setItemEnabled(main->pauseid, action); | 158 | main->file->setItemEnabled(main->pauseid, action); |
162 | } | 159 | } |
163 | 160 | ||
164 | 161 | ||
165 | int UI::MainLoop() { | 162 | int UI::MainLoop() { |
166 | return app->exec(); | 163 | return app->exec(); |
167 | } | 164 | } |
168 | 165 | ||
169 | void UI::update_hsbox(char *str) { | 166 | void UI::update_hsbox(char *str) { |
170 | highscorestr = str; | 167 | highscorestr = str; |
171 | } | 168 | } |
172 | 169 | ||
173 | void UI::update_scorebox(int level, int score) { | 170 | void UI::update_scorebox(int level, int score) { |
174 | scorestr.sprintf ("%s %d:\n%s: %d", QT_TR_NOOP("After Level"), level, QT_TR_NOOP("Your score"), score); | 171 | scorestr.sprintf ("%s %d:\n%s: %d", QT_TR_NOOP("After Level"), level, QT_TR_NOOP("Your score"), score); |
175 | } | 172 | } |
diff --git a/noncore/games/kbill/field.cpp b/noncore/games/kbill/field.cpp index a1b3560..a974ab2 100644 --- a/noncore/games/kbill/field.cpp +++ b/noncore/games/kbill/field.cpp | |||
@@ -1,84 +1,83 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | field.cpp - description | 2 | field.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Thu Dec 30 1999 | 4 | begin : Thu Dec 30 1999 |
5 | copyright : (C) 1999 by Jurrien Loonstra | 5 | copyright : (C) 1999 by Jurrien Loonstra |
6 | email : j.h.loonstra@st.hanze.nl | 6 | email : j.h.loonstra@st.hanze.nl |
7 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | 8 | ||
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * | 11 | * This program is free software; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation; either version 2 of the License, or * | 13 | * the Free Software Foundation; either version 2 of the License, or * |
14 | * (at your option) any later version. * | 14 | * (at your option) any later version. * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | 17 | ||
18 | #include <qpainter.h> | ||
19 | 18 | ||
20 | #include "objects.h" | 19 | #include "objects.h" |
21 | 20 | ||
22 | #include "field.h" | 21 | #include "field.h" |
23 | 22 | ||
24 | Field::Field(QWidget *parent, const char *name ) : QWidget(parent,name) { | 23 | Field::Field(QWidget *parent, const char *name ) : QWidget(parent,name) { |
25 | setFixedSize(game.scrwidth, game.scrheight); | 24 | setFixedSize(game.scrwidth, game.scrheight); |
26 | setBackgroundColor(white); | 25 | setBackgroundColor(white); |
27 | timer = new QTimer(this); | 26 | timer = new QTimer(this); |
28 | 27 | ||
29 | playing = false; | 28 | playing = false; |
30 | 29 | ||
31 | connect(timer, SIGNAL(timeout()), SLOT(Timer())); | 30 | connect(timer, SIGNAL(timeout()), SLOT(Timer())); |
32 | } | 31 | } |
33 | 32 | ||
34 | Field::~Field(){ | 33 | Field::~Field(){ |
35 | delete timer; | 34 | delete timer; |
36 | } | 35 | } |
37 | 36 | ||
38 | void Field::setPixmap(QPixmap *pix) { | 37 | void Field::setPixmap(QPixmap *pix) { |
39 | this->pix = pix; | 38 | this->pix = pix; |
40 | } | 39 | } |
41 | 40 | ||
42 | // -------------------------------------------------------- | 41 | // -------------------------------------------------------- |
43 | 42 | ||
44 | void Field::mousePressEvent(QMouseEvent *e){ | 43 | void Field::mousePressEvent(QMouseEvent *e){ |
45 | game.button_press(e->x(), e->y()); | 44 | game.button_press(e->x(), e->y()); |
46 | } | 45 | } |
47 | 46 | ||
48 | void Field::mouseReleaseEvent(QMouseEvent *e){ | 47 | void Field::mouseReleaseEvent(QMouseEvent *e){ |
49 | game.button_release(e->x(), e->y()); | 48 | game.button_release(e->x(), e->y()); |
50 | } | 49 | } |
51 | 50 | ||
52 | void Field::enterEvent(QEvent *) { | 51 | void Field::enterEvent(QEvent *) { |
53 | if (playing && !timer->isActive()) { | 52 | if (playing && !timer->isActive()) { |
54 | playing = true; | 53 | playing = true; |
55 | timer->start(250, FALSE); | 54 | timer->start(250, FALSE); |
56 | } | 55 | } |
57 | } | 56 | } |
58 | 57 | ||
59 | void Field::leaveEvent(QEvent *) { | 58 | void Field::leaveEvent(QEvent *) { |
60 | if (timer->isActive() && playing) { | 59 | if (timer->isActive() && playing) { |
61 | playing = true; | 60 | playing = true; |
62 | timer->stop(); | 61 | timer->stop(); |
63 | } | 62 | } |
64 | } | 63 | } |
65 | 64 | ||
66 | void Field::stopTimer() { | 65 | void Field::stopTimer() { |
67 | playing = false; | 66 | playing = false; |
68 | if (timer->isActive()) | 67 | if (timer->isActive()) |
69 | timer->stop(); | 68 | timer->stop(); |
70 | } | 69 | } |
71 | 70 | ||
72 | void Field::startTimer() { | 71 | void Field::startTimer() { |
73 | playing = true; | 72 | playing = true; |
74 | if (!timer->isActive()) | 73 | if (!timer->isActive()) |
75 | timer->start(250, FALSE); | 74 | timer->start(250, FALSE); |
76 | } | 75 | } |
77 | 76 | ||
78 | void Field::Timer(){ | 77 | void Field::Timer(){ |
79 | game.update(); | 78 | game.update(); |
80 | } | 79 | } |
81 | 80 | ||
82 | void Field::paintEvent(QPaintEvent *) { | 81 | void Field::paintEvent(QPaintEvent *) { |
83 | bitBlt(this, 0, 0, pix); | 82 | bitBlt(this, 0, 0, pix); |
84 | } \ No newline at end of file | 83 | } \ No newline at end of file |
diff --git a/noncore/games/kbill/inputbox.cpp b/noncore/games/kbill/inputbox.cpp index b191ea8..5087fbb 100644 --- a/noncore/games/kbill/inputbox.cpp +++ b/noncore/games/kbill/inputbox.cpp | |||
@@ -1,51 +1,50 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | inputbox.cpp - description | 2 | inputbox.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Sat Jan 1 2000 | 4 | begin : Sat Jan 1 2000 |
5 | copyright : (C) 2000 by Jurrien Loonstra | 5 | copyright : (C) 2000 by Jurrien Loonstra |
6 | email : j.h.loonstra@st.hanze.nl | 6 | email : j.h.loonstra@st.hanze.nl |
7 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | 8 | ||
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * | 11 | * This program is free software; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation; either version 2 of the License, or * | 13 | * the Free Software Foundation; either version 2 of the License, or * |
14 | * (at your option) any later version. * | 14 | * (at your option) any later version. * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | 17 | ||
18 | #include "inputbox.h" | 18 | #include "inputbox.h" |
19 | #include <qdialog.h> | ||
20 | InputBox::InputBox(QWidget *parent, const char *name, const char *caption, const char *text) : QDialog(parent, name, TRUE) { | 19 | InputBox::InputBox(QWidget *parent, const char *name, const char *caption, const char *text) : QDialog(parent, name, TRUE) { |
21 | // setCaption(caption); | 20 | // setCaption(caption); |
22 | // | 21 | // |
23 | // question = new QLabel(this); | 22 | // question = new QLabel(this); |
24 | // question->setText(text); | 23 | // question->setText(text); |
25 | // question->setGeometry(10, 10, 240, 50); | 24 | // question->setGeometry(10, 10, 240, 50); |
26 | // | 25 | // |
27 | // input = new QLineEdit(this); | 26 | // input = new QLineEdit(this); |
28 | // input->setGeometry(10, 60, 240, 30); | 27 | // input->setGeometry(10, 60, 240, 30); |
29 | // input->setFocus(); | 28 | // input->setFocus(); |
30 | // input->setMaxLength(19); | 29 | // input->setMaxLength(19); |
31 | // | 30 | // |
32 | // ok = new QPushButton( "Ok", this ); | 31 | // ok = new QPushButton( "Ok", this ); |
33 | // ok->setGeometry(10, 100, 100,30 ); | 32 | // ok->setGeometry(10, 100, 100,30 ); |
34 | // ok->setDefault(TRUE); | 33 | // ok->setDefault(TRUE); |
35 | // connect( ok, SIGNAL(clicked()), SLOT(accept()) ); | 34 | // connect( ok, SIGNAL(clicked()), SLOT(accept()) ); |
36 | // | 35 | // |
37 | // cancel = new QPushButton( "Cancel", this ); | 36 | // cancel = new QPushButton( "Cancel", this ); |
38 | // cancel->setGeometry(150, 100, 100,30 ); | 37 | // cancel->setGeometry(150, 100, 100,30 ); |
39 | // connect( cancel, SIGNAL(clicked()), SLOT(reject()) ); | 38 | // connect( cancel, SIGNAL(clicked()), SLOT(reject()) ); |
40 | } | 39 | } |
41 | 40 | ||
42 | InputBox::~InputBox(){ | 41 | InputBox::~InputBox(){ |
43 | delete ok; | 42 | delete ok; |
44 | delete cancel; | 43 | delete cancel; |
45 | delete question; | 44 | delete question; |
46 | delete input; | 45 | delete input; |
47 | } | 46 | } |
48 | 47 | ||
49 | QString InputBox::getText() const{ | 48 | QString InputBox::getText() const{ |
50 | return input->text(); | 49 | return input->text(); |
51 | } | 50 | } |
diff --git a/noncore/games/kbill/kbill.cpp b/noncore/games/kbill/kbill.cpp index 18a6875..74d7c75 100644 --- a/noncore/games/kbill/kbill.cpp +++ b/noncore/games/kbill/kbill.cpp | |||
@@ -1,132 +1,128 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | kbill.cpp - description | 2 | kbill.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Thu Dec 30 16:55:55 CET 1999 | 4 | begin : Thu Dec 30 16:55:55 CET 1999 |
5 | copyright : (C) 1999 by Jurrien Loonstra | 5 | copyright : (C) 1999 by Jurrien Loonstra |
6 | email : j.h.loonstra@st.hanze.nl | 6 | email : j.h.loonstra@st.hanze.nl |
7 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | 8 | ||
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * | 11 | * This program is free software; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation; either version 2 of the License, or * | 13 | * the Free Software Foundation; either version 2 of the License, or * |
14 | * (at your option) any later version. * | 14 | * (at your option) any later version. * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | 17 | ||
18 | #include <qmessagebox.h> | 18 | #include <qmessagebox.h> |
19 | #include <qmultilinedit.h> | ||
20 | #include <qmenubar.h> | 19 | #include <qmenubar.h> |
21 | #include <qtextbrowser.h> | 20 | #include <qtextbrowser.h> |
22 | #include <qfont.h> | ||
23 | #include <qwidget.h> | ||
24 | #include "kbill.h" | 21 | #include "kbill.h" |
25 | #include "inputbox.h" | ||
26 | #include "helpdialog.h" | 22 | #include "helpdialog.h" |
27 | #include "objects.h" | 23 | #include "objects.h" |
28 | #include "Strings.h" | 24 | #include "Strings.h" |
29 | 25 | ||
30 | KBill::KBill() : QMainWindow() { | 26 | KBill::KBill() : QMainWindow() { |
31 | setCaption(tr("kBill")); | 27 | setCaption(tr("kBill")); |
32 | file = new QPopupMenu(); | 28 | file = new QPopupMenu(); |
33 | file->insertItem(tr("New game"), this, SLOT(NewGame())); | 29 | file->insertItem(tr("New game"), this, SLOT(NewGame())); |
34 | pauseid = file->insertItem(tr("Pause game"), this, SLOT(Pause())); | 30 | pauseid = file->insertItem(tr("Pause game"), this, SLOT(Pause())); |
35 | //these are dissabled until I fix them | 31 | //these are dissabled until I fix them |
36 | //file->insertItem(tr("Warp to level..."), this, SLOT(WarpTo())); | 32 | //file->insertItem(tr("Warp to level..."), this, SLOT(WarpTo())); |
37 | //file->insertItem(tr("View high scores"), this, SLOT(ViewHighScores())); | 33 | //file->insertItem(tr("View high scores"), this, SLOT(ViewHighScores())); |
38 | 34 | ||
39 | 35 | ||
40 | help = new QPopupMenu(); | 36 | help = new QPopupMenu(); |
41 | help->insertItem(tr("Story of kBill"), this, SLOT(Story())); | 37 | help->insertItem(tr("Story of kBill"), this, SLOT(Story())); |
42 | help->insertItem(tr("Rules"), this, SLOT(Rules())); | 38 | help->insertItem(tr("Rules"), this, SLOT(Rules())); |
43 | 39 | ||
44 | 40 | ||
45 | menu = new QMenuBar(this); | 41 | menu = new QMenuBar(this); |
46 | menu->insertItem(tr("&File"), file); | 42 | menu->insertItem(tr("&File"), file); |
47 | menu->insertSeparator(); | 43 | menu->insertSeparator(); |
48 | menu->insertItem(tr("&Help"), help); | 44 | menu->insertItem(tr("&Help"), help); |
49 | 45 | ||
50 | field = new Field(this); | 46 | field = new Field(this); |
51 | //setView(field); | 47 | //setView(field); |
52 | //setMainWidget(field); | 48 | //setMainWidget(field); |
53 | //setMenu(menu); | 49 | //setMenu(menu); |
54 | } | 50 | } |
55 | 51 | ||
56 | KBill::~KBill() { | 52 | KBill::~KBill() { |
57 | } | 53 | } |
58 | 54 | ||
59 | Field* KBill::getField() { | 55 | Field* KBill::getField() { |
60 | return field; | 56 | return field; |
61 | } | 57 | } |
62 | 58 | ||
63 | // ----------------------------------------------------------------------- | 59 | // ----------------------------------------------------------------------- |
64 | 60 | ||
65 | void KBill::Quit() { | 61 | void KBill::Quit() { |
66 | field->stopTimer(); | 62 | field->stopTimer(); |
67 | qApp->quit(); | 63 | qApp->quit(); |
68 | 64 | ||
69 | } | 65 | } |
70 | 66 | ||
71 | void KBill::About(){ | 67 | void KBill::About(){ |
72 | // field->stopTimer(); | 68 | // field->stopTimer(); |
73 | // AboutBox about(this); | 69 | // AboutBox about(this); |
74 | // about.exec(); | 70 | // about.exec(); |
75 | // field->startTimer(); | 71 | // field->startTimer(); |
76 | } | 72 | } |
77 | 73 | ||
78 | void KBill::NewGame() { | 74 | void KBill::NewGame() { |
79 | field->stopTimer(); | 75 | field->stopTimer(); |
80 | // if (KMsgBox::yesNo(this, i18n("New Game"), i18n(newgamestr), KMsgBox::QUESTION) == 1) | 76 | // if (KMsgBox::yesNo(this, i18n("New Game"), i18n(newgamestr), KMsgBox::QUESTION) == 1) |
81 | game.start(1); | 77 | game.start(1); |
82 | // else | 78 | // else |
83 | field->startTimer(); | 79 | field->startTimer(); |
84 | } | 80 | } |
85 | 81 | ||
86 | void KBill::Pause() { | 82 | void KBill::Pause() { |
87 | field->stopTimer(); | 83 | field->stopTimer(); |
88 | QMessageBox::message(tr("Pause Game"), tr(pausestr), 0); | 84 | QMessageBox::message(tr("Pause Game"), tr(pausestr), 0); |
89 | field->startTimer(); | 85 | field->startTimer(); |
90 | } | 86 | } |
91 | 87 | ||
92 | void KBill::WarpTo() { | 88 | void KBill::WarpTo() { |
93 | /* field->stopTimer(); | 89 | /* field->stopTimer(); |
94 | InputBox b(this, 0, "Warp To Level", tr(warpstr)); | 90 | InputBox b(this, 0, "Warp To Level", tr(warpstr)); |
95 | bool status = b.exec() == 1; | 91 | bool status = b.exec() == 1; |
96 | field->startTimer(); | 92 | field->startTimer(); |
97 | if (status) { | 93 | if (status) { |
98 | bool ok; | 94 | bool ok; |
99 | int level = b.getText().toUInt(&ok); | 95 | int level = b.getText().toUInt(&ok); |
100 | if (ok) { | 96 | if (ok) { |
101 | field->startTimer(); | 97 | field->startTimer(); |
102 | game.warp_to_level(level); | 98 | game.warp_to_level(level); |
103 | return; | 99 | return; |
104 | } | 100 | } |
105 | }*/ | 101 | }*/ |
106 | } | 102 | } |
107 | 103 | ||
108 | void KBill::ViewHighScores() { | 104 | void KBill::ViewHighScores() { |
109 | //ui.popup_dialog(Game::HIGHSCORE); | 105 | //ui.popup_dialog(Game::HIGHSCORE); |
110 | } | 106 | } |
111 | 107 | ||
112 | void KBill::Story() { | 108 | void KBill::Story() { |
113 | field->stopTimer(); | 109 | field->stopTimer(); |
114 | HelpDialog *stryDialog = new HelpDialog(this,"helpdialog",1); | 110 | HelpDialog *stryDialog = new HelpDialog(this,"helpdialog",1); |
115 | QString stryString = tr("<b>The Story</b><p>Yet again, the fate of the world rests in your hands! An evil computer hacker, known only by his handle 'Bill', has created the ultimate computer virus. A virus so powerful that it has the power to transmute an ordinary computer into a toaster oven. (oooh!) 'Bill' has cloned himself into a billion-jillion micro-Bills. Their sole purpose is to deliver the nefarious virus, which has been cleverly disguised as a popular operating system. As System Administrator and Exterminator, your job is to keep Bill from succeeding at his task."); | 111 | QString stryString = tr("<b>The Story</b><p>Yet again, the fate of the world rests in your hands! An evil computer hacker, known only by his handle 'Bill', has created the ultimate computer virus. A virus so powerful that it has the power to transmute an ordinary computer into a toaster oven. (oooh!) 'Bill' has cloned himself into a billion-jillion micro-Bills. Their sole purpose is to deliver the nefarious virus, which has been cleverly disguised as a popular operating system. As System Administrator and Exterminator, your job is to keep Bill from succeeding at his task."); |
116 | stryDialog->setCaption(tr("The story of KBill")); | 112 | stryDialog->setCaption(tr("The story of KBill")); |
117 | stryDialog->TextBrowser1->setText(stryString); | 113 | stryDialog->TextBrowser1->setText(stryString); |
118 | stryDialog->resize(200,200); | 114 | stryDialog->resize(200,200); |
119 | stryDialog->show(); | 115 | stryDialog->show(); |
120 | field->startTimer(); | 116 | field->startTimer(); |
121 | } | 117 | } |
122 | 118 | ||
123 | void KBill::Rules() { | 119 | void KBill::Rules() { |
124 | field->stopTimer(); | 120 | field->stopTimer(); |
125 | HelpDialog *rulesDialog = new HelpDialog(this,"helpdialog",1); | 121 | HelpDialog *rulesDialog = new HelpDialog(this,"helpdialog",1); |
126 | rulesDialog->setCaption(tr("The rules of KBill")); | 122 | rulesDialog->setCaption(tr("The rules of KBill")); |
127 | QString rulesStr = tr("<b>The Rules</b><p>kBill has been painstakingly designed and researched in order to make it as easy to use for the whole family as it is for little Sally. Years - nay - days of beta testing and consulting with the cheapest of human interface designers have resulted in a game that is easy to use, yet nothing at all like a Macintosh.<p><UL><LI>Whack the Bills (click)</LI><LI>Restart the computer (click)</LI><LI>Pick up stolen OSes & return (drag) them to their respective computers</LI><LI>Drag the bucket to extinguish sparks</LI><LI>Scoring is based on total uptime, with bonuses for killing Bills.</LI></UL><P>As for the rest, you can probably work it out for yourself. We did, so it can't be too hard"); | 123 | QString rulesStr = tr("<b>The Rules</b><p>kBill has been painstakingly designed and researched in order to make it as easy to use for the whole family as it is for little Sally. Years - nay - days of beta testing and consulting with the cheapest of human interface designers have resulted in a game that is easy to use, yet nothing at all like a Macintosh.<p><UL><LI>Whack the Bills (click)</LI><LI>Restart the computer (click)</LI><LI>Pick up stolen OSes & return (drag) them to their respective computers</LI><LI>Drag the bucket to extinguish sparks</LI><LI>Scoring is based on total uptime, with bonuses for killing Bills.</LI></UL><P>As for the rest, you can probably work it out for yourself. We did, so it can't be too hard"); |
128 | rulesDialog->TextBrowser1->setText(rulesStr); | 124 | rulesDialog->TextBrowser1->setText(rulesStr); |
129 | rulesDialog->resize(200,200); | 125 | rulesDialog->resize(200,200); |
130 | rulesDialog->show(); | 126 | rulesDialog->show(); |
131 | field->startTimer(); | 127 | field->startTimer(); |
132 | } | 128 | } |
diff --git a/noncore/games/kcheckers/kcheckers.cpp b/noncore/games/kcheckers/kcheckers.cpp index 2eb37e5..a27dd18 100644 --- a/noncore/games/kcheckers/kcheckers.cpp +++ b/noncore/games/kcheckers/kcheckers.cpp | |||
@@ -1,515 +1,514 @@ | |||
1 | 1 | ||
2 | #include <qimage.h> | 2 | #include <qimage.h> |
3 | #include <qframe.h> | ||
4 | #include <qlayout.h> | 3 | #include <qlayout.h> |
5 | #include <qmenubar.h> | 4 | #include <qmenubar.h> |
6 | #include <qtoolbar.h> | 5 | #include <qtoolbar.h> |
7 | #include <qpe/config.h> | 6 | #include <qpe/config.h> |
8 | #include <qwhatsthis.h> | 7 | #include <qwhatsthis.h> |
9 | #include <qtoolbutton.h> | 8 | #include <qtoolbutton.h> |
10 | #include <qmessagebox.h> | 9 | #include <qmessagebox.h> |
11 | #include <qapplication.h> | 10 | #include <qapplication.h> |
12 | 11 | ||
13 | #include "kcheckers.h" | 12 | #include "kcheckers.h" |
14 | #include "echeckers.h" | 13 | #include "echeckers.h" |
15 | #include "rcheckers.h" | 14 | #include "rcheckers.h" |
16 | 15 | ||
17 | #include "pics/logo.xpm" | 16 | #include "pics/logo.xpm" |
18 | #include "pics/undo.xpm" | 17 | #include "pics/undo.xpm" |
19 | #include "pics/exit.xpm" | 18 | #include "pics/exit.xpm" |
20 | #include "pics/help.xpm" | 19 | #include "pics/help.xpm" |
21 | #include "pics/wood1.xpm" | 20 | #include "pics/wood1.xpm" |
22 | #include "pics/wood2.xpm" | 21 | #include "pics/wood2.xpm" |
23 | #include "pics/wood3.xpm" | 22 | #include "pics/wood3.xpm" |
24 | #include "pics/green1.xpm" | 23 | #include "pics/green1.xpm" |
25 | #include "pics/green2.xpm" | 24 | #include "pics/green2.xpm" |
26 | #include "pics/green3.xpm" | 25 | #include "pics/green3.xpm" |
27 | #include "pics/marble1.xpm" | 26 | #include "pics/marble1.xpm" |
28 | #include "pics/marble2.xpm" | 27 | #include "pics/marble2.xpm" |
29 | #include "pics/marble3.xpm" | 28 | #include "pics/marble3.xpm" |
30 | #include "pics/biglogo.xpm" | 29 | #include "pics/biglogo.xpm" |
31 | #include "pics/man_black.xpm" | 30 | #include "pics/man_black.xpm" |
32 | #include "pics/man_white.xpm" | 31 | #include "pics/man_white.xpm" |
33 | #include "pics/king_black.xpm" | 32 | #include "pics/king_black.xpm" |
34 | #include "pics/king_white.xpm" | 33 | #include "pics/king_white.xpm" |
35 | #include "pics/contexthelp.xpm" | 34 | #include "pics/contexthelp.xpm" |
36 | 35 | ||
37 | 36 | ||
38 | QString KCheckers::enNumeration="1 2 3 4 5 6 7 8 9 1011121314151617181920212223242526272829303132"; | 37 | QString KCheckers::enNumeration="1 2 3 4 5 6 7 8 9 1011121314151617181920212223242526272829303132"; |
39 | QString KCheckers::ruNumeration="B8D8F8H8A7C7E7G7B6D6F6H6A5C5E5G5B4D4F4H4A3C3E3G3B2D2F2H2A1C1E1G1"; | 38 | QString KCheckers::ruNumeration="B8D8F8H8A7C7E7G7B6D6F6H6A5C5E5G5B4D4F4H4A3C3E3G3B2D2F2H2A1C1E1G1"; |
40 | 39 | ||
41 | const int KCheckers::t[]={6,7,8,9,11,12,13,14,17,18,19,20,22,23, | 40 | const int KCheckers::t[]={6,7,8,9,11,12,13,14,17,18,19,20,22,23, |
42 | 24,25,28,29,30,31,33,34,35,36,39,40,41,42,44,45,46,47}; | 41 | 24,25,28,29,30,31,33,34,35,36,39,40,41,42,44,45,46,47}; |
43 | 42 | ||
44 | 43 | ||
45 | KCheckers::KCheckers(QWidget *p, const char* n, WFlags ) | 44 | KCheckers::KCheckers(QWidget *p, const char* n, WFlags ) |
46 | :QMainWindow(p,n,WStyle_DialogBorder) | 45 | :QMainWindow(p,n,WStyle_DialogBorder) |
47 | { | 46 | { |
48 | setCaption(tr("KCheckers") ); | 47 | setCaption(tr("KCheckers") ); |
49 | setIcon(QPixmap(biglogo_xpm)); | 48 | setIcon(QPixmap(biglogo_xpm)); |
50 | 49 | ||
51 | setToolBarsMovable(false); | 50 | setToolBarsMovable(false); |
52 | 51 | ||
53 | // Make a menubar | 52 | // Make a menubar |
54 | 53 | ||
55 | gameMenu=new QPopupMenu; | 54 | gameMenu=new QPopupMenu; |
56 | CHECK_PTR(gameMenu); | 55 | CHECK_PTR(gameMenu); |
57 | 56 | ||
58 | gameMenu->insertItem(QPixmap(logo_xpm),tr("&New"),this,SLOT(newGame()),CTRL+Key_N); | 57 | gameMenu->insertItem(QPixmap(logo_xpm),tr("&New"),this,SLOT(newGame()),CTRL+Key_N); |
59 | gameMenu->insertSeparator(); | 58 | gameMenu->insertSeparator(); |
60 | undoID=gameMenu->insertItem(QPixmap(undo_xpm),tr("&Undo Move"),this,SLOT(undoMove()),CTRL+Key_Z); | 59 | undoID=gameMenu->insertItem(QPixmap(undo_xpm),tr("&Undo Move"),this,SLOT(undoMove()),CTRL+Key_Z); |
61 | gameMenu->insertSeparator(); | 60 | gameMenu->insertSeparator(); |
62 | gameMenu->insertItem(QPixmap(exit_xpm),tr("&Quit"),qApp,SLOT(closeAllWindows()),CTRL+Key_Q); | 61 | gameMenu->insertItem(QPixmap(exit_xpm),tr("&Quit"),qApp,SLOT(closeAllWindows()),CTRL+Key_Q); |
63 | 62 | ||
64 | skillMenu=new QPopupMenu; | 63 | skillMenu=new QPopupMenu; |
65 | CHECK_PTR(skillMenu); | 64 | CHECK_PTR(skillMenu); |
66 | 65 | ||
67 | skillMenu->insertItem(tr("&Beginner"),this,SLOT(setSkillBeginner()),CTRL+Key_1,BEGINNER); | 66 | skillMenu->insertItem(tr("&Beginner"),this,SLOT(setSkillBeginner()),CTRL+Key_1,BEGINNER); |
68 | skillMenu->insertItem(tr("&Novice"), this,SLOT(setSkillNovice()), CTRL+Key_2,NOVICE); | 67 | skillMenu->insertItem(tr("&Novice"), this,SLOT(setSkillNovice()), CTRL+Key_2,NOVICE); |
69 | skillMenu->insertItem(tr("&Average"), this,SLOT(setSkillAverage()), CTRL+Key_3,AVERAGE); | 68 | skillMenu->insertItem(tr("&Average"), this,SLOT(setSkillAverage()), CTRL+Key_3,AVERAGE); |
70 | skillMenu->insertItem(tr("&Good"), this,SLOT(setSkillGood()), CTRL+Key_4,GOOD); | 69 | skillMenu->insertItem(tr("&Good"), this,SLOT(setSkillGood()), CTRL+Key_4,GOOD); |
71 | skillMenu->insertItem(tr("&Expert"), this,SLOT(setSkillExpert()), CTRL+Key_5,EXPERT); | 70 | skillMenu->insertItem(tr("&Expert"), this,SLOT(setSkillExpert()), CTRL+Key_5,EXPERT); |
72 | skillMenu->insertItem(tr("&Master"), this,SLOT(setSkillMaster()), CTRL+Key_6,MASTER); | 71 | skillMenu->insertItem(tr("&Master"), this,SLOT(setSkillMaster()), CTRL+Key_6,MASTER); |
73 | 72 | ||
74 | optionsMenu=new QPopupMenu; | 73 | optionsMenu=new QPopupMenu; |
75 | CHECK_PTR(optionsMenu); | 74 | CHECK_PTR(optionsMenu); |
76 | 75 | ||
77 | numID=optionsMenu->insertItem(tr("&Show Numeration"),this,SLOT(showNumeration())); | 76 | numID=optionsMenu->insertItem(tr("&Show Numeration"),this,SLOT(showNumeration())); |
78 | optionsMenu->insertSeparator(); | 77 | optionsMenu->insertSeparator(); |
79 | optionsMenu->insertItem(tr("&English Rules"),this,SLOT(setRulesEnglish()),0,ENGLISH); | 78 | optionsMenu->insertItem(tr("&English Rules"),this,SLOT(setRulesEnglish()),0,ENGLISH); |
80 | optionsMenu->insertItem(tr("&Russian Rules"),this,SLOT(setRulesRussian()),0,RUSSIAN); | 79 | optionsMenu->insertItem(tr("&Russian Rules"),this,SLOT(setRulesRussian()),0,RUSSIAN); |
81 | optionsMenu->insertSeparator(); | 80 | optionsMenu->insertSeparator(); |
82 | optionsMenu->insertItem(tr("&Green Board"), this,SLOT(setPatternGreen()), 0,GREEN); | 81 | optionsMenu->insertItem(tr("&Green Board"), this,SLOT(setPatternGreen()), 0,GREEN); |
83 | optionsMenu->insertItem(tr("&Marble Board"),this,SLOT(setPatternMarble()),0,MARBLE); | 82 | optionsMenu->insertItem(tr("&Marble Board"),this,SLOT(setPatternMarble()),0,MARBLE); |
84 | optionsMenu->insertItem(tr("&Wooden Board"),this,SLOT(setPatternWooden()),0,WOODEN); | 83 | optionsMenu->insertItem(tr("&Wooden Board"),this,SLOT(setPatternWooden()),0,WOODEN); |
85 | 84 | ||
86 | QPopupMenu* helpMenu=new QPopupMenu; | 85 | QPopupMenu* helpMenu=new QPopupMenu; |
87 | CHECK_PTR(helpMenu); | 86 | CHECK_PTR(helpMenu); |
88 | 87 | ||
89 | helpMenu->insertItem(QPixmap(contexthelp_xpm),tr("What's This"),this,SLOT(whatsThis()),SHIFT+Key_F1); | 88 | helpMenu->insertItem(QPixmap(contexthelp_xpm),tr("What's This"),this,SLOT(whatsThis()),SHIFT+Key_F1); |
90 | helpMenu->insertItem(QPixmap(help_xpm),tr("&Rules of Play"),this,SLOT(help()),Key_F1); | 89 | helpMenu->insertItem(QPixmap(help_xpm),tr("&Rules of Play"),this,SLOT(help()),Key_F1); |
91 | helpMenu->insertSeparator(); | 90 | helpMenu->insertSeparator(); |
92 | helpMenu->insertItem(QPixmap(logo_xpm),tr("&About KCheckers"),this,SLOT(about())); | 91 | helpMenu->insertItem(QPixmap(logo_xpm),tr("&About KCheckers"),this,SLOT(about())); |
93 | helpMenu->insertItem(tr("About &Qt"),this,SLOT(aboutQt())); | 92 | helpMenu->insertItem(tr("About &Qt"),this,SLOT(aboutQt())); |
94 | 93 | ||
95 | QToolBar* menuToolBar=new QToolBar(this); | 94 | QToolBar* menuToolBar=new QToolBar(this); |
96 | CHECK_PTR(menuToolBar); | 95 | CHECK_PTR(menuToolBar); |
97 | QMenuBar* menuBar=new QMenuBar(menuToolBar); | 96 | QMenuBar* menuBar=new QMenuBar(menuToolBar); |
98 | CHECK_PTR(menuBar); | 97 | CHECK_PTR(menuBar); |
99 | 98 | ||
100 | menuBar->insertItem(tr("&Game"), gameMenu); | 99 | menuBar->insertItem(tr("&Game"), gameMenu); |
101 | menuBar->insertItem(tr("&Skill"), skillMenu); | 100 | menuBar->insertItem(tr("&Skill"), skillMenu); |
102 | menuBar->insertItem(tr("&Options"),optionsMenu); | 101 | menuBar->insertItem(tr("&Options"),optionsMenu); |
103 | menuBar->insertItem(tr("&Help"), helpMenu); | 102 | menuBar->insertItem(tr("&Help"), helpMenu); |
104 | 103 | ||
105 | // Restore a settings | 104 | // Restore a settings |
106 | 105 | ||
107 | readConfig(); | 106 | readConfig(); |
108 | 107 | ||
109 | skillMenu->setItemChecked(skill,true); | 108 | skillMenu->setItemChecked(skill,true); |
110 | optionsMenu->setItemChecked(rules,true); | 109 | optionsMenu->setItemChecked(rules,true); |
111 | optionsMenu->setItemChecked(numID,false); | 110 | optionsMenu->setItemChecked(numID,false); |
112 | 111 | ||
113 | // Make a toolbar | 112 | // Make a toolbar |
114 | 113 | ||
115 | QToolBar* emptyToolBar=new QToolBar(this); | 114 | QToolBar* emptyToolBar=new QToolBar(this); |
116 | emptyToolBar->setHorizontalStretchable(true); | 115 | emptyToolBar->setHorizontalStretchable(true); |
117 | 116 | ||
118 | QToolBar* toolBar=new QToolBar(this); | 117 | QToolBar* toolBar=new QToolBar(this); |
119 | CHECK_PTR(toolBar); | 118 | CHECK_PTR(toolBar); |
120 | 119 | ||
121 | QSize buttonSize(24,24); | 120 | QSize buttonSize(24,24); |
122 | 121 | ||
123 | QToolButton* gameButton=new QToolButton(QPixmap(logo_xpm),tr(" New Game ") ,"",this,SLOT(newGame()),toolBar); | 122 | QToolButton* gameButton=new QToolButton(QPixmap(logo_xpm),tr(" New Game ") ,"",this,SLOT(newGame()),toolBar); |
124 | CHECK_PTR(gameButton); | 123 | CHECK_PTR(gameButton); |
125 | gameButton->setMinimumSize(buttonSize); | 124 | gameButton->setMinimumSize(buttonSize); |
126 | 125 | ||
127 | undoButton=new QToolButton(QPixmap(undo_xpm),tr(" Undo Move "),"",this,SLOT(undoMove()),toolBar); | 126 | undoButton=new QToolButton(QPixmap(undo_xpm),tr(" Undo Move "),"",this,SLOT(undoMove()),toolBar); |
128 | CHECK_PTR(undoButton); | 127 | CHECK_PTR(undoButton); |
129 | undoButton->setMinimumSize(buttonSize); | 128 | undoButton->setMinimumSize(buttonSize); |
130 | 129 | ||
131 | QToolButton* helpButton=new QToolButton(QPixmap(help_xpm),tr(" Rules of Play "),"",this,SLOT(help()),toolBar); | 130 | QToolButton* helpButton=new QToolButton(QPixmap(help_xpm),tr(" Rules of Play "),"",this,SLOT(help()),toolBar); |
132 | CHECK_PTR(helpButton); | 131 | CHECK_PTR(helpButton); |
133 | helpButton->setMinimumSize(buttonSize); | 132 | helpButton->setMinimumSize(buttonSize); |
134 | 133 | ||
135 | // Make a checkers board | 134 | // Make a checkers board |
136 | 135 | ||
137 | imageMan1=new QImage(man_black_xpm); CHECK_PTR(imageMan1); | 136 | imageMan1=new QImage(man_black_xpm); CHECK_PTR(imageMan1); |
138 | imageMan2=new QImage(man_white_xpm); CHECK_PTR(imageMan2); | 137 | imageMan2=new QImage(man_white_xpm); CHECK_PTR(imageMan2); |
139 | imageKing1=new QImage(king_black_xpm); CHECK_PTR(imageKing1); | 138 | imageKing1=new QImage(king_black_xpm); CHECK_PTR(imageKing1); |
140 | imageKing2=new QImage(king_white_xpm); CHECK_PTR(imageKing2); | 139 | imageKing2=new QImage(king_white_xpm); CHECK_PTR(imageKing2); |
141 | 140 | ||
142 | imageWood1=new QImage(wood1_xpm); CHECK_PTR(imageWood1); | 141 | imageWood1=new QImage(wood1_xpm); CHECK_PTR(imageWood1); |
143 | imageWood2=new QImage(wood2_xpm); CHECK_PTR(imageWood2); | 142 | imageWood2=new QImage(wood2_xpm); CHECK_PTR(imageWood2); |
144 | imageWood3=new QImage(wood3_xpm); CHECK_PTR(imageWood3); | 143 | imageWood3=new QImage(wood3_xpm); CHECK_PTR(imageWood3); |
145 | imageGreen1=new QImage(green1_xpm); CHECK_PTR(imageGreen1); | 144 | imageGreen1=new QImage(green1_xpm); CHECK_PTR(imageGreen1); |
146 | imageGreen2=new QImage(green2_xpm); CHECK_PTR(imageGreen2); | 145 | imageGreen2=new QImage(green2_xpm); CHECK_PTR(imageGreen2); |
147 | imageGreen3=new QImage(green3_xpm); CHECK_PTR(imageGreen3); | 146 | imageGreen3=new QImage(green3_xpm); CHECK_PTR(imageGreen3); |
148 | imageMarble1=new QImage(marble1_xpm); CHECK_PTR(imageMarble1); | 147 | imageMarble1=new QImage(marble1_xpm); CHECK_PTR(imageMarble1); |
149 | imageMarble2=new QImage(marble2_xpm); CHECK_PTR(imageMarble2); | 148 | imageMarble2=new QImage(marble2_xpm); CHECK_PTR(imageMarble2); |
150 | imageMarble3=new QImage(marble3_xpm); CHECK_PTR(imageMarble3); | 149 | imageMarble3=new QImage(marble3_xpm); CHECK_PTR(imageMarble3); |
151 | 150 | ||
152 | QWidget* centralWidget=new QWidget(this); | 151 | QWidget* centralWidget=new QWidget(this); |
153 | setCentralWidget(centralWidget); | 152 | setCentralWidget(centralWidget); |
154 | 153 | ||
155 | QFrame* frame=new QFrame(centralWidget); | 154 | QFrame* frame=new QFrame(centralWidget); |
156 | CHECK_PTR(frame); | 155 | CHECK_PTR(frame); |
157 | frame->setFrameStyle(QFrame::Box|QFrame::Plain); | 156 | frame->setFrameStyle(QFrame::Box|QFrame::Plain); |
158 | frame->setFixedSize(SIZE*8+2,SIZE*8+2); | 157 | frame->setFixedSize(SIZE*8+2,SIZE*8+2); |
159 | 158 | ||
160 | statusLabel = new QLabel(centralWidget); | 159 | statusLabel = new QLabel(centralWidget); |
161 | statusLabel->setAlignment(Qt::AlignHCenter); | 160 | statusLabel->setAlignment(Qt::AlignHCenter); |
162 | 161 | ||
163 | QVBoxLayout* vlayout=new QVBoxLayout(centralWidget); | 162 | QVBoxLayout* vlayout=new QVBoxLayout(centralWidget); |
164 | 163 | ||
165 | vlayout->addStretch(); | 164 | vlayout->addStretch(); |
166 | vlayout->addWidget(frame); | 165 | vlayout->addWidget(frame); |
167 | vlayout->addStretch(); | 166 | vlayout->addStretch(); |
168 | vlayout->addWidget(statusLabel); | 167 | vlayout->addWidget(statusLabel); |
169 | vlayout->addStretch(); | 168 | vlayout->addStretch(); |
170 | 169 | ||
171 | for(int i=0;i<64;i++) | 170 | for(int i=0;i<64;i++) |
172 | { | 171 | { |
173 | field[i]=new Field(frame,i); | 172 | field[i]=new Field(frame,i); |
174 | CHECK_PTR(field[i]); | 173 | CHECK_PTR(field[i]); |
175 | } | 174 | } |
176 | 175 | ||
177 | QGridLayout* grid=new QGridLayout(frame,8,8,1,0); | 176 | QGridLayout* grid=new QGridLayout(frame,8,8,1,0); |
178 | CHECK_PTR(grid); | 177 | CHECK_PTR(grid); |
179 | 178 | ||
180 | for(int i=0;i<4;i++) | 179 | for(int i=0;i<4;i++) |
181 | { | 180 | { |
182 | for(int k=0;k<4;k++) | 181 | for(int k=0;k<4;k++) |
183 | { | 182 | { |
184 | grid->addWidget(field[i*8+k+32],i*2, k*2 ); | 183 | grid->addWidget(field[i*8+k+32],i*2, k*2 ); |
185 | grid->addWidget(field[i*8+k ],i*2, k*2+1); | 184 | grid->addWidget(field[i*8+k ],i*2, k*2+1); |
186 | grid->addWidget(field[i*8+k+4 ],i*2+1,k*2 ); | 185 | grid->addWidget(field[i*8+k+4 ],i*2+1,k*2 ); |
187 | grid->addWidget(field[i*8+k+36],i*2+1,k*2+1); | 186 | grid->addWidget(field[i*8+k+36],i*2+1,k*2+1); |
188 | } | 187 | } |
189 | } | 188 | } |
190 | 189 | ||
191 | for(int i=0;i<32;i++) | 190 | for(int i=0;i<32;i++) |
192 | connect(field[i],SIGNAL(click(int)),this,SLOT(click(int))); | 191 | connect(field[i],SIGNAL(click(int)),this,SLOT(click(int))); |
193 | 192 | ||
194 | selected=false; | 193 | selected=false; |
195 | 194 | ||
196 | setPattern(pattern); | 195 | setPattern(pattern); |
197 | 196 | ||
198 | QWhatsThis::add(frame,"A checkers board"); | 197 | QWhatsThis::add(frame,"A checkers board"); |
199 | 198 | ||
200 | userFirst=false; | 199 | userFirst=false; |
201 | 200 | ||
202 | game=NULL; | 201 | game=NULL; |
203 | newGame(); | 202 | newGame(); |
204 | } | 203 | } |
205 | 204 | ||
206 | 205 | ||
207 | void KCheckers::readConfig() | 206 | void KCheckers::readConfig() |
208 | { | 207 | { |
209 | Config config("KCheckers"); | 208 | Config config("KCheckers"); |
210 | config.setGroup("KCheckers"); | 209 | config.setGroup("KCheckers"); |
211 | QString entry; | 210 | QString entry; |
212 | 211 | ||
213 | entry=config.readEntry("skill","novice"); | 212 | entry=config.readEntry("skill","novice"); |
214 | if(entry=="beginner") skill=BEGINNER; | 213 | if(entry=="beginner") skill=BEGINNER; |
215 | else if(entry=="average") skill=AVERAGE; | 214 | else if(entry=="average") skill=AVERAGE; |
216 | else if(entry=="good") skill=GOOD; | 215 | else if(entry=="good") skill=GOOD; |
217 | else if(entry=="expert") skill=EXPERT; | 216 | else if(entry=="expert") skill=EXPERT; |
218 | else if(entry=="master") skill=MASTER; | 217 | else if(entry=="master") skill=MASTER; |
219 | else skill=NOVICE; | 218 | else skill=NOVICE; |
220 | 219 | ||
221 | entry=config.readEntry("rules","english"); | 220 | entry=config.readEntry("rules","english"); |
222 | if(entry=="russian") rules=RUSSIAN; | 221 | if(entry=="russian") rules=RUSSIAN; |
223 | else rules=ENGLISH; | 222 | else rules=ENGLISH; |
224 | 223 | ||
225 | entry=config.readEntry("theme","wooden"); | 224 | entry=config.readEntry("theme","wooden"); |
226 | if(entry=="green") pattern=GREEN; | 225 | if(entry=="green") pattern=GREEN; |
227 | else if(entry=="marble") pattern=MARBLE; | 226 | else if(entry=="marble") pattern=MARBLE; |
228 | else pattern=WOODEN; | 227 | else pattern=WOODEN; |
229 | } | 228 | } |
230 | 229 | ||
231 | 230 | ||
232 | void KCheckers::closeEvent(QCloseEvent* event) | 231 | void KCheckers::closeEvent(QCloseEvent* event) |
233 | { | 232 | { |
234 | Config config("KCheckers"); | 233 | Config config("KCheckers"); |
235 | config.setGroup("KCheckers"); | 234 | config.setGroup("KCheckers"); |
236 | QString entry; | 235 | QString entry; |
237 | 236 | ||
238 | if(skill==BEGINNER) entry="beginner"; | 237 | if(skill==BEGINNER) entry="beginner"; |
239 | if(skill==NOVICE) entry="novice"; | 238 | if(skill==NOVICE) entry="novice"; |
240 | if(skill==AVERAGE) entry="average"; | 239 | if(skill==AVERAGE) entry="average"; |
241 | if(skill==GOOD) entry="good"; | 240 | if(skill==GOOD) entry="good"; |
242 | if(skill==EXPERT) entry="expert"; | 241 | if(skill==EXPERT) entry="expert"; |
243 | if(skill==MASTER) entry="master"; | 242 | if(skill==MASTER) entry="master"; |
244 | config.writeEntry("skill",entry); | 243 | config.writeEntry("skill",entry); |
245 | 244 | ||
246 | if(rules==ENGLISH) entry="english"; | 245 | if(rules==ENGLISH) entry="english"; |
247 | if(rules==RUSSIAN) entry="russian"; | 246 | if(rules==RUSSIAN) entry="russian"; |
248 | config.writeEntry("rules",entry); | 247 | config.writeEntry("rules",entry); |
249 | 248 | ||
250 | if(pattern==GREEN) entry="green"; | 249 | if(pattern==GREEN) entry="green"; |
251 | if(pattern==MARBLE) entry="marble"; | 250 | if(pattern==MARBLE) entry="marble"; |
252 | if(pattern==WOODEN) entry="wooden"; | 251 | if(pattern==WOODEN) entry="wooden"; |
253 | config.writeEntry("theme",entry); | 252 | config.writeEntry("theme",entry); |
254 | 253 | ||
255 | event->accept(); | 254 | event->accept(); |
256 | } | 255 | } |
257 | 256 | ||
258 | 257 | ||
259 | void KCheckers::setSkill(int set) | 258 | void KCheckers::setSkill(int set) |
260 | { | 259 | { |
261 | skillMenu->setItemChecked(skill,false); | 260 | skillMenu->setItemChecked(skill,false); |
262 | 261 | ||
263 | skill=set; | 262 | skill=set; |
264 | skillMenu->setItemChecked(skill,true); | 263 | skillMenu->setItemChecked(skill,true); |
265 | 264 | ||
266 | game->setLevel(skill); | 265 | game->setLevel(skill); |
267 | } | 266 | } |
268 | 267 | ||
269 | 268 | ||
270 | void KCheckers::setRules(int set) | 269 | void KCheckers::setRules(int set) |
271 | { | 270 | { |
272 | optionsMenu->setItemChecked(rules,false); | 271 | optionsMenu->setItemChecked(rules,false); |
273 | 272 | ||
274 | rules=set; | 273 | rules=set; |
275 | optionsMenu->setItemChecked(rules,true); | 274 | optionsMenu->setItemChecked(rules,true); |
276 | 275 | ||
277 | colorChange(); | 276 | colorChange(); |
278 | newGame(); | 277 | newGame(); |
279 | } | 278 | } |
280 | 279 | ||
281 | 280 | ||
282 | void KCheckers::setPattern(int set) | 281 | void KCheckers::setPattern(int set) |
283 | { | 282 | { |
284 | optionsMenu->setItemChecked(pattern,false); | 283 | optionsMenu->setItemChecked(pattern,false); |
285 | 284 | ||
286 | pattern=set; | 285 | pattern=set; |
287 | optionsMenu->setItemChecked(pattern,true); | 286 | optionsMenu->setItemChecked(pattern,true); |
288 | 287 | ||
289 | switch(pattern) | 288 | switch(pattern) |
290 | { | 289 | { |
291 | case GREEN: | 290 | case GREEN: |
292 | imagePat1=imageGreen1; | 291 | imagePat1=imageGreen1; |
293 | imagePat2=imageGreen2; | 292 | imagePat2=imageGreen2; |
294 | imageFrame=imageGreen3; | 293 | imageFrame=imageGreen3; |
295 | break; | 294 | break; |
296 | case MARBLE: | 295 | case MARBLE: |
297 | imagePat1=imageMarble1; | 296 | imagePat1=imageMarble1; |
298 | imagePat2=imageMarble2; | 297 | imagePat2=imageMarble2; |
299 | imageFrame=imageMarble3; | 298 | imageFrame=imageMarble3; |
300 | break; | 299 | break; |
301 | case WOODEN: | 300 | case WOODEN: |
302 | imagePat1=imageWood1; | 301 | imagePat1=imageWood1; |
303 | imagePat2=imageWood2; | 302 | imagePat2=imageWood2; |
304 | imageFrame=imageWood3; | 303 | imageFrame=imageWood3; |
305 | } | 304 | } |
306 | 305 | ||
307 | for(int i=0; i<32;i++) field[i]->setPattern(imagePat2); | 306 | for(int i=0; i<32;i++) field[i]->setPattern(imagePat2); |
308 | for(int i=32;i<64;i++) field[i]->setPattern(imagePat1); | 307 | for(int i=32;i<64;i++) field[i]->setPattern(imagePat1); |
309 | 308 | ||
310 | if(selected) field[from]->setFrame(imageFrame); | 309 | if(selected) field[from]->setFrame(imageFrame); |
311 | } | 310 | } |
312 | 311 | ||
313 | 312 | ||
314 | void KCheckers::showNumeration() | 313 | void KCheckers::showNumeration() |
315 | { | 314 | { |
316 | if(optionsMenu->isItemChecked(numID)) | 315 | if(optionsMenu->isItemChecked(numID)) |
317 | { | 316 | { |
318 | optionsMenu->setItemChecked(numID,false); | 317 | optionsMenu->setItemChecked(numID,false); |
319 | for(int i=0;i<32;i++) field[i]->setLabel(""); | 318 | for(int i=0;i<32;i++) field[i]->setLabel(""); |
320 | } | 319 | } |
321 | else | 320 | else |
322 | { | 321 | { |
323 | optionsMenu->setItemChecked(numID,true); | 322 | optionsMenu->setItemChecked(numID,true); |
324 | drawNumeration(); | 323 | drawNumeration(); |
325 | } | 324 | } |
326 | } | 325 | } |
327 | 326 | ||
328 | 327 | ||
329 | void KCheckers::drawNumeration() | 328 | void KCheckers::drawNumeration() |
330 | { | 329 | { |
331 | if(rules==ENGLISH) | 330 | if(rules==ENGLISH) |
332 | { | 331 | { |
333 | if(userFirst) | 332 | if(userFirst) |
334 | for(int i=0;i<32;i++) | 333 | for(int i=0;i<32;i++) |
335 | field[i]->setLabel(enNumeration.mid(i*2,2)); | 334 | field[i]->setLabel(enNumeration.mid(i*2,2)); |
336 | else | 335 | else |
337 | for(int i=0;i<32;i++) | 336 | for(int i=0;i<32;i++) |
338 | field[i]->setLabel(enNumeration.mid(62-i*2,2)); | 337 | field[i]->setLabel(enNumeration.mid(62-i*2,2)); |
339 | } | 338 | } |
340 | else | 339 | else |
341 | { | 340 | { |
342 | if(userFirst) | 341 | if(userFirst) |
343 | for(int i=0;i<32;i++) | 342 | for(int i=0;i<32;i++) |
344 | field[i]->setLabel(ruNumeration.mid(i*2,2)); | 343 | field[i]->setLabel(ruNumeration.mid(i*2,2)); |
345 | else | 344 | else |
346 | for(int i=0;i<32;i++) | 345 | for(int i=0;i<32;i++) |
347 | field[i]->setLabel(ruNumeration.mid(62-i*2,2)); | 346 | field[i]->setLabel(ruNumeration.mid(62-i*2,2)); |
348 | } | 347 | } |
349 | } | 348 | } |
350 | 349 | ||
351 | 350 | ||
352 | void KCheckers::drawBoard(int i) | 351 | void KCheckers::drawBoard(int i) |
353 | { | 352 | { |
354 | switch(game->board[t[i]]) | 353 | switch(game->board[t[i]]) |
355 | { | 354 | { |
356 | case MAN1: | 355 | case MAN1: |
357 | field[i]->setPicture(imageMan1); | 356 | field[i]->setPicture(imageMan1); |
358 | break; | 357 | break; |
359 | case MAN2: | 358 | case MAN2: |
360 | field[i]->setPicture(imageMan2); | 359 | field[i]->setPicture(imageMan2); |
361 | break; | 360 | break; |
362 | case KING1: | 361 | case KING1: |
363 | field[i]->setPicture(imageKing1); | 362 | field[i]->setPicture(imageKing1); |
364 | break; | 363 | break; |
365 | case KING2: | 364 | case KING2: |
366 | field[i]->setPicture(imageKing2); | 365 | field[i]->setPicture(imageKing2); |
367 | break; | 366 | break; |
368 | default: | 367 | default: |
369 | field[i]->setPicture(NULL); | 368 | field[i]->setPicture(NULL); |
370 | } | 369 | } |
371 | } | 370 | } |
372 | 371 | ||
373 | 372 | ||
374 | void KCheckers::help() | 373 | void KCheckers::help() |
375 | { | 374 | { |
376 | QMessageBox::information(this,"Rules of Play", | 375 | QMessageBox::information(this,"Rules of Play", |
377 | "In the beginning of game you have\n" | 376 | "In the beginning of game you have\n" |
378 | "12 checkers (men).\n" | 377 | "12 checkers (men).\n" |
379 | "The men move forward only.\n" | 378 | "The men move forward only.\n" |
380 | "The men can capture:\n" | 379 | "The men can capture:\n" |
381 | "- by jumping forward only (english\n" | 380 | "- by jumping forward only (english\n" |
382 | " rules);\n" | 381 | " rules);\n" |
383 | "- by jumping forward or backward\n" | 382 | "- by jumping forward or backward\n" |
384 | " (russian rules).\n" | 383 | " (russian rules).\n" |
385 | "A man which reaches the far side of\n" | 384 | "A man which reaches the far side of\n" |
386 | "the board becomes a king.\n" | 385 | "the board becomes a king.\n" |
387 | "The kings move forward or\n" | 386 | "The kings move forward or\n" |
388 | "backward:\n" | 387 | "backward:\n" |
389 | "- to one square only (english rules);\n" | 388 | "- to one square only (english rules);\n" |
390 | "- to any number of squares (russian\n" | 389 | "- to any number of squares (russian\n" |
391 | " rules).\n" | 390 | " rules).\n" |
392 | "The kings capture by jumping\n" | 391 | "The kings capture by jumping\n" |
393 | "forward or backward.\n" | 392 | "forward or backward.\n" |
394 | "Whenever a player is able to make a\n" | 393 | "Whenever a player is able to make a\n" |
395 | "capture he must do so.", | 394 | "capture he must do so.", |
396 | QMessageBox::Ok|QMessageBox::Default); | 395 | QMessageBox::Ok|QMessageBox::Default); |
397 | } | 396 | } |
398 | 397 | ||
399 | 398 | ||
400 | void KCheckers::about() | 399 | void KCheckers::about() |
401 | { | 400 | { |
402 | QMessageBox::about(this,"About KCheckers", | 401 | QMessageBox::about(this,"About KCheckers", |
403 | "KCheckers, a board game. Ver 0.3\n" | 402 | "KCheckers, a board game. Ver 0.3\n" |
404 | "(C) 2002, A. Peredri <andi@ukr.net>\n\n" | 403 | "(C) 2002, A. Peredri <andi@ukr.net>\n\n" |
405 | "http://kcheckers.tuxfamily.org\n\n" | 404 | "http://kcheckers.tuxfamily.org\n\n" |
406 | "Contributors:\n" | 405 | "Contributors:\n" |
407 | "S. Rosen <srosen@erols.com>\n\n" | 406 | "S. Rosen <srosen@erols.com>\n\n" |
408 | "Qtopia version: S.Prud'homme\n" | 407 | "Qtopia version: S.Prud'homme\n" |
409 | "<prudhomme@laposte.net>\n\n" | 408 | "<prudhomme@laposte.net>\n\n" |
410 | "This program is distributed under the\n" | 409 | "This program is distributed under the\n" |
411 | "terms of the GNU General Public\n" | 410 | "terms of the GNU General Public\n" |
412 | "License."); | 411 | "License."); |
413 | } | 412 | } |
414 | 413 | ||
415 | 414 | ||
416 | void KCheckers::aboutQt() | 415 | void KCheckers::aboutQt() |
417 | { | 416 | { |
418 | QMessageBox::aboutQt(this); | 417 | QMessageBox::aboutQt(this); |
419 | } | 418 | } |
420 | 419 | ||
421 | 420 | ||
422 | void KCheckers::newGame() | 421 | void KCheckers::newGame() |
423 | { | 422 | { |
424 | if(game) delete game; | 423 | if(game) delete game; |
425 | 424 | ||
426 | switch(rules) | 425 | switch(rules) |
427 | { | 426 | { |
428 | case ENGLISH: | 427 | case ENGLISH: |
429 | game=new ECheckers(skill); | 428 | game=new ECheckers(skill); |
430 | CHECK_PTR(game); | 429 | CHECK_PTR(game); |
431 | break; | 430 | break; |
432 | 431 | ||
433 | case RUSSIAN: | 432 | case RUSSIAN: |
434 | game=new RCheckers(skill); | 433 | game=new RCheckers(skill); |
435 | CHECK_PTR(game); | 434 | CHECK_PTR(game); |
436 | } | 435 | } |
437 | 436 | ||
438 | unselect(); | 437 | unselect(); |
439 | gameOver=false; | 438 | gameOver=false; |
440 | 439 | ||
441 | gameMenu->setItemEnabled(undoID,false); | 440 | gameMenu->setItemEnabled(undoID,false); |
442 | undoButton->setEnabled(false); | 441 | undoButton->setEnabled(false); |
443 | 442 | ||
444 | colorChange(); | 443 | colorChange(); |
445 | 444 | ||
446 | for(int i=0;i<32;i++) drawBoard(i); | 445 | for(int i=0;i<32;i++) drawBoard(i); |
447 | if(optionsMenu->isItemChecked(numID)) drawNumeration(); | 446 | if(optionsMenu->isItemChecked(numID)) drawNumeration(); |
448 | 447 | ||
449 | if(!userFirst) compGo(); | 448 | if(!userFirst) compGo(); |
450 | 449 | ||
451 | statusLabel->setText(tr("Go!")); | 450 | statusLabel->setText(tr("Go!")); |
452 | } | 451 | } |
453 | 452 | ||
454 | 453 | ||
455 | // Undo the last computer and user moves | 454 | // Undo the last computer and user moves |
456 | 455 | ||
457 | void KCheckers::undoMove() | 456 | void KCheckers::undoMove() |
458 | { | 457 | { |
459 | for(int i=0;i<32;i++) | 458 | for(int i=0;i<32;i++) |
460 | { | 459 | { |
461 | game->board[t[i]]=undoBoard[i]; | 460 | game->board[t[i]]=undoBoard[i]; |
462 | drawBoard(i); | 461 | drawBoard(i); |
463 | } | 462 | } |
464 | 463 | ||
465 | unselect(); | 464 | unselect(); |
466 | gameOver=false; | 465 | gameOver=false; |
467 | 466 | ||
468 | gameMenu->setItemEnabled(undoID,false); | 467 | gameMenu->setItemEnabled(undoID,false); |
469 | undoButton->setEnabled(false); | 468 | undoButton->setEnabled(false); |
470 | 469 | ||
471 | statusLabel->setText(tr("Go!")); | 470 | statusLabel->setText(tr("Go!")); |
472 | } | 471 | } |
473 | 472 | ||
474 | 473 | ||
475 | void KCheckers::colorChange() | 474 | void KCheckers::colorChange() |
476 | { | 475 | { |
477 | userFirst=!userFirst; | 476 | userFirst=!userFirst; |
478 | 477 | ||
479 | QImage* image; | 478 | QImage* image; |
480 | image=imageMan1; | 479 | image=imageMan1; |
481 | imageMan1=imageMan2; | 480 | imageMan1=imageMan2; |
482 | imageMan2=image; | 481 | imageMan2=image; |
483 | image=imageKing1; | 482 | image=imageKing1; |
484 | imageKing1=imageKing2; | 483 | imageKing1=imageKing2; |
485 | imageKing2=image; | 484 | imageKing2=image; |
486 | } | 485 | } |
487 | 486 | ||
488 | 487 | ||
489 | void KCheckers::unselect() | 488 | void KCheckers::unselect() |
490 | { | 489 | { |
491 | if(selected) field[from]->setFrame(NULL); | 490 | if(selected) field[from]->setFrame(NULL); |
492 | selected=false; | 491 | selected=false; |
493 | } | 492 | } |
494 | 493 | ||
495 | 494 | ||
496 | void KCheckers::click(int fieldNumber) | 495 | void KCheckers::click(int fieldNumber) |
497 | { | 496 | { |
498 | if(gameOver) return; | 497 | if(gameOver) return; |
499 | switch(game->board[t[fieldNumber]]) | 498 | switch(game->board[t[fieldNumber]]) |
500 | { | 499 | { |
501 | case MAN1: | 500 | case MAN1: |
502 | case KING1: | 501 | case KING1: |
503 | // User selected | 502 | // User selected |
504 | if(!selected) | 503 | if(!selected) |
505 | { | 504 | { |
506 | from=fieldNumber; | 505 | from=fieldNumber; |
507 | selected=true; | 506 | selected=true; |
508 | field[fieldNumber]->setFrame(imageFrame); | 507 | field[fieldNumber]->setFrame(imageFrame); |
509 | return; | 508 | return; |
510 | } | 509 | } |
511 | // User reselected | 510 | // User reselected |
512 | else | 511 | else |
513 | { | 512 | { |
514 | field[from]->setFrame(NULL); | 513 | field[from]->setFrame(NULL); |
515 | from=fieldNumber; | 514 | from=fieldNumber; |
diff --git a/noncore/games/kcheckers/main.cpp b/noncore/games/kcheckers/main.cpp index 6ac570a..e22dbcc 100644 --- a/noncore/games/kcheckers/main.cpp +++ b/noncore/games/kcheckers/main.cpp | |||
@@ -1,10 +1,8 @@ | |||
1 | 1 | ||
2 | #include <qpe/qpeapplication.h> | ||
3 | #include <qfont.h> | ||
4 | 2 | ||
5 | #include "kcheckers.h" | 3 | #include "kcheckers.h" |
6 | #include <opie/oapplicationfactory.h> | 4 | #include <opie/oapplicationfactory.h> |
7 | 5 | ||
8 | OPIE_EXPORT_APP( OApplicationFactory<KCheckers> ) | 6 | OPIE_EXPORT_APP( OApplicationFactory<KCheckers> ) |
9 | 7 | ||
10 | 8 | ||
diff --git a/noncore/games/kpacman/board.cpp b/noncore/games/kpacman/board.cpp index f95f699..f82b5f9 100644 --- a/noncore/games/kpacman/board.cpp +++ b/noncore/games/kpacman/board.cpp | |||
@@ -1,425 +1,422 @@ | |||
1 | 1 | ||
2 | #include "portable.h" | ||
3 | 2 | ||
4 | #if defined( KDE2_PORT ) | 3 | #if defined( KDE2_PORT ) |
5 | #include <kapp.h> | 4 | #include <kapp.h> |
6 | #include <klocale.h> | 5 | #include <klocale.h> |
7 | #endif | 6 | #endif |
8 | 7 | ||
9 | #include <qrect.h> | ||
10 | #include <qregexp.h> | ||
11 | #include <qmessagebox.h> | 8 | #include <qmessagebox.h> |
12 | #include <qfile.h> | 9 | #include <qfile.h> |
13 | #include <qtextstream.h> | 10 | #include <qtextstream.h> |
14 | 11 | ||
15 | #include "board.h" | 12 | #include "board.h" |
16 | #include "bitmaps.h" | 13 | #include "bitmaps.h" |
17 | 14 | ||
18 | Board::Board(int size) : QArray<int> (size) | 15 | Board::Board(int size) : QArray<int> (size) |
19 | { | 16 | { |
20 | sz = size; // set size of board | 17 | sz = size; // set size of board |
21 | 18 | ||
22 | map = ""; | 19 | map = ""; |
23 | mapName = ""; // no map loaded so far | 20 | mapName = ""; // no map loaded so far |
24 | 21 | ||
25 | init(None); // initialize varibales | 22 | init(None); // initialize varibales |
26 | } | 23 | } |
27 | 24 | ||
28 | void Board::init(Image image, QString levelName) | 25 | void Board::init(Image image, QString levelName) |
29 | { | 26 | { |
30 | prisonEntry = OUT; | 27 | prisonEntry = OUT; |
31 | prisonExit = OUT; | 28 | prisonExit = OUT; |
32 | fruitHome = OUT; | 29 | fruitHome = OUT; |
33 | fruitPosition = OUT; | 30 | fruitPosition = OUT; |
34 | pacmanHome = OUT; | 31 | pacmanHome = OUT; |
35 | pacmanPosition = OUT; | 32 | pacmanPosition = OUT; |
36 | for (int m = 0; m < 8; m++) { | 33 | for (int m = 0; m < 8; m++) { |
37 | monsterHome[m] = OUT; | 34 | monsterHome[m] = OUT; |
38 | monsterPosition[m] = OUT; | 35 | monsterPosition[m] = OUT; |
39 | } | 36 | } |
40 | for (int e = 0; e < 8; e++) { | 37 | for (int e = 0; e < 8; e++) { |
41 | energizerPosition[e] = OUT; | 38 | energizerPosition[e] = OUT; |
42 | } | 39 | } |
43 | for (int e = 0; e < 8; e++) { | 40 | for (int e = 0; e < 8; e++) { |
44 | tunnelPosition[e] = OUT; | 41 | tunnelPosition[e] = OUT; |
45 | } | 42 | } |
46 | 43 | ||
47 | fill(0); | 44 | fill(0); |
48 | numPoints = 0; | 45 | numPoints = 0; |
49 | numEnergizers = 0; | 46 | numEnergizers = 0; |
50 | numMonsters = 0; | 47 | numMonsters = 0; |
51 | numTunnels = 0; | 48 | numTunnels = 0; |
52 | 49 | ||
53 | if (!levelName.isNull() && !levelName.isEmpty()) | 50 | if (!levelName.isNull() && !levelName.isEmpty()) |
54 | if (mapName == levelName) | 51 | if (mapName == levelName) |
55 | image = File; | 52 | image = File; |
56 | else { | 53 | else { |
57 | QFile levelFile(levelName); | 54 | QFile levelFile(levelName); |
58 | if (!levelFile.open(IO_ReadOnly)) { | 55 | if (!levelFile.open(IO_ReadOnly)) { |
59 | 56 | ||
60 | QString msg = "The levelmap could not be constructed.\n\n" | 57 | QString msg = "The levelmap could not be constructed.\n\n" |
61 | "The file '@LEVELNAME@' does not exist,\n" | 58 | "The file '@LEVELNAME@' does not exist,\n" |
62 | "or could not be opened for reading."; | 59 | "or could not be opened for reading."; |
63 | msg.replace(QRegExp("@LEVELNAME@"), levelName); | 60 | msg.replace(QRegExp("@LEVELNAME@"), levelName); |
64 | // QMessageBox::information(0, tr("Initialization Error"), msg); | 61 | // QMessageBox::information(0, tr("Initialization Error"), msg); |
65 | printf("%s\n", msg.data()); | 62 | printf("%s\n", msg.data()); |
66 | } else { | 63 | } else { |
67 | map.fill(' ', BoardHeight*BoardWidth); | 64 | map.fill(' ', BoardHeight*BoardWidth); |
68 | int height = 0; | 65 | int height = 0; |
69 | 66 | ||
70 | QTextStream levelStream(&levelFile); | 67 | QTextStream levelStream(&levelFile); |
71 | while (!levelStream.eof() && height < BoardHeight) { | 68 | while (!levelStream.eof() && height < BoardHeight) { |
72 | QString line = levelStream.readLine(); | 69 | QString line = levelStream.readLine(); |
73 | 70 | ||
74 | if (line.find(QRegExp("^ *;")) == -1) { | 71 | if (line.find(QRegExp("^ *;")) == -1) { |
75 | 72 | ||
76 | line.replace(QRegExp(";.*"), ""); // strip off comments | 73 | line.replace(QRegExp(";.*"), ""); // strip off comments |
77 | line.replace(QRegExp("\" *$"), ""); // strip off trailing " | 74 | line.replace(QRegExp("\" *$"), ""); // strip off trailing " |
78 | line.replace(QRegExp("^ *\""), ""); // strip off leading " | 75 | line.replace(QRegExp("^ *\""), ""); // strip off leading " |
79 | 76 | ||
80 | map.replace(height*BoardWidth, | 77 | map.replace(height*BoardWidth, |
81 | (line.length() > BoardWidth) ? BoardWidth : line.length(), | 78 | (line.length() > BoardWidth) ? BoardWidth : line.length(), |
82 | line.data()); | 79 | line.data()); |
83 | 80 | ||
84 | height++; | 81 | height++; |
85 | } | 82 | } |
86 | } | 83 | } |
87 | mapName = levelName; | 84 | mapName = levelName; |
88 | levelFile.close(); | 85 | levelFile.close(); |
89 | image = File; | 86 | image = File; |
90 | } | 87 | } |
91 | } | 88 | } |
92 | 89 | ||
93 | switch (image) { | 90 | switch (image) { |
94 | case Intro : // setup(demo_bits); | 91 | case Intro : // setup(demo_bits); |
95 | break; | 92 | break; |
96 | case Demo : setup(demo_bits); | 93 | case Demo : setup(demo_bits); |
97 | break; | 94 | break; |
98 | case Level : setup(demo_bits); | 95 | case Level : setup(demo_bits); |
99 | break; | 96 | break; |
100 | case File : setup((uchar *) map.data()); | 97 | case File : setup((uchar *) map.data()); |
101 | break; | 98 | break; |
102 | default : break; | 99 | default : break; |
103 | } | 100 | } |
104 | } | 101 | } |
105 | 102 | ||
106 | void Board::setup(const uchar *buf) | 103 | void Board::setup(const uchar *buf) |
107 | { | 104 | { |
108 | for ( int index = 0; buf[index] != 0 && index < BoardWidth*BoardHeight; index++ ) { | 105 | for ( int index = 0; buf[index] != 0 && index < BoardWidth*BoardHeight; index++ ) { |
109 | switch (buf[index]) { | 106 | switch (buf[index]) { |
110 | case '*' : set(index, brick); break; | 107 | case '*' : set(index, brick); break; |
111 | case '+' : set(index, out); break; | 108 | case '+' : set(index, out); break; |
112 | case '#' : set(index, prison); break; | 109 | case '#' : set(index, prison); break; |
113 | case '-' : set(index, gate); break; | 110 | case '-' : set(index, gate); break; |
114 | case 'E' : set(index, tunnel); break; | 111 | case 'E' : set(index, tunnel); break; |
115 | case '.' : set(index, Point); break; | 112 | case '.' : set(index, Point); break; |
116 | case 'o' : set(index, energizer); break; | 113 | case 'o' : set(index, energizer); break; |
117 | case 'I' : set(index, prisonentry); break; | 114 | case 'I' : set(index, prisonentry); break; |
118 | case 'O' : set(index, prisonexit); break; | 115 | case 'O' : set(index, prisonexit); break; |
119 | case 'F' : set(index, fruithome); break; | 116 | case 'F' : set(index, fruithome); break; |
120 | case 'P' : set(index, pacmanhome); break; | 117 | case 'P' : set(index, pacmanhome); break; |
121 | default : if (buf[index] >= '0' && buf[index] <= '7') { | 118 | default : if (buf[index] >= '0' && buf[index] <= '7') { |
122 | set(index, monsterhome, buf[index]-(uchar)'0'); | 119 | set(index, monsterhome, buf[index]-(uchar)'0'); |
123 | } | 120 | } |
124 | } | 121 | } |
125 | } | 122 | } |
126 | } | 123 | } |
127 | 124 | ||
128 | bool Board::inBounds(int pos) | 125 | bool Board::inBounds(int pos) |
129 | { | 126 | { |
130 | return ( pos < 0 || pos > sz-1 ? FALSE : TRUE); | 127 | return ( pos < 0 || pos > sz-1 ? FALSE : TRUE); |
131 | } | 128 | } |
132 | 129 | ||
133 | void Board::set(int pos, Square sq, int m) | 130 | void Board::set(int pos, Square sq, int m) |
134 | { | 131 | { |
135 | if (inBounds(pos)) | 132 | if (inBounds(pos)) |
136 | switch (sq) { | 133 | switch (sq) { |
137 | case out : at(pos) = OUT; break; | 134 | case out : at(pos) = OUT; break; |
138 | case Point : at(pos) |= pointBit; numPoints++; break; | 135 | case Point : at(pos) |= pointBit; numPoints++; break; |
139 | case tunnel : at(pos) = sq; | 136 | case tunnel : at(pos) = sq; |
140 | for (int e = 0; e < numTunnels; e++) { // if tunnel is already on board | 137 | for (int e = 0; e < numTunnels; e++) { // if tunnel is already on board |
141 | if (tunnelPosition[e] == pos) // don't do it again. | 138 | if (tunnelPosition[e] == pos) // don't do it again. |
142 | pos = OUT; | 139 | pos = OUT; |
143 | } | 140 | } |
144 | if (pos != OUT) { | 141 | if (pos != OUT) { |
145 | tunnelPosition[numTunnels] = pos; | 142 | tunnelPosition[numTunnels] = pos; |
146 | numTunnels++; | 143 | numTunnels++; |
147 | } | 144 | } |
148 | break; | 145 | break; |
149 | case energizer : at(pos) |= energizerBit; | 146 | case energizer : at(pos) |= energizerBit; |
150 | for (int e = 0; e < numEnergizers; e++) { | 147 | for (int e = 0; e < numEnergizers; e++) { |
151 | if (energizerPosition[e] == pos) | 148 | if (energizerPosition[e] == pos) |
152 | pos = OUT; | 149 | pos = OUT; |
153 | } | 150 | } |
154 | if (pos != OUT) { | 151 | if (pos != OUT) { |
155 | energizerPosition[numEnergizers] = pos; | 152 | energizerPosition[numEnergizers] = pos; |
156 | numEnergizers++; | 153 | numEnergizers++; |
157 | } | 154 | } |
158 | break; | 155 | break; |
159 | case fruit : at(pos) |= fruitBit; fruitPosition = pos; break; | 156 | case fruit : at(pos) |= fruitBit; fruitPosition = pos; break; |
160 | case pacman : at(pos) |= pacmanBit; pacmanPosition = pos; break; | 157 | case pacman : at(pos) |= pacmanBit; pacmanPosition = pos; break; |
161 | case monster : at(pos) |= (monsterBit << m); | 158 | case monster : at(pos) |= (monsterBit << m); |
162 | monsterPosition[m] = pos; break; | 159 | monsterPosition[m] = pos; break; |
163 | case prisonentry : prisonEntry = pos; at(pos) = empty; break; | 160 | case prisonentry : prisonEntry = pos; at(pos) = empty; break; |
164 | case prisonexit : prisonExit = pos; at(pos) = empty; break; | 161 | case prisonexit : prisonExit = pos; at(pos) = empty; break; |
165 | case fruithome : fruitHome = pos; at(pos) = empty; break; | 162 | case fruithome : fruitHome = pos; at(pos) = empty; break; |
166 | case pacmanhome : pacmanHome = pos; at(pos) = empty; break; | 163 | case pacmanhome : pacmanHome = pos; at(pos) = empty; break; |
167 | case monsterhome : monsterHome[m] = pos; at(pos) = empty; | 164 | case monsterhome : monsterHome[m] = pos; at(pos) = empty; |
168 | if (m == 0 && prisonExit == OUT) | 165 | if (m == 0 && prisonExit == OUT) |
169 | prisonExit = pos; | 166 | prisonExit = pos; |
170 | if (m == 1 && prisonEntry == OUT) | 167 | if (m == 1 && prisonEntry == OUT) |
171 | prisonEntry = pos; | 168 | prisonEntry = pos; |
172 | numMonsters++; | 169 | numMonsters++; |
173 | break; | 170 | break; |
174 | default : at(pos) = sq; | 171 | default : at(pos) = sq; |
175 | } | 172 | } |
176 | } | 173 | } |
177 | 174 | ||
178 | void Board::reset(int pos, Square sq, int m) | 175 | void Board::reset(int pos, Square sq, int m) |
179 | { | 176 | { |
180 | bool found = FALSE; | 177 | bool found = FALSE; |
181 | if (inBounds(pos)) | 178 | if (inBounds(pos)) |
182 | switch (sq) { | 179 | switch (sq) { |
183 | case out : at(pos) = empty; break; | 180 | case out : at(pos) = empty; break; |
184 | case Point : at(pos) &= ~ pointBit; numPoints--; break; | 181 | case Point : at(pos) &= ~ pointBit; numPoints--; break; |
185 | case energizer : at(pos) &= ~ energizerBit; | 182 | case energizer : at(pos) &= ~ energizerBit; |
186 | for (int e = 0; e < numEnergizers; e++) { // delete the position of the eaten | 183 | for (int e = 0; e < numEnergizers; e++) { // delete the position of the eaten |
187 | if (found) // energizer in the position array | 184 | if (found) // energizer in the position array |
188 | energizerPosition[e-1] = energizerPosition[e]; | 185 | energizerPosition[e-1] = energizerPosition[e]; |
189 | if (energizerPosition[e] == pos) | 186 | if (energizerPosition[e] == pos) |
190 | found = TRUE; | 187 | found = TRUE; |
191 | } | 188 | } |
192 | energizerPosition[numEnergizers--] = OUT; | 189 | energizerPosition[numEnergizers--] = OUT; |
193 | break; | 190 | break; |
194 | case fruit : at(pos) &= ~ fruitBit; fruitPosition = OUT; break; | 191 | case fruit : at(pos) &= ~ fruitBit; fruitPosition = OUT; break; |
195 | case pacman : at(pos) &= ~ pacmanBit; pacmanPosition = OUT; break; | 192 | case pacman : at(pos) &= ~ pacmanBit; pacmanPosition = OUT; break; |
196 | case monster : at(pos) &= ~ (monsterBit << m); | 193 | case monster : at(pos) &= ~ (monsterBit << m); |
197 | monsterPosition[m] = OUT; break; | 194 | monsterPosition[m] = OUT; break; |
198 | default : at(pos) = at(pos) & varBits; | 195 | default : at(pos) = at(pos) & varBits; |
199 | } | 196 | } |
200 | } | 197 | } |
201 | 198 | ||
202 | int Board::position(Square sq, int m) | 199 | int Board::position(Square sq, int m) |
203 | { | 200 | { |
204 | switch(sq) { | 201 | switch(sq) { |
205 | case prisonentry : return prisonEntry; | 202 | case prisonentry : return prisonEntry; |
206 | case prisonexit : return prisonExit; | 203 | case prisonexit : return prisonExit; |
207 | case fruit : return fruitPosition; | 204 | case fruit : return fruitPosition; |
208 | case fruithome : return fruitHome; | 205 | case fruithome : return fruitHome; |
209 | case pacman : return pacmanPosition; | 206 | case pacman : return pacmanPosition; |
210 | case pacmanhome : return pacmanHome; | 207 | case pacmanhome : return pacmanHome; |
211 | case monster : return monsterPosition[m]; | 208 | case monster : return monsterPosition[m]; |
212 | case monsterhome : return monsterHome[m]; | 209 | case monsterhome : return monsterHome[m]; |
213 | case energizer : return energizerPosition[m]; | 210 | case energizer : return energizerPosition[m]; |
214 | case tunnel : return tunnelPosition[m]; | 211 | case tunnel : return tunnelPosition[m]; |
215 | default : return OUT; | 212 | default : return OUT; |
216 | } | 213 | } |
217 | } | 214 | } |
218 | 215 | ||
219 | bool Board::isOut(int pos) | 216 | bool Board::isOut(int pos) |
220 | { | 217 | { |
221 | if (inBounds(pos)) | 218 | if (inBounds(pos)) |
222 | return (at(pos) == OUT ? TRUE : FALSE); | 219 | return (at(pos) == OUT ? TRUE : FALSE); |
223 | return TRUE; | 220 | return TRUE; |
224 | } | 221 | } |
225 | 222 | ||
226 | bool Board::isEmpty(int pos) | 223 | bool Board::isEmpty(int pos) |
227 | { | 224 | { |
228 | if (inBounds(pos)) | 225 | if (inBounds(pos)) |
229 | return ((at(pos) & fixBits) == empty ? TRUE : FALSE); | 226 | return ((at(pos) & fixBits) == empty ? TRUE : FALSE); |
230 | return TRUE; | 227 | return TRUE; |
231 | } | 228 | } |
232 | 229 | ||
233 | bool Board::isBrick(int pos) | 230 | bool Board::isBrick(int pos) |
234 | { | 231 | { |
235 | if (inBounds(pos)) | 232 | if (inBounds(pos)) |
236 | return ((at(pos) & fixBits) == brick ? TRUE : FALSE); | 233 | return ((at(pos) & fixBits) == brick ? TRUE : FALSE); |
237 | return FALSE; | 234 | return FALSE; |
238 | } | 235 | } |
239 | 236 | ||
240 | bool Board::isPrison(int pos) | 237 | bool Board::isPrison(int pos) |
241 | { | 238 | { |
242 | if (inBounds(pos)) | 239 | if (inBounds(pos)) |
243 | return ((at(pos) & fixBits) == prison ? TRUE : FALSE); | 240 | return ((at(pos) & fixBits) == prison ? TRUE : FALSE); |
244 | return FALSE; | 241 | return FALSE; |
245 | } | 242 | } |
246 | 243 | ||
247 | bool Board::isGate(int pos) | 244 | bool Board::isGate(int pos) |
248 | { | 245 | { |
249 | if (inBounds(pos)) | 246 | if (inBounds(pos)) |
250 | return ((at(pos) & fixBits) == gate ? TRUE : FALSE); | 247 | return ((at(pos) & fixBits) == gate ? TRUE : FALSE); |
251 | return FALSE; | 248 | return FALSE; |
252 | } | 249 | } |
253 | 250 | ||
254 | bool Board::isTunnel(int pos) | 251 | bool Board::isTunnel(int pos) |
255 | { | 252 | { |
256 | if (inBounds(pos)) | 253 | if (inBounds(pos)) |
257 | return ((at(pos) & fixBits) == tunnel ? TRUE : FALSE); | 254 | return ((at(pos) & fixBits) == tunnel ? TRUE : FALSE); |
258 | return FALSE; | 255 | return FALSE; |
259 | } | 256 | } |
260 | 257 | ||
261 | bool Board::isPoint(int pos) | 258 | bool Board::isPoint(int pos) |
262 | { | 259 | { |
263 | if (inBounds(pos) && at(pos) != OUT) | 260 | if (inBounds(pos) && at(pos) != OUT) |
264 | return ((at(pos) & pointBit) != 0 ? TRUE : FALSE); | 261 | return ((at(pos) & pointBit) != 0 ? TRUE : FALSE); |
265 | return FALSE; | 262 | return FALSE; |
266 | } | 263 | } |
267 | 264 | ||
268 | bool Board::isEnergizer(int pos) | 265 | bool Board::isEnergizer(int pos) |
269 | { | 266 | { |
270 | if (inBounds(pos) && at(pos) != OUT) | 267 | if (inBounds(pos) && at(pos) != OUT) |
271 | return ((at(pos) & energizerBit) != 0 ? TRUE : FALSE); | 268 | return ((at(pos) & energizerBit) != 0 ? TRUE : FALSE); |
272 | return FALSE; | 269 | return FALSE; |
273 | } | 270 | } |
274 | 271 | ||
275 | bool Board::isFruit(int pos) | 272 | bool Board::isFruit(int pos) |
276 | { | 273 | { |
277 | if (inBounds(pos) && at(pos) != OUT) | 274 | if (inBounds(pos) && at(pos) != OUT) |
278 | return ((at(pos) & fruitBit) != 0 ? TRUE : FALSE); | 275 | return ((at(pos) & fruitBit) != 0 ? TRUE : FALSE); |
279 | return FALSE; | 276 | return FALSE; |
280 | } | 277 | } |
281 | 278 | ||
282 | bool Board::isPacman(int pos) | 279 | bool Board::isPacman(int pos) |
283 | { | 280 | { |
284 | if (inBounds(pos) && at(pos) != OUT) | 281 | if (inBounds(pos) && at(pos) != OUT) |
285 | return ((at(pos) & pacmanBit) != 0 ? TRUE : FALSE); | 282 | return ((at(pos) & pacmanBit) != 0 ? TRUE : FALSE); |
286 | return FALSE; | 283 | return FALSE; |
287 | } | 284 | } |
288 | 285 | ||
289 | bool Board::isMonster(int pos) | 286 | bool Board::isMonster(int pos) |
290 | { | 287 | { |
291 | if (inBounds(pos) && at(pos) != OUT) | 288 | if (inBounds(pos) && at(pos) != OUT) |
292 | return ((at(pos) & monsterBits) != 0 ? TRUE : FALSE); | 289 | return ((at(pos) & monsterBits) != 0 ? TRUE : FALSE); |
293 | return FALSE; | 290 | return FALSE; |
294 | } | 291 | } |
295 | 292 | ||
296 | bool Board::isWay(int pos, int dir, Square sq) { | 293 | bool Board::isWay(int pos, int dir, Square sq) { |
297 | int p1 = move(pos, dir, 2); | 294 | int p1 = move(pos, dir, 2); |
298 | if (p1 == OUT) | 295 | if (p1 == OUT) |
299 | return (sq == out ? TRUE : FALSE); | 296 | return (sq == out ? TRUE : FALSE); |
300 | int p2, p3; | 297 | int p2, p3; |
301 | if (dir == N || dir == S) { | 298 | if (dir == N || dir == S) { |
302 | p2 = move(p1, E); | 299 | p2 = move(p1, E); |
303 | p3 = move(p1, W); | 300 | p3 = move(p1, W); |
304 | } else { | 301 | } else { |
305 | p2 = move(p1, N); | 302 | p2 = move(p1, N); |
306 | p3 = move(p1, S); | 303 | p3 = move(p1, S); |
307 | } | 304 | } |
308 | switch (sq) { | 305 | switch (sq) { |
309 | case out : return isOut(p1) | isOut(p2) | isOut(p3); | 306 | case out : return isOut(p1) | isOut(p2) | isOut(p3); |
310 | case empty : return isEmpty(p1) & isEmpty(p2) & isEmpty(p3); | 307 | case empty : return isEmpty(p1) & isEmpty(p2) & isEmpty(p3); |
311 | case brick : return isBrick(p1) | isBrick(p2) | isBrick(p3); | 308 | case brick : return isBrick(p1) | isBrick(p2) | isBrick(p3); |
312 | case prison : return isPrison(p1) | isPrison(p2) | isPrison(p3); | 309 | case prison : return isPrison(p1) | isPrison(p2) | isPrison(p3); |
313 | case gate : return isGate(p1) & isGate(p2) & isGate(p3); | 310 | case gate : return isGate(p1) & isGate(p2) & isGate(p3); |
314 | case tunnel : return isTunnel(p1) & | 311 | case tunnel : return isTunnel(p1) & |
315 | (isTunnel(p2) || isEmpty(p2)) & | 312 | (isTunnel(p2) || isEmpty(p2)) & |
316 | (isTunnel(p3) || isEmpty(p3)); | 313 | (isTunnel(p3) || isEmpty(p3)); |
317 | default : return FALSE; | 314 | default : return FALSE; |
318 | } | 315 | } |
319 | } | 316 | } |
320 | 317 | ||
321 | bool Board::isJump(int pos, int dir) { | 318 | bool Board::isJump(int pos, int dir) { |
322 | switch (dir) { | 319 | switch (dir) { |
323 | case NW: return pos < BoardWidth || x(pos) == 0; | 320 | case NW: return pos < BoardWidth || x(pos) == 0; |
324 | case N: return pos < BoardWidth; | 321 | case N: return pos < BoardWidth; |
325 | case NE: return pos < BoardWidth || x(pos) == BoardWidth-1; | 322 | case NE: return pos < BoardWidth || x(pos) == BoardWidth-1; |
326 | case W: return x(pos) == 0; | 323 | case W: return x(pos) == 0; |
327 | case E: return x(pos) == BoardWidth-1; | 324 | case E: return x(pos) == BoardWidth-1; |
328 | case SW: return pos >= sz-BoardWidth || x(pos) == 0; | 325 | case SW: return pos >= sz-BoardWidth || x(pos) == 0; |
329 | case S: return pos >= sz-BoardWidth; | 326 | case S: return pos >= sz-BoardWidth; |
330 | case SE: return pos >= sz-BoardWidth || x(pos) == BoardWidth-1; | 327 | case SE: return pos >= sz-BoardWidth || x(pos) == BoardWidth-1; |
331 | } | 328 | } |
332 | return FALSE; | 329 | return FALSE; |
333 | } | 330 | } |
334 | 331 | ||
335 | int Board::move(int pos, int dir, int steps) | 332 | int Board::move(int pos, int dir, int steps) |
336 | { | 333 | { |
337 | if (steps < 0) { // move backwards | 334 | if (steps < 0) { // move backwards |
338 | dir = turn(dir); // turn around and do your steps | 335 | dir = turn(dir); // turn around and do your steps |
339 | steps *= -1; | 336 | steps *= -1; |
340 | } | 337 | } |
341 | 338 | ||
342 | while (steps-- != 0) { // until all steps are gone | 339 | while (steps-- != 0) { // until all steps are gone |
343 | switch (dir) { | 340 | switch (dir) { |
344 | case NW: pos = pos >= BoardWidth && x(pos) > 0 ? (pos-BoardWidth)-1 : sz-1; | 341 | case NW: pos = pos >= BoardWidth && x(pos) > 0 ? (pos-BoardWidth)-1 : sz-1; |
345 | break; | 342 | break; |
346 | case N: pos = pos >= BoardWidth ? pos-BoardWidth : (sz-BoardWidth)+x(pos); | 343 | case N: pos = pos >= BoardWidth ? pos-BoardWidth : (sz-BoardWidth)+x(pos); |
347 | break; | 344 | break; |
348 | case NE: pos = pos >= BoardWidth && x(pos) < BoardWidth-1 ? | 345 | case NE: pos = pos >= BoardWidth && x(pos) < BoardWidth-1 ? |
349 | (pos-BoardWidth)+1 : sz-BoardWidth; | 346 | (pos-BoardWidth)+1 : sz-BoardWidth; |
350 | break; | 347 | break; |
351 | case W: pos = x(pos) > 0 ? pos-1 : pos+(BoardWidth-1); | 348 | case W: pos = x(pos) > 0 ? pos-1 : pos+(BoardWidth-1); |
352 | break; | 349 | break; |
353 | case E: pos = x(pos) < BoardWidth-1 ? pos+1 : pos-(BoardWidth-1); | 350 | case E: pos = x(pos) < BoardWidth-1 ? pos+1 : pos-(BoardWidth-1); |
354 | break; | 351 | break; |
355 | case SW: pos = pos < sz-BoardWidth && x(pos) > 0 ? (pos+BoardWidth)-1 : BoardWidth-1; | 352 | case SW: pos = pos < sz-BoardWidth && x(pos) > 0 ? (pos+BoardWidth)-1 : BoardWidth-1; |
356 | break; | 353 | break; |
357 | case S: pos = pos < sz-BoardWidth ? pos+BoardWidth : x(pos); | 354 | case S: pos = pos < sz-BoardWidth ? pos+BoardWidth : x(pos); |
358 | break; | 355 | break; |
359 | case SE: pos = pos < sz-BoardWidth && x(pos) < BoardWidth-1 ? (pos+BoardWidth)+1 : 0; | 356 | case SE: pos = pos < sz-BoardWidth && x(pos) < BoardWidth-1 ? (pos+BoardWidth)+1 : 0; |
360 | break; | 357 | break; |
361 | } | 358 | } |
362 | } | 359 | } |
363 | return pos; // here we are | 360 | return pos; // here we are |
364 | } | 361 | } |
365 | 362 | ||
366 | int Board::closeup(int pos, int dir, int target) | 363 | int Board::closeup(int pos, int dir, int target) |
367 | { | 364 | { |
368 | if (dir == N || dir == S) { | 365 | if (dir == N || dir == S) { |
369 | if (x(target) < x(pos)) | 366 | if (x(target) < x(pos)) |
370 | return W; | 367 | return W; |
371 | if (x(target) > x(pos)) | 368 | if (x(target) > x(pos)) |
372 | return E; | 369 | return E; |
373 | } else { | 370 | } else { |
374 | if (y(target) < y(pos)) | 371 | if (y(target) < y(pos)) |
375 | return N; | 372 | return N; |
376 | if (y(target) > y(pos)) | 373 | if (y(target) > y(pos)) |
377 | return S; | 374 | return S; |
378 | } | 375 | } |
379 | return dir; | 376 | return dir; |
380 | } | 377 | } |
381 | 378 | ||
382 | int Board::x(int pos) | 379 | int Board::x(int pos) |
383 | { | 380 | { |
384 | return pos % BoardWidth; | 381 | return pos % BoardWidth; |
385 | } | 382 | } |
386 | 383 | ||
387 | int Board::y(int pos) | 384 | int Board::y(int pos) |
388 | { | 385 | { |
389 | return pos/BoardWidth; | 386 | return pos/BoardWidth; |
390 | } | 387 | } |
391 | 388 | ||
392 | int Board::turn(int dir) | 389 | int Board::turn(int dir) |
393 | { | 390 | { |
394 | switch (dir) { | 391 | switch (dir) { |
395 | case N : return S; | 392 | case N : return S; |
396 | case NE : return SW; | 393 | case NE : return SW; |
397 | case E : return W; | 394 | case E : return W; |
398 | case SE : return NW; | 395 | case SE : return NW; |
399 | case S : return N; | 396 | case S : return N; |
400 | case SW : return NE; | 397 | case SW : return NE; |
401 | case W : return E; | 398 | case W : return E; |
402 | case NW : return SE; | 399 | case NW : return SE; |
403 | default : return dir; | 400 | default : return dir; |
404 | } | 401 | } |
405 | } | 402 | } |
406 | 403 | ||
407 | int Board::points() | 404 | int Board::points() |
408 | { | 405 | { |
409 | return numPoints; | 406 | return numPoints; |
410 | } | 407 | } |
411 | 408 | ||
412 | int Board::energizers() | 409 | int Board::energizers() |
413 | { | 410 | { |
414 | return numEnergizers; | 411 | return numEnergizers; |
415 | } | 412 | } |
416 | 413 | ||
417 | int Board::monsters() | 414 | int Board::monsters() |
418 | { | 415 | { |
419 | return numMonsters; | 416 | return numMonsters; |
420 | } | 417 | } |
421 | 418 | ||
422 | int Board::tunnels() | 419 | int Board::tunnels() |
423 | { | 420 | { |
424 | return numTunnels; | 421 | return numTunnels; |
425 | } | 422 | } |
diff --git a/noncore/games/kpacman/keys.cpp b/noncore/games/kpacman/keys.cpp index 07ce135..5200bc2 100644 --- a/noncore/games/kpacman/keys.cpp +++ b/noncore/games/kpacman/keys.cpp | |||
@@ -1,205 +1,200 @@ | |||
1 | 1 | ||
2 | #include "portable.h" | 2 | #include "portable.h" |
3 | 3 | ||
4 | #if defined( KDE2_PORT ) | 4 | #if defined( KDE2_PORT ) |
5 | #include <kapp.h> | 5 | #include <kapp.h> |
6 | #include <kconfig.h> | 6 | #include <kconfig.h> |
7 | #include <klocale.h> | 7 | #include <klocale.h> |
8 | #include <kstddirs.h> | 8 | #include <kstddirs.h> |
9 | #include <kaccel.h> | 9 | #include <kaccel.h> |
10 | 10 | ||
11 | #include <keys.h> | 11 | #include <keys.h> |
12 | #include <keys.moc> | 12 | #include <keys.moc> |
13 | #elif defined( QPE_PORT ) | 13 | #elif defined( QPE_PORT ) |
14 | #include <qaccel.h> | 14 | #include <qaccel.h> |
15 | #include <qpe/qpeapplication.h> | 15 | #include <qpe/qpeapplication.h> |
16 | #include <qpe/config.h> | 16 | #include <qpe/config.h> |
17 | #include "keys.h" | 17 | #include "keys.h" |
18 | #endif | 18 | #endif |
19 | 19 | ||
20 | #include <qpushbt.h> | 20 | #include <qpushbt.h> |
21 | #include <qlabel.h> | ||
22 | #include <qframe.h> | ||
23 | #include <qkeycode.h> | ||
24 | #include <qpixmap.h> | ||
25 | #include <qstring.h> | ||
26 | 21 | ||
27 | Keys::Keys( QWidget *parent, const char *name) | 22 | Keys::Keys( QWidget *parent, const char *name) |
28 | : QDialog( parent, name, TRUE ) | 23 | : QDialog( parent, name, TRUE ) |
29 | { | 24 | { |
30 | //KStandardDirs *dirs = KGlobal::dirs(); | 25 | //KStandardDirs *dirs = KGlobal::dirs(); |
31 | 26 | ||
32 | QPushButton *okButton = new QPushButton(this); | 27 | QPushButton *okButton = new QPushButton(this); |
33 | okButton->setText(tr("Ok")); | 28 | okButton->setText(tr("Ok")); |
34 | okButton->setFixedSize(okButton->size()); | 29 | okButton->setFixedSize(okButton->size()); |
35 | connect( okButton, SIGNAL(clicked()),this, SLOT(ok()) ); | 30 | connect( okButton, SIGNAL(clicked()),this, SLOT(ok()) ); |
36 | okButton->move(20,210); | 31 | okButton->move(20,210); |
37 | 32 | ||
38 | QPushButton *defaultButton = new QPushButton(this); | 33 | QPushButton *defaultButton = new QPushButton(this); |
39 | defaultButton->setText(tr("Defaults")); | 34 | defaultButton->setText(tr("Defaults")); |
40 | defaultButton->setFixedSize(defaultButton->size()); | 35 | defaultButton->setFixedSize(defaultButton->size()); |
41 | connect( defaultButton, SIGNAL(clicked()),this, SLOT(defaults()) ); | 36 | connect( defaultButton, SIGNAL(clicked()),this, SLOT(defaults()) ); |
42 | defaultButton->move(140,210); | 37 | defaultButton->move(140,210); |
43 | 38 | ||
44 | QPushButton *cancelButton = new QPushButton(this); | 39 | QPushButton *cancelButton = new QPushButton(this); |
45 | cancelButton->setText(tr("Cancel")); | 40 | cancelButton->setText(tr("Cancel")); |
46 | cancelButton->setFixedSize(cancelButton->size()); | 41 | cancelButton->setFixedSize(cancelButton->size()); |
47 | connect( cancelButton, SIGNAL(clicked()),this, SLOT(reject()) ); | 42 | connect( cancelButton, SIGNAL(clicked()),this, SLOT(reject()) ); |
48 | cancelButton->move(260,210); | 43 | cancelButton->move(260,210); |
49 | 44 | ||
50 | QFrame *separator = new QFrame(this); | 45 | QFrame *separator = new QFrame(this); |
51 | separator->setFrameStyle( QFrame::HLine | QFrame::Sunken ); | 46 | separator->setFrameStyle( QFrame::HLine | QFrame::Sunken ); |
52 | separator->setGeometry( 20, 190, 340, 4 ); | 47 | separator->setGeometry( 20, 190, 340, 4 ); |
53 | 48 | ||
54 | for ( int x = 0; x < 4; x++) { | 49 | for ( int x = 0; x < 4; x++) { |
55 | QLabel *l = new QLabel(this); | 50 | QLabel *l = new QLabel(this); |
56 | l->setAlignment(AlignCenter); | 51 | l->setAlignment(AlignCenter); |
57 | labels[x] = l; | 52 | labels[x] = l; |
58 | } | 53 | } |
59 | 54 | ||
60 | labels[0]->setGeometry(120, 20, 140, 20 ); | 55 | labels[0]->setGeometry(120, 20, 140, 20 ); |
61 | labels[1]->setGeometry(120,160, 140, 20 ); | 56 | labels[1]->setGeometry(120,160, 140, 20 ); |
62 | labels[2]->setGeometry( 20, 92, 100, 20 ); | 57 | labels[2]->setGeometry( 20, 92, 100, 20 ); |
63 | labels[3]->setGeometry(265, 92, 100, 20 ); | 58 | labels[3]->setGeometry(265, 92, 100, 20 ); |
64 | 59 | ||
65 | QString pixPath; | 60 | QString pixPath; |
66 | 61 | ||
67 | QPushButton *up = new QPushButton(this); | 62 | QPushButton *up = new QPushButton(this); |
68 | pixPath = FIND_APP_DATA( "pics/up.xpm" ); | 63 | pixPath = FIND_APP_DATA( "pics/up.xpm" ); |
69 | up->setPixmap( QPixmap(pixPath)); | 64 | up->setPixmap( QPixmap(pixPath)); |
70 | up->setFixedSize(up->pixmap()->size()); | 65 | up->setFixedSize(up->pixmap()->size()); |
71 | connect( up, SIGNAL(clicked()),this, SLOT(butUp()) ); | 66 | connect( up, SIGNAL(clicked()),this, SLOT(butUp()) ); |
72 | up->move(180, 50); | 67 | up->move(180, 50); |
73 | 68 | ||
74 | QPushButton *down = new QPushButton(this); | 69 | QPushButton *down = new QPushButton(this); |
75 | pixPath = FIND_APP_DATA( "pics/down.xpm"); | 70 | pixPath = FIND_APP_DATA( "pics/down.xpm"); |
76 | down->setPixmap( QPixmap(pixPath)); | 71 | down->setPixmap( QPixmap(pixPath)); |
77 | down->setFixedSize(down->pixmap()->size()); | 72 | down->setFixedSize(down->pixmap()->size()); |
78 | connect( down, SIGNAL(clicked()),this, SLOT(butDown()) ); | 73 | connect( down, SIGNAL(clicked()),this, SLOT(butDown()) ); |
79 | down->move(180, 130); | 74 | down->move(180, 130); |
80 | 75 | ||
81 | QPushButton *left = new QPushButton(this); | 76 | QPushButton *left = new QPushButton(this); |
82 | pixPath = FIND_APP_DATA( "pics/left.xpm"); | 77 | pixPath = FIND_APP_DATA( "pics/left.xpm"); |
83 | left->setPixmap( QPixmap(pixPath)); | 78 | left->setPixmap( QPixmap(pixPath)); |
84 | left->setFixedSize(left->pixmap()->size()); | 79 | left->setFixedSize(left->pixmap()->size()); |
85 | connect( left, SIGNAL(clicked()),this, SLOT(butLeft()) ); | 80 | connect( left, SIGNAL(clicked()),this, SLOT(butLeft()) ); |
86 | left->move(140, 90); | 81 | left->move(140, 90); |
87 | 82 | ||
88 | QPushButton *right = new QPushButton(this); | 83 | QPushButton *right = new QPushButton(this); |
89 | pixPath = FIND_APP_DATA( "pics/right.xpm"); | 84 | pixPath = FIND_APP_DATA( "pics/right.xpm"); |
90 | right->setPixmap( QPixmap(pixPath)); | 85 | right->setPixmap( QPixmap(pixPath)); |
91 | right->setFixedSize(right->pixmap()->size()); | 86 | right->setFixedSize(right->pixmap()->size()); |
92 | connect( right, SIGNAL(clicked()),this, SLOT(butRight()) ); | 87 | connect( right, SIGNAL(clicked()),this, SLOT(butRight()) ); |
93 | right->move(220, 90); | 88 | right->move(220, 90); |
94 | 89 | ||
95 | 90 | ||
96 | setCaption(tr("Change Direction Keys")); | 91 | setCaption(tr("Change Direction Keys")); |
97 | setFixedSize(380, 260); | 92 | setFixedSize(380, 260); |
98 | lab = 0; | 93 | lab = 0; |
99 | init(); | 94 | init(); |
100 | } | 95 | } |
101 | 96 | ||
102 | void Keys::keyPressEvent( QKeyEvent *e ) | 97 | void Keys::keyPressEvent( QKeyEvent *e ) |
103 | { | 98 | { |
104 | uint kCode = e->key() & ~(SHIFT | CTRL | ALT); | 99 | uint kCode = e->key() & ~(SHIFT | CTRL | ALT); |
105 | QString string = KAccel::keyToString(kCode); | 100 | QString string = KAccel::keyToString(kCode); |
106 | 101 | ||
107 | if (lab != 0) { | 102 | if (lab != 0) { |
108 | if ( string.isNull() ) | 103 | if ( string.isNull() ) |
109 | lab->setText(tr("Undefined key")); | 104 | lab->setText(tr("Undefined key")); |
110 | else | 105 | else |
111 | lab->setText(string); | 106 | lab->setText(string); |
112 | } | 107 | } |
113 | else if ( lab == 0 && e->key() == Key_Escape) | 108 | else if ( lab == 0 && e->key() == Key_Escape) |
114 | reject(); | 109 | reject(); |
115 | } | 110 | } |
116 | 111 | ||
117 | void Keys::butUp() | 112 | void Keys::butUp() |
118 | { | 113 | { |
119 | getKey(0); | 114 | getKey(0); |
120 | } | 115 | } |
121 | 116 | ||
122 | void Keys::butDown() | 117 | void Keys::butDown() |
123 | { | 118 | { |
124 | getKey(1); | 119 | getKey(1); |
125 | } | 120 | } |
126 | 121 | ||
127 | void Keys::butLeft() | 122 | void Keys::butLeft() |
128 | { | 123 | { |
129 | getKey(2); | 124 | getKey(2); |
130 | } | 125 | } |
131 | 126 | ||
132 | void Keys::butRight() | 127 | void Keys::butRight() |
133 | { | 128 | { |
134 | getKey(3); | 129 | getKey(3); |
135 | } | 130 | } |
136 | 131 | ||
137 | void Keys::getKey(int i) | 132 | void Keys::getKey(int i) |
138 | { | 133 | { |
139 | if ( lab != 0) | 134 | if ( lab != 0) |
140 | focusOut(lab); | 135 | focusOut(lab); |
141 | 136 | ||
142 | focusIn(labels[i]); | 137 | focusIn(labels[i]); |
143 | } | 138 | } |
144 | 139 | ||
145 | void Keys::focusOut(QLabel *l) | 140 | void Keys::focusOut(QLabel *l) |
146 | { | 141 | { |
147 | l->setFrameStyle( QFrame::NoFrame ); | 142 | l->setFrameStyle( QFrame::NoFrame ); |
148 | l->setBackgroundColor(backgroundColor()); | 143 | l->setBackgroundColor(backgroundColor()); |
149 | l->repaint(); | 144 | l->repaint(); |
150 | } | 145 | } |
151 | 146 | ||
152 | void Keys::focusIn(QLabel *l) | 147 | void Keys::focusIn(QLabel *l) |
153 | { | 148 | { |
154 | lab = l; | 149 | lab = l; |
155 | lab->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 150 | lab->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
156 | lab->setBackgroundColor(white); | 151 | lab->setBackgroundColor(white); |
157 | lab->repaint(); | 152 | lab->repaint(); |
158 | } | 153 | } |
159 | 154 | ||
160 | void Keys::defaults() | 155 | void Keys::defaults() |
161 | { | 156 | { |
162 | if ( lab != 0) | 157 | if ( lab != 0) |
163 | focusOut(lab); | 158 | focusOut(lab); |
164 | 159 | ||
165 | lab = 0; | 160 | lab = 0; |
166 | 161 | ||
167 | labels[0]->setText("Up"); | 162 | labels[0]->setText("Up"); |
168 | labels[1]->setText("Down"); | 163 | labels[1]->setText("Down"); |
169 | labels[2]->setText("Left"); | 164 | labels[2]->setText("Left"); |
170 | labels[3]->setText("Right"); | 165 | labels[3]->setText("Right"); |
171 | } | 166 | } |
172 | 167 | ||
173 | void Keys::init() | 168 | void Keys::init() |
174 | { | 169 | { |
175 | APP_CONFIG_BEGIN( cfg ); | 170 | APP_CONFIG_BEGIN( cfg ); |
176 | QString up("Up"); | 171 | QString up("Up"); |
177 | up = cfg->readEntry("upKey", (const char*) up); | 172 | up = cfg->readEntry("upKey", (const char*) up); |
178 | labels[0]->setText(up); | 173 | labels[0]->setText(up); |
179 | 174 | ||
180 | QString down("Down"); | 175 | QString down("Down"); |
181 | down = cfg->readEntry("downKey", (const char*) down); | 176 | down = cfg->readEntry("downKey", (const char*) down); |
182 | labels[1]->setText(down); | 177 | labels[1]->setText(down); |
183 | 178 | ||
184 | QString left("Left"); | 179 | QString left("Left"); |
185 | left = cfg->readEntry("leftKey", (const char*) left); | 180 | left = cfg->readEntry("leftKey", (const char*) left); |
186 | labels[2]->setText(left); | 181 | labels[2]->setText(left); |
187 | 182 | ||
188 | QString right("Right"); | 183 | QString right("Right"); |
189 | right = cfg->readEntry("rightKey", (const char*) right); | 184 | right = cfg->readEntry("rightKey", (const char*) right); |
190 | labels[3]->setText(right); | 185 | labels[3]->setText(right); |
191 | APP_CONFIG_END( cfg ); | 186 | APP_CONFIG_END( cfg ); |
192 | } | 187 | } |
193 | 188 | ||
194 | void Keys::ok() | 189 | void Keys::ok() |
195 | { | 190 | { |
196 | /* | 191 | /* |
197 | APP_CONFIG_BEGIN( cfg ); | 192 | APP_CONFIG_BEGIN( cfg ); |
198 | cfg->writeEntry("upKey", (const char*) labels[0]->text() ); | 193 | cfg->writeEntry("upKey", (const char*) labels[0]->text() ); |
199 | cfg->writeEntry("downKey", (const char*) labels[1]->text() ); | 194 | cfg->writeEntry("downKey", (const char*) labels[1]->text() ); |
200 | cfg->writeEntry("leftKey", (const char*) labels[2]->text() ); | 195 | cfg->writeEntry("leftKey", (const char*) labels[2]->text() ); |
201 | cfg->writeEntry("rightKey",(const char*) labels[3]->text() ); | 196 | cfg->writeEntry("rightKey",(const char*) labels[3]->text() ); |
202 | APP_CONFIG_END( cfg ); | 197 | APP_CONFIG_END( cfg ); |
203 | */ | 198 | */ |
204 | accept(); | 199 | accept(); |
205 | } | 200 | } |
diff --git a/noncore/games/kpacman/kpacman.cpp b/noncore/games/kpacman/kpacman.cpp index df27c76..be2e46d 100644 --- a/noncore/games/kpacman/kpacman.cpp +++ b/noncore/games/kpacman/kpacman.cpp | |||
@@ -1,368 +1,363 @@ | |||
1 | 1 | ||
2 | #include "portable.h" | 2 | #include "portable.h" |
3 | 3 | ||
4 | #if defined( KDE2_PORT ) | 4 | #if defined( KDE2_PORT ) |
5 | #include <kpacman.h> | 5 | #include <kpacman.h> |
6 | #include <kpacman.moc> | 6 | #include <kpacman.moc> |
7 | #include <kcolordlg.h> | 7 | #include <kcolordlg.h> |
8 | #elif defined( QPE_PORT ) | 8 | #elif defined( QPE_PORT ) |
9 | #include <qmenubar.h> | 9 | #include <qmenubar.h> |
10 | #include <qpe/config.h> | 10 | #include <qpe/config.h> |
11 | #include <qapplication.h> | 11 | #include <qapplication.h> |
12 | #include "kpacman.h" | 12 | #include "kpacman.h" |
13 | #endif | 13 | #endif |
14 | 14 | ||
15 | #include <qkeycode.h> | ||
16 | #include <qcolor.h> | ||
17 | #include <qstring.h> | ||
18 | #include <qpopmenu.h> | ||
19 | #include <qmsgbox.h> | ||
20 | 15 | ||
21 | Kpacman::Kpacman(QWidget *parent, const char *name) | 16 | Kpacman::Kpacman(QWidget *parent, const char *name) |
22 | : KTMainWindow(parent, name) | 17 | : KTMainWindow(parent, name) |
23 | { | 18 | { |
24 | schemesPopup = new QList<QPopupMenu>; | 19 | schemesPopup = new QList<QPopupMenu>; |
25 | schemesPopup->setAutoDelete(TRUE); | 20 | schemesPopup->setAutoDelete(TRUE); |
26 | 21 | ||
27 | menu(); | 22 | menu(); |
28 | 23 | ||
29 | m_view = new QWidget( this, "m_view" ); | 24 | m_view = new QWidget( this, "m_view" ); |
30 | m_view->setBackgroundColor( black ); | 25 | m_view->setBackgroundColor( black ); |
31 | m_layout = new QGridLayout( m_view ); | 26 | m_layout = new QGridLayout( m_view ); |
32 | m_layout->setMargin( 7 ); | 27 | m_layout->setMargin( 7 ); |
33 | 28 | ||
34 | view = new KpacmanWidget( this, QString(name)+"widget"); | 29 | view = new KpacmanWidget( this, QString(name)+"widget"); |
35 | m_layout->addWidget( view, 0, 0 ); | 30 | m_layout->addWidget( view, 0, 0 ); |
36 | 31 | ||
37 | setCaption( tr("KPacman") ); | 32 | setCaption( tr("KPacman") ); |
38 | 33 | ||
39 | view->referee->setFocus(); | 34 | view->referee->setFocus(); |
40 | 35 | ||
41 | connect(view->referee, SIGNAL(setScore(int, int)), | 36 | connect(view->referee, SIGNAL(setScore(int, int)), |
42 | view->score, SLOT(setScore(int, int))); | 37 | view->score, SLOT(setScore(int, int))); |
43 | connect(view->referee, SIGNAL(setPoints(int)), | 38 | connect(view->referee, SIGNAL(setPoints(int)), |
44 | view->score, SLOT(set(int))); | 39 | view->score, SLOT(set(int))); |
45 | connect(view->referee, SIGNAL(setLifes(int)), | 40 | connect(view->referee, SIGNAL(setLifes(int)), |
46 | view->status, SLOT(setLifes(int))); | 41 | view->status, SLOT(setLifes(int))); |
47 | connect(view->referee, SIGNAL(setLevel(int)), | 42 | connect(view->referee, SIGNAL(setLevel(int)), |
48 | view->status, SLOT(setLevel(int))); | 43 | view->status, SLOT(setLevel(int))); |
49 | connect(view->referee, SIGNAL(forcedHallOfFame(bool)), | 44 | connect(view->referee, SIGNAL(forcedHallOfFame(bool)), |
50 | this, SLOT(forcedHallOfFame(bool))); | 45 | this, SLOT(forcedHallOfFame(bool))); |
51 | connect(view->referee, SIGNAL(togglePaused()), this, SLOT(togglePaused())); | 46 | connect(view->referee, SIGNAL(togglePaused()), this, SLOT(togglePaused())); |
52 | connect(view->referee, SIGNAL(toggleNew()), this, SLOT(toggleNew())); | 47 | connect(view->referee, SIGNAL(toggleNew()), this, SLOT(toggleNew())); |
53 | 48 | ||
54 | connect(view->score, SIGNAL(toggleNew()), this, SLOT(toggleNew())); | 49 | connect(view->score, SIGNAL(toggleNew()), this, SLOT(toggleNew())); |
55 | connect(view->score, SIGNAL(forcedHallOfFame(bool)), | 50 | connect(view->score, SIGNAL(forcedHallOfFame(bool)), |
56 | this, SLOT(forcedHallOfFame(bool))); | 51 | this, SLOT(forcedHallOfFame(bool))); |
57 | 52 | ||
58 | APP_CONFIG_BEGIN( cfg ); | 53 | APP_CONFIG_BEGIN( cfg ); |
59 | focusOutPause = !cfg->readBoolEntry("FocusOutPause", TRUE); | 54 | focusOutPause = !cfg->readBoolEntry("FocusOutPause", TRUE); |
60 | focusInContinue = !cfg->readBoolEntry("FocusInContinue", TRUE); | 55 | focusInContinue = !cfg->readBoolEntry("FocusInContinue", TRUE); |
61 | hideMouseCursor = !cfg->readBoolEntry("HideMouseCursor", TRUE); | 56 | hideMouseCursor = !cfg->readBoolEntry("HideMouseCursor", TRUE); |
62 | APP_CONFIG_END( cfg ); | 57 | APP_CONFIG_END( cfg ); |
63 | 58 | ||
64 | toggleFocusOutPause(); | 59 | toggleFocusOutPause(); |
65 | toggleFocusInContinue(); | 60 | toggleFocusInContinue(); |
66 | toggleHideMouseCursor(); | 61 | toggleHideMouseCursor(); |
67 | 62 | ||
68 | setCentralWidget( m_view ); | 63 | setCentralWidget( m_view ); |
69 | } | 64 | } |
70 | 65 | ||
71 | Kpacman::~Kpacman() | 66 | Kpacman::~Kpacman() |
72 | { | 67 | { |
73 | /* APP_CONFIG_BEGIN( cfg ); | 68 | /* APP_CONFIG_BEGIN( cfg ); |
74 | cfg->writeEntry("FocusOutPause", focusOutPause); | 69 | cfg->writeEntry("FocusOutPause", focusOutPause); |
75 | cfg->writeEntry("FocusInContinue", focusInContinue); | 70 | cfg->writeEntry("FocusInContinue", focusInContinue); |
76 | cfg->writeEntry("HideMouseCursor", hideMouseCursor); | 71 | cfg->writeEntry("HideMouseCursor", hideMouseCursor); |
77 | APP_CONFIG_END( cfg ); | 72 | APP_CONFIG_END( cfg ); |
78 | */ | 73 | */ |
79 | delete _menuBar; | 74 | delete _menuBar; |
80 | } | 75 | } |
81 | 76 | ||
82 | void Kpacman::menu() | 77 | void Kpacman::menu() |
83 | { | 78 | { |
84 | gamePopup = new QPopupMenu(); | 79 | gamePopup = new QPopupMenu(); |
85 | CHECK_PTR( gamePopup ); | 80 | CHECK_PTR( gamePopup ); |
86 | newID = gamePopup->insertItem(tr("&New"), this, SLOT(newKpacman()),Key_F2); | 81 | newID = gamePopup->insertItem(tr("&New"), this, SLOT(newKpacman()),Key_F2); |
87 | pauseID = gamePopup->insertItem(tr("&Pause"), | 82 | pauseID = gamePopup->insertItem(tr("&Pause"), |
88 | this, SLOT(pauseKpacman()), Key_F3); | 83 | this, SLOT(pauseKpacman()), Key_F3); |
89 | hofID = gamePopup->insertItem(tr("&Hall of fame"), | 84 | hofID = gamePopup->insertItem(tr("&Hall of fame"), |
90 | this, SLOT(toggleHallOfFame()), Key_F4); | 85 | this, SLOT(toggleHallOfFame()), Key_F4); |
91 | gamePopup->insertSeparator(); | 86 | gamePopup->insertSeparator(); |
92 | gamePopup->insertItem(tr("&Quit"), this, SLOT(quitKpacman()), CTRL+Key_Q); | 87 | gamePopup->insertItem(tr("&Quit"), this, SLOT(quitKpacman()), CTRL+Key_Q); |
93 | gamePopup->setCheckable(TRUE); | 88 | gamePopup->setCheckable(TRUE); |
94 | 89 | ||
95 | optionsPopup = new QPopupMenu(); | 90 | optionsPopup = new QPopupMenu(); |
96 | CHECK_PTR(optionsPopup); | 91 | CHECK_PTR(optionsPopup); |
97 | 92 | ||
98 | modesPopup = new QPopupMenu(); | 93 | modesPopup = new QPopupMenu(); |
99 | CHECK_PTR(modesPopup); | 94 | CHECK_PTR(modesPopup); |
100 | 95 | ||
101 | hideMouseCursorID = optionsPopup->insertItem(tr("&Hide Mousecursor"), | 96 | hideMouseCursorID = optionsPopup->insertItem(tr("&Hide Mousecursor"), |
102 | this, SLOT(toggleHideMouseCursor()), | 97 | this, SLOT(toggleHideMouseCursor()), |
103 | CTRL+Key_H); | 98 | CTRL+Key_H); |
104 | optionsPopup->insertSeparator(); | 99 | optionsPopup->insertSeparator(); |
105 | 100 | ||
106 | if (lookupSchemes() > 0) { | 101 | if (lookupSchemes() > 0) { |
107 | optionsPopup->insertItem(tr("&Select graphic scheme"), modesPopup); | 102 | optionsPopup->insertItem(tr("&Select graphic scheme"), modesPopup); |
108 | optionsPopup->insertSeparator(); | 103 | optionsPopup->insertSeparator(); |
109 | } | 104 | } |
110 | 105 | ||
111 | focusOutPauseID = optionsPopup->insertItem(tr("&Pause in Background"), | 106 | focusOutPauseID = optionsPopup->insertItem(tr("&Pause in Background"), |
112 | this, SLOT(toggleFocusOutPause())); | 107 | this, SLOT(toggleFocusOutPause())); |
113 | focusInContinueID = optionsPopup->insertItem(tr("&Continue in Foreground"), | 108 | focusInContinueID = optionsPopup->insertItem(tr("&Continue in Foreground"), |
114 | this, SLOT(toggleFocusInContinue())); | 109 | this, SLOT(toggleFocusInContinue())); |
115 | optionsPopup->insertSeparator(); | 110 | optionsPopup->insertSeparator(); |
116 | 111 | ||
117 | optionsPopup->insertItem(tr("Change &keys..."), this, SLOT(confKeys())); | 112 | optionsPopup->insertItem(tr("Change &keys..."), this, SLOT(confKeys())); |
118 | 113 | ||
119 | #ifndef QPE_PORT | 114 | #ifndef QPE_PORT |
120 | QString aboutText = tr("@PACKAGE@ - @VERSION@\n\n" | 115 | QString aboutText = tr("@PACKAGE@ - @VERSION@\n\n" |
121 | "Joerg Thoennissen (joe@dsite.de)\n\n" | 116 | "Joerg Thoennissen (joe@dsite.de)\n\n" |
122 | "A pacman game for the KDE Desktop\n\n" | 117 | "A pacman game for the KDE Desktop\n\n" |
123 | "The program based on the source of ksnake\n" | 118 | "The program based on the source of ksnake\n" |
124 | "by Michel Filippi (mfilippi@sade.rhein-main.de).\n" | 119 | "by Michel Filippi (mfilippi@sade.rhein-main.de).\n" |
125 | "The design was strongly influenced by the pacman\n" | 120 | "The design was strongly influenced by the pacman\n" |
126 | "(c) 1980 MIDWAY MFG.CO.\n\n" | 121 | "(c) 1980 MIDWAY MFG.CO.\n\n" |
127 | "I like to thank my girlfriend Elke Krueers for\n" | 122 | "I like to thank my girlfriend Elke Krueers for\n" |
128 | "the last 10 years of her friendship.\n"); | 123 | "the last 10 years of her friendship.\n"); |
129 | aboutText.replace(QRegExp("@PACKAGE@"), PACKAGE); | 124 | aboutText.replace(QRegExp("@PACKAGE@"), PACKAGE); |
130 | aboutText.replace(QRegExp("@VERSION@"), VERSION); | 125 | aboutText.replace(QRegExp("@VERSION@"), VERSION); |
131 | QPopupMenu *helpPopup = helpMenu(aboutText, FALSE); | 126 | QPopupMenu *helpPopup = helpMenu(aboutText, FALSE); |
132 | #endif | 127 | #endif |
133 | 128 | ||
134 | //_menuBar = new KMenuBar(this); | 129 | //_menuBar = new KMenuBar(this); |
135 | //CHECK_PTR( _menuBar ); | 130 | //CHECK_PTR( _menuBar ); |
136 | //_menuBar->insertItem(tr("&Game"), gamePopup); | 131 | //_menuBar->insertItem(tr("&Game"), gamePopup); |
137 | //_menuBar->insertItem(tr("&Options"), optionsPopup); | 132 | //_menuBar->insertItem(tr("&Options"), optionsPopup); |
138 | //_menuBar->insertSeparator(); | 133 | //_menuBar->insertSeparator(); |
139 | #ifndef QPE_PORT | 134 | #ifndef QPE_PORT |
140 | _menuBar->insertItem(tr("&Help"), helpPopup); | 135 | _menuBar->insertItem(tr("&Help"), helpPopup); |
141 | #endif | 136 | #endif |
142 | } | 137 | } |
143 | 138 | ||
144 | int Kpacman::lookupSchemes() | 139 | int Kpacman::lookupSchemes() |
145 | { | 140 | { |
146 | APP_CONFIG_BEGIN( cfg ); | 141 | APP_CONFIG_BEGIN( cfg ); |
147 | int ModeCount = cfg->readNumEntry("ModeCount", 0); | 142 | int ModeCount = cfg->readNumEntry("ModeCount", 0); |
148 | int Mode = cfg->readNumEntry("Mode", 0); | 143 | int Mode = cfg->readNumEntry("Mode", 0); |
149 | int SchemeCount = cfg->readNumEntry("SchemeCount", 0); | 144 | int SchemeCount = cfg->readNumEntry("SchemeCount", 0); |
150 | int Scheme = cfg->readNumEntry("Scheme", 0); | 145 | int Scheme = cfg->readNumEntry("Scheme", 0); |
151 | 146 | ||
152 | /* | 147 | /* |
153 | if (SchemeCount == 0 || Scheme == -1) { | 148 | if (SchemeCount == 0 || Scheme == -1) { |
154 | QMessageBox::warning(this, tr("Configuration Error"), | 149 | QMessageBox::warning(this, tr("Configuration Error"), |
155 | tr("There are no schemes defined,\n" | 150 | tr("There are no schemes defined,\n" |
156 | "or no scheme is selected.")); | 151 | "or no scheme is selected.")); |
157 | APP_CONFIG_END( cfg ); | 152 | APP_CONFIG_END( cfg ); |
158 | return 0; | 153 | return 0; |
159 | } | 154 | } |
160 | */ | 155 | */ |
161 | 156 | ||
162 | connect(modesPopup, SIGNAL(activated(int)), this, SLOT(schemeChecked(int))); | 157 | connect(modesPopup, SIGNAL(activated(int)), this, SLOT(schemeChecked(int))); |
163 | modeID.resize(ModeCount > 0 ? ModeCount : 0); | 158 | modeID.resize(ModeCount > 0 ? ModeCount : 0); |
164 | 159 | ||
165 | if (!schemesPopup->isEmpty()) | 160 | if (!schemesPopup->isEmpty()) |
166 | schemesPopup->clear(); | 161 | schemesPopup->clear(); |
167 | 162 | ||
168 | SAVE_CONFIG_GROUP( cfg, oldgroup ); | 163 | SAVE_CONFIG_GROUP( cfg, oldgroup ); |
169 | 164 | ||
170 | QString ModeGroup; | 165 | QString ModeGroup; |
171 | QString ModeName; | 166 | QString ModeName; |
172 | 167 | ||
173 | for (int m = 0; m < ModeCount; m++) { | 168 | for (int m = 0; m < ModeCount; m++) { |
174 | ModeGroup.sprintf("Mode %d", m); | 169 | ModeGroup.sprintf("Mode %d", m); |
175 | cfg->setGroup(ModeGroup); | 170 | cfg->setGroup(ModeGroup); |
176 | 171 | ||
177 | ModeName = cfg->readEntry("Description", ModeGroup); | 172 | ModeName = cfg->readEntry("Description", ModeGroup); |
178 | 173 | ||
179 | QPopupMenu *p = new QPopupMenu; | 174 | QPopupMenu *p = new QPopupMenu; |
180 | p->setCheckable(TRUE); | 175 | p->setCheckable(TRUE); |
181 | connect(p, SIGNAL(activated(int)), this, SLOT(schemeChecked(int))); | 176 | connect(p, SIGNAL(activated(int)), this, SLOT(schemeChecked(int))); |
182 | schemesPopup->append(p); | 177 | schemesPopup->append(p); |
183 | 178 | ||
184 | modeID[m] = modesPopup->insertItem(ModeName, schemesPopup->at(m)); | 179 | modeID[m] = modesPopup->insertItem(ModeName, schemesPopup->at(m)); |
185 | modesPopup->setItemEnabled(modeID[m], FALSE); | 180 | modesPopup->setItemEnabled(modeID[m], FALSE); |
186 | modesPopup->setItemChecked(modeID[m], m == Mode); | 181 | modesPopup->setItemChecked(modeID[m], m == Mode); |
187 | } | 182 | } |
188 | 183 | ||
189 | schemeID.resize(SchemeCount); | 184 | schemeID.resize(SchemeCount); |
190 | schemeMode.resize(SchemeCount); | 185 | schemeMode.resize(SchemeCount); |
191 | 186 | ||
192 | QString SchemeGroup; | 187 | QString SchemeGroup; |
193 | QString SchemeName; | 188 | QString SchemeName; |
194 | int SchemeMode; | 189 | int SchemeMode; |
195 | 190 | ||
196 | for (int i = 0; i < SchemeCount; i++) { | 191 | for (int i = 0; i < SchemeCount; i++) { |
197 | SchemeGroup.sprintf("Scheme %d", i); | 192 | SchemeGroup.sprintf("Scheme %d", i); |
198 | cfg->setGroup(SchemeGroup); | 193 | cfg->setGroup(SchemeGroup); |
199 | 194 | ||
200 | SchemeName = cfg->readEntry("Description", SchemeGroup); | 195 | SchemeName = cfg->readEntry("Description", SchemeGroup); |
201 | SchemeMode = cfg->readNumEntry("Mode", -1); | 196 | SchemeMode = cfg->readNumEntry("Mode", -1); |
202 | 197 | ||
203 | schemeMode[i] = SchemeMode; | 198 | schemeMode[i] = SchemeMode; |
204 | if (SchemeMode == -1) { | 199 | if (SchemeMode == -1) { |
205 | schemeID[i] = modesPopup->insertItem(SchemeName); | 200 | schemeID[i] = modesPopup->insertItem(SchemeName); |
206 | modesPopup->setItemChecked(schemeID[i], i == Scheme); | 201 | modesPopup->setItemChecked(schemeID[i], i == Scheme); |
207 | } else { | 202 | } else { |
208 | schemeID[i] = schemesPopup->at(SchemeMode)->insertItem(SchemeName); | 203 | schemeID[i] = schemesPopup->at(SchemeMode)->insertItem(SchemeName); |
209 | schemesPopup->at(SchemeMode)-> | 204 | schemesPopup->at(SchemeMode)-> |
210 | setItemChecked(schemeID[i], i == Scheme); | 205 | setItemChecked(schemeID[i], i == Scheme); |
211 | modesPopup->setItemEnabled(modeID[SchemeMode], TRUE); | 206 | modesPopup->setItemEnabled(modeID[SchemeMode], TRUE); |
212 | } | 207 | } |
213 | } | 208 | } |
214 | 209 | ||
215 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 210 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
216 | 211 | ||
217 | APP_CONFIG_END( cfg ); | 212 | APP_CONFIG_END( cfg ); |
218 | return SchemeCount; | 213 | return SchemeCount; |
219 | } | 214 | } |
220 | 215 | ||
221 | void Kpacman::quitKpacman() | 216 | void Kpacman::quitKpacman() |
222 | { | 217 | { |
223 | APP_QUIT(); | 218 | APP_QUIT(); |
224 | } | 219 | } |
225 | 220 | ||
226 | void Kpacman::newKpacman() | 221 | void Kpacman::newKpacman() |
227 | { | 222 | { |
228 | if (!gamePopup->isItemEnabled(hofID)) | 223 | if (!gamePopup->isItemEnabled(hofID)) |
229 | gamePopup->setItemEnabled(hofID, TRUE); | 224 | gamePopup->setItemEnabled(hofID, TRUE); |
230 | 225 | ||
231 | if (gamePopup->isItemChecked(hofID)) | 226 | if (gamePopup->isItemChecked(hofID)) |
232 | toggleHallOfFame(); | 227 | toggleHallOfFame(); |
233 | 228 | ||
234 | if (gamePopup->isItemChecked(pauseID)) | 229 | if (gamePopup->isItemChecked(pauseID)) |
235 | pauseKpacman(); | 230 | pauseKpacman(); |
236 | 231 | ||
237 | view->referee->play(); | 232 | view->referee->play(); |
238 | } | 233 | } |
239 | 234 | ||
240 | void Kpacman::pauseKpacman() | 235 | void Kpacman::pauseKpacman() |
241 | { | 236 | { |
242 | view->referee->pause(); | 237 | view->referee->pause(); |
243 | view->score->setPause(gamePopup->isItemChecked(pauseID)); | 238 | view->score->setPause(gamePopup->isItemChecked(pauseID)); |
244 | } | 239 | } |
245 | 240 | ||
246 | void Kpacman::toggleHallOfFame() | 241 | void Kpacman::toggleHallOfFame() |
247 | { | 242 | { |
248 | gamePopup->setItemChecked(hofID, !gamePopup->isItemChecked(hofID)); | 243 | gamePopup->setItemChecked(hofID, !gamePopup->isItemChecked(hofID)); |
249 | view->referee->toggleHallOfFame(); | 244 | view->referee->toggleHallOfFame(); |
250 | 245 | ||
251 | if (gamePopup->isItemChecked(hofID)) { | 246 | if (gamePopup->isItemChecked(hofID)) { |
252 | view->referee->lower(); | 247 | view->referee->lower(); |
253 | view->status->lower(); | 248 | view->status->lower(); |
254 | } else { | 249 | } else { |
255 | view->status->raise(); | 250 | view->status->raise(); |
256 | view->referee->raise(); | 251 | view->referee->raise(); |
257 | view->referee->setFocus(); | 252 | view->referee->setFocus(); |
258 | } | 253 | } |
259 | } | 254 | } |
260 | 255 | ||
261 | /* | 256 | /* |
262 | * Disable or enable the "Hall of fame"-menuitem if the referee says so. | 257 | * Disable or enable the "Hall of fame"-menuitem if the referee says so. |
263 | * This is done, to disable turning off the "hall of fame"-display, in the automated | 258 | * This is done, to disable turning off the "hall of fame"-display, in the automated |
264 | * sequence of displaying the introduction, the demonstration (or playing) and the | 259 | * sequence of displaying the introduction, the demonstration (or playing) and the |
265 | * hall of fame. | 260 | * hall of fame. |
266 | * If on == TRUE then also lower the referee and the status widgets. | 261 | * If on == TRUE then also lower the referee and the status widgets. |
267 | */ | 262 | */ |
268 | void Kpacman::forcedHallOfFame(bool on) | 263 | void Kpacman::forcedHallOfFame(bool on) |
269 | { | 264 | { |
270 | if (!on && !gamePopup->isItemChecked(hofID)) | 265 | if (!on && !gamePopup->isItemChecked(hofID)) |
271 | return; | 266 | return; |
272 | 267 | ||
273 | gamePopup->setItemEnabled(hofID, !on); | 268 | gamePopup->setItemEnabled(hofID, !on); |
274 | gamePopup->setItemChecked(hofID, on); | 269 | gamePopup->setItemChecked(hofID, on); |
275 | 270 | ||
276 | view->referee->toggleHallOfFame(); | 271 | view->referee->toggleHallOfFame(); |
277 | if (on) { | 272 | if (on) { |
278 | view->referee->lower(); | 273 | view->referee->lower(); |
279 | view->status->lower(); | 274 | view->status->lower(); |
280 | } else { | 275 | } else { |
281 | view->status->raise(); | 276 | view->status->raise(); |
282 | view->referee->raise(); | 277 | view->referee->raise(); |
283 | view->referee->setFocus(); | 278 | view->referee->setFocus(); |
284 | view->referee->intro(); | 279 | view->referee->intro(); |
285 | } | 280 | } |
286 | } | 281 | } |
287 | 282 | ||
288 | void Kpacman::togglePaused() | 283 | void Kpacman::togglePaused() |
289 | { | 284 | { |
290 | static bool checked = FALSE; | 285 | static bool checked = FALSE; |
291 | checked = !checked; | 286 | checked = !checked; |
292 | gamePopup->setItemChecked( pauseID, checked ); | 287 | gamePopup->setItemChecked( pauseID, checked ); |
293 | view->score->setPause(gamePopup->isItemChecked(pauseID)); | 288 | view->score->setPause(gamePopup->isItemChecked(pauseID)); |
294 | } | 289 | } |
295 | 290 | ||
296 | /* | 291 | /* |
297 | * This disables the "New Game" menuitem to prevent interruptions of the current | 292 | * This disables the "New Game" menuitem to prevent interruptions of the current |
298 | * play. | 293 | * play. |
299 | */ | 294 | */ |
300 | void Kpacman::toggleNew() | 295 | void Kpacman::toggleNew() |
301 | { | 296 | { |
302 | gamePopup->setItemEnabled(newID, !gamePopup->isItemEnabled(newID)); | 297 | gamePopup->setItemEnabled(newID, !gamePopup->isItemEnabled(newID)); |
303 | } | 298 | } |
304 | 299 | ||
305 | void Kpacman::toggleHideMouseCursor() | 300 | void Kpacman::toggleHideMouseCursor() |
306 | { | 301 | { |
307 | hideMouseCursor = !hideMouseCursor; | 302 | hideMouseCursor = !hideMouseCursor; |
308 | optionsPopup->setItemChecked(hideMouseCursorID, hideMouseCursor); | 303 | optionsPopup->setItemChecked(hideMouseCursorID, hideMouseCursor); |
309 | if (hideMouseCursor) | 304 | if (hideMouseCursor) |
310 | view->setCursor(blankCursor); | 305 | view->setCursor(blankCursor); |
311 | else | 306 | else |
312 | view->setCursor(arrowCursor); | 307 | view->setCursor(arrowCursor); |
313 | } | 308 | } |
314 | 309 | ||
315 | void Kpacman::toggleFocusOutPause() | 310 | void Kpacman::toggleFocusOutPause() |
316 | { | 311 | { |
317 | focusOutPause = !focusOutPause; | 312 | focusOutPause = !focusOutPause; |
318 | optionsPopup->setItemChecked(focusOutPauseID, focusOutPause); | 313 | optionsPopup->setItemChecked(focusOutPauseID, focusOutPause); |
319 | view->referee->setFocusOutPause(focusOutPause); | 314 | view->referee->setFocusOutPause(focusOutPause); |
320 | } | 315 | } |
321 | 316 | ||
322 | void Kpacman::toggleFocusInContinue() | 317 | void Kpacman::toggleFocusInContinue() |
323 | { | 318 | { |
324 | focusInContinue = !focusInContinue; | 319 | focusInContinue = !focusInContinue; |
325 | optionsPopup->setItemChecked(focusInContinueID, focusInContinue); | 320 | optionsPopup->setItemChecked(focusInContinueID, focusInContinue); |
326 | view->referee->setFocusInContinue(focusInContinue); | 321 | view->referee->setFocusInContinue(focusInContinue); |
327 | } | 322 | } |
328 | 323 | ||
329 | void Kpacman::confKeys() | 324 | void Kpacman::confKeys() |
330 | { | 325 | { |
331 | Keys *keys = new Keys(); | 326 | Keys *keys = new Keys(); |
332 | if (keys->exec() == QDialog::Accepted) { | 327 | if (keys->exec() == QDialog::Accepted) { |
333 | view->referee->initKeys(); | 328 | view->referee->initKeys(); |
334 | view->score->initKeys(); | 329 | view->score->initKeys(); |
335 | } | 330 | } |
336 | delete keys; | 331 | delete keys; |
337 | } | 332 | } |
338 | 333 | ||
339 | void Kpacman::schemeChecked(int id) | 334 | void Kpacman::schemeChecked(int id) |
340 | { | 335 | { |
341 | int mode = 0, scheme = -1; | 336 | int mode = 0, scheme = -1; |
342 | 337 | ||
343 | for (uint s = 0; s < schemeID.size(); s++) { | 338 | for (uint s = 0; s < schemeID.size(); s++) { |
344 | if (schemeID[s] == id) { | 339 | if (schemeID[s] == id) { |
345 | scheme = s; | 340 | scheme = s; |
346 | mode = schemeMode[s]; | 341 | mode = schemeMode[s]; |
347 | } | 342 | } |
348 | if (schemeMode[s] == -1) { | 343 | if (schemeMode[s] == -1) { |
349 | modesPopup->setItemChecked(schemeID[s], schemeID[s] == id); | 344 | modesPopup->setItemChecked(schemeID[s], schemeID[s] == id); |
350 | } else { | 345 | } else { |
351 | modesPopup->setItemChecked(modeID[schemeMode[s]], schemeMode[s] == mode); | 346 | modesPopup->setItemChecked(modeID[schemeMode[s]], schemeMode[s] == mode); |
352 | schemesPopup->at(schemeMode[s])->setItemChecked(schemeID[s], schemeID[s] == id); | 347 | schemesPopup->at(schemeMode[s])->setItemChecked(schemeID[s], schemeID[s] == id); |
353 | } | 348 | } |
354 | } | 349 | } |
355 | /* | 350 | /* |
356 | APP_CONFIG_BEGIN( cfg ); | 351 | APP_CONFIG_BEGIN( cfg ); |
357 | cfg->writeEntry("Scheme", scheme); | 352 | cfg->writeEntry("Scheme", scheme); |
358 | cfg->writeEntry("Mode", mode); | 353 | cfg->writeEntry("Mode", mode); |
359 | APP_CONFIG_END( cfg ); | 354 | APP_CONFIG_END( cfg ); |
360 | */ | 355 | */ |
361 | 356 | ||
362 | view->setScheme(scheme, mode); | 357 | view->setScheme(scheme, mode); |
363 | view->updateGeometry(); | 358 | view->updateGeometry(); |
364 | updateGeometry(); | 359 | updateGeometry(); |
365 | update(); | 360 | update(); |
366 | repaint(TRUE); | 361 | repaint(TRUE); |
367 | show(); | 362 | show(); |
368 | } | 363 | } |
diff --git a/noncore/games/kpacman/kpacmanwidget.cpp b/noncore/games/kpacman/kpacmanwidget.cpp index 823d2bf..9631495 100644 --- a/noncore/games/kpacman/kpacmanwidget.cpp +++ b/noncore/games/kpacman/kpacmanwidget.cpp | |||
@@ -1,158 +1,153 @@ | |||
1 | 1 | ||
2 | #include "portable.h" | 2 | #include "portable.h" |
3 | 3 | ||
4 | #if defined( KDE2_PORT ) | 4 | #if defined( KDE2_PORT ) |
5 | #include <kapp.h> | 5 | #include <kapp.h> |
6 | #include <kconfig.h> | 6 | #include <kconfig.h> |
7 | #include <kstddirs.h> | 7 | #include <kstddirs.h> |
8 | #include <kpacmanwidget.h> | 8 | #include <kpacmanwidget.h> |
9 | #include <kpacmanwidget.moc> | 9 | #include <kpacmanwidget.moc> |
10 | #elif defined( QPE_PORT ) | 10 | #elif defined( QPE_PORT ) |
11 | #include <qpe/qpeapplication.h> | 11 | #include <qpe/qpeapplication.h> |
12 | #include <qpe/config.h> | 12 | #include <qpe/config.h> |
13 | #include "kpacmanwidget.h" | 13 | #include "kpacmanwidget.h" |
14 | #endif | 14 | #endif |
15 | 15 | ||
16 | #include <qmessagebox.h> | ||
17 | 16 | ||
18 | #include "bitfont.h" | ||
19 | #include "score.h" | ||
20 | #include "referee.h" | ||
21 | #include "status.h" | ||
22 | 17 | ||
23 | KpacmanWidget::KpacmanWidget( QWidget *parent, const char *name) | 18 | KpacmanWidget::KpacmanWidget( QWidget *parent, const char *name) |
24 | : QWidget( parent, name ) | 19 | : QWidget( parent, name ) |
25 | { | 20 | { |
26 | score = 0l; | 21 | score = 0l; |
27 | referee = 0l; | 22 | referee = 0l; |
28 | status = 0l; | 23 | status = 0l; |
29 | bitfont = NULL; | 24 | bitfont = NULL; |
30 | fontName = ""; | 25 | fontName = ""; |
31 | 26 | ||
32 | scheme = mode = -1; | 27 | scheme = mode = -1; |
33 | confScheme(); | 28 | confScheme(); |
34 | 29 | ||
35 | score = new Score(this, name, scheme, mode, bitfont); | 30 | score = new Score(this, name, scheme, mode, bitfont); |
36 | referee = new Referee( this, name, scheme, mode, bitfont); | 31 | referee = new Referee( this, name, scheme, mode, bitfont); |
37 | status = new Status(this, name, scheme, mode); | 32 | status = new Status(this, name, scheme, mode); |
38 | 33 | ||
39 | setBackgroundColor( black ); | 34 | setBackgroundColor( black ); |
40 | } | 35 | } |
41 | 36 | ||
42 | KpacmanWidget::~KpacmanWidget() | 37 | KpacmanWidget::~KpacmanWidget() |
43 | { | 38 | { |
44 | } | 39 | } |
45 | 40 | ||
46 | void KpacmanWidget::confMisc(bool defGroup) | 41 | void KpacmanWidget::confMisc(bool defGroup) |
47 | { | 42 | { |
48 | APP_CONFIG_BEGIN( cfg ); | 43 | APP_CONFIG_BEGIN( cfg ); |
49 | //KStandardDirs *dirs = KGlobal::dirs(); | 44 | //KStandardDirs *dirs = KGlobal::dirs(); |
50 | QString findPath; | 45 | QString findPath; |
51 | 46 | ||
52 | if (defGroup || cfg->hasKey("Font")) { | 47 | if (defGroup || cfg->hasKey("Font")) { |
53 | fontName = cfg->readEntry("Font"); | 48 | fontName = cfg->readEntry("Font"); |
54 | 49 | ||
55 | if (fontName.left(1) != "/" && fontName.left(1) != "~") | 50 | if (fontName.left(1) != "/" && fontName.left(1) != "~") |
56 | fontName.insert(0, "fonts/"); | 51 | fontName.insert(0, "fonts/"); |
57 | if (fontName.right(1) == "/") | 52 | if (fontName.right(1) == "/") |
58 | fontName.append("font.xbm"); | 53 | fontName.append("font.xbm"); |
59 | 54 | ||
60 | //findPath = dirs->findResource("appdata", fontName); | 55 | //findPath = dirs->findResource("appdata", fontName); |
61 | findPath = FIND_APP_DATA( fontName ); | 56 | findPath = FIND_APP_DATA( fontName ); |
62 | if (!findPath.isEmpty()) | 57 | if (!findPath.isEmpty()) |
63 | fontName = findPath; | 58 | fontName = findPath; |
64 | 59 | ||
65 | bitfontFirstChar = cfg->readNumEntry("FontFirstChar", 0x0e); | 60 | bitfontFirstChar = cfg->readNumEntry("FontFirstChar", 0x0e); |
66 | bitfontLastChar = cfg->readNumEntry("FontLastChar", 0x5f); | 61 | bitfontLastChar = cfg->readNumEntry("FontLastChar", 0x5f); |
67 | } | 62 | } |
68 | APP_CONFIG_END( cfg ); | 63 | APP_CONFIG_END( cfg ); |
69 | } | 64 | } |
70 | 65 | ||
71 | void KpacmanWidget::confScheme() | 66 | void KpacmanWidget::confScheme() |
72 | { | 67 | { |
73 | APP_CONFIG_BEGIN( cfg ); | 68 | APP_CONFIG_BEGIN( cfg ); |
74 | QString lastFontName = fontName; | 69 | QString lastFontName = fontName; |
75 | SAVE_CONFIG_GROUP( cfg, oldgroup ); | 70 | SAVE_CONFIG_GROUP( cfg, oldgroup ); |
76 | QString newgroup; | 71 | QString newgroup; |
77 | 72 | ||
78 | // if not set, read mode and scheme from the configfile | 73 | // if not set, read mode and scheme from the configfile |
79 | if (mode == -1 && scheme == -1) { | 74 | if (mode == -1 && scheme == -1) { |
80 | scheme = cfg->readNumEntry("Scheme", -1); | 75 | scheme = cfg->readNumEntry("Scheme", -1); |
81 | mode = cfg->readNumEntry("Mode", -1); | 76 | mode = cfg->readNumEntry("Mode", -1); |
82 | 77 | ||
83 | // if mode is not set in the defGroup-group, lookup the scheme group | 78 | // if mode is not set in the defGroup-group, lookup the scheme group |
84 | if (scheme != -1 || mode == -1) { | 79 | if (scheme != -1 || mode == -1) { |
85 | newgroup.sprintf("Scheme %d", scheme); | 80 | newgroup.sprintf("Scheme %d", scheme); |
86 | cfg->setGroup(newgroup); | 81 | cfg->setGroup(newgroup); |
87 | 82 | ||
88 | mode = cfg->readNumEntry("Mode", -1); | 83 | mode = cfg->readNumEntry("Mode", -1); |
89 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 84 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
90 | } | 85 | } |
91 | } | 86 | } |
92 | 87 | ||
93 | confMisc(); | 88 | confMisc(); |
94 | 89 | ||
95 | if (mode != -1) { | 90 | if (mode != -1) { |
96 | newgroup.sprintf("Mode %d", mode); | 91 | newgroup.sprintf("Mode %d", mode); |
97 | cfg->setGroup(newgroup); | 92 | cfg->setGroup(newgroup); |
98 | 93 | ||
99 | confMisc(FALSE); | 94 | confMisc(FALSE); |
100 | } | 95 | } |
101 | 96 | ||
102 | if (scheme != -1) { | 97 | if (scheme != -1) { |
103 | newgroup.sprintf("Scheme %d", scheme); | 98 | newgroup.sprintf("Scheme %d", scheme); |
104 | cfg->setGroup(newgroup); | 99 | cfg->setGroup(newgroup); |
105 | 100 | ||
106 | confMisc(FALSE); | 101 | confMisc(FALSE); |
107 | } | 102 | } |
108 | 103 | ||
109 | if (lastFontName != fontName) { | 104 | if (lastFontName != fontName) { |
110 | 105 | ||
111 | if (bitfont != 0) | 106 | if (bitfont != 0) |
112 | delete bitfont; | 107 | delete bitfont; |
113 | 108 | ||
114 | bitfont = new Bitfont(fontName, bitfontFirstChar, bitfontLastChar); | 109 | bitfont = new Bitfont(fontName, bitfontFirstChar, bitfontLastChar); |
115 | if (bitfont->width() == 0 || bitfont->height() == 0) { | 110 | if (bitfont->width() == 0 || bitfont->height() == 0) { |
116 | QString msg = tr("The bitfont could not be contructed.\n\n" | 111 | QString msg = tr("The bitfont could not be contructed.\n\n" |
117 | "The file '@FONTNAME@' does not exist,\n" | 112 | "The file '@FONTNAME@' does not exist,\n" |
118 | "or is of an unknown format."); | 113 | "or is of an unknown format."); |
119 | msg.replace(QRegExp("@FONTNAME@"), fontName); | 114 | msg.replace(QRegExp("@FONTNAME@"), fontName); |
120 | // QMessageBox::critical(this, tr("Initialization Error"), msg); | 115 | // QMessageBox::critical(this, tr("Initialization Error"), msg); |
121 | printf("%s\n", msg.data()); | 116 | printf("%s\n", msg.data()); |
122 | } | 117 | } |
123 | } | 118 | } |
124 | 119 | ||
125 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 120 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
126 | APP_CONFIG_END( cfg ); | 121 | APP_CONFIG_END( cfg ); |
127 | } | 122 | } |
128 | 123 | ||
129 | void KpacmanWidget::setScheme(int Scheme, int Mode) | 124 | void KpacmanWidget::setScheme(int Scheme, int Mode) |
130 | { | 125 | { |
131 | mode = Mode; | 126 | mode = Mode; |
132 | scheme = Scheme; | 127 | scheme = Scheme; |
133 | 128 | ||
134 | confScheme(); | 129 | confScheme(); |
135 | 130 | ||
136 | score->setScheme(Scheme, Mode, bitfont); | 131 | score->setScheme(Scheme, Mode, bitfont); |
137 | referee->setScheme(Scheme, Mode, bitfont); | 132 | referee->setScheme(Scheme, Mode, bitfont); |
138 | status->setScheme(Scheme, Mode); | 133 | status->setScheme(Scheme, Mode); |
139 | 134 | ||
140 | score->repaint(FALSE); | 135 | score->repaint(FALSE); |
141 | referee->repaint(FALSE); | 136 | referee->repaint(FALSE); |
142 | status->repaint(FALSE); | 137 | status->repaint(FALSE); |
143 | } | 138 | } |
144 | 139 | ||
145 | void KpacmanWidget::resizeEvent( QResizeEvent * ) | 140 | void KpacmanWidget::resizeEvent( QResizeEvent * ) |
146 | { | 141 | { |
147 | qWarning("Resize"); | 142 | qWarning("Resize"); |
148 | referee->setGeometry(0, bitfont->height()*3, referee->width(), referee->height()); | 143 | referee->setGeometry(0, bitfont->height()*3, referee->width(), referee->height()); |
149 | referee->setBackgroundColor(BLACK); | 144 | referee->setBackgroundColor(BLACK); |
150 | 145 | ||
151 | if(!status ) return; | 146 | if(!status ) return; |
152 | status->setGeometry(0, bitfont->height()*3+referee->height(), referee->width(), | 147 | status->setGeometry(0, bitfont->height()*3+referee->height(), referee->width(), |
153 | status->height()); | 148 | status->height()); |
154 | status->setBackgroundColor(BLACK); | 149 | status->setBackgroundColor(BLACK); |
155 | 150 | ||
156 | score->setGeometry(0, 0, referee->width(), bitfont->height()*3+referee->height()+status->height()); | 151 | score->setGeometry(0, 0, referee->width(), bitfont->height()*3+referee->height()+status->height()); |
157 | score->setBackgroundColor(BLACK); | 152 | score->setBackgroundColor(BLACK); |
158 | } | 153 | } |
diff --git a/noncore/games/kpacman/monster.cpp b/noncore/games/kpacman/monster.cpp index 2f402b4..80b4655 100644 --- a/noncore/games/kpacman/monster.cpp +++ b/noncore/games/kpacman/monster.cpp | |||
@@ -1,262 +1,261 @@ | |||
1 | #include "monster.h" | 1 | #include "monster.h" |
2 | #include "board.h" | ||
3 | 2 | ||
4 | Monster::Monster(Board *b, int mid) | 3 | Monster::Monster(Board *b, int mid) |
5 | { | 4 | { |
6 | board = b; | 5 | board = b; |
7 | ID = mid; | 6 | ID = mid; |
8 | 7 | ||
9 | setREM(0); | 8 | setREM(0); |
10 | setHarmless(0, 0, 0); | 9 | setHarmless(0, 0, 0); |
11 | setArrested(0, 0); | 10 | setArrested(0, 0); |
12 | setFreedom(board->position(prisonexit)); | 11 | setFreedom(board->position(prisonexit)); |
13 | if (mid == 0) | 12 | if (mid == 0) |
14 | setPrison(board->position(prisonentry)); | 13 | setPrison(board->position(prisonentry)); |
15 | else | 14 | else |
16 | setPrison(board->position(monsterhome, mid)); | 15 | setPrison(board->position(monsterhome, mid)); |
17 | 16 | ||
18 | actualPosition = lastPosition = OUT; | 17 | actualPosition = lastPosition = OUT; |
19 | feetPosition = 0; | 18 | feetPosition = 0; |
20 | IQ = 0; | 19 | IQ = 0; |
21 | maxBodyPixmaps = 0; | 20 | maxBodyPixmaps = 0; |
22 | maxEyesPixmaps = 0; | 21 | maxEyesPixmaps = 0; |
23 | } | 22 | } |
24 | 23 | ||
25 | void Monster::setMaxPixmaps(int maxBody, int maxEyes) | 24 | void Monster::setMaxPixmaps(int maxBody, int maxEyes) |
26 | { | 25 | { |
27 | if (feetPosition >= (maxBody/10)) | 26 | if (feetPosition >= (maxBody/10)) |
28 | feetPosition = 0; | 27 | feetPosition = 0; |
29 | maxBodyPixmaps = maxBody; | 28 | maxBodyPixmaps = maxBody; |
30 | maxEyesPixmaps = maxEyes; | 29 | maxEyesPixmaps = maxEyes; |
31 | } | 30 | } |
32 | 31 | ||
33 | void Monster::setArrested(int ticks, int duration) | 32 | void Monster::setArrested(int ticks, int duration) |
34 | { | 33 | { |
35 | actualState = dangerous; | 34 | actualState = dangerous; |
36 | pauseDuration = ticks; | 35 | pauseDuration = ticks; |
37 | pause = 0; | 36 | pause = 0; |
38 | arrestDuration = arrestLeft = duration; | 37 | arrestDuration = arrestLeft = duration; |
39 | arrestPause = ticks; | 38 | arrestPause = ticks; |
40 | harmlessLeft = 0; | 39 | harmlessLeft = 0; |
41 | } | 40 | } |
42 | 41 | ||
43 | void Monster::setDangerous(int ticks, int iq) | 42 | void Monster::setDangerous(int ticks, int iq) |
44 | { | 43 | { |
45 | actualState = dangerous; | 44 | actualState = dangerous; |
46 | pauseDuration = ticks; | 45 | pauseDuration = ticks; |
47 | pause = 0; | 46 | pause = 0; |
48 | dangerousPause = ticks; | 47 | dangerousPause = ticks; |
49 | harmlessLeft = 0; | 48 | harmlessLeft = 0; |
50 | IQ = iq; | 49 | IQ = iq; |
51 | } | 50 | } |
52 | 51 | ||
53 | void Monster::setHarmless(int ticks, int hDuration, int wDuration) | 52 | void Monster::setHarmless(int ticks, int hDuration, int wDuration) |
54 | { | 53 | { |
55 | actualState = harmless; | 54 | actualState = harmless; |
56 | pauseDuration = ticks; | 55 | pauseDuration = ticks; |
57 | pause = 0; | 56 | pause = 0; |
58 | harmlessDuration = harmlessLeft = hDuration; | 57 | harmlessDuration = harmlessLeft = hDuration; |
59 | warningDuration = wDuration; | 58 | warningDuration = wDuration; |
60 | } | 59 | } |
61 | 60 | ||
62 | void Monster::setREM(int ticks) | 61 | void Monster::setREM(int ticks) |
63 | { | 62 | { |
64 | actualState = rem; | 63 | actualState = rem; |
65 | pauseDuration = ticks; | 64 | pauseDuration = ticks; |
66 | pause = 0; | 65 | pause = 0; |
67 | } | 66 | } |
68 | 67 | ||
69 | void Monster::setPosition(int pos) | 68 | void Monster::setPosition(int pos) |
70 | { | 69 | { |
71 | board->reset(lastPosition, monster, ID); // reset old position on the board | 70 | board->reset(lastPosition, monster, ID); // reset old position on the board |
72 | actualPosition = lastPosition = pos; // set position of monster | 71 | actualPosition = lastPosition = pos; // set position of monster |
73 | board->set(actualPosition, monster, ID); | 72 | board->set(actualPosition, monster, ID); |
74 | feetPosition = 0; | 73 | feetPosition = 0; |
75 | } | 74 | } |
76 | 75 | ||
77 | void Monster::setPrison(int pos) | 76 | void Monster::setPrison(int pos) |
78 | { | 77 | { |
79 | prisonPosition = pos; | 78 | prisonPosition = pos; |
80 | } | 79 | } |
81 | 80 | ||
82 | void Monster::setFreedom(int pos) | 81 | void Monster::setFreedom(int pos) |
83 | { | 82 | { |
84 | freedomPosition = pos; | 83 | freedomPosition = pos; |
85 | } | 84 | } |
86 | 85 | ||
87 | void Monster::setDirection(int dir) | 86 | void Monster::setDirection(int dir) |
88 | { | 87 | { |
89 | if (dir == X) | 88 | if (dir == X) |
90 | lastDirection = actualDirection; | 89 | lastDirection = actualDirection; |
91 | actualDirection = dir; | 90 | actualDirection = dir; |
92 | } | 91 | } |
93 | 92 | ||
94 | monsterState Monster::state() | 93 | monsterState Monster::state() |
95 | { | 94 | { |
96 | return actualState; | 95 | return actualState; |
97 | } | 96 | } |
98 | 97 | ||
99 | int Monster::position() | 98 | int Monster::position() |
100 | { | 99 | { |
101 | return actualPosition; | 100 | return actualPosition; |
102 | } | 101 | } |
103 | 102 | ||
104 | int Monster::direction() | 103 | int Monster::direction() |
105 | { | 104 | { |
106 | return actualDirection; | 105 | return actualDirection; |
107 | } | 106 | } |
108 | 107 | ||
109 | int Monster::id() | 108 | int Monster::id() |
110 | { | 109 | { |
111 | return ID; | 110 | return ID; |
112 | } | 111 | } |
113 | 112 | ||
114 | bool Monster::move() | 113 | bool Monster::move() |
115 | { | 114 | { |
116 | if (arrestLeft > 1) | 115 | if (arrestLeft > 1) |
117 | arrestLeft--; | 116 | arrestLeft--; |
118 | 117 | ||
119 | if (harmlessLeft > 0) { | 118 | if (harmlessLeft > 0) { |
120 | harmlessLeft--; | 119 | harmlessLeft--; |
121 | if (harmlessLeft == 0 && actualState == harmless) { | 120 | if (harmlessLeft == 0 && actualState == harmless) { |
122 | actualState = dangerous; | 121 | actualState = dangerous; |
123 | pauseDuration = dangerousPause; | 122 | pauseDuration = dangerousPause; |
124 | } | 123 | } |
125 | } | 124 | } |
126 | 125 | ||
127 | if (pause-- > 0) | 126 | if (pause-- > 0) |
128 | return FALSE; | 127 | return FALSE; |
129 | else | 128 | else |
130 | pause = pauseDuration; | 129 | pause = pauseDuration; |
131 | 130 | ||
132 | if (actualPosition == OUT) | 131 | if (actualPosition == OUT) |
133 | return FALSE; | 132 | return FALSE; |
134 | 133 | ||
135 | if (actualDirection == X) { | 134 | if (actualDirection == X) { |
136 | if (++feetPosition >= (maxBodyPixmaps/10)) | 135 | if (++feetPosition >= (maxBodyPixmaps/10)) |
137 | feetPosition = 0; | 136 | feetPosition = 0; |
138 | return TRUE; | 137 | return TRUE; |
139 | } | 138 | } |
140 | 139 | ||
141 | lastPosition = actualPosition; | 140 | lastPosition = actualPosition; |
142 | int d = actualDirection; | 141 | int d = actualDirection; |
143 | 142 | ||
144 | if (arrestLeft > 1) { // during the arrest, only up and down | 143 | if (arrestLeft > 1) { // during the arrest, only up and down |
145 | if (!board->isWay(actualPosition, d, empty) && | 144 | if (!board->isWay(actualPosition, d, empty) && |
146 | !board->isWay(actualPosition, d, tunnel)) | 145 | !board->isWay(actualPosition, d, tunnel)) |
147 | d = board->turn(actualDirection); | 146 | d = board->turn(actualDirection); |
148 | } | 147 | } |
149 | 148 | ||
150 | if (arrestLeft == 1) { // going out of the prison | 149 | if (arrestLeft == 1) { // going out of the prison |
151 | if (((d == W || d == E) && | 150 | if (((d == W || d == E) && |
152 | board->x(actualPosition) == board->x(freedomPosition)) || | 151 | board->x(actualPosition) == board->x(freedomPosition)) || |
153 | ((d == S || d == N) && | 152 | ((d == S || d == N) && |
154 | board->y(actualPosition) == board->y(freedomPosition)) || | 153 | board->y(actualPosition) == board->y(freedomPosition)) || |
155 | board->isWay(actualPosition, d, brick) || | 154 | board->isWay(actualPosition, d, brick) || |
156 | board->isWay(actualPosition, d, prison)) { | 155 | board->isWay(actualPosition, d, prison)) { |
157 | d = board->closeup(actualPosition, d, freedomPosition); | 156 | d = board->closeup(actualPosition, d, freedomPosition); |
158 | } | 157 | } |
159 | while (board->isWay(actualPosition, d, brick) || | 158 | while (board->isWay(actualPosition, d, brick) || |
160 | board->isWay(actualPosition, d, prison)) { | 159 | board->isWay(actualPosition, d, prison)) { |
161 | if (d == actualDirection) | 160 | if (d == actualDirection) |
162 | d = rand() % 4; | 161 | d = rand() % 4; |
163 | else | 162 | else |
164 | d = actualDirection; | 163 | d = actualDirection; |
165 | } | 164 | } |
166 | if (actualState == dangerous) | 165 | if (actualState == dangerous) |
167 | pauseDuration = dangerousPause; | 166 | pauseDuration = dangerousPause; |
168 | 167 | ||
169 | } | 168 | } |
170 | 169 | ||
171 | if (arrestLeft == 0) | 170 | if (arrestLeft == 0) |
172 | if (actualState == rem) { // on the way to prison | 171 | if (actualState == rem) { // on the way to prison |
173 | 172 | ||
174 | d = board->closeup(actualPosition, d, prisonPosition); | 173 | d = board->closeup(actualPosition, d, prisonPosition); |
175 | 174 | ||
176 | while (board->isWay(actualPosition, d, brick) || | 175 | while (board->isWay(actualPosition, d, brick) || |
177 | board->isWay(actualPosition, d, prison)) { | 176 | board->isWay(actualPosition, d, prison)) { |
178 | if (d != actualDirection) // if new direction is not possible, | 177 | if (d != actualDirection) // if new direction is not possible, |
179 | d = actualDirection; // try current direction first. | 178 | d = actualDirection; // try current direction first. |
180 | else | 179 | else |
181 | d = rand() % 4; | 180 | d = rand() % 4; |
182 | } | 181 | } |
183 | 182 | ||
184 | } else { // dangerous or harmless movement | 183 | } else { // dangerous or harmless movement |
185 | if (rand() % (int) ((190-IQ)/10) == 0) { | 184 | if (rand() % (int) ((190-IQ)/10) == 0) { |
186 | d = board->closeup(actualPosition, d, board->position(pacman)); | 185 | d = board->closeup(actualPosition, d, board->position(pacman)); |
187 | if (actualState == harmless) | 186 | if (actualState == harmless) |
188 | d = board->turn(d); | 187 | d = board->turn(d); |
189 | } else | 188 | } else |
190 | do // try new direction, but not the opposite | 189 | do // try new direction, but not the opposite |
191 | d = rand() % 4; // direction, to prevent hectic movement. | 190 | d = rand() % 4; // direction, to prevent hectic movement. |
192 | while (d == board->turn(actualDirection)); | 191 | while (d == board->turn(actualDirection)); |
193 | 192 | ||
194 | while ((!board->isWay(actualPosition, d, empty) && | 193 | while ((!board->isWay(actualPosition, d, empty) && |
195 | !board->isWay(actualPosition, d, tunnel)) || | 194 | !board->isWay(actualPosition, d, tunnel)) || |
196 | d == board->turn(actualDirection)) { | 195 | d == board->turn(actualDirection)) { |
197 | if (d != actualDirection) // if new direction is not possible, | 196 | if (d != actualDirection) // if new direction is not possible, |
198 | d = actualDirection; // try current direction first. | 197 | d = actualDirection; // try current direction first. |
199 | else | 198 | else |
200 | d = rand() % 4; | 199 | d = rand() % 4; |
201 | } | 200 | } |
202 | } | 201 | } |
203 | 202 | ||
204 | actualDirection = d; | 203 | actualDirection = d; |
205 | actualPosition = board->move(actualPosition, actualDirection); | 204 | actualPosition = board->move(actualPosition, actualDirection); |
206 | 205 | ||
207 | if (arrestLeft == 1 && actualPosition == freedomPosition) | 206 | if (arrestLeft == 1 && actualPosition == freedomPosition) |
208 | arrestLeft = 0; | 207 | arrestLeft = 0; |
209 | 208 | ||
210 | if (actualState == rem && actualPosition == prisonPosition) { | 209 | if (actualState == rem && actualPosition == prisonPosition) { |
211 | actualState = dangerous; | 210 | actualState = dangerous; |
212 | pauseDuration = arrestPause; | 211 | pauseDuration = arrestPause; |
213 | arrestLeft = arrestDuration+1; | 212 | arrestLeft = arrestDuration+1; |
214 | actualDirection = S; | 213 | actualDirection = S; |
215 | } | 214 | } |
216 | 215 | ||
217 | if (actualPosition != lastPosition) { | 216 | if (actualPosition != lastPosition) { |
218 | board->reset(lastPosition, monster, ID); | 217 | board->reset(lastPosition, monster, ID); |
219 | board->set(actualPosition, monster, ID); | 218 | board->set(actualPosition, monster, ID); |
220 | } | 219 | } |
221 | 220 | ||
222 | if (++feetPosition >= (maxBodyPixmaps/10)) | 221 | if (++feetPosition >= (maxBodyPixmaps/10)) |
223 | feetPosition = 0; | 222 | feetPosition = 0; |
224 | 223 | ||
225 | return TRUE; | 224 | return TRUE; |
226 | } | 225 | } |
227 | 226 | ||
228 | int Monster::body() | 227 | int Monster::body() |
229 | { | 228 | { |
230 | if (actualState == rem || actualPosition == OUT) | 229 | if (actualState == rem || actualPosition == OUT) |
231 | return -1; | 230 | return -1; |
232 | else | 231 | else |
233 | if (actualState == harmless) | 232 | if (actualState == harmless) |
234 | if (harmlessLeft > warningDuration || | 233 | if (harmlessLeft > warningDuration || |
235 | harmlessLeft % (int) (warningDuration/4.5) > (int) (warningDuration/9)) | 234 | harmlessLeft % (int) (warningDuration/4.5) > (int) (warningDuration/9)) |
236 | return ((maxBodyPixmaps/10)*8)+feetPosition; | 235 | return ((maxBodyPixmaps/10)*8)+feetPosition; |
237 | else | 236 | else |
238 | return ((maxBodyPixmaps/10)*9)+feetPosition; | 237 | return ((maxBodyPixmaps/10)*9)+feetPosition; |
239 | else | 238 | else |
240 | return ((maxBodyPixmaps/10)*ID)+feetPosition; | 239 | return ((maxBodyPixmaps/10)*ID)+feetPosition; |
241 | } | 240 | } |
242 | 241 | ||
243 | int Monster::eyes() | 242 | int Monster::eyes() |
244 | { | 243 | { |
245 | if (actualState == harmless || actualPosition == OUT) | 244 | if (actualState == harmless || actualPosition == OUT) |
246 | return -1; | 245 | return -1; |
247 | else | 246 | else |
248 | switch (actualDirection) { | 247 | switch (actualDirection) { |
249 | case N : return 0; | 248 | case N : return 0; |
250 | case E : return 1; | 249 | case E : return 1; |
251 | case S : return 2; | 250 | case S : return 2; |
252 | case W : return 3; | 251 | case W : return 3; |
253 | case X : switch (lastDirection) { | 252 | case X : switch (lastDirection) { |
254 | case N : return 0; | 253 | case N : return 0; |
255 | case E : return 1; | 254 | case E : return 1; |
256 | case S : return 2; | 255 | case S : return 2; |
257 | default : return 3; | 256 | default : return 3; |
258 | } | 257 | } |
259 | default : return -1; | 258 | default : return -1; |
260 | } | 259 | } |
261 | } | 260 | } |
262 | 261 | ||
diff --git a/noncore/games/kpacman/pacman.cpp b/noncore/games/kpacman/pacman.cpp index 40f60a8..82524b4 100644 --- a/noncore/games/kpacman/pacman.cpp +++ b/noncore/games/kpacman/pacman.cpp | |||
@@ -1,147 +1,146 @@ | |||
1 | #include "pacman.h" | 1 | #include "pacman.h" |
2 | #include "board.h" | ||
3 | 2 | ||
4 | Pacman::Pacman(Board *b) | 3 | Pacman::Pacman(Board *b) |
5 | { | 4 | { |
6 | board = b; | 5 | board = b; |
7 | setDemo(FALSE); | 6 | setDemo(FALSE); |
8 | setAlive(0); | 7 | setAlive(0); |
9 | actualPosition = lastPosition = OUT; | 8 | actualPosition = lastPosition = OUT; |
10 | mouthPosition = 0; | 9 | mouthPosition = 0; |
11 | lastPix = 0; | 10 | lastPix = 0; |
12 | maxPixmaps = 0; | 11 | maxPixmaps = 0; |
13 | } | 12 | } |
14 | 13 | ||
15 | void Pacman::setMaxPixmaps(int max) | 14 | void Pacman::setMaxPixmaps(int max) |
16 | { | 15 | { |
17 | if (actualDirection == X && lastPix >= 0) { | 16 | if (actualDirection == X && lastPix >= 0) { |
18 | actualDirection = lastPix / (maxPixmaps/4); | 17 | actualDirection = lastPix / (maxPixmaps/4); |
19 | if (max < maxPixmaps) | 18 | if (max < maxPixmaps) |
20 | mouthPosition = 0; | 19 | mouthPosition = 0; |
21 | else | 20 | else |
22 | mouthPosition = lastPix % (maxPixmaps/4); | 21 | mouthPosition = lastPix % (maxPixmaps/4); |
23 | maxPixmaps = max; | 22 | maxPixmaps = max; |
24 | 23 | ||
25 | lastPix = pix(); | 24 | lastPix = pix(); |
26 | 25 | ||
27 | actualDirection = X; | 26 | actualDirection = X; |
28 | } else | 27 | } else |
29 | maxPixmaps = max; | 28 | maxPixmaps = max; |
30 | } | 29 | } |
31 | 30 | ||
32 | void Pacman::setAlive(int ticks) | 31 | void Pacman::setAlive(int ticks) |
33 | { | 32 | { |
34 | actualState = alive; | 33 | actualState = alive; |
35 | pauseDuration = ticks; | 34 | pauseDuration = ticks; |
36 | pause = 0; | 35 | pause = 0; |
37 | } | 36 | } |
38 | 37 | ||
39 | void Pacman::setPosition(int pos) | 38 | void Pacman::setPosition(int pos) |
40 | { | 39 | { |
41 | board->reset(lastPosition, pacman); | 40 | board->reset(lastPosition, pacman); |
42 | actualPosition = lastPosition = pos; | 41 | actualPosition = lastPosition = pos; |
43 | board->set(actualPosition, pacman); | 42 | board->set(actualPosition, pacman); |
44 | mouthPosition = 0; | 43 | mouthPosition = 0; |
45 | } | 44 | } |
46 | 45 | ||
47 | void Pacman::setDirection(int dir, bool forced) | 46 | void Pacman::setDirection(int dir, bool forced) |
48 | { | 47 | { |
49 | if (forced || | 48 | if (forced || |
50 | board->isWay(actualPosition, dir, empty) || | 49 | board->isWay(actualPosition, dir, empty) || |
51 | board->isWay(actualPosition, dir, tunnel)) { | 50 | board->isWay(actualPosition, dir, tunnel)) { |
52 | if (dir == X) | 51 | if (dir == X) |
53 | lastPix = pix(); | 52 | lastPix = pix(); |
54 | actualDirection = dir; | 53 | actualDirection = dir; |
55 | nextDirection = X; | 54 | nextDirection = X; |
56 | } else | 55 | } else |
57 | nextDirection = dir; | 56 | nextDirection = dir; |
58 | } | 57 | } |
59 | 58 | ||
60 | void Pacman::setDemo(bool yes) | 59 | void Pacman::setDemo(bool yes) |
61 | { | 60 | { |
62 | demo = yes; | 61 | demo = yes; |
63 | } | 62 | } |
64 | 63 | ||
65 | pacmanState Pacman::state() | 64 | pacmanState Pacman::state() |
66 | { | 65 | { |
67 | return actualState; | 66 | return actualState; |
68 | } | 67 | } |
69 | 68 | ||
70 | int Pacman::position() | 69 | int Pacman::position() |
71 | { | 70 | { |
72 | return actualPosition; | 71 | return actualPosition; |
73 | } | 72 | } |
74 | 73 | ||
75 | int Pacman::direction() | 74 | int Pacman::direction() |
76 | { | 75 | { |
77 | return actualDirection; | 76 | return actualDirection; |
78 | } | 77 | } |
79 | 78 | ||
80 | bool Pacman::move() | 79 | bool Pacman::move() |
81 | { | 80 | { |
82 | if (pause-- > 0) | 81 | if (pause-- > 0) |
83 | return FALSE; | 82 | return FALSE; |
84 | else | 83 | else |
85 | pause = pauseDuration; | 84 | pause = pauseDuration; |
86 | 85 | ||
87 | if (actualDirection == X || actualPosition == OUT) | 86 | if (actualDirection == X || actualPosition == OUT) |
88 | return FALSE; | 87 | return FALSE; |
89 | 88 | ||
90 | lastPosition = actualPosition; | 89 | lastPosition = actualPosition; |
91 | 90 | ||
92 | if (demo) { | 91 | if (demo) { |
93 | int d = actualDirection; | 92 | int d = actualDirection; |
94 | 93 | ||
95 | do // try new direction, but not the opposite | 94 | do // try new direction, but not the opposite |
96 | d = rand() % 4; // direction, to prevent hectic movement. | 95 | d = rand() % 4; // direction, to prevent hectic movement. |
97 | while (d == board->turn(actualDirection)); | 96 | while (d == board->turn(actualDirection)); |
98 | 97 | ||
99 | while (!board->isWay(actualPosition, d, empty) && | 98 | while (!board->isWay(actualPosition, d, empty) && |
100 | !board->isWay(actualPosition, d, tunnel)) { | 99 | !board->isWay(actualPosition, d, tunnel)) { |
101 | if (d != actualDirection) // if new actualDirection is not possible, | 100 | if (d != actualDirection) // if new actualDirection is not possible, |
102 | d = actualDirection; // try current actualDirection first. | 101 | d = actualDirection; // try current actualDirection first. |
103 | else | 102 | else |
104 | d = rand() % 4; | 103 | d = rand() % 4; |
105 | } | 104 | } |
106 | 105 | ||
107 | actualDirection = d; | 106 | actualDirection = d; |
108 | actualPosition = board->move(actualPosition, actualDirection); | 107 | actualPosition = board->move(actualPosition, actualDirection); |
109 | 108 | ||
110 | } else { | 109 | } else { |
111 | 110 | ||
112 | if (nextDirection != X) | 111 | if (nextDirection != X) |
113 | if (board->isWay(actualPosition, nextDirection, empty) || | 112 | if (board->isWay(actualPosition, nextDirection, empty) || |
114 | board->isWay(actualPosition, nextDirection, tunnel)) { | 113 | board->isWay(actualPosition, nextDirection, tunnel)) { |
115 | actualDirection = nextDirection; | 114 | actualDirection = nextDirection; |
116 | nextDirection = X; | 115 | nextDirection = X; |
117 | } | 116 | } |
118 | 117 | ||
119 | if (board->isWay(actualPosition, actualDirection, empty) || | 118 | if (board->isWay(actualPosition, actualDirection, empty) || |
120 | board->isWay(actualPosition, actualDirection, tunnel)) | 119 | board->isWay(actualPosition, actualDirection, tunnel)) |
121 | actualPosition = board->move(actualPosition, actualDirection); | 120 | actualPosition = board->move(actualPosition, actualDirection); |
122 | } | 121 | } |
123 | 122 | ||
124 | if (actualPosition != lastPosition) { | 123 | if (actualPosition != lastPosition) { |
125 | board->reset(lastPosition, pacman); | 124 | board->reset(lastPosition, pacman); |
126 | board->set(actualPosition, pacman); | 125 | board->set(actualPosition, pacman); |
127 | 126 | ||
128 | if (++mouthPosition >= (maxPixmaps/4)) | 127 | if (++mouthPosition >= (maxPixmaps/4)) |
129 | mouthPosition = 0; | 128 | mouthPosition = 0; |
130 | } | 129 | } |
131 | return TRUE; | 130 | return TRUE; |
132 | } | 131 | } |
133 | 132 | ||
134 | int Pacman::pix() | 133 | int Pacman::pix() |
135 | { | 134 | { |
136 | if (actualPosition != OUT && maxPixmaps > 0) | 135 | if (actualPosition != OUT && maxPixmaps > 0) |
137 | switch (actualDirection) { | 136 | switch (actualDirection) { |
138 | case N : return ((maxPixmaps/4)*0)+mouthPosition; | 137 | case N : return ((maxPixmaps/4)*0)+mouthPosition; |
139 | case E : return ((maxPixmaps/4)*1)+mouthPosition; | 138 | case E : return ((maxPixmaps/4)*1)+mouthPosition; |
140 | case S : return ((maxPixmaps/4)*2)+mouthPosition; | 139 | case S : return ((maxPixmaps/4)*2)+mouthPosition; |
141 | case W : return ((maxPixmaps/4)*3)+mouthPosition; | 140 | case W : return ((maxPixmaps/4)*3)+mouthPosition; |
142 | case X : return lastPix; | 141 | case X : return lastPix; |
143 | } | 142 | } |
144 | 143 | ||
145 | return -1; | 144 | return -1; |
146 | } | 145 | } |
147 | 146 | ||
diff --git a/noncore/games/kpacman/painter.cpp b/noncore/games/kpacman/painter.cpp index d8c7460..410d3f5 100644 --- a/noncore/games/kpacman/painter.cpp +++ b/noncore/games/kpacman/painter.cpp | |||
@@ -1,536 +1,528 @@ | |||
1 | 1 | ||
2 | #include "portable.h" | 2 | #include "portable.h" |
3 | 3 | ||
4 | #if defined( KDE2_PORT ) | 4 | #if defined( KDE2_PORT ) |
5 | #include <kapp.h> | 5 | #include <kapp.h> |
6 | #include <kconfig.h> | 6 | #include <kconfig.h> |
7 | #include <kstddirs.h> | 7 | #include <kstddirs.h> |
8 | #elif defined( QPE_PORT ) | 8 | #elif defined( QPE_PORT ) |
9 | #include <qpe/qpeapplication.h> | 9 | #include <qpe/qpeapplication.h> |
10 | #include <qpe/config.h> | 10 | #include <qpe/config.h> |
11 | #endif | 11 | #endif |
12 | 12 | ||
13 | #include <qcolor.h> | 13 | |
14 | #include <qpainter.h> | ||
15 | #include <qpixmap.h> | ||
16 | #include <qbitmap.h> | ||
17 | #include <qrect.h> | ||
18 | #include <qstring.h> | ||
19 | |||
20 | #include <qmessagebox.h> | ||
21 | #include <qfileinfo.h> | 14 | #include <qfileinfo.h> |
22 | 15 | ||
23 | #include "painter.h" | 16 | #include "painter.h" |
24 | #include "board.h" | ||
25 | 17 | ||
26 | Painter::Painter( Board *b, QWidget *parent, int Scheme, int Mode, Bitfont *font) | 18 | Painter::Painter( Board *b, QWidget *parent, int Scheme, int Mode, Bitfont *font) |
27 | { | 19 | { |
28 | w = parent; | 20 | w = parent; |
29 | board = b; | 21 | board = b; |
30 | 22 | ||
31 | pointPix = NULL; | 23 | pointPix = NULL; |
32 | wallPix = NULL; | 24 | wallPix = NULL; |
33 | prisonPix = NULL; | 25 | prisonPix = NULL; |
34 | energizerPix = NULL; | 26 | energizerPix = NULL; |
35 | fruitPix = NULL; | 27 | fruitPix = NULL; |
36 | pacmanPix = NULL; | 28 | pacmanPix = NULL; |
37 | dyingPix = NULL; | 29 | dyingPix = NULL; |
38 | eyesPix = NULL; | 30 | eyesPix = NULL; |
39 | monsterPix = NULL; | 31 | monsterPix = NULL; |
40 | fruitScorePix = NULL; | 32 | fruitScorePix = NULL; |
41 | monsterScorePix = NULL; | 33 | monsterScorePix = NULL; |
42 | 34 | ||
43 | lastPointPixmapName = ""; | 35 | lastPointPixmapName = ""; |
44 | lastWallPixmapName = ""; | 36 | lastWallPixmapName = ""; |
45 | lastPrisonPixmapName = ""; | 37 | lastPrisonPixmapName = ""; |
46 | lastEnergizerPixmapName = ""; | 38 | lastEnergizerPixmapName = ""; |
47 | lastFruitPixmapName = ""; | 39 | lastFruitPixmapName = ""; |
48 | lastPacmanPixmapName = ""; | 40 | lastPacmanPixmapName = ""; |
49 | lastDyingPixmapName = ""; | 41 | lastDyingPixmapName = ""; |
50 | lastEyesPixmapName = ""; | 42 | lastEyesPixmapName = ""; |
51 | lastMonsterPixmapName = ""; | 43 | lastMonsterPixmapName = ""; |
52 | lastFruitScorePixmapName = ""; | 44 | lastFruitScorePixmapName = ""; |
53 | lastMonsterScorePixmapName = ""; | 45 | lastMonsterScorePixmapName = ""; |
54 | 46 | ||
55 | bitfont = font; | 47 | bitfont = font; |
56 | 48 | ||
57 | scheme = Scheme; | 49 | scheme = Scheme; |
58 | mode = Mode; | 50 | mode = Mode; |
59 | level = 0; | 51 | level = 0; |
60 | 52 | ||
61 | confScheme(); | 53 | confScheme(); |
62 | } | 54 | } |
63 | 55 | ||
64 | QList<QPixmap> *Painter::loadPixmap(QWidget*, QString pixmapName, | 56 | QList<QPixmap> *Painter::loadPixmap(QWidget*, QString pixmapName, |
65 | QList<QPixmap> *pixmaps) | 57 | QList<QPixmap> *pixmaps) |
66 | { | 58 | { |
67 | if (pixmaps == NULL) { | 59 | if (pixmaps == NULL) { |
68 | pixmaps = new QList<QPixmap>; | 60 | pixmaps = new QList<QPixmap>; |
69 | pixmaps->setAutoDelete(TRUE); | 61 | pixmaps->setAutoDelete(TRUE); |
70 | } | 62 | } |
71 | 63 | ||
72 | if (!pixmaps->isEmpty()) | 64 | if (!pixmaps->isEmpty()) |
73 | pixmaps->clear(); | 65 | pixmaps->clear(); |
74 | 66 | ||
75 | QPixmap PIXMAP(pixmapName); | 67 | QPixmap PIXMAP(pixmapName); |
76 | if (PIXMAP.isNull() || PIXMAP.mask() == NULL) { | 68 | if (PIXMAP.isNull() || PIXMAP.mask() == NULL) { |
77 | QString msg = "The pixmap could not be contructed.\n\n" | 69 | QString msg = "The pixmap could not be contructed.\n\n" |
78 | "The file '@PIXMAPNAME@' does not exist,\n" | 70 | "The file '@PIXMAPNAME@' does not exist,\n" |
79 | "or is of an unknown format."; | 71 | "or is of an unknown format."; |
80 | msg.replace(QRegExp("@PIXMAPNAME@"), pixmapName); | 72 | msg.replace(QRegExp("@PIXMAPNAME@"), pixmapName); |
81 | // QMessageBox::critical(parent, tr("Initialization Error"), msg); | 73 | // QMessageBox::critical(parent, tr("Initialization Error"), msg); |
82 | printf("%s\n", msg.data()); | 74 | printf("%s\n", msg.data()); |
83 | return 0; | 75 | return 0; |
84 | } | 76 | } |
85 | 77 | ||
86 | int height = PIXMAP.height(); | 78 | int height = PIXMAP.height(); |
87 | int width = (height == 0) ? 0 : PIXMAP.width()/(PIXMAP.width()/height); | 79 | int width = (height == 0) ? 0 : PIXMAP.width()/(PIXMAP.width()/height); |
88 | 80 | ||
89 | QBitmap BITMAP; | 81 | QBitmap BITMAP; |
90 | QBitmap MASK; | 82 | QBitmap MASK; |
91 | 83 | ||
92 | BITMAP = *PIXMAP.mask(); | 84 | BITMAP = *PIXMAP.mask(); |
93 | MASK.resize(width, height); | 85 | MASK.resize(width, height); |
94 | 86 | ||
95 | for (int x = 0; x < PIXMAP.width()/width; x++) { | 87 | for (int x = 0; x < PIXMAP.width()/width; x++) { |
96 | QPixmap *pixmap = new QPixmap(width, height); | 88 | QPixmap *pixmap = new QPixmap(width, height); |
97 | pixmaps->append(pixmap); | 89 | pixmaps->append(pixmap); |
98 | bitBlt(pixmap, 0, 0, &PIXMAP, x*width, 0, width, height, QPixmap::CopyROP, TRUE); | 90 | bitBlt(pixmap, 0, 0, &PIXMAP, x*width, 0, width, height, QPixmap::CopyROP, TRUE); |
99 | bitBlt(&MASK, 0, 0, &BITMAP, x*width, 0, width, height, QPixmap::CopyROP, TRUE); | 91 | bitBlt(&MASK, 0, 0, &BITMAP, x*width, 0, width, height, QPixmap::CopyROP, TRUE); |
100 | pixmap->setMask(MASK); | 92 | pixmap->setMask(MASK); |
101 | } | 93 | } |
102 | 94 | ||
103 | return pixmaps; | 95 | return pixmaps; |
104 | } | 96 | } |
105 | 97 | ||
106 | QList<QPixmap> *Painter::textPixmap(QStrList &str, QList<QPixmap> *pixmaps, | 98 | QList<QPixmap> *Painter::textPixmap(QStrList &str, QList<QPixmap> *pixmaps, |
107 | QColor fg, QColor bg) | 99 | QColor fg, QColor bg) |
108 | { | 100 | { |
109 | if (pixmaps == NULL) { | 101 | if (pixmaps == NULL) { |
110 | pixmaps = new QList<QPixmap>; | 102 | pixmaps = new QList<QPixmap>; |
111 | pixmaps->setAutoDelete(TRUE); | 103 | pixmaps->setAutoDelete(TRUE); |
112 | } | 104 | } |
113 | 105 | ||
114 | if (!pixmaps->isEmpty()) | 106 | if (!pixmaps->isEmpty()) |
115 | pixmaps->clear(); | 107 | pixmaps->clear(); |
116 | 108 | ||
117 | for (uint s = 0; s < str.count(); s++) { | 109 | for (uint s = 0; s < str.count(); s++) { |
118 | QPixmap *pixmap = new QPixmap(bitfont->text(str.at(s), fg, bg)); | 110 | QPixmap *pixmap = new QPixmap(bitfont->text(str.at(s), fg, bg)); |
119 | pixmaps->append(pixmap); | 111 | pixmaps->append(pixmap); |
120 | } | 112 | } |
121 | 113 | ||
122 | return pixmaps; | 114 | return pixmaps; |
123 | } | 115 | } |
124 | 116 | ||
125 | QList<QPixmap> *Painter::textPixmap(QString str, QList<QPixmap> *pixmaps, | 117 | QList<QPixmap> *Painter::textPixmap(QString str, QList<QPixmap> *pixmaps, |
126 | QColor fg, QColor bg) | 118 | QColor fg, QColor bg) |
127 | { | 119 | { |
128 | if (pixmaps == NULL) { | 120 | if (pixmaps == NULL) { |
129 | pixmaps = new QList<QPixmap>; | 121 | pixmaps = new QList<QPixmap>; |
130 | pixmaps->setAutoDelete(TRUE); | 122 | pixmaps->setAutoDelete(TRUE); |
131 | } | 123 | } |
132 | 124 | ||
133 | if (!pixmaps->isEmpty()) | 125 | if (!pixmaps->isEmpty()) |
134 | pixmaps->clear(); | 126 | pixmaps->clear(); |
135 | 127 | ||
136 | QPixmap *pixmap = new QPixmap(bitfont->text(str, fg, bg)); | 128 | QPixmap *pixmap = new QPixmap(bitfont->text(str, fg, bg)); |
137 | pixmaps->append(pixmap); | 129 | pixmaps->append(pixmap); |
138 | 130 | ||
139 | return pixmaps; | 131 | return pixmaps; |
140 | } | 132 | } |
141 | 133 | ||
142 | /* Return the point of the upperleft pixel of the block representing that position | 134 | /* Return the point of the upperleft pixel of the block representing that position |
143 | * on the board. | 135 | * on the board. |
144 | */ | 136 | */ |
145 | QPoint Painter::point(int pos) | 137 | QPoint Painter::point(int pos) |
146 | { | 138 | { |
147 | return QPoint((board->x(pos)-1)*BlockWidth, (board->y(pos)-1)*BlockHeight); | 139 | return QPoint((board->x(pos)-1)*BlockWidth, (board->y(pos)-1)*BlockHeight); |
148 | } | 140 | } |
149 | 141 | ||
150 | 142 | ||
151 | QRect Painter::rect(int pos, PixMap pix, uint i) | 143 | QRect Painter::rect(int pos, PixMap pix, uint i) |
152 | { | 144 | { |
153 | if (pos == OUT) | 145 | if (pos == OUT) |
154 | return QRect(); | 146 | return QRect(); |
155 | 147 | ||
156 | QPixmap *PIXMAP = NULL; | 148 | QPixmap *PIXMAP = NULL; |
157 | switch (pix) { | 149 | switch (pix) { |
158 | case PacmanPix : PIXMAP = pacmanPix-> | 150 | case PacmanPix : PIXMAP = pacmanPix-> |
159 | at(checkRange(i, pacmanPix->count()-1)); | 151 | at(checkRange(i, pacmanPix->count()-1)); |
160 | break; | 152 | break; |
161 | case DyingPix : PIXMAP = dyingPix-> | 153 | case DyingPix : PIXMAP = dyingPix-> |
162 | at(checkRange(i, dyingPix->count()-1)); | 154 | at(checkRange(i, dyingPix->count()-1)); |
163 | break; | 155 | break; |
164 | case MonsterPix : PIXMAP = monsterPix-> | 156 | case MonsterPix : PIXMAP = monsterPix-> |
165 | at(checkRange(i, monsterPix->count()-1)); | 157 | at(checkRange(i, monsterPix->count()-1)); |
166 | break; | 158 | break; |
167 | case EyesPix : PIXMAP = eyesPix-> | 159 | case EyesPix : PIXMAP = eyesPix-> |
168 | at(checkRange(i, eyesPix->count()-1)); | 160 | at(checkRange(i, eyesPix->count()-1)); |
169 | break; | 161 | break; |
170 | case FruitPix : PIXMAP = fruitPix-> | 162 | case FruitPix : PIXMAP = fruitPix-> |
171 | at(checkRange(i, fruitPix->count()-1)); | 163 | at(checkRange(i, fruitPix->count()-1)); |
172 | break; | 164 | break; |
173 | case PointPix : PIXMAP = pointPix-> | 165 | case PointPix : PIXMAP = pointPix-> |
174 | at(checkRange(i, pointPix->count()-1)); | 166 | at(checkRange(i, pointPix->count()-1)); |
175 | break; | 167 | break; |
176 | case EnergizerPix : PIXMAP = energizerPix-> | 168 | case EnergizerPix : PIXMAP = energizerPix-> |
177 | at(checkRange(i, energizerPix->count()-1)); | 169 | at(checkRange(i, energizerPix->count()-1)); |
178 | break; | 170 | break; |
179 | case FruitScorePix : PIXMAP = fruitScorePix-> | 171 | case FruitScorePix : PIXMAP = fruitScorePix-> |
180 | at(checkRange(i, fruitScorePix->count()-1)); | 172 | at(checkRange(i, fruitScorePix->count()-1)); |
181 | break; | 173 | break; |
182 | case MonsterScorePix : PIXMAP = monsterScorePix-> | 174 | case MonsterScorePix : PIXMAP = monsterScorePix-> |
183 | at(checkRange(i,monsterScorePix->count()-1)); | 175 | at(checkRange(i,monsterScorePix->count()-1)); |
184 | break; | 176 | break; |
185 | default : PIXMAP = wallPix-> | 177 | default : PIXMAP = wallPix-> |
186 | at(checkRange(i, wallPix->count()-1)); | 178 | at(checkRange(i, wallPix->count()-1)); |
187 | } | 179 | } |
188 | if (PIXMAP == NULL) | 180 | if (PIXMAP == NULL) |
189 | return QRect(); | 181 | return QRect(); |
190 | 182 | ||
191 | QRect rect = PIXMAP->rect(); | 183 | QRect rect = PIXMAP->rect(); |
192 | QPoint point = this->point(pos); | 184 | QPoint point = this->point(pos); |
193 | rect.moveCenter(QPoint(point.x()-1, point.y()-1)); | 185 | rect.moveCenter(QPoint(point.x()-1, point.y()-1)); |
194 | 186 | ||
195 | return rect; | 187 | return rect; |
196 | } | 188 | } |
197 | 189 | ||
198 | QRect Painter::rect(int pos, QString str, int align) | 190 | QRect Painter::rect(int pos, QString str, int align) |
199 | { | 191 | { |
200 | if (pos == OUT) // return an empty rect if the position | 192 | if (pos == OUT) // return an empty rect if the position |
201 | return QRect(); // is invalid | 193 | return QRect(); // is invalid |
202 | QPoint point = this->point(pos); | 194 | QPoint point = this->point(pos); |
203 | QRect rect = bitfont->rect(str); | 195 | QRect rect = bitfont->rect(str); |
204 | 196 | ||
205 | rect.moveCenter(QPoint(point.x()-1, point.y()-1)); | 197 | rect.moveCenter(QPoint(point.x()-1, point.y()-1)); |
206 | 198 | ||
207 | int dx = 0; | 199 | int dx = 0; |
208 | int dy = 0; | 200 | int dy = 0; |
209 | 201 | ||
210 | if (align & QLabel::AlignLeft || align & QLabel::AlignRight) { | 202 | if (align & QLabel::AlignLeft || align & QLabel::AlignRight) { |
211 | dx = (str.length()-1) * (bitfont->width()/2); | 203 | dx = (str.length()-1) * (bitfont->width()/2); |
212 | if (align & QLabel::AlignRight) | 204 | if (align & QLabel::AlignRight) |
213 | dx *= -1; | 205 | dx *= -1; |
214 | } | 206 | } |
215 | 207 | ||
216 | if (align & QLabel::AlignTop || align & QLabel::AlignBottom) { | 208 | if (align & QLabel::AlignTop || align & QLabel::AlignBottom) { |
217 | dy = bitfont->height()/2; | 209 | dy = bitfont->height()/2; |
218 | if (align & QLabel::AlignBottom) | 210 | if (align & QLabel::AlignBottom) |
219 | dy *= -1; | 211 | dy *= -1; |
220 | } | 212 | } |
221 | 213 | ||
222 | if (dx != 0 || dy != 0) | 214 | if (dx != 0 || dy != 0) |
223 | rect.moveBy(dx, dy); | 215 | rect.moveBy(dx, dy); |
224 | 216 | ||
225 | return rect; | 217 | return rect; |
226 | } | 218 | } |
227 | 219 | ||
228 | QRect Painter::rect(QRect r1, QRect r2) | 220 | QRect Painter::rect(QRect r1, QRect r2) |
229 | { | 221 | { |
230 | QRect rect; | 222 | QRect rect; |
231 | rect.setLeft(r1.left() < r2.left() ? r1.left() : r2.left()); | 223 | rect.setLeft(r1.left() < r2.left() ? r1.left() : r2.left()); |
232 | rect.setTop(r1.top() < r2.top() ? r1.top() : r2.top()); | 224 | rect.setTop(r1.top() < r2.top() ? r1.top() : r2.top()); |
233 | rect.setRight(r1.right() > r2.right() ? r1.right() : r2.right()); | 225 | rect.setRight(r1.right() > r2.right() ? r1.right() : r2.right()); |
234 | rect.setBottom(r1.bottom() > r2.bottom() ? r1.bottom() : r2.bottom()); | 226 | rect.setBottom(r1.bottom() > r2.bottom() ? r1.bottom() : r2.bottom()); |
235 | 227 | ||
236 | return rect; | 228 | return rect; |
237 | } | 229 | } |
238 | 230 | ||
239 | void Painter::erase(int pos, PixMap pix, uint i) | 231 | void Painter::erase(int pos, PixMap pix, uint i) |
240 | { | 232 | { |
241 | if (pos == OUT) | 233 | if (pos == OUT) |
242 | return; | 234 | return; |
243 | QRect rect = this->rect(pos, pix, i); | 235 | QRect rect = this->rect(pos, pix, i); |
244 | bitBlt(&roomPix, rect.x(), rect.y(), &backPix, | 236 | bitBlt(&roomPix, rect.x(), rect.y(), &backPix, |
245 | rect.x(), rect.y(), rect.width(), rect.height()); | 237 | rect.x(), rect.y(), rect.width(), rect.height()); |
246 | } | 238 | } |
247 | 239 | ||
248 | int Painter::maxPixmaps(PixMap pix) | 240 | int Painter::maxPixmaps(PixMap pix) |
249 | { | 241 | { |
250 | switch (pix) { | 242 | switch (pix) { |
251 | case WallPix : return (int) wallPix->count(); | 243 | case WallPix : return (int) wallPix->count(); |
252 | case PrisonPix : return (int) prisonPix->count(); | 244 | case PrisonPix : return (int) prisonPix->count(); |
253 | case PointPix : return (int) pointPix->count(); | 245 | case PointPix : return (int) pointPix->count(); |
254 | case EnergizerPix : return (int) energizerPix->count(); | 246 | case EnergizerPix : return (int) energizerPix->count(); |
255 | case FruitPix : return (int) fruitPix->count(); | 247 | case FruitPix : return (int) fruitPix->count(); |
256 | case PacmanPix : return (int) pacmanPix->count(); | 248 | case PacmanPix : return (int) pacmanPix->count(); |
257 | case DyingPix : return (int) dyingPix->count(); | 249 | case DyingPix : return (int) dyingPix->count(); |
258 | case EyesPix : return (int) eyesPix->count(); | 250 | case EyesPix : return (int) eyesPix->count(); |
259 | case MonsterPix : return (int) monsterPix->count(); | 251 | case MonsterPix : return (int) monsterPix->count(); |
260 | case FruitScorePix : return (int) fruitScorePix->count(); | 252 | case FruitScorePix : return (int) fruitScorePix->count(); |
261 | case MonsterScorePix : return (int) monsterScorePix->count(); | 253 | case MonsterScorePix : return (int) monsterScorePix->count(); |
262 | default : return 0; | 254 | default : return 0; |
263 | } | 255 | } |
264 | } | 256 | } |
265 | 257 | ||
266 | void Painter::draw(QPoint point, DrawWidget where, QPixmap pix) | 258 | void Painter::draw(QPoint point, DrawWidget where, QPixmap pix) |
267 | { | 259 | { |
268 | switch (where) { | 260 | switch (where) { |
269 | case Widget : bitBlt(w, point.x(), point.y(), &pix); | 261 | case Widget : bitBlt(w, point.x(), point.y(), &pix); |
270 | break; | 262 | break; |
271 | case RoomPix : bitBlt(&roomPix, point.x(), point.y(), &pix); | 263 | case RoomPix : bitBlt(&roomPix, point.x(), point.y(), &pix); |
272 | break; | 264 | break; |
273 | case BackPix : bitBlt(&backPix, point.x(), point.y(), &pix); | 265 | case BackPix : bitBlt(&backPix, point.x(), point.y(), &pix); |
274 | break; | 266 | break; |
275 | } | 267 | } |
276 | } | 268 | } |
277 | 269 | ||
278 | void Painter::draw(QRect rect, DrawWidget where, QPixmap pix) | 270 | void Painter::draw(QRect rect, DrawWidget where, QPixmap pix) |
279 | { | 271 | { |
280 | draw(QPoint(rect.x(), rect.y()), where, pix); | 272 | draw(QPoint(rect.x(), rect.y()), where, pix); |
281 | } | 273 | } |
282 | 274 | ||
283 | void Painter::draw(int pos, DrawWidget where, PixMap pix, uint i) | 275 | void Painter::draw(int pos, DrawWidget where, PixMap pix, uint i) |
284 | { | 276 | { |
285 | QPixmap *PIXMAP = NULL; | 277 | QPixmap *PIXMAP = NULL; |
286 | switch (pix) { | 278 | switch (pix) { |
287 | case PacmanPix : PIXMAP = pacmanPix-> | 279 | case PacmanPix : PIXMAP = pacmanPix-> |
288 | at(checkRange(i, pacmanPix->count()-1)); | 280 | at(checkRange(i, pacmanPix->count()-1)); |
289 | break; | 281 | break; |
290 | case DyingPix : PIXMAP = dyingPix-> | 282 | case DyingPix : PIXMAP = dyingPix-> |
291 | at(checkRange(i, dyingPix->count()-1)); | 283 | at(checkRange(i, dyingPix->count()-1)); |
292 | break; | 284 | break; |
293 | case MonsterPix : PIXMAP = monsterPix-> | 285 | case MonsterPix : PIXMAP = monsterPix-> |
294 | at(checkRange(i, monsterPix->count()-1)); | 286 | at(checkRange(i, monsterPix->count()-1)); |
295 | break; | 287 | break; |
296 | case EyesPix : PIXMAP = eyesPix-> | 288 | case EyesPix : PIXMAP = eyesPix-> |
297 | at(checkRange(i, eyesPix->count()-1)); | 289 | at(checkRange(i, eyesPix->count()-1)); |
298 | break; | 290 | break; |
299 | case FruitPix : PIXMAP = fruitPix-> | 291 | case FruitPix : PIXMAP = fruitPix-> |
300 | at(checkRange(i, fruitPix->count()-1)); | 292 | at(checkRange(i, fruitPix->count()-1)); |
301 | break; | 293 | break; |
302 | case EnergizerPix : PIXMAP = energizerPix-> | 294 | case EnergizerPix : PIXMAP = energizerPix-> |
303 | at(checkRange(i, energizerPix->count()-1)); | 295 | at(checkRange(i, energizerPix->count()-1)); |
304 | break; | 296 | break; |
305 | case FruitScorePix : PIXMAP = fruitScorePix-> | 297 | case FruitScorePix : PIXMAP = fruitScorePix-> |
306 | at(checkRange(i, fruitScorePix->count()-1)); | 298 | at(checkRange(i, fruitScorePix->count()-1)); |
307 | break; | 299 | break; |
308 | case MonsterScorePix : PIXMAP = monsterScorePix-> | 300 | case MonsterScorePix : PIXMAP = monsterScorePix-> |
309 | at(checkRange(i,monsterScorePix->count()-1)); | 301 | at(checkRange(i,monsterScorePix->count()-1)); |
310 | break; | 302 | break; |
311 | default : ; | 303 | default : ; |
312 | } | 304 | } |
313 | 305 | ||
314 | if (PIXMAP == NULL) | 306 | if (PIXMAP == NULL) |
315 | return; | 307 | return; |
316 | 308 | ||
317 | QRect rect = PIXMAP->rect(); | 309 | QRect rect = PIXMAP->rect(); |
318 | QPoint point = this->point(pos); | 310 | QPoint point = this->point(pos); |
319 | rect.moveCenter(QPoint(point.x()-1, point.y()-1)); | 311 | rect.moveCenter(QPoint(point.x()-1, point.y()-1)); |
320 | 312 | ||
321 | switch (where) { | 313 | switch (where) { |
322 | case Widget : bitBlt(w, rect.x(), rect.y(), PIXMAP); | 314 | case Widget : bitBlt(w, rect.x(), rect.y(), PIXMAP); |
323 | break; | 315 | break; |
324 | case RoomPix : bitBlt(&roomPix, rect.x(), rect.y(), PIXMAP); | 316 | case RoomPix : bitBlt(&roomPix, rect.x(), rect.y(), PIXMAP); |
325 | break; | 317 | break; |
326 | case BackPix : bitBlt(&backPix, rect.x(), rect.y(), PIXMAP); | 318 | case BackPix : bitBlt(&backPix, rect.x(), rect.y(), PIXMAP); |
327 | break; | 319 | break; |
328 | } | 320 | } |
329 | } | 321 | } |
330 | 322 | ||
331 | QPixmap Painter::draw(int pos, DrawWidget where, | 323 | QPixmap Painter::draw(int pos, DrawWidget where, |
332 | QString str, QColor fg, QColor bg, int align) | 324 | QString str, QColor fg, QColor bg, int align) |
333 | { | 325 | { |
334 | QPixmap TEXT = bitfont->text(str, fg, bg); | 326 | QPixmap TEXT = bitfont->text(str, fg, bg); |
335 | 327 | ||
336 | QRect rect = this->rect(pos, str, align); | 328 | QRect rect = this->rect(pos, str, align); |
337 | QPixmap SAVE = QPixmap(rect.width(), rect.height()); | 329 | QPixmap SAVE = QPixmap(rect.width(), rect.height()); |
338 | 330 | ||
339 | switch (where) { | 331 | switch (where) { |
340 | case Widget : bitBlt(&SAVE, 0, 0, w, rect.x(), rect.y()); | 332 | case Widget : bitBlt(&SAVE, 0, 0, w, rect.x(), rect.y()); |
341 | bitBlt(w, rect.x(), rect.y(), &TEXT); | 333 | bitBlt(w, rect.x(), rect.y(), &TEXT); |
342 | break; | 334 | break; |
343 | case RoomPix : bitBlt(&SAVE, 0, 0, &roomPix, rect.x(), rect.y()); | 335 | case RoomPix : bitBlt(&SAVE, 0, 0, &roomPix, rect.x(), rect.y()); |
344 | bitBlt(&roomPix, rect.x(), rect.y(), &TEXT); | 336 | bitBlt(&roomPix, rect.x(), rect.y(), &TEXT); |
345 | break; | 337 | break; |
346 | case BackPix : bitBlt(&SAVE, 0, 0, &backPix, rect.x(), rect.y()); | 338 | case BackPix : bitBlt(&SAVE, 0, 0, &backPix, rect.x(), rect.y()); |
347 | bitBlt(&backPix, rect.x(), rect.y(), &TEXT); | 339 | bitBlt(&backPix, rect.x(), rect.y(), &TEXT); |
348 | break; | 340 | break; |
349 | } | 341 | } |
350 | 342 | ||
351 | return SAVE; | 343 | return SAVE; |
352 | } | 344 | } |
353 | 345 | ||
354 | QRect Painter::draw(int col, int row, DrawWidget where, | 346 | QRect Painter::draw(int col, int row, DrawWidget where, |
355 | QString str, QColor fg, QColor bg, int align) | 347 | QString str, QColor fg, QColor bg, int align) |
356 | { | 348 | { |
357 | QPixmap TEXT = bitfont->text(str, fg, bg); | 349 | QPixmap TEXT = bitfont->text(str, fg, bg); |
358 | 350 | ||
359 | QRect rect = this->rect(row*BoardWidth+col, str, align); | 351 | QRect rect = this->rect(row*BoardWidth+col, str, align); |
360 | draw(rect, where, TEXT); | 352 | draw(rect, where, TEXT); |
361 | 353 | ||
362 | return rect; | 354 | return rect; |
363 | } | 355 | } |
364 | 356 | ||
365 | void Painter::initPixmaps() | 357 | void Painter::initPixmaps() |
366 | { | 358 | { |
367 | if (lastPointPixmapName != pointPixmapName.at(level)) { | 359 | if (lastPointPixmapName != pointPixmapName.at(level)) { |
368 | pointPix = loadPixmap(w, pointPixmapName.at(level), pointPix); | 360 | pointPix = loadPixmap(w, pointPixmapName.at(level), pointPix); |
369 | lastPointPixmapName = pointPixmapName.at(level); | 361 | lastPointPixmapName = pointPixmapName.at(level); |
370 | } | 362 | } |
371 | if (lastPrisonPixmapName != prisonPixmapName.at(level)) { | 363 | if (lastPrisonPixmapName != prisonPixmapName.at(level)) { |
372 | prisonPix = loadPixmap(w, prisonPixmapName.at(level), prisonPix); | 364 | prisonPix = loadPixmap(w, prisonPixmapName.at(level), prisonPix); |
373 | lastPrisonPixmapName = prisonPixmapName.at(level); | 365 | lastPrisonPixmapName = prisonPixmapName.at(level); |
374 | } | 366 | } |
375 | if (lastEnergizerPixmapName != energizerPixmapName.at(level)) { | 367 | if (lastEnergizerPixmapName != energizerPixmapName.at(level)) { |
376 | energizerPix = loadPixmap(w, energizerPixmapName.at(level), energizerPix); | 368 | energizerPix = loadPixmap(w, energizerPixmapName.at(level), energizerPix); |
377 | lastEnergizerPixmapName = energizerPixmapName.at(level); | 369 | lastEnergizerPixmapName = energizerPixmapName.at(level); |
378 | } | 370 | } |
379 | if (lastFruitPixmapName != fruitPixmapName.at(level)) { | 371 | if (lastFruitPixmapName != fruitPixmapName.at(level)) { |
380 | fruitPix = loadPixmap(w, fruitPixmapName.at(level), fruitPix); | 372 | fruitPix = loadPixmap(w, fruitPixmapName.at(level), fruitPix); |
381 | lastFruitPixmapName = fruitPixmapName.at(level); | 373 | lastFruitPixmapName = fruitPixmapName.at(level); |
382 | } | 374 | } |
383 | if (lastPacmanPixmapName != pacmanPixmapName.at(level)) { | 375 | if (lastPacmanPixmapName != pacmanPixmapName.at(level)) { |
384 | pacmanPix = loadPixmap(w, pacmanPixmapName.at(level), pacmanPix); | 376 | pacmanPix = loadPixmap(w, pacmanPixmapName.at(level), pacmanPix); |
385 | lastPacmanPixmapName = pacmanPixmapName.at(level); | 377 | lastPacmanPixmapName = pacmanPixmapName.at(level); |
386 | } | 378 | } |
387 | if (lastDyingPixmapName != dyingPixmapName.at(level)) { | 379 | if (lastDyingPixmapName != dyingPixmapName.at(level)) { |
388 | dyingPix = loadPixmap(w, dyingPixmapName.at(level), dyingPix); | 380 | dyingPix = loadPixmap(w, dyingPixmapName.at(level), dyingPix); |
389 | lastDyingPixmapName = dyingPixmapName.at(level); | 381 | lastDyingPixmapName = dyingPixmapName.at(level); |
390 | } | 382 | } |
391 | if (lastEyesPixmapName != eyesPixmapName.at(level)) { | 383 | if (lastEyesPixmapName != eyesPixmapName.at(level)) { |
392 | eyesPix = loadPixmap(w, eyesPixmapName.at(level), eyesPix); | 384 | eyesPix = loadPixmap(w, eyesPixmapName.at(level), eyesPix); |
393 | lastEyesPixmapName = eyesPixmapName.at(level); | 385 | lastEyesPixmapName = eyesPixmapName.at(level); |
394 | } | 386 | } |
395 | if (lastMonsterPixmapName != monsterPixmapName.at(level)) { | 387 | if (lastMonsterPixmapName != monsterPixmapName.at(level)) { |
396 | monsterPix = loadPixmap(w, monsterPixmapName.at(level), monsterPix); | 388 | monsterPix = loadPixmap(w, monsterPixmapName.at(level), monsterPix); |
397 | lastMonsterPixmapName = monsterPixmapName.at(level); | 389 | lastMonsterPixmapName = monsterPixmapName.at(level); |
398 | } | 390 | } |
399 | 391 | ||
400 | if (lastFruitScorePixmapName != fruitScorePixmapName.at(level) || | 392 | if (lastFruitScorePixmapName != fruitScorePixmapName.at(level) || |
401 | (const char *) *fruitScorePixmapName.at(level) == '\0') { | 393 | (const char *) *fruitScorePixmapName.at(level) == '\0') { |
402 | if ((const char *) *fruitScorePixmapName.at(level) == '\0') { | 394 | if ((const char *) *fruitScorePixmapName.at(level) == '\0') { |
403 | fruitScorePix = textPixmap(fruitScoreString, fruitScorePix, PINK); | 395 | fruitScorePix = textPixmap(fruitScoreString, fruitScorePix, PINK); |
404 | } else { | 396 | } else { |
405 | fruitScorePix = loadPixmap(w, fruitScorePixmapName.at(level), | 397 | fruitScorePix = loadPixmap(w, fruitScorePixmapName.at(level), |
406 | fruitScorePix); | 398 | fruitScorePix); |
407 | lastFruitScorePixmapName = fruitScorePixmapName.at(level); | 399 | lastFruitScorePixmapName = fruitScorePixmapName.at(level); |
408 | } | 400 | } |
409 | } | 401 | } |
410 | 402 | ||
411 | if (lastMonsterScorePixmapName != monsterScorePixmapName.at(level) || | 403 | if (lastMonsterScorePixmapName != monsterScorePixmapName.at(level) || |
412 | (const char *) *monsterScorePixmapName.at(level) == '\0') { | 404 | (const char *) *monsterScorePixmapName.at(level) == '\0') { |
413 | if ((const char *) *monsterScorePixmapName.at(level) == '\0') { | 405 | if ((const char *) *monsterScorePixmapName.at(level) == '\0') { |
414 | monsterScorePix = textPixmap(monsterScoreString, monsterScorePix, CYAN); | 406 | monsterScorePix = textPixmap(monsterScoreString, monsterScorePix, CYAN); |
415 | } else { | 407 | } else { |
416 | monsterScorePix = loadPixmap(w, monsterScorePixmapName.at(level), | 408 | monsterScorePix = loadPixmap(w, monsterScorePixmapName.at(level), |
417 | monsterScorePix); | 409 | monsterScorePix); |
418 | lastMonsterScorePixmapName = monsterScorePixmapName.at(level); | 410 | lastMonsterScorePixmapName = monsterScorePixmapName.at(level); |
419 | } | 411 | } |
420 | } | 412 | } |
421 | 413 | ||
422 | if (lastWallPixmapName != wallPixmapName.at(level)) { | 414 | if (lastWallPixmapName != wallPixmapName.at(level)) { |
423 | wallPix = loadPixmap(w, wallPixmapName.at(level), wallPix); | 415 | wallPix = loadPixmap(w, wallPixmapName.at(level), wallPix); |
424 | if (wallPix->isEmpty()) { | 416 | if (wallPix->isEmpty()) { |
425 | BlockWidth = 0; | 417 | BlockWidth = 0; |
426 | BlockHeight = 0; | 418 | BlockHeight = 0; |
427 | } else { | 419 | } else { |
428 | BlockWidth = wallPix->at(0)->width(); | 420 | BlockWidth = wallPix->at(0)->width(); |
429 | BlockHeight = wallPix->at(0)->height(); | 421 | BlockHeight = wallPix->at(0)->height(); |
430 | } | 422 | } |
431 | lastWallPixmapName = wallPixmapName.at(level); | 423 | lastWallPixmapName = wallPixmapName.at(level); |
432 | } | 424 | } |
433 | } | 425 | } |
434 | 426 | ||
435 | void Painter::initbackPixmaps() | 427 | void Painter::initbackPixmaps() |
436 | { | 428 | { |
437 | backgroundColor = BLACK; | 429 | backgroundColor = BLACK; |
438 | 430 | ||
439 | backPix.resize((BoardWidth-3)*BlockWidth, (BoardHeight-3)*BlockHeight ); | 431 | backPix.resize((BoardWidth-3)*BlockWidth, (BoardHeight-3)*BlockHeight ); |
440 | backPix.fill(backgroundColor); | 432 | backPix.fill(backgroundColor); |
441 | } | 433 | } |
442 | 434 | ||
443 | void Painter::initRoomPixmap() | 435 | void Painter::initRoomPixmap() |
444 | { | 436 | { |
445 | roomPix.resize((BoardWidth-3)*BlockWidth, (BoardHeight-3)*BlockHeight ); | 437 | roomPix.resize((BoardWidth-3)*BlockWidth, (BoardHeight-3)*BlockHeight ); |
446 | bitBlt(&roomPix,0,0, &backPix); | 438 | bitBlt(&roomPix,0,0, &backPix); |
447 | 439 | ||
448 | for (unsigned int x = 0; x < board->size(); x++) { | 440 | for (unsigned int x = 0; x < board->size(); x++) { |
449 | if (board->isBrick(x)) | 441 | if (board->isBrick(x)) |
450 | drawBrick(x); | 442 | drawBrick(x); |
451 | if (board->isPrison(x) || board->isGate(x)) | 443 | if (board->isPrison(x) || board->isGate(x)) |
452 | drawPrison(x); | 444 | drawPrison(x); |
453 | if (board->isPoint(x)) | 445 | if (board->isPoint(x)) |
454 | drawPoint(x); | 446 | drawPoint(x); |
455 | } | 447 | } |
456 | } | 448 | } |
457 | 449 | ||
458 | void Painter::drawBrick(int pos) | 450 | void Painter::drawBrick(int pos) |
459 | { | 451 | { |
460 | int border = 0; | 452 | int border = 0; |
461 | if (board->isBrick(board->move(pos, N ))) border |= (1 << 0); | 453 | if (board->isBrick(board->move(pos, N ))) border |= (1 << 0); |
462 | if (board->isBrick(board->move(pos, NE))) border |= (1 << 1); | 454 | if (board->isBrick(board->move(pos, NE))) border |= (1 << 1); |
463 | if (board->isBrick(board->move(pos, E ))) border |= (1 << 2); | 455 | if (board->isBrick(board->move(pos, E ))) border |= (1 << 2); |
464 | if (board->isBrick(board->move(pos, SE))) border |= (1 << 3); | 456 | if (board->isBrick(board->move(pos, SE))) border |= (1 << 3); |
465 | if (board->isBrick(board->move(pos, S ))) border |= (1 << 4); | 457 | if (board->isBrick(board->move(pos, S ))) border |= (1 << 4); |
466 | if (board->isBrick(board->move(pos, SW))) border |= (1 << 5); | 458 | if (board->isBrick(board->move(pos, SW))) border |= (1 << 5); |
467 | if (board->isBrick(board->move(pos, W ))) border |= (1 << 6); | 459 | if (board->isBrick(board->move(pos, W ))) border |= (1 << 6); |
468 | if (board->isBrick(board->move(pos, NW))) border |= (1 << 7); | 460 | if (board->isBrick(board->move(pos, NW))) border |= (1 << 7); |
469 | 461 | ||
470 | if (board->isOut(board->move(pos, N ))) border |= (1 << 8); | 462 | if (board->isOut(board->move(pos, N ))) border |= (1 << 8); |
471 | if (board->isOut(board->move(pos, NE))) border |= (1 << 9); | 463 | if (board->isOut(board->move(pos, NE))) border |= (1 << 9); |
472 | if (board->isOut(board->move(pos, E ))) border |= (1 << 10); | 464 | if (board->isOut(board->move(pos, E ))) border |= (1 << 10); |
473 | if (board->isOut(board->move(pos, SE))) border |= (1 << 11); | 465 | if (board->isOut(board->move(pos, SE))) border |= (1 << 11); |
474 | if (board->isOut(board->move(pos, S ))) border |= (1 << 12); | 466 | if (board->isOut(board->move(pos, S ))) border |= (1 << 12); |
475 | if (board->isOut(board->move(pos, SW))) border |= (1 << 13); | 467 | if (board->isOut(board->move(pos, SW))) border |= (1 << 13); |
476 | if (board->isOut(board->move(pos, W ))) border |= (1 << 14); | 468 | if (board->isOut(board->move(pos, W ))) border |= (1 << 14); |
477 | if (board->isOut(board->move(pos, NW))) border |= (1 << 15); | 469 | if (board->isOut(board->move(pos, NW))) border |= (1 << 15); |
478 | 470 | ||
479 | switch (border & 0xFF) { | 471 | switch (border & 0xFF) { |
480 | case 31 : border = 0; break; | 472 | case 31 : border = 0; break; |
481 | case 159 : border = 0; break; | 473 | case 159 : border = 0; break; |
482 | case 63 : border = 0; break; | 474 | case 63 : border = 0; break; |
483 | case 191 : border = 0; break; | 475 | case 191 : border = 0; break; |
484 | case 241 : border = 1; break; | 476 | case 241 : border = 1; break; |
485 | case 249 : border = 1; break; | 477 | case 249 : border = 1; break; |
486 | case 243 : border = 1; break; | 478 | case 243 : border = 1; break; |
487 | case 251 : border = 1; break; | 479 | case 251 : border = 1; break; |
488 | case 124 : border = 2; break; | 480 | case 124 : border = 2; break; |
489 | case 252 : border = 2; break; | 481 | case 252 : border = 2; break; |
490 | case 126 : border = 2; break; | 482 | case 126 : border = 2; break; |
491 | case 199 : border = 3; break; | 483 | case 199 : border = 3; break; |
492 | case 231 : border = 3; break; | 484 | case 231 : border = 3; break; |
493 | case 207 : border = 3; break; | 485 | case 207 : border = 3; break; |
494 | case 28 : if ((border >> 8) > 0) | 486 | case 28 : if ((border >> 8) > 0) |
495 | border = 24; | 487 | border = 24; |
496 | else | 488 | else |
497 | border = 4; | 489 | border = 4; |
498 | break; | 490 | break; |
499 | case 112 : if ((border >> 8) > 0) | 491 | case 112 : if ((border >> 8) > 0) |
500 | border = 27; | 492 | border = 27; |
501 | else | 493 | else |
502 | border = 5; | 494 | border = 5; |
503 | break; | 495 | break; |
504 | case 7 : if ((border >> 8) > 0) | 496 | case 7 : if ((border >> 8) > 0) |
505 | border = 25; | 497 | border = 25; |
506 | else | 498 | else |
507 | border = 6; | 499 | border = 6; |
508 | break; | 500 | break; |
509 | case 193 : if ((border >> 8) > 0) | 501 | case 193 : if ((border >> 8) > 0) |
510 | border = 26; | 502 | border = 26; |
511 | else | 503 | else |
512 | border = 7; | 504 | border = 7; |
513 | break; | 505 | break; |
514 | case 247 : if ((border & (1 << 11)) > 0) | 506 | case 247 : if ((border & (1 << 11)) > 0) |
515 | border = 23; | 507 | border = 23; |
516 | else | 508 | else |
517 | border = 8; | 509 | border = 8; |
518 | break; | 510 | break; |
519 | case 119 : if ((border & (1 << 15)) > 0) | 511 | case 119 : if ((border & (1 << 15)) > 0) |
520 | border = 8; | 512 | border = 8; |
521 | if ((border & (1 << 11)) > 0) | 513 | if ((border & (1 << 11)) > 0) |
522 | border = 11; | 514 | border = 11; |
523 | break; | 515 | break; |
524 | case 223 : if ((border & (1 << 13)) > 0) | 516 | case 223 : if ((border & (1 << 13)) > 0) |
525 | border = 20; | 517 | border = 20; |
526 | else | 518 | else |
527 | border = 9; | 519 | border = 9; |
528 | break; | 520 | break; |
529 | case 221 : if ((border & (1 << 13)) > 0) | 521 | case 221 : if ((border & (1 << 13)) > 0) |
530 | border = 10; | 522 | border = 10; |
531 | if ((border & (1 << 9)) > 0) | 523 | if ((border & (1 << 9)) > 0) |
532 | border = 9; | 524 | border = 9; |
533 | break; | 525 | break; |
534 | case 253 : if ((border & (1 << 9)) > 0) | 526 | case 253 : if ((border & (1 << 9)) > 0) |
535 | border = 21; | 527 | border = 21; |
536 | else | 528 | else |
diff --git a/noncore/games/kpacman/referee.cpp b/noncore/games/kpacman/referee.cpp index 1b810d8..2d0f3be 100644 --- a/noncore/games/kpacman/referee.cpp +++ b/noncore/games/kpacman/referee.cpp | |||
@@ -1,542 +1,533 @@ | |||
1 | 1 | ||
2 | #include "portable.h" | 2 | #include "portable.h" |
3 | 3 | ||
4 | #if defined( KDE2_PORT ) | 4 | #if defined( KDE2_PORT ) |
5 | #include <kapp.h> | 5 | #include <kapp.h> |
6 | #include <kconfig.h> | 6 | #include <kconfig.h> |
7 | #include <kstddirs.h> | 7 | #include <kstddirs.h> |
8 | #include <kaccel.h> | 8 | #include <kaccel.h> |
9 | #include <referee.h> | 9 | #include <referee.h> |
10 | #include <referee.moc> | 10 | #include <referee.moc> |
11 | #elif defined( QPE_PORT ) | 11 | #elif defined( QPE_PORT ) |
12 | #include <qaccel.h> | 12 | #include <qaccel.h> |
13 | #include <qpe/qpeapplication.h> | 13 | #include <qpe/qpeapplication.h> |
14 | #include <qpe/config.h> | 14 | #include <qpe/config.h> |
15 | #include "referee.h" | 15 | #include "referee.h" |
16 | #endif | 16 | #endif |
17 | 17 | ||
18 | #include <qdatetm.h> | ||
19 | #include <stdlib.h> | 18 | #include <stdlib.h> |
20 | #include <qtimer.h> | 19 | #include <qtimer.h> |
21 | #include <qevent.h> | ||
22 | #include <qcolor.h> | ||
23 | #include <qkeycode.h> | ||
24 | #include <qfileinfo.h> | 20 | #include <qfileinfo.h> |
25 | 21 | ||
26 | #include "board.h" | ||
27 | #include "pacman.h" | ||
28 | #include "monster.h" | ||
29 | #include "fruit.h" | ||
30 | #include "painter.h" | ||
31 | 22 | ||
32 | Referee::Referee( QWidget *parent, const char *name, int Scheme, int Mode, Bitfont *font) | 23 | Referee::Referee( QWidget *parent, const char *name, int Scheme, int Mode, Bitfont *font) |
33 | : QWidget( parent, name ) | 24 | : QWidget( parent, name ) |
34 | { | 25 | { |
35 | gameState.resize(12); | 26 | gameState.resize(12); |
36 | gameTimer = 0; | 27 | gameTimer = 0; |
37 | energizerTimer = 0; | 28 | energizerTimer = 0; |
38 | 29 | ||
39 | focusedPause = FALSE; | 30 | focusedPause = FALSE; |
40 | setFocusPolicy(QWidget::StrongFocus); | 31 | setFocusPolicy(QWidget::StrongFocus); |
41 | 32 | ||
42 | initKeys(); | 33 | initKeys(); |
43 | 34 | ||
44 | scheme = Scheme; | 35 | scheme = Scheme; |
45 | mode = Mode; | 36 | mode = Mode; |
46 | confScheme(); | 37 | confScheme(); |
47 | 38 | ||
48 | board = new Board(BoardWidth*BoardHeight); | 39 | board = new Board(BoardWidth*BoardHeight); |
49 | 40 | ||
50 | pix = new Painter(board, this, scheme, mode, font); | 41 | pix = new Painter(board, this, scheme, mode, font); |
51 | setFixedSize(pix->levelPix().size()); | 42 | setFixedSize(pix->levelPix().size()); |
52 | 43 | ||
53 | pacman = new Pacman(board); | 44 | pacman = new Pacman(board); |
54 | 45 | ||
55 | fruit = new Fruit(board); | 46 | fruit = new Fruit(board); |
56 | 47 | ||
57 | monsters = new QList<Monster>; | 48 | monsters = new QList<Monster>; |
58 | monsters->setAutoDelete(TRUE); | 49 | monsters->setAutoDelete(TRUE); |
59 | 50 | ||
60 | monsterRect = new QList<QRect>; | 51 | monsterRect = new QList<QRect>; |
61 | monsterRect->setAutoDelete(TRUE); | 52 | monsterRect->setAutoDelete(TRUE); |
62 | 53 | ||
63 | energizers = new QList<Energizer>; | 54 | energizers = new QList<Energizer>; |
64 | energizers->setAutoDelete(TRUE); | 55 | energizers->setAutoDelete(TRUE); |
65 | 56 | ||
66 | energizerRect = new QList<QRect>; | 57 | energizerRect = new QList<QRect>; |
67 | energizerRect->setAutoDelete(TRUE); | 58 | energizerRect->setAutoDelete(TRUE); |
68 | 59 | ||
69 | pacmanRect.setRect(0, 0, 0, 0); | 60 | pacmanRect.setRect(0, 0, 0, 0); |
70 | fruitRect.setRect(0, 0, 0, 0); | 61 | fruitRect.setRect(0, 0, 0, 0); |
71 | 62 | ||
72 | QTime midnight( 0, 0, 0 ); | 63 | QTime midnight( 0, 0, 0 ); |
73 | srand( midnight.secsTo(QTime::currentTime()) ); | 64 | srand( midnight.secsTo(QTime::currentTime()) ); |
74 | 65 | ||
75 | lifes = 0; | 66 | lifes = 0; |
76 | points = 0; | 67 | points = 0; |
77 | 68 | ||
78 | emit setLifes(lifes); | 69 | emit setLifes(lifes); |
79 | emit setPoints(points); | 70 | emit setPoints(points); |
80 | 71 | ||
81 | intro(); | 72 | intro(); |
82 | } | 73 | } |
83 | 74 | ||
84 | void Referee::paintEvent( QPaintEvent *e) | 75 | void Referee::paintEvent( QPaintEvent *e) |
85 | { | 76 | { |
86 | if (gameState.testBit(HallOfFame)) | 77 | if (gameState.testBit(HallOfFame)) |
87 | return; | 78 | return; |
88 | 79 | ||
89 | QRect rect = e->rect(); | 80 | QRect rect = e->rect(); |
90 | 81 | ||
91 | if (!rect.isEmpty()) { | 82 | if (!rect.isEmpty()) { |
92 | QPixmap p = pix->levelPix(); | 83 | QPixmap p = pix->levelPix(); |
93 | bitBlt(this, rect.x(), rect.y(), | 84 | bitBlt(this, rect.x(), rect.y(), |
94 | &p, rect.x(), rect.y(), rect.width(), rect.height()); | 85 | &p, rect.x(), rect.y(), rect.width(), rect.height()); |
95 | } | 86 | } |
96 | 87 | ||
97 | if ((gameState.testBit(GameOver) || gameState.testBit(Demonstration)) && | 88 | if ((gameState.testBit(GameOver) || gameState.testBit(Demonstration)) && |
98 | rect.intersects(pix->rect(board->position(fruithome), tr("GAME OVER")))) | 89 | rect.intersects(pix->rect(board->position(fruithome), tr("GAME OVER")))) |
99 | pix->draw(board->position(fruithome), Widget, tr("GAME OVER"), RED); | 90 | pix->draw(board->position(fruithome), Widget, tr("GAME OVER"), RED); |
100 | 91 | ||
101 | for (Energizer *e = energizers->first(); e != 0; e = energizers->next()) { | 92 | for (Energizer *e = energizers->first(); e != 0; e = energizers->next()) { |
102 | if (e && e->state() == on && | 93 | if (e && e->state() == on && |
103 | rect.intersects(pix->rect(e->position(), EnergizerPix)) && | 94 | rect.intersects(pix->rect(e->position(), EnergizerPix)) && |
104 | !(e->position() == pacman->position() && gameState.testBit(Scoring))) { | 95 | !(e->position() == pacman->position() && gameState.testBit(Scoring))) { |
105 | if (e->pix() != -1) | 96 | if (e->pix() != -1) |
106 | pix->draw(e->position(), Widget, EnergizerPix, e->pix()); | 97 | pix->draw(e->position(), Widget, EnergizerPix, e->pix()); |
107 | } | 98 | } |
108 | } | 99 | } |
109 | 100 | ||
110 | if (!gameState.testBit(Init)) { | 101 | if (!gameState.testBit(Init)) { |
111 | 102 | ||
112 | if (!gameState.testBit(Dying) && (fruit->pix() != -1)) | 103 | if (!gameState.testBit(Dying) && (fruit->pix() != -1)) |
113 | if (fruit->state() != active) { | 104 | if (fruit->state() != active) { |
114 | if (rect.intersects(pix->rect(fruit->position(), FruitScorePix, fruit->pix()))) | 105 | if (rect.intersects(pix->rect(fruit->position(), FruitScorePix, fruit->pix()))) |
115 | pix->draw(fruit->position(), Widget, FruitScorePix, fruit->pix()); | 106 | pix->draw(fruit->position(), Widget, FruitScorePix, fruit->pix()); |
116 | } else { | 107 | } else { |
117 | if (rect.intersects(pix->rect(fruit->position(), FruitPix, fruit->pix()))) | 108 | if (rect.intersects(pix->rect(fruit->position(), FruitPix, fruit->pix()))) |
118 | pix->draw(fruit->position(), Widget, FruitPix, fruit->pix()); | 109 | pix->draw(fruit->position(), Widget, FruitPix, fruit->pix()); |
119 | } | 110 | } |
120 | 111 | ||
121 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) | 112 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) |
122 | if (m && m->state() == harmless && | 113 | if (m && m->state() == harmless && |
123 | rect.intersects(pix->rect(m->position(), MonsterPix)) && | 114 | rect.intersects(pix->rect(m->position(), MonsterPix)) && |
124 | !(m->position() == pacman->position() && gameState.testBit(Scoring))) { | 115 | !(m->position() == pacman->position() && gameState.testBit(Scoring))) { |
125 | if (m->body() != -1) | 116 | if (m->body() != -1) |
126 | pix->draw(m->position(), Widget, MonsterPix, m->body()); | 117 | pix->draw(m->position(), Widget, MonsterPix, m->body()); |
127 | if (m->eyes() != -1) | 118 | if (m->eyes() != -1) |
128 | pix->draw(m->position(), Widget, EyesPix, m->eyes()); | 119 | pix->draw(m->position(), Widget, EyesPix, m->eyes()); |
129 | } | 120 | } |
130 | 121 | ||
131 | if (!gameState.testBit(Scoring) && !gameState.testBit(LevelDone) && | 122 | if (!gameState.testBit(Scoring) && !gameState.testBit(LevelDone) && |
132 | rect.intersects(pix->rect(pacman->position(), PacmanPix)) && pacman->pix() != -1) | 123 | rect.intersects(pix->rect(pacman->position(), PacmanPix)) && pacman->pix() != -1) |
133 | pix->draw(pacman->position(), Widget, PacmanPix, pacman->pix()); | 124 | pix->draw(pacman->position(), Widget, PacmanPix, pacman->pix()); |
134 | 125 | ||
135 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) | 126 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) |
136 | if (m && m->state() != harmless && | 127 | if (m && m->state() != harmless && |
137 | rect.intersects(pix->rect(m->position(), MonsterPix)) && | 128 | rect.intersects(pix->rect(m->position(), MonsterPix)) && |
138 | !(m->position() == pacman->position() && gameState.testBit(Scoring))) { | 129 | !(m->position() == pacman->position() && gameState.testBit(Scoring))) { |
139 | if (m->body() != -1) | 130 | if (m->body() != -1) |
140 | pix->draw(m->position(), Widget, MonsterPix, m->body()); | 131 | pix->draw(m->position(), Widget, MonsterPix, m->body()); |
141 | if (m->eyes() != -1) | 132 | if (m->eyes() != -1) |
142 | pix->draw(m->position(), Widget, EyesPix, m->eyes()); | 133 | pix->draw(m->position(), Widget, EyesPix, m->eyes()); |
143 | } | 134 | } |
144 | } | 135 | } |
145 | 136 | ||
146 | if (gameState.testBit(Scoring) && | 137 | if (gameState.testBit(Scoring) && |
147 | rect.intersects(pix->rect(pacman->position(), MonsterScorePix, monstersEaten-1))) | 138 | rect.intersects(pix->rect(pacman->position(), MonsterScorePix, monstersEaten-1))) |
148 | pix->draw(pacman->position(), Widget, MonsterScorePix, monstersEaten-1); | 139 | pix->draw(pacman->position(), Widget, MonsterScorePix, monstersEaten-1); |
149 | 140 | ||
150 | if (gameState.testBit(Init) && gameState.testBit(Dying) && | 141 | if (gameState.testBit(Init) && gameState.testBit(Dying) && |
151 | timerCount < pix->maxPixmaps(DyingPix) && | 142 | timerCount < pix->maxPixmaps(DyingPix) && |
152 | rect.intersects(pix->rect(pacman->position(), PacmanPix))) | 143 | rect.intersects(pix->rect(pacman->position(), PacmanPix))) |
153 | pix->draw(pacman->position(), Widget, DyingPix, timerCount); | 144 | pix->draw(pacman->position(), Widget, DyingPix, timerCount); |
154 | 145 | ||
155 | if (gameState.testBit(LevelDone) && | 146 | if (gameState.testBit(LevelDone) && |
156 | rect.intersects(pix->rect(pacman->position(), PacmanPix))) | 147 | rect.intersects(pix->rect(pacman->position(), PacmanPix))) |
157 | pix->draw(pacman->position(), Widget, PacmanPix, pacman->pix()); | 148 | pix->draw(pacman->position(), Widget, PacmanPix, pacman->pix()); |
158 | 149 | ||
159 | if (gameState.testBit(Player) && | 150 | if (gameState.testBit(Player) && |
160 | rect.intersects(pix->rect(board->position(monsterhome, 0), tr("PLAYER ONE")))) | 151 | rect.intersects(pix->rect(board->position(monsterhome, 0), tr("PLAYER ONE")))) |
161 | pix->draw(board->position(monsterhome, 0), Widget, tr("PLAYER ONE"), CYAN); | 152 | pix->draw(board->position(monsterhome, 0), Widget, tr("PLAYER ONE"), CYAN); |
162 | 153 | ||
163 | if (gameState.testBit(Ready) && | 154 | if (gameState.testBit(Ready) && |
164 | rect.intersects(pix->rect(board->position(fruithome), tr("READY!")))) | 155 | rect.intersects(pix->rect(board->position(fruithome), tr("READY!")))) |
165 | pix->draw(board->position(fruithome), Widget, tr("READY!"), YELLOW); | 156 | pix->draw(board->position(fruithome), Widget, tr("READY!"), YELLOW); |
166 | 157 | ||
167 | if (gameState.testBit(Paused) && | 158 | if (gameState.testBit(Paused) && |
168 | rect.intersects(pix->rect((BoardWidth*BoardHeight)/2-BoardWidth, tr("PAUSED")))) | 159 | rect.intersects(pix->rect((BoardWidth*BoardHeight)/2-BoardWidth, tr("PAUSED")))) |
169 | pix->draw((BoardWidth*BoardHeight)/2-BoardWidth, Widget, tr("PAUSED"), RED, BLACK); | 160 | pix->draw((BoardWidth*BoardHeight)/2-BoardWidth, Widget, tr("PAUSED"), RED, BLACK); |
170 | } | 161 | } |
171 | 162 | ||
172 | void Referee::timerEvent( QTimerEvent *e ) | 163 | void Referee::timerEvent( QTimerEvent *e ) |
173 | { | 164 | { |
174 | if (gameState.testBit(HallOfFame)) | 165 | if (gameState.testBit(HallOfFame)) |
175 | return; | 166 | return; |
176 | 167 | ||
177 | QRect lastRect; | 168 | QRect lastRect; |
178 | int lastPix; | 169 | int lastPix; |
179 | bool moved = FALSE; | 170 | bool moved = FALSE; |
180 | int eated = 0; | 171 | int eated = 0; |
181 | 172 | ||
182 | if (e->timerId() == energizerTimer) { | 173 | if (e->timerId() == energizerTimer) { |
183 | for (int e = 0; e < board->energizers(); e++) { | 174 | for (int e = 0; e < board->energizers(); e++) { |
184 | lastRect = pix->rect(energizers->at(e)->position(), EnergizerPix); | 175 | lastRect = pix->rect(energizers->at(e)->position(), EnergizerPix); |
185 | lastPix = energizers->at(e)->pix(); | 176 | lastPix = energizers->at(e)->pix(); |
186 | if (energizers->at(e)->move()) { | 177 | if (energizers->at(e)->move()) { |
187 | moved = TRUE; | 178 | moved = TRUE; |
188 | *energizerRect->at(e) = pix->rect(energizers->at(e)->position(), EnergizerPix); | 179 | *energizerRect->at(e) = pix->rect(energizers->at(e)->position(), EnergizerPix); |
189 | if (lastPix == energizers->at(e)->pix() && | 180 | if (lastPix == energizers->at(e)->pix() && |
190 | lastRect == pix->rect(energizers->at(e)->position(), EnergizerPix)) | 181 | lastRect == pix->rect(energizers->at(e)->position(), EnergizerPix)) |
191 | energizerRect->at(e)->setRect(0, 0, 0, 0); | 182 | energizerRect->at(e)->setRect(0, 0, 0, 0); |
192 | else | 183 | else |
193 | *energizerRect->at(e) = pix->rect(*energizerRect->at(e), lastRect); | 184 | *energizerRect->at(e) = pix->rect(*energizerRect->at(e), lastRect); |
194 | } | 185 | } |
195 | } | 186 | } |
196 | 187 | ||
197 | for (int e = 0; e < board->energizers(); e++) | 188 | for (int e = 0; e < board->energizers(); e++) |
198 | if (!energizerRect->at(e)->isNull()) | 189 | if (!energizerRect->at(e)->isNull()) |
199 | repaint(*energizerRect->at(e), FALSE); | 190 | repaint(*energizerRect->at(e), FALSE); |
200 | 191 | ||
201 | return; | 192 | return; |
202 | } | 193 | } |
203 | 194 | ||
204 | timerCount++; | 195 | timerCount++; |
205 | 196 | ||
206 | lastRect = pix->rect(pacman->position(), PacmanPix); | 197 | lastRect = pix->rect(pacman->position(), PacmanPix); |
207 | lastPix = pacman->pix(); | 198 | lastPix = pacman->pix(); |
208 | 199 | ||
209 | if (moved = pacman->move()) { // pacman really moved | 200 | if (moved = pacman->move()) { // pacman really moved |
210 | pacmanRect = pix->rect(pacman->position(), PacmanPix); | 201 | pacmanRect = pix->rect(pacman->position(), PacmanPix); |
211 | if (lastPix == pacman->pix() && | 202 | if (lastPix == pacman->pix() && |
212 | lastRect == pix->rect(pacman->position(), PacmanPix)) | 203 | lastRect == pix->rect(pacman->position(), PacmanPix)) |
213 | pacmanRect.setRect(0, 0, 0, 0); // nothing to do, because the pixmap | 204 | pacmanRect.setRect(0, 0, 0, 0); // nothing to do, because the pixmap |
214 | else // and the position isn't changed. | 205 | else // and the position isn't changed. |
215 | pacmanRect = pix->rect(pacmanRect, lastRect); | 206 | pacmanRect = pix->rect(pacmanRect, lastRect); |
216 | } else | 207 | } else |
217 | pacmanRect.setRect(0, 0, 0, 0); | 208 | pacmanRect.setRect(0, 0, 0, 0); |
218 | 209 | ||
219 | int pos = pacman->position(); | 210 | int pos = pacman->position(); |
220 | 211 | ||
221 | if (moved && board->isMonster(pos) && !gameState.testBit(Dying)) { | 212 | if (moved && board->isMonster(pos) && !gameState.testBit(Dying)) { |
222 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) | 213 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) |
223 | if (m && m->position() == pos) { | 214 | if (m && m->position() == pos) { |
224 | if (m->state() == harmless && !gameState.testBit(Dying)) { | 215 | if (m->state() == harmless && !gameState.testBit(Dying)) { |
225 | m->setREM(remTicks[level]); | 216 | m->setREM(remTicks[level]); |
226 | m->setDirection(X); // prevent movement before eaten() | 217 | m->setDirection(X); // prevent movement before eaten() |
227 | eated++; | 218 | eated++; |
228 | if (gameState.testBit(Introducing)) | 219 | if (gameState.testBit(Introducing)) |
229 | m->setPosition(OUT); | 220 | m->setPosition(OUT); |
230 | } | 221 | } |
231 | if (m->state() == dangerous && !gameState.testBit(Dying)) | 222 | if (m->state() == dangerous && !gameState.testBit(Dying)) |
232 | killed(); | 223 | killed(); |
233 | } | 224 | } |
234 | } | 225 | } |
235 | 226 | ||
236 | if (moved && !gameState.testBit(Dying)) { | 227 | if (moved && !gameState.testBit(Dying)) { |
237 | if (board->isPoint(pos)) { | 228 | if (board->isPoint(pos)) { |
238 | board->reset(pos, Point); | 229 | board->reset(pos, Point); |
239 | score(pointScore); | 230 | score(pointScore); |
240 | pix->erase(pos, PointPix); | 231 | pix->erase(pos, PointPix); |
241 | } | 232 | } |
242 | if (board->isEnergizer(pos)) { | 233 | if (board->isEnergizer(pos)) { |
243 | for (int e = 0; e < board->energizers();e++) { | 234 | for (int e = 0; e < board->energizers();e++) { |
244 | if (energizers->at(e)->position() == pos) { | 235 | if (energizers->at(e)->position() == pos) { |
245 | energizers->at(e)->setOff(); | 236 | energizers->at(e)->setOff(); |
246 | energizers->remove(e); | 237 | energizers->remove(e); |
247 | energizerRect->remove(e); | 238 | energizerRect->remove(e); |
248 | e = board->energizers(); | 239 | e = board->energizers(); |
249 | } | 240 | } |
250 | } | 241 | } |
251 | board->reset(pos, energizer); | 242 | board->reset(pos, energizer); |
252 | score(energizerScore); | 243 | score(energizerScore); |
253 | monstersEaten = 0; | 244 | monstersEaten = 0; |
254 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) | 245 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) |
255 | if (m && m->state() != rem) { | 246 | if (m && m->state() != rem) { |
256 | m->setHarmless(harmlessTicks[level], harmlessDurTicks[level], | 247 | m->setHarmless(harmlessTicks[level], harmlessDurTicks[level], |
257 | harmlessWarnTicks[level]); | 248 | harmlessWarnTicks[level]); |
258 | if (gameState.testBit(Introducing)) | 249 | if (gameState.testBit(Introducing)) |
259 | m->setDirection(board->turn(m->direction())); | 250 | m->setDirection(board->turn(m->direction())); |
260 | } | 251 | } |
261 | } | 252 | } |
262 | if (pos == fruit->position() && fruit->state() == active) { | 253 | if (pos == fruit->position() && fruit->state() == active) { |
263 | fruit->setEaten(fruitScoreDurTicks[level]); | 254 | fruit->setEaten(fruitScoreDurTicks[level]); |
264 | initFruit(FALSE); | 255 | initFruit(FALSE); |
265 | score(fruitScore[fruit->pix()]); | 256 | score(fruitScore[fruit->pix()]); |
266 | } | 257 | } |
267 | } | 258 | } |
268 | 259 | ||
269 | if (!gameState.testBit(Introducing)) { | 260 | if (!gameState.testBit(Introducing)) { |
270 | if (fruit->state() != active && fruit->pix() >= 0) | 261 | if (fruit->state() != active && fruit->pix() >= 0) |
271 | lastRect = pix->rect(fruit->position(), FruitScorePix, fruit->pix()); | 262 | lastRect = pix->rect(fruit->position(), FruitScorePix, fruit->pix()); |
272 | else | 263 | else |
273 | lastRect = pix->rect(fruit->position(), FruitPix, fruit->pix()); | 264 | lastRect = pix->rect(fruit->position(), FruitPix, fruit->pix()); |
274 | 265 | ||
275 | lastPix = fruit->pix(); | 266 | lastPix = fruit->pix(); |
276 | if (fruit->move()) { | 267 | if (fruit->move()) { |
277 | if (pos == fruit->position() && fruit->state() == active) { | 268 | if (pos == fruit->position() && fruit->state() == active) { |
278 | fruit->setEaten(fruitScoreDurTicks[level]); | 269 | fruit->setEaten(fruitScoreDurTicks[level]); |
279 | initFruit(FALSE); | 270 | initFruit(FALSE); |
280 | score(fruitScore[fruit->pix()]); | 271 | score(fruitScore[fruit->pix()]); |
281 | } | 272 | } |
282 | if (fruit->state() != active && fruit->pix() >= 0) | 273 | if (fruit->state() != active && fruit->pix() >= 0) |
283 | fruitRect = pix->rect(fruit->position(), FruitScorePix, fruit->pix()); | 274 | fruitRect = pix->rect(fruit->position(), FruitScorePix, fruit->pix()); |
284 | else | 275 | else |
285 | fruitRect = pix->rect(fruit->position(), FruitPix, fruit->pix()); | 276 | fruitRect = pix->rect(fruit->position(), FruitPix, fruit->pix()); |
286 | if (lastPix == fruit->pix() && lastRect == fruitRect) | 277 | if (lastPix == fruit->pix() && lastRect == fruitRect) |
287 | fruitRect.setRect(0, 0, 0, 0); | 278 | fruitRect.setRect(0, 0, 0, 0); |
288 | else | 279 | else |
289 | fruitRect = pix->rect(fruitRect, lastRect); | 280 | fruitRect = pix->rect(fruitRect, lastRect); |
290 | } else | 281 | } else |
291 | fruitRect.setRect(0, 0, 0, 0); | 282 | fruitRect.setRect(0, 0, 0, 0); |
292 | } else | 283 | } else |
293 | fruitRect.setRect(0, 0, 0, 0); | 284 | fruitRect.setRect(0, 0, 0, 0); |
294 | 285 | ||
295 | int lastBodyPix; | 286 | int lastBodyPix; |
296 | int lastEyesPix; | 287 | int lastEyesPix; |
297 | 288 | ||
298 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) | 289 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) |
299 | if (m) { | 290 | if (m) { |
300 | lastRect = pix->rect(m->position(), MonsterPix); | 291 | lastRect = pix->rect(m->position(), MonsterPix); |
301 | lastBodyPix = m->body(); | 292 | lastBodyPix = m->body(); |
302 | lastEyesPix = m->eyes(); | 293 | lastEyesPix = m->eyes(); |
303 | if (m->move()) { | 294 | if (m->move()) { |
304 | moved = TRUE; | 295 | moved = TRUE; |
305 | *monsterRect->at(m->id()) = pix->rect(m->position(), MonsterPix); | 296 | *monsterRect->at(m->id()) = pix->rect(m->position(), MonsterPix); |
306 | if (lastBodyPix == m->body() && lastEyesPix == m->eyes() && | 297 | if (lastBodyPix == m->body() && lastEyesPix == m->eyes() && |
307 | lastRect == pix->rect(m->position(), MonsterPix)) | 298 | lastRect == pix->rect(m->position(), MonsterPix)) |
308 | monsterRect->at(m->id())->setRect(0, 0, 0, 0); | 299 | monsterRect->at(m->id())->setRect(0, 0, 0, 0); |
309 | else | 300 | else |
310 | *monsterRect->at(m->id()) = pix->rect(*monsterRect->at(m->id()), lastRect); | 301 | *monsterRect->at(m->id()) = pix->rect(*monsterRect->at(m->id()), lastRect); |
311 | if (m->position() == pos && !gameState.testBit(Dying)) { | 302 | if (m->position() == pos && !gameState.testBit(Dying)) { |
312 | if (m->state() == harmless && !gameState.testBit(Dying)) { | 303 | if (m->state() == harmless && !gameState.testBit(Dying)) { |
313 | m->setREM(remTicks[level]); | 304 | m->setREM(remTicks[level]); |
314 | eated++; | 305 | eated++; |
315 | if (gameState.testBit(Introducing)) { | 306 | if (gameState.testBit(Introducing)) { |
316 | m->setPosition(OUT); | 307 | m->setPosition(OUT); |
317 | m->setDirection(X); | 308 | m->setDirection(X); |
318 | } | 309 | } |
319 | } | 310 | } |
320 | if (m->state() == dangerous && !gameState.testBit(Dying)) | 311 | if (m->state() == dangerous && !gameState.testBit(Dying)) |
321 | killed(); | 312 | killed(); |
322 | } | 313 | } |
323 | } else | 314 | } else |
324 | monsterRect->at(m->id())->setRect(0, 0, 0, 0); | 315 | monsterRect->at(m->id())->setRect(0, 0, 0, 0); |
325 | } | 316 | } |
326 | 317 | ||
327 | for (int m = 0; m < board->monsters(); m++) | 318 | for (int m = 0; m < board->monsters(); m++) |
328 | if (pacmanRect.intersects(*monsterRect->at(m))) { | 319 | if (pacmanRect.intersects(*monsterRect->at(m))) { |
329 | pacmanRect = pix->rect(pacmanRect, *monsterRect->at(m)); | 320 | pacmanRect = pix->rect(pacmanRect, *monsterRect->at(m)); |
330 | monsterRect->at(m)->setRect(0, 0, 0, 0); | 321 | monsterRect->at(m)->setRect(0, 0, 0, 0); |
331 | } else | 322 | } else |
332 | for (int im = m+1; im < board->monsters(); im++) | 323 | for (int im = m+1; im < board->monsters(); im++) |
333 | if (monsterRect->at(m)->intersects(*monsterRect->at(im))) { | 324 | if (monsterRect->at(m)->intersects(*monsterRect->at(im))) { |
334 | *monsterRect->at(m) = pix->rect(*monsterRect->at(m), *monsterRect->at(im)); | 325 | *monsterRect->at(m) = pix->rect(*monsterRect->at(m), *monsterRect->at(im)); |
335 | monsterRect->at(im)->setRect(0, 0, 0, 0); | 326 | monsterRect->at(im)->setRect(0, 0, 0, 0); |
336 | } | 327 | } |
337 | 328 | ||
338 | if (!pacmanRect.isNull()) | 329 | if (!pacmanRect.isNull()) |
339 | repaint(pacmanRect, FALSE); | 330 | repaint(pacmanRect, FALSE); |
340 | 331 | ||
341 | if (!fruitRect.isNull()) | 332 | if (!fruitRect.isNull()) |
342 | repaint(fruitRect, FALSE); | 333 | repaint(fruitRect, FALSE); |
343 | 334 | ||
344 | for (int m = 0; m < board->monsters(); m++) | 335 | for (int m = 0; m < board->monsters(); m++) |
345 | if (!monsterRect->at(m)->isNull()) | 336 | if (!monsterRect->at(m)->isNull()) |
346 | repaint(*monsterRect->at(m), FALSE); | 337 | repaint(*monsterRect->at(m), FALSE); |
347 | 338 | ||
348 | if (board->points() == 0 && !gameState.testBit(Dying)) | 339 | if (board->points() == 0 && !gameState.testBit(Dying)) |
349 | levelUp(); | 340 | levelUp(); |
350 | 341 | ||
351 | if (eated > 0 && !gameState.testBit(Dying)) { | 342 | if (eated > 0 && !gameState.testBit(Dying)) { |
352 | timerCount = eated; | 343 | timerCount = eated; |
353 | eaten(); | 344 | eaten(); |
354 | } | 345 | } |
355 | 346 | ||
356 | if (gameState.testBit(Introducing) && moved) | 347 | if (gameState.testBit(Introducing) && moved) |
357 | introPlay(); | 348 | introPlay(); |
358 | } | 349 | } |
359 | 350 | ||
360 | void Referee::repaintFigures() | 351 | void Referee::repaintFigures() |
361 | { | 352 | { |
362 | pacmanRect = pix->rect(pacman->position(), PacmanPix); | 353 | pacmanRect = pix->rect(pacman->position(), PacmanPix); |
363 | 354 | ||
364 | for (int e = 0; e < board->energizers(); e++) { | 355 | for (int e = 0; e < board->energizers(); e++) { |
365 | *energizerRect->at(e) = pix->rect(board->position(energizer, e), EnergizerPix); | 356 | *energizerRect->at(e) = pix->rect(board->position(energizer, e), EnergizerPix); |
366 | 357 | ||
367 | if (pacmanRect.intersects(*energizerRect->at(e))) { | 358 | if (pacmanRect.intersects(*energizerRect->at(e))) { |
368 | pacmanRect = pix->rect(pacmanRect, *energizerRect->at(e)); | 359 | pacmanRect = pix->rect(pacmanRect, *energizerRect->at(e)); |
369 | energizerRect->at(e)->setRect(0, 0, 0, 0); | 360 | energizerRect->at(e)->setRect(0, 0, 0, 0); |
370 | } else | 361 | } else |
371 | for (int ie = e+1; ie < board->energizers(); ie++) | 362 | for (int ie = e+1; ie < board->energizers(); ie++) |
372 | if (energizerRect->at(e)->intersects(*energizerRect->at(ie))) { | 363 | if (energizerRect->at(e)->intersects(*energizerRect->at(ie))) { |
373 | *energizerRect->at(e) = pix->rect(*energizerRect->at(e), *energizerRect->at(ie)); | 364 | *energizerRect->at(e) = pix->rect(*energizerRect->at(e), *energizerRect->at(ie)); |
374 | energizerRect->at(ie)->setRect(0, 0, 0, 0); | 365 | energizerRect->at(ie)->setRect(0, 0, 0, 0); |
375 | } | 366 | } |
376 | } | 367 | } |
377 | 368 | ||
378 | if (fruit->pix() != -1 && fruit->state() != active) | 369 | if (fruit->pix() != -1 && fruit->state() != active) |
379 | fruitRect = pix->rect(fruit->position(), FruitScorePix, fruit->pix()); | 370 | fruitRect = pix->rect(fruit->position(), FruitScorePix, fruit->pix()); |
380 | else | 371 | else |
381 | fruitRect = pix->rect(fruit->position(), FruitPix, fruit->pix()); | 372 | fruitRect = pix->rect(fruit->position(), FruitPix, fruit->pix()); |
382 | 373 | ||
383 | if (pacmanRect.intersects(fruitRect)) { | 374 | if (pacmanRect.intersects(fruitRect)) { |
384 | pacmanRect = pix->rect(pacmanRect, fruitRect); | 375 | pacmanRect = pix->rect(pacmanRect, fruitRect); |
385 | fruitRect.setRect(0, 0, 0, 0); | 376 | fruitRect.setRect(0, 0, 0, 0); |
386 | } | 377 | } |
387 | 378 | ||
388 | for (int m = 0; m < board->monsters(); m++) { | 379 | for (int m = 0; m < board->monsters(); m++) { |
389 | *monsterRect->at(m) = pix->rect(board->position(monster, m), MonsterPix); | 380 | *monsterRect->at(m) = pix->rect(board->position(monster, m), MonsterPix); |
390 | 381 | ||
391 | if (pacmanRect.intersects(*monsterRect->at(m))) { | 382 | if (pacmanRect.intersects(*monsterRect->at(m))) { |
392 | pacmanRect = pix->rect(pacmanRect, *monsterRect->at(m)); | 383 | pacmanRect = pix->rect(pacmanRect, *monsterRect->at(m)); |
393 | monsterRect->at(m)->setRect(0, 0, 0, 0); | 384 | monsterRect->at(m)->setRect(0, 0, 0, 0); |
394 | } else | 385 | } else |
395 | for (int im = m+1; im < board->monsters(); im++) | 386 | for (int im = m+1; im < board->monsters(); im++) |
396 | if (monsterRect->at(m)->intersects(*monsterRect->at(im))) { | 387 | if (monsterRect->at(m)->intersects(*monsterRect->at(im))) { |
397 | *monsterRect->at(m) = pix->rect(*monsterRect->at(m), *monsterRect->at(im)); | 388 | *monsterRect->at(m) = pix->rect(*monsterRect->at(m), *monsterRect->at(im)); |
398 | monsterRect->at(im)->setRect(0, 0, 0, 0); | 389 | monsterRect->at(im)->setRect(0, 0, 0, 0); |
399 | } | 390 | } |
400 | } | 391 | } |
401 | 392 | ||
402 | if (!pacmanRect.isNull()) | 393 | if (!pacmanRect.isNull()) |
403 | repaint(pacmanRect, FALSE); | 394 | repaint(pacmanRect, FALSE); |
404 | 395 | ||
405 | if (!fruitRect.isNull()) | 396 | if (!fruitRect.isNull()) |
406 | repaint(fruitRect, FALSE); | 397 | repaint(fruitRect, FALSE); |
407 | 398 | ||
408 | for (int m = 0; m < board->monsters(); m++) | 399 | for (int m = 0; m < board->monsters(); m++) |
409 | if (!monsterRect->at(m)->isNull()) | 400 | if (!monsterRect->at(m)->isNull()) |
410 | repaint(*monsterRect->at(m), FALSE); | 401 | repaint(*monsterRect->at(m), FALSE); |
411 | 402 | ||
412 | for (int e = 0; e < board->energizers(); e++) | 403 | for (int e = 0; e < board->energizers(); e++) |
413 | if (!energizerRect->at(e)->isNull()) | 404 | if (!energizerRect->at(e)->isNull()) |
414 | repaint(*energizerRect->at(e), FALSE); | 405 | repaint(*energizerRect->at(e), FALSE); |
415 | 406 | ||
416 | } | 407 | } |
417 | 408 | ||
418 | void Referee::initKeys() | 409 | void Referee::initKeys() |
419 | { | 410 | { |
420 | APP_CONFIG_BEGIN( cfg ); | 411 | APP_CONFIG_BEGIN( cfg ); |
421 | QString up("Up"); | 412 | QString up("Up"); |
422 | up = cfg->readEntry("upKey", (const char*) up); | 413 | up = cfg->readEntry("upKey", (const char*) up); |
423 | UpKey = KAccel::stringToKey(up); | 414 | UpKey = KAccel::stringToKey(up); |
424 | 415 | ||
425 | QString down("Down"); | 416 | QString down("Down"); |
426 | down = cfg->readEntry("downKey", (const char*) down); | 417 | down = cfg->readEntry("downKey", (const char*) down); |
427 | DownKey = KAccel::stringToKey(down); | 418 | DownKey = KAccel::stringToKey(down); |
428 | 419 | ||
429 | QString left("Left"); | 420 | QString left("Left"); |
430 | left = cfg->readEntry("leftKey", (const char*) left); | 421 | left = cfg->readEntry("leftKey", (const char*) left); |
431 | LeftKey = KAccel::stringToKey(left); | 422 | LeftKey = KAccel::stringToKey(left); |
432 | 423 | ||
433 | QString right("Right"); | 424 | QString right("Right"); |
434 | right = cfg->readEntry("rightKey", (const char*) right); | 425 | right = cfg->readEntry("rightKey", (const char*) right); |
435 | RightKey = KAccel::stringToKey(right); | 426 | RightKey = KAccel::stringToKey(right); |
436 | APP_CONFIG_END( cfg ); | 427 | APP_CONFIG_END( cfg ); |
437 | } | 428 | } |
438 | 429 | ||
439 | void Referee::fillArray(QArray<int> &array, QString values, int max) | 430 | void Referee::fillArray(QArray<int> &array, QString values, int max) |
440 | { | 431 | { |
441 | if (max < 0) | 432 | if (max < 0) |
442 | max = values.contains(',')+1; | 433 | max = values.contains(',')+1; |
443 | 434 | ||
444 | array.resize(max); | 435 | array.resize(max); |
445 | int last = 0; | 436 | int last = 0; |
446 | bool ok; | 437 | bool ok; |
447 | QString value; | 438 | QString value; |
448 | 439 | ||
449 | for (uint i = 0; i < array.size(); i++) { | 440 | for (uint i = 0; i < array.size(); i++) { |
450 | if (values.find(',') < 0 && values.length() > 0) { | 441 | if (values.find(',') < 0 && values.length() > 0) { |
451 | value = values; | 442 | value = values; |
452 | values = ""; | 443 | values = ""; |
453 | } | 444 | } |
454 | if (values.find(',') >= 0) { | 445 | if (values.find(',') >= 0) { |
455 | value = values.left(values.find(',')); | 446 | value = values.left(values.find(',')); |
456 | values.remove(0,values.find(',')+1); | 447 | values.remove(0,values.find(',')+1); |
457 | } | 448 | } |
458 | array[i] = value.toInt(&ok); | 449 | array[i] = value.toInt(&ok); |
459 | if (ok) | 450 | if (ok) |
460 | last = array[i]; | 451 | last = array[i]; |
461 | else | 452 | else |
462 | array[i] = last; | 453 | array[i] = last; |
463 | } | 454 | } |
464 | } | 455 | } |
465 | 456 | ||
466 | void Referee::fillStrList(QStrList &list, QString values, int max) | 457 | void Referee::fillStrList(QStrList &list, QString values, int max) |
467 | { | 458 | { |
468 | if (!list.isEmpty()) | 459 | if (!list.isEmpty()) |
469 | list.clear(); | 460 | list.clear(); |
470 | 461 | ||
471 | QString last = ""; | 462 | QString last = ""; |
472 | QString value; | 463 | QString value; |
473 | 464 | ||
474 | for (uint i = 0; i < (uint) max; i++) { | 465 | for (uint i = 0; i < (uint) max; i++) { |
475 | if (values.find(',') < 0 && values.length() > 0) { | 466 | if (values.find(',') < 0 && values.length() > 0) { |
476 | value = values; | 467 | value = values; |
477 | values = ""; | 468 | values = ""; |
478 | } | 469 | } |
479 | if (values.find(',') >= 0) { | 470 | if (values.find(',') >= 0) { |
480 | value = values.left(values.find(',')); | 471 | value = values.left(values.find(',')); |
481 | values.remove(0,values.find(',')+1); | 472 | values.remove(0,values.find(',')+1); |
482 | } | 473 | } |
483 | if (!value.isEmpty()) | 474 | if (!value.isEmpty()) |
484 | last = value; | 475 | last = value; |
485 | 476 | ||
486 | list.append(last); | 477 | list.append(last); |
487 | } | 478 | } |
488 | } | 479 | } |
489 | 480 | ||
490 | void Referee::fillMapName() | 481 | void Referee::fillMapName() |
491 | { | 482 | { |
492 | QStrList list = mapName; | 483 | QStrList list = mapName; |
493 | 484 | ||
494 | if (!mapName.isEmpty()) | 485 | if (!mapName.isEmpty()) |
495 | mapName.clear(); | 486 | mapName.clear(); |
496 | 487 | ||
497 | QString map; | 488 | QString map; |
498 | 489 | ||
499 | QFileInfo fileInfo; | 490 | QFileInfo fileInfo; |
500 | 491 | ||
501 | for (uint i = 0; i < list.count(); i++) { | 492 | for (uint i = 0; i < list.count(); i++) { |
502 | map = list.at(i); | 493 | map = list.at(i); |
503 | 494 | ||
504 | if (map.left(1) != "/" && map.left(1) != "~") | 495 | if (map.left(1) != "/" && map.left(1) != "~") |
505 | map = FIND_APP_DATA( mapDirectory+map ); | 496 | map = FIND_APP_DATA( mapDirectory+map ); |
506 | 497 | ||
507 | fileInfo.setFile(map); | 498 | fileInfo.setFile(map); |
508 | if (!fileInfo.isReadable()) | 499 | if (!fileInfo.isReadable()) |
509 | map = ""; | 500 | map = ""; |
510 | 501 | ||
511 | mapName.append(map); | 502 | mapName.append(map); |
512 | } | 503 | } |
513 | } | 504 | } |
514 | 505 | ||
515 | void Referee::confLevels(bool defGroup) | 506 | void Referee::confLevels(bool defGroup) |
516 | { | 507 | { |
517 | APP_CONFIG_BEGIN( cfg ); | 508 | APP_CONFIG_BEGIN( cfg ); |
518 | if (defGroup || cfg->hasKey("Levels")) | 509 | if (defGroup || cfg->hasKey("Levels")) |
519 | maxLevel = cfg->readNumEntry("Levels", 13); | 510 | maxLevel = cfg->readNumEntry("Levels", 13); |
520 | APP_CONFIG_END( cfg ); | 511 | APP_CONFIG_END( cfg ); |
521 | } | 512 | } |
522 | 513 | ||
523 | void Referee::confMisc(bool defGroup) | 514 | void Referee::confMisc(bool defGroup) |
524 | { | 515 | { |
525 | APP_CONFIG_BEGIN( cfg ); | 516 | APP_CONFIG_BEGIN( cfg ); |
526 | if (defGroup || cfg->hasKey("PixmapDirectory")) { | 517 | if (defGroup || cfg->hasKey("PixmapDirectory")) { |
527 | pixmapDirectory = cfg->readEntry("PixmapDirectory"); | 518 | pixmapDirectory = cfg->readEntry("PixmapDirectory"); |
528 | 519 | ||
529 | if (pixmapDirectory.left(1) != "/" && pixmapDirectory.left(1) != "~") | 520 | if (pixmapDirectory.left(1) != "/" && pixmapDirectory.left(1) != "~") |
530 | pixmapDirectory.insert(0, "pics/"); | 521 | pixmapDirectory.insert(0, "pics/"); |
531 | if (pixmapDirectory.right(1) != "/") | 522 | if (pixmapDirectory.right(1) != "/") |
532 | pixmapDirectory.append("/"); | 523 | pixmapDirectory.append("/"); |
533 | } | 524 | } |
534 | 525 | ||
535 | if (defGroup || cfg->hasKey("MapDirectory")) { | 526 | if (defGroup || cfg->hasKey("MapDirectory")) { |
536 | mapDirectory = cfg->readEntry("MapDirectory"); | 527 | mapDirectory = cfg->readEntry("MapDirectory"); |
537 | 528 | ||
538 | if (mapDirectory.left(1) != "/" && mapDirectory.left(1) != "~") | 529 | if (mapDirectory.left(1) != "/" && mapDirectory.left(1) != "~") |
539 | mapDirectory.insert(0, "maps/"); | 530 | mapDirectory.insert(0, "maps/"); |
540 | if (mapDirectory.right(1) != "/") | 531 | if (mapDirectory.right(1) != "/") |
541 | mapDirectory.append("/"); | 532 | mapDirectory.append("/"); |
542 | } | 533 | } |
diff --git a/noncore/games/kpacman/score.cpp b/noncore/games/kpacman/score.cpp index e91771b..6878b81 100644 --- a/noncore/games/kpacman/score.cpp +++ b/noncore/games/kpacman/score.cpp | |||
@@ -1,541 +1,535 @@ | |||
1 | 1 | ||
2 | #include "portable.h" | 2 | #include "portable.h" |
3 | 3 | ||
4 | #if defined( KDE2_PORT ) | 4 | #if defined( KDE2_PORT ) |
5 | #include <score.h> | 5 | #include <score.h> |
6 | #include <score.moc> | 6 | #include <score.moc> |
7 | 7 | ||
8 | #include <kaccel.h> | 8 | #include <kaccel.h> |
9 | #include <kapp.h> | 9 | #include <kapp.h> |
10 | #include <kconfig.h> | 10 | #include <kconfig.h> |
11 | #include <kstddirs.h> | 11 | #include <kstddirs.h> |
12 | #include <kmessagebox.h> | 12 | #include <kmessagebox.h> |
13 | #elif defined( QPE_PORT ) | 13 | #elif defined( QPE_PORT ) |
14 | #include <qaccel.h> | 14 | #include <qaccel.h> |
15 | #include <qpe/config.h> | 15 | #include <qpe/config.h> |
16 | #include "score.h" | 16 | #include "score.h" |
17 | #endif | 17 | #endif |
18 | 18 | ||
19 | #include <stdlib.h> | 19 | #include <stdlib.h> |
20 | #include <ctype.h> | 20 | #include <ctype.h> |
21 | 21 | ||
22 | #include <qpixmap.h> | ||
23 | #include <qstring.h> | ||
24 | #include <qdstream.h> | ||
25 | #include <qkeycode.h> | ||
26 | #include <qtimer.h> | 22 | #include <qtimer.h> |
27 | #include <qfileinfo.h> | ||
28 | 23 | ||
29 | #include "bitfont.h" | ||
30 | 24 | ||
31 | Score::Score(QWidget *parent, const char *name, int Scheme, int Mode, Bitfont *font) : QWidget(parent, name) | 25 | Score::Score(QWidget *parent, const char *name, int Scheme, int Mode, Bitfont *font) : QWidget(parent, name) |
32 | { | 26 | { |
33 | setFocusPolicy(QWidget::StrongFocus); | 27 | setFocusPolicy(QWidget::StrongFocus); |
34 | 28 | ||
35 | paused = FALSE; | 29 | paused = FALSE; |
36 | 30 | ||
37 | lastScore = -1; | 31 | lastScore = -1; |
38 | lastPlayer = -1; | 32 | lastPlayer = -1; |
39 | 33 | ||
40 | cursorBlinkTimer = 0; | 34 | cursorBlinkTimer = 0; |
41 | cursorBlinkMS = -1; | 35 | cursorBlinkMS = -1; |
42 | cursor.x = -1; | 36 | cursor.x = -1; |
43 | cursor.y = -1; | 37 | cursor.y = -1; |
44 | cursor.on = FALSE; | 38 | cursor.on = FALSE; |
45 | cursor.chr = QChar('?'); | 39 | cursor.chr = QChar('?'); |
46 | 40 | ||
47 | initKeys(); | 41 | initKeys(); |
48 | 42 | ||
49 | scheme = Scheme; | 43 | scheme = Scheme; |
50 | mode = Mode; | 44 | mode = Mode; |
51 | confScheme(); | 45 | confScheme(); |
52 | 46 | ||
53 | bitfont = font; | 47 | bitfont = font; |
54 | 48 | ||
55 | highscoreFile.setName(locateHighscoreFilePath().filePath()); | 49 | highscoreFile.setName(locateHighscoreFilePath().filePath()); |
56 | read(); | 50 | read(); |
57 | 51 | ||
58 | for (int p = 0; p < maxPlayer; p++) { | 52 | for (int p = 0; p < maxPlayer; p++) { |
59 | playerScore[p] = 0; | 53 | playerScore[p] = 0; |
60 | playerName[p] = getenv("LOGNAME"); | 54 | playerName[p] = getenv("LOGNAME"); |
61 | if (playerName[p].length() < minPlayerNameLength) | 55 | if (playerName[p].length() < minPlayerNameLength) |
62 | playerName[p].setExpand(minPlayerNameLength-1, ' '); | 56 | playerName[p].setExpand(minPlayerNameLength-1, ' '); |
63 | 57 | ||
64 | for (uint i = 0; i < playerName[p].length(); i++) | 58 | for (uint i = 0; i < playerName[p].length(); i++) |
65 | if (playerName[p].at(i) < bitfont->firstChar() || | 59 | if (playerName[p].at(i) < bitfont->firstChar() || |
66 | playerName[p].at(i) > bitfont->lastChar()) | 60 | playerName[p].at(i) > bitfont->lastChar()) |
67 | playerName[p].at(i) = playerName[p].at(i).upper(); | 61 | playerName[p].at(i) = playerName[p].at(i).upper(); |
68 | } | 62 | } |
69 | } | 63 | } |
70 | 64 | ||
71 | Score::~Score() | 65 | Score::~Score() |
72 | { | 66 | { |
73 | // write(); | 67 | // write(); |
74 | } | 68 | } |
75 | 69 | ||
76 | void Score::paintEvent( QPaintEvent *e) | 70 | void Score::paintEvent( QPaintEvent *e) |
77 | { | 71 | { |
78 | if (rect(1, 0, tr(" 1UP ")).intersects(e->rect())) { | 72 | if (rect(1, 0, tr(" 1UP ")).intersects(e->rect())) { |
79 | QPixmap pix; | 73 | QPixmap pix; |
80 | QColor fg = BLACK; | 74 | QColor fg = BLACK; |
81 | if (cursor.on || paused || lastPlayer != 0) | 75 | if (cursor.on || paused || lastPlayer != 0) |
82 | fg = WHITE; | 76 | fg = WHITE; |
83 | pix = bitfont->text(tr(" 1UP "), fg, BLACK); | 77 | pix = bitfont->text(tr(" 1UP "), fg, BLACK); |
84 | bitBlt(this, x(1), y(0), &pix); | 78 | bitBlt(this, x(1), y(0), &pix); |
85 | } | 79 | } |
86 | 80 | ||
87 | if (rect(8, 0, tr(" HIGH SCORE ")).intersects(e->rect())) { | 81 | if (rect(8, 0, tr(" HIGH SCORE ")).intersects(e->rect())) { |
88 | QPixmap pix = bitfont->text(tr(" HIGH SCORE "), WHITE, BLACK); | 82 | QPixmap pix = bitfont->text(tr(" HIGH SCORE "), WHITE, BLACK); |
89 | bitBlt(this, x(8), y(0), &pix); | 83 | bitBlt(this, x(8), y(0), &pix); |
90 | } | 84 | } |
91 | 85 | ||
92 | if (maxPlayer > 1 && rect(21, 0, tr(" 2UP ")).intersects(e->rect())) { | 86 | if (maxPlayer > 1 && rect(21, 0, tr(" 2UP ")).intersects(e->rect())) { |
93 | QPixmap pix; | 87 | QPixmap pix; |
94 | QColor fg = BLACK; | 88 | QColor fg = BLACK; |
95 | if (cursor.on || paused || lastPlayer != 1) | 89 | if (cursor.on || paused || lastPlayer != 1) |
96 | fg = WHITE; | 90 | fg = WHITE; |
97 | pix = bitfont->text(tr(" 2UP "), fg, BLACK); | 91 | pix = bitfont->text(tr(" 2UP "), fg, BLACK); |
98 | bitBlt(this, x(21), y(0), &pix); | 92 | bitBlt(this, x(21), y(0), &pix); |
99 | } | 93 | } |
100 | 94 | ||
101 | QString s; | 95 | QString s; |
102 | 96 | ||
103 | s.sprintf("%6d0", playerScore[0]/10); | 97 | s.sprintf("%6d0", playerScore[0]/10); |
104 | if (rect(0, 1, s).intersects(e->rect())) { | 98 | if (rect(0, 1, s).intersects(e->rect())) { |
105 | QPixmap pix = bitfont->text(s, WHITE, BLACK); | 99 | QPixmap pix = bitfont->text(s, WHITE, BLACK); |
106 | bitBlt(this, x(0), y(1), &pix); | 100 | bitBlt(this, x(0), y(1), &pix); |
107 | } | 101 | } |
108 | 102 | ||
109 | s.sprintf("%8d0", HighScore/10); | 103 | s.sprintf("%8d0", HighScore/10); |
110 | if (rect(8, 1, s).intersects(e->rect())) { | 104 | if (rect(8, 1, s).intersects(e->rect())) { |
111 | QPixmap pix = bitfont->text(s, WHITE, BLACK); | 105 | QPixmap pix = bitfont->text(s, WHITE, BLACK); |
112 | bitBlt(this, x(8), y(1), &pix); | 106 | bitBlt(this, x(8), y(1), &pix); |
113 | } | 107 | } |
114 | 108 | ||
115 | if (lastScore >= 0) { | 109 | if (lastScore >= 0) { |
116 | if (rect(1, 4*1.25, tr(" CONGRATULATIONS ")).intersects(e->rect())) { | 110 | if (rect(1, 4*1.25, tr(" CONGRATULATIONS ")).intersects(e->rect())) { |
117 | QPixmap pix = bitfont->text(tr(" CONGRATULATIONS "), YELLOW, BLACK); | 111 | QPixmap pix = bitfont->text(tr(" CONGRATULATIONS "), YELLOW, BLACK); |
118 | bitBlt(this, x(1), y(4*1.25), &pix); | 112 | bitBlt(this, x(1), y(4*1.25), &pix); |
119 | } | 113 | } |
120 | if (rect(1, 6*1.25, tr(" YOU HAVE ARCHIEVED ")).intersects(e->rect())) { | 114 | if (rect(1, 6*1.25, tr(" YOU HAVE ARCHIEVED ")).intersects(e->rect())) { |
121 | QPixmap pix = bitfont->text(tr(" YOU HAVE ARCHIEVED "), CYAN, BLACK); | 115 | QPixmap pix = bitfont->text(tr(" YOU HAVE ARCHIEVED "), CYAN, BLACK); |
122 | bitBlt(this, x(1), y(6*1.25), &pix); | 116 | bitBlt(this, x(1), y(6*1.25), &pix); |
123 | } | 117 | } |
124 | if (rect(1, 7*1.25, tr(" A SCORE IN THE TOP 10. ")).intersects(e->rect())) { | 118 | if (rect(1, 7*1.25, tr(" A SCORE IN THE TOP 10. ")).intersects(e->rect())) { |
125 | QPixmap pix = bitfont->text(tr(" A SCORE IN THE TOP 10. "), CYAN, BLACK); | 119 | QPixmap pix = bitfont->text(tr(" A SCORE IN THE TOP 10. "), CYAN, BLACK); |
126 | bitBlt(this, x(1), y(7*1.25), &pix); | 120 | bitBlt(this, x(1), y(7*1.25), &pix); |
127 | } | 121 | } |
128 | if (rect(1, 8*1.25, tr(" ")).intersects(e->rect())) { | 122 | if (rect(1, 8*1.25, tr(" ")).intersects(e->rect())) { |
129 | QPixmap pix = bitfont->text(tr(" "), CYAN, BLACK); | 123 | QPixmap pix = bitfont->text(tr(" "), CYAN, BLACK); |
130 | bitBlt(this, x(1), y(8*1.25), &pix); | 124 | bitBlt(this, x(1), y(8*1.25), &pix); |
131 | } | 125 | } |
132 | } | 126 | } |
133 | 127 | ||
134 | if (rect(1, 9.5*1.25, tr("RNK SCORE NAME DATE")).intersects(e->rect())) { | 128 | if (rect(1, 9.5*1.25, tr("RNK SCORE NAME DATE")).intersects(e->rect())) { |
135 | QPixmap pix = bitfont->text(tr("RNK SCORE NAME DATE"), WHITE, BLACK); | 129 | QPixmap pix = bitfont->text(tr("RNK SCORE NAME DATE"), WHITE, BLACK); |
136 | bitBlt(this, x(1), y(9.5*1.25), &pix); | 130 | bitBlt(this, x(1), y(9.5*1.25), &pix); |
137 | } | 131 | } |
138 | 132 | ||
139 | for (int i = 0; i < 10; i++) { | 133 | for (int i = 0; i < 10; i++) { |
140 | s.sprintf("%2d%9d %-3.3s %-8.8s", | 134 | s.sprintf("%2d%9d %-3.3s %-8.8s", |
141 | i+1, hallOfFame[i].points, hallOfFame[i].name.utf8().data(), | 135 | i+1, hallOfFame[i].points, hallOfFame[i].name.utf8().data(), |
142 | formatDate(hallOfFame[i].moment.date()).data()); | 136 | formatDate(hallOfFame[i].moment.date()).data()); |
143 | if (rect(1, (11+i)*1.25, s).intersects(e->rect())) { | 137 | if (rect(1, (11+i)*1.25, s).intersects(e->rect())) { |
144 | QPixmap pix = bitfont->text(s, (i == lastScore) ? YELLOW : WHITE, BLACK); | 138 | QPixmap pix = bitfont->text(s, (i == lastScore) ? YELLOW : WHITE, BLACK); |
145 | bitBlt(this, x(1), y((11+i)*1.25), &pix); | 139 | bitBlt(this, x(1), y((11+i)*1.25), &pix); |
146 | } | 140 | } |
147 | } | 141 | } |
148 | 142 | ||
149 | if (cursor.x != -1 && cursor.y != -1 && cursor.on) { | 143 | if (cursor.x != -1 && cursor.y != -1 && cursor.on) { |
150 | if (rect(cursor.x, (cursor.y*1.25), cursor.chr).intersects(e->rect())) { | 144 | if (rect(cursor.x, (cursor.y*1.25), cursor.chr).intersects(e->rect())) { |
151 | QPixmap pix = bitfont->text(cursor.chr, BLACK, YELLOW); | 145 | QPixmap pix = bitfont->text(cursor.chr, BLACK, YELLOW); |
152 | bitBlt(this, x(cursor.x), y(cursor.y*1.25), &pix); | 146 | bitBlt(this, x(cursor.x), y(cursor.y*1.25), &pix); |
153 | } | 147 | } |
154 | } | 148 | } |
155 | 149 | ||
156 | if (paused) { | 150 | if (paused) { |
157 | 151 | ||
158 | QPixmap pix = bitfont->text(tr("PAUSED"), RED, BLACK); | 152 | QPixmap pix = bitfont->text(tr("PAUSED"), RED, BLACK); |
159 | QRect r = bitfont->rect(tr("PAUSED")); | 153 | QRect r = bitfont->rect(tr("PAUSED")); |
160 | r.moveCenter(QPoint(this->width()/2, this->height()/2)); | 154 | r.moveCenter(QPoint(this->width()/2, this->height()/2)); |
161 | 155 | ||
162 | bitBlt(this, r.x(), r.y(), &pix); | 156 | bitBlt(this, r.x(), r.y(), &pix); |
163 | } | 157 | } |
164 | } | 158 | } |
165 | 159 | ||
166 | void Score::timerEvent(QTimerEvent*) | 160 | void Score::timerEvent(QTimerEvent*) |
167 | { | 161 | { |
168 | cursor.on = !cursor.on; | 162 | cursor.on = !cursor.on; |
169 | 163 | ||
170 | if (paused) | 164 | if (paused) |
171 | return; | 165 | return; |
172 | 166 | ||
173 | if (cursor.x != -1 && cursor.y != -1) | 167 | if (cursor.x != -1 && cursor.y != -1) |
174 | repaint(rect(cursor.x, cursor.y*1.25, cursor.chr), FALSE); | 168 | repaint(rect(cursor.x, cursor.y*1.25, cursor.chr), FALSE); |
175 | scrollRepeat = FALSE; | 169 | scrollRepeat = FALSE; |
176 | 170 | ||
177 | if (lastPlayer == 0) | 171 | if (lastPlayer == 0) |
178 | repaint(rect(1, 0, tr(" 1UP ")), FALSE); | 172 | repaint(rect(1, 0, tr(" 1UP ")), FALSE); |
179 | 173 | ||
180 | if (lastPlayer == 1) | 174 | if (lastPlayer == 1) |
181 | repaint(rect(21, 0, tr(" 2UP ")), FALSE); | 175 | repaint(rect(21, 0, tr(" 2UP ")), FALSE); |
182 | } | 176 | } |
183 | 177 | ||
184 | void Score::keyPressEvent(QKeyEvent *k) | 178 | void Score::keyPressEvent(QKeyEvent *k) |
185 | { | 179 | { |
186 | if (lastScore < 0 || lastPlayer < 0 || lastPlayer >= maxPlayer || paused) { | 180 | if (lastScore < 0 || lastPlayer < 0 || lastPlayer >= maxPlayer || paused) { |
187 | k->ignore(); | 181 | k->ignore(); |
188 | return; | 182 | return; |
189 | } | 183 | } |
190 | 184 | ||
191 | int x = cursor.x; | 185 | int x = cursor.x; |
192 | int y = cursor.y; | 186 | int y = cursor.y; |
193 | 187 | ||
194 | uint key = k->key(); | 188 | uint key = k->key(); |
195 | 189 | ||
196 | if (scrollRepeat && (key == UpKey || key == Key_Up || key == DownKey || key == Key_Down)) { | 190 | if (scrollRepeat && (key == UpKey || key == Key_Up || key == DownKey || key == Key_Down)) { |
197 | k->ignore(); | 191 | k->ignore(); |
198 | return; | 192 | return; |
199 | } | 193 | } |
200 | 194 | ||
201 | if (key != Key_Return) { | 195 | if (key != Key_Return) { |
202 | if (key == RightKey || key == Key_Right) | 196 | if (key == RightKey || key == Key_Right) |
203 | if (++cursor.x > 16) | 197 | if (++cursor.x > 16) |
204 | cursor.x = 14; | 198 | cursor.x = 14; |
205 | if (key == LeftKey || key == Key_Left) | 199 | if (key == LeftKey || key == Key_Left) |
206 | if (--cursor.x < 14) | 200 | if (--cursor.x < 14) |
207 | cursor.x = 16; | 201 | cursor.x = 16; |
208 | if (key == UpKey || key == Key_Up) | 202 | if (key == UpKey || key == Key_Up) |
209 | if (cursor.chr.unicode() < bitfont->lastChar()) | 203 | if (cursor.chr.unicode() < bitfont->lastChar()) |
210 | cursor.chr = cursor.chr.unicode()+1; | 204 | cursor.chr = cursor.chr.unicode()+1; |
211 | else | 205 | else |
212 | cursor.chr = bitfont->firstChar(); | 206 | cursor.chr = bitfont->firstChar(); |
213 | if (key == DownKey || key == Key_Down) | 207 | if (key == DownKey || key == Key_Down) |
214 | if (cursor.chr.unicode() > bitfont->firstChar()) | 208 | if (cursor.chr.unicode() > bitfont->firstChar()) |
215 | cursor.chr = cursor.chr.unicode()-1; | 209 | cursor.chr = cursor.chr.unicode()-1; |
216 | else | 210 | else |
217 | cursor.chr = bitfont->lastChar(); | 211 | cursor.chr = bitfont->lastChar(); |
218 | 212 | ||
219 | if (cursor.x == x && cursor.y == y && | 213 | if (cursor.x == x && cursor.y == y && |
220 | cursor.chr == hallOfFame[lastScore].name.at(cursor.x-14)) { | 214 | cursor.chr == hallOfFame[lastScore].name.at(cursor.x-14)) { |
221 | uint ascii = k->ascii(); | 215 | uint ascii = k->ascii(); |
222 | 216 | ||
223 | if (ascii < bitfont->firstChar() || ascii > bitfont->lastChar()) | 217 | if (ascii < bitfont->firstChar() || ascii > bitfont->lastChar()) |
224 | ascii = toupper(ascii); | 218 | ascii = toupper(ascii); |
225 | 219 | ||
226 | if (ascii >= bitfont->firstChar() && ascii <= bitfont->lastChar()) { | 220 | if (ascii >= bitfont->firstChar() && ascii <= bitfont->lastChar()) { |
227 | cursor.chr = ascii; | 221 | cursor.chr = ascii; |
228 | hallOfFame[lastScore].name.at(cursor.x-14) = cursor.chr; | 222 | hallOfFame[lastScore].name.at(cursor.x-14) = cursor.chr; |
229 | if (++cursor.x > 16) | 223 | if (++cursor.x > 16) |
230 | cursor.x = 14; | 224 | cursor.x = 14; |
231 | } | 225 | } |
232 | } | 226 | } |
233 | } | 227 | } |
234 | 228 | ||
235 | if (key == Key_Return) { | 229 | if (key == Key_Return) { |
236 | playerName[lastPlayer] = hallOfFame[lastScore].name; | 230 | playerName[lastPlayer] = hallOfFame[lastScore].name; |
237 | write(); | 231 | write(); |
238 | read(); | 232 | read(); |
239 | lastScore = -1; | 233 | lastScore = -1; |
240 | cursor.x = -1; | 234 | cursor.x = -1; |
241 | cursor.y = -1; | 235 | cursor.y = -1; |
242 | // killTimers(); | 236 | // killTimers(); |
243 | emit toggleNew(); | 237 | emit toggleNew(); |
244 | end(); | 238 | end(); |
245 | } | 239 | } |
246 | 240 | ||
247 | if (x != cursor.x || y != cursor.y) { | 241 | if (x != cursor.x || y != cursor.y) { |
248 | if (cursor.x != -1) | 242 | if (cursor.x != -1) |
249 | cursor.chr = hallOfFame[lastScore].name.at(cursor.x-14); | 243 | cursor.chr = hallOfFame[lastScore].name.at(cursor.x-14); |
250 | scrollRepeat = FALSE; | 244 | scrollRepeat = FALSE; |
251 | repaint(rect(x, y*1.25, cursor.chr), FALSE); | 245 | repaint(rect(x, y*1.25, cursor.chr), FALSE); |
252 | } else | 246 | } else |
253 | hallOfFame[lastScore].name.at(cursor.x-14) = cursor.chr; | 247 | hallOfFame[lastScore].name.at(cursor.x-14) = cursor.chr; |
254 | 248 | ||
255 | if (key == UpKey || key == Key_Up || key == DownKey || key == Key_Down) | 249 | if (key == UpKey || key == Key_Up || key == DownKey || key == Key_Down) |
256 | scrollRepeat = TRUE; | 250 | scrollRepeat = TRUE; |
257 | else | 251 | else |
258 | repaint(rect(cursor.x, cursor.y*1.25, cursor.chr), FALSE); | 252 | repaint(rect(cursor.x, cursor.y*1.25, cursor.chr), FALSE); |
259 | } | 253 | } |
260 | 254 | ||
261 | void Score::initKeys() | 255 | void Score::initKeys() |
262 | { | 256 | { |
263 | APP_CONFIG_BEGIN( cfg ); | 257 | APP_CONFIG_BEGIN( cfg ); |
264 | QString up("Up"); | 258 | QString up("Up"); |
265 | up = cfg->readEntry("upKey", (const char*) up); | 259 | up = cfg->readEntry("upKey", (const char*) up); |
266 | UpKey = KAccel::stringToKey(up); | 260 | UpKey = KAccel::stringToKey(up); |
267 | 261 | ||
268 | QString down("Down"); | 262 | QString down("Down"); |
269 | down = cfg->readEntry("downKey", (const char*) down); | 263 | down = cfg->readEntry("downKey", (const char*) down); |
270 | DownKey = KAccel::stringToKey(down); | 264 | DownKey = KAccel::stringToKey(down); |
271 | 265 | ||
272 | QString left("Left"); | 266 | QString left("Left"); |
273 | left = cfg->readEntry("leftKey", (const char*) left); | 267 | left = cfg->readEntry("leftKey", (const char*) left); |
274 | LeftKey = KAccel::stringToKey(left); | 268 | LeftKey = KAccel::stringToKey(left); |
275 | 269 | ||
276 | QString right("Right"); | 270 | QString right("Right"); |
277 | right = cfg->readEntry("rightKey", (const char*) right); | 271 | right = cfg->readEntry("rightKey", (const char*) right); |
278 | RightKey = KAccel::stringToKey(right); | 272 | RightKey = KAccel::stringToKey(right); |
279 | APP_CONFIG_END( cfg ); | 273 | APP_CONFIG_END( cfg ); |
280 | } | 274 | } |
281 | 275 | ||
282 | void Score::confTiming(bool defGroup) | 276 | void Score::confTiming(bool defGroup) |
283 | { | 277 | { |
284 | APP_CONFIG_BEGIN( cfg ); | 278 | APP_CONFIG_BEGIN( cfg ); |
285 | if (defGroup || cfg->hasKey("CursorBlinkMS")) | 279 | if (defGroup || cfg->hasKey("CursorBlinkMS")) |
286 | cursorBlinkMS = cfg->readNumEntry("CursorBlinkMS", 250); | 280 | cursorBlinkMS = cfg->readNumEntry("CursorBlinkMS", 250); |
287 | if (defGroup || cfg->hasKey("HallOfFameMS")) | 281 | if (defGroup || cfg->hasKey("HallOfFameMS")) |
288 | hallOfFameMS = cfg->readNumEntry("HallOfFameMS", 7000); | 282 | hallOfFameMS = cfg->readNumEntry("HallOfFameMS", 7000); |
289 | if (defGroup || cfg->hasKey("AfterPauseMS")) | 283 | if (defGroup || cfg->hasKey("AfterPauseMS")) |
290 | afterPauseMS = cfg->readNumEntry("AfterPauseMS", 1000); | 284 | afterPauseMS = cfg->readNumEntry("AfterPauseMS", 1000); |
291 | APP_CONFIG_END( cfg ); | 285 | APP_CONFIG_END( cfg ); |
292 | } | 286 | } |
293 | 287 | ||
294 | void Score::confScheme() | 288 | void Score::confScheme() |
295 | { | 289 | { |
296 | APP_CONFIG_BEGIN( cfg ); | 290 | APP_CONFIG_BEGIN( cfg ); |
297 | SAVE_CONFIG_GROUP( cfg, oldgroup ); | 291 | SAVE_CONFIG_GROUP( cfg, oldgroup ); |
298 | QString newgroup; | 292 | QString newgroup; |
299 | 293 | ||
300 | // if not set, read mode and scheme from the configfile | 294 | // if not set, read mode and scheme from the configfile |
301 | if (mode == -1 && scheme == -1) { | 295 | if (mode == -1 && scheme == -1) { |
302 | scheme = cfg->readNumEntry("Scheme", -1); | 296 | scheme = cfg->readNumEntry("Scheme", -1); |
303 | mode = cfg->readNumEntry("Mode", -1); | 297 | mode = cfg->readNumEntry("Mode", -1); |
304 | 298 | ||
305 | // if mode is not set in the defGroup-group, lookup the scheme group | 299 | // if mode is not set in the defGroup-group, lookup the scheme group |
306 | if (scheme != -1 || mode == -1) { | 300 | if (scheme != -1 || mode == -1) { |
307 | newgroup.sprintf("Scheme %d", scheme); | 301 | newgroup.sprintf("Scheme %d", scheme); |
308 | cfg->setGroup(newgroup); | 302 | cfg->setGroup(newgroup); |
309 | 303 | ||
310 | mode = cfg->readNumEntry("Mode", -1); | 304 | mode = cfg->readNumEntry("Mode", -1); |
311 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 305 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
312 | } | 306 | } |
313 | } | 307 | } |
314 | 308 | ||
315 | int oldCursorBlinkMS = cursorBlinkMS; | 309 | int oldCursorBlinkMS = cursorBlinkMS; |
316 | 310 | ||
317 | confTiming(); | 311 | confTiming(); |
318 | 312 | ||
319 | if (mode != -1) { | 313 | if (mode != -1) { |
320 | newgroup.sprintf("Mode %d", mode); | 314 | newgroup.sprintf("Mode %d", mode); |
321 | cfg->setGroup(newgroup); | 315 | cfg->setGroup(newgroup); |
322 | 316 | ||
323 | confTiming(FALSE); | 317 | confTiming(FALSE); |
324 | } | 318 | } |
325 | 319 | ||
326 | if (scheme != -1) { | 320 | if (scheme != -1) { |
327 | newgroup.sprintf("Scheme %d", scheme); | 321 | newgroup.sprintf("Scheme %d", scheme); |
328 | cfg->setGroup(newgroup); | 322 | cfg->setGroup(newgroup); |
329 | 323 | ||
330 | confTiming(FALSE); | 324 | confTiming(FALSE); |
331 | } | 325 | } |
332 | 326 | ||
333 | if (cursorBlinkMS != oldCursorBlinkMS) { | 327 | if (cursorBlinkMS != oldCursorBlinkMS) { |
334 | if (cursorBlinkTimer) | 328 | if (cursorBlinkTimer) |
335 | killTimer(cursorBlinkTimer); | 329 | killTimer(cursorBlinkTimer); |
336 | cursorBlinkTimer = startTimer(cursorBlinkMS); | 330 | cursorBlinkTimer = startTimer(cursorBlinkMS); |
337 | } | 331 | } |
338 | 332 | ||
339 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 333 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
340 | APP_CONFIG_END( cfg ); | 334 | APP_CONFIG_END( cfg ); |
341 | } | 335 | } |
342 | 336 | ||
343 | void Score::setScheme(int Scheme, int Mode, Bitfont *font) | 337 | void Score::setScheme(int Scheme, int Mode, Bitfont *font) |
344 | { | 338 | { |
345 | mode = Mode; | 339 | mode = Mode; |
346 | scheme = Scheme; | 340 | scheme = Scheme; |
347 | 341 | ||
348 | confScheme(); | 342 | confScheme(); |
349 | 343 | ||
350 | bitfont = font; | 344 | bitfont = font; |
351 | 345 | ||
352 | for (int p = 0; p < maxPlayer; p++) | 346 | for (int p = 0; p < maxPlayer; p++) |
353 | for (uint i = 0; i < playerName[p].length(); i++) | 347 | for (uint i = 0; i < playerName[p].length(); i++) |
354 | if (playerName[p].at(i) < bitfont->firstChar() || | 348 | if (playerName[p].at(i) < bitfont->firstChar() || |
355 | playerName[p].at(i) > bitfont->lastChar()) | 349 | playerName[p].at(i) > bitfont->lastChar()) |
356 | playerName[p].at(i) = playerName[p].at(i).upper(); | 350 | playerName[p].at(i) = playerName[p].at(i).upper(); |
357 | 351 | ||
358 | for (int i = 0; i < 10; i++) | 352 | for (int i = 0; i < 10; i++) |
359 | for (uint j = 0; j < hallOfFame[i].name.length(); j++) | 353 | for (uint j = 0; j < hallOfFame[i].name.length(); j++) |
360 | if (hallOfFame[i].name.at(j) < bitfont->firstChar() || | 354 | if (hallOfFame[i].name.at(j) < bitfont->firstChar() || |
361 | hallOfFame[i].name.at(j) > bitfont->lastChar()) | 355 | hallOfFame[i].name.at(j) > bitfont->lastChar()) |
362 | hallOfFame[i].name.at(j) = hallOfFame[i].name.at(j).upper(); | 356 | hallOfFame[i].name.at(j) = hallOfFame[i].name.at(j).upper(); |
363 | 357 | ||
364 | if (cursor.chr.unicode() < bitfont->firstChar() || | 358 | if (cursor.chr.unicode() < bitfont->firstChar() || |
365 | cursor.chr.unicode() > bitfont->lastChar()) | 359 | cursor.chr.unicode() > bitfont->lastChar()) |
366 | cursor.chr = cursor.chr.upper(); | 360 | cursor.chr = cursor.chr.upper(); |
367 | } | 361 | } |
368 | 362 | ||
369 | void Score::set(int score) | 363 | void Score::set(int score) |
370 | { | 364 | { |
371 | set(score, 0); | 365 | set(score, 0); |
372 | } | 366 | } |
373 | 367 | ||
374 | void Score::set(int score, int player) | 368 | void Score::set(int score, int player) |
375 | { | 369 | { |
376 | if (player < 0 || player >= maxPlayer) | 370 | if (player < 0 || player >= maxPlayer) |
377 | return; | 371 | return; |
378 | 372 | ||
379 | lastPlayer = player; | 373 | lastPlayer = player; |
380 | playerScore[lastPlayer] = score; | 374 | playerScore[lastPlayer] = score; |
381 | 375 | ||
382 | QString s; | 376 | QString s; |
383 | 377 | ||
384 | s.sprintf("%6d0", playerScore[lastPlayer]/10); | 378 | s.sprintf("%6d0", playerScore[lastPlayer]/10); |
385 | repaint(rect(0, 1, s), FALSE); | 379 | repaint(rect(0, 1, s), FALSE); |
386 | 380 | ||
387 | if (score > HighScore) { | 381 | if (score > HighScore) { |
388 | HighScore = score; | 382 | HighScore = score; |
389 | s.sprintf("%8d0", HighScore/10); | 383 | s.sprintf("%8d0", HighScore/10); |
390 | repaint(rect(8, 1, s), FALSE); | 384 | repaint(rect(8, 1, s), FALSE); |
391 | } | 385 | } |
392 | } | 386 | } |
393 | 387 | ||
394 | /* | 388 | /* |
395 | * Set the score for player after the game if over. If the score is in the | 389 | * Set the score for player after the game if over. If the score is in the |
396 | * high scores then the hall of fame is updated (shifted) and the scoreboard | 390 | * high scores then the hall of fame is updated (shifted) and the scoreboard |
397 | * is shown. | 391 | * is shown. |
398 | */ | 392 | */ |
399 | 393 | ||
400 | void Score::setScore(int level, int player) | 394 | void Score::setScore(int level, int player) |
401 | { | 395 | { |
402 | lastScore = -1; | 396 | lastScore = -1; |
403 | 397 | ||
404 | if (player < 0 || player >= maxPlayer || level == 0) { | 398 | if (player < 0 || player >= maxPlayer || level == 0) { |
405 | if (level != 0) | 399 | if (level != 0) |
406 | emit toggleNew(); | 400 | emit toggleNew(); |
407 | QTimer::singleShot(hallOfFameMS, this, SLOT(end())); | 401 | QTimer::singleShot(hallOfFameMS, this, SLOT(end())); |
408 | return; | 402 | return; |
409 | } | 403 | } |
410 | 404 | ||
411 | lastPlayer = player; | 405 | lastPlayer = player; |
412 | 406 | ||
413 | for (int i = 0; i < 10; i++) | 407 | for (int i = 0; i < 10; i++) |
414 | if ( playerScore[lastPlayer] > hallOfFame[i].points) { | 408 | if ( playerScore[lastPlayer] > hallOfFame[i].points) { |
415 | lastScore = i; | 409 | lastScore = i; |
416 | break; | 410 | break; |
417 | } | 411 | } |
418 | 412 | ||
419 | if (lastScore < 0) { | 413 | if (lastScore < 0) { |
420 | emit toggleNew(); | 414 | emit toggleNew(); |
421 | QTimer::singleShot(hallOfFameMS, this, SLOT(end())); | 415 | QTimer::singleShot(hallOfFameMS, this, SLOT(end())); |
422 | return; | 416 | return; |
423 | } | 417 | } |
424 | 418 | ||
425 | for (int i = 9; i > lastScore && i > 0; i--) | 419 | for (int i = 9; i > lastScore && i > 0; i--) |
426 | hallOfFame[i] = hallOfFame[i-1]; | 420 | hallOfFame[i] = hallOfFame[i-1]; |
427 | 421 | ||
428 | hallOfFame[lastScore].points = playerScore[lastPlayer]; | 422 | hallOfFame[lastScore].points = playerScore[lastPlayer]; |
429 | hallOfFame[lastScore].levels = level; | 423 | hallOfFame[lastScore].levels = level; |
430 | hallOfFame[lastScore].moment = QDateTime::currentDateTime(); | 424 | hallOfFame[lastScore].moment = QDateTime::currentDateTime(); |
431 | hallOfFame[lastScore].name = playerName[lastPlayer]; | 425 | hallOfFame[lastScore].name = playerName[lastPlayer]; |
432 | 426 | ||
433 | cursor.x = 14; | 427 | cursor.x = 14; |
434 | cursor.y = 11+lastScore; | 428 | cursor.y = 11+lastScore; |
435 | cursor.chr = hallOfFame[lastScore].name.at(cursor.x-14); | 429 | cursor.chr = hallOfFame[lastScore].name.at(cursor.x-14); |
436 | 430 | ||
437 | // startTimer(cursorBlinkMS); | 431 | // startTimer(cursorBlinkMS); |
438 | setFocus(); | 432 | setFocus(); |
439 | } | 433 | } |
440 | 434 | ||
441 | /* | 435 | /* |
442 | * Read the highscores, if no file or a file shorter than 4 bytes (versions before 0.2.4 stores only | 436 | * Read the highscores, if no file or a file shorter than 4 bytes (versions before 0.2.4 stores only |
443 | * the points of one highscore) exists - the highscores were initialized with default values. | 437 | * the points of one highscore) exists - the highscores were initialized with default values. |
444 | */ | 438 | */ |
445 | void Score::read() | 439 | void Score::read() |
446 | { | 440 | { |
447 | if (highscoreFile.exists() && highscoreFile.size() > 4) { | 441 | if (highscoreFile.exists() && highscoreFile.size() > 4) { |
448 | if (highscoreFile.open(IO_ReadOnly)) { | 442 | if (highscoreFile.open(IO_ReadOnly)) { |
449 | QDataStream s(&highscoreFile); | 443 | QDataStream s(&highscoreFile); |
450 | char *name; | 444 | char *name; |
451 | for (int i = 0; i < 10; i++) { | 445 | for (int i = 0; i < 10; i++) { |
452 | s >> hallOfFame[i].points >> hallOfFame[i].levels >> hallOfFame[i].duration >> | 446 | s >> hallOfFame[i].points >> hallOfFame[i].levels >> hallOfFame[i].duration >> |
453 | hallOfFame[i].moment >> name; | 447 | hallOfFame[i].moment >> name; |
454 | hallOfFame[i].name = QString::fromLatin1(name); | 448 | hallOfFame[i].name = QString::fromLatin1(name); |
455 | delete(name); | 449 | delete(name); |
456 | } | 450 | } |
457 | highscoreFile.close(); | 451 | highscoreFile.close(); |
458 | } | 452 | } |
459 | } else { | 453 | } else { |
460 | for (int i = 0; i < 10; i++) { | 454 | for (int i = 0; i < 10; i++) { |
461 | hallOfFame[i].points = 5000; | 455 | hallOfFame[i].points = 5000; |
462 | hallOfFame[i].levels = 0; | 456 | hallOfFame[i].levels = 0; |
463 | hallOfFame[i].duration = QTime(); | 457 | hallOfFame[i].duration = QTime(); |
464 | hallOfFame[i].moment = QDateTime(); | 458 | hallOfFame[i].moment = QDateTime(); |
465 | hallOfFame[i].name = "???"; | 459 | hallOfFame[i].name = "???"; |
466 | } | 460 | } |
467 | // write(); | 461 | // write(); |
468 | } | 462 | } |
469 | 463 | ||
470 | for (int i = 0; i < 10; i++) | 464 | for (int i = 0; i < 10; i++) |
471 | for (uint j = 0; j < hallOfFame[i].name.length(); j++) | 465 | for (uint j = 0; j < hallOfFame[i].name.length(); j++) |
472 | if (hallOfFame[i].name.at(j) < bitfont->firstChar() || | 466 | if (hallOfFame[i].name.at(j) < bitfont->firstChar() || |
473 | hallOfFame[i].name.at(j) > bitfont->lastChar()) | 467 | hallOfFame[i].name.at(j) > bitfont->lastChar()) |
474 | hallOfFame[i].name.at(j) = hallOfFame[i].name.at(j).upper(); | 468 | hallOfFame[i].name.at(j) = hallOfFame[i].name.at(j).upper(); |
475 | 469 | ||
476 | HighScore = hallOfFame[0].points; | 470 | HighScore = hallOfFame[0].points; |
477 | } | 471 | } |
478 | 472 | ||
479 | void Score::write() | 473 | void Score::write() |
480 | { | 474 | { |
481 | if (highscoreFile.open(IO_WriteOnly)) { | 475 | if (highscoreFile.open(IO_WriteOnly)) { |
482 | QDataStream s(&highscoreFile); | 476 | QDataStream s(&highscoreFile); |
483 | for (int i = 0; i < 10; i++) | 477 | for (int i = 0; i < 10; i++) |
484 | s << hallOfFame[i].points << hallOfFame[i].levels << hallOfFame[i].duration << | 478 | s << hallOfFame[i].points << hallOfFame[i].levels << hallOfFame[i].duration << |
485 | hallOfFame[i].moment << hallOfFame[i].name.latin1(); | 479 | hallOfFame[i].moment << hallOfFame[i].name.latin1(); |
486 | highscoreFile.close(); | 480 | highscoreFile.close(); |
487 | } | 481 | } |
488 | } | 482 | } |
489 | 483 | ||
490 | void Score::setPause(bool Paused) | 484 | void Score::setPause(bool Paused) |
491 | { | 485 | { |
492 | paused = Paused; | 486 | paused = Paused; |
493 | 487 | ||
494 | QRect r = bitfont->rect(tr("PAUSED")); | 488 | QRect r = bitfont->rect(tr("PAUSED")); |
495 | r.moveCenter(QPoint(this->width()/2, this->height()/2)); | 489 | r.moveCenter(QPoint(this->width()/2, this->height()/2)); |
496 | repaint(r, TRUE); | 490 | repaint(r, TRUE); |
497 | 491 | ||
498 | // repaint 1UP or 2UP | 492 | // repaint 1UP or 2UP |
499 | repaint(FALSE); | 493 | repaint(FALSE); |
500 | } | 494 | } |
501 | 495 | ||
502 | void Score::end() | 496 | void Score::end() |
503 | { | 497 | { |
504 | if (paused) { | 498 | if (paused) { |
505 | QTimer::singleShot(afterPauseMS, this, SLOT(end())); | 499 | QTimer::singleShot(afterPauseMS, this, SLOT(end())); |
506 | return; | 500 | return; |
507 | } | 501 | } |
508 | 502 | ||
509 | // repaint 1UP or 2UP | 503 | // repaint 1UP or 2UP |
510 | lastPlayer = -1; | 504 | lastPlayer = -1; |
511 | repaint(FALSE); | 505 | repaint(FALSE); |
512 | 506 | ||
513 | emit forcedHallOfFame(FALSE); | 507 | emit forcedHallOfFame(FALSE); |
514 | } | 508 | } |
515 | 509 | ||
516 | /* | 510 | /* |
517 | * Return the date in a formatted QString. The format can be changed using internationalization | 511 | * Return the date in a formatted QString. The format can be changed using internationalization |
518 | * of the string "YY/MM/DD". Invalid QDate's where returned as "00/00/00". | 512 | * of the string "YY/MM/DD". Invalid QDate's where returned as "00/00/00". |
519 | */ | 513 | */ |
520 | QString Score::formatDate(QDate date) | 514 | QString Score::formatDate(QDate date) |
521 | { | 515 | { |
522 | QString s = tr("@YY@/@MM@/@DD@"); | 516 | QString s = tr("@YY@/@MM@/@DD@"); |
523 | 517 | ||
524 | QString dd; | 518 | QString dd; |
525 | dd.sprintf("%02d", date.isValid() ? date.year() % 100 : 0); | 519 | dd.sprintf("%02d", date.isValid() ? date.year() % 100 : 0); |
526 | s.replace(QRegExp("@YY@"), dd); | 520 | s.replace(QRegExp("@YY@"), dd); |
527 | dd.sprintf("%02d", date.isValid() ? date.month() : 0); | 521 | dd.sprintf("%02d", date.isValid() ? date.month() : 0); |
528 | s.replace(QRegExp("@MM@"), dd); | 522 | s.replace(QRegExp("@MM@"), dd); |
529 | dd.sprintf("%02d", date.isValid() ? date.day() : 0); | 523 | dd.sprintf("%02d", date.isValid() ? date.day() : 0); |
530 | s.replace(QRegExp("@DD@"), dd); | 524 | s.replace(QRegExp("@DD@"), dd); |
531 | 525 | ||
532 | return s; | 526 | return s; |
533 | } | 527 | } |
534 | 528 | ||
535 | QRect Score::rect(int col, float row, QString str, int align) | 529 | QRect Score::rect(int col, float row, QString str, int align) |
536 | { | 530 | { |
537 | QRect r = bitfont->rect(str); | 531 | QRect r = bitfont->rect(str); |
538 | r.moveBy(x(col), y(row)); | 532 | r.moveBy(x(col), y(row)); |
539 | 533 | ||
540 | int dx = 0; | 534 | int dx = 0; |
541 | int dy = 0; | 535 | int dy = 0; |
diff --git a/noncore/games/kpacman/status.cpp b/noncore/games/kpacman/status.cpp index 2a17c21..02ff63d 100644 --- a/noncore/games/kpacman/status.cpp +++ b/noncore/games/kpacman/status.cpp | |||
@@ -1,368 +1,366 @@ | |||
1 | 1 | ||
2 | #include "portable.h" | 2 | #include "portable.h" |
3 | 3 | ||
4 | #if defined( KDE2_PORT ) | 4 | #if defined( KDE2_PORT ) |
5 | #include <kapp.h> | 5 | #include <kapp.h> |
6 | #include <klocale.h> | 6 | #include <klocale.h> |
7 | #include <kstddirs.h> | 7 | #include <kstddirs.h> |
8 | #include <status.h> | 8 | #include <status.h> |
9 | #include <status.moc> | 9 | #include <status.moc> |
10 | #elif defined( QPE_PORT ) | 10 | #elif defined( QPE_PORT ) |
11 | #include <qpe/qpeapplication.h> | 11 | #include <qpe/qpeapplication.h> |
12 | #include <qpe/config.h> | 12 | #include <qpe/config.h> |
13 | #include "status.h" | 13 | #include "status.h" |
14 | #endif | 14 | #endif |
15 | 15 | ||
16 | #include <qpixmap.h> | ||
17 | #include <qbitmap.h> | 16 | #include <qbitmap.h> |
18 | #include <qstring.h> | ||
19 | #include <qmsgbox.h> | 17 | #include <qmsgbox.h> |
20 | #include <qfileinfo.h> | 18 | #include <qfileinfo.h> |
21 | 19 | ||
22 | Status::Status( QWidget *parent, const char *name, int Scheme, int Mode ) : | 20 | Status::Status( QWidget *parent, const char *name, int Scheme, int Mode ) : |
23 | QWidget( parent, name ) | 21 | QWidget( parent, name ) |
24 | { | 22 | { |
25 | qWarning("Status::Status"); | 23 | qWarning("Status::Status"); |
26 | actualLifes = 0; | 24 | actualLifes = 0; |
27 | actualLevel = 0; | 25 | actualLevel = 0; |
28 | 26 | ||
29 | lifesPix = NULL; | 27 | lifesPix = NULL; |
30 | levelPix = NULL; | 28 | levelPix = NULL; |
31 | 29 | ||
32 | scheme = Scheme; | 30 | scheme = Scheme; |
33 | mode = Mode; | 31 | mode = Mode; |
34 | level = 0; | 32 | level = 0; |
35 | 33 | ||
36 | confScheme(); | 34 | confScheme(); |
37 | } | 35 | } |
38 | 36 | ||
39 | QList<QPixmap> *Status::loadPixmap(QWidget *parent, QString pixmapName, | 37 | QList<QPixmap> *Status::loadPixmap(QWidget *parent, QString pixmapName, |
40 | QList<QPixmap> *pixmaps) | 38 | QList<QPixmap> *pixmaps) |
41 | { | 39 | { |
42 | if (pixmaps == NULL) { | 40 | if (pixmaps == NULL) { |
43 | pixmaps = new QList<QPixmap>; | 41 | pixmaps = new QList<QPixmap>; |
44 | pixmaps->setAutoDelete(TRUE); | 42 | pixmaps->setAutoDelete(TRUE); |
45 | } | 43 | } |
46 | 44 | ||
47 | if (!pixmaps->isEmpty()) | 45 | if (!pixmaps->isEmpty()) |
48 | pixmaps->clear(); | 46 | pixmaps->clear(); |
49 | 47 | ||
50 | QPixmap PIXMAP(pixmapName); | 48 | QPixmap PIXMAP(pixmapName); |
51 | if (PIXMAP.isNull() || PIXMAP.mask() == NULL) { | 49 | if (PIXMAP.isNull() || PIXMAP.mask() == NULL) { |
52 | QString msg = tr("The pixmap could not be contructed.\n\n" | 50 | QString msg = tr("The pixmap could not be contructed.\n\n" |
53 | "The file '@PIXMAPNAME@' does not exist,\n" | 51 | "The file '@PIXMAPNAME@' does not exist,\n" |
54 | "or is of an unknown format."); | 52 | "or is of an unknown format."); |
55 | msg.replace(QRegExp("@PIXMAPNAME@"), pixmapName); | 53 | msg.replace(QRegExp("@PIXMAPNAME@"), pixmapName); |
56 | QMessageBox::information(parent, tr("Initialization Error"), | 54 | QMessageBox::information(parent, tr("Initialization Error"), |
57 | (const char *) msg); | 55 | (const char *) msg); |
58 | return 0; | 56 | return 0; |
59 | } | 57 | } |
60 | 58 | ||
61 | int height = PIXMAP.height(); | 59 | int height = PIXMAP.height(); |
62 | int width = (height == 0) ? 0 : PIXMAP.width()/(PIXMAP.width()/height); | 60 | int width = (height == 0) ? 0 : PIXMAP.width()/(PIXMAP.width()/height); |
63 | 61 | ||
64 | QBitmap BITMAP; | 62 | QBitmap BITMAP; |
65 | QBitmap MASK; | 63 | QBitmap MASK; |
66 | 64 | ||
67 | BITMAP = *PIXMAP.mask(); | 65 | BITMAP = *PIXMAP.mask(); |
68 | MASK.resize(width, height); | 66 | MASK.resize(width, height); |
69 | 67 | ||
70 | for (int x = 0; x < PIXMAP.width()/width; x++) { | 68 | for (int x = 0; x < PIXMAP.width()/width; x++) { |
71 | QPixmap *pixmap = new QPixmap(width, height); | 69 | QPixmap *pixmap = new QPixmap(width, height); |
72 | pixmaps->append(pixmap); | 70 | pixmaps->append(pixmap); |
73 | bitBlt(pixmap, 0, 0, &PIXMAP, x*width, 0, width, height, CopyROP, TRUE); | 71 | bitBlt(pixmap, 0, 0, &PIXMAP, x*width, 0, width, height, CopyROP, TRUE); |
74 | bitBlt(&MASK, 0, 0, &BITMAP, x*width, 0, width, height, CopyROP, TRUE); | 72 | bitBlt(&MASK, 0, 0, &BITMAP, x*width, 0, width, height, CopyROP, TRUE); |
75 | pixmap->setMask(MASK); | 73 | pixmap->setMask(MASK); |
76 | } | 74 | } |
77 | 75 | ||
78 | return pixmaps; | 76 | return pixmaps; |
79 | } | 77 | } |
80 | 78 | ||
81 | void Status::paintEvent( QPaintEvent *) | 79 | void Status::paintEvent( QPaintEvent *) |
82 | { | 80 | { |
83 | for (int x = 0; x < actualLifes && !lifesPix->isEmpty(); x++) | 81 | for (int x = 0; x < actualLifes && !lifesPix->isEmpty(); x++) |
84 | bitBlt(this, lifesPix->at(0)->width()+(lifesPix->at(0)->width()*x), | 82 | bitBlt(this, lifesPix->at(0)->width()+(lifesPix->at(0)->width()*x), |
85 | (height()-lifesPix->at(0)->height())/2, | 83 | (height()-lifesPix->at(0)->height())/2, |
86 | lifesPix->at(0), 0, 0, | 84 | lifesPix->at(0), 0, 0, |
87 | lifesPix->at(0)->width(), lifesPix->at(0)->height()); | 85 | lifesPix->at(0)->width(), lifesPix->at(0)->height()); |
88 | 86 | ||
89 | for (int x = 0; x < actualLevel && !levelPix->isEmpty(); x++) { | 87 | for (int x = 0; x < actualLevel && !levelPix->isEmpty(); x++) { |
90 | erase((width()-levelPix->at(x)->width()*2)-(levelPix->at(x)->width()*levelPos[x]), | 88 | erase((width()-levelPix->at(x)->width()*2)-(levelPix->at(x)->width()*levelPos[x]), |
91 | (height()-levelPix->at(x)->height())/2, | 89 | (height()-levelPix->at(x)->height())/2, |
92 | levelPix->at(x)->width(), levelPix->at(x)->height()); | 90 | levelPix->at(x)->width(), levelPix->at(x)->height()); |
93 | bitBlt(this, (width()-levelPix->at(x)->width()*2)-(levelPix->at(x)->width()*levelPos[x]), | 91 | bitBlt(this, (width()-levelPix->at(x)->width()*2)-(levelPix->at(x)->width()*levelPos[x]), |
94 | (height()-levelPix->at(x)->height())/2, | 92 | (height()-levelPix->at(x)->height())/2, |
95 | levelPix->at(x), 0, 0, | 93 | levelPix->at(x), 0, 0, |
96 | levelPix->at(x)->width(), levelPix->at(x)->height()); | 94 | levelPix->at(x)->width(), levelPix->at(x)->height()); |
97 | } | 95 | } |
98 | } | 96 | } |
99 | 97 | ||
100 | void Status::initPixmaps() | 98 | void Status::initPixmaps() |
101 | { | 99 | { |
102 | if (lastLifesPixmapName != lifesPixmapName.at(level)) { | 100 | if (lastLifesPixmapName != lifesPixmapName.at(level)) { |
103 | lifesPix = loadPixmap(this, lifesPixmapName.at(level), lifesPix); | 101 | lifesPix = loadPixmap(this, lifesPixmapName.at(level), lifesPix); |
104 | lastLifesPixmapName = lifesPixmapName.at(level); | 102 | lastLifesPixmapName = lifesPixmapName.at(level); |
105 | } | 103 | } |
106 | if (lastLevelPixmapName != levelPixmapName.at(level)) { | 104 | if (lastLevelPixmapName != levelPixmapName.at(level)) { |
107 | levelPix = loadPixmap(this, levelPixmapName.at(level), levelPix); | 105 | levelPix = loadPixmap(this, levelPixmapName.at(level), levelPix); |
108 | lastLevelPixmapName = levelPixmapName.at(level); | 106 | lastLevelPixmapName = levelPixmapName.at(level); |
109 | } | 107 | } |
110 | } | 108 | } |
111 | 109 | ||
112 | QString Status::decodeHexOctString(QString s) | 110 | QString Status::decodeHexOctString(QString s) |
113 | { | 111 | { |
114 | QString value; | 112 | QString value; |
115 | QString valids; | 113 | QString valids; |
116 | int pos, xpos = 0, opos = 0; | 114 | int pos, xpos = 0, opos = 0; |
117 | int v, len, leadin; | 115 | int v, len, leadin; |
118 | const char *ptr; | 116 | const char *ptr; |
119 | uchar c; | 117 | uchar c; |
120 | 118 | ||
121 | while (((xpos = s.find(QRegExp("\\\\x[0-9a-fA-F]+"), xpos)) != -1) || | 119 | while (((xpos = s.find(QRegExp("\\\\x[0-9a-fA-F]+"), xpos)) != -1) || |
122 | ((opos = s.find(QRegExp("\\\\[0-7]+"), opos)) != -1)) { | 120 | ((opos = s.find(QRegExp("\\\\[0-7]+"), opos)) != -1)) { |
123 | if (xpos != -1) { | 121 | if (xpos != -1) { |
124 | valids = "0123456789abcdef"; | 122 | valids = "0123456789abcdef"; |
125 | leadin = 2; | 123 | leadin = 2; |
126 | pos = xpos; | 124 | pos = xpos; |
127 | } else { | 125 | } else { |
128 | valids = "01234567"; | 126 | valids = "01234567"; |
129 | leadin = 1; | 127 | leadin = 1; |
130 | pos = opos; | 128 | pos = opos; |
131 | } | 129 | } |
132 | 130 | ||
133 | c = '\0'; | 131 | c = '\0'; |
134 | len = 0; | 132 | len = 0; |
135 | value = s.mid(pos+leadin, 3); | 133 | value = s.mid(pos+leadin, 3); |
136 | ptr = (const char *) value; | 134 | ptr = (const char *) value; |
137 | 135 | ||
138 | while (*ptr != '\0' && (v = valids.find(*ptr++, 0, FALSE)) != -1) { | 136 | while (*ptr != '\0' && (v = valids.find(*ptr++, 0, FALSE)) != -1) { |
139 | c = (c * valids.length()) + v; | 137 | c = (c * valids.length()) + v; |
140 | len++; | 138 | len++; |
141 | } | 139 | } |
142 | 140 | ||
143 | value.fill(c, 1); | 141 | value.fill(c, 1); |
144 | s.replace(pos, len+leadin, value); | 142 | s.replace(pos, len+leadin, value); |
145 | } | 143 | } |
146 | 144 | ||
147 | return s; | 145 | return s; |
148 | } | 146 | } |
149 | 147 | ||
150 | void Status::fillArray(QArray<int> &array, QString values, int max) | 148 | void Status::fillArray(QArray<int> &array, QString values, int max) |
151 | { | 149 | { |
152 | array.resize(max); | 150 | array.resize(max); |
153 | int last = 0; | 151 | int last = 0; |
154 | bool ok; | 152 | bool ok; |
155 | QString value; | 153 | QString value; |
156 | 154 | ||
157 | for (uint i = 0; i < array.size(); i++) { | 155 | for (uint i = 0; i < array.size(); i++) { |
158 | if (values.find(',') < 0 && values.length() > 0) { | 156 | if (values.find(',') < 0 && values.length() > 0) { |
159 | value = values; | 157 | value = values; |
160 | values = ""; | 158 | values = ""; |
161 | } | 159 | } |
162 | if (values.find(',') >= 0) { | 160 | if (values.find(',') >= 0) { |
163 | value = values.left(values.find(',')); | 161 | value = values.left(values.find(',')); |
164 | values.remove(0,values.find(',')+1); | 162 | values.remove(0,values.find(',')+1); |
165 | } | 163 | } |
166 | array[i] = value.toInt(&ok); | 164 | array[i] = value.toInt(&ok); |
167 | if (ok) | 165 | if (ok) |
168 | last = array[i]; | 166 | last = array[i]; |
169 | else | 167 | else |
170 | array[i] = last; | 168 | array[i] = last; |
171 | } | 169 | } |
172 | } | 170 | } |
173 | 171 | ||
174 | void Status::fillStrList(QStrList &list, QString values, int max) | 172 | void Status::fillStrList(QStrList &list, QString values, int max) |
175 | { | 173 | { |
176 | if (!list.isEmpty()) | 174 | if (!list.isEmpty()) |
177 | list.clear(); | 175 | list.clear(); |
178 | 176 | ||
179 | QString last = ""; | 177 | QString last = ""; |
180 | QString value; | 178 | QString value; |
181 | 179 | ||
182 | for (uint i = 0; i < (uint) max; i++) { | 180 | for (uint i = 0; i < (uint) max; i++) { |
183 | if (values.find(',') < 0 && values.length() > 0) { | 181 | if (values.find(',') < 0 && values.length() > 0) { |
184 | value = values; | 182 | value = values; |
185 | values = ""; | 183 | values = ""; |
186 | } | 184 | } |
187 | if (values.find(',') >= 0) { | 185 | if (values.find(',') >= 0) { |
188 | value = values.left(values.find(',')); | 186 | value = values.left(values.find(',')); |
189 | values.remove(0,values.find(',')+1); | 187 | values.remove(0,values.find(',')+1); |
190 | } | 188 | } |
191 | if (!value.isEmpty()) | 189 | if (!value.isEmpty()) |
192 | last = decodeHexOctString(value); | 190 | last = decodeHexOctString(value); |
193 | list.append(last); | 191 | list.append(last); |
194 | } | 192 | } |
195 | } | 193 | } |
196 | 194 | ||
197 | void Status::fillPixmapName(QStrList &pixmapName) | 195 | void Status::fillPixmapName(QStrList &pixmapName) |
198 | { | 196 | { |
199 | QStrList list = pixmapName; | 197 | QStrList list = pixmapName; |
200 | 198 | ||
201 | if (!pixmapName.isEmpty()) | 199 | if (!pixmapName.isEmpty()) |
202 | pixmapName.clear(); | 200 | pixmapName.clear(); |
203 | 201 | ||
204 | QString pixmap; | 202 | QString pixmap; |
205 | 203 | ||
206 | QFileInfo fileInfo; | 204 | QFileInfo fileInfo; |
207 | 205 | ||
208 | for (uint i = 0; i < list.count(); i++) { | 206 | for (uint i = 0; i < list.count(); i++) { |
209 | pixmap = list.at(i); | 207 | pixmap = list.at(i); |
210 | 208 | ||
211 | if (pixmap.left(1) != "/" && pixmap.left(1) != "~") | 209 | if (pixmap.left(1) != "/" && pixmap.left(1) != "~") |
212 | pixmap = FIND_APP_DATA( pixmapDirectory+pixmap ); | 210 | pixmap = FIND_APP_DATA( pixmapDirectory+pixmap ); |
213 | 211 | ||
214 | fileInfo.setFile(pixmap); | 212 | fileInfo.setFile(pixmap); |
215 | if (!fileInfo.isReadable() || !fileInfo.isFile()) | 213 | if (!fileInfo.isReadable() || !fileInfo.isFile()) |
216 | pixmap = ""; | 214 | pixmap = ""; |
217 | 215 | ||
218 | pixmapName.append(pixmap); | 216 | pixmapName.append(pixmap); |
219 | } | 217 | } |
220 | } | 218 | } |
221 | 219 | ||
222 | void Status::confLevels(bool defGroup) | 220 | void Status::confLevels(bool defGroup) |
223 | { | 221 | { |
224 | APP_CONFIG_BEGIN( cfg ); | 222 | APP_CONFIG_BEGIN( cfg ); |
225 | if (defGroup || cfg->hasKey("Levels")) | 223 | if (defGroup || cfg->hasKey("Levels")) |
226 | maxLevel = cfg->readNumEntry("Levels", 13); | 224 | maxLevel = cfg->readNumEntry("Levels", 13); |
227 | APP_CONFIG_END( cfg ); | 225 | APP_CONFIG_END( cfg ); |
228 | } | 226 | } |
229 | 227 | ||
230 | void Status::confMisc(bool defGroup) | 228 | void Status::confMisc(bool defGroup) |
231 | { | 229 | { |
232 | APP_CONFIG_BEGIN( cfg ); | 230 | APP_CONFIG_BEGIN( cfg ); |
233 | if (defGroup || cfg->hasKey("LevelPosition")) | 231 | if (defGroup || cfg->hasKey("LevelPosition")) |
234 | fillArray(levelPos, cfg->readEntry("LevelPosition", "0,1,2,3,,4,,5,,6,,7"), maxLevel); | 232 | fillArray(levelPos, cfg->readEntry("LevelPosition", "0,1,2,3,,4,,5,,6,,7"), maxLevel); |
235 | 233 | ||
236 | if (defGroup || cfg->hasKey("PixmapDirectory")) { | 234 | if (defGroup || cfg->hasKey("PixmapDirectory")) { |
237 | pixmapDirectory = cfg->readEntry("PixmapDirectory"); | 235 | pixmapDirectory = cfg->readEntry("PixmapDirectory"); |
238 | 236 | ||
239 | if (pixmapDirectory.left(1) != "/" && pixmapDirectory.left(1) != "~") | 237 | if (pixmapDirectory.left(1) != "/" && pixmapDirectory.left(1) != "~") |
240 | pixmapDirectory.insert(0, "pics/"); | 238 | pixmapDirectory.insert(0, "pics/"); |
241 | if (pixmapDirectory.right(1) != "/") | 239 | if (pixmapDirectory.right(1) != "/") |
242 | pixmapDirectory.append("/"); | 240 | pixmapDirectory.append("/"); |
243 | } | 241 | } |
244 | 242 | ||
245 | if (defGroup || cfg->hasKey("LifesPixmapName")) | 243 | if (defGroup || cfg->hasKey("LifesPixmapName")) |
246 | fillStrList(lifesPixmapName, | 244 | fillStrList(lifesPixmapName, |
247 | cfg->readEntry("LifesPixmapName", "lifes.xpm"), maxLevel+1); | 245 | cfg->readEntry("LifesPixmapName", "lifes.xpm"), maxLevel+1); |
248 | if (defGroup || cfg->hasKey("LevelPixmapName")) | 246 | if (defGroup || cfg->hasKey("LevelPixmapName")) |
249 | fillStrList(levelPixmapName, | 247 | fillStrList(levelPixmapName, |
250 | cfg->readEntry("LevelPixmapName", "fruit.xpm"), maxLevel+1); | 248 | cfg->readEntry("LevelPixmapName", "fruit.xpm"), maxLevel+1); |
251 | APP_CONFIG_END( cfg ); | 249 | APP_CONFIG_END( cfg ); |
252 | } | 250 | } |
253 | 251 | ||
254 | void Status::confScheme() | 252 | void Status::confScheme() |
255 | { | 253 | { |
256 | APP_CONFIG_BEGIN( cfg ); | 254 | APP_CONFIG_BEGIN( cfg ); |
257 | SAVE_CONFIG_GROUP( cfg, oldgroup ); | 255 | SAVE_CONFIG_GROUP( cfg, oldgroup ); |
258 | QString newgroup; | 256 | QString newgroup; |
259 | 257 | ||
260 | // if not set, read mode and scheme from the configfile | 258 | // if not set, read mode and scheme from the configfile |
261 | if (mode == -1 && scheme == -1) { | 259 | if (mode == -1 && scheme == -1) { |
262 | scheme = cfg->readNumEntry("Scheme", -1); | 260 | scheme = cfg->readNumEntry("Scheme", -1); |
263 | mode = cfg->readNumEntry("Mode", -1); | 261 | mode = cfg->readNumEntry("Mode", -1); |
264 | 262 | ||
265 | // if mode is not set in the defGroup-group, lookup the scheme group | 263 | // if mode is not set in the defGroup-group, lookup the scheme group |
266 | if (scheme != -1 || mode == -1) { | 264 | if (scheme != -1 || mode == -1) { |
267 | newgroup.sprintf("Scheme %d", scheme); | 265 | newgroup.sprintf("Scheme %d", scheme); |
268 | cfg->setGroup(newgroup); | 266 | cfg->setGroup(newgroup); |
269 | 267 | ||
270 | mode = cfg->readNumEntry("Mode", -1); | 268 | mode = cfg->readNumEntry("Mode", -1); |
271 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 269 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
272 | } | 270 | } |
273 | } | 271 | } |
274 | 272 | ||
275 | confLevels(); | 273 | confLevels(); |
276 | 274 | ||
277 | if (mode != -1) { | 275 | if (mode != -1) { |
278 | newgroup.sprintf("Mode %d", mode); | 276 | newgroup.sprintf("Mode %d", mode); |
279 | cfg->setGroup(newgroup); | 277 | cfg->setGroup(newgroup); |
280 | 278 | ||
281 | confLevels(FALSE); | 279 | confLevels(FALSE); |
282 | } | 280 | } |
283 | 281 | ||
284 | if (scheme != -1) { | 282 | if (scheme != -1) { |
285 | newgroup.sprintf("Scheme %d", scheme); | 283 | newgroup.sprintf("Scheme %d", scheme); |
286 | cfg->setGroup(newgroup); | 284 | cfg->setGroup(newgroup); |
287 | 285 | ||
288 | confLevels(FALSE); | 286 | confLevels(FALSE); |
289 | } | 287 | } |
290 | 288 | ||
291 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 289 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
292 | 290 | ||
293 | confMisc(); | 291 | confMisc(); |
294 | 292 | ||
295 | if (mode != -1) { | 293 | if (mode != -1) { |
296 | newgroup.sprintf("Mode %d", mode); | 294 | newgroup.sprintf("Mode %d", mode); |
297 | cfg->setGroup(newgroup); | 295 | cfg->setGroup(newgroup); |
298 | 296 | ||
299 | confMisc(FALSE); | 297 | confMisc(FALSE); |
300 | } | 298 | } |
301 | 299 | ||
302 | if (scheme != -1) { | 300 | if (scheme != -1) { |
303 | newgroup.sprintf("Scheme %d", scheme); | 301 | newgroup.sprintf("Scheme %d", scheme); |
304 | cfg->setGroup(newgroup); | 302 | cfg->setGroup(newgroup); |
305 | 303 | ||
306 | confMisc(FALSE); | 304 | confMisc(FALSE); |
307 | } | 305 | } |
308 | 306 | ||
309 | fillPixmapName(lifesPixmapName); | 307 | fillPixmapName(lifesPixmapName); |
310 | fillPixmapName(levelPixmapName); | 308 | fillPixmapName(levelPixmapName); |
311 | 309 | ||
312 | initPixmaps(); | 310 | initPixmaps(); |
313 | 311 | ||
314 | setFixedHeight(minHeight()); | 312 | setFixedHeight(minHeight()); |
315 | 313 | ||
316 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 314 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
317 | APP_CONFIG_END( cfg ); | 315 | APP_CONFIG_END( cfg ); |
318 | } | 316 | } |
319 | 317 | ||
320 | void Status::setScheme(int Scheme, int Mode) | 318 | void Status::setScheme(int Scheme, int Mode) |
321 | { | 319 | { |
322 | mode = Mode; | 320 | mode = Mode; |
323 | scheme = Scheme; | 321 | scheme = Scheme; |
324 | 322 | ||
325 | confScheme(); | 323 | confScheme(); |
326 | 324 | ||
327 | repaint(); | 325 | repaint(); |
328 | } | 326 | } |
329 | 327 | ||
330 | int Status::minHeight() | 328 | int Status::minHeight() |
331 | { | 329 | { |
332 | if (lifesPix->isEmpty() && levelPix->isEmpty()) | 330 | if (lifesPix->isEmpty() && levelPix->isEmpty()) |
333 | return 0; | 331 | return 0; |
334 | if (levelPix->isEmpty()) | 332 | if (levelPix->isEmpty()) |
335 | return lifesPix->at(0)->height(); | 333 | return lifesPix->at(0)->height(); |
336 | if (lifesPix->isEmpty()) | 334 | if (lifesPix->isEmpty()) |
337 | return levelPix->at(0)->height(); | 335 | return levelPix->at(0)->height(); |
338 | return (lifesPix->at(0)->height() > levelPix->at(0)->height()) ? | 336 | return (lifesPix->at(0)->height() > levelPix->at(0)->height()) ? |
339 | lifesPix->at(0)->height() : levelPix->at(0)->height(); | 337 | lifesPix->at(0)->height() : levelPix->at(0)->height(); |
340 | } | 338 | } |
341 | 339 | ||
342 | int Status::minWidth() | 340 | int Status::minWidth() |
343 | { | 341 | { |
344 | if (lifesPix->isEmpty() && levelPix->isEmpty()) | 342 | if (lifesPix->isEmpty() && levelPix->isEmpty()) |
345 | return 0; | 343 | return 0; |
346 | if (levelPix->isEmpty()) | 344 | if (levelPix->isEmpty()) |
347 | return lifesPix->at(0)->width(); | 345 | return lifesPix->at(0)->width(); |
348 | if (lifesPix->isEmpty()) | 346 | if (lifesPix->isEmpty()) |
349 | return levelPix->at(0)->width(); | 347 | return levelPix->at(0)->width(); |
350 | return (lifesPix->at(0)->width() > levelPix->at(0)->width()) ? | 348 | return (lifesPix->at(0)->width() > levelPix->at(0)->width()) ? |
351 | lifesPix->at(0)->width() : levelPix->at(0)->width(); | 349 | lifesPix->at(0)->width() : levelPix->at(0)->width(); |
352 | } | 350 | } |
353 | 351 | ||
354 | void Status::setLifes(int lifes) | 352 | void Status::setLifes(int lifes) |
355 | { | 353 | { |
356 | actualLifes = lifes; | 354 | actualLifes = lifes; |
357 | repaint(); | 355 | repaint(); |
358 | } | 356 | } |
359 | 357 | ||
360 | void Status::setLevel(int Level) | 358 | void Status::setLevel(int Level) |
361 | { | 359 | { |
362 | level = Level; | 360 | level = Level; |
363 | 361 | ||
364 | initPixmaps(); | 362 | initPixmaps(); |
365 | 363 | ||
366 | actualLevel = (level > (int) levelPix->count()) ? (int) levelPix->count() : level; | 364 | actualLevel = (level > (int) levelPix->count()) ? (int) levelPix->count() : level; |
367 | repaint(); | 365 | repaint(); |
368 | } | 366 | } |
diff --git a/noncore/games/mindbreaker/mindbreaker.cpp b/noncore/games/mindbreaker/mindbreaker.cpp index e1f43d0..2b924c6 100644 --- a/noncore/games/mindbreaker/mindbreaker.cpp +++ b/noncore/games/mindbreaker/mindbreaker.cpp | |||
@@ -1,545 +1,541 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "mindbreaker.h" | 21 | #include "mindbreaker.h" |
22 | 22 | ||
23 | #include <qtopia/resource.h> | 23 | #include <qtopia/resource.h> |
24 | #include <qtopia/config.h> | 24 | #include <qtopia/config.h> |
25 | #include <qtopia/qpeapplication.h> | 25 | #include <qtopia/qpeapplication.h> |
26 | #include <qtoolbar.h> | 26 | #include <qtoolbar.h> |
27 | 27 | ||
28 | #include <qpainter.h> | ||
29 | #include <qpixmap.h> | ||
30 | #include <qtoolbutton.h> | 28 | #include <qtoolbutton.h> |
31 | #include <qpushbutton.h> | ||
32 | #include <qmessagebox.h> | 29 | #include <qmessagebox.h> |
33 | #include <qlabel.h> | ||
34 | #include <qlayout.h> | 30 | #include <qlayout.h> |
35 | #include <qtimer.h> | 31 | #include <qtimer.h> |
36 | 32 | ||
37 | #include <stdlib.h> | 33 | #include <stdlib.h> |
38 | #include <sys/time.h> | 34 | #include <sys/time.h> |
39 | #include <unistd.h> | 35 | #include <unistd.h> |
40 | 36 | ||
41 | static int pegRTTI = 3393393; | 37 | static int pegRTTI = 3393393; |
42 | 38 | ||
43 | static int adjusted_panel_height; | 39 | static int adjusted_panel_height; |
44 | static int adjusted_panel_width; | 40 | static int adjusted_panel_width; |
45 | 41 | ||
46 | static int adjusted_bin_margin; | 42 | static int adjusted_bin_margin; |
47 | static int adjusted_peg_size; | 43 | static int adjusted_peg_size; |
48 | static int adjusted_answerpeg_size; | 44 | static int adjusted_answerpeg_size; |
49 | 45 | ||
50 | static int adjusted_title_height; | 46 | static int adjusted_title_height; |
51 | static int adjusted_title_width; | 47 | static int adjusted_title_width; |
52 | 48 | ||
53 | static int adjusted_first_peg_x_diff; | 49 | static int adjusted_first_peg_x_diff; |
54 | static int adjusted_first_peg_y_diff; | 50 | static int adjusted_first_peg_y_diff; |
55 | static int adjusted_peg_spacing; | 51 | static int adjusted_peg_spacing; |
56 | 52 | ||
57 | static int adjusted_answerpegx; | 53 | static int adjusted_answerpegx; |
58 | static int adjusted_answerpegy; | 54 | static int adjusted_answerpegy; |
59 | static int adjusted_answerpeg_xdiff; | 55 | static int adjusted_answerpeg_xdiff; |
60 | static int adjusted_answerpeg_ydiff; | 56 | static int adjusted_answerpeg_ydiff; |
61 | 57 | ||
62 | static int adjusted_board_height; | 58 | static int adjusted_board_height; |
63 | static int adjusted_board_width; | 59 | static int adjusted_board_width; |
64 | 60 | ||
65 | static void setupBoardSize(int w, int h) | 61 | static void setupBoardSize(int w, int h) |
66 | { | 62 | { |
67 | adjusted_panel_width = w * 3/4; | 63 | adjusted_panel_width = w * 3/4; |
68 | adjusted_title_width = w * 3/4; | 64 | adjusted_title_width = w * 3/4; |
69 | 65 | ||
70 | adjusted_title_height = h/10; | 66 | adjusted_title_height = h/10; |
71 | adjusted_panel_height = (h-adjusted_title_height)/9; | 67 | adjusted_panel_height = (h-adjusted_title_height)/9; |
72 | 68 | ||
73 | adjusted_bin_margin = w * 10/240; | 69 | adjusted_bin_margin = w * 10/240; |
74 | adjusted_peg_size = adjusted_panel_height*3/4; | 70 | adjusted_peg_size = adjusted_panel_height*3/4; |
75 | adjusted_answerpeg_size = QMIN(adjusted_panel_width*15/180,adjusted_panel_height*15/25); | 71 | adjusted_answerpeg_size = QMIN(adjusted_panel_width*15/180,adjusted_panel_height*15/25); |
76 | 72 | ||
77 | // looks a bit dodgy on larger sizes | 73 | // looks a bit dodgy on larger sizes |
78 | if ( adjusted_peg_size > 40 ) | 74 | if ( adjusted_peg_size > 40 ) |
79 | adjusted_peg_size = 40; | 75 | adjusted_peg_size = 40; |
80 | 76 | ||
81 | adjusted_first_peg_x_diff = w * 31/240-adjusted_peg_size/2; | 77 | adjusted_first_peg_x_diff = w * 31/240-adjusted_peg_size/2; |
82 | adjusted_first_peg_y_diff = (adjusted_panel_height - adjusted_peg_size)/2; | 78 | adjusted_first_peg_y_diff = (adjusted_panel_height - adjusted_peg_size)/2; |
83 | adjusted_peg_spacing = w * 30/240; | 79 | adjusted_peg_spacing = w * 30/240; |
84 | 80 | ||
85 | // looks a bit dodgy on larger sizes (still does though, but not as much...) | 81 | // looks a bit dodgy on larger sizes (still does though, but not as much...) |
86 | if ( adjusted_answerpeg_size > 22 ) | 82 | if ( adjusted_answerpeg_size > 22 ) |
87 | adjusted_answerpeg_size = 22; | 83 | adjusted_answerpeg_size = 22; |
88 | 84 | ||
89 | adjusted_answerpegx = adjusted_panel_width * 159/180 - adjusted_answerpeg_size/2; | 85 | adjusted_answerpegx = adjusted_panel_width * 159/180 - adjusted_answerpeg_size/2; |
90 | adjusted_answerpegy = adjusted_panel_height/3 - adjusted_answerpeg_size/2; | 86 | adjusted_answerpegy = adjusted_panel_height/3 - adjusted_answerpeg_size/2; |
91 | adjusted_answerpeg_xdiff = adjusted_panel_width * 10/180; | 87 | adjusted_answerpeg_xdiff = adjusted_panel_width * 10/180; |
92 | adjusted_answerpeg_ydiff = adjusted_panel_height * 9/25; | 88 | adjusted_answerpeg_ydiff = adjusted_panel_height * 9/25; |
93 | 89 | ||
94 | adjusted_board_height = adjusted_title_height + (adjusted_panel_height * 9); | 90 | adjusted_board_height = adjusted_title_height + (adjusted_panel_height * 9); |
95 | adjusted_board_width = adjusted_panel_width + (adjusted_bin_margin * 2) + adjusted_peg_size; | 91 | adjusted_board_width = adjusted_panel_width + (adjusted_bin_margin * 2) + adjusted_peg_size; |
96 | 92 | ||
97 | // qDebug("Adjusted width %d height %d", adjusted_board_width, adjusted_board_height); | 93 | // qDebug("Adjusted width %d height %d", adjusted_board_width, adjusted_board_height); |
98 | } | 94 | } |
99 | 95 | ||
100 | 96 | ||
101 | /* helper class, */ | 97 | /* helper class, */ |
102 | class Peg : public QCanvasRectangle | 98 | class Peg : public QCanvasRectangle |
103 | { | 99 | { |
104 | public: | 100 | public: |
105 | Peg(QCanvas *canvas, int type, int go = -1, int pos = -1); | 101 | Peg(QCanvas *canvas, int type, int go = -1, int pos = -1); |
106 | int rtti() const {return pegRTTI; } | 102 | int rtti() const {return pegRTTI; } |
107 | void advance(int phase); | 103 | void advance(int phase); |
108 | 104 | ||
109 | bool hit( const QPoint &) const; | 105 | bool hit( const QPoint &) const; |
110 | 106 | ||
111 | /* a placed peg is one that has been set down on the board correctly and | 107 | /* a placed peg is one that has been set down on the board correctly and |
112 | should not be moved, only copied */ | 108 | should not be moved, only copied */ |
113 | bool placed() const; | 109 | bool placed() const; |
114 | void setPlaced(bool); | 110 | void setPlaced(bool); |
115 | 111 | ||
116 | int pegGo() const; | 112 | int pegGo() const; |
117 | int pegPos() const; | 113 | int pegPos() const; |
118 | void setPegPos(int); | 114 | void setPegPos(int); |
119 | 115 | ||
120 | int type() const; | 116 | int type() const; |
121 | 117 | ||
122 | static void buildImages(); | 118 | static void buildImages(); |
123 | static QImage imageForType(int t); | 119 | static QImage imageForType(int t); |
124 | 120 | ||
125 | static int eggLevel; | 121 | static int eggLevel; |
126 | 122 | ||
127 | protected: | 123 | protected: |
128 | void drawShape(QPainter &); | 124 | void drawShape(QPainter &); |
129 | private: | 125 | private: |
130 | static QVector<QImage> normalPegs; | 126 | static QVector<QImage> normalPegs; |
131 | static QVector<QImage> specialPegs; | 127 | static QVector<QImage> specialPegs; |
132 | 128 | ||
133 | bool isplaced; | 129 | bool isplaced; |
134 | int pegtype; | 130 | int pegtype; |
135 | int peg_go; | 131 | int peg_go; |
136 | int peg_pos; | 132 | int peg_pos; |
137 | 133 | ||
138 | int aniStep; | 134 | int aniStep; |
139 | }; | 135 | }; |
140 | int Peg::eggLevel = 0; | 136 | int Peg::eggLevel = 0; |
141 | QVector<QImage> Peg::normalPegs; | 137 | QVector<QImage> Peg::normalPegs; |
142 | QVector<QImage> Peg::specialPegs; | 138 | QVector<QImage> Peg::specialPegs; |
143 | 139 | ||
144 | void Peg::buildImages() | 140 | void Peg::buildImages() |
145 | { | 141 | { |
146 | QImage pegs = Resource::loadImage("mindbreaker/pegs"); | 142 | QImage pegs = Resource::loadImage("mindbreaker/pegs"); |
147 | int x = 0; | 143 | int x = 0; |
148 | int y = 0; | 144 | int y = 0; |
149 | int i; | 145 | int i; |
150 | eggLevel = 0; | 146 | eggLevel = 0; |
151 | normalPegs.resize(10); | 147 | normalPegs.resize(10); |
152 | for (i = 0; i < 6; i++) { | 148 | for (i = 0; i < 6; i++) { |
153 | normalPegs.insert(i, new QImage(pegs.copy(x, y, peg_size, peg_size). | 149 | normalPegs.insert(i, new QImage(pegs.copy(x, y, peg_size, peg_size). |
154 | smoothScale(adjusted_peg_size, adjusted_peg_size) )); | 150 | smoothScale(adjusted_peg_size, adjusted_peg_size) )); |
155 | x += peg_size; | 151 | x += peg_size; |
156 | } | 152 | } |
157 | specialPegs.resize(5); | 153 | specialPegs.resize(5); |
158 | for (i = 0; i < 5; i++) { | 154 | for (i = 0; i < 5; i++) { |
159 | specialPegs.insert(i, new QImage(pegs.copy(x,y,peg_size, peg_size). | 155 | specialPegs.insert(i, new QImage(pegs.copy(x,y,peg_size, peg_size). |
160 | smoothScale(adjusted_peg_size, adjusted_peg_size) )); | 156 | smoothScale(adjusted_peg_size, adjusted_peg_size) )); |
161 | x += peg_size; | 157 | x += peg_size; |
162 | } | 158 | } |
163 | 159 | ||
164 | QImage image = Resource::loadImage("mindbreaker/mindbreaker"); | 160 | QImage image = Resource::loadImage("mindbreaker/mindbreaker"); |
165 | /* copy from master image to functional images */ | 161 | /* copy from master image to functional images */ |
166 | x = 0; | 162 | x = 0; |
167 | y = panel_height; | 163 | y = panel_height; |
168 | normalPegs.insert(8, | 164 | normalPegs.insert(8, |
169 | new QImage( image.copy(x, y, panel_width, panel_height). | 165 | new QImage( image.copy(x, y, panel_width, panel_height). |
170 | smoothScale( adjusted_panel_width, adjusted_panel_height) | 166 | smoothScale( adjusted_panel_width, adjusted_panel_height) |
171 | )); | 167 | )); |
172 | y += panel_height; | 168 | y += panel_height; |
173 | y += title_height; | 169 | y += title_height; |
174 | normalPegs.insert(9, | 170 | normalPegs.insert(9, |
175 | new QImage(image.copy(x, y, title_width, title_height). | 171 | new QImage(image.copy(x, y, title_width, title_height). |
176 | smoothScale( adjusted_title_width, adjusted_title_height) | 172 | smoothScale( adjusted_title_width, adjusted_title_height) |
177 | )); | 173 | )); |
178 | y += title_height; | 174 | y += title_height; |
179 | 175 | ||
180 | x = 6 * peg_size; | 176 | x = 6 * peg_size; |
181 | normalPegs.insert(6, | 177 | normalPegs.insert(6, |
182 | new QImage(image.copy(x, y, answerpeg_size, answerpeg_size). | 178 | new QImage(image.copy(x, y, answerpeg_size, answerpeg_size). |
183 | smoothScale( adjusted_answerpeg_size, adjusted_answerpeg_size) )); | 179 | smoothScale( adjusted_answerpeg_size, adjusted_answerpeg_size) )); |
184 | x += answerpeg_size; | 180 | x += answerpeg_size; |
185 | normalPegs.insert(7, | 181 | normalPegs.insert(7, |
186 | new QImage(image.copy(x, y, answerpeg_size, answerpeg_size). | 182 | new QImage(image.copy(x, y, answerpeg_size, answerpeg_size). |
187 | smoothScale( adjusted_answerpeg_size, adjusted_answerpeg_size) )); | 183 | smoothScale( adjusted_answerpeg_size, adjusted_answerpeg_size) )); |
188 | } | 184 | } |
189 | 185 | ||
190 | QImage Peg::imageForType(int t) | 186 | QImage Peg::imageForType(int t) |
191 | { | 187 | { |
192 | if (eggLevel > t ) { | 188 | if (eggLevel > t ) { |
193 | if( t < 5) { | 189 | if( t < 5) { |
194 | return *specialPegs[t]; | 190 | return *specialPegs[t]; |
195 | } else { | 191 | } else { |
196 | return *normalPegs[rand() % 6]; | 192 | return *normalPegs[rand() % 6]; |
197 | } | 193 | } |
198 | } | 194 | } |
199 | return *normalPegs[t]; | 195 | return *normalPegs[t]; |
200 | } | 196 | } |
201 | 197 | ||
202 | Peg::Peg(QCanvas *canvas , int t, int g, int p) | 198 | Peg::Peg(QCanvas *canvas , int t, int g, int p) |
203 | : QCanvasRectangle(canvas) | 199 | : QCanvasRectangle(canvas) |
204 | { | 200 | { |
205 | setSize(normalPegs[t]->width(), normalPegs[t]->height() ); | 201 | setSize(normalPegs[t]->width(), normalPegs[t]->height() ); |
206 | pegtype = t; | 202 | pegtype = t; |
207 | isplaced = FALSE; | 203 | isplaced = FALSE; |
208 | peg_pos = p; | 204 | peg_pos = p; |
209 | peg_go = g; | 205 | peg_go = g; |
210 | aniStep = rand() % 6; | 206 | aniStep = rand() % 6; |
211 | setAnimated(TRUE); | 207 | setAnimated(TRUE); |
212 | } | 208 | } |
213 | 209 | ||
214 | void Peg::advance(int phase) { | 210 | void Peg::advance(int phase) { |
215 | if (phase == 0) | 211 | if (phase == 0) |
216 | aniStep = (++aniStep) % 6; | 212 | aniStep = (++aniStep) % 6; |
217 | else { | 213 | else { |
218 | hide(); | 214 | hide(); |
219 | show(); | 215 | show(); |
220 | } | 216 | } |
221 | } | 217 | } |
222 | 218 | ||
223 | void Peg::drawShape(QPainter &p ) | 219 | void Peg::drawShape(QPainter &p ) |
224 | { | 220 | { |
225 | if ((pegtype == 5) && eggLevel > 5) { | 221 | if ((pegtype == 5) && eggLevel > 5) { |
226 | p.drawImage(int(x()), int(y()), *normalPegs[aniStep]); | 222 | p.drawImage(int(x()), int(y()), *normalPegs[aniStep]); |
227 | } else | 223 | } else |
228 | p.drawImage(int(x()), int(y()), imageForType(pegtype)); | 224 | p.drawImage(int(x()), int(y()), imageForType(pegtype)); |
229 | } | 225 | } |
230 | 226 | ||
231 | bool Peg::hit( const QPoint &p ) const | 227 | bool Peg::hit( const QPoint &p ) const |
232 | { | 228 | { |
233 | int ix = p.x() - int(x()); | 229 | int ix = p.x() - int(x()); |
234 | int iy = p.y() - int(y()); | 230 | int iy = p.y() - int(y()); |
235 | if (!normalPegs[pegtype]->valid(ix, iy)) | 231 | if (!normalPegs[pegtype]->valid(ix, iy)) |
236 | return FALSE; | 232 | return FALSE; |
237 | QRgb pixel = normalPegs[pegtype]->pixel(ix, iy); | 233 | QRgb pixel = normalPegs[pegtype]->pixel(ix, iy); |
238 | return (qAlpha(pixel ) != 0); | 234 | return (qAlpha(pixel ) != 0); |
239 | } | 235 | } |
240 | 236 | ||
241 | inline bool Peg::placed() const | 237 | inline bool Peg::placed() const |
242 | { | 238 | { |
243 | return isplaced; | 239 | return isplaced; |
244 | } | 240 | } |
245 | 241 | ||
246 | inline int Peg::pegGo() const | 242 | inline int Peg::pegGo() const |
247 | { | 243 | { |
248 | return peg_go; | 244 | return peg_go; |
249 | } | 245 | } |
250 | 246 | ||
251 | inline int Peg::pegPos() const | 247 | inline int Peg::pegPos() const |
252 | { | 248 | { |
253 | return peg_pos; | 249 | return peg_pos; |
254 | } | 250 | } |
255 | 251 | ||
256 | inline void Peg::setPegPos(int p) | 252 | inline void Peg::setPegPos(int p) |
257 | { | 253 | { |
258 | peg_pos = p; | 254 | peg_pos = p; |
259 | } | 255 | } |
260 | 256 | ||
261 | inline void Peg::setPlaced(bool p) | 257 | inline void Peg::setPlaced(bool p) |
262 | { | 258 | { |
263 | isplaced = p; | 259 | isplaced = p; |
264 | } | 260 | } |
265 | 261 | ||
266 | inline int Peg::type() const | 262 | inline int Peg::type() const |
267 | { | 263 | { |
268 | return pegtype; | 264 | return pegtype; |
269 | } | 265 | } |
270 | 266 | ||
271 | /* Load the main image, copy from it the pegs, the board, and the answer image | 267 | /* Load the main image, copy from it the pegs, the board, and the answer image |
272 | * and use these to create the tray, answer and board | 268 | * and use these to create the tray, answer and board |
273 | */ | 269 | */ |
274 | MindBreaker::MindBreaker( QWidget *parent, const char *name, int wFlags ) | 270 | MindBreaker::MindBreaker( QWidget *parent, const char *name, int wFlags ) |
275 | : QMainWindow(parent, name, wFlags) | 271 | : QMainWindow(parent, name, wFlags) |
276 | { | 272 | { |
277 | setCaption( tr("Mind Breaker")); | 273 | setCaption( tr("Mind Breaker")); |
278 | QPEApplication::setInputMethodHint( this, QPEApplication::AlwaysOff ); | 274 | QPEApplication::setInputMethodHint( this, QPEApplication::AlwaysOff ); |
279 | setMinimumSize(160,210); | 275 | setMinimumSize(160,210); |
280 | 276 | ||
281 | QWidget *w = new QWidget( this ); | 277 | QWidget *w = new QWidget( this ); |
282 | w->setBackgroundColor( black ); | 278 | w->setBackgroundColor( black ); |
283 | QHBoxLayout *hb = new QHBoxLayout( w ); | 279 | QHBoxLayout *hb = new QHBoxLayout( w ); |
284 | hb->addStretch(); | 280 | hb->addStretch(); |
285 | board = new MindBreakerBoard(w); | 281 | board = new MindBreakerBoard(w); |
286 | hb->addWidget( board, 100 ); | 282 | hb->addWidget( board, 100 ); |
287 | hb->addStretch(); | 283 | hb->addStretch(); |
288 | 284 | ||
289 | setCentralWidget(w); | 285 | setCentralWidget(w); |
290 | 286 | ||
291 | setToolBarsMovable( FALSE ); | 287 | setToolBarsMovable( FALSE ); |
292 | 288 | ||
293 | QToolBar *tb = new QToolBar(this); | 289 | QToolBar *tb = new QToolBar(this); |
294 | tb->setHorizontalStretchable( TRUE ); | 290 | tb->setHorizontalStretchable( TRUE ); |
295 | 291 | ||
296 | QIconSet newicon = Resource::loadIconSet("new"); | 292 | QIconSet newicon = Resource::loadIconSet("new"); |
297 | new QToolButton(newicon, tr("New Game"), 0, | 293 | new QToolButton(newicon, tr("New Game"), 0, |
298 | board, SLOT(clear()), tb, "NewGame"); | 294 | board, SLOT(clear()), tb, "NewGame"); |
299 | 295 | ||
300 | score = new QToolButton(tb); | 296 | score = new QToolButton(tb); |
301 | score->setText(""); | 297 | score->setText(""); |
302 | score->setMaximumHeight(20); | 298 | score->setMaximumHeight(20); |
303 | score->setUsesTextLabel(TRUE); | 299 | score->setUsesTextLabel(TRUE); |
304 | tb->setStretchableWidget(score); | 300 | tb->setStretchableWidget(score); |
305 | 301 | ||
306 | connect(board, SIGNAL(scoreChanged(int,int)), this, SLOT(setScore(int,int))); | 302 | connect(board, SIGNAL(scoreChanged(int,int)), this, SLOT(setScore(int,int))); |
307 | connect(score, SIGNAL(clicked()), board, SLOT(resetScore())); | 303 | connect(score, SIGNAL(clicked()), board, SLOT(resetScore())); |
308 | 304 | ||
309 | int a, b; | 305 | int a, b; |
310 | board->getScore(&a, &b); | 306 | board->getScore(&a, &b); |
311 | setScore(a,b); | 307 | setScore(a,b); |
312 | 308 | ||
313 | layout()->setResizeMode(QLayout::FreeResize); | 309 | layout()->setResizeMode(QLayout::FreeResize); |
314 | } | 310 | } |
315 | 311 | ||
316 | void MindBreaker::setScore(int turns, int games) | 312 | void MindBreaker::setScore(int turns, int games) |
317 | { | 313 | { |
318 | double average; | 314 | double average; |
319 | double total_turns = turns; | 315 | double total_turns = turns; |
320 | double total_games = games; | 316 | double total_games = games; |
321 | 317 | ||
322 | if(total_games > 0) | 318 | if(total_games > 0) |
323 | average = total_turns / total_games; | 319 | average = total_turns / total_games; |
324 | else | 320 | else |
325 | average = 0.0; | 321 | average = 0.0; |
326 | 322 | ||
327 | score->setText(tr("win avg: %1 turns (%2 games)").arg(average).arg(games)); | 323 | score->setText(tr("win avg: %1 turns (%2 games)").arg(average).arg(games)); |
328 | } | 324 | } |
329 | 325 | ||
330 | void MindBreaker::resizeEvent( QResizeEvent *e ) | 326 | void MindBreaker::resizeEvent( QResizeEvent *e ) |
331 | { | 327 | { |
332 | board->fixSize(); | 328 | board->fixSize(); |
333 | QMainWindow::resizeEvent( e ); | 329 | QMainWindow::resizeEvent( e ); |
334 | } | 330 | } |
335 | 331 | ||
336 | 332 | ||
337 | MindBreakerBoard::MindBreakerBoard( QWidget *parent, | 333 | MindBreakerBoard::MindBreakerBoard( QWidget *parent, |
338 | const char *name, int wFlags ) | 334 | const char *name, int wFlags ) |
339 | : QCanvasView(0, parent, name, wFlags), | 335 | : QCanvasView(0, parent, name, wFlags), |
340 | moving(0), game_over(FALSE), total_turns(0), total_games(0) | 336 | moving(0), game_over(FALSE), total_turns(0), total_games(0) |
341 | { | 337 | { |
342 | setFrameStyle( NoFrame ); | 338 | setFrameStyle( NoFrame ); |
343 | setupBoardSize(qApp->desktop()->width(),qApp->desktop()->height()); | 339 | setupBoardSize(qApp->desktop()->width(),qApp->desktop()->height()); |
344 | cnv.resize(100,100); | 340 | cnv.resize(100,100); |
345 | setCanvas(&cnv); | 341 | setCanvas(&cnv); |
346 | setBackgroundColor( black ); | 342 | setBackgroundColor( black ); |
347 | 343 | ||
348 | struct timeval tv; | 344 | struct timeval tv; |
349 | 345 | ||
350 | current_go = 0; | 346 | current_go = 0; |
351 | gettimeofday(&tv, 0); | 347 | gettimeofday(&tv, 0); |
352 | srand(tv.tv_usec); | 348 | srand(tv.tv_usec); |
353 | 349 | ||
354 | canvas()->setAdvancePeriod(500); | 350 | canvas()->setAdvancePeriod(500); |
355 | current_highlight = 0; | 351 | current_highlight = 0; |
356 | 352 | ||
357 | widthTimer = new QTimer( this ); | 353 | widthTimer = new QTimer( this ); |
358 | connect(widthTimer, SIGNAL(timeout()), this, SLOT(doFixSize()) ); | 354 | connect(widthTimer, SIGNAL(timeout()), this, SLOT(doFixSize()) ); |
359 | 355 | ||
360 | setMaximumWidth( QMIN(qApp->desktop()->height(),qApp->desktop()->width()) ); | 356 | setMaximumWidth( QMIN(qApp->desktop()->height(),qApp->desktop()->width()) ); |
361 | //doFixSize(); // build images... needs to be done before reading config. | 357 | //doFixSize(); // build images... needs to be done before reading config. |
362 | //readConfig(); // first read... to ensure initial labels and side look right. | 358 | //readConfig(); // first read... to ensure initial labels and side look right. |
363 | } | 359 | } |
364 | 360 | ||
365 | void MindBreakerBoard::readConfig() | 361 | void MindBreakerBoard::readConfig() |
366 | { | 362 | { |
367 | Config c("MindBreaker", Config::User); | 363 | Config c("MindBreaker", Config::User); |
368 | c.setGroup("Board"); | 364 | c.setGroup("Board"); |
369 | game_over = FALSE; | 365 | game_over = FALSE; |
370 | int i; | 366 | int i; |
371 | if (c.readNumEntry("Answer0") < 0) { | 367 | if (c.readNumEntry("Answer0") < 0) { |
372 | for (i = 0; i < 4; i++) { | 368 | for (i = 0; i < 4; i++) { |
373 | answer[i] = rand() % 6; | 369 | answer[i] = rand() % 6; |
374 | current_guess[i] = 6; | 370 | current_guess[i] = 6; |
375 | } | 371 | } |
376 | total_turns = 0; | 372 | total_turns = 0; |
377 | total_games = 0; | 373 | total_games = 0; |
378 | } else { | 374 | } else { |
379 | int j; | 375 | int j; |
380 | c.setGroup("Score"); | 376 | c.setGroup("Score"); |
381 | total_turns = c.readNumEntry("Turns"); | 377 | total_turns = c.readNumEntry("Turns"); |
382 | total_games = c.readNumEntry("Games"); | 378 | total_games = c.readNumEntry("Games"); |
383 | if(total_turns < 0) | 379 | if(total_turns < 0) |
384 | total_turns = 0; | 380 | total_turns = 0; |
385 | if(total_games < 0) | 381 | if(total_games < 0) |
386 | total_games = 0; | 382 | total_games = 0; |
387 | 383 | ||
388 | 384 | ||
389 | checkScores(); | 385 | checkScores(); |
390 | c.setGroup("Board"); | 386 | c.setGroup("Board"); |
391 | for(i = 0; i < 4; i++) | 387 | for(i = 0; i < 4; i++) |
392 | answer[i] = c.readNumEntry(QString("Answer%1").arg(i)); | 388 | answer[i] = c.readNumEntry(QString("Answer%1").arg(i)); |
393 | /* read, and parse past guesses */ | 389 | /* read, and parse past guesses */ |
394 | current_go = 0; | 390 | current_go = 0; |
395 | for(j=0; j < 9; j++) { | 391 | for(j=0; j < 9; j++) { |
396 | current_guess[0] = c.readNumEntry(QString("Go%1p0").arg(j)); | 392 | current_guess[0] = c.readNumEntry(QString("Go%1p0").arg(j)); |
397 | if (current_guess[0] < 0) | 393 | if (current_guess[0] < 0) |
398 | break; | 394 | break; |
399 | placeGuessPeg(0, current_guess[0]); | 395 | placeGuessPeg(0, current_guess[0]); |
400 | current_guess[1] = c.readNumEntry(QString("Go%1p1").arg(j)); | 396 | current_guess[1] = c.readNumEntry(QString("Go%1p1").arg(j)); |
401 | placeGuessPeg(1, current_guess[1]); | 397 | placeGuessPeg(1, current_guess[1]); |
402 | current_guess[2] = c.readNumEntry(QString("Go%1p2").arg(j)); | 398 | current_guess[2] = c.readNumEntry(QString("Go%1p2").arg(j)); |
403 | placeGuessPeg(2, current_guess[2]); | 399 | placeGuessPeg(2, current_guess[2]); |
404 | current_guess[3] = c.readNumEntry(QString("Go%1p3").arg(j)); | 400 | current_guess[3] = c.readNumEntry(QString("Go%1p3").arg(j)); |
405 | placeGuessPeg(3, current_guess[3]); | 401 | placeGuessPeg(3, current_guess[3]); |
406 | checkGuess(); | 402 | checkGuess(); |
407 | } | 403 | } |
408 | for(i = 0; i < 4; i++) { | 404 | for(i = 0; i < 4; i++) { |
409 | current_guess[i] = c.readNumEntry(QString("CurrentGo%1").arg(i)); | 405 | current_guess[i] = c.readNumEntry(QString("CurrentGo%1").arg(i)); |
410 | if (current_guess[i] != 6) | 406 | if (current_guess[i] != 6) |
411 | placeGuessPeg(i, current_guess[i]); | 407 | placeGuessPeg(i, current_guess[i]); |
412 | } | 408 | } |
413 | } | 409 | } |
414 | } | 410 | } |
415 | 411 | ||
416 | MindBreakerBoard::~MindBreakerBoard() | 412 | MindBreakerBoard::~MindBreakerBoard() |
417 | { | 413 | { |
418 | int i; | 414 | int i; |
419 | if (game_over) { | 415 | if (game_over) { |
420 | current_go = 0; | 416 | current_go = 0; |
421 | /* clear the answer, clear the guess */ | 417 | /* clear the answer, clear the guess */ |
422 | for (i = 0; i < 4; i++) { | 418 | for (i = 0; i < 4; i++) { |
423 | answer[i] = rand() % 6; | 419 | answer[i] = rand() % 6; |
424 | current_guess[i] = 6; | 420 | current_guess[i] = 6; |
425 | } | 421 | } |
426 | } | 422 | } |
427 | writeConfig(); | 423 | writeConfig(); |
428 | } | 424 | } |
429 | 425 | ||
430 | void MindBreakerBoard::writeConfig() | 426 | void MindBreakerBoard::writeConfig() |
431 | { | 427 | { |
432 | Config c("MindBreaker", Config::User); | 428 | Config c("MindBreaker", Config::User); |
433 | c.setGroup("Board"); | 429 | c.setGroup("Board"); |
434 | c.clearGroup(); | 430 | c.clearGroup(); |
435 | /* write the board */ | 431 | /* write the board */ |
436 | int i,j; | 432 | int i,j; |
437 | for (i = 0; i < current_go; i++) { | 433 | for (i = 0; i < current_go; i++) { |
438 | for(j = 0; j < 4; j++) | 434 | for(j = 0; j < 4; j++) |
439 | c.writeEntry(QString("Go%1p%2").arg(i).arg(j), past_guesses[4*i+j]); | 435 | c.writeEntry(QString("Go%1p%2").arg(i).arg(j), past_guesses[4*i+j]); |
440 | } | 436 | } |
441 | for(j = 0; j < 4; j++) | 437 | for(j = 0; j < 4; j++) |
442 | c.writeEntry(QString("CurrentGo%1").arg(j), current_guess[j]); | 438 | c.writeEntry(QString("CurrentGo%1").arg(j), current_guess[j]); |
443 | for(j = 0; j < 4; j++) | 439 | for(j = 0; j < 4; j++) |
444 | c.writeEntry(QString("Answer%1").arg(j), answer[j]); | 440 | c.writeEntry(QString("Answer%1").arg(j), answer[j]); |
445 | 441 | ||
446 | c.setGroup("Score"); | 442 | c.setGroup("Score"); |
447 | /* write the score */ | 443 | /* write the score */ |
448 | 444 | ||
449 | c.writeEntry("Turns", total_turns); | 445 | c.writeEntry("Turns", total_turns); |
450 | c.writeEntry("Games", total_games); | 446 | c.writeEntry("Games", total_games); |
451 | } | 447 | } |
452 | 448 | ||
453 | void MindBreakerBoard::getScore(int *a, int *b) | 449 | void MindBreakerBoard::getScore(int *a, int *b) |
454 | { | 450 | { |
455 | *a = total_turns; | 451 | *a = total_turns; |
456 | *b = total_games; | 452 | *b = total_games; |
457 | return; | 453 | return; |
458 | } | 454 | } |
459 | 455 | ||
460 | void MindBreakerBoard::fixSize() | 456 | void MindBreakerBoard::fixSize() |
461 | { | 457 | { |
462 | hide(); | 458 | hide(); |
463 | setMaximumWidth( parentWidget()->height() ); | 459 | setMaximumWidth( parentWidget()->height() ); |
464 | widthTimer->start( 20, TRUE ); | 460 | widthTimer->start( 20, TRUE ); |
465 | } | 461 | } |
466 | 462 | ||
467 | void MindBreakerBoard::doFixSize() | 463 | void MindBreakerBoard::doFixSize() |
468 | { | 464 | { |
469 | QSize s = size(); | 465 | QSize s = size(); |
470 | int fw = frameWidth(); | 466 | int fw = frameWidth(); |
471 | s.setWidth(s.width() - fw); | 467 | s.setWidth(s.width() - fw); |
472 | s.setHeight(s.height() - fw); | 468 | s.setHeight(s.height() - fw); |
473 | 469 | ||
474 | /* min size is 200 x 260 */ | 470 | /* min size is 200 x 260 */ |
475 | /* | 471 | /* |
476 | if (s.width() < adjusted_board_width) | 472 | if (s.width() < adjusted_board_width) |
477 | s.setWidth(adjusted_board_width); | 473 | s.setWidth(adjusted_board_width); |
478 | 474 | ||
479 | if (s.height() < adjusted_board_height) | 475 | if (s.height() < adjusted_board_height) |
480 | s.setHeight(adjusted_board_height); | 476 | s.setHeight(adjusted_board_height); |
481 | */ | 477 | */ |
482 | 478 | ||
483 | if ( current_highlight ) // non-first resize | 479 | if ( current_highlight ) // non-first resize |
484 | writeConfig(); | 480 | writeConfig(); |
485 | 481 | ||
486 | setupBoardSize(s.width() - fw, s.height() - fw); | 482 | setupBoardSize(s.width() - fw, s.height() - fw); |
487 | canvas()->resize(s.width() - fw, s.height() - fw); | 483 | canvas()->resize(s.width() - fw, s.height() - fw); |
488 | Peg::buildImages(); // must be done BEFORE any pegs are made | 484 | Peg::buildImages(); // must be done BEFORE any pegs are made |
489 | 485 | ||
490 | QImage image = Resource::loadImage("mindbreaker/mindbreaker"); | 486 | QImage image = Resource::loadImage("mindbreaker/mindbreaker"); |
491 | 487 | ||
492 | /* copy from master image to functional images */ | 488 | /* copy from master image to functional images */ |
493 | int x = 0; | 489 | int x = 0; |
494 | int y = 0; | 490 | int y = 0; |
495 | panelImage = image.copy(x, y, panel_width, panel_height). | 491 | panelImage = image.copy(x, y, panel_width, panel_height). |
496 | smoothScale( adjusted_panel_width, adjusted_panel_height); | 492 | smoothScale( adjusted_panel_width, adjusted_panel_height); |
497 | 493 | ||
498 | y += panel_height; | 494 | y += panel_height; |
499 | y += panel_height; | 495 | y += panel_height; |
500 | 496 | ||
501 | titleImage = image.copy(x, y, title_width, title_height). | 497 | titleImage = image.copy(x, y, title_width, title_height). |
502 | smoothScale( adjusted_title_width, adjusted_title_height); | 498 | smoothScale( adjusted_title_width, adjusted_title_height); |
503 | show(); | 499 | show(); |
504 | 500 | ||
505 | delete current_highlight; | 501 | delete current_highlight; |
506 | current_highlight = new Peg(canvas(), 8); | 502 | current_highlight = new Peg(canvas(), 8); |
507 | current_highlight->setPlaced(TRUE); | 503 | current_highlight->setPlaced(TRUE); |
508 | current_highlight->setX(0); | 504 | current_highlight->setX(0); |
509 | current_highlight->setY(adjusted_board_height - ((current_go + 1) * adjusted_panel_height)); | 505 | current_highlight->setY(adjusted_board_height - ((current_go + 1) * adjusted_panel_height)); |
510 | current_highlight->setZ(0); | 506 | current_highlight->setZ(0); |
511 | current_highlight->show(); | 507 | current_highlight->show(); |
512 | 508 | ||
513 | /* set up the game */ | 509 | /* set up the game */ |
514 | //readConfig(); | 510 | //readConfig(); |
515 | 511 | ||
516 | /* draw initial screen */ | 512 | /* draw initial screen */ |
517 | //drawBackground(); | 513 | //drawBackground(); |
518 | //canvas()->update(); | 514 | //canvas()->update(); |
519 | clear(); | 515 | clear(); |
520 | 516 | ||
521 | readConfig(); | 517 | readConfig(); |
522 | } | 518 | } |
523 | 519 | ||
524 | void MindBreakerBoard::placeGuessPeg(int pos, int pegId) | 520 | void MindBreakerBoard::placeGuessPeg(int pos, int pegId) |
525 | { | 521 | { |
526 | int x = adjusted_first_peg_x_diff + (pos * adjusted_peg_spacing); | 522 | int x = adjusted_first_peg_x_diff + (pos * adjusted_peg_spacing); |
527 | int y = adjusted_board_height - ((current_go + 1) * adjusted_panel_height) | 523 | int y = adjusted_board_height - ((current_go + 1) * adjusted_panel_height) |
528 | + adjusted_first_peg_y_diff; | 524 | + adjusted_first_peg_y_diff; |
529 | 525 | ||
530 | Peg *peg = new Peg(canvas(), pegId, current_go, pos); | 526 | Peg *peg = new Peg(canvas(), pegId, current_go, pos); |
531 | peg->setPegPos(pos); | 527 | peg->setPegPos(pos); |
532 | peg->setPlaced(TRUE); | 528 | peg->setPlaced(TRUE); |
533 | peg->setX(x); | 529 | peg->setX(x); |
534 | peg->setY(y); | 530 | peg->setY(y); |
535 | peg->setZ(2); | 531 | peg->setZ(2); |
536 | peg->show(); | 532 | peg->show(); |
537 | } | 533 | } |
538 | 534 | ||
539 | void MindBreakerBoard::drawBackground() | 535 | void MindBreakerBoard::drawBackground() |
540 | { | 536 | { |
541 | int i, j, x, y, x_gap, y_gap; | 537 | int i, j, x, y, x_gap, y_gap; |
542 | QPixmap background = QPixmap(canvas()->width(), canvas()->height()); | 538 | QPixmap background = QPixmap(canvas()->width(), canvas()->height()); |
543 | 539 | ||
544 | QPainter painter(&background); | 540 | QPainter painter(&background); |
545 | 541 | ||
diff --git a/noncore/games/minesweep/main.cpp b/noncore/games/minesweep/main.cpp index bd70f7c..e187be5 100644 --- a/noncore/games/minesweep/main.cpp +++ b/noncore/games/minesweep/main.cpp | |||
@@ -1,27 +1,26 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "minesweep.h" | 21 | #include "minesweep.h" |
22 | 22 | ||
23 | #include <qpe/qpeapplication.h> | ||
24 | #include <opie/oapplicationfactory.h> | 23 | #include <opie/oapplicationfactory.h> |
25 | 24 | ||
26 | OPIE_EXPORT_APP( OApplicationFactory<MineSweep> ) | 25 | OPIE_EXPORT_APP( OApplicationFactory<MineSweep> ) |
27 | 26 | ||
diff --git a/noncore/games/minesweep/minefield.cpp b/noncore/games/minesweep/minefield.cpp index 1790110..72c05b0 100644 --- a/noncore/games/minesweep/minefield.cpp +++ b/noncore/games/minesweep/minefield.cpp | |||
@@ -1,540 +1,536 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include "minefield.h" | 20 | #include "minefield.h" |
21 | 21 | ||
22 | #include <qtopia/config.h> | 22 | #include <qtopia/config.h> |
23 | #include <qtopia/qpeapplication.h> | 23 | #include <qtopia/qpeapplication.h> |
24 | 24 | ||
25 | #include <qpainter.h> | ||
26 | #include <qdrawutil.h> | ||
27 | #include <qpixmap.h> | ||
28 | #include <qimage.h> | ||
29 | #include <qtimer.h> | 25 | #include <qtimer.h> |
30 | 26 | ||
31 | #include <stdlib.h> | 27 | #include <stdlib.h> |
32 | 28 | ||
33 | static const char *pix_flag[]={ | 29 | static const char *pix_flag[]={ |
34 | "13 13 3 1", | 30 | "13 13 3 1", |
35 | "# c #000000", | 31 | "# c #000000", |
36 | "x c #ff0000", | 32 | "x c #ff0000", |
37 | ". c None", | 33 | ". c None", |
38 | ".............", | 34 | ".............", |
39 | ".............", | 35 | ".............", |
40 | ".....#xxxxxx.", | 36 | ".....#xxxxxx.", |
41 | ".....#xxxxxx.", | 37 | ".....#xxxxxx.", |
42 | ".....#xxxxxx.", | 38 | ".....#xxxxxx.", |
43 | ".....#xxxxxx.", | 39 | ".....#xxxxxx.", |
44 | ".....#.......", | 40 | ".....#.......", |
45 | ".....#.......", | 41 | ".....#.......", |
46 | ".....#.......", | 42 | ".....#.......", |
47 | ".....#.......", | 43 | ".....#.......", |
48 | "...#####.....", | 44 | "...#####.....", |
49 | "..#######....", | 45 | "..#######....", |
50 | "............."}; | 46 | "............."}; |
51 | 47 | ||
52 | static const char *pix_mine[]={ | 48 | static const char *pix_mine[]={ |
53 | "13 13 3 1", | 49 | "13 13 3 1", |
54 | "# c #000000", | 50 | "# c #000000", |
55 | ". c None", | 51 | ". c None", |
56 | "a c #ffffff", | 52 | "a c #ffffff", |
57 | "......#......", | 53 | "......#......", |
58 | "......#......", | 54 | "......#......", |
59 | "..#.#####.#..", | 55 | "..#.#####.#..", |
60 | "...#######...", | 56 | "...#######...", |
61 | "..##aa#####..", | 57 | "..##aa#####..", |
62 | "..##aa#####..", | 58 | "..##aa#####..", |
63 | "#############", | 59 | "#############", |
64 | "..#########..", | 60 | "..#########..", |
65 | "..#########..", | 61 | "..#########..", |
66 | "...#######...", | 62 | "...#######...", |
67 | "..#.#####.#..", | 63 | "..#.#####.#..", |
68 | "......#......", | 64 | "......#......", |
69 | "......#......"}; | 65 | "......#......"}; |
70 | 66 | ||
71 | 67 | ||
72 | static const int maxGrid = 28; | 68 | static const int maxGrid = 28; |
73 | static const int minGrid = 12; | 69 | static const int minGrid = 12; |
74 | 70 | ||
75 | 71 | ||
76 | 72 | ||
77 | class Mine : public Qt | 73 | class Mine : public Qt |
78 | { | 74 | { |
79 | public: | 75 | public: |
80 | enum MineState { | 76 | enum MineState { |
81 | Hidden = 0, | 77 | Hidden = 0, |
82 | Empty, | 78 | Empty, |
83 | Mined, | 79 | Mined, |
84 | Flagged, | 80 | Flagged, |
85 | #ifdef MARK_UNSURE | 81 | #ifdef MARK_UNSURE |
86 | Unsure, | 82 | Unsure, |
87 | #endif | 83 | #endif |
88 | Exploded, | 84 | Exploded, |
89 | Wrong | 85 | Wrong |
90 | }; | 86 | }; |
91 | 87 | ||
92 | Mine( MineField* ); | 88 | Mine( MineField* ); |
93 | void paint( QPainter * p, const QColorGroup & cg, const QRect & cr ); | 89 | void paint( QPainter * p, const QColorGroup & cg, const QRect & cr ); |
94 | 90 | ||
95 | QSize sizeHint() const { return QSize( maxGrid, maxGrid ); } | 91 | QSize sizeHint() const { return QSize( maxGrid, maxGrid ); } |
96 | 92 | ||
97 | void activate( bool sure = TRUE ); | 93 | void activate( bool sure = TRUE ); |
98 | void setHint( int ); | 94 | void setHint( int ); |
99 | 95 | ||
100 | void setState( MineState ); | 96 | void setState( MineState ); |
101 | MineState state() const { return st; } | 97 | MineState state() const { return st; } |
102 | 98 | ||
103 | bool isMined() const { return mined; } | 99 | bool isMined() const { return mined; } |
104 | void setMined( bool m ) { mined = m; } | 100 | void setMined( bool m ) { mined = m; } |
105 | 101 | ||
106 | static void paletteChange(); | 102 | static void paletteChange(); |
107 | 103 | ||
108 | private: | 104 | private: |
109 | bool mined; | 105 | bool mined; |
110 | int hint; | 106 | int hint; |
111 | 107 | ||
112 | MineState st; | 108 | MineState st; |
113 | MineField *field; | 109 | MineField *field; |
114 | 110 | ||
115 | static QPixmap* knownField; | 111 | static QPixmap* knownField; |
116 | static QPixmap* unknownField; | 112 | static QPixmap* unknownField; |
117 | static QPixmap* flag_pix; | 113 | static QPixmap* flag_pix; |
118 | static QPixmap* mine_pix; | 114 | static QPixmap* mine_pix; |
119 | }; | 115 | }; |
120 | 116 | ||
121 | QPixmap* Mine::knownField = 0; | 117 | QPixmap* Mine::knownField = 0; |
122 | QPixmap* Mine::unknownField = 0; | 118 | QPixmap* Mine::unknownField = 0; |
123 | QPixmap* Mine::flag_pix = 0; | 119 | QPixmap* Mine::flag_pix = 0; |
124 | QPixmap* Mine::mine_pix = 0; | 120 | QPixmap* Mine::mine_pix = 0; |
125 | 121 | ||
126 | Mine::Mine( MineField *f ) | 122 | Mine::Mine( MineField *f ) |
127 | { | 123 | { |
128 | mined = FALSE; | 124 | mined = FALSE; |
129 | st = Hidden; | 125 | st = Hidden; |
130 | hint = 0; | 126 | hint = 0; |
131 | field = f; | 127 | field = f; |
132 | } | 128 | } |
133 | 129 | ||
134 | void Mine::activate( bool sure ) | 130 | void Mine::activate( bool sure ) |
135 | { | 131 | { |
136 | if ( !sure ) { | 132 | if ( !sure ) { |
137 | switch ( st ) { | 133 | switch ( st ) { |
138 | case Hidden: | 134 | case Hidden: |
139 | setState( Flagged ); | 135 | setState( Flagged ); |
140 | break; | 136 | break; |
141 | case Flagged: | 137 | case Flagged: |
142 | #ifdef MARK_UNSURE | 138 | #ifdef MARK_UNSURE |
143 | setState( Unsure ); | 139 | setState( Unsure ); |
144 | break; | 140 | break; |
145 | case Unsure: | 141 | case Unsure: |
146 | #endif | 142 | #endif |
147 | setState( Hidden ); | 143 | setState( Hidden ); |
148 | default: | 144 | default: |
149 | break; | 145 | break; |
150 | } | 146 | } |
151 | } else if ( st == Flagged ) { | 147 | } else if ( st == Flagged ) { |
152 | return; | 148 | return; |
153 | } else { | 149 | } else { |
154 | if ( mined ) { | 150 | if ( mined ) { |
155 | setState( Exploded ); | 151 | setState( Exploded ); |
156 | } else { | 152 | } else { |
157 | setState( Empty ); | 153 | setState( Empty ); |
158 | } | 154 | } |
159 | } | 155 | } |
160 | } | 156 | } |
161 | 157 | ||
162 | void Mine::setState( MineState s ) | 158 | void Mine::setState( MineState s ) |
163 | { | 159 | { |
164 | st = s; | 160 | st = s; |
165 | } | 161 | } |
166 | 162 | ||
167 | void Mine::setHint( int h ) | 163 | void Mine::setHint( int h ) |
168 | { | 164 | { |
169 | hint = h; | 165 | hint = h; |
170 | } | 166 | } |
171 | 167 | ||
172 | void Mine::paletteChange() | 168 | void Mine::paletteChange() |
173 | { | 169 | { |
174 | delete knownField; | 170 | delete knownField; |
175 | knownField = 0; | 171 | knownField = 0; |
176 | delete unknownField; | 172 | delete unknownField; |
177 | unknownField = 0; | 173 | unknownField = 0; |
178 | delete mine_pix; | 174 | delete mine_pix; |
179 | mine_pix = 0; | 175 | mine_pix = 0; |
180 | delete flag_pix; | 176 | delete flag_pix; |
181 | flag_pix = 0; | 177 | flag_pix = 0; |
182 | } | 178 | } |
183 | 179 | ||
184 | void Mine::paint( QPainter* p, const QColorGroup &cg, const QRect& cr ) | 180 | void Mine::paint( QPainter* p, const QColorGroup &cg, const QRect& cr ) |
185 | { | 181 | { |
186 | int x = cr.x(); | 182 | int x = cr.x(); |
187 | int y = cr.y(); | 183 | int y = cr.y(); |
188 | if ( !knownField || knownField->width() != cr.width() || | 184 | if ( !knownField || knownField->width() != cr.width() || |
189 | knownField->height() != cr.height() ) { | 185 | knownField->height() != cr.height() ) { |
190 | delete knownField; | 186 | delete knownField; |
191 | knownField = new QPixmap( cr.width(), cr.height() ); | 187 | knownField = new QPixmap( cr.width(), cr.height() ); |
192 | QPainter pp( knownField ); | 188 | QPainter pp( knownField ); |
193 | QBrush br( cg.button().dark(115) ); | 189 | QBrush br( cg.button().dark(115) ); |
194 | qDrawWinButton( &pp, QRect( 0, 0, cr.width(), cr.height() ), cg, TRUE, &br ); | 190 | qDrawWinButton( &pp, QRect( 0, 0, cr.width(), cr.height() ), cg, TRUE, &br ); |
195 | } | 191 | } |
196 | 192 | ||
197 | const int pmmarg=cr.width()/5; | 193 | const int pmmarg=cr.width()/5; |
198 | 194 | ||
199 | if ( !unknownField || unknownField->width() != cr.width() || | 195 | if ( !unknownField || unknownField->width() != cr.width() || |
200 | unknownField->height() != cr.height() ) { | 196 | unknownField->height() != cr.height() ) { |
201 | delete unknownField; | 197 | delete unknownField; |
202 | unknownField = new QPixmap( cr.width(), cr.height() ); | 198 | unknownField = new QPixmap( cr.width(), cr.height() ); |
203 | QPainter pp( unknownField ); | 199 | QPainter pp( unknownField ); |
204 | QBrush br( cg.button() ); | 200 | QBrush br( cg.button() ); |
205 | qDrawWinButton( &pp, QRect( 0, 0, cr.width(), cr.height() ), cg, FALSE, &br ); | 201 | qDrawWinButton( &pp, QRect( 0, 0, cr.width(), cr.height() ), cg, FALSE, &br ); |
206 | } | 202 | } |
207 | 203 | ||
208 | if ( !flag_pix || flag_pix->width() != cr.width()-pmmarg*2 || | 204 | if ( !flag_pix || flag_pix->width() != cr.width()-pmmarg*2 || |
209 | flag_pix->height() != cr.height()-pmmarg*2 ) { | 205 | flag_pix->height() != cr.height()-pmmarg*2 ) { |
210 | delete flag_pix; | 206 | delete flag_pix; |
211 | flag_pix = new QPixmap( cr.width()-pmmarg*2, cr.height()-pmmarg*2 ); | 207 | flag_pix = new QPixmap( cr.width()-pmmarg*2, cr.height()-pmmarg*2 ); |
212 | flag_pix->convertFromImage( QImage(pix_flag).smoothScale(cr.width()-pmmarg*2, cr.height()-pmmarg*2) ); | 208 | flag_pix->convertFromImage( QImage(pix_flag).smoothScale(cr.width()-pmmarg*2, cr.height()-pmmarg*2) ); |
213 | } | 209 | } |
214 | 210 | ||
215 | if ( !mine_pix || mine_pix->width() != cr.width()-pmmarg*2 || | 211 | if ( !mine_pix || mine_pix->width() != cr.width()-pmmarg*2 || |
216 | mine_pix->height() != cr.height()-pmmarg*2 ) { | 212 | mine_pix->height() != cr.height()-pmmarg*2 ) { |
217 | delete mine_pix; | 213 | delete mine_pix; |
218 | mine_pix = new QPixmap( cr.width()-pmmarg*2, cr.height()-pmmarg*2 ); | 214 | mine_pix = new QPixmap( cr.width()-pmmarg*2, cr.height()-pmmarg*2 ); |
219 | mine_pix->convertFromImage( QImage(pix_mine).smoothScale(cr.width()-pmmarg*2, cr.height()-pmmarg*2) ); | 215 | mine_pix->convertFromImage( QImage(pix_mine).smoothScale(cr.width()-pmmarg*2, cr.height()-pmmarg*2) ); |
220 | } | 216 | } |
221 | 217 | ||
222 | p->save(); | 218 | p->save(); |
223 | 219 | ||
224 | switch(st) { | 220 | switch(st) { |
225 | case Hidden: | 221 | case Hidden: |
226 | p->drawPixmap( x, y, *unknownField ); | 222 | p->drawPixmap( x, y, *unknownField ); |
227 | break; | 223 | break; |
228 | case Empty: | 224 | case Empty: |
229 | p->drawPixmap( x, y, *knownField ); | 225 | p->drawPixmap( x, y, *knownField ); |
230 | if ( hint > 0 ) { | 226 | if ( hint > 0 ) { |
231 | switch( hint ) { | 227 | switch( hint ) { |
232 | case 1: | 228 | case 1: |
233 | p->setPen( blue ); | 229 | p->setPen( blue ); |
234 | break; | 230 | break; |
235 | case 2: | 231 | case 2: |
236 | p->setPen( green.dark() ); | 232 | p->setPen( green.dark() ); |
237 | break; | 233 | break; |
238 | case 3: | 234 | case 3: |
239 | p->setPen( red ); | 235 | p->setPen( red ); |
240 | break; | 236 | break; |
241 | case 4: | 237 | case 4: |
242 | p->setPen( darkYellow.dark() ); | 238 | p->setPen( darkYellow.dark() ); |
243 | break; | 239 | break; |
244 | case 5: | 240 | case 5: |
245 | p->setPen( darkMagenta ); | 241 | p->setPen( darkMagenta ); |
246 | break; | 242 | break; |
247 | case 6: | 243 | case 6: |
248 | p->setPen( darkRed ); | 244 | p->setPen( darkRed ); |
249 | break; | 245 | break; |
250 | default: | 246 | default: |
251 | p->setPen( black ); | 247 | p->setPen( black ); |
252 | break; | 248 | break; |
253 | } | 249 | } |
254 | p->drawText( cr, AlignHCenter | AlignVCenter, QString::number( hint ) ); | 250 | p->drawText( cr, AlignHCenter | AlignVCenter, QString::number( hint ) ); |
255 | } | 251 | } |
256 | break; | 252 | break; |
257 | case Mined: | 253 | case Mined: |
258 | p->drawPixmap( x, y, *knownField ); | 254 | p->drawPixmap( x, y, *knownField ); |
259 | p->drawPixmap( x+pmmarg, y+pmmarg, *mine_pix ); | 255 | p->drawPixmap( x+pmmarg, y+pmmarg, *mine_pix ); |
260 | break; | 256 | break; |
261 | case Exploded: | 257 | case Exploded: |
262 | p->drawPixmap( x, y, *knownField ); | 258 | p->drawPixmap( x, y, *knownField ); |
263 | p->drawPixmap( x+pmmarg, y+pmmarg, *mine_pix ); | 259 | p->drawPixmap( x+pmmarg, y+pmmarg, *mine_pix ); |
264 | p->setPen( red ); | 260 | p->setPen( red ); |
265 | p->drawText( cr, AlignHCenter | AlignVCenter, "X" ); | 261 | p->drawText( cr, AlignHCenter | AlignVCenter, "X" ); |
266 | break; | 262 | break; |
267 | case Flagged: | 263 | case Flagged: |
268 | p->drawPixmap( x, y, *unknownField ); | 264 | p->drawPixmap( x, y, *unknownField ); |
269 | p->drawPixmap( x+pmmarg, y+pmmarg, *flag_pix ); | 265 | p->drawPixmap( x+pmmarg, y+pmmarg, *flag_pix ); |
270 | break; | 266 | break; |
271 | #ifdef MARK_UNSURE | 267 | #ifdef MARK_UNSURE |
272 | case Unsure: | 268 | case Unsure: |
273 | p->drawPixmap( x, y, *unknownField ); | 269 | p->drawPixmap( x, y, *unknownField ); |
274 | p->drawText( cr, AlignHCenter | AlignVCenter, "?" ); | 270 | p->drawText( cr, AlignHCenter | AlignVCenter, "?" ); |
275 | break; | 271 | break; |
276 | #endif | 272 | #endif |
277 | case Wrong: | 273 | case Wrong: |
278 | p->drawPixmap( x, y, *unknownField ); | 274 | p->drawPixmap( x, y, *unknownField ); |
279 | p->drawPixmap( x+pmmarg, y+pmmarg, *flag_pix ); | 275 | p->drawPixmap( x+pmmarg, y+pmmarg, *flag_pix ); |
280 | p->setPen( red ); | 276 | p->setPen( red ); |
281 | p->drawText( cr, AlignHCenter | AlignVCenter, "X" ); | 277 | p->drawText( cr, AlignHCenter | AlignVCenter, "X" ); |
282 | break; | 278 | break; |
283 | } | 279 | } |
284 | 280 | ||
285 | p->restore(); | 281 | p->restore(); |
286 | } | 282 | } |
287 | 283 | ||
288 | /* | 284 | /* |
289 | MineField implementation | 285 | MineField implementation |
290 | */ | 286 | */ |
291 | 287 | ||
292 | MineField::MineField( QWidget* parent, const char* name ) | 288 | MineField::MineField( QWidget* parent, const char* name ) |
293 | : QScrollView( parent, name ) | 289 | : QScrollView( parent, name ) |
294 | { | 290 | { |
295 | viewport()->setBackgroundMode( NoBackground ); | 291 | viewport()->setBackgroundMode( NoBackground ); |
296 | setState( GameOver ); | 292 | setState( GameOver ); |
297 | 293 | ||
298 | setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum ) ); | 294 | setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum ) ); |
299 | 295 | ||
300 | setFocusPolicy( QWidget::NoFocus ); | 296 | setFocusPolicy( QWidget::NoFocus ); |
301 | 297 | ||
302 | holdTimer = new QTimer( this ); | 298 | holdTimer = new QTimer( this ); |
303 | connect( holdTimer, SIGNAL( timeout() ), this, SLOT( held() ) ); | 299 | connect( holdTimer, SIGNAL( timeout() ), this, SLOT( held() ) ); |
304 | 300 | ||
305 | flagAction = NoAction; | 301 | flagAction = NoAction; |
306 | ignoreClick = FALSE; | 302 | ignoreClick = FALSE; |
307 | currRow = currCol = -1; | 303 | currRow = currCol = -1; |
308 | minecount=0; | 304 | minecount=0; |
309 | mineguess=0; | 305 | mineguess=0; |
310 | nonminecount=0; | 306 | nonminecount=0; |
311 | cellSize = -1; | 307 | cellSize = -1; |
312 | 308 | ||
313 | numRows = numCols = 0; | 309 | numRows = numCols = 0; |
314 | mines = NULL; | 310 | mines = NULL; |
315 | } | 311 | } |
316 | 312 | ||
317 | MineField::~MineField() | 313 | MineField::~MineField() |
318 | { | 314 | { |
319 | for ( int i = 0; i < numCols*numRows; i++ ) | 315 | for ( int i = 0; i < numCols*numRows; i++ ) |
320 | delete mines[i]; | 316 | delete mines[i]; |
321 | delete[] mines; | 317 | delete[] mines; |
322 | } | 318 | } |
323 | 319 | ||
324 | void MineField::setState( State st ) | 320 | void MineField::setState( State st ) |
325 | { | 321 | { |
326 | stat = st; | 322 | stat = st; |
327 | } | 323 | } |
328 | 324 | ||
329 | void MineField::setup( int level ) | 325 | void MineField::setup( int level ) |
330 | { | 326 | { |
331 | lev = level; | 327 | lev = level; |
332 | setState( Waiting ); | 328 | setState( Waiting ); |
333 | //viewport()->setUpdatesEnabled( FALSE ); | 329 | //viewport()->setUpdatesEnabled( FALSE ); |
334 | 330 | ||
335 | int i; | 331 | int i; |
336 | for ( i = 0; i < numCols*numRows; i++ ) | 332 | for ( i = 0; i < numCols*numRows; i++ ) |
337 | delete mines[i]; | 333 | delete mines[i]; |
338 | delete[] mines; | 334 | delete[] mines; |
339 | 335 | ||
340 | switch( lev ) { | 336 | switch( lev ) { |
341 | case 1: | 337 | case 1: |
342 | numRows = 9 ; | 338 | numRows = 9 ; |
343 | numCols = 9 ; | 339 | numCols = 9 ; |
344 | minecount = 12; | 340 | minecount = 12; |
345 | break; | 341 | break; |
346 | case 2: | 342 | case 2: |
347 | numRows = 13; | 343 | numRows = 13; |
348 | numCols = 13; | 344 | numCols = 13; |
349 | minecount = 33; | 345 | minecount = 33; |
350 | break; | 346 | break; |
351 | case 3: | 347 | case 3: |
352 | numCols = 18; | 348 | numCols = 18; |
353 | numRows = 18; | 349 | numRows = 18; |
354 | minecount = 66 ; | 350 | minecount = 66 ; |
355 | break; | 351 | break; |
356 | } | 352 | } |
357 | mines = new Mine* [numRows*numCols]; | 353 | mines = new Mine* [numRows*numCols]; |
358 | for ( i = 0; i < numCols*numRows; i++ ) | 354 | for ( i = 0; i < numCols*numRows; i++ ) |
359 | mines[i] = new Mine( this ); | 355 | mines[i] = new Mine( this ); |
360 | 356 | ||
361 | 357 | ||
362 | nonminecount = numRows*numCols - minecount; | 358 | nonminecount = numRows*numCols - minecount; |
363 | mineguess = minecount; | 359 | mineguess = minecount; |
364 | emit mineCount( mineguess ); | 360 | emit mineCount( mineguess ); |
365 | Mine::paletteChange(); | 361 | Mine::paletteChange(); |
366 | 362 | ||
367 | if ( availableRect.isValid() ) | 363 | if ( availableRect.isValid() ) |
368 | setCellSize(findCellSize()); | 364 | setCellSize(findCellSize()); |
369 | // viewport()->setUpdatesEnabled( TRUE ); | 365 | // viewport()->setUpdatesEnabled( TRUE ); |
370 | //viewport()->repaint( TRUE ); | 366 | //viewport()->repaint( TRUE ); |
371 | updateContents( 0, 0, numCols*cellSize, numRows*cellSize ); | 367 | updateContents( 0, 0, numCols*cellSize, numRows*cellSize ); |
372 | updateGeometry(); | 368 | updateGeometry(); |
373 | } | 369 | } |
374 | 370 | ||
375 | void MineField::drawContents( QPainter * p, int clipx, int clipy, int clipw, int cliph ) | 371 | void MineField::drawContents( QPainter * p, int clipx, int clipy, int clipw, int cliph ) |
376 | { | 372 | { |
377 | int c1 = clipx / cellSize; | 373 | int c1 = clipx / cellSize; |
378 | int c2 = ( clipx + clipw - 1 ) / cellSize; | 374 | int c2 = ( clipx + clipw - 1 ) / cellSize; |
379 | int r1 = clipy / cellSize; | 375 | int r1 = clipy / cellSize; |
380 | int r2 = ( clipy + cliph - 1 ) / cellSize; | 376 | int r2 = ( clipy + cliph - 1 ) / cellSize; |
381 | 377 | ||
382 | for ( int c = c1; c <= c2 ; c++ ) { | 378 | for ( int c = c1; c <= c2 ; c++ ) { |
383 | for ( int r = r1; r <= r2 ; r++ ) { | 379 | for ( int r = r1; r <= r2 ; r++ ) { |
384 | int x = c * cellSize; | 380 | int x = c * cellSize; |
385 | int y = r * cellSize; | 381 | int y = r * cellSize; |
386 | Mine *m = mine( r, c ); | 382 | Mine *m = mine( r, c ); |
387 | if ( m ) | 383 | if ( m ) |
388 | m->paint( p, colorGroup(), QRect(x, y, cellSize, cellSize ) ); | 384 | m->paint( p, colorGroup(), QRect(x, y, cellSize, cellSize ) ); |
389 | } | 385 | } |
390 | } | 386 | } |
391 | } | 387 | } |
392 | 388 | ||
393 | 389 | ||
394 | // Chicken and egg problem: We need to know how big the parent is | 390 | // Chicken and egg problem: We need to know how big the parent is |
395 | // before we can decide how big to make the table. | 391 | // before we can decide how big to make the table. |
396 | 392 | ||
397 | void MineField::setAvailableRect( const QRect &r ) | 393 | void MineField::setAvailableRect( const QRect &r ) |
398 | { | 394 | { |
399 | availableRect = r; | 395 | availableRect = r; |
400 | int newCellSize = findCellSize(); | 396 | int newCellSize = findCellSize(); |
401 | 397 | ||
402 | 398 | ||
403 | if ( newCellSize == cellSize ) { | 399 | if ( newCellSize == cellSize ) { |
404 | setCellSize( cellSize ); | 400 | setCellSize( cellSize ); |
405 | } else { | 401 | } else { |
406 | viewport()->setUpdatesEnabled( FALSE ); | 402 | viewport()->setUpdatesEnabled( FALSE ); |
407 | setCellSize( newCellSize ); | 403 | setCellSize( newCellSize ); |
408 | viewport()->setUpdatesEnabled( TRUE ); | 404 | viewport()->setUpdatesEnabled( TRUE ); |
409 | viewport()->repaint( TRUE ); | 405 | viewport()->repaint( TRUE ); |
410 | } | 406 | } |
411 | } | 407 | } |
412 | 408 | ||
413 | int MineField::findCellSize() | 409 | int MineField::findCellSize() |
414 | { | 410 | { |
415 | int w = availableRect.width() - 2; | 411 | int w = availableRect.width() - 2; |
416 | int h = availableRect.height() - 2; | 412 | int h = availableRect.height() - 2; |
417 | int cellsize; | 413 | int cellsize; |
418 | 414 | ||
419 | cellsize = QMIN( w/numCols, h/numRows ); | 415 | cellsize = QMIN( w/numCols, h/numRows ); |
420 | cellsize = QMIN( QMAX( cellsize, minGrid ), maxGrid ); | 416 | cellsize = QMIN( QMAX( cellsize, minGrid ), maxGrid ); |
421 | return cellsize; | 417 | return cellsize; |
422 | } | 418 | } |
423 | 419 | ||
424 | 420 | ||
425 | void MineField::setCellSize( int cellsize ) | 421 | void MineField::setCellSize( int cellsize ) |
426 | { | 422 | { |
427 | int b = 2; | 423 | int b = 2; |
428 | 424 | ||
429 | int w2 = cellsize*numCols; | 425 | int w2 = cellsize*numCols; |
430 | int h2 = cellsize*numRows; | 426 | int h2 = cellsize*numRows; |
431 | 427 | ||
432 | int w = QMIN( availableRect.width(), w2+b ); | 428 | int w = QMIN( availableRect.width(), w2+b ); |
433 | int h = QMIN( availableRect.height(), h2+b ); | 429 | int h = QMIN( availableRect.height(), h2+b ); |
434 | 430 | ||
435 | // | 431 | // |
436 | // Don't rely on the change in cellsize to force a resize, | 432 | // Don't rely on the change in cellsize to force a resize, |
437 | // as it's possible to have the same size cells when going | 433 | // as it's possible to have the same size cells when going |
438 | // from a large play area to a small one. | 434 | // from a large play area to a small one. |
439 | // | 435 | // |
440 | resizeContents(w2, h2); | 436 | resizeContents(w2, h2); |
441 | 437 | ||
442 | if ( availableRect.height() < h2 && | 438 | if ( availableRect.height() < h2 && |
443 | availableRect.width() - w > style().scrollBarExtent().width() ) { | 439 | availableRect.width() - w > style().scrollBarExtent().width() ) { |
444 | w += style().scrollBarExtent().width(); | 440 | w += style().scrollBarExtent().width(); |
445 | } | 441 | } |
446 | 442 | ||
447 | setGeometry( availableRect.x() + (availableRect.width()-w)/2, | 443 | setGeometry( availableRect.x() + (availableRect.width()-w)/2, |
448 | availableRect.y() + (availableRect.height()-h)/2, w, h ); | 444 | availableRect.y() + (availableRect.height()-h)/2, w, h ); |
449 | cellSize = cellsize; | 445 | cellSize = cellsize; |
450 | } | 446 | } |
451 | 447 | ||
452 | 448 | ||
453 | void MineField::placeMines() | 449 | void MineField::placeMines() |
454 | { | 450 | { |
455 | int mines = minecount; | 451 | int mines = minecount; |
456 | while ( mines ) { | 452 | while ( mines ) { |
457 | int col = int((double(rand()) / double(RAND_MAX)) * numCols); | 453 | int col = int((double(rand()) / double(RAND_MAX)) * numCols); |
458 | int row = int((double(rand()) / double(RAND_MAX)) * numRows); | 454 | int row = int((double(rand()) / double(RAND_MAX)) * numRows); |
459 | 455 | ||
460 | Mine* m = mine( row, col ); | 456 | Mine* m = mine( row, col ); |
461 | 457 | ||
462 | if ( m && !m->isMined() && m->state() == Mine::Hidden ) { | 458 | if ( m && !m->isMined() && m->state() == Mine::Hidden ) { |
463 | m->setMined( TRUE ); | 459 | m->setMined( TRUE ); |
464 | mines--; | 460 | mines--; |
465 | } | 461 | } |
466 | } | 462 | } |
467 | } | 463 | } |
468 | 464 | ||
469 | 465 | ||
470 | void MineField::updateCell( int r, int c ) | 466 | void MineField::updateCell( int r, int c ) |
471 | { | 467 | { |
472 | updateContents( c*cellSize, r*cellSize, cellSize, cellSize ); | 468 | updateContents( c*cellSize, r*cellSize, cellSize, cellSize ); |
473 | } | 469 | } |
474 | 470 | ||
475 | 471 | ||
476 | void MineField::contentsMousePressEvent( QMouseEvent* e ) | 472 | void MineField::contentsMousePressEvent( QMouseEvent* e ) |
477 | { | 473 | { |
478 | int c = e->pos().x() / cellSize; | 474 | int c = e->pos().x() / cellSize; |
479 | int r = e->pos().y() / cellSize; | 475 | int r = e->pos().y() / cellSize; |
480 | if ( onBoard( r, c ) ) | 476 | if ( onBoard( r, c ) ) |
481 | cellPressed( r, c ); | 477 | cellPressed( r, c ); |
482 | else | 478 | else |
483 | currCol = currRow = -1; | 479 | currCol = currRow = -1; |
484 | } | 480 | } |
485 | 481 | ||
486 | void MineField::contentsMouseReleaseEvent( QMouseEvent* e ) | 482 | void MineField::contentsMouseReleaseEvent( QMouseEvent* e ) |
487 | { | 483 | { |
488 | int c = e->pos().x() / cellSize; | 484 | int c = e->pos().x() / cellSize; |
489 | int r = e->pos().y() / cellSize; | 485 | int r = e->pos().y() / cellSize; |
490 | if ( onBoard( r, c ) && c == currCol && r == currRow ) | 486 | if ( onBoard( r, c ) && c == currCol && r == currRow ) |
491 | cellClicked( r, c ); | 487 | cellClicked( r, c ); |
492 | 488 | ||
493 | 489 | ||
494 | if ( flagAction == FlagNext ) { | 490 | if ( flagAction == FlagNext ) { |
495 | flagAction = NoAction; | 491 | flagAction = NoAction; |
496 | } | 492 | } |
497 | } | 493 | } |
498 | 494 | ||
499 | 495 | ||
500 | 496 | ||
501 | /* | 497 | /* |
502 | state == Waiting means no "hold" | 498 | state == Waiting means no "hold" |
503 | 499 | ||
504 | 500 | ||
505 | */ | 501 | */ |
506 | void MineField::cellPressed( int row, int col ) | 502 | void MineField::cellPressed( int row, int col ) |
507 | { | 503 | { |
508 | if ( state() == GameOver ) | 504 | if ( state() == GameOver ) |
509 | return; | 505 | return; |
510 | currRow = row; | 506 | currRow = row; |
511 | currCol = col; | 507 | currCol = col; |
512 | if ( state() == Playing ) | 508 | if ( state() == Playing ) |
513 | holdTimer->start( 150, TRUE ); | 509 | holdTimer->start( 150, TRUE ); |
514 | } | 510 | } |
515 | 511 | ||
516 | void MineField::held() | 512 | void MineField::held() |
517 | { | 513 | { |
518 | flagAction = FlagNext; | 514 | flagAction = FlagNext; |
519 | updateMine( currRow, currCol ); | 515 | updateMine( currRow, currCol ); |
520 | ignoreClick = TRUE; | 516 | ignoreClick = TRUE; |
521 | } | 517 | } |
522 | 518 | ||
523 | 519 | ||
524 | 520 | ||
525 | 521 | ||
526 | void MineField::keyPressEvent( QKeyEvent* e ) | 522 | void MineField::keyPressEvent( QKeyEvent* e ) |
527 | { | 523 | { |
528 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 524 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
529 | flagAction = ( e->key() == Key_Up ) ? FlagOn : NoAction; | 525 | flagAction = ( e->key() == Key_Up ) ? FlagOn : NoAction; |
530 | #else | 526 | #else |
531 | flagAction = ( ( e->state() & ShiftButton ) == ShiftButton ) ? FlagOn : NoAction; | 527 | flagAction = ( ( e->state() & ShiftButton ) == ShiftButton ) ? FlagOn : NoAction; |
532 | #endif | 528 | #endif |
533 | } | 529 | } |
534 | 530 | ||
535 | void MineField::keyReleaseEvent( QKeyEvent* ) | 531 | void MineField::keyReleaseEvent( QKeyEvent* ) |
536 | { | 532 | { |
537 | flagAction = NoAction; | 533 | flagAction = NoAction; |
538 | } | 534 | } |
539 | 535 | ||
540 | int MineField::getHint( int row, int col ) | 536 | int MineField::getHint( int row, int col ) |
diff --git a/noncore/games/minesweep/minesweep.cpp b/noncore/games/minesweep/minesweep.cpp index d707dab..4a6a92c 100644 --- a/noncore/games/minesweep/minesweep.cpp +++ b/noncore/games/minesweep/minesweep.cpp | |||
@@ -1,413 +1,408 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "minesweep.h" | 21 | #include "minesweep.h" |
22 | #include "minefield.h" | 22 | #include "minefield.h" |
23 | 23 | ||
24 | #include <qtopia/qpeapplication.h> | 24 | #include <qtopia/qpeapplication.h> |
25 | #include <qtopia/resource.h> | 25 | #include <qtopia/resource.h> |
26 | #include <qtopia/config.h> | 26 | #include <qtopia/config.h> |
27 | 27 | ||
28 | #include <qtoolbar.h> | 28 | #include <qtoolbar.h> |
29 | #include <qmenubar.h> | 29 | #include <qmenubar.h> |
30 | #include <qpopupmenu.h> | ||
31 | #include <qpushbutton.h> | 30 | #include <qpushbutton.h> |
32 | #include <qlcdnumber.h> | 31 | #include <qlcdnumber.h> |
33 | #include <qmessagebox.h> | ||
34 | #include <qtimer.h> | 32 | #include <qtimer.h> |
35 | #include <qpalette.h> | ||
36 | #include <qapplication.h> | ||
37 | #include <qlayout.h> | ||
38 | #include <qlabel.h> | 33 | #include <qlabel.h> |
39 | 34 | ||
40 | #include <stdlib.h> | 35 | #include <stdlib.h> |
41 | #include <time.h> | 36 | #include <time.h> |
42 | 37 | ||
43 | 38 | ||
44 | 39 | ||
45 | 40 | ||
46 | static const char *pix_new[]={ | 41 | static const char *pix_new[]={ |
47 | "20 20 3 1", | 42 | "20 20 3 1", |
48 | " c None", | 43 | " c None", |
49 | "# c #00FF00", | 44 | "# c #00FF00", |
50 | ". c #000000", | 45 | ". c #000000", |
51 | " ", | 46 | " ", |
52 | " ...... ", | 47 | " ...... ", |
53 | " ..######.. ", | 48 | " ..######.. ", |
54 | " .##########. ", | 49 | " .##########. ", |
55 | " .############. ", | 50 | " .############. ", |
56 | " .##############. ", | 51 | " .##############. ", |
57 | " .##############. ", | 52 | " .##############. ", |
58 | " .################. ", | 53 | " .################. ", |
59 | " .################. ", | 54 | " .################. ", |
60 | " .################. ", | 55 | " .################. ", |
61 | " .################. ", | 56 | " .################. ", |
62 | " .################. ", | 57 | " .################. ", |
63 | " .################. ", | 58 | " .################. ", |
64 | " .##############. ", | 59 | " .##############. ", |
65 | " .##############. ", | 60 | " .##############. ", |
66 | " .############. ", | 61 | " .############. ", |
67 | " .##########. ", | 62 | " .##########. ", |
68 | " ..######.. ", | 63 | " ..######.. ", |
69 | " ...... ", | 64 | " ...... ", |
70 | " "}; | 65 | " "}; |
71 | 66 | ||
72 | 67 | ||
73 | /* XPM */ | 68 | /* XPM */ |
74 | static const char * happy_xpm[] = { | 69 | static const char * happy_xpm[] = { |
75 | "20 20 3 1", | 70 | "20 20 3 1", |
76 | " c None", | 71 | " c None", |
77 | ".c #ffff3f ", | 72 | ".c #ffff3f ", |
78 | "#c #000000", | 73 | "#c #000000", |
79 | " ", | 74 | " ", |
80 | " ###### ", | 75 | " ###### ", |
81 | " ##......## ", | 76 | " ##......## ", |
82 | " #..........# ", | 77 | " #..........# ", |
83 | " #............# ", | 78 | " #............# ", |
84 | " #..............# ", | 79 | " #..............# ", |
85 | " #..............# ", | 80 | " #..............# ", |
86 | " #....##....##....# ", | 81 | " #....##....##....# ", |
87 | " #....##....##....# ", | 82 | " #....##....##....# ", |
88 | " #................# ", | 83 | " #................# ", |
89 | " #................# ", | 84 | " #................# ", |
90 | " #................# ", | 85 | " #................# ", |
91 | " #...#........#...# ", | 86 | " #...#........#...# ", |
92 | " #.##........##.# ", | 87 | " #.##........##.# ", |
93 | " #...########...# ", | 88 | " #...########...# ", |
94 | " #...######...# ", | 89 | " #...######...# ", |
95 | " #..........# ", | 90 | " #..........# ", |
96 | " ##......## ", | 91 | " ##......## ", |
97 | " ###### ", | 92 | " ###### ", |
98 | " "}; | 93 | " "}; |
99 | 94 | ||
100 | 95 | ||
101 | /* XPM */ | 96 | /* XPM */ |
102 | static const char * worried_xpm[] = { | 97 | static const char * worried_xpm[] = { |
103 | "20 20 3 1", | 98 | "20 20 3 1", |
104 | " c None", | 99 | " c None", |
105 | ".c #ffff3f", | 100 | ".c #ffff3f", |
106 | "#c #000000", | 101 | "#c #000000", |
107 | " ", | 102 | " ", |
108 | " ###### ", | 103 | " ###### ", |
109 | " ##......## ", | 104 | " ##......## ", |
110 | " #..........# ", | 105 | " #..........# ", |
111 | " #............# ", | 106 | " #............# ", |
112 | " #..............# ", | 107 | " #..............# ", |
113 | " #..............# ", | 108 | " #..............# ", |
114 | " #....##....##....# ", | 109 | " #....##....##....# ", |
115 | " #....##....##....# ", | 110 | " #....##....##....# ", |
116 | " #................# ", | 111 | " #................# ", |
117 | " #................# ", | 112 | " #................# ", |
118 | " #................# ", | 113 | " #................# ", |
119 | " #................# ", | 114 | " #................# ", |
120 | " #....######....# ", | 115 | " #....######....# ", |
121 | " #..............# ", | 116 | " #..............# ", |
122 | " #............# ", | 117 | " #............# ", |
123 | " #..........# ", | 118 | " #..........# ", |
124 | " ##......## ", | 119 | " ##......## ", |
125 | " ###### ", | 120 | " ###### ", |
126 | " "}; | 121 | " "}; |
127 | 122 | ||
128 | 123 | ||
129 | /* XPM */ | 124 | /* XPM */ |
130 | static const char * dead_xpm[] = { | 125 | static const char * dead_xpm[] = { |
131 | "20 20 3 1", | 126 | "20 20 3 1", |
132 | " c None", | 127 | " c None", |
133 | ".c #ffff3f", | 128 | ".c #ffff3f", |
134 | "#c #000000", | 129 | "#c #000000", |
135 | " ", | 130 | " ", |
136 | " ###### ", | 131 | " ###### ", |
137 | " ##......## ", | 132 | " ##......## ", |
138 | " #..........# ", | 133 | " #..........# ", |
139 | " #............# ", | 134 | " #............# ", |
140 | " #..............# ", | 135 | " #..............# ", |
141 | " #..#.#...#.#...# ", | 136 | " #..#.#...#.#...# ", |
142 | " #....#.....#.....# ", | 137 | " #....#.....#.....# ", |
143 | " #...#.#...#.#....# ", | 138 | " #...#.#...#.#....# ", |
144 | " #................# ", | 139 | " #................# ", |
145 | " #................# ", | 140 | " #................# ", |
146 | " #................# ", | 141 | " #................# ", |
147 | " #......####......# ", | 142 | " #......####......# ", |
148 | " #....# #....# ", | 143 | " #....# #....# ", |
149 | " #...#......#...# ", | 144 | " #...#......#...# ", |
150 | " #............# ", | 145 | " #............# ", |
151 | " #..........# ", | 146 | " #..........# ", |
152 | " ##......## ", | 147 | " ##......## ", |
153 | " ###### ", | 148 | " ###### ", |
154 | " "}; | 149 | " "}; |
155 | 150 | ||
156 | 151 | ||
157 | class ResultIndicator : private QLabel | 152 | class ResultIndicator : private QLabel |
158 | { | 153 | { |
159 | public: | 154 | public: |
160 | static void showResult( QWidget *ref, bool won ); | 155 | static void showResult( QWidget *ref, bool won ); |
161 | private: | 156 | private: |
162 | ResultIndicator( QWidget *parent, const char *name, WFlags f) | 157 | ResultIndicator( QWidget *parent, const char *name, WFlags f) |
163 | :QLabel( parent, name, f ) {} | 158 | :QLabel( parent, name, f ) {} |
164 | 159 | ||
165 | void timerEvent( QTimerEvent *); | 160 | void timerEvent( QTimerEvent *); |
166 | void center(); | 161 | void center(); |
167 | bool twoStage; | 162 | bool twoStage; |
168 | int timerId; | 163 | int timerId; |
169 | }; | 164 | }; |
170 | 165 | ||
171 | void ResultIndicator::showResult( QWidget *ref, bool won ) | 166 | void ResultIndicator::showResult( QWidget *ref, bool won ) |
172 | { | 167 | { |
173 | ResultIndicator *r = new ResultIndicator( ref, 0, WStyle_Customize | WStyle_Tool | WType_TopLevel ); | 168 | ResultIndicator *r = new ResultIndicator( ref, 0, WStyle_Customize | WStyle_Tool | WType_TopLevel ); |
174 | 169 | ||
175 | r->setAlignment( AlignCenter ); | 170 | r->setAlignment( AlignCenter ); |
176 | r->setFrameStyle( Sunken|StyledPanel ); | 171 | r->setFrameStyle( Sunken|StyledPanel ); |
177 | if ( won ) { | 172 | if ( won ) { |
178 | r->setText( MineSweep::tr("You won!") ); | 173 | r->setText( MineSweep::tr("You won!") ); |
179 | r->center(); | 174 | r->center(); |
180 | r->show(); | 175 | r->show(); |
181 | r->twoStage = FALSE; | 176 | r->twoStage = FALSE; |
182 | r->timerId = r->startTimer(1500); | 177 | r->timerId = r->startTimer(1500); |
183 | } else { | 178 | } else { |
184 | QPalette p( red ); | 179 | QPalette p( red ); |
185 | r->setPalette( p ); | 180 | r->setPalette( p ); |
186 | r->setText( MineSweep::tr("You exploded!") ); | 181 | r->setText( MineSweep::tr("You exploded!") ); |
187 | r->resize( ref->size() ); | 182 | r->resize( ref->size() ); |
188 | r->move( ref->mapToGlobal(QPoint(0,0)) ); | 183 | r->move( ref->mapToGlobal(QPoint(0,0)) ); |
189 | r->show(); | 184 | r->show(); |
190 | r->twoStage = TRUE; | 185 | r->twoStage = TRUE; |
191 | r->timerId =r->startTimer(200); | 186 | r->timerId =r->startTimer(200); |
192 | } | 187 | } |
193 | } | 188 | } |
194 | 189 | ||
195 | void ResultIndicator::center() | 190 | void ResultIndicator::center() |
196 | { | 191 | { |
197 | QWidget *w = parentWidget(); | 192 | QWidget *w = parentWidget(); |
198 | 193 | ||
199 | QPoint pp = w->mapToGlobal( QPoint(0,0) ); | 194 | QPoint pp = w->mapToGlobal( QPoint(0,0) ); |
200 | QSize s = sizeHint()*3; | 195 | QSize s = sizeHint()*3; |
201 | s.setWidth( QMIN(s.width(), w->width()) ); | 196 | s.setWidth( QMIN(s.width(), w->width()) ); |
202 | pp = QPoint( pp.x() + w->width()/2 - s.width()/2, | 197 | pp = QPoint( pp.x() + w->width()/2 - s.width()/2, |
203 | pp.y() + w->height()/ 2 - s.height()/2 ); | 198 | pp.y() + w->height()/ 2 - s.height()/2 ); |
204 | 199 | ||
205 | setGeometry( QRect(pp, s) ); | 200 | setGeometry( QRect(pp, s) ); |
206 | 201 | ||
207 | } | 202 | } |
208 | 203 | ||
209 | void ResultIndicator::timerEvent( QTimerEvent *te ) | 204 | void ResultIndicator::timerEvent( QTimerEvent *te ) |
210 | { | 205 | { |
211 | if ( te->timerId() != timerId ) | 206 | if ( te->timerId() != timerId ) |
212 | return; | 207 | return; |
213 | killTimer( timerId ); | 208 | killTimer( timerId ); |
214 | if ( twoStage ) { | 209 | if ( twoStage ) { |
215 | center(); | 210 | center(); |
216 | twoStage = FALSE; | 211 | twoStage = FALSE; |
217 | timerId = startTimer( 1000 ); | 212 | timerId = startTimer( 1000 ); |
218 | } else { | 213 | } else { |
219 | delete this; | 214 | delete this; |
220 | } | 215 | } |
221 | } | 216 | } |
222 | 217 | ||
223 | 218 | ||
224 | class MineFrame : public QFrame | 219 | class MineFrame : public QFrame |
225 | { | 220 | { |
226 | public: | 221 | public: |
227 | MineFrame( QWidget *parent, const char *name = 0 ) | 222 | MineFrame( QWidget *parent, const char *name = 0 ) |
228 | :QFrame( parent, name ), field(0) {} | 223 | :QFrame( parent, name ), field(0) {} |
229 | void setField( MineField *f ) { | 224 | void setField( MineField *f ) { |
230 | field = f; | 225 | field = f; |
231 | setMinimumSize( field->sizeHint() ); | 226 | setMinimumSize( field->sizeHint() ); |
232 | } | 227 | } |
233 | protected: | 228 | protected: |
234 | void resizeEvent( QResizeEvent *e ) { | 229 | void resizeEvent( QResizeEvent *e ) { |
235 | field->setAvailableRect( contentsRect()); | 230 | field->setAvailableRect( contentsRect()); |
236 | QFrame::resizeEvent(e); | 231 | QFrame::resizeEvent(e); |
237 | } | 232 | } |
238 | private: | 233 | private: |
239 | MineField *field; | 234 | MineField *field; |
240 | }; | 235 | }; |
241 | 236 | ||
242 | 237 | ||
243 | 238 | ||
244 | MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f ) | 239 | MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f ) |
245 | : QMainWindow( parent, name, f ) | 240 | : QMainWindow( parent, name, f ) |
246 | { | 241 | { |
247 | srand(::time(0)); | 242 | srand(::time(0)); |
248 | setCaption( tr("Mine Hunt") ); | 243 | setCaption( tr("Mine Hunt") ); |
249 | QPEApplication::setInputMethodHint(this, QPEApplication::AlwaysOff ); | 244 | QPEApplication::setInputMethodHint(this, QPEApplication::AlwaysOff ); |
250 | setIcon( Resource::loadPixmap( "minesweep/MineHunt" ) ); | 245 | setIcon( Resource::loadPixmap( "minesweep/MineHunt" ) ); |
251 | 246 | ||
252 | QToolBar *toolBar = new QToolBar( this ); | 247 | QToolBar *toolBar = new QToolBar( this ); |
253 | toolBar->setHorizontalStretchable( TRUE ); | 248 | toolBar->setHorizontalStretchable( TRUE ); |
254 | 249 | ||
255 | QMenuBar *menuBar = new QMenuBar( toolBar ); | 250 | QMenuBar *menuBar = new QMenuBar( toolBar ); |
256 | 251 | ||
257 | QPopupMenu *gameMenu = new QPopupMenu( this ); | 252 | QPopupMenu *gameMenu = new QPopupMenu( this ); |
258 | gameMenu->insertItem( tr("Beginner"), this, SLOT( beginner() ) ); | 253 | gameMenu->insertItem( tr("Beginner"), this, SLOT( beginner() ) ); |
259 | gameMenu->insertItem( tr("Advanced"), this, SLOT( advanced() ) ); | 254 | gameMenu->insertItem( tr("Advanced"), this, SLOT( advanced() ) ); |
260 | 255 | ||
261 | if (qApp->desktop()->width() >= 240) { | 256 | if (qApp->desktop()->width() >= 240) { |
262 | gameMenu->insertItem( tr("Expert"), this, SLOT( expert() ) ); | 257 | gameMenu->insertItem( tr("Expert"), this, SLOT( expert() ) ); |
263 | } | 258 | } |
264 | 259 | ||
265 | menuBar->insertItem( tr("Game"), gameMenu ); | 260 | menuBar->insertItem( tr("Game"), gameMenu ); |
266 | 261 | ||
267 | guessLCD = new QLCDNumber( toolBar ); | 262 | guessLCD = new QLCDNumber( toolBar ); |
268 | toolBar->setStretchableWidget( guessLCD ); | 263 | toolBar->setStretchableWidget( guessLCD ); |
269 | 264 | ||
270 | QPalette lcdPal( red ); | 265 | QPalette lcdPal( red ); |
271 | lcdPal.setColor( QColorGroup::Background, QApplication::palette().active().background() ); | 266 | lcdPal.setColor( QColorGroup::Background, QApplication::palette().active().background() ); |
272 | lcdPal.setColor( QColorGroup::Button, QApplication::palette().active().button() ); | 267 | lcdPal.setColor( QColorGroup::Button, QApplication::palette().active().button() ); |
273 | 268 | ||
274 | // guessLCD->setPalette( lcdPal ); | 269 | // guessLCD->setPalette( lcdPal ); |
275 | guessLCD->setSegmentStyle( QLCDNumber::Flat ); | 270 | guessLCD->setSegmentStyle( QLCDNumber::Flat ); |
276 | guessLCD->setFrameStyle( QFrame::NoFrame ); | 271 | guessLCD->setFrameStyle( QFrame::NoFrame ); |
277 | guessLCD->setNumDigits( 2 ); | 272 | guessLCD->setNumDigits( 2 ); |
278 | guessLCD->setBackgroundMode( PaletteButton ); | 273 | guessLCD->setBackgroundMode( PaletteButton ); |
279 | newGameButton = new QPushButton( toolBar ); | 274 | newGameButton = new QPushButton( toolBar ); |
280 | newGameButton->setPixmap( QPixmap( pix_new ) ); | 275 | newGameButton->setPixmap( QPixmap( pix_new ) ); |
281 | newGameButton->setFocusPolicy(QWidget::NoFocus); | 276 | newGameButton->setFocusPolicy(QWidget::NoFocus); |
282 | connect( newGameButton, SIGNAL(clicked()), this, SLOT(newGame()) ); | 277 | connect( newGameButton, SIGNAL(clicked()), this, SLOT(newGame()) ); |
283 | 278 | ||
284 | timeLCD = new QLCDNumber( toolBar ); | 279 | timeLCD = new QLCDNumber( toolBar ); |
285 | // timeLCD->setPalette( lcdPal ); | 280 | // timeLCD->setPalette( lcdPal ); |
286 | timeLCD->setSegmentStyle( QLCDNumber::Flat ); | 281 | timeLCD->setSegmentStyle( QLCDNumber::Flat ); |
287 | timeLCD->setFrameStyle( QFrame::NoFrame ); | 282 | timeLCD->setFrameStyle( QFrame::NoFrame ); |
288 | timeLCD->setNumDigits( 5 ); // "mm:ss" | 283 | timeLCD->setNumDigits( 5 ); // "mm:ss" |
289 | timeLCD->setBackgroundMode( PaletteButton ); | 284 | timeLCD->setBackgroundMode( PaletteButton ); |
290 | 285 | ||
291 | setToolBarsMovable ( FALSE ); | 286 | setToolBarsMovable ( FALSE ); |
292 | 287 | ||
293 | addToolBar( toolBar ); | 288 | addToolBar( toolBar ); |
294 | 289 | ||
295 | MineFrame *mainframe = new MineFrame( this ); | 290 | MineFrame *mainframe = new MineFrame( this ); |
296 | mainframe->setFrameShape( QFrame::Box ); | 291 | mainframe->setFrameShape( QFrame::Box ); |
297 | mainframe->setFrameShadow( QFrame::Raised ); | 292 | mainframe->setFrameShadow( QFrame::Raised ); |
298 | 293 | ||
299 | mainframe->setLineWidth(2); | 294 | mainframe->setLineWidth(2); |
300 | 295 | ||
301 | field = new MineField( mainframe ); | 296 | field = new MineField( mainframe ); |
302 | mainframe->setField( field ); | 297 | mainframe->setField( field ); |
303 | QFont fnt = field->font(); | 298 | QFont fnt = field->font(); |
304 | fnt.setBold( TRUE ); | 299 | fnt.setBold( TRUE ); |
305 | field->setFont( QFont( fnt ) ); | 300 | field->setFont( QFont( fnt ) ); |
306 | field->setFocus(); | 301 | field->setFocus(); |
307 | setCentralWidget( mainframe ); | 302 | setCentralWidget( mainframe ); |
308 | 303 | ||
309 | connect( field, SIGNAL( gameOver(bool) ), this, SLOT( gameOver(bool) ) ); | 304 | connect( field, SIGNAL( gameOver(bool) ), this, SLOT( gameOver(bool) ) ); |
310 | connect( field, SIGNAL( mineCount(int) ), this, SLOT( setCounter(int) ) ); | 305 | connect( field, SIGNAL( mineCount(int) ), this, SLOT( setCounter(int) ) ); |
311 | connect( field, SIGNAL( gameStarted()), this, SLOT( startPlaying() ) ); | 306 | connect( field, SIGNAL( gameStarted()), this, SLOT( startPlaying() ) ); |
312 | 307 | ||
313 | timer = new QTimer( this ); | 308 | timer = new QTimer( this ); |
314 | connect( timer, SIGNAL( timeout() ), this, SLOT( updateTime() ) ); | 309 | connect( timer, SIGNAL( timeout() ), this, SLOT( updateTime() ) ); |
315 | 310 | ||
316 | readConfig(); | 311 | readConfig(); |
317 | } | 312 | } |
318 | 313 | ||
319 | MineSweep::~MineSweep() | 314 | MineSweep::~MineSweep() |
320 | { | 315 | { |
321 | writeConfig(); | 316 | writeConfig(); |
322 | } | 317 | } |
323 | 318 | ||
324 | void MineSweep::gameOver( bool won ) | 319 | void MineSweep::gameOver( bool won ) |
325 | { | 320 | { |
326 | field->showMines(); | 321 | field->showMines(); |
327 | if ( won ) { | 322 | if ( won ) { |
328 | newGameButton->setPixmap( QPixmap( happy_xpm ) ); | 323 | newGameButton->setPixmap( QPixmap( happy_xpm ) ); |
329 | } else { | 324 | } else { |
330 | newGameButton->setPixmap( QPixmap( dead_xpm ) ); | 325 | newGameButton->setPixmap( QPixmap( dead_xpm ) ); |
331 | } | 326 | } |
332 | ResultIndicator::showResult( this, won ); | 327 | ResultIndicator::showResult( this, won ); |
333 | timer->stop(); | 328 | timer->stop(); |
334 | } | 329 | } |
335 | 330 | ||
336 | void MineSweep::newGame() | 331 | void MineSweep::newGame() |
337 | { | 332 | { |
338 | newGame(field->level()); | 333 | newGame(field->level()); |
339 | } | 334 | } |
340 | 335 | ||
341 | void MineSweep::newGame(int level) | 336 | void MineSweep::newGame(int level) |
342 | { | 337 | { |
343 | timeLCD->display( "0:00" ); | 338 | timeLCD->display( "0:00" ); |
344 | field->setup( level ); | 339 | field->setup( level ); |
345 | newGameButton->setPixmap( QPixmap( pix_new ) ); | 340 | newGameButton->setPixmap( QPixmap( pix_new ) ); |
346 | timer->stop(); | 341 | timer->stop(); |
347 | } | 342 | } |
348 | 343 | ||
349 | void MineSweep::startPlaying() | 344 | void MineSweep::startPlaying() |
350 | { | 345 | { |
351 | newGameButton->setPixmap( QPixmap( worried_xpm ) ); | 346 | newGameButton->setPixmap( QPixmap( worried_xpm ) ); |
352 | starttime = QDateTime::currentDateTime(); | 347 | starttime = QDateTime::currentDateTime(); |
353 | timer->start( 1000 ); | 348 | timer->start( 1000 ); |
354 | } | 349 | } |
355 | 350 | ||
356 | void MineSweep::beginner() | 351 | void MineSweep::beginner() |
357 | { | 352 | { |
358 | newGame(1); | 353 | newGame(1); |
359 | } | 354 | } |
360 | 355 | ||
361 | void MineSweep::advanced() | 356 | void MineSweep::advanced() |
362 | { | 357 | { |
363 | newGame(2); | 358 | newGame(2); |
364 | } | 359 | } |
365 | 360 | ||
366 | void MineSweep::expert() | 361 | void MineSweep::expert() |
367 | { | 362 | { |
368 | newGame(3); | 363 | newGame(3); |
369 | } | 364 | } |
370 | 365 | ||
371 | void MineSweep::setCounter( int c ) | 366 | void MineSweep::setCounter( int c ) |
372 | { | 367 | { |
373 | if ( !guessLCD ) | 368 | if ( !guessLCD ) |
374 | return; | 369 | return; |
375 | 370 | ||
376 | guessLCD->display( c ); | 371 | guessLCD->display( c ); |
377 | } | 372 | } |
378 | 373 | ||
379 | void MineSweep::updateTime() | 374 | void MineSweep::updateTime() |
380 | { | 375 | { |
381 | if ( !timeLCD ) | 376 | if ( !timeLCD ) |
382 | return; | 377 | return; |
383 | 378 | ||
384 | int s = starttime.secsTo(QDateTime::currentDateTime()); | 379 | int s = starttime.secsTo(QDateTime::currentDateTime()); |
385 | if ( s/60 > 99 ) | 380 | if ( s/60 > 99 ) |
386 | timeLCD->display( "-----" ); | 381 | timeLCD->display( "-----" ); |
387 | else | 382 | else |
388 | timeLCD->display( QString().sprintf("%2d:%02d",s/60,s%60) ); | 383 | timeLCD->display( QString().sprintf("%2d:%02d",s/60,s%60) ); |
389 | } | 384 | } |
390 | 385 | ||
391 | void MineSweep::writeConfig() const | 386 | void MineSweep::writeConfig() const |
392 | { | 387 | { |
393 | Config cfg("MineSweep"); | 388 | Config cfg("MineSweep"); |
394 | cfg.setGroup("Panel"); | 389 | cfg.setGroup("Panel"); |
395 | cfg.writeEntry("Time", | 390 | cfg.writeEntry("Time", |
396 | timer->isActive() ? starttime.secsTo(QDateTime::currentDateTime()) : -1); | 391 | timer->isActive() ? starttime.secsTo(QDateTime::currentDateTime()) : -1); |
397 | field->writeConfig(cfg); | 392 | field->writeConfig(cfg); |
398 | } | 393 | } |
399 | 394 | ||
400 | void MineSweep::readConfig() | 395 | void MineSweep::readConfig() |
401 | { | 396 | { |
402 | Config cfg("MineSweep"); | 397 | Config cfg("MineSweep"); |
403 | field->readConfig(cfg); | 398 | field->readConfig(cfg); |
404 | cfg.setGroup("Panel"); | 399 | cfg.setGroup("Panel"); |
405 | int s = cfg.readNumEntry("Time",-1); | 400 | int s = cfg.readNumEntry("Time",-1); |
406 | if ( s<0 ) { | 401 | if ( s<0 ) { |
407 | newGame(); | 402 | newGame(); |
408 | } else { | 403 | } else { |
409 | startPlaying(); | 404 | startPlaying(); |
410 | starttime = QDateTime::currentDateTime().addSecs(-s); | 405 | starttime = QDateTime::currentDateTime().addSecs(-s); |
411 | updateTime(); | 406 | updateTime(); |
412 | } | 407 | } |
413 | } | 408 | } |
diff --git a/noncore/games/oyatzee/oyatzee.cpp b/noncore/games/oyatzee/oyatzee.cpp index 0bd22f6..86318db 100644 --- a/noncore/games/oyatzee/oyatzee.cpp +++ b/noncore/games/oyatzee/oyatzee.cpp | |||
@@ -1,524 +1,518 @@ | |||
1 | #include "oyatzee.h" | 1 | #include "oyatzee.h" |
2 | 2 | ||
3 | #include <qmessagebox.h> | 3 | #include <qmessagebox.h> |
4 | #include <qapplication.h> | ||
5 | #include <qdir.h> | ||
6 | #include <qlabel.h> | ||
7 | #include <qpushbutton.h> | 4 | #include <qpushbutton.h> |
8 | #include <qtimer.h> | ||
9 | #include <qvbox.h> | ||
10 | #include <qpainter.h> | 5 | #include <qpainter.h> |
11 | #include <qlayout.h> | 6 | #include <qlayout.h> |
12 | #include <qpoint.h> | ||
13 | 7 | ||
14 | #include <stdlib.h> | 8 | #include <stdlib.h> |
15 | 9 | ||
16 | OYatzee::OYatzee( QWidget *parent , const char *name, WFlags fl ) : QMainWindow( parent , name , fl ) | 10 | OYatzee::OYatzee( QWidget *parent , const char *name, WFlags fl ) : QMainWindow( parent , name , fl ) |
17 | { | 11 | { |
18 | QWidget *thing = new QWidget( this ); | 12 | QWidget *thing = new QWidget( this ); |
19 | setCentralWidget( thing ); | 13 | setCentralWidget( thing ); |
20 | 14 | ||
21 | setCaption( tr( "OYatzee" ) ); | 15 | setCaption( tr( "OYatzee" ) ); |
22 | 16 | ||
23 | setPlayerNumber( 4 ); | 17 | setPlayerNumber( 4 ); |
24 | setRoundsNumber( 1 ); | 18 | setRoundsNumber( 1 ); |
25 | 19 | ||
26 | lastPlayerFinished = false; | 20 | lastPlayerFinished = false; |
27 | currentPlayer = 1; | 21 | currentPlayer = 1; |
28 | 22 | ||
29 | ps.append( new Player( "Carsten" ) ); | 23 | ps.append( new Player( "Carsten" ) ); |
30 | ps.append( new Player( "Julia" ) ); | 24 | ps.append( new Player( "Julia" ) ); |
31 | ps.append( new Player( "Christine" ) ); | 25 | ps.append( new Player( "Christine" ) ); |
32 | ps.append( new Player( "Stephan" ) ); | 26 | ps.append( new Player( "Stephan" ) ); |
33 | 27 | ||
34 | 28 | ||
35 | QVBoxLayout *vbox = new QVBoxLayout( thing ); | 29 | QVBoxLayout *vbox = new QVBoxLayout( thing ); |
36 | 30 | ||
37 | sb = new Scoreboard( ps, thing , "sb" ); | 31 | sb = new Scoreboard( ps, thing , "sb" ); |
38 | connect( sb->pb , SIGNAL( item( int ) ), this , SLOT( slotEndRound( int ) ) ); | 32 | connect( sb->pb , SIGNAL( item( int ) ), this , SLOT( slotEndRound( int ) ) ); |
39 | 33 | ||
40 | dw = new DiceWidget( thing , "dw" ); | 34 | dw = new DiceWidget( thing , "dw" ); |
41 | dw->setMaximumHeight( this->height()/4 ); | 35 | dw->setMaximumHeight( this->height()/4 ); |
42 | connect( dw->rollButton, SIGNAL( clicked() ), this , SLOT( slotRollDices() ) ); | 36 | connect( dw->rollButton, SIGNAL( clicked() ), this , SLOT( slotRollDices() ) ); |
43 | 37 | ||
44 | vbox->addWidget( sb ); | 38 | vbox->addWidget( sb ); |
45 | vbox->addWidget( dw ); | 39 | vbox->addWidget( dw ); |
46 | } | 40 | } |
47 | 41 | ||
48 | void OYatzee::slotEndRound( int item ) | 42 | void OYatzee::slotEndRound( int item ) |
49 | { | 43 | { |
50 | qDebug( "Der User hat Nummer %d ausgewählt" , item ); | 44 | qDebug( "Der User hat Nummer %d ausgewählt" , item ); |
51 | 45 | ||
52 | /* | 46 | /* |
53 | * if the user clicked on Total, Bonus or Score and thus not on a | 47 | * if the user clicked on Total, Bonus or Score and thus not on a |
54 | * selectable item return and do nothing | 48 | * selectable item return and do nothing |
55 | */ | 49 | */ |
56 | if ( item == 7 || item == 8 || item == 16 ) return; | 50 | if ( item == 7 || item == 8 || item == 16 ) return; |
57 | 51 | ||
58 | /* | 52 | /* |
59 | * check if the user can really click on that item | 53 | * check if the user can really click on that item |
60 | */ | 54 | */ |
61 | if ( posibilities.find( item ) == posibilities.end() ) return; | 55 | if ( posibilities.find( item ) == posibilities.end() ) return; |
62 | 56 | ||
63 | QValueListInt numbers; | 57 | QValueListInt numbers; |
64 | 58 | ||
65 | Dice *d = dw->diceList.first(); | 59 | Dice *d = dw->diceList.first(); |
66 | for ( ; d != 0 ; d = dw->diceList.next() ) | 60 | for ( ; d != 0 ; d = dw->diceList.next() ) |
67 | { | 61 | { |
68 | numbers.append( d->hasValue() ); | 62 | numbers.append( d->hasValue() ); |
69 | } | 63 | } |
70 | 64 | ||
71 | int points = 0; | 65 | int points = 0; |
72 | 66 | ||
73 | switch ( item ) | 67 | switch ( item ) |
74 | { | 68 | { |
75 | case Ones: | 69 | case Ones: |
76 | points = getPoints( 1 , numbers ); | 70 | points = getPoints( 1 , numbers ); |
77 | break; | 71 | break; |
78 | case Twos: | 72 | case Twos: |
79 | points = getPoints( 2 , numbers ); | 73 | points = getPoints( 2 , numbers ); |
80 | break; | 74 | break; |
81 | case Threes: | 75 | case Threes: |
82 | points = getPoints( 3 , numbers ); | 76 | points = getPoints( 3 , numbers ); |
83 | break; | 77 | break; |
84 | case Fours: | 78 | case Fours: |
85 | points = getPoints( 4 , numbers ); | 79 | points = getPoints( 4 , numbers ); |
86 | break; | 80 | break; |
87 | case Fives: | 81 | case Fives: |
88 | points = getPoints( 5 , numbers ); | 82 | points = getPoints( 5 , numbers ); |
89 | break; | 83 | break; |
90 | case Sixes: | 84 | case Sixes: |
91 | points = getPoints( 6 , numbers ); | 85 | points = getPoints( 6 , numbers ); |
92 | break; | 86 | break; |
93 | case ThreeOfAKind: | 87 | case ThreeOfAKind: |
94 | points = oakPoints; | 88 | points = oakPoints; |
95 | break; | 89 | break; |
96 | case FourOfAKind: | 90 | case FourOfAKind: |
97 | points = oakPoints; | 91 | points = oakPoints; |
98 | break; | 92 | break; |
99 | case FullHouse: | 93 | case FullHouse: |
100 | points = 25; | 94 | points = 25; |
101 | break; | 95 | break; |
102 | case SStraight: | 96 | case SStraight: |
103 | points = 30; | 97 | points = 30; |
104 | break; | 98 | break; |
105 | case LStraight: | 99 | case LStraight: |
106 | points = 40; | 100 | points = 40; |
107 | break; | 101 | break; |
108 | case Yatzee: | 102 | case Yatzee: |
109 | points = 50; | 103 | points = 50; |
110 | break; | 104 | break; |
111 | case Chance: | 105 | case Chance: |
112 | points = getPoints ( Chance , numbers ); | 106 | points = getPoints ( Chance , numbers ); |
113 | } | 107 | } |
114 | 108 | ||
115 | sb->nextRB(currentPlayer-1)->updateMap( item , points ); | 109 | sb->nextRB(currentPlayer-1)->updateMap( item , points ); |
116 | nextPlayer(); | 110 | nextPlayer(); |
117 | 111 | ||
118 | qDebug( "Punkte: %d" , points ); | 112 | qDebug( "Punkte: %d" , points ); |
119 | } | 113 | } |
120 | 114 | ||
121 | void OYatzee::nextPlayer() | 115 | void OYatzee::nextPlayer() |
122 | { | 116 | { |
123 | currentPlayer++; | 117 | currentPlayer++; |
124 | 118 | ||
125 | if ( currentPlayer > numOfPlayers ) | 119 | if ( currentPlayer > numOfPlayers ) |
126 | { | 120 | { |
127 | currentPlayer = 1; | 121 | currentPlayer = 1; |
128 | } | 122 | } |
129 | 123 | ||
130 | ps.at(currentPlayer-1)->turn = 0; | 124 | ps.at(currentPlayer-1)->turn = 0; |
131 | } | 125 | } |
132 | 126 | ||
133 | int OYatzee::getPoints( const int num , QValueListInt l) | 127 | int OYatzee::getPoints( const int num , QValueListInt l) |
134 | { | 128 | { |
135 | QValueListInt::Iterator it = l.begin(); | 129 | QValueListInt::Iterator it = l.begin(); |
136 | int c = 0; | 130 | int c = 0; |
137 | 131 | ||
138 | if ( num != Chance ) | 132 | if ( num != Chance ) |
139 | { | 133 | { |
140 | for ( ; it != l.end() ; ++it ) | 134 | for ( ; it != l.end() ; ++it ) |
141 | { | 135 | { |
142 | if ( *it == num ) | 136 | if ( *it == num ) |
143 | c++; | 137 | c++; |
144 | } | 138 | } |
145 | 139 | ||
146 | return c * num; | 140 | return c * num; |
147 | } | 141 | } |
148 | else | 142 | else |
149 | { | 143 | { |
150 | for ( ; it != l.end() ; ++it ) | 144 | for ( ; it != l.end() ; ++it ) |
151 | { | 145 | { |
152 | c += *it; | 146 | c += *it; |
153 | } | 147 | } |
154 | return c; | 148 | return c; |
155 | } | 149 | } |
156 | } | 150 | } |
157 | 151 | ||
158 | OYatzee::~OYatzee() | 152 | OYatzee::~OYatzee() |
159 | { | 153 | { |
160 | } | 154 | } |
161 | 155 | ||
162 | void OYatzee::detectPosibilities() | 156 | void OYatzee::detectPosibilities() |
163 | { | 157 | { |
164 | posibilities.clear(); | 158 | posibilities.clear(); |
165 | qDebug( "running detectPosibilities()" ); | 159 | qDebug( "running detectPosibilities()" ); |
166 | 160 | ||
167 | Dice *d = dw->diceList.first(); | 161 | Dice *d = dw->diceList.first(); |
168 | 162 | ||
169 | QValueListInt numbers; | 163 | QValueListInt numbers; |
170 | 164 | ||
171 | for ( ; d != 0 ; d = dw->diceList.next() ) | 165 | for ( ; d != 0 ; d = dw->diceList.next() ) |
172 | { | 166 | { |
173 | numbers.append( d->hasValue() ); | 167 | numbers.append( d->hasValue() ); |
174 | } | 168 | } |
175 | 169 | ||
176 | //the 6 numbers | 170 | //the 6 numbers |
177 | QValueListInt::Iterator it; | 171 | QValueListInt::Iterator it; |
178 | 172 | ||
179 | for ( int i = 1 ; i < 7 ; ++i ) // check for 1-->6 | 173 | for ( int i = 1 ; i < 7 ; ++i ) // check for 1-->6 |
180 | { | 174 | { |
181 | bool cont = false; | 175 | bool cont = false; |
182 | it = numbers.begin(); | 176 | it = numbers.begin(); |
183 | for ( ; it != numbers.end() ; ++it ) | 177 | for ( ; it != numbers.end() ; ++it ) |
184 | { | 178 | { |
185 | if ( cont ) | 179 | if ( cont ) |
186 | continue; | 180 | continue; |
187 | 181 | ||
188 | if ( numbers.find( i ) != numbers.end() ) | 182 | if ( numbers.find( i ) != numbers.end() ) |
189 | { | 183 | { |
190 | posibilities.append( i ); | 184 | posibilities.append( i ); |
191 | cont = true; | 185 | cont = true; |
192 | } | 186 | } |
193 | } | 187 | } |
194 | } | 188 | } |
195 | 189 | ||
196 | //3er, 4er, Yatzee | 190 | //3er, 4er, Yatzee |
197 | it = numbers.begin(); | 191 | it = numbers.begin(); |
198 | int count; | 192 | int count; |
199 | int temp; | 193 | int temp; |
200 | int countFH = 0; //for the full-house-check | 194 | int countFH = 0; //for the full-house-check |
201 | 195 | ||
202 | for ( int i = 1 ; i < 7 ; ++i ) // check for 1-->6 at least 3 times | 196 | for ( int i = 1 ; i < 7 ; ++i ) // check for 1-->6 at least 3 times |
203 | { | 197 | { |
204 | count = 0; | 198 | count = 0; |
205 | temp = 0; | 199 | temp = 0; |
206 | it = numbers.begin(); | 200 | it = numbers.begin(); |
207 | for ( ; it != numbers.end() ; ++it ) | 201 | for ( ; it != numbers.end() ; ++it ) |
208 | { | 202 | { |
209 | if ( *it == i ) | 203 | if ( *it == i ) |
210 | { | 204 | { |
211 | count++; | 205 | count++; |
212 | temp++; | 206 | temp++; |
213 | } | 207 | } |
214 | if ( temp == 2 ) | 208 | if ( temp == 2 ) |
215 | countFH = temp; | 209 | countFH = temp; |
216 | } | 210 | } |
217 | 211 | ||
218 | if ( count >= 3 ) | 212 | if ( count >= 3 ) |
219 | { | 213 | { |
220 | posibilities.append( 9 ); | 214 | posibilities.append( 9 ); |
221 | 215 | ||
222 | //now we check if it is a full house | 216 | //now we check if it is a full house |
223 | if ( count == 3 && countFH == 2 ) //aka Full House | 217 | if ( count == 3 && countFH == 2 ) //aka Full House |
224 | posibilities.append( 11 ); | 218 | posibilities.append( 11 ); |
225 | if ( count >= 4 ) | 219 | if ( count >= 4 ) |
226 | posibilities.append( 10 ); | 220 | posibilities.append( 10 ); |
227 | if ( count == 5 ) //Yatzee | 221 | if ( count == 5 ) //Yatzee |
228 | posibilities.append( 14 ); | 222 | posibilities.append( 14 ); |
229 | 223 | ||
230 | oakPoints = count * i; | 224 | oakPoints = count * i; |
231 | } | 225 | } |
232 | } | 226 | } |
233 | 227 | ||
234 | //S-Straight | 228 | //S-Straight |
235 | if ( numbers.find( 3 ) != numbers.end() && numbers.find( 4 ) != numbers.end() ) | 229 | if ( numbers.find( 3 ) != numbers.end() && numbers.find( 4 ) != numbers.end() ) |
236 | { | 230 | { |
237 | bool isLong = false; | 231 | bool isLong = false; |
238 | bool isShort = true; | 232 | bool isShort = true; |
239 | //L-Straight | 233 | //L-Straight |
240 | if ( numbers.find( 2 ) != numbers.end() && numbers.find( 5 ) != numbers.end() ) | 234 | if ( numbers.find( 2 ) != numbers.end() && numbers.find( 5 ) != numbers.end() ) |
241 | { | 235 | { |
242 | isShort = true; | 236 | isShort = true; |
243 | 237 | ||
244 | //12345 or 23456 | 238 | //12345 or 23456 |
245 | if ( numbers.find( 1 ) != numbers.end() || numbers.find( 6) != numbers.end() ) | 239 | if ( numbers.find( 1 ) != numbers.end() || numbers.find( 6) != numbers.end() ) |
246 | isLong = true; | 240 | isLong = true; |
247 | } | 241 | } |
248 | //1234 | 242 | //1234 |
249 | if ( numbers.find( 1 ) != numbers.end() && numbers.find( 2 ) != numbers.end() ) | 243 | if ( numbers.find( 1 ) != numbers.end() && numbers.find( 2 ) != numbers.end() ) |
250 | isShort = true; | 244 | isShort = true; |
251 | //3456 | 245 | //3456 |
252 | if ( numbers.find( 5 ) != numbers.end() && numbers.find( 6 ) != numbers.end() ) | 246 | if ( numbers.find( 5 ) != numbers.end() && numbers.find( 6 ) != numbers.end() ) |
253 | isShort = true; | 247 | isShort = true; |
254 | 248 | ||
255 | if ( isShort ) | 249 | if ( isShort ) |
256 | posibilities.append( 12 ); | 250 | posibilities.append( 12 ); |
257 | if ( isLong ) | 251 | if ( isLong ) |
258 | posibilities.append( 13 ); | 252 | posibilities.append( 13 ); |
259 | } | 253 | } |
260 | 254 | ||
261 | posibilities.append( 13 ); //Chance, well, this is allways possible | 255 | posibilities.append( 13 ); //Chance, well, this is allways possible |
262 | 256 | ||
263 | displayPossibilites(); | 257 | displayPossibilites(); |
264 | } | 258 | } |
265 | 259 | ||
266 | void OYatzee::displayPossibilites() | 260 | void OYatzee::displayPossibilites() |
267 | { | 261 | { |
268 | //X for ( QValueListInt::Iterator it = posibilities.begin() ; it != posibilities.end(); ++it ) | 262 | //X for ( QValueListInt::Iterator it = posibilities.begin() ; it != posibilities.end(); ++it ) |
269 | //X { | 263 | //X { |
270 | //X qDebug( QString::number( *it ) ); | 264 | //X qDebug( QString::number( *it ) ); |
271 | //X switch ( *it ) | 265 | //X switch ( *it ) |
272 | //X { | 266 | //X { |
273 | //X case Ones: | 267 | //X case Ones: |
274 | //X qDebug( "1er" ); | 268 | //X qDebug( "1er" ); |
275 | //X break; | 269 | //X break; |
276 | //X case Twos: | 270 | //X case Twos: |
277 | //X qDebug( "2er" ); | 271 | //X qDebug( "2er" ); |
278 | //X break; | 272 | //X break; |
279 | //X case Threes: | 273 | //X case Threes: |
280 | //X qDebug( "3er" ); | 274 | //X qDebug( "3er" ); |
281 | //X break; | 275 | //X break; |
282 | //X case Fours: | 276 | //X case Fours: |
283 | //X qDebug( "4er" ); | 277 | //X qDebug( "4er" ); |
284 | //X break; | 278 | //X break; |
285 | //X case Fives: | 279 | //X case Fives: |
286 | //X qDebug( "5er" ); | 280 | //X qDebug( "5er" ); |
287 | //X break; | 281 | //X break; |
288 | //X case Sixes: | 282 | //X case Sixes: |
289 | //X qDebug( "6er" ); | 283 | //X qDebug( "6er" ); |
290 | //X break; | 284 | //X break; |
291 | //X case ThreeOfAKind: | 285 | //X case ThreeOfAKind: |
292 | //X qDebug( "3oaK" ); | 286 | //X qDebug( "3oaK" ); |
293 | //X break; | 287 | //X break; |
294 | //X case FourOfAKind: | 288 | //X case FourOfAKind: |
295 | //X qDebug( "4oaK" ); | 289 | //X qDebug( "4oaK" ); |
296 | //X break; | 290 | //X break; |
297 | //X case FullHouse: | 291 | //X case FullHouse: |
298 | //X qDebug( "Full House" ); | 292 | //X qDebug( "Full House" ); |
299 | //X break; | 293 | //X break; |
300 | //X case SStraight: | 294 | //X case SStraight: |
301 | //X qDebug( "Short S" ); | 295 | //X qDebug( "Short S" ); |
302 | //X break; | 296 | //X break; |
303 | //X case LStraight: | 297 | //X case LStraight: |
304 | //X qDebug( "Long S" ); | 298 | //X qDebug( "Long S" ); |
305 | //X break; | 299 | //X break; |
306 | //X case Yatzee: | 300 | //X case Yatzee: |
307 | //X qDebug( "Yatzee!" ); | 301 | //X qDebug( "Yatzee!" ); |
308 | //X break; | 302 | //X break; |
309 | //X case Chance: | 303 | //X case Chance: |
310 | //X qDebug( "Chance" ); | 304 | //X qDebug( "Chance" ); |
311 | //X break; | 305 | //X break; |
312 | //X } | 306 | //X } |
313 | //X } | 307 | //X } |
314 | 308 | ||
315 | sb->pb->setIntlist( posibilities ); | 309 | sb->pb->setIntlist( posibilities ); |
316 | sb->pb->update(); | 310 | sb->pb->update(); |
317 | } | 311 | } |
318 | 312 | ||
319 | void OYatzee::startGame() | 313 | void OYatzee::startGame() |
320 | { | 314 | { |
321 | /* | 315 | /* |
322 | * TODO | 316 | * TODO |
323 | */ | 317 | */ |
324 | } | 318 | } |
325 | 319 | ||
326 | void OYatzee::stopGame(){} | 320 | void OYatzee::stopGame(){} |
327 | 321 | ||
328 | void OYatzee::setPlayerNumber( const int num ) | 322 | void OYatzee::setPlayerNumber( const int num ) |
329 | { | 323 | { |
330 | numOfPlayers = num; | 324 | numOfPlayers = num; |
331 | } | 325 | } |
332 | 326 | ||
333 | void OYatzee::setRoundsNumber( const int num ) | 327 | void OYatzee::setRoundsNumber( const int num ) |
334 | { | 328 | { |
335 | numOfRounds = num; | 329 | numOfRounds = num; |
336 | } | 330 | } |
337 | 331 | ||
338 | void OYatzee::slotStartGame() | 332 | void OYatzee::slotStartGame() |
339 | { | 333 | { |
340 | } | 334 | } |
341 | 335 | ||
342 | void OYatzee::slotRollDices() | 336 | void OYatzee::slotRollDices() |
343 | { | 337 | { |
344 | qDebug( "Roll nummer: %d" , ps.at( currentPlayer-1 )->turn ); | 338 | qDebug( "Roll nummer: %d" , ps.at( currentPlayer-1 )->turn ); |
345 | 339 | ||
346 | if ( ps.at( currentPlayer-1 )->turn == 3 ) | 340 | if ( ps.at( currentPlayer-1 )->turn == 3 ) |
347 | { | 341 | { |
348 | QMessageBox::information( this, | 342 | QMessageBox::information( this, |
349 | "OYatzee", | 343 | "OYatzee", |
350 | tr( "Only three rolls per turn allowed." ) ); | 344 | tr( "Only three rolls per turn allowed." ) ); |
351 | return; | 345 | return; |
352 | } | 346 | } |
353 | 347 | ||
354 | Dice *d = dw->diceList.first(); | 348 | Dice *d = dw->diceList.first(); |
355 | 349 | ||
356 | for ( ; d != 0 ; d = dw->diceList.next() ) | 350 | for ( ; d != 0 ; d = dw->diceList.next() ) |
357 | { | 351 | { |
358 | if ( !d->isSelected ) | 352 | if ( !d->isSelected ) |
359 | d->roll(); | 353 | d->roll(); |
360 | } | 354 | } |
361 | 355 | ||
362 | //qDebug( "Roll nummer (vorher): %d" , ps.at( currentPlayer-1 )->turn ); | 356 | //qDebug( "Roll nummer (vorher): %d" , ps.at( currentPlayer-1 )->turn ); |
363 | ps.at(currentPlayer-1)->turn++; | 357 | ps.at(currentPlayer-1)->turn++; |
364 | //qDebug( "Roll nummer (nachher): %d" , ps.at( currentPlayer-1 )->turn ); | 358 | //qDebug( "Roll nummer (nachher): %d" , ps.at( currentPlayer-1 )->turn ); |
365 | 359 | ||
366 | detectPosibilities(); | 360 | detectPosibilities(); |
367 | } | 361 | } |
368 | 362 | ||
369 | /* | 363 | /* |
370 | * Scoreboard | 364 | * Scoreboard |
371 | */ | 365 | */ |
372 | Scoreboard::Scoreboard( playerList ps, QWidget *parent, const char *name ) : QWidget( parent , name ) | 366 | Scoreboard::Scoreboard( playerList ps, QWidget *parent, const char *name ) : QWidget( parent , name ) |
373 | { | 367 | { |
374 | ps_ = ps; | 368 | ps_ = ps; |
375 | 369 | ||
376 | pb = new Possibilityboard( this , "pb" ); | 370 | pb = new Possibilityboard( this , "pb" ); |
377 | 371 | ||
378 | createResultboards( 4 ); | 372 | createResultboards( 4 ); |
379 | 373 | ||
380 | QHBoxLayout *hbox = new QHBoxLayout( this ); | 374 | QHBoxLayout *hbox = new QHBoxLayout( this ); |
381 | 375 | ||
382 | hbox->addWidget( pb ); | 376 | hbox->addWidget( pb ); |
383 | 377 | ||
384 | hbox->addSpacing( 25 ); | 378 | hbox->addSpacing( 25 ); |
385 | 379 | ||
386 | Resultboard *r = rbList.first(); | 380 | Resultboard *r = rbList.first(); |
387 | 381 | ||
388 | for ( ; r != 0 ; r = rbList.next() ) | 382 | for ( ; r != 0 ; r = rbList.next() ) |
389 | { | 383 | { |
390 | hbox->addWidget( r ); | 384 | hbox->addWidget( r ); |
391 | } | 385 | } |
392 | } | 386 | } |
393 | 387 | ||
394 | Resultboard* Scoreboard::nextRB( int currentPlayer ) | 388 | Resultboard* Scoreboard::nextRB( int currentPlayer ) |
395 | { | 389 | { |
396 | Resultboard *b; | 390 | Resultboard *b; |
397 | 391 | ||
398 | b = rbList.at( currentPlayer ); | 392 | b = rbList.at( currentPlayer ); |
399 | 393 | ||
400 | qDebug( "Anzahl: %d" ,rbList.count() ); | 394 | qDebug( "Anzahl: %d" ,rbList.count() ); |
401 | 395 | ||
402 | return b; | 396 | return b; |
403 | } | 397 | } |
404 | 398 | ||
405 | void Scoreboard::createResultboards(const int num) | 399 | void Scoreboard::createResultboards(const int num) |
406 | { | 400 | { |
407 | Player *p = ps_.first(); | 401 | Player *p = ps_.first(); |
408 | for ( int i = 0 ; i < num ; ++i , p = ps_.next() ) | 402 | for ( int i = 0 ; i < num ; ++i , p = ps_.next() ) |
409 | { | 403 | { |
410 | QString n = p->playerName; | 404 | QString n = p->playerName; |
411 | rbList.append( new Resultboard( n , this ) ); | 405 | rbList.append( new Resultboard( n , this ) ); |
412 | } | 406 | } |
413 | } | 407 | } |
414 | 408 | ||
415 | void Scoreboard::paintEvent( QPaintEvent * ) | 409 | void Scoreboard::paintEvent( QPaintEvent * ) |
416 | { | 410 | { |
417 | //X QPainter p; | 411 | //X QPainter p; |
418 | //X p.begin( this ); | 412 | //X p.begin( this ); |
419 | //X | 413 | //X |
420 | //X p.drawRect( 0,0, this->width() , this->height() ); | 414 | //X p.drawRect( 0,0, this->width() , this->height() ); |
421 | } | 415 | } |
422 | 416 | ||
423 | /* | 417 | /* |
424 | * Dice | 418 | * Dice |
425 | */ | 419 | */ |
426 | Dice::Dice( QWidget *parent , const char *name ) : QFrame( parent , name ) | 420 | Dice::Dice( QWidget *parent , const char *name ) : QFrame( parent , name ) |
427 | { | 421 | { |
428 | QTime t = QTime::currentTime(); // set random seed | 422 | QTime t = QTime::currentTime(); // set random seed |
429 | srand(t.hour()*12+t.minute()*60+t.second()*60); | 423 | srand(t.hour()*12+t.minute()*60+t.second()*60); |
430 | 424 | ||
431 | connect( this , SIGNAL( selected() ), this , SLOT( slotSelected() ) ); | 425 | connect( this , SIGNAL( selected() ), this , SLOT( slotSelected() ) ); |
432 | } | 426 | } |
433 | 427 | ||
434 | void Dice::slotSelected() | 428 | void Dice::slotSelected() |
435 | { | 429 | { |
436 | if ( isSelected ) | 430 | if ( isSelected ) |
437 | isSelected = false; | 431 | isSelected = false; |
438 | else isSelected = true; | 432 | else isSelected = true; |
439 | 433 | ||
440 | update(); | 434 | update(); |
441 | } | 435 | } |
442 | 436 | ||
443 | const int Dice::hasValue() const | 437 | const int Dice::hasValue() const |
444 | { | 438 | { |
445 | return Value; | 439 | return Value; |
446 | } | 440 | } |
447 | 441 | ||
448 | void Dice::roll() | 442 | void Dice::roll() |
449 | { | 443 | { |
450 | Value = rand()%6; | 444 | Value = rand()%6; |
451 | Value += 1; | 445 | Value += 1; |
452 | 446 | ||
453 | update(); | 447 | update(); |
454 | } | 448 | } |
455 | 449 | ||
456 | void Dice::mousePressEvent( QMouseEvent* /*e*/ ) | 450 | void Dice::mousePressEvent( QMouseEvent* /*e*/ ) |
457 | { | 451 | { |
458 | emit selected(); | 452 | emit selected(); |
459 | } | 453 | } |
460 | 454 | ||
461 | void Dice::paintEvent( QPaintEvent * ) | 455 | void Dice::paintEvent( QPaintEvent * ) |
462 | { | 456 | { |
463 | QPainter p; | 457 | QPainter p; |
464 | p.begin( this ); | 458 | p.begin( this ); |
465 | 459 | ||
466 | p.drawRect( 0,0, this->width() , this->height() ); | 460 | p.drawRect( 0,0, this->width() , this->height() ); |
467 | 461 | ||
468 | if ( isSelected ) | 462 | if ( isSelected ) |
469 | p.drawRect( 20,20, 10,10 ); | 463 | p.drawRect( 20,20, 10,10 ); |
470 | 464 | ||
471 | paintNumber( &p ); | 465 | paintNumber( &p ); |
472 | } | 466 | } |
473 | 467 | ||
474 | void Dice::paintNumber( QPainter *p ) | 468 | void Dice::paintNumber( QPainter *p ) |
475 | { | 469 | { |
476 | p->setBrush( Qt::black ); | 470 | p->setBrush( Qt::black ); |
477 | 471 | ||
478 | int w = this->width(); | 472 | int w = this->width(); |
479 | int h = this->height(); | 473 | int h = this->height(); |
480 | int r = this->width(); | 474 | int r = this->width(); |
481 | r /= 10; | 475 | r /= 10; |
482 | 476 | ||
483 | switch ( Value ) | 477 | switch ( Value ) |
484 | { | 478 | { |
485 | case 1: | 479 | case 1: |
486 | p->drawEllipse( (int)( 0.5*w - r ) , (int)( 0.5*h - r ) , r , r ) ; | 480 | p->drawEllipse( (int)( 0.5*w - r ) , (int)( 0.5*h - r ) , r , r ) ; |
487 | break; | 481 | break; |
488 | case 2: | 482 | case 2: |
489 | p->drawEllipse( (int)( 0.3*w - r ) , (int)( 0.3*h - r ) , r , r ) ; | 483 | p->drawEllipse( (int)( 0.3*w - r ) , (int)( 0.3*h - r ) , r , r ) ; |
490 | p->drawEllipse( (int)( 0.7*w - r ) , (int)( 0.7*h - r ) , r , r ) ; | 484 | p->drawEllipse( (int)( 0.7*w - r ) , (int)( 0.7*h - r ) , r , r ) ; |
491 | break; | 485 | break; |
492 | case 3: | 486 | case 3: |
493 | p->drawEllipse( (int)( 0.5*w - r ) , (int)( 0.5*h - r ) , r , r ) ; | 487 | p->drawEllipse( (int)( 0.5*w - r ) , (int)( 0.5*h - r ) , r , r ) ; |
494 | p->drawEllipse( (int)( 0.2*w - r ) , (int)( 0.2*h - r ) , r , r ) ; | 488 | p->drawEllipse( (int)( 0.2*w - r ) , (int)( 0.2*h - r ) , r , r ) ; |
495 | p->drawEllipse( (int)( 0.8*w - r ) , (int)( 0.8*h - r ) , r , r ) ; | 489 | p->drawEllipse( (int)( 0.8*w - r ) , (int)( 0.8*h - r ) , r , r ) ; |
496 | break; | 490 | break; |
497 | case 4: | 491 | case 4: |
498 | p->drawEllipse( (int)( 0.2*w - r ) , (int)( 0.2*h - r ) , r , r ) ; | 492 | p->drawEllipse( (int)( 0.2*w - r ) , (int)( 0.2*h - r ) , r , r ) ; |
499 | p->drawEllipse( (int)( 0.8*w - r ) , (int)( 0.8*h - r ) , r , r ) ; | 493 | p->drawEllipse( (int)( 0.8*w - r ) , (int)( 0.8*h - r ) , r , r ) ; |
500 | p->drawEllipse( (int)( 0.8*w - r ) , (int)( 0.2*h - r ) , r , r ) ; | 494 | p->drawEllipse( (int)( 0.8*w - r ) , (int)( 0.2*h - r ) , r , r ) ; |
501 | p->drawEllipse( (int)( 0.2*w - r ) , (int)( 0.8*h - r ) , r , r ) ; | 495 | p->drawEllipse( (int)( 0.2*w - r ) , (int)( 0.8*h - r ) , r , r ) ; |
502 | break; | 496 | break; |
503 | case 5: | 497 | case 5: |
504 | p->drawEllipse( (int)( 0.5*w - r ) , (int)( 0.5*h - r ) , r , r ) ; | 498 | p->drawEllipse( (int)( 0.5*w - r ) , (int)( 0.5*h - r ) , r , r ) ; |
505 | p->drawEllipse( (int)( 0.2*w - r ) , (int)( 0.2*h - r ) , r , r ) ; | 499 | p->drawEllipse( (int)( 0.2*w - r ) , (int)( 0.2*h - r ) , r , r ) ; |
506 | p->drawEllipse( (int)( 0.8*w - r ) , (int)( 0.8*h - r ) , r , r ) ; | 500 | p->drawEllipse( (int)( 0.8*w - r ) , (int)( 0.8*h - r ) , r , r ) ; |
507 | p->drawEllipse( (int)( 0.8*w - r ) , (int)( 0.2*h - r ) , r , r ) ; | 501 | p->drawEllipse( (int)( 0.8*w - r ) , (int)( 0.2*h - r ) , r , r ) ; |
508 | p->drawEllipse( (int)( 0.2*w - r ) , (int)( 0.8*h - r ) , r , r ) ; | 502 | p->drawEllipse( (int)( 0.2*w - r ) , (int)( 0.8*h - r ) , r , r ) ; |
509 | break; | 503 | break; |
510 | case 6: | 504 | case 6: |
511 | p->drawEllipse( (int)( 0.2*w - r ) , (int)( 0.2*h - r ) , r , r ) ; | 505 | p->drawEllipse( (int)( 0.2*w - r ) , (int)( 0.2*h - r ) , r , r ) ; |
512 | p->drawEllipse( (int)( 0.8*w - r ) , (int)( 0.8*h - r ) , r , r ) ; | 506 | p->drawEllipse( (int)( 0.8*w - r ) , (int)( 0.8*h - r ) , r , r ) ; |
513 | p->drawEllipse( (int)( 0.8*w - r ) , (int)( 0.2*h - r ) , r , r ) ; | 507 | p->drawEllipse( (int)( 0.8*w - r ) , (int)( 0.2*h - r ) , r , r ) ; |
514 | p->drawEllipse( (int)( 0.2*w - r ) , (int)( 0.8*h - r ) , r , r ) ; | 508 | p->drawEllipse( (int)( 0.2*w - r ) , (int)( 0.8*h - r ) , r , r ) ; |
515 | p->drawEllipse( (int)( 0.2*w - r ) , (int)( 0.5*h - r ) , r , r ) ; | 509 | p->drawEllipse( (int)( 0.2*w - r ) , (int)( 0.5*h - r ) , r , r ) ; |
516 | p->drawEllipse( (int)( 0.8*w - r ) , (int)( 0.5*h - r ) , r , r ) ; | 510 | p->drawEllipse( (int)( 0.8*w - r ) , (int)( 0.5*h - r ) , r , r ) ; |
517 | break; | 511 | break; |
518 | } | 512 | } |
519 | } | 513 | } |
520 | 514 | ||
521 | /* | 515 | /* |
522 | * DiceWidget | 516 | * DiceWidget |
523 | */ | 517 | */ |
524 | DiceWidget::DiceWidget( QWidget *parent , const char *name ) : QWidget( parent , name ) | 518 | DiceWidget::DiceWidget( QWidget *parent , const char *name ) : QWidget( parent , name ) |
diff --git a/noncore/games/parashoot/base.cpp b/noncore/games/parashoot/base.cpp index cdf1dfa..5f3c79d 100644 --- a/noncore/games/parashoot/base.cpp +++ b/noncore/games/parashoot/base.cpp | |||
@@ -1,77 +1,75 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include "codes.h" | 20 | #include "codes.h" |
21 | #include "base.h" | 21 | #include "base.h" |
22 | #include "man.h" | ||
23 | 22 | ||
24 | #include <qtopia/resource.h> | 23 | #include <qtopia/resource.h> |
25 | 24 | ||
26 | #include <qregexp.h> | ||
27 | 25 | ||
28 | int damage; | 26 | int damage; |
29 | 27 | ||
30 | Base::Base(QCanvas* canvas) : | 28 | Base::Base(QCanvas* canvas) : |
31 | QCanvasSprite(0, canvas), | 29 | QCanvasSprite(0, canvas), |
32 | kaboom("landmine"), | 30 | kaboom("landmine"), |
33 | ohdear("crmble01") | 31 | ohdear("crmble01") |
34 | { | 32 | { |
35 | basearray = new QCanvasPixmapArray(); | 33 | basearray = new QCanvasPixmapArray(); |
36 | QString b0 = Resource::findPixmap("parashoot/b0001"); | 34 | QString b0 = Resource::findPixmap("parashoot/b0001"); |
37 | b0.replace(QRegExp("0001"),"%1"); | 35 | b0.replace(QRegExp("0001"),"%1"); |
38 | basearray->readPixmaps(b0, 4); | 36 | basearray->readPixmaps(b0, 4); |
39 | setSequence(basearray); | 37 | setSequence(basearray); |
40 | setFrame(0); | 38 | setFrame(0); |
41 | move(2, canvas->height()-50); | 39 | move(2, canvas->height()-50); |
42 | setZ(10); | 40 | setZ(10); |
43 | show(); | 41 | show(); |
44 | damage = 0; | 42 | damage = 0; |
45 | } | 43 | } |
46 | 44 | ||
47 | void Base::damageBase() | 45 | void Base::damageBase() |
48 | { | 46 | { |
49 | damage++; | 47 | damage++; |
50 | 48 | ||
51 | switch(damage) { | 49 | switch(damage) { |
52 | case 1: setFrame(1); ohdear.play(); break; | 50 | case 1: setFrame(1); ohdear.play(); break; |
53 | case 2: setFrame(2); ohdear.play(); break; | 51 | case 2: setFrame(2); ohdear.play(); break; |
54 | case 3: setFrame(3); kaboom.play(); break; | 52 | case 3: setFrame(3); kaboom.play(); break; |
55 | } | 53 | } |
56 | show(); | 54 | show(); |
57 | } | 55 | } |
58 | 56 | ||
59 | bool Base::baseDestroyed() | 57 | bool Base::baseDestroyed() |
60 | { | 58 | { |
61 | return (damage >= 3); | 59 | return (damage >= 3); |
62 | } | 60 | } |
63 | 61 | ||
64 | Base::~Base() | 62 | Base::~Base() |
65 | { | 63 | { |
66 | } | 64 | } |
67 | 65 | ||
68 | int Base::rtti() const | 66 | int Base::rtti() const |
69 | { | 67 | { |
70 | return base_rtti; | 68 | return base_rtti; |
71 | } | 69 | } |
72 | 70 | ||
73 | void | 71 | void |
74 | Base::reposition(void) | 72 | Base::reposition(void) |
75 | { | 73 | { |
76 | move(2, canvas()->height()-50); | 74 | move(2, canvas()->height()-50); |
77 | } | 75 | } |
diff --git a/noncore/games/parashoot/cannon.cpp b/noncore/games/parashoot/cannon.cpp index 5671351..330d850 100644 --- a/noncore/games/parashoot/cannon.cpp +++ b/noncore/games/parashoot/cannon.cpp | |||
@@ -1,150 +1,149 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include <qtopia/resource.h> | 21 | #include <qtopia/resource.h> |
22 | 22 | ||
23 | #include <qregexp.h> | ||
24 | 23 | ||
25 | #include "codes.h" | 24 | #include "codes.h" |
26 | #include "cannon.h" | 25 | #include "cannon.h" |
27 | 26 | ||
28 | Cannon::Cannon(QCanvas* canvas) : | 27 | Cannon::Cannon(QCanvas* canvas) : |
29 | QCanvasSprite(0, canvas) | 28 | QCanvasSprite(0, canvas) |
30 | { | 29 | { |
31 | shotsfired=0; | 30 | shotsfired=0; |
32 | index = 8; | 31 | index = 8; |
33 | cannonx = 0; | 32 | cannonx = 0; |
34 | cannony = 0; | 33 | cannony = 0; |
35 | cannonarray = new QCanvasPixmapArray(); | 34 | cannonarray = new QCanvasPixmapArray(); |
36 | QString c0 = Resource::findPixmap("parashoot/can0001"); | 35 | QString c0 = Resource::findPixmap("parashoot/can0001"); |
37 | c0.replace(QRegExp("0001"),"%1"); | 36 | c0.replace(QRegExp("0001"),"%1"); |
38 | cannonarray->readPixmaps(c0,17); | 37 | cannonarray->readPixmaps(c0,17); |
39 | setSequence(cannonarray); | 38 | setSequence(cannonarray); |
40 | setFrame(index); | 39 | setFrame(index); |
41 | 40 | ||
42 | reposition(); | 41 | reposition(); |
43 | 42 | ||
44 | movedir = NoDir; | 43 | movedir = NoDir; |
45 | moveDelay = 0; | 44 | moveDelay = 0; |
46 | setAnimated(TRUE); | 45 | setAnimated(TRUE); |
47 | show(); | 46 | show(); |
48 | } | 47 | } |
49 | 48 | ||
50 | void Cannon::advance(int stage) | 49 | void Cannon::advance(int stage) |
51 | { | 50 | { |
52 | if ( stage == 1 && moveDelay-- == 0 ) { | 51 | if ( stage == 1 && moveDelay-- == 0 ) { |
53 | if (movedir == Left) { | 52 | if (movedir == Left) { |
54 | if (index > 0) { | 53 | if (index > 0) { |
55 | setFrame(index-1); | 54 | setFrame(index-1); |
56 | index--; | 55 | index--; |
57 | } | 56 | } |
58 | } | 57 | } |
59 | if (movedir == Right) { | 58 | if (movedir == Right) { |
60 | if (index < 16) { | 59 | if (index < 16) { |
61 | setFrame(index+1); | 60 | setFrame(index+1); |
62 | index++; | 61 | index++; |
63 | } | 62 | } |
64 | } | 63 | } |
65 | moveDelay = 0; | 64 | moveDelay = 0; |
66 | } | 65 | } |
67 | } | 66 | } |
68 | 67 | ||
69 | void Cannon::pointCannon(Direction dir) | 68 | void Cannon::pointCannon(Direction dir) |
70 | { | 69 | { |
71 | movedir = dir; | 70 | movedir = dir; |
72 | moveDelay = 0; | 71 | moveDelay = 0; |
73 | advance(1); | 72 | advance(1); |
74 | moveDelay = 1; | 73 | moveDelay = 1; |
75 | } | 74 | } |
76 | 75 | ||
77 | void Cannon::setCoords() | 76 | void Cannon::setCoords() |
78 | { | 77 | { |
79 | switch(index) { | 78 | switch(index) { |
80 | case 0: cannonx = barrelxpos-29; cannony = barrelypos-8; break; | 79 | case 0: cannonx = barrelxpos-29; cannony = barrelypos-8; break; |
81 | case 1: cannonx = barrelxpos-27; cannony = barrelypos-8; break; | 80 | case 1: cannonx = barrelxpos-27; cannony = barrelypos-8; break; |
82 | case 2: cannonx = barrelxpos-25; cannony = barrelypos-6; break; | 81 | case 2: cannonx = barrelxpos-25; cannony = barrelypos-6; break; |
83 | case 3: cannonx = barrelxpos-23; cannony = barrelypos-4; break; | 82 | case 3: cannonx = barrelxpos-23; cannony = barrelypos-4; break; |
84 | case 4: cannonx = barrelxpos-21; cannony = barrelypos-2; break; | 83 | case 4: cannonx = barrelxpos-21; cannony = barrelypos-2; break; |
85 | case 5: cannonx = barrelxpos-19; cannony = barrelypos; break; | 84 | case 5: cannonx = barrelxpos-19; cannony = barrelypos; break; |
86 | case 6: cannonx = barrelxpos-15; cannony = barrelypos; break; | 85 | case 6: cannonx = barrelxpos-15; cannony = barrelypos; break; |
87 | case 7: cannonx = barrelxpos-10; cannony = barrelypos; break; | 86 | case 7: cannonx = barrelxpos-10; cannony = barrelypos; break; |
88 | case 8: cannonx = barrelxpos; cannony = barrelypos; break; | 87 | case 8: cannonx = barrelxpos; cannony = barrelypos; break; |
89 | case 9: cannonx = barrelxpos+2; cannony = barrelypos; break; | 88 | case 9: cannonx = barrelxpos+2; cannony = barrelypos; break; |
90 | case 10: cannonx = barrelxpos+6; cannony = barrelypos; break; | 89 | case 10: cannonx = barrelxpos+6; cannony = barrelypos; break; |
91 | case 11: cannonx = barrelxpos+8; cannony = barrelypos; break; | 90 | case 11: cannonx = barrelxpos+8; cannony = barrelypos; break; |
92 | case 12: cannonx = barrelxpos+12; cannony = barrelypos-2; break; | 91 | case 12: cannonx = barrelxpos+12; cannony = barrelypos-2; break; |
93 | case 13: cannonx = barrelxpos+18; cannony = barrelypos-4; break; | 92 | case 13: cannonx = barrelxpos+18; cannony = barrelypos-4; break; |
94 | case 14: cannonx = barrelxpos+22; cannony = barrelypos-6; break; | 93 | case 14: cannonx = barrelxpos+22; cannony = barrelypos-6; break; |
95 | case 15: cannonx = barrelxpos+26; cannony = barrelypos-8; break; | 94 | case 15: cannonx = barrelxpos+26; cannony = barrelypos-8; break; |
96 | case 16: cannonx = barrelxpos+28; cannony = barrelypos-8; break; | 95 | case 16: cannonx = barrelxpos+28; cannony = barrelypos-8; break; |
97 | } | 96 | } |
98 | } | 97 | } |
99 | 98 | ||
100 | double Cannon::shootAngle() | 99 | double Cannon::shootAngle() |
101 | { | 100 | { |
102 | switch(index) { | 101 | switch(index) { |
103 | case 0: return 30.0; | 102 | case 0: return 30.0; |
104 | case 1: return 37.5; | 103 | case 1: return 37.5; |
105 | case 2: return 45.0; | 104 | case 2: return 45.0; |
106 | case 3: return 52.5; | 105 | case 3: return 52.5; |
107 | case 4: return 60.0; | 106 | case 4: return 60.0; |
108 | case 5: return 67.5; | 107 | case 5: return 67.5; |
109 | case 6: return 75.0; | 108 | case 6: return 75.0; |
110 | case 7: return 82.5; | 109 | case 7: return 82.5; |
111 | case 8: return 90.0; | 110 | case 8: return 90.0; |
112 | case 9: return 97.5; | 111 | case 9: return 97.5; |
113 | case 10: return 105.0; | 112 | case 10: return 105.0; |
114 | case 11: return 112.5; | 113 | case 11: return 112.5; |
115 | case 12: return 120.0; | 114 | case 12: return 120.0; |
116 | case 13: return 127.5; | 115 | case 13: return 127.5; |
117 | case 14: return 135.0; | 116 | case 14: return 135.0; |
118 | case 15: return 142.5; | 117 | case 15: return 142.5; |
119 | case 16: return 150.0; | 118 | case 16: return 150.0; |
120 | } | 119 | } |
121 | return 0; | 120 | return 0; |
122 | } | 121 | } |
123 | 122 | ||
124 | void Cannon::shoot() | 123 | void Cannon::shoot() |
125 | { | 124 | { |
126 | setCoords(); | 125 | setCoords(); |
127 | Bullet* bullet = new Bullet(canvas(), shootAngle(), cannonx, cannony); | 126 | Bullet* bullet = new Bullet(canvas(), shootAngle(), cannonx, cannony); |
128 | connect(bullet, SIGNAL(score(int)), this, SIGNAL(score(int))); | 127 | connect(bullet, SIGNAL(score(int)), this, SIGNAL(score(int))); |
129 | shotsfired++; | 128 | shotsfired++; |
130 | } | 129 | } |
131 | 130 | ||
132 | Cannon::~Cannon() | 131 | Cannon::~Cannon() |
133 | { | 132 | { |
134 | } | 133 | } |
135 | 134 | ||
136 | int Cannon::rtti() const | 135 | int Cannon::rtti() const |
137 | { | 136 | { |
138 | return cannon_rtti; | 137 | return cannon_rtti; |
139 | } | 138 | } |
140 | 139 | ||
141 | void Cannon::reposition(void) | 140 | void Cannon::reposition(void) |
142 | { | 141 | { |
143 | move(canvas()->width()/2-20, canvas()->height()-32); | 142 | move(canvas()->width()/2-20, canvas()->height()-32); |
144 | // co ords for barrel of cannon when upright | 143 | // co ords for barrel of cannon when upright |
145 | barrelypos = canvas()->height()-32; | 144 | barrelypos = canvas()->height()-32; |
146 | barrelxpos = canvas()->width()/2; | 145 | barrelxpos = canvas()->width()/2; |
147 | 146 | ||
148 | setFrame(index); | 147 | setFrame(index); |
149 | setCoords(); | 148 | setCoords(); |
150 | } | 149 | } |
diff --git a/noncore/games/parashoot/helicopter.cpp b/noncore/games/parashoot/helicopter.cpp index 036b21e..7d91cd1 100644 --- a/noncore/games/parashoot/helicopter.cpp +++ b/noncore/games/parashoot/helicopter.cpp | |||
@@ -1,120 +1,119 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "helicopter.h" | 21 | #include "helicopter.h" |
22 | #include "man.h" | 22 | #include "man.h" |
23 | #include "codes.h" | 23 | #include "codes.h" |
24 | 24 | ||
25 | #include <qtopia/resource.h> | 25 | #include <qtopia/resource.h> |
26 | 26 | ||
27 | #include <qregexp.h> | ||
28 | 27 | ||
29 | static QList<Helicopter> all; | 28 | static QList<Helicopter> all; |
30 | 29 | ||
31 | Helicopter::Helicopter(QCanvas* canvas) : | 30 | Helicopter::Helicopter(QCanvas* canvas) : |
32 | QCanvasSprite(0, canvas), | 31 | QCanvasSprite(0, canvas), |
33 | chikachika("aland01") | 32 | chikachika("aland01") |
34 | { | 33 | { |
35 | all.append(this); | 34 | all.append(this); |
36 | hits = 0; | 35 | hits = 0; |
37 | QCanvasPixmapArray* helicopterarray = new QCanvasPixmapArray(); | 36 | QCanvasPixmapArray* helicopterarray = new QCanvasPixmapArray(); |
38 | QString h0 = Resource::findPixmap("parashoot/helicopter0001"); | 37 | QString h0 = Resource::findPixmap("parashoot/helicopter0001"); |
39 | h0.replace(QRegExp("0001"),"%1"); | 38 | h0.replace(QRegExp("0001"),"%1"); |
40 | helicopterarray->readPixmaps(h0,4 ); | 39 | helicopterarray->readPixmaps(h0,4 ); |
41 | 40 | ||
42 | setSequence(helicopterarray); | 41 | setSequence(helicopterarray); |
43 | setAnimated(true); | 42 | setAnimated(true); |
44 | move(canvas->width(), 5); | 43 | move(canvas->width(), 5); |
45 | setVelocity(-2, 0); | 44 | setVelocity(-2, 0); |
46 | chikachika.playLoop(); | 45 | chikachika.playLoop(); |
47 | show(); | 46 | show(); |
48 | } | 47 | } |
49 | 48 | ||
50 | Helicopter::~Helicopter() | 49 | Helicopter::~Helicopter() |
51 | { | 50 | { |
52 | all.remove(this); | 51 | all.remove(this); |
53 | } | 52 | } |
54 | 53 | ||
55 | int fr = 0; | 54 | int fr = 0; |
56 | 55 | ||
57 | void Helicopter::advance(int phase) | 56 | void Helicopter::advance(int phase) |
58 | { | 57 | { |
59 | QCanvasSprite::advance(phase); | 58 | QCanvasSprite::advance(phase); |
60 | if (phase == 0) { | 59 | if (phase == 0) { |
61 | if (frame() == 3) { | 60 | if (frame() == 3) { |
62 | delete this; | 61 | delete this; |
63 | return; | 62 | return; |
64 | } | 63 | } |
65 | 64 | ||
66 | if (hits >= 2) { | 65 | if (hits >= 2) { |
67 | setFrame(3); | 66 | setFrame(3); |
68 | } else { | 67 | } else { |
69 | setFrame(fr%3); | 68 | setFrame(fr%3); |
70 | fr++; | 69 | fr++; |
71 | checkCollision(); | 70 | checkCollision(); |
72 | } | 71 | } |
73 | } | 72 | } |
74 | } | 73 | } |
75 | 74 | ||
76 | void Helicopter::checkCollision() | 75 | void Helicopter::checkCollision() |
77 | { | 76 | { |
78 | if (x() == 6) { | 77 | if (x() == 6) { |
79 | setAnimated(false); //setVelocity(0, 0); | 78 | setAnimated(false); //setVelocity(0, 0); |
80 | dropman(); | 79 | dropman(); |
81 | } | 80 | } |
82 | if (x() < 0) | 81 | if (x() < 0) |
83 | done(); | 82 | done(); |
84 | } | 83 | } |
85 | 84 | ||
86 | void Helicopter::dropman() | 85 | void Helicopter::dropman() |
87 | { | 86 | { |
88 | (void)new Man(canvas(), 15, 25); | 87 | (void)new Man(canvas(), 15, 25); |
89 | (void)new Man(canvas(), 35, 25); | 88 | (void)new Man(canvas(), 35, 25); |
90 | takeOff(); | 89 | takeOff(); |
91 | } | 90 | } |
92 | 91 | ||
93 | void Helicopter::done() | 92 | void Helicopter::done() |
94 | { | 93 | { |
95 | hits++; | 94 | hits++; |
96 | } | 95 | } |
97 | 96 | ||
98 | void Helicopter::takeOff() | 97 | void Helicopter::takeOff() |
99 | { | 98 | { |
100 | setVelocity(-1, 0); | 99 | setVelocity(-1, 0); |
101 | } | 100 | } |
102 | 101 | ||
103 | int Helicopter::rtti() const | 102 | int Helicopter::rtti() const |
104 | { | 103 | { |
105 | return helicopter_rtti; | 104 | return helicopter_rtti; |
106 | } | 105 | } |
107 | 106 | ||
108 | void Helicopter::silenceAll() | 107 | void Helicopter::silenceAll() |
109 | { | 108 | { |
110 | for (Helicopter* h = all.first(); h; h = all.next()) | 109 | for (Helicopter* h = all.first(); h; h = all.next()) |
111 | h->chikachika.stop(); | 110 | h->chikachika.stop(); |
112 | } | 111 | } |
113 | 112 | ||
114 | void Helicopter::deleteAll() | 113 | void Helicopter::deleteAll() |
115 | { | 114 | { |
116 | Helicopter* h; | 115 | Helicopter* h; |
117 | while ((h = all.first())) | 116 | while ((h = all.first())) |
118 | delete h; | 117 | delete h; |
119 | } | 118 | } |
120 | 119 | ||
diff --git a/noncore/games/parashoot/interface.cpp b/noncore/games/parashoot/interface.cpp index 948b92c..5c9b0ef 100644 --- a/noncore/games/parashoot/interface.cpp +++ b/noncore/games/parashoot/interface.cpp | |||
@@ -1,282 +1,278 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "interface.h" | 21 | #include "interface.h" |
22 | #include "man.h" | 22 | #include "man.h" |
23 | 23 | ||
24 | #include <qtopia/qpeapplication.h> | 24 | #include <qtopia/qpeapplication.h> |
25 | #include <qtopia/resource.h> | 25 | #include <qtopia/resource.h> |
26 | 26 | ||
27 | #include <qlabel.h> | ||
28 | #include <qmessagebox.h> | ||
29 | #include <qapplication.h> | ||
30 | #include <qstyle.h> | ||
31 | #include <qtoolbar.h> | 27 | #include <qtoolbar.h> |
32 | #include <qtoolbutton.h> | 28 | #include <qtoolbutton.h> |
33 | 29 | ||
34 | ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) : | 30 | ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) : |
35 | QMainWindow(parent,name,f), | 31 | QMainWindow(parent,name,f), |
36 | canvas( 232, 258 ), | 32 | canvas( 232, 258 ), |
37 | cannon(NULL), | 33 | cannon(NULL), |
38 | base(NULL), | 34 | base(NULL), |
39 | gamestopped( true ), | 35 | gamestopped( true ), |
40 | waitover( false ), | 36 | waitover( false ), |
41 | fanfare("level_up"), | 37 | fanfare("level_up"), |
42 | score(0) | 38 | score(0) |
43 | { | 39 | { |
44 | QPEApplication::grabKeyboard(); | 40 | QPEApplication::grabKeyboard(); |
45 | QPEApplication::setInputMethodHint(this, QPEApplication::AlwaysOff ); | 41 | QPEApplication::setInputMethodHint(this, QPEApplication::AlwaysOff ); |
46 | 42 | ||
47 | updatespeed = 80; | 43 | updatespeed = 80; |
48 | canvas.setAdvancePeriod(80); | 44 | canvas.setAdvancePeriod(80); |
49 | 45 | ||
50 | pb = new QCanvasView(&canvas, this); | 46 | pb = new QCanvasView(&canvas, this); |
51 | pb->setFocus(); | 47 | pb->setFocus(); |
52 | 48 | ||
53 | setToolBarsMovable( FALSE ); | 49 | setToolBarsMovable( FALSE ); |
54 | 50 | ||
55 | QToolBar* toolbar = new QToolBar(this); | 51 | QToolBar* toolbar = new QToolBar(this); |
56 | toolbar->setHorizontalStretchable( TRUE ); | 52 | toolbar->setHorizontalStretchable( TRUE ); |
57 | 53 | ||
58 | setCaption( tr("ParaShoot") ); | 54 | setCaption( tr("ParaShoot") ); |
59 | new QToolButton( Resource::loadIconSet("new"), tr("New Game"), 0, | 55 | new QToolButton( Resource::loadIconSet("new"), tr("New Game"), 0, |
60 | this, SLOT(newGame()), toolbar, "New Game"); | 56 | this, SLOT(newGame()), toolbar, "New Game"); |
61 | 57 | ||
62 | levelscore = new QLabel(toolbar); | 58 | levelscore = new QLabel(toolbar); |
63 | levelscore->setBackgroundMode( PaletteButton ); | 59 | levelscore->setBackgroundMode( PaletteButton ); |
64 | levelscore->setAlignment( AlignRight | AlignVCenter | ExpandTabs ); | 60 | levelscore->setAlignment( AlignRight | AlignVCenter | ExpandTabs ); |
65 | toolbar->setStretchableWidget( levelscore ); | 61 | toolbar->setStretchableWidget( levelscore ); |
66 | showScore(0,0); | 62 | showScore(0,0); |
67 | 63 | ||
68 | setCentralWidget(pb); | 64 | setCentralWidget(pb); |
69 | 65 | ||
70 | autoDropTimer = new QTimer(this); | 66 | autoDropTimer = new QTimer(this); |
71 | connect (autoDropTimer, SIGNAL(timeout()), this, SLOT(play()) ); | 67 | connect (autoDropTimer, SIGNAL(timeout()), this, SLOT(play()) ); |
72 | 68 | ||
73 | pauseTimer = new QTimer(this); | 69 | pauseTimer = new QTimer(this); |
74 | connect(pauseTimer, SIGNAL(timeout()), this, SLOT(wait()) ); | 70 | connect(pauseTimer, SIGNAL(timeout()), this, SLOT(wait()) ); |
75 | 71 | ||
76 | setFocusPolicy(StrongFocus); | 72 | setFocusPolicy(StrongFocus); |
77 | } | 73 | } |
78 | 74 | ||
79 | 75 | ||
80 | void ParaShoot::resizeEvent(QResizeEvent *) | 76 | void ParaShoot::resizeEvent(QResizeEvent *) |
81 | { | 77 | { |
82 | QSize s = centralWidget()->size(); | 78 | QSize s = centralWidget()->size(); |
83 | int fw = style().defaultFrameWidth(); | 79 | int fw = style().defaultFrameWidth(); |
84 | canvas.resize( s.width() - fw - 2, s.height() - fw - 2); | 80 | canvas.resize( s.width() - fw - 2, s.height() - fw - 2); |
85 | 81 | ||
86 | QImage bgimage = Resource::loadImage("parashoot/sky"); | 82 | QImage bgimage = Resource::loadImage("parashoot/sky"); |
87 | QPixmap bgpixmap; | 83 | QPixmap bgpixmap; |
88 | 84 | ||
89 | bgpixmap.convertFromImage(bgimage.smoothScale(canvas.width(), | 85 | bgpixmap.convertFromImage(bgimage.smoothScale(canvas.width(), |
90 | canvas.height()), QPixmap::Auto); | 86 | canvas.height()), QPixmap::Auto); |
91 | canvas.setBackgroundPixmap(bgpixmap); | 87 | canvas.setBackgroundPixmap(bgpixmap); |
92 | 88 | ||
93 | if (base) { | 89 | if (base) { |
94 | base->reposition(); | 90 | base->reposition(); |
95 | } | 91 | } |
96 | 92 | ||
97 | if (cannon) { | 93 | if (cannon) { |
98 | cannon->reposition(); | 94 | cannon->reposition(); |
99 | } | 95 | } |
100 | } | 96 | } |
101 | 97 | ||
102 | void ParaShoot::focusOutEvent (QFocusEvent *) | 98 | void ParaShoot::focusOutEvent (QFocusEvent *) |
103 | { | 99 | { |
104 | if (!gamestopped) | 100 | if (!gamestopped) |
105 | canvas.setAdvancePeriod(-1); | 101 | canvas.setAdvancePeriod(-1); |
106 | } | 102 | } |
107 | 103 | ||
108 | void ParaShoot::focusInEvent (QFocusEvent *) | 104 | void ParaShoot::focusInEvent (QFocusEvent *) |
109 | { | 105 | { |
110 | if (!gamestopped) | 106 | if (!gamestopped) |
111 | canvas.setAdvancePeriod(updatespeed); | 107 | canvas.setAdvancePeriod(updatespeed); |
112 | } | 108 | } |
113 | 109 | ||
114 | void ParaShoot::showScore( int score, int level ) | 110 | void ParaShoot::showScore( int score, int level ) |
115 | { | 111 | { |
116 | levelscore->setText(tr(" Level: %1 Score: %2 ").arg(score).arg(level) ); | 112 | levelscore->setText(tr(" Level: %1 Score: %2 ").arg(score).arg(level) ); |
117 | } | 113 | } |
118 | 114 | ||
119 | 115 | ||
120 | void ParaShoot::newGame() | 116 | void ParaShoot::newGame() |
121 | { | 117 | { |
122 | clear(); | 118 | clear(); |
123 | if (pauseTimer->isActive()) | 119 | if (pauseTimer->isActive()) |
124 | pauseTimer->stop(); | 120 | pauseTimer->stop(); |
125 | clear(); | 121 | clear(); |
126 | Man::setManCount(0); | 122 | Man::setManCount(0); |
127 | score = 0; | 123 | score = 0; |
128 | Bullet::setShotCount(0); | 124 | Bullet::setShotCount(0); |
129 | Bullet::setNobullets(0); | 125 | Bullet::setNobullets(0); |
130 | nomen = 2; | 126 | nomen = 2; |
131 | Bullet::setLimit(nomen); | 127 | Bullet::setLimit(nomen); |
132 | level = 0; | 128 | level = 0; |
133 | updatespeed = 80; | 129 | updatespeed = 80; |
134 | showScore(0,0); | 130 | showScore(0,0); |
135 | gamestopped = false; | 131 | gamestopped = false; |
136 | Helicopter::deleteAll(); | 132 | Helicopter::deleteAll(); |
137 | waitover = true; | 133 | waitover = true; |
138 | base = new Base(&canvas); | 134 | base = new Base(&canvas); |
139 | cannon = new Cannon(&canvas); | 135 | cannon = new Cannon(&canvas); |
140 | connect( cannon, SIGNAL(score(int)), this, SLOT(increaseScore(int))); | 136 | connect( cannon, SIGNAL(score(int)), this, SLOT(increaseScore(int))); |
141 | autoDropTimer->start(100); | 137 | autoDropTimer->start(100); |
142 | } | 138 | } |
143 | 139 | ||
144 | 140 | ||
145 | void ParaShoot::clear() | 141 | void ParaShoot::clear() |
146 | { | 142 | { |
147 | autoDropTimer->stop(); | 143 | autoDropTimer->stop(); |
148 | // QCanvasItem* item; | 144 | // QCanvasItem* item; |
149 | QCanvasItemList l = canvas.allItems(); | 145 | QCanvasItemList l = canvas.allItems(); |
150 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { | 146 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { |
151 | delete *it; | 147 | delete *it; |
152 | } | 148 | } |
153 | } | 149 | } |
154 | 150 | ||
155 | void ParaShoot::gameOver() | 151 | void ParaShoot::gameOver() |
156 | { | 152 | { |
157 | QCanvasItem* item; | 153 | QCanvasItem* item; |
158 | QCanvasItemList l = canvas.allItems(); | 154 | QCanvasItemList l = canvas.allItems(); |
159 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { | 155 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { |
160 | item = *it; | 156 | item = *it; |
161 | if ((item->rtti()==1500) || (item->rtti()==1600) || item->rtti()==1900) | 157 | if ((item->rtti()==1500) || (item->rtti()==1600) || item->rtti()==1900) |
162 | item->setAnimated(false); | 158 | item->setAnimated(false); |
163 | } | 159 | } |
164 | autoDropTimer->stop(); | 160 | autoDropTimer->stop(); |
165 | Helicopter::silenceAll(); | 161 | Helicopter::silenceAll(); |
166 | 162 | ||
167 | int shots = Bullet::getShotCount(); | 163 | int shots = Bullet::getShotCount(); |
168 | 164 | ||
169 | int shotsFired = cannon->shotsFired(); | 165 | int shotsFired = cannon->shotsFired(); |
170 | if ( shotsFired == 0 ) | 166 | if ( shotsFired == 0 ) |
171 | shotsFired = 1; | 167 | shotsFired = 1; |
172 | QCanvasText* gameover = new QCanvasText( | 168 | QCanvasText* gameover = new QCanvasText( |
173 | tr( " GAME OVER!\n" | 169 | tr( " GAME OVER!\n" |
174 | " Your Score: %1\n" | 170 | " Your Score: %1\n" |
175 | " Parachuters Killed: %2\n" | 171 | " Parachuters Killed: %2\n" |
176 | " Accuracy: %3% " ).arg(score).arg(shots).arg(shots * 100 / shotsFired ), | 172 | " Accuracy: %3% " ).arg(score).arg(shots).arg(shots * 100 / shotsFired ), |
177 | &canvas); | 173 | &canvas); |
178 | gameover->setColor(red); | 174 | gameover->setColor(red); |
179 | gameover->setFont( QFont("times", 16, QFont::Bold) ); | 175 | gameover->setFont( QFont("times", 16, QFont::Bold) ); |
180 | gameover->move((canvas.width() - gameover->boundingRect().width()) / 2, | 176 | gameover->move((canvas.width() - gameover->boundingRect().width()) / 2, |
181 | (canvas.height() - gameover->boundingRect().height()) / 2); | 177 | (canvas.height() - gameover->boundingRect().height()) / 2); |
182 | gameover->setZ(500); | 178 | gameover->setZ(500); |
183 | gameover->show(); | 179 | gameover->show(); |
184 | gamestopped = true; | 180 | gamestopped = true; |
185 | waitover = false; | 181 | waitover = false; |
186 | pauseTimer->start(3000); | 182 | pauseTimer->start(3000); |
187 | } | 183 | } |
188 | 184 | ||
189 | void ParaShoot::wait() | 185 | void ParaShoot::wait() |
190 | { | 186 | { |
191 | waitover = true; | 187 | waitover = true; |
192 | pauseTimer->stop(); | 188 | pauseTimer->stop(); |
193 | } | 189 | } |
194 | 190 | ||
195 | void ParaShoot::play() | 191 | void ParaShoot::play() |
196 | { | 192 | { |
197 | if (Man::getManCount() < nomen ) { | 193 | if (Man::getManCount() < nomen ) { |
198 | new Man(&canvas); | 194 | new Man(&canvas); |
199 | } | 195 | } |
200 | if (Base::baseDestroyed()) { | 196 | if (Base::baseDestroyed()) { |
201 | gameOver(); | 197 | gameOver(); |
202 | return; | 198 | return; |
203 | } | 199 | } |
204 | } | 200 | } |
205 | 201 | ||
206 | void ParaShoot::increaseScore(int x) | 202 | void ParaShoot::increaseScore(int x) |
207 | { | 203 | { |
208 | score += x; | 204 | score += x; |
209 | if ( score / 150 != (score-x) / 150 ) | 205 | if ( score / 150 != (score-x) / 150 ) |
210 | levelUp(); | 206 | levelUp(); |
211 | showScore(level,score); | 207 | showScore(level,score); |
212 | } | 208 | } |
213 | 209 | ||
214 | void ParaShoot::levelUp() | 210 | void ParaShoot::levelUp() |
215 | { | 211 | { |
216 | level++; | 212 | level++; |
217 | int stage = level % 3; | 213 | int stage = level % 3; |
218 | switch(stage) { | 214 | switch(stage) { |
219 | case 0: | 215 | case 0: |
220 | nomen++; | 216 | nomen++; |
221 | Bullet::setLimit(nomen); | 217 | Bullet::setLimit(nomen); |
222 | fanfare.play(); | 218 | fanfare.play(); |
223 | break; | 219 | break; |
224 | case 1: | 220 | case 1: |
225 | new Helicopter(&canvas); | 221 | new Helicopter(&canvas); |
226 | break; | 222 | break; |
227 | case 2: | 223 | case 2: |
228 | moveFaster(); | 224 | moveFaster(); |
229 | fanfare.play(); | 225 | fanfare.play(); |
230 | break; | 226 | break; |
231 | default: return; | 227 | default: return; |
232 | } | 228 | } |
233 | } | 229 | } |
234 | 230 | ||
235 | void ParaShoot::moveFaster() | 231 | void ParaShoot::moveFaster() |
236 | { | 232 | { |
237 | if (updatespeed > 50) | 233 | if (updatespeed > 50) |
238 | updatespeed = updatespeed-5; | 234 | updatespeed = updatespeed-5; |
239 | else | 235 | else |
240 | updatespeed = updatespeed-3; | 236 | updatespeed = updatespeed-3; |
241 | canvas.setAdvancePeriod(updatespeed); | 237 | canvas.setAdvancePeriod(updatespeed); |
242 | } | 238 | } |
243 | 239 | ||
244 | void ParaShoot::keyPressEvent(QKeyEvent* event) | 240 | void ParaShoot::keyPressEvent(QKeyEvent* event) |
245 | { | 241 | { |
246 | if (gamestopped) { | 242 | if (gamestopped) { |
247 | if (waitover) | 243 | if (waitover) |
248 | newGame(); | 244 | newGame(); |
249 | else | 245 | else |
250 | return; | 246 | return; |
251 | } else { | 247 | } else { |
252 | switch(event->key()) { | 248 | switch(event->key()) { |
253 | case Key_Up: | 249 | case Key_Up: |
254 | case Key_F1: | 250 | case Key_F1: |
255 | case Key_F9: | 251 | case Key_F9: |
256 | case Key_Space: | 252 | case Key_Space: |
257 | if ( cannon ) | 253 | if ( cannon ) |
258 | cannon->shoot(); | 254 | cannon->shoot(); |
259 | break; | 255 | break; |
260 | case Key_Left:{ | 256 | case Key_Left:{ |
261 | if (cannon ) | 257 | if (cannon ) |
262 | cannon->pointCannon(Cannon::Left); | 258 | cannon->pointCannon(Cannon::Left); |
263 | lastcannonkey=Key_Left; | 259 | lastcannonkey=Key_Left; |
264 | break; | 260 | break; |
265 | } | 261 | } |
266 | case Key_Right:{ | 262 | case Key_Right:{ |
267 | if ( cannon ) | 263 | if ( cannon ) |
268 | cannon->pointCannon(Cannon::Right); | 264 | cannon->pointCannon(Cannon::Right); |
269 | lastcannonkey=Key_Right; | 265 | lastcannonkey=Key_Right; |
270 | break; | 266 | break; |
271 | } | 267 | } |
272 | default: | 268 | default: |
273 | return; | 269 | return; |
274 | } | 270 | } |
275 | } | 271 | } |
276 | } | 272 | } |
277 | 273 | ||
278 | void ParaShoot::keyReleaseEvent(QKeyEvent* event) | 274 | void ParaShoot::keyReleaseEvent(QKeyEvent* event) |
279 | { | 275 | { |
280 | if ( cannon && lastcannonkey == event->key() ) | 276 | if ( cannon && lastcannonkey == event->key() ) |
281 | cannon->pointCannon(Cannon::NoDir); | 277 | cannon->pointCannon(Cannon::NoDir); |
282 | } | 278 | } |
diff --git a/noncore/games/parashoot/main.cpp b/noncore/games/parashoot/main.cpp index ee36d26..40f809f 100644 --- a/noncore/games/parashoot/main.cpp +++ b/noncore/games/parashoot/main.cpp | |||
@@ -1,27 +1,26 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "interface.h" | 21 | #include "interface.h" |
22 | 22 | ||
23 | #include <qpe/qpeapplication.h> | ||
24 | #include <opie/oapplicationfactory.h> | 23 | #include <opie/oapplicationfactory.h> |
25 | 24 | ||
26 | OPIE_EXPORT_APP( OApplicationFactory<ParaShoot> ) | 25 | OPIE_EXPORT_APP( OApplicationFactory<ParaShoot> ) |
27 | 26 | ||
diff --git a/noncore/games/parashoot/man.cpp b/noncore/games/parashoot/man.cpp index 94807c2..0a151b0 100644 --- a/noncore/games/parashoot/man.cpp +++ b/noncore/games/parashoot/man.cpp | |||
@@ -1,191 +1,190 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "codes.h" | 21 | #include "codes.h" |
22 | #include "man.h" | 22 | #include "man.h" |
23 | #include "base.h" | 23 | #include "base.h" |
24 | 24 | ||
25 | #include <qtopia/resource.h> | 25 | #include <qtopia/resource.h> |
26 | 26 | ||
27 | #include <qregexp.h> | ||
28 | 27 | ||
29 | int mancount; | 28 | int mancount; |
30 | 29 | ||
31 | Man::Man(QCanvas* canvas) : | 30 | Man::Man(QCanvas* canvas) : |
32 | QCanvasSprite(0, canvas), | 31 | QCanvasSprite(0, canvas), |
33 | splat("lose") // No tr | 32 | splat("lose") // No tr |
34 | { | 33 | { |
35 | manarray = new QCanvasPixmapArray(); | 34 | manarray = new QCanvasPixmapArray(); |
36 | QString m0 = Resource::findPixmap("parashoot/man0001"); | 35 | QString m0 = Resource::findPixmap("parashoot/man0001"); |
37 | m0.replace(QRegExp("0001"),"%1"); | 36 | m0.replace(QRegExp("0001"),"%1"); |
38 | manarray->readPixmaps(m0, 7); | 37 | manarray->readPixmaps(m0, 7); |
39 | setSequence(manarray); | 38 | setSequence(manarray); |
40 | setAnimated(true); | 39 | setAnimated(true); |
41 | mancount++; | 40 | mancount++; |
42 | dead = false; | 41 | dead = false; |
43 | start(); | 42 | start(); |
44 | } | 43 | } |
45 | 44 | ||
46 | Man::Man(QCanvas* canvas, int x, int y) : | 45 | Man::Man(QCanvas* canvas, int x, int y) : |
47 | QCanvasSprite(0, canvas), | 46 | QCanvasSprite(0, canvas), |
48 | splat("bang") // No tr | 47 | splat("bang") // No tr |
49 | { | 48 | { |
50 | manarray = new QCanvasPixmapArray(); | 49 | manarray = new QCanvasPixmapArray(); |
51 | QString m0 = Resource::findPixmap("parashoot/man0001"); | 50 | QString m0 = Resource::findPixmap("parashoot/man0001"); |
52 | m0.replace(QString("0001"),"%1"); | 51 | m0.replace(QString("0001"),"%1"); |
53 | manarray->readPixmaps(m0, 7); | 52 | manarray->readPixmaps(m0, 7); |
54 | setSequence(manarray); | 53 | setSequence(manarray); |
55 | move(x, y); | 54 | move(x, y); |
56 | setFrame(5); | 55 | setFrame(5); |
57 | setZ(300); | 56 | setZ(300); |
58 | show(); | 57 | show(); |
59 | 58 | ||
60 | static bool first_time = TRUE; | 59 | static bool first_time = TRUE; |
61 | if (first_time) { | 60 | if (first_time) { |
62 | first_time = FALSE; | 61 | first_time = FALSE; |
63 | QTime midnight(0, 0, 0); | 62 | QTime midnight(0, 0, 0); |
64 | srand(midnight.secsTo(QTime::currentTime()) ); | 63 | srand(midnight.secsTo(QTime::currentTime()) ); |
65 | } | 64 | } |
66 | int yfallspeed = 0; | 65 | int yfallspeed = 0; |
67 | yfallspeed = (rand() % 3) + 1; | 66 | yfallspeed = (rand() % 3) + 1; |
68 | setVelocity(0, yfallspeed); | 67 | setVelocity(0, yfallspeed); |
69 | 68 | ||
70 | mancount++; | 69 | mancount++; |
71 | dead = false; | 70 | dead = false; |
72 | } | 71 | } |
73 | int f = 0; | 72 | int f = 0; |
74 | 73 | ||
75 | void Man::advance(int phase) | 74 | void Man::advance(int phase) |
76 | { | 75 | { |
77 | QCanvasSprite::advance(phase); | 76 | QCanvasSprite::advance(phase); |
78 | if (phase == 0) { | 77 | if (phase == 0) { |
79 | checkCollision(); | 78 | checkCollision(); |
80 | if (dead) { | 79 | if (dead) { |
81 | if (count < 10) { | 80 | if (count < 10) { |
82 | setFrame(6); | 81 | setFrame(6); |
83 | setVelocity(0,0); | 82 | setVelocity(0,0); |
84 | count++; | 83 | count++; |
85 | } else { | 84 | } else { |
86 | delete this; | 85 | delete this; |
87 | return; | 86 | return; |
88 | } | 87 | } |
89 | } | 88 | } |
90 | if (y() > canvas()->height()-43) { | 89 | if (y() > canvas()->height()-43) { |
91 | setFrame(f%5); | 90 | setFrame(f%5); |
92 | f++; | 91 | f++; |
93 | move(x(), canvas()->height()-26); | 92 | move(x(), canvas()->height()-26); |
94 | setVelocity(-2, 0); | 93 | setVelocity(-2, 0); |
95 | } else if (xVelocity() == -2) { | 94 | } else if (xVelocity() == -2) { |
96 | // | 95 | // |
97 | // There's been a resize event while this Man has | 96 | // There's been a resize event while this Man has |
98 | // been on the ground. Move the man back to the | 97 | // been on the ground. Move the man back to the |
99 | // new ground location. This is not neat. | 98 | // new ground location. This is not neat. |
100 | // | 99 | // |
101 | move(x(), canvas()->height()-26); | 100 | move(x(), canvas()->height()-26); |
102 | } | 101 | } |
103 | } | 102 | } |
104 | } | 103 | } |
105 | 104 | ||
106 | void Man::setInitialCoords() | 105 | void Man::setInitialCoords() |
107 | { | 106 | { |
108 | static bool first_time = TRUE; | 107 | static bool first_time = TRUE; |
109 | if (first_time) { | 108 | if (first_time) { |
110 | first_time = FALSE; | 109 | first_time = FALSE; |
111 | QTime midnight(0, 0, 0); | 110 | QTime midnight(0, 0, 0); |
112 | srand(midnight.secsTo(QTime::currentTime()) ); | 111 | srand(midnight.secsTo(QTime::currentTime()) ); |
113 | } | 112 | } |
114 | dx = rand() % (canvas()->width()-16); | 113 | dx = rand() % (canvas()->width()-16); |
115 | dy = -43; //height of a man off the screen | 114 | dy = -43; //height of a man off the screen |
116 | } | 115 | } |
117 | 116 | ||
118 | //check if man has reached the base | 117 | //check if man has reached the base |
119 | void Man::checkCollision() | 118 | void Man::checkCollision() |
120 | { | 119 | { |
121 | if ( (x() < 23) && (y() == canvas()->height()-26)) { | 120 | if ( (x() < 23) && (y() == canvas()->height()-26)) { |
122 | QCanvasItem* item; | 121 | QCanvasItem* item; |
123 | QCanvasItemList l=collisions(FALSE); | 122 | QCanvasItemList l=collisions(FALSE); |
124 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { | 123 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { |
125 | item = *it; | 124 | item = *it; |
126 | if ( (item->rtti()== 1800) && (item->collidesWith(this)) ) { | 125 | if ( (item->rtti()== 1800) && (item->collidesWith(this)) ) { |
127 | Base* base = (Base*) item; | 126 | Base* base = (Base*) item; |
128 | base->damageBase(); | 127 | base->damageBase(); |
129 | start(); | 128 | start(); |
130 | } | 129 | } |
131 | } | 130 | } |
132 | } | 131 | } |
133 | 132 | ||
134 | // | 133 | // |
135 | // resize events may cause Man objects to appear | 134 | // resize events may cause Man objects to appear |
136 | // outside the screen. Get rid of them if this | 135 | // outside the screen. Get rid of them if this |
137 | // is the case. | 136 | // is the case. |
138 | // | 137 | // |
139 | if ((x() < 0) || (x() > canvas()->width())) { | 138 | if ((x() < 0) || (x() > canvas()->width())) { |
140 | delete this; | 139 | delete this; |
141 | return; | 140 | return; |
142 | } | 141 | } |
143 | } | 142 | } |
144 | 143 | ||
145 | void Man::start() | 144 | void Man::start() |
146 | { | 145 | { |
147 | setInitialCoords(); | 146 | setInitialCoords(); |
148 | move(dx, dy); | 147 | move(dx, dy); |
149 | setFrame(5); | 148 | setFrame(5); |
150 | setZ(300); | 149 | setZ(300); |
151 | show(); | 150 | show(); |
152 | 151 | ||
153 | static bool first_time = TRUE; | 152 | static bool first_time = TRUE; |
154 | if (first_time) { | 153 | if (first_time) { |
155 | first_time = FALSE; | 154 | first_time = FALSE; |
156 | QTime midnight(0, 0, 0); | 155 | QTime midnight(0, 0, 0); |
157 | srand(midnight.secsTo(QTime::currentTime()) ); | 156 | srand(midnight.secsTo(QTime::currentTime()) ); |
158 | } | 157 | } |
159 | int yfallspeed = 0; | 158 | int yfallspeed = 0; |
160 | yfallspeed = (rand() % 3) + 1; | 159 | yfallspeed = (rand() % 3) + 1; |
161 | setVelocity(0, yfallspeed); | 160 | setVelocity(0, yfallspeed); |
162 | } | 161 | } |
163 | 162 | ||
164 | void Man::done() | 163 | void Man::done() |
165 | { | 164 | { |
166 | splat.play(); | 165 | splat.play(); |
167 | count = 0; | 166 | count = 0; |
168 | dead = true; | 167 | dead = true; |
169 | setFrame(6); | 168 | setFrame(6); |
170 | } | 169 | } |
171 | 170 | ||
172 | int Man::getManCount() | 171 | int Man::getManCount() |
173 | { | 172 | { |
174 | return mancount; | 173 | return mancount; |
175 | } | 174 | } |
176 | 175 | ||
177 | void Man::setManCount(int count) | 176 | void Man::setManCount(int count) |
178 | { | 177 | { |
179 | mancount = count; | 178 | mancount = count; |
180 | } | 179 | } |
181 | 180 | ||
182 | 181 | ||
183 | int Man::rtti() const | 182 | int Man::rtti() const |
184 | { | 183 | { |
185 | return man_rtti; | 184 | return man_rtti; |
186 | } | 185 | } |
187 | 186 | ||
188 | Man::~Man() | 187 | Man::~Man() |
189 | { | 188 | { |
190 | mancount--; | 189 | mancount--; |
191 | } | 190 | } |
diff --git a/noncore/games/qasteroids/main.cpp b/noncore/games/qasteroids/main.cpp index c762990..18a13eb 100644 --- a/noncore/games/qasteroids/main.cpp +++ b/noncore/games/qasteroids/main.cpp | |||
@@ -1,27 +1,26 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "toplevel.h" | 21 | #include "toplevel.h" |
22 | 22 | ||
23 | #include <qpe/qpeapplication.h> | ||
24 | #include <opie/oapplicationfactory.h> | 23 | #include <opie/oapplicationfactory.h> |
25 | 24 | ||
26 | 25 | ||
27 | OPIE_EXPORT_APP( OApplicationFactory<KAstTopLevel> ) | 26 | OPIE_EXPORT_APP( OApplicationFactory<KAstTopLevel> ) |
diff --git a/noncore/games/qasteroids/toplevel.cpp b/noncore/games/qasteroids/toplevel.cpp index c4fea89..9053d3d 100644 --- a/noncore/games/qasteroids/toplevel.cpp +++ b/noncore/games/qasteroids/toplevel.cpp | |||
@@ -1,535 +1,533 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************//* | 19 | **********************************************************************//* |
20 | * KAsteroids - Copyright (c) Martin R. Jones 1997 | 20 | * KAsteroids - Copyright (c) Martin R. Jones 1997 |
21 | * | 21 | * |
22 | * Part of the KDE project | 22 | * Part of the KDE project |
23 | */ | 23 | */ |
24 | //--- toplevel.cpp --- | 24 | //--- toplevel.cpp --- |
25 | 25 | ||
26 | #include "toplevel.h" | 26 | #include "toplevel.h" |
27 | #include "ledmeter.h" | 27 | #include "ledmeter.h" |
28 | 28 | ||
29 | #include <qpe/qpeapplication.h> | 29 | #include <qpe/qpeapplication.h> |
30 | #include <qpe/resource.h> | 30 | #include <qpe/resource.h> |
31 | 31 | ||
32 | #include <qaccel.h> | ||
33 | #include <qlabel.h> | 32 | #include <qlabel.h> |
34 | #include <qlayout.h> | 33 | #include <qlayout.h> |
35 | #include <qlcdnumber.h> | 34 | #include <qlcdnumber.h> |
36 | #include <qpushbutton.h> | ||
37 | 35 | ||
38 | #include <sys/utsname.h> | 36 | #include <sys/utsname.h> |
39 | 37 | ||
40 | 38 | ||
41 | #define SB_SCORE1 | 39 | #define SB_SCORE1 |
42 | #define SB_LEVEL2 | 40 | #define SB_LEVEL2 |
43 | #define SB_SHIPS3 | 41 | #define SB_SHIPS3 |
44 | 42 | ||
45 | struct SLevel | 43 | struct SLevel |
46 | { | 44 | { |
47 | int nrocks; | 45 | int nrocks; |
48 | double rockSpeed; | 46 | double rockSpeed; |
49 | }; | 47 | }; |
50 | 48 | ||
51 | #define MAX_LEVELS16 | 49 | #define MAX_LEVELS16 |
52 | 50 | ||
53 | SLevel levels[MAX_LEVELS] = | 51 | SLevel levels[MAX_LEVELS] = |
54 | { | 52 | { |
55 | { 1, 0.4 }, | 53 | { 1, 0.4 }, |
56 | { 1, 0.6 }, | 54 | { 1, 0.6 }, |
57 | { 2, 0.5 }, | 55 | { 2, 0.5 }, |
58 | { 2, 0.7 }, | 56 | { 2, 0.7 }, |
59 | { 2, 0.8 }, | 57 | { 2, 0.8 }, |
60 | { 3, 0.6 }, | 58 | { 3, 0.6 }, |
61 | { 3, 0.7 }, | 59 | { 3, 0.7 }, |
62 | { 3, 0.8 }, | 60 | { 3, 0.8 }, |
63 | { 4, 0.6 }, | 61 | { 4, 0.6 }, |
64 | { 4, 0.7 }, | 62 | { 4, 0.7 }, |
65 | { 4, 0.8 }, | 63 | { 4, 0.8 }, |
66 | { 5, 0.7 }, | 64 | { 5, 0.7 }, |
67 | { 5, 0.8 }, | 65 | { 5, 0.8 }, |
68 | { 5, 0.9 }, | 66 | { 5, 0.9 }, |
69 | { 5, 1.0 } | 67 | { 5, 1.0 } |
70 | }; | 68 | }; |
71 | 69 | ||
72 | const char *soundEvents[] = | 70 | const char *soundEvents[] = |
73 | { | 71 | { |
74 | "ShipDestroyed", | 72 | "ShipDestroyed", |
75 | "RockDestroyed", | 73 | "RockDestroyed", |
76 | 0 | 74 | 0 |
77 | }; | 75 | }; |
78 | 76 | ||
79 | const char *soundDefaults[] = | 77 | const char *soundDefaults[] = |
80 | { | 78 | { |
81 | "Explosion.wav", | 79 | "Explosion.wav", |
82 | "ploop.wav", | 80 | "ploop.wav", |
83 | 0 | 81 | 0 |
84 | }; | 82 | }; |
85 | 83 | ||
86 | 84 | ||
87 | KAstTopLevel::KAstTopLevel( QWidget *parent, const char *_name, WFlags fl ) | 85 | KAstTopLevel::KAstTopLevel( QWidget *parent, const char *_name, WFlags fl ) |
88 | : QMainWindow( parent, _name, fl ) | 86 | : QMainWindow( parent, _name, fl ) |
89 | { | 87 | { |
90 | setCaption( tr("Asteroids") ); | 88 | setCaption( tr("Asteroids") ); |
91 | 89 | ||
92 | QPEApplication::grabKeyboard(); | 90 | QPEApplication::grabKeyboard(); |
93 | 91 | ||
94 | QWidget *border = new QWidget( this ); | 92 | QWidget *border = new QWidget( this ); |
95 | border->setBackgroundColor( black ); | 93 | border->setBackgroundColor( black ); |
96 | setCentralWidget( border ); | 94 | setCentralWidget( border ); |
97 | 95 | ||
98 | QVBoxLayout *borderLayout = new QVBoxLayout( border ); | 96 | QVBoxLayout *borderLayout = new QVBoxLayout( border ); |
99 | 97 | ||
100 | QWidget *mainWin = new QWidget( border ); | 98 | QWidget *mainWin = new QWidget( border ); |
101 | borderLayout->addWidget( mainWin, 2, AlignHCenter ); | 99 | borderLayout->addWidget( mainWin, 2, AlignHCenter ); |
102 | 100 | ||
103 | view = new KAsteroidsView( mainWin ); | 101 | view = new KAsteroidsView( mainWin ); |
104 | connect( view, SIGNAL( shipKilled() ), SLOT( slotShipKilled() ) ); | 102 | connect( view, SIGNAL( shipKilled() ), SLOT( slotShipKilled() ) ); |
105 | connect( view, SIGNAL( rockHit(int) ), SLOT( slotRockHit(int) ) ); | 103 | connect( view, SIGNAL( rockHit(int) ), SLOT( slotRockHit(int) ) ); |
106 | connect( view, SIGNAL( rocksRemoved() ), SLOT( slotRocksRemoved() ) ); | 104 | connect( view, SIGNAL( rocksRemoved() ), SLOT( slotRocksRemoved() ) ); |
107 | connect( view, SIGNAL( updateVitals() ), SLOT( slotUpdateVitals() ) ); | 105 | connect( view, SIGNAL( updateVitals() ), SLOT( slotUpdateVitals() ) ); |
108 | 106 | ||
109 | QVBoxLayout *vb = new QVBoxLayout( mainWin ); | 107 | QVBoxLayout *vb = new QVBoxLayout( mainWin ); |
110 | QHBoxLayout *hb = new QHBoxLayout; | 108 | QHBoxLayout *hb = new QHBoxLayout; |
111 | QHBoxLayout *hbd = new QHBoxLayout; | 109 | QHBoxLayout *hbd = new QHBoxLayout; |
112 | vb->addLayout( hb ); | 110 | vb->addLayout( hb ); |
113 | 111 | ||
114 | QFont labelFont( "helvetica", 12 ); | 112 | QFont labelFont( "helvetica", 12 ); |
115 | QColorGroup grp( darkGreen, black, QColor( 128, 128, 128 ), | 113 | QColorGroup grp( darkGreen, black, QColor( 128, 128, 128 ), |
116 | QColor( 64, 64, 64 ), black, darkGreen, black ); | 114 | QColor( 64, 64, 64 ), black, darkGreen, black ); |
117 | QPalette pal( grp, grp, grp ); | 115 | QPalette pal( grp, grp, grp ); |
118 | 116 | ||
119 | mainWin->setPalette( pal ); | 117 | mainWin->setPalette( pal ); |
120 | 118 | ||
121 | QLabel *label; | 119 | QLabel *label; |
122 | label = new QLabel( tr("Score"), mainWin ); | 120 | label = new QLabel( tr("Score"), mainWin ); |
123 | label->setFont( labelFont ); | 121 | label->setFont( labelFont ); |
124 | label->setPalette( pal ); | 122 | label->setPalette( pal ); |
125 | // label->setFixedWidth( label->sizeHint().width() ); | 123 | // label->setFixedWidth( label->sizeHint().width() ); |
126 | hb->addWidget( label ); | 124 | hb->addWidget( label ); |
127 | 125 | ||
128 | scoreLCD = new QLCDNumber( 5, mainWin ); | 126 | scoreLCD = new QLCDNumber( 5, mainWin ); |
129 | scoreLCD->setFrameStyle( QFrame::NoFrame ); | 127 | scoreLCD->setFrameStyle( QFrame::NoFrame ); |
130 | scoreLCD->setSegmentStyle( QLCDNumber::Flat ); | 128 | scoreLCD->setSegmentStyle( QLCDNumber::Flat ); |
131 | scoreLCD->setFixedHeight( 16 ); | 129 | scoreLCD->setFixedHeight( 16 ); |
132 | scoreLCD->setPalette( pal ); | 130 | scoreLCD->setPalette( pal ); |
133 | hb->addWidget( scoreLCD ); | 131 | hb->addWidget( scoreLCD ); |
134 | hb->addStretch( 1 ); | 132 | hb->addStretch( 1 ); |
135 | 133 | ||
136 | label = new QLabel( tr("Level"), mainWin ); | 134 | label = new QLabel( tr("Level"), mainWin ); |
137 | label->setFont( labelFont ); | 135 | label->setFont( labelFont ); |
138 | label->setPalette( pal ); | 136 | label->setPalette( pal ); |
139 | // label->setFixedWidth( label->sizeHint().width() ); | 137 | // label->setFixedWidth( label->sizeHint().width() ); |
140 | hb->addWidget( label ); | 138 | hb->addWidget( label ); |
141 | 139 | ||
142 | levelLCD = new QLCDNumber( 2, mainWin ); | 140 | levelLCD = new QLCDNumber( 2, mainWin ); |
143 | levelLCD->setFrameStyle( QFrame::NoFrame ); | 141 | levelLCD->setFrameStyle( QFrame::NoFrame ); |
144 | levelLCD->setSegmentStyle( QLCDNumber::Flat ); | 142 | levelLCD->setSegmentStyle( QLCDNumber::Flat ); |
145 | levelLCD->setFixedHeight( 16 ); | 143 | levelLCD->setFixedHeight( 16 ); |
146 | levelLCD->setPalette( pal ); | 144 | levelLCD->setPalette( pal ); |
147 | hb->addWidget( levelLCD ); | 145 | hb->addWidget( levelLCD ); |
148 | hb->addStretch( 1 ); | 146 | hb->addStretch( 1 ); |
149 | 147 | ||
150 | label = new QLabel( tr("Ships"), mainWin ); | 148 | label = new QLabel( tr("Ships"), mainWin ); |
151 | label->setFont( labelFont ); | 149 | label->setFont( labelFont ); |
152 | // label->setFixedWidth( label->sizeHint().width() ); | 150 | // label->setFixedWidth( label->sizeHint().width() ); |
153 | label->setPalette( pal ); | 151 | label->setPalette( pal ); |
154 | hb->addWidget( label ); | 152 | hb->addWidget( label ); |
155 | 153 | ||
156 | shipsLCD = new QLCDNumber( 1, mainWin ); | 154 | shipsLCD = new QLCDNumber( 1, mainWin ); |
157 | shipsLCD->setFrameStyle( QFrame::NoFrame ); | 155 | shipsLCD->setFrameStyle( QFrame::NoFrame ); |
158 | shipsLCD->setSegmentStyle( QLCDNumber::Flat ); | 156 | shipsLCD->setSegmentStyle( QLCDNumber::Flat ); |
159 | shipsLCD->setFixedHeight( 16 ); | 157 | shipsLCD->setFixedHeight( 16 ); |
160 | shipsLCD->setPalette( pal ); | 158 | shipsLCD->setPalette( pal ); |
161 | hb->addWidget( shipsLCD ); | 159 | hb->addWidget( shipsLCD ); |
162 | 160 | ||
163 | // hb->addStrut( 14 ); | 161 | // hb->addStrut( 14 ); |
164 | 162 | ||
165 | vb->addWidget( view, 10 ); | 163 | vb->addWidget( view, 10 ); |
166 | 164 | ||
167 | // -- bottom layout: | 165 | // -- bottom layout: |
168 | vb->addLayout( hbd ); | 166 | vb->addLayout( hbd ); |
169 | 167 | ||
170 | QFont smallFont( "helvetica", 12 ); | 168 | QFont smallFont( "helvetica", 12 ); |
171 | hbd->addSpacing( 5 ); | 169 | hbd->addSpacing( 5 ); |
172 | 170 | ||
173 | /* | 171 | /* |
174 | label = new QLabel( tr( "T" ), mainWin ); | 172 | label = new QLabel( tr( "T" ), mainWin ); |
175 | label->setFont( smallFont ); | 173 | label->setFont( smallFont ); |
176 | label->setFixedWidth( label->sizeHint().width() ); | 174 | label->setFixedWidth( label->sizeHint().width() ); |
177 | label->setPalette( pal ); | 175 | label->setPalette( pal ); |
178 | hbd->addWidget( label ); | 176 | hbd->addWidget( label ); |
179 | 177 | ||
180 | teleportsLCD = new QLCDNumber( 1, mainWin ); | 178 | teleportsLCD = new QLCDNumber( 1, mainWin ); |
181 | teleportsLCD->setFrameStyle( QFrame::NoFrame ); | 179 | teleportsLCD->setFrameStyle( QFrame::NoFrame ); |
182 | teleportsLCD->setSegmentStyle( QLCDNumber::Flat ); | 180 | teleportsLCD->setSegmentStyle( QLCDNumber::Flat ); |
183 | teleportsLCD->setPalette( pal ); | 181 | teleportsLCD->setPalette( pal ); |
184 | teleportsLCD->setFixedHeight( 18 ); | 182 | teleportsLCD->setFixedHeight( 18 ); |
185 | hbd->addWidget( teleportsLCD ); | 183 | hbd->addWidget( teleportsLCD ); |
186 | 184 | ||
187 | hbd->addSpacing( 10 ); | 185 | hbd->addSpacing( 10 ); |
188 | */ | 186 | */ |
189 | label = new QLabel( mainWin ); | 187 | label = new QLabel( mainWin ); |
190 | label->setPixmap( Resource::loadPixmap("qasteroids/powerups/brake.png") ); | 188 | label->setPixmap( Resource::loadPixmap("qasteroids/powerups/brake.png") ); |
191 | label->setFixedWidth( 16 ); | 189 | label->setFixedWidth( 16 ); |
192 | label->setPalette( pal ); | 190 | label->setPalette( pal ); |
193 | hbd->addWidget( label ); | 191 | hbd->addWidget( label ); |
194 | 192 | ||
195 | brakesLCD = new QLCDNumber( 1, mainWin ); | 193 | brakesLCD = new QLCDNumber( 1, mainWin ); |
196 | brakesLCD->setFrameStyle( QFrame::NoFrame ); | 194 | brakesLCD->setFrameStyle( QFrame::NoFrame ); |
197 | brakesLCD->setSegmentStyle( QLCDNumber::Flat ); | 195 | brakesLCD->setSegmentStyle( QLCDNumber::Flat ); |
198 | brakesLCD->setPalette( pal ); | 196 | brakesLCD->setPalette( pal ); |
199 | brakesLCD->setFixedHeight( 16 ); | 197 | brakesLCD->setFixedHeight( 16 ); |
200 | hbd->addWidget( brakesLCD ); | 198 | hbd->addWidget( brakesLCD ); |
201 | 199 | ||
202 | hbd->addSpacing( 5 ); | 200 | hbd->addSpacing( 5 ); |
203 | 201 | ||
204 | label = new QLabel( mainWin ); | 202 | label = new QLabel( mainWin ); |
205 | label->setPixmap( Resource::loadPixmap("qasteroids/powerups/shield.png") ); | 203 | label->setPixmap( Resource::loadPixmap("qasteroids/powerups/shield.png") ); |
206 | label->setFixedWidth( 16 ); | 204 | label->setFixedWidth( 16 ); |
207 | label->setPalette( pal ); | 205 | label->setPalette( pal ); |
208 | hbd->addWidget( label ); | 206 | hbd->addWidget( label ); |
209 | 207 | ||
210 | shieldLCD = new QLCDNumber( 1, mainWin ); | 208 | shieldLCD = new QLCDNumber( 1, mainWin ); |
211 | shieldLCD->setFrameStyle( QFrame::NoFrame ); | 209 | shieldLCD->setFrameStyle( QFrame::NoFrame ); |
212 | shieldLCD->setSegmentStyle( QLCDNumber::Flat ); | 210 | shieldLCD->setSegmentStyle( QLCDNumber::Flat ); |
213 | shieldLCD->setPalette( pal ); | 211 | shieldLCD->setPalette( pal ); |
214 | shieldLCD->setFixedHeight( 16 ); | 212 | shieldLCD->setFixedHeight( 16 ); |
215 | hbd->addWidget( shieldLCD ); | 213 | hbd->addWidget( shieldLCD ); |
216 | 214 | ||
217 | hbd->addSpacing( 5 ); | 215 | hbd->addSpacing( 5 ); |
218 | 216 | ||
219 | label = new QLabel( mainWin ); | 217 | label = new QLabel( mainWin ); |
220 | label->setPixmap( Resource::loadPixmap("qasteroids/powerups/shoot.png") ); | 218 | label->setPixmap( Resource::loadPixmap("qasteroids/powerups/shoot.png") ); |
221 | label->setFixedWidth( 16 ); | 219 | label->setFixedWidth( 16 ); |
222 | label->setPalette( pal ); | 220 | label->setPalette( pal ); |
223 | hbd->addWidget( label ); | 221 | hbd->addWidget( label ); |
224 | 222 | ||
225 | shootLCD = new QLCDNumber( 1, mainWin ); | 223 | shootLCD = new QLCDNumber( 1, mainWin ); |
226 | shootLCD->setFrameStyle( QFrame::NoFrame ); | 224 | shootLCD->setFrameStyle( QFrame::NoFrame ); |
227 | shootLCD->setSegmentStyle( QLCDNumber::Flat ); | 225 | shootLCD->setSegmentStyle( QLCDNumber::Flat ); |
228 | shootLCD->setPalette( pal ); | 226 | shootLCD->setPalette( pal ); |
229 | shootLCD->setFixedHeight( 16 ); | 227 | shootLCD->setFixedHeight( 16 ); |
230 | hbd->addWidget( shootLCD ); | 228 | hbd->addWidget( shootLCD ); |
231 | 229 | ||
232 | hbd->addStretch( 1 ); | 230 | hbd->addStretch( 1 ); |
233 | 231 | ||
234 | label = new QLabel( tr( "Fuel" ), mainWin ); | 232 | label = new QLabel( tr( "Fuel" ), mainWin ); |
235 | label->setFont( smallFont ); | 233 | label->setFont( smallFont ); |
236 | label->setFixedWidth( label->sizeHint().width() + 5 ); | 234 | label->setFixedWidth( label->sizeHint().width() + 5 ); |
237 | label->setPalette( pal ); | 235 | label->setPalette( pal ); |
238 | hbd->addWidget( label ); | 236 | hbd->addWidget( label ); |
239 | 237 | ||
240 | powerMeter = new KALedMeter( mainWin ); | 238 | powerMeter = new KALedMeter( mainWin ); |
241 | powerMeter->setFrameStyle( QFrame::Box | QFrame::Plain ); | 239 | powerMeter->setFrameStyle( QFrame::Box | QFrame::Plain ); |
242 | powerMeter->setRange( MAX_POWER_LEVEL ); | 240 | powerMeter->setRange( MAX_POWER_LEVEL ); |
243 | powerMeter->addColorRange( 10, darkRed ); | 241 | powerMeter->addColorRange( 10, darkRed ); |
244 | powerMeter->addColorRange( 20, QColor(160, 96, 0) ); | 242 | powerMeter->addColorRange( 20, QColor(160, 96, 0) ); |
245 | powerMeter->addColorRange( 70, darkGreen ); | 243 | powerMeter->addColorRange( 70, darkGreen ); |
246 | powerMeter->setCount( 15 ); | 244 | powerMeter->setCount( 15 ); |
247 | powerMeter->setPalette( pal ); | 245 | powerMeter->setPalette( pal ); |
248 | powerMeter->setFixedSize( 60, 12 ); | 246 | powerMeter->setFixedSize( 60, 12 ); |
249 | hbd->addWidget( powerMeter ); | 247 | hbd->addWidget( powerMeter ); |
250 | 248 | ||
251 | shipsRemain = 3; | 249 | shipsRemain = 3; |
252 | showHiscores = FALSE; | 250 | showHiscores = FALSE; |
253 | 251 | ||
254 | actions.insert( Qt::Key_Up, Thrust ); | 252 | actions.insert( Qt::Key_Up, Thrust ); |
255 | actions.insert( Qt::Key_Left, RotateLeft ); | 253 | actions.insert( Qt::Key_Left, RotateLeft ); |
256 | actions.insert( Qt::Key_Right, RotateRight ); | 254 | actions.insert( Qt::Key_Right, RotateRight ); |
257 | actions.insert( Qt::Key_Enter, Shoot ); | 255 | actions.insert( Qt::Key_Enter, Shoot ); |
258 | actions.insert( Qt::Key_Z, Teleport ); | 256 | actions.insert( Qt::Key_Z, Teleport ); |
259 | actions.insert( Qt::Key_Down, Brake ); | 257 | actions.insert( Qt::Key_Down, Brake ); |
260 | actions.insert( Qt::Key_P, Pause ); | 258 | actions.insert( Qt::Key_P, Pause ); |
261 | 259 | ||
262 | 260 | ||
263 | struct utsname name; /* check for embedix kernel running on the zaurus, if | 261 | struct utsname name; /* check for embedix kernel running on the zaurus, if |
264 | lineo change string, this break | 262 | lineo change string, this break |
265 | */ | 263 | */ |
266 | if (uname(&name) != -1) { | 264 | if (uname(&name) != -1) { |
267 | QString release=name.release; | 265 | QString release=name.release; |
268 | if(release.find("embedix",0,TRUE) !=-1) { | 266 | if(release.find("embedix",0,TRUE) !=-1) { |
269 | actions.insert( Key_F12, Launch ); | 267 | actions.insert( Key_F12, Launch ); |
270 | actions.insert( Key_F11, Shield ); | 268 | actions.insert( Key_F11, Shield ); |
271 | actions.insert( Key_F9, NewGame ); | 269 | actions.insert( Key_F9, NewGame ); |
272 | } else { | 270 | } else { |
273 | // ipaq | 271 | // ipaq |
274 | actions.insert( Key_F12, Shoot ); | 272 | actions.insert( Key_F12, Shoot ); |
275 | actions.insert( Key_F11, Shield ); | 273 | actions.insert( Key_F11, Shield ); |
276 | actions.insert( Key_F10, Launch ); | 274 | actions.insert( Key_F10, Launch ); |
277 | actions.insert( Key_F9, NewGame ); | 275 | actions.insert( Key_F9, NewGame ); |
278 | } | 276 | } |
279 | } | 277 | } |
280 | 278 | ||
281 | // actions.insert( Qt::Key_S, Shield ); | 279 | // actions.insert( Qt::Key_S, Shield ); |
282 | // actions.insert( Qt::Key_X, Brake ); | 280 | // actions.insert( Qt::Key_X, Brake ); |
283 | // actions.insert( Qt::Key_L, Launch ); | 281 | // actions.insert( Qt::Key_L, Launch ); |
284 | actions.insert( Qt::Key_Space, Shoot ); | 282 | actions.insert( Qt::Key_Space, Shoot ); |
285 | 283 | ||
286 | view->showText( tr( "Press Calendar to start playing" ), yellow ); | 284 | view->showText( tr( "Press Calendar to start playing" ), yellow ); |
287 | 285 | ||
288 | setFocusPolicy( StrongFocus ); | 286 | setFocusPolicy( StrongFocus ); |
289 | 287 | ||
290 | slotNewGame(); | 288 | slotNewGame(); |
291 | } | 289 | } |
292 | 290 | ||
293 | KAstTopLevel::~KAstTopLevel() | 291 | KAstTopLevel::~KAstTopLevel() |
294 | { | 292 | { |
295 | } | 293 | } |
296 | 294 | ||
297 | void KAstTopLevel::playSound( const char * ) | 295 | void KAstTopLevel::playSound( const char * ) |
298 | { | 296 | { |
299 | } | 297 | } |
300 | 298 | ||
301 | void KAstTopLevel::keyPressEvent( QKeyEvent *event ) | 299 | void KAstTopLevel::keyPressEvent( QKeyEvent *event ) |
302 | { | 300 | { |
303 | if ( event->isAutoRepeat() || !actions.contains( event->key() ) ) | 301 | if ( event->isAutoRepeat() || !actions.contains( event->key() ) ) |
304 | { | 302 | { |
305 | event->ignore(); | 303 | event->ignore(); |
306 | return; | 304 | return; |
307 | } | 305 | } |
308 | 306 | ||
309 | Action a = actions[ event->key() ]; | 307 | Action a = actions[ event->key() ]; |
310 | 308 | ||
311 | switch ( a ) | 309 | switch ( a ) |
312 | { | 310 | { |
313 | case RotateLeft: | 311 | case RotateLeft: |
314 | view->rotateLeft( TRUE ); | 312 | view->rotateLeft( TRUE ); |
315 | break; | 313 | break; |
316 | 314 | ||
317 | case RotateRight: | 315 | case RotateRight: |
318 | view->rotateRight( TRUE ); | 316 | view->rotateRight( TRUE ); |
319 | break; | 317 | break; |
320 | 318 | ||
321 | case Thrust: | 319 | case Thrust: |
322 | view->thrust( TRUE ); | 320 | view->thrust( TRUE ); |
323 | break; | 321 | break; |
324 | 322 | ||
325 | case Shoot: | 323 | case Shoot: |
326 | view->shoot( TRUE ); | 324 | view->shoot( TRUE ); |
327 | break; | 325 | break; |
328 | 326 | ||
329 | case Shield: | 327 | case Shield: |
330 | view->setShield( TRUE ); | 328 | view->setShield( TRUE ); |
331 | break; | 329 | break; |
332 | 330 | ||
333 | case Teleport: | 331 | case Teleport: |
334 | view->teleport( TRUE ); | 332 | view->teleport( TRUE ); |
335 | break; | 333 | break; |
336 | 334 | ||
337 | case Brake: | 335 | case Brake: |
338 | view->brake( TRUE ); | 336 | view->brake( TRUE ); |
339 | break; | 337 | break; |
340 | 338 | ||
341 | default: | 339 | default: |
342 | event->ignore(); | 340 | event->ignore(); |
343 | return; | 341 | return; |
344 | } | 342 | } |
345 | event->accept(); | 343 | event->accept(); |
346 | } | 344 | } |
347 | 345 | ||
348 | void KAstTopLevel::keyReleaseEvent( QKeyEvent *event ) | 346 | void KAstTopLevel::keyReleaseEvent( QKeyEvent *event ) |
349 | { | 347 | { |
350 | if ( event->isAutoRepeat() || !actions.contains( event->key() ) ) | 348 | if ( event->isAutoRepeat() || !actions.contains( event->key() ) ) |
351 | { | 349 | { |
352 | event->ignore(); | 350 | event->ignore(); |
353 | return; | 351 | return; |
354 | } | 352 | } |
355 | 353 | ||
356 | Action a = actions[ event->key() ]; | 354 | Action a = actions[ event->key() ]; |
357 | 355 | ||
358 | switch ( a ) | 356 | switch ( a ) |
359 | { | 357 | { |
360 | case RotateLeft: | 358 | case RotateLeft: |
361 | view->rotateLeft( FALSE ); | 359 | view->rotateLeft( FALSE ); |
362 | break; | 360 | break; |
363 | 361 | ||
364 | case RotateRight: | 362 | case RotateRight: |
365 | view->rotateRight( FALSE ); | 363 | view->rotateRight( FALSE ); |
366 | break; | 364 | break; |
367 | 365 | ||
368 | case Thrust: | 366 | case Thrust: |
369 | view->thrust( FALSE ); | 367 | view->thrust( FALSE ); |
370 | break; | 368 | break; |
371 | 369 | ||
372 | case Shoot: | 370 | case Shoot: |
373 | view->shoot( FALSE ); | 371 | view->shoot( FALSE ); |
374 | break; | 372 | break; |
375 | 373 | ||
376 | case Brake: | 374 | case Brake: |
377 | view->brake( FALSE ); | 375 | view->brake( FALSE ); |
378 | break; | 376 | break; |
379 | 377 | ||
380 | case Shield: | 378 | case Shield: |
381 | view->setShield( FALSE ); | 379 | view->setShield( FALSE ); |
382 | break; | 380 | break; |
383 | 381 | ||
384 | case Teleport: | 382 | case Teleport: |
385 | view->teleport( FALSE ); | 383 | view->teleport( FALSE ); |
386 | break; | 384 | break; |
387 | 385 | ||
388 | case Launch: | 386 | case Launch: |
389 | if ( waitShip ) | 387 | if ( waitShip ) |
390 | { | 388 | { |
391 | view->newShip(); | 389 | view->newShip(); |
392 | waitShip = FALSE; | 390 | waitShip = FALSE; |
393 | view->hideText(); | 391 | view->hideText(); |
394 | } | 392 | } |
395 | else | 393 | else |
396 | { | 394 | { |
397 | event->ignore(); | 395 | event->ignore(); |
398 | return; | 396 | return; |
399 | } | 397 | } |
400 | break; | 398 | break; |
401 | 399 | ||
402 | case NewGame: | 400 | case NewGame: |
403 | slotNewGame(); | 401 | slotNewGame(); |
404 | break; | 402 | break; |
405 | /* | 403 | /* |
406 | case Pause: | 404 | case Pause: |
407 | { | 405 | { |
408 | view->pause( TRUE ); | 406 | view->pause( TRUE ); |
409 | QMessageBox::information( this, | 407 | QMessageBox::information( this, |
410 | tr("KAsteroids is paused"), | 408 | tr("KAsteroids is paused"), |
411 | tr("Paused") ); | 409 | tr("Paused") ); |
412 | view->pause( FALSE ); | 410 | view->pause( FALSE ); |
413 | } | 411 | } |
414 | break; | 412 | break; |
415 | */ | 413 | */ |
416 | default: | 414 | default: |
417 | event->ignore(); | 415 | event->ignore(); |
418 | return; | 416 | return; |
419 | } | 417 | } |
420 | 418 | ||
421 | event->accept(); | 419 | event->accept(); |
422 | } | 420 | } |
423 | 421 | ||
424 | void KAstTopLevel::showEvent( QShowEvent *e ) | 422 | void KAstTopLevel::showEvent( QShowEvent *e ) |
425 | { | 423 | { |
426 | QMainWindow::showEvent( e ); | 424 | QMainWindow::showEvent( e ); |
427 | view->pause( FALSE ); | 425 | view->pause( FALSE ); |
428 | setFocus(); | 426 | setFocus(); |
429 | } | 427 | } |
430 | 428 | ||
431 | void KAstTopLevel::hideEvent( QHideEvent *e ) | 429 | void KAstTopLevel::hideEvent( QHideEvent *e ) |
432 | { | 430 | { |
433 | QMainWindow::hideEvent( e ); | 431 | QMainWindow::hideEvent( e ); |
434 | view->pause( TRUE ); | 432 | view->pause( TRUE ); |
435 | } | 433 | } |
436 | 434 | ||
437 | void KAstTopLevel::focusInEvent( QFocusEvent * ) | 435 | void KAstTopLevel::focusInEvent( QFocusEvent * ) |
438 | { | 436 | { |
439 | view->pause( FALSE ); | 437 | view->pause( FALSE ); |
440 | setFocus(); | 438 | setFocus(); |
441 | } | 439 | } |
442 | 440 | ||
443 | void KAstTopLevel::focusOutEvent( QFocusEvent * ) | 441 | void KAstTopLevel::focusOutEvent( QFocusEvent * ) |
444 | { | 442 | { |
445 | view->pause( TRUE ); | 443 | view->pause( TRUE ); |
446 | } | 444 | } |
447 | 445 | ||
448 | void KAstTopLevel::slotNewGame() | 446 | void KAstTopLevel::slotNewGame() |
449 | { | 447 | { |
450 | shipsRemain = 3; | 448 | shipsRemain = 3; |
451 | score = 0; | 449 | score = 0; |
452 | scoreLCD->display( 0 ); | 450 | scoreLCD->display( 0 ); |
453 | level = 0; | 451 | level = 0; |
454 | levelLCD->display( level+1 ); | 452 | levelLCD->display( level+1 ); |
455 | shipsLCD->display( shipsRemain-1 ); | 453 | shipsLCD->display( shipsRemain-1 ); |
456 | view->newGame(); | 454 | view->newGame(); |
457 | view->setRockSpeed( levels[0].rockSpeed ); | 455 | view->setRockSpeed( levels[0].rockSpeed ); |
458 | view->addRocks( levels[0].nrocks ); | 456 | view->addRocks( levels[0].nrocks ); |
459 | view->newShip(); | 457 | view->newShip(); |
460 | waitShip = FALSE; | 458 | waitShip = FALSE; |
461 | view->hideText(); | 459 | view->hideText(); |
462 | isPaused = FALSE; | 460 | isPaused = FALSE; |
463 | } | 461 | } |
464 | 462 | ||
465 | void KAstTopLevel::slotShipKilled() | 463 | void KAstTopLevel::slotShipKilled() |
466 | { | 464 | { |
467 | shipsRemain--; | 465 | shipsRemain--; |
468 | shipsLCD->display( shipsRemain-1 ); | 466 | shipsLCD->display( shipsRemain-1 ); |
469 | 467 | ||
470 | playSound( "ShipDestroyed" ); | 468 | playSound( "ShipDestroyed" ); |
471 | 469 | ||
472 | if ( shipsRemain > 0 ) | 470 | if ( shipsRemain > 0 ) |
473 | { | 471 | { |
474 | waitShip = TRUE; | 472 | waitShip = TRUE; |
475 | view->showText( tr( "Ship Destroyed.\nPress Contacts/Home key."), yellow ); | 473 | view->showText( tr( "Ship Destroyed.\nPress Contacts/Home key."), yellow ); |
476 | } | 474 | } |
477 | else | 475 | else |
478 | { | 476 | { |
479 | view->endGame(); | 477 | view->endGame(); |
480 | doStats(); | 478 | doStats(); |
481 | } | 479 | } |
482 | } | 480 | } |
483 | 481 | ||
484 | void KAstTopLevel::slotRockHit( int size ) | 482 | void KAstTopLevel::slotRockHit( int size ) |
485 | { | 483 | { |
486 | switch ( size ) | 484 | switch ( size ) |
487 | { | 485 | { |
488 | case 0: | 486 | case 0: |
489 | score += 10; | 487 | score += 10; |
490 | break; | 488 | break; |
491 | 489 | ||
492 | case 1: | 490 | case 1: |
493 | score += 20; | 491 | score += 20; |
494 | break; | 492 | break; |
495 | 493 | ||
496 | default: | 494 | default: |
497 | score += 40; | 495 | score += 40; |
498 | } | 496 | } |
499 | 497 | ||
500 | playSound( "RockDestroyed" ); | 498 | playSound( "RockDestroyed" ); |
501 | 499 | ||
502 | scoreLCD->display( score ); | 500 | scoreLCD->display( score ); |
503 | } | 501 | } |
504 | 502 | ||
505 | void KAstTopLevel::slotRocksRemoved() | 503 | void KAstTopLevel::slotRocksRemoved() |
506 | { | 504 | { |
507 | level++; | 505 | level++; |
508 | 506 | ||
509 | if ( level >= MAX_LEVELS ) | 507 | if ( level >= MAX_LEVELS ) |
510 | level = MAX_LEVELS - 1; | 508 | level = MAX_LEVELS - 1; |
511 | 509 | ||
512 | view->setRockSpeed( levels[level-1].rockSpeed ); | 510 | view->setRockSpeed( levels[level-1].rockSpeed ); |
513 | view->addRocks( levels[level-1].nrocks ); | 511 | view->addRocks( levels[level-1].nrocks ); |
514 | 512 | ||
515 | levelLCD->display( level+1 ); | 513 | levelLCD->display( level+1 ); |
516 | } | 514 | } |
517 | 515 | ||
518 | void KAstTopLevel::doStats() | 516 | void KAstTopLevel::doStats() |
519 | { | 517 | { |
520 | QString r( "0.00" ); | 518 | QString r( "0.00" ); |
521 | if ( view->shots() ) | 519 | if ( view->shots() ) |
522 | r = QString::number( (double)view->hits() / view->shots() * 100.0, | 520 | r = QString::number( (double)view->hits() / view->shots() * 100.0, |
523 | 'g', 2 ); | 521 | 'g', 2 ); |
524 | 522 | ||
525 | view->showText( tr( "Game Over.\nPress Calendar for a new game." ), yellow, FALSE ); | 523 | view->showText( tr( "Game Over.\nPress Calendar for a new game." ), yellow, FALSE ); |
526 | } | 524 | } |
527 | 525 | ||
528 | void KAstTopLevel::slotUpdateVitals() | 526 | void KAstTopLevel::slotUpdateVitals() |
529 | { | 527 | { |
530 | brakesLCD->display( view->brakeCount() ); | 528 | brakesLCD->display( view->brakeCount() ); |
531 | shieldLCD->display( view->shieldCount() ); | 529 | shieldLCD->display( view->shieldCount() ); |
532 | shootLCD->display( view->shootCount() ); | 530 | shootLCD->display( view->shootCount() ); |
533 | // teleportsLCD->display( view->teleportCount() ); | 531 | // teleportsLCD->display( view->teleportCount() ); |
534 | powerMeter->setValue( view->power() ); | 532 | powerMeter->setValue( view->power() ); |
535 | } | 533 | } |
diff --git a/noncore/games/qasteroids/view.cpp b/noncore/games/qasteroids/view.cpp index 448a54a..352c63b 100644 --- a/noncore/games/qasteroids/view.cpp +++ b/noncore/games/qasteroids/view.cpp | |||
@@ -1,543 +1,540 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************//* | 19 | **********************************************************************//* |
20 | * KAsteroids - Copyright (c) Martin R. Jones 1997 | 20 | * KAsteroids - Copyright (c) Martin R. Jones 1997 |
21 | * | 21 | * |
22 | * Part of the KDE project | 22 | * Part of the KDE project |
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include "view.h" | 25 | #include "view.h" |
26 | 26 | ||
27 | #include <qpe/resource.h> | 27 | #include <qpe/resource.h> |
28 | 28 | ||
29 | #include <qapplication.h> | ||
30 | #include <qkeycode.h> | ||
31 | #include <qaccel.h> | ||
32 | 29 | ||
33 | #include <stdlib.h> | 30 | #include <stdlib.h> |
34 | #include <math.h> | 31 | #include <math.h> |
35 | 32 | ||
36 | #define IMG_BACKGROUND "qasteroids/bg.png" | 33 | #define IMG_BACKGROUND "qasteroids/bg.png" |
37 | 34 | ||
38 | #define REFRESH_DELAY 33 | 35 | #define REFRESH_DELAY 33 |
39 | #define SHIP_SPEED 0.3 | 36 | #define SHIP_SPEED 0.3 |
40 | #define MISSILE_SPEED 10.0 | 37 | #define MISSILE_SPEED 10.0 |
41 | #define SHIP_STEPS 64 | 38 | #define SHIP_STEPS 64 |
42 | #define ROTATE_RATE 2 | 39 | #define ROTATE_RATE 2 |
43 | #define SHIELD_ON_COST 1 | 40 | #define SHIELD_ON_COST 1 |
44 | #define SHIELD_HIT_COST 30 | 41 | #define SHIELD_HIT_COST 30 |
45 | #define BRAKE_ON_COST 4 | 42 | #define BRAKE_ON_COST 4 |
46 | 43 | ||
47 | #define MAX_ROCK_SPEED 2.5 | 44 | #define MAX_ROCK_SPEED 2.5 |
48 | #define MAX_POWERUP_SPEED 1.5 | 45 | #define MAX_POWERUP_SPEED 1.5 |
49 | #define MAX_SHIP_SPEED 8 | 46 | #define MAX_SHIP_SPEED 8 |
50 | #define MAX_BRAKES 5 | 47 | #define MAX_BRAKES 5 |
51 | #define MAX_SHIELDS 5 | 48 | #define MAX_SHIELDS 5 |
52 | #define MAX_FIREPOWER 5 | 49 | #define MAX_FIREPOWER 5 |
53 | 50 | ||
54 | #define TEXT_SPEED 4 | 51 | #define TEXT_SPEED 4 |
55 | 52 | ||
56 | #define PI_X_2 6.283185307 | 53 | #define PI_X_2 6.283185307 |
57 | #ifndef M_PI | 54 | #ifndef M_PI |
58 | #define M_PI 3.141592654 | 55 | #define M_PI 3.141592654 |
59 | #endif | 56 | #endif |
60 | 57 | ||
61 | struct | 58 | struct |
62 | { | 59 | { |
63 | int id; | 60 | int id; |
64 | const char *path; | 61 | const char *path; |
65 | int frames; | 62 | int frames; |
66 | } | 63 | } |
67 | kas_animations [] = | 64 | kas_animations [] = |
68 | { | 65 | { |
69 | // { ID_ROCK_LARGE, "rock1/rock1\%1.png", 32 }, | 66 | // { ID_ROCK_LARGE, "rock1/rock1\%1.png", 32 }, |
70 | { ID_ROCK_MEDIUM, "rock2/rock2\%1.png", 32 }, | 67 | { ID_ROCK_MEDIUM, "rock2/rock2\%1.png", 32 }, |
71 | { ID_ROCK_SMALL, "rock3/rock3\%1.png", 32 }, | 68 | { ID_ROCK_SMALL, "rock3/rock3\%1.png", 32 }, |
72 | { ID_SHIP, "ship/ship\%1.png", 32 }, | 69 | { ID_SHIP, "ship/ship\%1.png", 32 }, |
73 | { ID_MISSILE, "missile/missile.png", 0 }, | 70 | { ID_MISSILE, "missile/missile.png", 0 }, |
74 | { ID_BIT, "bits/bits\%1.png", 16 }, | 71 | { ID_BIT, "bits/bits\%1.png", 16 }, |
75 | { ID_EXHAUST, "exhaust/exhaust.png", 0 }, | 72 | { ID_EXHAUST, "exhaust/exhaust.png", 0 }, |
76 | { ID_ENERGY_POWERUP, "powerups/energy.png", 0 }, | 73 | { ID_ENERGY_POWERUP, "powerups/energy.png", 0 }, |
77 | // { ID_TELEPORT_POWERUP, "powerups/teleport%1.png", 12 }, | 74 | // { ID_TELEPORT_POWERUP, "powerups/teleport%1.png", 12 }, |
78 | { ID_BRAKE_POWERUP, "powerups/brake.png", 0 }, | 75 | { ID_BRAKE_POWERUP, "powerups/brake.png", 0 }, |
79 | { ID_SHIELD_POWERUP, "powerups/shield.png", 0 }, | 76 | { ID_SHIELD_POWERUP, "powerups/shield.png", 0 }, |
80 | { ID_SHOOT_POWERUP, "powerups/shoot.png", 0 }, | 77 | { ID_SHOOT_POWERUP, "powerups/shoot.png", 0 }, |
81 | { ID_SHIELD, "shield/shield\%1.png", 6 }, | 78 | { ID_SHIELD, "shield/shield\%1.png", 6 }, |
82 | { 0, 0, 0 } | 79 | { 0, 0, 0 } |
83 | }; | 80 | }; |
84 | 81 | ||
85 | 82 | ||
86 | 83 | ||
87 | KAsteroidsView::KAsteroidsView( QWidget *parent, const char *name ) | 84 | KAsteroidsView::KAsteroidsView( QWidget *parent, const char *name ) |
88 | : QWidget( parent, name ), | 85 | : QWidget( parent, name ), |
89 | field(200, 200), | 86 | field(200, 200), |
90 | view(&field,this) | 87 | view(&field,this) |
91 | { | 88 | { |
92 | view.setVScrollBarMode( QScrollView::AlwaysOff ); | 89 | view.setVScrollBarMode( QScrollView::AlwaysOff ); |
93 | view.setHScrollBarMode( QScrollView::AlwaysOff ); | 90 | view.setHScrollBarMode( QScrollView::AlwaysOff ); |
94 | rocks.setAutoDelete( TRUE ); | 91 | rocks.setAutoDelete( TRUE ); |
95 | missiles.setAutoDelete( TRUE ); | 92 | missiles.setAutoDelete( TRUE ); |
96 | bits.setAutoDelete( TRUE ); | 93 | bits.setAutoDelete( TRUE ); |
97 | powerups.setAutoDelete( TRUE ); | 94 | powerups.setAutoDelete( TRUE ); |
98 | exhaust.setAutoDelete( TRUE ); | 95 | exhaust.setAutoDelete( TRUE ); |
99 | 96 | ||
100 | QPixmap pm( Resource::loadPixmap(IMG_BACKGROUND) ); | 97 | QPixmap pm( Resource::loadPixmap(IMG_BACKGROUND) ); |
101 | field.setBackgroundPixmap( pm ); | 98 | field.setBackgroundPixmap( pm ); |
102 | 99 | ||
103 | textSprite = new QCanvasText( &field ); | 100 | textSprite = new QCanvasText( &field ); |
104 | QFont font( "helvetica", 14 ); | 101 | QFont font( "helvetica", 14 ); |
105 | textSprite->setFont( font ); | 102 | textSprite->setFont( font ); |
106 | 103 | ||
107 | shield = 0; | 104 | shield = 0; |
108 | shieldOn = FALSE; | 105 | shieldOn = FALSE; |
109 | refreshRate = REFRESH_DELAY; | 106 | refreshRate = REFRESH_DELAY; |
110 | 107 | ||
111 | readSprites(); | 108 | readSprites(); |
112 | 109 | ||
113 | shieldTimer = new QTimer( this ); | 110 | shieldTimer = new QTimer( this ); |
114 | connect( shieldTimer, SIGNAL(timeout()), this, SLOT(hideShield()) ); | 111 | connect( shieldTimer, SIGNAL(timeout()), this, SLOT(hideShield()) ); |
115 | mTimerId = -1; | 112 | mTimerId = -1; |
116 | 113 | ||
117 | shipPower = MAX_POWER_LEVEL; | 114 | shipPower = MAX_POWER_LEVEL; |
118 | vitalsChanged = TRUE; | 115 | vitalsChanged = TRUE; |
119 | can_destroy_powerups = FALSE; | 116 | can_destroy_powerups = FALSE; |
120 | 117 | ||
121 | mPaused = TRUE; | 118 | mPaused = TRUE; |
122 | } | 119 | } |
123 | 120 | ||
124 | // - - - | 121 | // - - - |
125 | 122 | ||
126 | KAsteroidsView::~KAsteroidsView() | 123 | KAsteroidsView::~KAsteroidsView() |
127 | { | 124 | { |
128 | } | 125 | } |
129 | 126 | ||
130 | // - - - | 127 | // - - - |
131 | 128 | ||
132 | void KAsteroidsView::reset() | 129 | void KAsteroidsView::reset() |
133 | { | 130 | { |
134 | rocks.clear(); | 131 | rocks.clear(); |
135 | missiles.clear(); | 132 | missiles.clear(); |
136 | bits.clear(); | 133 | bits.clear(); |
137 | powerups.clear(); | 134 | powerups.clear(); |
138 | exhaust.clear(); | 135 | exhaust.clear(); |
139 | 136 | ||
140 | shotsFired = 0; | 137 | shotsFired = 0; |
141 | shotsHit = 0; | 138 | shotsHit = 0; |
142 | 139 | ||
143 | rockSpeed = 1.0; | 140 | rockSpeed = 1.0; |
144 | powerupSpeed = 1.0; | 141 | powerupSpeed = 1.0; |
145 | mFrameNum = 0; | 142 | mFrameNum = 0; |
146 | mPaused = FALSE; | 143 | mPaused = FALSE; |
147 | 144 | ||
148 | ship->hide(); | 145 | ship->hide(); |
149 | shield->hide(); | 146 | shield->hide(); |
150 | /* | 147 | /* |
151 | if ( mTimerId >= 0 ) { | 148 | if ( mTimerId >= 0 ) { |
152 | killTimer( mTimerId ); | 149 | killTimer( mTimerId ); |
153 | mTimerId = -1; | 150 | mTimerId = -1; |
154 | } | 151 | } |
155 | */ | 152 | */ |
156 | } | 153 | } |
157 | 154 | ||
158 | // - -- | 155 | // - -- |
159 | 156 | ||
160 | void KAsteroidsView::newGame() | 157 | void KAsteroidsView::newGame() |
161 | { | 158 | { |
162 | if ( shieldOn ) | 159 | if ( shieldOn ) |
163 | { | 160 | { |
164 | shield->hide(); | 161 | shield->hide(); |
165 | shieldOn = FALSE; | 162 | shieldOn = FALSE; |
166 | } | 163 | } |
167 | reset(); | 164 | reset(); |
168 | if ( mTimerId < 0 ) | 165 | if ( mTimerId < 0 ) |
169 | mTimerId = startTimer( REFRESH_DELAY ); | 166 | mTimerId = startTimer( REFRESH_DELAY ); |
170 | emit updateVitals(); | 167 | emit updateVitals(); |
171 | } | 168 | } |
172 | 169 | ||
173 | // - - - | 170 | // - - - |
174 | 171 | ||
175 | void KAsteroidsView::endGame() | 172 | void KAsteroidsView::endGame() |
176 | { | 173 | { |
177 | } | 174 | } |
178 | 175 | ||
179 | void KAsteroidsView::pause( bool p ) | 176 | void KAsteroidsView::pause( bool p ) |
180 | { | 177 | { |
181 | if ( !mPaused && p ) { | 178 | if ( !mPaused && p ) { |
182 | if ( mTimerId >= 0 ) { | 179 | if ( mTimerId >= 0 ) { |
183 | killTimer( mTimerId ); | 180 | killTimer( mTimerId ); |
184 | mTimerId = -1; | 181 | mTimerId = -1; |
185 | } | 182 | } |
186 | } else if ( mPaused && !p ) | 183 | } else if ( mPaused && !p ) |
187 | mTimerId = startTimer( REFRESH_DELAY ); | 184 | mTimerId = startTimer( REFRESH_DELAY ); |
188 | mPaused = p; | 185 | mPaused = p; |
189 | } | 186 | } |
190 | 187 | ||
191 | // - - - | 188 | // - - - |
192 | 189 | ||
193 | void KAsteroidsView::newShip() | 190 | void KAsteroidsView::newShip() |
194 | { | 191 | { |
195 | ship->move( field.width()/2, field.height()/2, 0 ); | 192 | ship->move( field.width()/2, field.height()/2, 0 ); |
196 | shield->move( field.width()/2, field.height()/2, 0 ); | 193 | shield->move( field.width()/2, field.height()/2, 0 ); |
197 | ship->setVelocity( 0.0, 0.0 ); | 194 | ship->setVelocity( 0.0, 0.0 ); |
198 | shipDx = 0; | 195 | shipDx = 0; |
199 | shipDy = 0; | 196 | shipDy = 0; |
200 | shipAngle = 0; | 197 | shipAngle = 0; |
201 | rotateL = FALSE; | 198 | rotateL = FALSE; |
202 | rotateR = FALSE; | 199 | rotateR = FALSE; |
203 | thrustShip = FALSE; | 200 | thrustShip = FALSE; |
204 | shootShip = FALSE; | 201 | shootShip = FALSE; |
205 | brakeShip = FALSE; | 202 | brakeShip = FALSE; |
206 | teleportShip = FALSE; | 203 | teleportShip = FALSE; |
207 | shieldOn = TRUE; | 204 | shieldOn = TRUE; |
208 | shootDelay = 0; | 205 | shootDelay = 0; |
209 | shipPower = MAX_POWER_LEVEL; | 206 | shipPower = MAX_POWER_LEVEL; |
210 | rotateRate = ROTATE_RATE; | 207 | rotateRate = ROTATE_RATE; |
211 | rotateSlow = 0; | 208 | rotateSlow = 0; |
212 | 209 | ||
213 | mBrakeCount = 0; | 210 | mBrakeCount = 0; |
214 | mTeleportCount = 0; | 211 | mTeleportCount = 0; |
215 | mShootCount = 0; | 212 | mShootCount = 0; |
216 | 213 | ||
217 | ship->show(); | 214 | ship->show(); |
218 | shield->show(); | 215 | shield->show(); |
219 | mShieldCount = 1; // just in case the ship appears on a rock. | 216 | mShieldCount = 1; // just in case the ship appears on a rock. |
220 | shieldTimer->start( 1000, TRUE ); | 217 | shieldTimer->start( 1000, TRUE ); |
221 | } | 218 | } |
222 | 219 | ||
223 | void KAsteroidsView::setShield( bool s ) | 220 | void KAsteroidsView::setShield( bool s ) |
224 | { | 221 | { |
225 | if ( shieldTimer->isActive() && !s ) { | 222 | if ( shieldTimer->isActive() && !s ) { |
226 | shieldTimer->stop(); | 223 | shieldTimer->stop(); |
227 | hideShield(); | 224 | hideShield(); |
228 | } else { | 225 | } else { |
229 | shieldOn = s && mShieldCount; | 226 | shieldOn = s && mShieldCount; |
230 | } | 227 | } |
231 | } | 228 | } |
232 | 229 | ||
233 | void KAsteroidsView::brake( bool b ) | 230 | void KAsteroidsView::brake( bool b ) |
234 | { | 231 | { |
235 | if ( mBrakeCount ) | 232 | if ( mBrakeCount ) |
236 | { | 233 | { |
237 | if ( brakeShip && !b ) | 234 | if ( brakeShip && !b ) |
238 | { | 235 | { |
239 | rotateL = FALSE; | 236 | rotateL = FALSE; |
240 | rotateR = FALSE; | 237 | rotateR = FALSE; |
241 | thrustShip = FALSE; | 238 | thrustShip = FALSE; |
242 | rotateRate = ROTATE_RATE; | 239 | rotateRate = ROTATE_RATE; |
243 | } | 240 | } |
244 | 241 | ||
245 | brakeShip = b; | 242 | brakeShip = b; |
246 | } | 243 | } |
247 | } | 244 | } |
248 | 245 | ||
249 | // - - - | 246 | // - - - |
250 | 247 | ||
251 | void KAsteroidsView::readSprites() | 248 | void KAsteroidsView::readSprites() |
252 | { | 249 | { |
253 | QString sprites_prefix = Resource::findPixmap( IMG_BACKGROUND ); | 250 | QString sprites_prefix = Resource::findPixmap( IMG_BACKGROUND ); |
254 | int sep = sprites_prefix.findRev( "/" ); | 251 | int sep = sprites_prefix.findRev( "/" ); |
255 | 252 | ||
256 | sprites_prefix.truncate( sep ); | 253 | sprites_prefix.truncate( sep ); |
257 | 254 | ||
258 | int i = 0; | 255 | int i = 0; |
259 | while ( kas_animations[i].id ) | 256 | while ( kas_animations[i].id ) |
260 | { | 257 | { |
261 | animation.insert( kas_animations[i].id, | 258 | animation.insert( kas_animations[i].id, |
262 | new QCanvasPixmapArray( sprites_prefix + "/" + kas_animations[i].path, | 259 | new QCanvasPixmapArray( sprites_prefix + "/" + kas_animations[i].path, |
263 | kas_animations[i].frames ) ); | 260 | kas_animations[i].frames ) ); |
264 | i++; | 261 | i++; |
265 | } | 262 | } |
266 | 263 | ||
267 | ship = new QCanvasSprite( animation[ID_SHIP], &field ); | 264 | ship = new QCanvasSprite( animation[ID_SHIP], &field ); |
268 | ship->hide(); | 265 | ship->hide(); |
269 | 266 | ||
270 | shield = new KShield( animation[ID_SHIELD], &field ); | 267 | shield = new KShield( animation[ID_SHIELD], &field ); |
271 | shield->hide(); | 268 | shield->hide(); |
272 | } | 269 | } |
273 | 270 | ||
274 | // - - - | 271 | // - - - |
275 | 272 | ||
276 | void KAsteroidsView::addRocks( int num ) | 273 | void KAsteroidsView::addRocks( int num ) |
277 | { | 274 | { |
278 | for ( int i = 0; i < num; i++ ) | 275 | for ( int i = 0; i < num; i++ ) |
279 | { | 276 | { |
280 | KRock *rock = new KRock( animation[ID_ROCK_MEDIUM], &field, | 277 | KRock *rock = new KRock( animation[ID_ROCK_MEDIUM], &field, |
281 | ID_ROCK_MEDIUM, randInt(2), randInt(2) ? -1 : 1 ); | 278 | ID_ROCK_MEDIUM, randInt(2), randInt(2) ? -1 : 1 ); |
282 | double dx = (2.0 - randDouble()*4.0) * rockSpeed; | 279 | double dx = (2.0 - randDouble()*4.0) * rockSpeed; |
283 | double dy = (2.0 - randDouble()*4.0) * rockSpeed; | 280 | double dy = (2.0 - randDouble()*4.0) * rockSpeed; |
284 | rock->setVelocity( dx, dy ); | 281 | rock->setVelocity( dx, dy ); |
285 | rock->setFrame( randInt( rock->frameCount() ) ); | 282 | rock->setFrame( randInt( rock->frameCount() ) ); |
286 | if ( dx > 0 ) | 283 | if ( dx > 0 ) |
287 | { | 284 | { |
288 | if ( dy > 0 ) | 285 | if ( dy > 0 ) |
289 | rock->move( 5, 5, 0 ); | 286 | rock->move( 5, 5, 0 ); |
290 | else | 287 | else |
291 | rock->move( 5, field.height() - 25, 0 ); | 288 | rock->move( 5, field.height() - 25, 0 ); |
292 | } | 289 | } |
293 | else | 290 | else |
294 | { | 291 | { |
295 | if ( dy > 0 ) | 292 | if ( dy > 0 ) |
296 | rock->move( field.width() - 25, 5, 0 ); | 293 | rock->move( field.width() - 25, 5, 0 ); |
297 | else | 294 | else |
298 | rock->move( field.width() - 25, field.height() - 25, 0 ); | 295 | rock->move( field.width() - 25, field.height() - 25, 0 ); |
299 | } | 296 | } |
300 | rock->show( ); | 297 | rock->show( ); |
301 | rocks.append( rock ); | 298 | rocks.append( rock ); |
302 | } | 299 | } |
303 | } | 300 | } |
304 | 301 | ||
305 | // - - - | 302 | // - - - |
306 | 303 | ||
307 | void KAsteroidsView::showText( const QString &text, const QColor &color, bool scroll ) | 304 | void KAsteroidsView::showText( const QString &text, const QColor &color, bool scroll ) |
308 | { | 305 | { |
309 | textSprite->setTextFlags( AlignLeft | AlignVCenter ); | 306 | textSprite->setTextFlags( AlignLeft | AlignVCenter ); |
310 | textSprite->setText( text ); | 307 | textSprite->setText( text ); |
311 | textSprite->setColor( color ); | 308 | textSprite->setColor( color ); |
312 | 309 | ||
313 | if ( scroll ) { | 310 | if ( scroll ) { |
314 | textSprite->move( (field.width()-textSprite->boundingRect().width()) / 2, | 311 | textSprite->move( (field.width()-textSprite->boundingRect().width()) / 2, |
315 | -textSprite->boundingRect().height() ); | 312 | -textSprite->boundingRect().height() ); |
316 | textDy = TEXT_SPEED; | 313 | textDy = TEXT_SPEED; |
317 | } else { | 314 | } else { |
318 | textSprite->move( (field.width()-textSprite->boundingRect().width()) / 2, | 315 | textSprite->move( (field.width()-textSprite->boundingRect().width()) / 2, |
319 | (field.height()-textSprite->boundingRect().height()) / 2 ); | 316 | (field.height()-textSprite->boundingRect().height()) / 2 ); |
320 | textDy = 0; | 317 | textDy = 0; |
321 | } | 318 | } |
322 | textSprite->show(); | 319 | textSprite->show(); |
323 | } | 320 | } |
324 | 321 | ||
325 | // - - - | 322 | // - - - |
326 | 323 | ||
327 | void KAsteroidsView::hideText() | 324 | void KAsteroidsView::hideText() |
328 | { | 325 | { |
329 | textDy = -TEXT_SPEED; | 326 | textDy = -TEXT_SPEED; |
330 | } | 327 | } |
331 | 328 | ||
332 | // - - - | 329 | // - - - |
333 | 330 | ||
334 | void KAsteroidsView::resizeEvent(QResizeEvent* event) | 331 | void KAsteroidsView::resizeEvent(QResizeEvent* event) |
335 | { | 332 | { |
336 | QWidget::resizeEvent(event); | 333 | QWidget::resizeEvent(event); |
337 | field.resize(width()-4, height()-4); | 334 | field.resize(width()-4, height()-4); |
338 | view.resize(width(),height()); | 335 | view.resize(width(),height()); |
339 | } | 336 | } |
340 | 337 | ||
341 | // - - - | 338 | // - - - |
342 | 339 | ||
343 | void KAsteroidsView::timerEvent( QTimerEvent * ) | 340 | void KAsteroidsView::timerEvent( QTimerEvent * ) |
344 | { | 341 | { |
345 | field.advance(); | 342 | field.advance(); |
346 | 343 | ||
347 | QCanvasSprite *rock; | 344 | QCanvasSprite *rock; |
348 | 345 | ||
349 | // move rocks forward | 346 | // move rocks forward |
350 | for ( rock = rocks.first(); rock; rock = rocks.next() ) { | 347 | for ( rock = rocks.first(); rock; rock = rocks.next() ) { |
351 | ((KRock *)rock)->nextFrame(); | 348 | ((KRock *)rock)->nextFrame(); |
352 | wrapSprite( rock ); | 349 | wrapSprite( rock ); |
353 | } | 350 | } |
354 | 351 | ||
355 | wrapSprite( ship ); | 352 | wrapSprite( ship ); |
356 | 353 | ||
357 | // check for missile collision with rocks. | 354 | // check for missile collision with rocks. |
358 | processMissiles(); | 355 | processMissiles(); |
359 | 356 | ||
360 | // these are generated when a ship explodes | 357 | // these are generated when a ship explodes |
361 | for ( KBit *bit = bits.first(); bit; bit = bits.next() ) | 358 | for ( KBit *bit = bits.first(); bit; bit = bits.next() ) |
362 | { | 359 | { |
363 | if ( bit->expired() ) | 360 | if ( bit->expired() ) |
364 | { | 361 | { |
365 | bits.removeRef( bit ); | 362 | bits.removeRef( bit ); |
366 | } | 363 | } |
367 | else | 364 | else |
368 | { | 365 | { |
369 | bit->growOlder(); | 366 | bit->growOlder(); |
370 | bit->setFrame( ( bit->frame()+1 ) % bit->frameCount() ); | 367 | bit->setFrame( ( bit->frame()+1 ) % bit->frameCount() ); |
371 | } | 368 | } |
372 | } | 369 | } |
373 | 370 | ||
374 | for ( KExhaust *e = exhaust.first(); e; e = exhaust.next() ) | 371 | for ( KExhaust *e = exhaust.first(); e; e = exhaust.next() ) |
375 | exhaust.removeRef( e ); | 372 | exhaust.removeRef( e ); |
376 | 373 | ||
377 | // move / rotate ship. | 374 | // move / rotate ship. |
378 | // check for collision with a rock. | 375 | // check for collision with a rock. |
379 | processShip(); | 376 | processShip(); |
380 | 377 | ||
381 | // move powerups and check for collision with player and missiles | 378 | // move powerups and check for collision with player and missiles |
382 | processPowerups(); | 379 | processPowerups(); |
383 | 380 | ||
384 | if ( textSprite->visible() ) | 381 | if ( textSprite->visible() ) |
385 | { | 382 | { |
386 | if ( textDy < 0 && | 383 | if ( textDy < 0 && |
387 | textSprite->boundingRect().y() <= -textSprite->boundingRect().height() ) { | 384 | textSprite->boundingRect().y() <= -textSprite->boundingRect().height() ) { |
388 | textSprite->hide(); | 385 | textSprite->hide(); |
389 | } else { | 386 | } else { |
390 | textSprite->moveBy( 0, textDy ); | 387 | textSprite->moveBy( 0, textDy ); |
391 | } | 388 | } |
392 | if ( textSprite->boundingRect().y() > (field.height()-textSprite->boundingRect().height())/2 ) | 389 | if ( textSprite->boundingRect().y() > (field.height()-textSprite->boundingRect().height())/2 ) |
393 | textDy = 0; | 390 | textDy = 0; |
394 | } | 391 | } |
395 | 392 | ||
396 | if ( vitalsChanged && !(mFrameNum % 10) ) { | 393 | if ( vitalsChanged && !(mFrameNum % 10) ) { |
397 | emit updateVitals(); | 394 | emit updateVitals(); |
398 | vitalsChanged = FALSE; | 395 | vitalsChanged = FALSE; |
399 | } | 396 | } |
400 | 397 | ||
401 | mFrameNum++; | 398 | mFrameNum++; |
402 | } | 399 | } |
403 | 400 | ||
404 | void KAsteroidsView::wrapSprite( QCanvasItem *s ) | 401 | void KAsteroidsView::wrapSprite( QCanvasItem *s ) |
405 | { | 402 | { |
406 | int x = int(s->x() + s->boundingRect().width() / 2); | 403 | int x = int(s->x() + s->boundingRect().width() / 2); |
407 | int y = int(s->y() + s->boundingRect().height() / 2); | 404 | int y = int(s->y() + s->boundingRect().height() / 2); |
408 | 405 | ||
409 | if ( x > field.width() ) | 406 | if ( x > field.width() ) |
410 | s->move( s->x() - field.width(), s->y() ); | 407 | s->move( s->x() - field.width(), s->y() ); |
411 | else if ( x < 0 ) | 408 | else if ( x < 0 ) |
412 | s->move( field.width() + s->x(), s->y() ); | 409 | s->move( field.width() + s->x(), s->y() ); |
413 | 410 | ||
414 | if ( y > field.height() ) | 411 | if ( y > field.height() ) |
415 | s->move( s->x(), s->y() - field.height() ); | 412 | s->move( s->x(), s->y() - field.height() ); |
416 | else if ( y < 0 ) | 413 | else if ( y < 0 ) |
417 | s->move( s->x(), field.height() + s->y() ); | 414 | s->move( s->x(), field.height() + s->y() ); |
418 | } | 415 | } |
419 | 416 | ||
420 | // - - - | 417 | // - - - |
421 | 418 | ||
422 | void KAsteroidsView::rockHit( QCanvasItem *hit ) | 419 | void KAsteroidsView::rockHit( QCanvasItem *hit ) |
423 | { | 420 | { |
424 | KPowerup *nPup = 0; | 421 | KPowerup *nPup = 0; |
425 | int rnd = static_cast<int>(randDouble()*30.0) % 30; | 422 | int rnd = static_cast<int>(randDouble()*30.0) % 30; |
426 | switch( rnd ) | 423 | switch( rnd ) |
427 | { | 424 | { |
428 | case 4: | 425 | case 4: |
429 | case 5: | 426 | case 5: |
430 | nPup = new KPowerup( animation[ID_ENERGY_POWERUP], &field, | 427 | nPup = new KPowerup( animation[ID_ENERGY_POWERUP], &field, |
431 | ID_ENERGY_POWERUP ); | 428 | ID_ENERGY_POWERUP ); |
432 | break; | 429 | break; |
433 | case 10: | 430 | case 10: |
434 | // nPup = new KPowerup( animation[ID_TELEPORT_POWERUP], &field, | 431 | // nPup = new KPowerup( animation[ID_TELEPORT_POWERUP], &field, |
435 | // ID_TELEPORT_POWERUP ); | 432 | // ID_TELEPORT_POWERUP ); |
436 | break; | 433 | break; |
437 | case 15: | 434 | case 15: |
438 | nPup = new KPowerup( animation[ID_BRAKE_POWERUP], &field, | 435 | nPup = new KPowerup( animation[ID_BRAKE_POWERUP], &field, |
439 | ID_BRAKE_POWERUP ); | 436 | ID_BRAKE_POWERUP ); |
440 | break; | 437 | break; |
441 | case 20: | 438 | case 20: |
442 | nPup = new KPowerup( animation[ID_SHIELD_POWERUP], &field, | 439 | nPup = new KPowerup( animation[ID_SHIELD_POWERUP], &field, |
443 | ID_SHIELD_POWERUP ); | 440 | ID_SHIELD_POWERUP ); |
444 | break; | 441 | break; |
445 | case 24: | 442 | case 24: |
446 | case 25: | 443 | case 25: |
447 | nPup = new KPowerup( animation[ID_SHOOT_POWERUP], &field, | 444 | nPup = new KPowerup( animation[ID_SHOOT_POWERUP], &field, |
448 | ID_SHOOT_POWERUP ); | 445 | ID_SHOOT_POWERUP ); |
449 | break; | 446 | break; |
450 | } | 447 | } |
451 | if ( nPup ) | 448 | if ( nPup ) |
452 | { | 449 | { |
453 | double r = 0.5 - randDouble(); | 450 | double r = 0.5 - randDouble(); |
454 | nPup->move( hit->x(), hit->y(), 0 ); | 451 | nPup->move( hit->x(), hit->y(), 0 ); |
455 | nPup->setVelocity( hit->xVelocity() + r, hit->yVelocity() + r ); | 452 | nPup->setVelocity( hit->xVelocity() + r, hit->yVelocity() + r ); |
456 | nPup->show( ); | 453 | nPup->show( ); |
457 | powerups.append( nPup ); | 454 | powerups.append( nPup ); |
458 | } | 455 | } |
459 | 456 | ||
460 | if ( hit->rtti() == ID_ROCK_LARGE || hit->rtti() == ID_ROCK_MEDIUM ) | 457 | if ( hit->rtti() == ID_ROCK_LARGE || hit->rtti() == ID_ROCK_MEDIUM ) |
461 | { | 458 | { |
462 | // break into smaller rocks | 459 | // break into smaller rocks |
463 | double addx[4] = { 1.0, 1.0, -1.0, -1.0 }; | 460 | double addx[4] = { 1.0, 1.0, -1.0, -1.0 }; |
464 | double addy[4] = { -1.0, 1.0, -1.0, 1.0 }; | 461 | double addy[4] = { -1.0, 1.0, -1.0, 1.0 }; |
465 | 462 | ||
466 | double dx = hit->xVelocity(); | 463 | double dx = hit->xVelocity(); |
467 | double dy = hit->yVelocity(); | 464 | double dy = hit->yVelocity(); |
468 | 465 | ||
469 | double maxRockSpeed = MAX_ROCK_SPEED * rockSpeed; | 466 | double maxRockSpeed = MAX_ROCK_SPEED * rockSpeed; |
470 | if ( dx > maxRockSpeed ) | 467 | if ( dx > maxRockSpeed ) |
471 | dx = maxRockSpeed; | 468 | dx = maxRockSpeed; |
472 | else if ( dx < -maxRockSpeed ) | 469 | else if ( dx < -maxRockSpeed ) |
473 | dx = -maxRockSpeed; | 470 | dx = -maxRockSpeed; |
474 | if ( dy > maxRockSpeed ) | 471 | if ( dy > maxRockSpeed ) |
475 | dy = maxRockSpeed; | 472 | dy = maxRockSpeed; |
476 | else if ( dy < -maxRockSpeed ) | 473 | else if ( dy < -maxRockSpeed ) |
477 | dy = -maxRockSpeed; | 474 | dy = -maxRockSpeed; |
478 | 475 | ||
479 | QCanvasSprite *nrock; | 476 | QCanvasSprite *nrock; |
480 | 477 | ||
481 | for ( int i = 0; i < 4; i++ ) | 478 | for ( int i = 0; i < 4; i++ ) |
482 | { | 479 | { |
483 | double r = rockSpeed/2 - randDouble()*rockSpeed; | 480 | double r = rockSpeed/2 - randDouble()*rockSpeed; |
484 | if ( hit->rtti() == ID_ROCK_LARGE ) | 481 | if ( hit->rtti() == ID_ROCK_LARGE ) |
485 | { | 482 | { |
486 | nrock = new KRock( animation[ID_ROCK_MEDIUM], &field, | 483 | nrock = new KRock( animation[ID_ROCK_MEDIUM], &field, |
487 | ID_ROCK_MEDIUM, randInt(2), randInt(2) ? -1 : 1 ); | 484 | ID_ROCK_MEDIUM, randInt(2), randInt(2) ? -1 : 1 ); |
488 | emit rockHit( 0 ); | 485 | emit rockHit( 0 ); |
489 | } | 486 | } |
490 | else | 487 | else |
491 | { | 488 | { |
492 | nrock = new KRock( animation[ID_ROCK_SMALL], &field, | 489 | nrock = new KRock( animation[ID_ROCK_SMALL], &field, |
493 | ID_ROCK_SMALL, randInt(2), randInt(2) ? -1 : 1 ); | 490 | ID_ROCK_SMALL, randInt(2), randInt(2) ? -1 : 1 ); |
494 | emit rockHit( 1 ); | 491 | emit rockHit( 1 ); |
495 | } | 492 | } |
496 | 493 | ||
497 | nrock->move( hit->x(), hit->y(), 0 ); | 494 | nrock->move( hit->x(), hit->y(), 0 ); |
498 | nrock->setVelocity( dx+addx[i]*rockSpeed+r, dy+addy[i]*rockSpeed+r ); | 495 | nrock->setVelocity( dx+addx[i]*rockSpeed+r, dy+addy[i]*rockSpeed+r ); |
499 | nrock->setFrame( randInt( nrock->frameCount() ) ); | 496 | nrock->setFrame( randInt( nrock->frameCount() ) ); |
500 | nrock->show( ); | 497 | nrock->show( ); |
501 | rocks.append( nrock ); | 498 | rocks.append( nrock ); |
502 | } | 499 | } |
503 | } | 500 | } |
504 | else if ( hit->rtti() == ID_ROCK_SMALL ) | 501 | else if ( hit->rtti() == ID_ROCK_SMALL ) |
505 | emit rockHit( 2 ); | 502 | emit rockHit( 2 ); |
506 | rocks.removeRef( (QCanvasSprite *)hit ); | 503 | rocks.removeRef( (QCanvasSprite *)hit ); |
507 | if ( rocks.count() == 0 ) | 504 | if ( rocks.count() == 0 ) |
508 | emit rocksRemoved(); | 505 | emit rocksRemoved(); |
509 | } | 506 | } |
510 | 507 | ||
511 | void KAsteroidsView::reducePower( int val ) | 508 | void KAsteroidsView::reducePower( int val ) |
512 | { | 509 | { |
513 | shipPower -= val; | 510 | shipPower -= val; |
514 | if ( shipPower <= 0 ) | 511 | if ( shipPower <= 0 ) |
515 | { | 512 | { |
516 | shipPower = 0; | 513 | shipPower = 0; |
517 | thrustShip = FALSE; | 514 | thrustShip = FALSE; |
518 | if ( shieldOn ) | 515 | if ( shieldOn ) |
519 | { | 516 | { |
520 | shieldOn = FALSE; | 517 | shieldOn = FALSE; |
521 | shield->hide(); | 518 | shield->hide(); |
522 | } | 519 | } |
523 | } | 520 | } |
524 | vitalsChanged = TRUE; | 521 | vitalsChanged = TRUE; |
525 | } | 522 | } |
526 | 523 | ||
527 | void KAsteroidsView::addExhaust( double x, double y, double dx, | 524 | void KAsteroidsView::addExhaust( double x, double y, double dx, |
528 | double dy, int count ) | 525 | double dy, int count ) |
529 | { | 526 | { |
530 | for ( int i = 0; i < count; i++ ) | 527 | for ( int i = 0; i < count; i++ ) |
531 | { | 528 | { |
532 | KExhaust *e = new KExhaust( animation[ID_EXHAUST], &field ); | 529 | KExhaust *e = new KExhaust( animation[ID_EXHAUST], &field ); |
533 | e->move( x + 2 - randDouble()*4, y + 2 - randDouble()*4 ); | 530 | e->move( x + 2 - randDouble()*4, y + 2 - randDouble()*4 ); |
534 | e->setVelocity( dx, dy ); | 531 | e->setVelocity( dx, dy ); |
535 | e->show( ); | 532 | e->show( ); |
536 | exhaust.append( e ); | 533 | exhaust.append( e ); |
537 | } | 534 | } |
538 | } | 535 | } |
539 | 536 | ||
540 | void KAsteroidsView::processMissiles() | 537 | void KAsteroidsView::processMissiles() |
541 | { | 538 | { |
542 | KMissile *missile; | 539 | KMissile *missile; |
543 | 540 | ||
diff --git a/noncore/games/sfcave/helpwindow.cpp b/noncore/games/sfcave/helpwindow.cpp index 544e237..8a5d034 100644 --- a/noncore/games/sfcave/helpwindow.cpp +++ b/noncore/games/sfcave/helpwindow.cpp | |||
@@ -1,81 +1,79 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | helpwindow.cpp - description | 2 | helpwindow.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Sun Sep 8 2002 | 4 | begin : Sun Sep 8 2002 |
5 | copyright : (C) 2002 by Andy Qua | 5 | copyright : (C) 2002 by Andy Qua |
6 | email : andy.qua@blueyonder.co.uk | 6 | email : andy.qua@blueyonder.co.uk |
7 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | 8 | ||
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * | 11 | * This program is free software; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation; either version 2 of the License, or * | 13 | * the Free Software Foundation; either version 2 of the License, or * |
14 | * (at your option) any later version. * | 14 | * (at your option) any later version. * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | 17 | ||
18 | #include <qwidget.h> | ||
19 | #include <qlayout.h> | 18 | #include <qlayout.h> |
20 | #include <qstring.h> | ||
21 | #include <qtextview.h> | 19 | #include <qtextview.h> |
22 | 20 | ||
23 | #include <qpe/qpeapplication.h> | 21 | #include <qpe/qpeapplication.h> |
24 | 22 | ||
25 | #include "helpwindow.h" | 23 | #include "helpwindow.h" |
26 | 24 | ||
27 | 25 | ||
28 | #define HELP_TEXT \ | 26 | #define HELP_TEXT \ |
29 | "<qt><h1>SFCave Help</h1><p> " \ | 27 | "<qt><h1>SFCave Help</h1><p> " \ |
30 | "SFCave is a flying game for the Zaurus.<br><br> " \ | 28 | "SFCave is a flying game for the Zaurus.<br><br> " \ |
31 | "The aim is to stay alive for as long as possible and get the highest score " \ | 29 | "The aim is to stay alive for as long as possible and get the highest score " \ |
32 | "you can.<br><br>" \ | 30 | "you can.<br><br>" \ |
33 | "There are three game types currently - SFCave, Gates, and Fly.<br>" \ | 31 | "There are three game types currently - SFCave, Gates, and Fly.<br>" \ |
34 | "<b>SFCave</b> is a remake of the classic SFCave game - fly through the " \ | 32 | "<b>SFCave</b> is a remake of the classic SFCave game - fly through the " \ |
35 | "cavern avoiding all the blocks that just happen to be hanging in " \ | 33 | "cavern avoiding all the blocks that just happen to be hanging in " \ |
36 | "midair<br><br>" \ | 34 | "midair<br><br>" \ |
37 | "<b>Gates</b> is similar to SFCave but instead you must fly through the " \ | 35 | "<b>Gates</b> is similar to SFCave but instead you must fly through the " \ |
38 | "without crashing.<br><br>" \ | 36 | "without crashing.<br><br>" \ |
39 | "<b>Fly</b> is somewhat different to SFCave and above. Instead, you have " \ | 37 | "<b>Fly</b> is somewhat different to SFCave and above. Instead, you have " \ |
40 | "are flying in the open air above a scrolling landscape, and the aim is to " \ | 38 | "are flying in the open air above a scrolling landscape, and the aim is to " \ |
41 | "hug the ground - the closer to the land you fly the more points " \ | 39 | "hug the ground - the closer to the land you fly the more points " \ |
42 | "scored.<br><br><br>" \ | 40 | "scored.<br><br><br>" \ |
43 | "Basic instruction - Press <b>Up</B> or <b>Down</b> on the circle pad to " \ | 41 | "Basic instruction - Press <b>Up</B> or <b>Down</b> on the circle pad to " \ |
44 | "start a new game, press the middle of the pad to apply thrust (makes you " \ | 42 | "start a new game, press the middle of the pad to apply thrust (makes you " \ |
45 | "go up), and release the pad to remove thrust and drop down.<br><br>" \ | 43 | "go up), and release the pad to remove thrust and drop down.<br><br>" \ |
46 | "Also, if playing the Fly game, you can press z to toggle the display " \ | 44 | "Also, if playing the Fly game, you can press z to toggle the display " \ |
47 | "of the scoring zones. This will display 4 red lines at varying heights " \ | 45 | "of the scoring zones. This will display 4 red lines at varying heights " \ |
48 | "above the landscape - if your ship falls into this zone, point are scored. " \ | 46 | "above the landscape - if your ship falls into this zone, point are scored. " \ |
49 | "The closer to the landscape you get the more points you get.<br><br>" \ | 47 | "The closer to the landscape you get the more points you get.<br><br>" \ |
50 | "In addition, SFCave has replays - save and load too so you can show off to all " \ | 48 | "In addition, SFCave has replays - save and load too so you can show off to all " \ |
51 | "your friends (or vice versa). Currently, this is in its infancy but will improve.<br>" \ | 49 | "your friends (or vice versa). Currently, this is in its infancy but will improve.<br>" \ |
52 | "To use, once you have crashed, press 'r' to replay the last game.<br>" \ | 50 | "To use, once you have crashed, press 'r' to replay the last game.<br>" \ |
53 | "To save the replay press 's'.<br>" \ | 51 | "To save the replay press 's'.<br>" \ |
54 | "To load a saved replay press 'l' (after you've crashed at least once).<br><br>" \ | 52 | "To load a saved replay press 'l' (after you've crashed at least once).<br><br>" \ |
55 | "Replays are currently saved to your home directory in a file called sfcave.replay." \ | 53 | "Replays are currently saved to your home directory in a file called sfcave.replay." \ |
56 | "This file can be copied and given to others as long as it it put in their home directory.<br><br>" \ | 54 | "This file can be copied and given to others as long as it it put in their home directory.<br><br>" \ |
57 | "Have lots of fun.<br>" \ | 55 | "Have lots of fun.<br>" \ |
58 | "Andy" \ | 56 | "Andy" \ |
59 | "</p></qt>" | 57 | "</p></qt>" |
60 | 58 | ||
61 | 59 | ||
62 | HelpWindow::HelpWindow( QWidget *parent, const char *name, bool modal, WFlags flags ) | 60 | HelpWindow::HelpWindow( QWidget *parent, const char *name, bool modal, WFlags flags ) |
63 | : QDialog( parent, name, modal, flags ) | 61 | : QDialog( parent, name, modal, flags ) |
64 | { | 62 | { |
65 | // resize( 230, 280 ); | 63 | // resize( 230, 280 ); |
66 | 64 | ||
67 | setCaption( "Help for SFCave" ); | 65 | setCaption( "Help for SFCave" ); |
68 | 66 | ||
69 | QVBoxLayout *layout = new QVBoxLayout( this ); | 67 | QVBoxLayout *layout = new QVBoxLayout( this ); |
70 | QString text = HELP_TEXT;; | 68 | QString text = HELP_TEXT;; |
71 | QTextView *view = new QTextView( text, 0, this, "view" ); | 69 | QTextView *view = new QTextView( text, 0, this, "view" ); |
72 | layout->insertSpacing( -1, 5 ); | 70 | layout->insertSpacing( -1, 5 ); |
73 | layout->insertWidget( -1, view ); | 71 | layout->insertWidget( -1, view ); |
74 | layout->insertSpacing( -1, 5 ); | 72 | layout->insertSpacing( -1, 5 ); |
75 | 73 | ||
76 | QPEApplication::showDialog( this ); | 74 | QPEApplication::showDialog( this ); |
77 | } | 75 | } |
78 | 76 | ||
79 | HelpWindow::~HelpWindow() | 77 | HelpWindow::~HelpWindow() |
80 | { | 78 | { |
81 | } | 79 | } |
diff --git a/noncore/games/snake/interface.cpp b/noncore/games/snake/interface.cpp index 2c60693..b5fb5bf 100644 --- a/noncore/games/snake/interface.cpp +++ b/noncore/games/snake/interface.cpp | |||
@@ -1,223 +1,219 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "interface.h" | 21 | #include "interface.h" |
22 | 22 | ||
23 | #include <qpe/resource.h> | 23 | #include <qpe/resource.h> |
24 | #include <qpe/qpeapplication.h> | ||
25 | 24 | ||
26 | #include <qpe/qpetoolbar.h> | 25 | #include <qpe/qpetoolbar.h> |
27 | #include <qtoolbutton.h> | 26 | #include <qtoolbutton.h> |
28 | #include <qstyle.h> | ||
29 | #include <qapplication.h> | ||
30 | #include <qmessagebox.h> | ||
31 | 27 | ||
32 | SnakeGame::SnakeGame(QWidget* parent, const char* name, WFlags f) : | 28 | SnakeGame::SnakeGame(QWidget* parent, const char* name, WFlags f) : |
33 | QMainWindow(parent,name,f), | 29 | QMainWindow(parent,name,f), |
34 | canvas(232, 258) | 30 | canvas(232, 258) |
35 | { | 31 | { |
36 | setCaption( tr("Snake") ); | 32 | setCaption( tr("Snake") ); |
37 | QPEApplication::setInputMethodHint(this, QPEApplication::AlwaysOff ); | 33 | QPEApplication::setInputMethodHint(this, QPEApplication::AlwaysOff ); |
38 | QPixmap bg = Resource::loadPixmap("snake/grass"); | 34 | QPixmap bg = Resource::loadPixmap("snake/grass"); |
39 | canvas.setBackgroundPixmap(bg); | 35 | canvas.setBackgroundPixmap(bg); |
40 | canvas.setUpdatePeriod(100); | 36 | canvas.setUpdatePeriod(100); |
41 | snake = 0; | 37 | snake = 0; |
42 | 38 | ||
43 | cv = new QCanvasView(&canvas, this); | 39 | cv = new QCanvasView(&canvas, this); |
44 | 40 | ||
45 | pauseTimer = new QTimer(this); | 41 | pauseTimer = new QTimer(this); |
46 | connect(pauseTimer, SIGNAL(timeout()), this, SLOT(wait()) ); | 42 | connect(pauseTimer, SIGNAL(timeout()), this, SLOT(wait()) ); |
47 | 43 | ||
48 | setToolBarsMovable( FALSE ); | 44 | setToolBarsMovable( FALSE ); |
49 | 45 | ||
50 | QToolBar* toolbar = new QToolBar( this); | 46 | QToolBar* toolbar = new QToolBar( this); |
51 | toolbar->setHorizontalStretchable( TRUE ); | 47 | toolbar->setHorizontalStretchable( TRUE ); |
52 | 48 | ||
53 | QPixmap newicon = Resource::loadPixmap("ksnake"); | 49 | QPixmap newicon = Resource::loadPixmap("ksnake"); |
54 | setIcon(newicon); | 50 | setIcon(newicon); |
55 | (void)new QToolButton(newicon, tr("New Game"), 0, | 51 | (void)new QToolButton(newicon, tr("New Game"), 0, |
56 | this, SLOT(newGame()), toolbar, "New Game"); | 52 | this, SLOT(newGame()), toolbar, "New Game"); |
57 | 53 | ||
58 | scorelabel = new QLabel(toolbar); | 54 | scorelabel = new QLabel(toolbar); |
59 | showScore(0); | 55 | showScore(0); |
60 | scorelabel->setBackgroundMode( PaletteButton ); | 56 | scorelabel->setBackgroundMode( PaletteButton ); |
61 | scorelabel->setAlignment( AlignRight | AlignVCenter | ExpandTabs ); | 57 | scorelabel->setAlignment( AlignRight | AlignVCenter | ExpandTabs ); |
62 | toolbar->setStretchableWidget( scorelabel ); | 58 | toolbar->setStretchableWidget( scorelabel ); |
63 | 59 | ||
64 | setFocusPolicy(StrongFocus); | 60 | setFocusPolicy(StrongFocus); |
65 | 61 | ||
66 | setCentralWidget(cv); | 62 | setCentralWidget(cv); |
67 | 63 | ||
68 | QTimer::singleShot( 16, this, SLOT(welcomescreen()) ); | 64 | QTimer::singleShot( 16, this, SLOT(welcomescreen()) ); |
69 | gamestopped = true; | 65 | gamestopped = true; |
70 | waitover = true; | 66 | waitover = true; |
71 | } | 67 | } |
72 | 68 | ||
73 | SnakeGame::~SnakeGame() | 69 | SnakeGame::~SnakeGame() |
74 | { | 70 | { |
75 | delete snake; | 71 | delete snake; |
76 | } | 72 | } |
77 | 73 | ||
78 | void SnakeGame::resizeEvent(QResizeEvent *) | 74 | void SnakeGame::resizeEvent(QResizeEvent *) |
79 | { | 75 | { |
80 | QSize s = centralWidget()->size(); | 76 | QSize s = centralWidget()->size(); |
81 | int fw = style().defaultFrameWidth(); | 77 | int fw = style().defaultFrameWidth(); |
82 | canvas.resize( s.width() - fw - 2, s.height() - fw - 2); | 78 | canvas.resize( s.width() - fw - 2, s.height() - fw - 2); |
83 | } | 79 | } |
84 | 80 | ||
85 | void SnakeGame::welcomescreen() | 81 | void SnakeGame::welcomescreen() |
86 | { | 82 | { |
87 | QCanvasText* title = new QCanvasText(tr("SNAKE!"), &canvas); | 83 | QCanvasText* title = new QCanvasText(tr("SNAKE!"), &canvas); |
88 | title->setColor(yellow); | 84 | title->setColor(yellow); |
89 | title->setFont( QFont("times", 18, QFont::Bold) ); | 85 | title->setFont( QFont("times", 18, QFont::Bold) ); |
90 | int w = title->boundingRect().width(); | 86 | int w = title->boundingRect().width(); |
91 | title->move(canvas.width()/2 -w/2, canvas.height()/2-110); | 87 | title->move(canvas.width()/2 -w/2, canvas.height()/2-110); |
92 | title->show(); | 88 | title->show(); |
93 | QCanvasPixmapArray* titlearray = new QCanvasPixmapArray(Resource::findPixmap("snake/title")); | 89 | QCanvasPixmapArray* titlearray = new QCanvasPixmapArray(Resource::findPixmap("snake/title")); |
94 | QCanvasSprite* titlepic = new QCanvasSprite(titlearray, &canvas); | 90 | QCanvasSprite* titlepic = new QCanvasSprite(titlearray, &canvas); |
95 | titlepic->move(canvas.width()/2 - 33, canvas.height()/2-85); | 91 | titlepic->move(canvas.width()/2 - 33, canvas.height()/2-85); |
96 | titlepic->show(); | 92 | titlepic->show(); |
97 | QCanvasText* instr = new QCanvasText(tr("Use the arrow keys to guide the\n" | 93 | QCanvasText* instr = new QCanvasText(tr("Use the arrow keys to guide the\n" |
98 | "snake to eat the mouse. You must not\n" | 94 | "snake to eat the mouse. You must not\n" |
99 | "crash into the walls, edges or its tail."), | 95 | "crash into the walls, edges or its tail."), |
100 | &canvas); | 96 | &canvas); |
101 | w = instr->boundingRect().width(); | 97 | w = instr->boundingRect().width(); |
102 | instr->move(canvas.width()/2-w/2, canvas.height()/2-20); | 98 | instr->move(canvas.width()/2-w/2, canvas.height()/2-20); |
103 | instr->setColor(white); | 99 | instr->setColor(white); |
104 | instr->show(); | 100 | instr->show(); |
105 | QCanvasText* cont = new QCanvasText(tr("Press any key to start"), &canvas); | 101 | QCanvasText* cont = new QCanvasText(tr("Press any key to start"), &canvas); |
106 | w = cont->boundingRect().width(); | 102 | w = cont->boundingRect().width(); |
107 | cont->move(canvas.width()/2-w/2, canvas.height()-20); | 103 | cont->move(canvas.width()/2-w/2, canvas.height()-20); |
108 | cont->setColor(yellow); | 104 | cont->setColor(yellow); |
109 | cont->show(); | 105 | cont->show(); |
110 | 106 | ||
111 | } | 107 | } |
112 | 108 | ||
113 | void SnakeGame::newGame() | 109 | void SnakeGame::newGame() |
114 | { | 110 | { |
115 | clear(); | 111 | clear(); |
116 | snake = new Snake(&canvas); | 112 | snake = new Snake(&canvas); |
117 | connect(snake, SIGNAL(dead()), this, SLOT(gameOver()) ); | 113 | connect(snake, SIGNAL(dead()), this, SLOT(gameOver()) ); |
118 | connect(snake, SIGNAL(targethit()), this, SLOT(levelUp()) ); | 114 | connect(snake, SIGNAL(targethit()), this, SLOT(levelUp()) ); |
119 | connect(snake, SIGNAL(scorechanged()), this, SLOT(scoreInc()) ); | 115 | connect(snake, SIGNAL(scorechanged()), this, SLOT(scoreInc()) ); |
120 | connect(this, SIGNAL(moveFaster()), snake, SLOT(increaseSpeed()) ); | 116 | connect(this, SIGNAL(moveFaster()), snake, SLOT(increaseSpeed()) ); |
121 | last = 0; | 117 | last = 0; |
122 | targetamount = 1; | 118 | targetamount = 1; |
123 | notargets = 1; | 119 | notargets = 1; |
124 | level = 1; | 120 | level = 1; |
125 | stage = 1; | 121 | stage = 1; |
126 | showScore(0); | 122 | showScore(0); |
127 | gamestopped = false; | 123 | gamestopped = false; |
128 | waitover = true; | 124 | waitover = true; |
129 | int y = canvas.height()-50; | 125 | int y = canvas.height()-50; |
130 | (void)new Obstacle(&canvas, 32); | 126 | (void)new Obstacle(&canvas, 32); |
131 | (void)new Obstacle(&canvas, y); | 127 | (void)new Obstacle(&canvas, y); |
132 | createTargets(); | 128 | createTargets(); |
133 | } | 129 | } |
134 | 130 | ||
135 | 131 | ||
136 | void SnakeGame::showScore(int score) | 132 | void SnakeGame::showScore(int score) |
137 | { | 133 | { |
138 | scorelabel->setText(tr(" Score : %1 ").arg(score) ); | 134 | scorelabel->setText(tr(" Score : %1 ").arg(score) ); |
139 | } | 135 | } |
140 | 136 | ||
141 | 137 | ||
142 | void SnakeGame::scoreInc() | 138 | void SnakeGame::scoreInc() |
143 | { | 139 | { |
144 | showScore( snake->getScore() ); | 140 | showScore( snake->getScore() ); |
145 | } | 141 | } |
146 | 142 | ||
147 | void SnakeGame::levelUp() | 143 | void SnakeGame::levelUp() |
148 | { | 144 | { |
149 | notargets--; | 145 | notargets--; |
150 | if (notargets == 0) { | 146 | if (notargets == 0) { |
151 | stage++; | 147 | stage++; |
152 | if (stage == 3) { | 148 | if (stage == 3) { |
153 | level++; | 149 | level++; |
154 | emit moveFaster(); | 150 | emit moveFaster(); |
155 | targetamount++; | 151 | targetamount++; |
156 | stage = 0; | 152 | stage = 0; |
157 | } | 153 | } |
158 | createTargets(); | 154 | createTargets(); |
159 | } | 155 | } |
160 | } | 156 | } |
161 | 157 | ||
162 | void SnakeGame::createTargets() | 158 | void SnakeGame::createTargets() |
163 | { | 159 | { |
164 | for (int i = 0; i < targetamount; i++) | 160 | for (int i = 0; i < targetamount; i++) |
165 | (void)new Target(&canvas); | 161 | (void)new Target(&canvas); |
166 | notargets = targetamount; | 162 | notargets = targetamount; |
167 | } | 163 | } |
168 | 164 | ||
169 | void SnakeGame::clear() | 165 | void SnakeGame::clear() |
170 | { | 166 | { |
171 | delete snake; | 167 | delete snake; |
172 | snake = 0; | 168 | snake = 0; |
173 | QCanvasItemList l = canvas.allItems(); | 169 | QCanvasItemList l = canvas.allItems(); |
174 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { | 170 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { |
175 | delete *it; | 171 | delete *it; |
176 | } | 172 | } |
177 | } | 173 | } |
178 | 174 | ||
179 | void SnakeGame::gameOver() | 175 | void SnakeGame::gameOver() |
180 | { | 176 | { |
181 | int score = snake->getScore(); | 177 | int score = snake->getScore(); |
182 | QString scoreoutput=""; | 178 | QString scoreoutput=""; |
183 | scoreoutput.setNum(score); | 179 | scoreoutput.setNum(score); |
184 | QCanvasText* gameover = new QCanvasText(tr("GAME OVER!\n Your Score: %1").arg( scoreoutput), &canvas); | 180 | QCanvasText* gameover = new QCanvasText(tr("GAME OVER!\n Your Score: %1").arg( scoreoutput), &canvas); |
185 | 181 | ||
186 | gameover->setZ(100); | 182 | gameover->setZ(100); |
187 | gameover->setColor(yellow); | 183 | gameover->setColor(yellow); |
188 | gameover->setFont( QFont("times", 18, QFont::Bold) ); | 184 | gameover->setFont( QFont("times", 18, QFont::Bold) ); |
189 | int w = gameover->boundingRect().width(); | 185 | int w = gameover->boundingRect().width(); |
190 | gameover->move(canvas.width()/2 -w/2, canvas.height()/2 -50); | 186 | gameover->move(canvas.width()/2 -w/2, canvas.height()/2 -50); |
191 | gameover->show(); | 187 | gameover->show(); |
192 | gamestopped = true; | 188 | gamestopped = true; |
193 | waitover = false; | 189 | waitover = false; |
194 | pauseTimer->start(1500); | 190 | pauseTimer->start(1500); |
195 | } | 191 | } |
196 | 192 | ||
197 | void SnakeGame::wait() | 193 | void SnakeGame::wait() |
198 | { | 194 | { |
199 | waitover = true; | 195 | waitover = true; |
200 | pauseTimer->stop(); | 196 | pauseTimer->stop(); |
201 | QCanvasText* cont = new QCanvasText(tr("Press any key to begin a new game."), | 197 | QCanvasText* cont = new QCanvasText(tr("Press any key to begin a new game."), |
202 | &canvas); | 198 | &canvas); |
203 | cont->setZ(100); | 199 | cont->setZ(100); |
204 | cont->setColor(white); | 200 | cont->setColor(white); |
205 | int w = cont->boundingRect().width(); | 201 | int w = cont->boundingRect().width(); |
206 | cont->move(canvas.width()/2 -w/2, canvas.height()/2); | 202 | cont->move(canvas.width()/2 -w/2, canvas.height()/2); |
207 | cont->show(); | 203 | cont->show(); |
208 | } | 204 | } |
209 | 205 | ||
210 | void SnakeGame::keyPressEvent(QKeyEvent* event) | 206 | void SnakeGame::keyPressEvent(QKeyEvent* event) |
211 | { | 207 | { |
212 | if (gamestopped) { | 208 | if (gamestopped) { |
213 | if (waitover) | 209 | if (waitover) |
214 | newGame(); | 210 | newGame(); |
215 | else | 211 | else |
216 | return; | 212 | return; |
217 | } | 213 | } |
218 | else { | 214 | else { |
219 | int newkey = event->key(); | 215 | int newkey = event->key(); |
220 | snake->go(newkey); | 216 | snake->go(newkey); |
221 | } | 217 | } |
222 | } | 218 | } |
223 | 219 | ||
diff --git a/noncore/games/snake/main.cpp b/noncore/games/snake/main.cpp index 77a2769..9a9b167 100644 --- a/noncore/games/snake/main.cpp +++ b/noncore/games/snake/main.cpp | |||
@@ -1,29 +1,28 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "interface.h" | 21 | #include "interface.h" |
22 | 22 | ||
23 | #include <qpe/qpeapplication.h> | ||
24 | #include <opie/oapplicationfactory.h> | 23 | #include <opie/oapplicationfactory.h> |
25 | 24 | ||
26 | 25 | ||
27 | OPIE_EXPORT_APP( OApplicationFactory<SnakeGame> ) | 26 | OPIE_EXPORT_APP( OApplicationFactory<SnakeGame> ) |
28 | 27 | ||
29 | 28 | ||
diff --git a/noncore/games/snake/snake.cpp b/noncore/games/snake/snake.cpp index 9f19841..8a683ab 100644 --- a/noncore/games/snake/snake.cpp +++ b/noncore/games/snake/snake.cpp | |||
@@ -1,246 +1,244 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "snake.h" | 21 | #include "snake.h" |
22 | #include "target.h" | 22 | #include "target.h" |
23 | #include "codes.h" | ||
24 | 23 | ||
25 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
26 | 25 | ||
27 | #include <qregexp.h> | ||
28 | 26 | ||
29 | static int Piecekey[4][4] = { {6, 0, 4, 3 }, {0, 6, 2, 1 }, { 1, 3, 5, 0 }, {2, 4, 0, 5 } }; | 27 | static int Piecekey[4][4] = { {6, 0, 4, 3 }, {0, 6, 2, 1 }, { 1, 3, 5, 0 }, {2, 4, 0, 5 } }; |
30 | 28 | ||
31 | Snake::Snake(QCanvas* c) | 29 | Snake::Snake(QCanvas* c) |
32 | { | 30 | { |
33 | canvas = c; | 31 | canvas = c; |
34 | score = 0; | 32 | score = 0; |
35 | snakelist.setAutoDelete(true); | 33 | snakelist.setAutoDelete(true); |
36 | autoMoveTimer = new QTimer(this); | 34 | autoMoveTimer = new QTimer(this); |
37 | connect( autoMoveTimer, SIGNAL(timeout()), this, SLOT(moveSnake()) ); | 35 | connect( autoMoveTimer, SIGNAL(timeout()), this, SLOT(moveSnake()) ); |
38 | createSnake(); | 36 | createSnake(); |
39 | } | 37 | } |
40 | 38 | ||
41 | void Snake::createSnake() | 39 | void Snake::createSnake() |
42 | { | 40 | { |
43 | snakeparts = new QCanvasPixmapArray(); | 41 | snakeparts = new QCanvasPixmapArray(); |
44 | QString s0 = Resource::findPixmap("snake/s0001"); | 42 | QString s0 = Resource::findPixmap("snake/s0001"); |
45 | s0.replace(QRegExp("0001"),"%1"); | 43 | s0.replace(QRegExp("0001"),"%1"); |
46 | snakeparts->readPixmaps(s0, 15); | 44 | snakeparts->readPixmaps(s0, 15); |
47 | 45 | ||
48 | grow = 0; | 46 | grow = 0; |
49 | last = Key_Right; | 47 | last = Key_Right; |
50 | 48 | ||
51 | QCanvasSprite* head = new QCanvasSprite(snakeparts, canvas ); | 49 | QCanvasSprite* head = new QCanvasSprite(snakeparts, canvas ); |
52 | head->setFrame(7); | 50 | head->setFrame(7); |
53 | snakelist.insert(0, head); | 51 | snakelist.insert(0, head); |
54 | head->show(); | 52 | head->show(); |
55 | head->move(34, 16); | 53 | head->move(34, 16); |
56 | 54 | ||
57 | QCanvasSprite* body = new QCanvasSprite(snakeparts, canvas ); | 55 | QCanvasSprite* body = new QCanvasSprite(snakeparts, canvas ); |
58 | body->setFrame(6); | 56 | body->setFrame(6); |
59 | snakelist.append( body ); | 57 | snakelist.append( body ); |
60 | body->show(); | 58 | body->show(); |
61 | body->move(18, 16); | 59 | body->move(18, 16); |
62 | 60 | ||
63 | QCanvasSprite* end = new QCanvasSprite(snakeparts, canvas ); | 61 | QCanvasSprite* end = new QCanvasSprite(snakeparts, canvas ); |
64 | end->setFrame(11); | 62 | end->setFrame(11); |
65 | snakelist.append( end ); | 63 | snakelist.append( end ); |
66 | end->show(); | 64 | end->show(); |
67 | end->move(2, 16); | 65 | end->move(2, 16); |
68 | 66 | ||
69 | currentdir = right; | 67 | currentdir = right; |
70 | speed = 250; | 68 | speed = 250; |
71 | autoMoveTimer->start(speed); | 69 | autoMoveTimer->start(speed); |
72 | moveSnake(); | 70 | moveSnake(); |
73 | } | 71 | } |
74 | 72 | ||
75 | void Snake::increaseSpeed() | 73 | void Snake::increaseSpeed() |
76 | { | 74 | { |
77 | if (speed > 150) | 75 | if (speed > 150) |
78 | speed = speed - 5; | 76 | speed = speed - 5; |
79 | autoMoveTimer->start(speed); | 77 | autoMoveTimer->start(speed); |
80 | } | 78 | } |
81 | 79 | ||
82 | void Snake::go(int newkey) | 80 | void Snake::go(int newkey) |
83 | { | 81 | { |
84 | // check key is a direction | 82 | // check key is a direction |
85 | if (!( (newkey == Key_Up) || (newkey == Key_Left) || | 83 | if (!( (newkey == Key_Up) || (newkey == Key_Left) || |
86 | (newkey == Key_Right) || (newkey == Key_Down) )) | 84 | (newkey == Key_Right) || (newkey == Key_Down) )) |
87 | return; | 85 | return; |
88 | // check move is possible | 86 | // check move is possible |
89 | if ( ((currentdir == left) && ((newkey == Key_Right) || (newkey == Key_Left)) ) || | 87 | if ( ((currentdir == left) && ((newkey == Key_Right) || (newkey == Key_Left)) ) || |
90 | ((currentdir == right) && ((newkey == Key_Left) || (newkey == Key_Right)) ) || | 88 | ((currentdir == right) && ((newkey == Key_Left) || (newkey == Key_Right)) ) || |
91 | ((currentdir == up) && ((newkey == Key_Down) || (newkey == Key_Up)) ) || | 89 | ((currentdir == up) && ((newkey == Key_Down) || (newkey == Key_Up)) ) || |
92 | ((currentdir == down) && ((newkey == Key_Up) || (newkey == Key_Down)) ) ) | 90 | ((currentdir == down) && ((newkey == Key_Up) || (newkey == Key_Down)) ) ) |
93 | return; | 91 | return; |
94 | else { | 92 | else { |
95 | Snake::changeHead(newkey); | 93 | Snake::changeHead(newkey); |
96 | Snake::moveSnake(); | 94 | Snake::moveSnake(); |
97 | } | 95 | } |
98 | } | 96 | } |
99 | 97 | ||
100 | void Snake::move(Direction dir) | 98 | void Snake::move(Direction dir) |
101 | { | 99 | { |
102 | autoMoveTimer->start(speed); | 100 | autoMoveTimer->start(speed); |
103 | int x = 0; | 101 | int x = 0; |
104 | int y = 0; | 102 | int y = 0; |
105 | newdir = dir; | 103 | newdir = dir; |
106 | switch (dir) { | 104 | switch (dir) { |
107 | case right: x = 16; break; | 105 | case right: x = 16; break; |
108 | case left: x = -16; break; | 106 | case left: x = -16; break; |
109 | case down: y = 16; break; | 107 | case down: y = 16; break; |
110 | case up: y = -16; break; | 108 | case up: y = -16; break; |
111 | } | 109 | } |
112 | int index = lookUpPiece(currentdir, newdir); | 110 | int index = lookUpPiece(currentdir, newdir); |
113 | QCanvasSprite* sprite = new QCanvasSprite(snakeparts, canvas ); | 111 | QCanvasSprite* sprite = new QCanvasSprite(snakeparts, canvas ); |
114 | sprite->setFrame(index); | 112 | sprite->setFrame(index); |
115 | snakelist.insert(1, sprite); | 113 | snakelist.insert(1, sprite); |
116 | sprite->move(snakelist.first()->x(), snakelist.first()->y() ); | 114 | sprite->move(snakelist.first()->x(), snakelist.first()->y() ); |
117 | 115 | ||
118 | snakelist.first()->moveBy(x, y); | 116 | snakelist.first()->moveBy(x, y); |
119 | if (grow <= 0) | 117 | if (grow <= 0) |
120 | changeTail(); | 118 | changeTail(); |
121 | else | 119 | else |
122 | grow--; | 120 | grow--; |
123 | sprite->show(); | 121 | sprite->show(); |
124 | 122 | ||
125 | currentdir = dir; | 123 | currentdir = dir; |
126 | } | 124 | } |
127 | 125 | ||
128 | void Snake::changeTail() | 126 | void Snake::changeTail() |
129 | { | 127 | { |
130 | snakelist.removeLast(); | 128 | snakelist.removeLast(); |
131 | 129 | ||
132 | double lastx = snakelist.last()->x(); | 130 | double lastx = snakelist.last()->x(); |
133 | double prevx = snakelist.prev()->x(); | 131 | double prevx = snakelist.prev()->x(); |
134 | int index = 0; | 132 | int index = 0; |
135 | 133 | ||
136 | if ( prevx == lastx ) { //vertical | 134 | if ( prevx == lastx ) { //vertical |
137 | if ( snakelist.prev()->y() > snakelist.last()->y() ) | 135 | if ( snakelist.prev()->y() > snakelist.last()->y() ) |
138 | index = 13; | 136 | index = 13; |
139 | else | 137 | else |
140 | index = 14; | 138 | index = 14; |
141 | } else { //horizontal | 139 | } else { //horizontal |
142 | if (snakelist.prev()->x() > snakelist.last()->x() ) | 140 | if (snakelist.prev()->x() > snakelist.last()->x() ) |
143 | index = 11; | 141 | index = 11; |
144 | else | 142 | else |
145 | index = 12; | 143 | index = 12; |
146 | } | 144 | } |
147 | 145 | ||
148 | snakelist.last()->setFrame(index); | 146 | snakelist.last()->setFrame(index); |
149 | } | 147 | } |
150 | 148 | ||
151 | void Snake::changeHead(int lastkey) | 149 | void Snake::changeHead(int lastkey) |
152 | { | 150 | { |
153 | int index = 0; | 151 | int index = 0; |
154 | last = lastkey; | 152 | last = lastkey; |
155 | 153 | ||
156 | switch (last) | 154 | switch (last) |
157 | { | 155 | { |
158 | case Key_Up: index = 10; break; | 156 | case Key_Up: index = 10; break; |
159 | case Key_Left: index = 8; break; | 157 | case Key_Left: index = 8; break; |
160 | case Key_Right: index = 7; break; | 158 | case Key_Right: index = 7; break; |
161 | case Key_Down: index = 9; break; | 159 | case Key_Down: index = 9; break; |
162 | } | 160 | } |
163 | 161 | ||
164 | if (index) { | 162 | if (index) { |
165 | snakelist.first()->setFrame(index); | 163 | snakelist.first()->setFrame(index); |
166 | } | 164 | } |
167 | } | 165 | } |
168 | 166 | ||
169 | // returns an integer corresponding to a particular type of snake piece | 167 | // returns an integer corresponding to a particular type of snake piece |
170 | int Snake::lookUpPiece(Direction currentdir, Direction newdir) | 168 | int Snake::lookUpPiece(Direction currentdir, Direction newdir) |
171 | { | 169 | { |
172 | return Piecekey[currentdir][newdir]; | 170 | return Piecekey[currentdir][newdir]; |
173 | } | 171 | } |
174 | 172 | ||
175 | void Snake::extendSnake() | 173 | void Snake::extendSnake() |
176 | { | 174 | { |
177 | grow++; | 175 | grow++; |
178 | } | 176 | } |
179 | 177 | ||
180 | void Snake::moveSnake() | 178 | void Snake::moveSnake() |
181 | { | 179 | { |
182 | switch (last) | 180 | switch (last) |
183 | { | 181 | { |
184 | case Key_Up: move(up); break; | 182 | case Key_Up: move(up); break; |
185 | case Key_Left: move(left); break; | 183 | case Key_Left: move(left); break; |
186 | case Key_Right: move(right); break; | 184 | case Key_Right: move(right); break; |
187 | case Key_Down: move(down); break; | 185 | case Key_Down: move(down); break; |
188 | } | 186 | } |
189 | detectCrash(); | 187 | detectCrash(); |
190 | } | 188 | } |
191 | 189 | ||
192 | void Snake::detectCrash() | 190 | void Snake::detectCrash() |
193 | { | 191 | { |
194 | QCanvasSprite* head = snakelist.first(); | 192 | QCanvasSprite* head = snakelist.first(); |
195 | QCanvasItem* item; | 193 | QCanvasItem* item; |
196 | QCanvasItemList l=head->collisions(FALSE); | 194 | QCanvasItemList l=head->collisions(FALSE); |
197 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { | 195 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { |
198 | item = *it; | 196 | item = *it; |
199 | // check if snake hit target | 197 | // check if snake hit target |
200 | if ( (item->rtti()== 1500 ) && (item->collidesWith(head)) ) { | 198 | if ( (item->rtti()== 1500 ) && (item->collidesWith(head)) ) { |
201 | Target* target = (Target*) item; | 199 | Target* target = (Target*) item; |
202 | target->done(); | 200 | target->done(); |
203 | emit targethit(); | 201 | emit targethit(); |
204 | extendSnake(); | 202 | extendSnake(); |
205 | setScore(5); | 203 | setScore(5); |
206 | return; | 204 | return; |
207 | } | 205 | } |
208 | // check if snake hit obstacles | 206 | // check if snake hit obstacles |
209 | if ( (item->rtti()==1600) && (item->collidesWith(head)) ) { | 207 | if ( (item->rtti()==1600) && (item->collidesWith(head)) ) { |
210 | emit dead(); | 208 | emit dead(); |
211 | autoMoveTimer->stop(); | 209 | autoMoveTimer->stop(); |
212 | return; | 210 | return; |
213 | } | 211 | } |
214 | } | 212 | } |
215 | //check if snake hit itself | 213 | //check if snake hit itself |
216 | for (uint i = 3; i < snakelist.count(); i++) { | 214 | for (uint i = 3; i < snakelist.count(); i++) { |
217 | if (head->collidesWith(snakelist.at(i)) ) { | 215 | if (head->collidesWith(snakelist.at(i)) ) { |
218 | emit dead(); | 216 | emit dead(); |
219 | autoMoveTimer->stop(); | 217 | autoMoveTimer->stop(); |
220 | return; | 218 | return; |
221 | } | 219 | } |
222 | } | 220 | } |
223 | //check if snake hit edge | 221 | //check if snake hit edge |
224 | if ( (head->x() > canvas->width()-5) || (head->y() > canvas->height()-10) | 222 | if ( (head->x() > canvas->width()-5) || (head->y() > canvas->height()-10) |
225 | || (head->x() <2) || (head->y() <-5) ) { | 223 | || (head->x() <2) || (head->y() <-5) ) { |
226 | emit dead(); | 224 | emit dead(); |
227 | autoMoveTimer->stop(); | 225 | autoMoveTimer->stop(); |
228 | return; | 226 | return; |
229 | } | 227 | } |
230 | } | 228 | } |
231 | 229 | ||
232 | void Snake::setScore(int amount) | 230 | void Snake::setScore(int amount) |
233 | { | 231 | { |
234 | score = score + amount; | 232 | score = score + amount; |
235 | emit scorechanged(); | 233 | emit scorechanged(); |
236 | } | 234 | } |
237 | 235 | ||
238 | int Snake::getScore() | 236 | int Snake::getScore() |
239 | { | 237 | { |
240 | return score; | 238 | return score; |
241 | } | 239 | } |
242 | 240 | ||
243 | Snake::~Snake() | 241 | Snake::~Snake() |
244 | { | 242 | { |
245 | autoMoveTimer->stop(); | 243 | autoMoveTimer->stop(); |
246 | } | 244 | } |
diff --git a/noncore/games/solitaire/canvascard.cpp b/noncore/games/solitaire/canvascard.cpp index 7c4a5ba..c36da6c 100644 --- a/noncore/games/solitaire/canvascard.cpp +++ b/noncore/games/solitaire/canvascard.cpp | |||
@@ -1,313 +1,308 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "cardgame.h" | ||
22 | #include "canvascard.h" | 21 | #include "canvascard.h" |
23 | 22 | ||
24 | #include <qpe/resource.h> | 23 | #include <qpe/resource.h> |
25 | 24 | ||
26 | #include <qpainter.h> | ||
27 | #include <qimage.h> | ||
28 | #include <qpaintdevice.h> | ||
29 | #include <qbitmap.h> | ||
30 | #include <qgfx_qws.h> // Needed to get the device's width | 25 | #include <qgfx_qws.h> // Needed to get the device's width |
31 | 26 | ||
32 | #include <math.h> | 27 | #include <math.h> |
33 | 28 | ||
34 | #if defined( QT_QWS_CASSIOPEIA ) | 29 | #if defined( QT_QWS_CASSIOPEIA ) |
35 | #define SLOW_HARDWARE | 30 | #define SLOW_HARDWARE |
36 | #endif | 31 | #endif |
37 | 32 | ||
38 | // Seems to be fast enough to me even without Transformations in the library | 33 | // Seems to be fast enough to me even without Transformations in the library |
39 | //#if defined( QT_NO_TRANSFORMATIONS ) && defined( QT_QWS_IPAQ ) | 34 | //#if defined( QT_NO_TRANSFORMATIONS ) && defined( QT_QWS_IPAQ ) |
40 | //#define SLOW_HARDWARE | 35 | //#define SLOW_HARDWARE |
41 | //#endif | 36 | //#endif |
42 | 37 | ||
43 | 38 | ||
44 | QBitmap *Create180RotatedBitmap(QBitmap *srcBitmap) | 39 | QBitmap *Create180RotatedBitmap(QBitmap *srcBitmap) |
45 | { | 40 | { |
46 | #ifdef QT_NO_TRANSFORMATIONS | 41 | #ifdef QT_NO_TRANSFORMATIONS |
47 | int w = srcBitmap->width(); | 42 | int w = srcBitmap->width(); |
48 | int h = srcBitmap->height(); | 43 | int h = srcBitmap->height(); |
49 | QBitmap *dstBitmap = new QBitmap( w, h ); | 44 | QBitmap *dstBitmap = new QBitmap( w, h ); |
50 | // ### this is very poorly implemented and probably could be much faster | 45 | // ### this is very poorly implemented and probably could be much faster |
51 | for (int i = 0; i < w; i++) | 46 | for (int i = 0; i < w; i++) |
52 | for (int j = 0; j < h; j++) | 47 | for (int j = 0; j < h; j++) |
53 | bitBlt( dstBitmap, i, j, srcBitmap, w - i - 1, h - j - 1, 1, 1 ); | 48 | bitBlt( dstBitmap, i, j, srcBitmap, w - i - 1, h - j - 1, 1, 1 ); |
54 | return dstBitmap; | 49 | return dstBitmap; |
55 | #else | 50 | #else |
56 | QWMatrix m; | 51 | QWMatrix m; |
57 | m.rotate( 180.0 ); | 52 | m.rotate( 180.0 ); |
58 | return new QBitmap( srcBitmap->xForm( m ) ); | 53 | return new QBitmap( srcBitmap->xForm( m ) ); |
59 | #endif | 54 | #endif |
60 | } | 55 | } |
61 | 56 | ||
62 | 57 | ||
63 | QPixmap *CreateScaledPixmap(QPixmap *srcPixmap, double scaleX, double scaleY) | 58 | QPixmap *CreateScaledPixmap(QPixmap *srcPixmap, double scaleX, double scaleY) |
64 | { | 59 | { |
65 | #ifdef QT_NO_TRANSFORMATIONS | 60 | #ifdef QT_NO_TRANSFORMATIONS |
66 | int w = srcPixmap->width(); | 61 | int w = srcPixmap->width(); |
67 | int h = srcPixmap->height(); | 62 | int h = srcPixmap->height(); |
68 | int newW = (int)(w * scaleX); | 63 | int newW = (int)(w * scaleX); |
69 | int newH = (int)(h * scaleY); | 64 | int newH = (int)(h * scaleY); |
70 | QPixmap *dstPixmap = new QPixmap( newW, newH ); | 65 | QPixmap *dstPixmap = new QPixmap( newW, newH ); |
71 | // ### this is very poorly implemented and probably could be much faster | 66 | // ### this is very poorly implemented and probably could be much faster |
72 | for (int i = 0; i < newW; i++) { | 67 | for (int i = 0; i < newW; i++) { |
73 | int srcX = w * i / newW; | 68 | int srcX = w * i / newW; |
74 | if (newH == h) { | 69 | if (newH == h) { |
75 | // Optimise for scaleing in the X-axis only | 70 | // Optimise for scaleing in the X-axis only |
76 | bitBlt( dstPixmap, i, 0, srcPixmap, srcX, 0, 1, h ); | 71 | bitBlt( dstPixmap, i, 0, srcPixmap, srcX, 0, 1, h ); |
77 | } else { | 72 | } else { |
78 | for (int j = 0; j < newH; j++) { | 73 | for (int j = 0; j < newH; j++) { |
79 | int srcY = h * j / newH; | 74 | int srcY = h * j / newH; |
80 | bitBlt( dstPixmap, i, j, srcPixmap, srcX, srcY, 1, 1 ); | 75 | bitBlt( dstPixmap, i, j, srcPixmap, srcX, srcY, 1, 1 ); |
81 | } | 76 | } |
82 | } | 77 | } |
83 | } | 78 | } |
84 | return dstPixmap; | 79 | return dstPixmap; |
85 | #else | 80 | #else |
86 | QWMatrix s; | 81 | QWMatrix s; |
87 | s.scale( scaleX, scaleY ); | 82 | s.scale( scaleX, scaleY ); |
88 | return new QPixmap( srcPixmap->xForm( s ) ); | 83 | return new QPixmap( srcPixmap->xForm( s ) ); |
89 | #endif | 84 | #endif |
90 | } | 85 | } |
91 | 86 | ||
92 | 87 | ||
93 | // Initialise static member variables to NULL | 88 | // Initialise static member variables to NULL |
94 | QPixmap *CanvasCard::cardsFaces = NULL; | 89 | QPixmap *CanvasCard::cardsFaces = NULL; |
95 | QPixmap *CanvasCard::cardsBacks = NULL; | 90 | QPixmap *CanvasCard::cardsBacks = NULL; |
96 | QBitmap *CanvasCard::cardsChars = NULL; | 91 | QBitmap *CanvasCard::cardsChars = NULL; |
97 | QBitmap *CanvasCard::cardsSuits = NULL; | 92 | QBitmap *CanvasCard::cardsSuits = NULL; |
98 | QBitmap *CanvasCard::cardsCharsUpsideDown = NULL; | 93 | QBitmap *CanvasCard::cardsCharsUpsideDown = NULL; |
99 | QBitmap *CanvasCard::cardsSuitsUpsideDown = NULL; | 94 | QBitmap *CanvasCard::cardsSuitsUpsideDown = NULL; |
100 | 95 | ||
101 | 96 | ||
102 | CanvasCard::CanvasCard( eValue v, eSuit s, bool f, QCanvas *canvas ) : | 97 | CanvasCard::CanvasCard( eValue v, eSuit s, bool f, QCanvas *canvas ) : |
103 | Card(v, s, f), QCanvasRectangle( 0, 0, 1, 1, canvas ), cardBack(1), scaleX(1.0), scaleY(1.0) | 98 | Card(v, s, f), QCanvasRectangle( 0, 0, 1, 1, canvas ), cardBack(1), scaleX(1.0), scaleY(1.0) |
104 | { | 99 | { |
105 | if ( !cardsFaces ) { | 100 | if ( !cardsFaces ) { |
106 | if ( qt_screen->deviceWidth() < 200 ) { | 101 | if ( qt_screen->deviceWidth() < 200 ) { |
107 | cardsFaces = new QPixmap( Resource::loadPixmap( "cards/card_face_small" ) ); | 102 | cardsFaces = new QPixmap( Resource::loadPixmap( "cards/card_face_small" ) ); |
108 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001_small" ) ); | 103 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001_small" ) ); |
109 | cardsChars = new QBitmap( Resource::loadBitmap( "cards/card_chars_small" ) ); | 104 | cardsChars = new QBitmap( Resource::loadBitmap( "cards/card_chars_small" ) ); |
110 | cardsSuits = new QBitmap( Resource::loadBitmap( "cards/card_suits_small" ) ); | 105 | cardsSuits = new QBitmap( Resource::loadBitmap( "cards/card_suits_small" ) ); |
111 | } else { | 106 | } else { |
112 | cardsFaces = new QPixmap( Resource::loadPixmap( "cards/card_face" ) ); | 107 | cardsFaces = new QPixmap( Resource::loadPixmap( "cards/card_face" ) ); |
113 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001" ) ); | 108 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001" ) ); |
114 | cardsChars = new QBitmap( Resource::loadBitmap( "cards/card_chars" ) ); | 109 | cardsChars = new QBitmap( Resource::loadBitmap( "cards/card_chars" ) ); |
115 | cardsSuits = new QBitmap( Resource::loadBitmap( "cards/card_suits" ) ); | 110 | cardsSuits = new QBitmap( Resource::loadBitmap( "cards/card_suits" ) ); |
116 | } | 111 | } |
117 | cardsCharsUpsideDown = Create180RotatedBitmap( cardsChars ); | 112 | cardsCharsUpsideDown = Create180RotatedBitmap( cardsChars ); |
118 | cardsSuitsUpsideDown = Create180RotatedBitmap( cardsSuits ); | 113 | cardsSuitsUpsideDown = Create180RotatedBitmap( cardsSuits ); |
119 | } | 114 | } |
120 | xOff = cardsFaces->width() / 2; | 115 | xOff = cardsFaces->width() / 2; |
121 | yOff = cardsFaces->height() / 2; | 116 | yOff = cardsFaces->height() / 2; |
122 | setSize( cardsFaces->width(), cardsFaces->height() ); | 117 | setSize( cardsFaces->width(), cardsFaces->height() ); |
123 | setPen( NoPen ); | 118 | setPen( NoPen ); |
124 | flipping = FALSE; | 119 | flipping = FALSE; |
125 | } | 120 | } |
126 | 121 | ||
127 | 122 | ||
128 | void CanvasCard::setCardBack(int b) | 123 | void CanvasCard::setCardBack(int b) |
129 | { | 124 | { |
130 | if ( cardBack != b ) { | 125 | if ( cardBack != b ) { |
131 | 126 | ||
132 | cardBack = b; | 127 | cardBack = b; |
133 | 128 | ||
134 | if ( cardsBacks ) | 129 | if ( cardsBacks ) |
135 | delete cardsBacks; | 130 | delete cardsBacks; |
136 | 131 | ||
137 | if ( qt_screen->deviceWidth() < 200 ) { | 132 | if ( qt_screen->deviceWidth() < 200 ) { |
138 | switch (cardBack) { | 133 | switch (cardBack) { |
139 | case 0: | 134 | case 0: |
140 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001_small" ) ); break; | 135 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001_small" ) ); break; |
141 | case 1: | 136 | case 1: |
142 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0002_small" ) ); break; | 137 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0002_small" ) ); break; |
143 | case 2: | 138 | case 2: |
144 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0003_small" ) ); break; | 139 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0003_small" ) ); break; |
145 | case 3: | 140 | case 3: |
146 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0004_small" ) ); break; | 141 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0004_small" ) ); break; |
147 | case 4: | 142 | case 4: |
148 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0005_small" ) ); break; | 143 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0005_small" ) ); break; |
149 | } | 144 | } |
150 | } else { | 145 | } else { |
151 | switch (cardBack) { | 146 | switch (cardBack) { |
152 | case 0: | 147 | case 0: |
153 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001" ) ); break; | 148 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0001" ) ); break; |
154 | case 1: | 149 | case 1: |
155 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0002" ) ); break; | 150 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0002" ) ); break; |
156 | case 2: | 151 | case 2: |
157 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0003" ) ); break; | 152 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0003" ) ); break; |
158 | case 3: | 153 | case 3: |
159 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0004" ) ); break; | 154 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0004" ) ); break; |
160 | case 4: | 155 | case 4: |
161 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0005" ) ); break; | 156 | cardsBacks = new QPixmap( Resource::loadPixmap( "cards/card_back0005" ) ); break; |
162 | } | 157 | } |
163 | } | 158 | } |
164 | 159 | ||
165 | if ( !isFacing() ) | 160 | if ( !isFacing() ) |
166 | redraw(); | 161 | redraw(); |
167 | } | 162 | } |
168 | } | 163 | } |
169 | 164 | ||
170 | 165 | ||
171 | void CanvasCard::draw(QPainter &painter) | 166 | void CanvasCard::draw(QPainter &painter) |
172 | { | 167 | { |
173 | int ix = (int)x(), iy = (int)y(); | 168 | int ix = (int)x(), iy = (int)y(); |
174 | 169 | ||
175 | QPainter *p = &painter; | 170 | QPainter *p = &painter; |
176 | QPixmap *unscaledCard = NULL; | 171 | QPixmap *unscaledCard = NULL; |
177 | 172 | ||
178 | if ((scaleX <= 0.98) || (scaleY <= 0.98)) | 173 | if ((scaleX <= 0.98) || (scaleY <= 0.98)) |
179 | { | 174 | { |
180 | p = new QPainter(); | 175 | p = new QPainter(); |
181 | unscaledCard = new QPixmap( cardsFaces->width(), cardsFaces->height() ); | 176 | unscaledCard = new QPixmap( cardsFaces->width(), cardsFaces->height() ); |
182 | p->begin(unscaledCard); | 177 | p->begin(unscaledCard); |
183 | ix = 0; | 178 | ix = 0; |
184 | iy = 0; | 179 | iy = 0; |
185 | } | 180 | } |
186 | 181 | ||
187 | if ( isFacing() ) { | 182 | if ( isFacing() ) { |
188 | 183 | ||
189 | /* | 184 | /* |
190 | // Now add the joker and card backs to the list of pixmaps | 185 | // Now add the joker and card backs to the list of pixmaps |
191 | QPixmap *CardsBack = new QPixmap( Resource::loadPixmap( "cards/card_joker.png" ) ); | 186 | QPixmap *CardsBack = new QPixmap( Resource::loadPixmap( "cards/card_joker.png" ) ); |
192 | QPoint *newBackHotspot = new QPoint( 0, 0 ); | 187 | QPoint *newBackHotspot = new QPoint( 0, 0 ); |
193 | pixmaps->append((const QPixmap *)CardsBack); | 188 | pixmaps->append((const QPixmap *)CardsBack); |
194 | hotspots->append((const QPoint *)newBackHotspot); | 189 | hotspots->append((const QPoint *)newBackHotspot); |
195 | */ | 190 | */ |
196 | 191 | ||
197 | int w = cardsFaces->width(), h = cardsFaces->height(); | 192 | int w = cardsFaces->width(), h = cardsFaces->height(); |
198 | 193 | ||
199 | //p->setBrush( NoBrush ); | 194 | //p->setBrush( NoBrush ); |
200 | p->setBrush( QColor( 0xFF, 0xFF, 0xFF ) ); | 195 | p->setBrush( QColor( 0xFF, 0xFF, 0xFF ) ); |
201 | 196 | ||
202 | if ( isRed() == TRUE ) | 197 | if ( isRed() == TRUE ) |
203 | p->setPen( QColor( 0xFF, 0, 0 ) ); | 198 | p->setPen( QColor( 0xFF, 0, 0 ) ); |
204 | else | 199 | else |
205 | p->setPen( QColor( 0, 0, 0 ) ); | 200 | p->setPen( QColor( 0, 0, 0 ) ); |
206 | 201 | ||
207 | if ( qt_screen->deviceWidth() < 200 ) { | 202 | if ( qt_screen->deviceWidth() < 200 ) { |
208 | p->drawPixmap( ix + 0, iy + 0, *cardsFaces ); | 203 | p->drawPixmap( ix + 0, iy + 0, *cardsFaces ); |
209 | p->drawPixmap( ix + 3, iy + 3, *cardsChars, 5*(getValue()-1), 0, 5, 6 ); | 204 | p->drawPixmap( ix + 3, iy + 3, *cardsChars, 5*(getValue()-1), 0, 5, 6 ); |
210 | p->drawPixmap( ix + 11, iy + 3, *cardsSuits, 5*(getSuit()-1), 0, 5, 6 ); | 205 | p->drawPixmap( ix + 11, iy + 3, *cardsSuits, 5*(getSuit()-1), 0, 5, 6 ); |
211 | p->drawPixmap( ix + w-3-5, iy + h-3-6, *cardsCharsUpsideDown, 5*(12-getValue()+1), 0, 5, 6 ); | 206 | p->drawPixmap( ix + w-3-5, iy + h-3-6, *cardsCharsUpsideDown, 5*(12-getValue()+1), 0, 5, 6 ); |
212 | p->drawPixmap( ix + w-11-5, iy + h-3-6, *cardsSuitsUpsideDown, 5*(3-getSuit()+1), 0, 5, 6 ); | 207 | p->drawPixmap( ix + w-11-5, iy + h-3-6, *cardsSuitsUpsideDown, 5*(3-getSuit()+1), 0, 5, 6 ); |
213 | } else { | 208 | } else { |
214 | p->drawPixmap( ix + 0, iy + 0, *cardsFaces ); | 209 | p->drawPixmap( ix + 0, iy + 0, *cardsFaces ); |
215 | p->drawPixmap( ix + 4, iy + 4, *cardsChars, 7*(getValue()-1), 0, 7, 7 ); | 210 | p->drawPixmap( ix + 4, iy + 4, *cardsChars, 7*(getValue()-1), 0, 7, 7 ); |
216 | p->drawPixmap( ix + 12, iy + 4, *cardsSuits, 7*(getSuit()-1), 0, 7, 8 ); | 211 | p->drawPixmap( ix + 12, iy + 4, *cardsSuits, 7*(getSuit()-1), 0, 7, 8 ); |
217 | p->drawPixmap( ix + w-4-7, iy + h-4-7, *cardsCharsUpsideDown, 7*(12-getValue()+1), 0, 7, 7 ); | 212 | p->drawPixmap( ix + w-4-7, iy + h-4-7, *cardsCharsUpsideDown, 7*(12-getValue()+1), 0, 7, 7 ); |
218 | p->drawPixmap( ix + w-12-7, iy + h-5-7, *cardsSuitsUpsideDown, 7*(3-getSuit()+1), 0, 7, 8 ); | 213 | p->drawPixmap( ix + w-12-7, iy + h-5-7, *cardsSuitsUpsideDown, 7*(3-getSuit()+1), 0, 7, 8 ); |
219 | } | 214 | } |
220 | 215 | ||
221 | } else { | 216 | } else { |
222 | 217 | ||
223 | p->drawPixmap( ix, iy, *cardsBacks ); | 218 | p->drawPixmap( ix, iy, *cardsBacks ); |
224 | 219 | ||
225 | } | 220 | } |
226 | 221 | ||
227 | if (p != &painter) | 222 | if (p != &painter) |
228 | { | 223 | { |
229 | p->end(); | 224 | p->end(); |
230 | QPixmap *scaledCard = CreateScaledPixmap( unscaledCard, scaleX, scaleY ); | 225 | QPixmap *scaledCard = CreateScaledPixmap( unscaledCard, scaleX, scaleY ); |
231 | int xoff = scaledCard->width() / 2; | 226 | int xoff = scaledCard->width() / 2; |
232 | int yoff = scaledCard->height() / 2; | 227 | int yoff = scaledCard->height() / 2; |
233 | painter.drawPixmap( (int)x() + xOff - xoff, (int)y() + yOff - yoff, *scaledCard ); | 228 | painter.drawPixmap( (int)x() + xOff - xoff, (int)y() + yOff - yoff, *scaledCard ); |
234 | delete p; | 229 | delete p; |
235 | delete unscaledCard; | 230 | delete unscaledCard; |
236 | delete scaledCard; | 231 | delete scaledCard; |
237 | } | 232 | } |
238 | } | 233 | } |
239 | 234 | ||
240 | 235 | ||
241 | static const double flipLift = 1.5; | 236 | static const double flipLift = 1.5; |
242 | 237 | ||
243 | 238 | ||
244 | void CanvasCard::flipTo(int x2, int y2, int steps) | 239 | void CanvasCard::flipTo(int x2, int y2, int steps) |
245 | { | 240 | { |
246 | flipSteps = steps; | 241 | flipSteps = steps; |
247 | 242 | ||
248 | #ifdef SLOW_HARDWARE | 243 | #ifdef SLOW_HARDWARE |
249 | move(x2,y2); | 244 | move(x2,y2); |
250 | Card::flipTo(x2,y2,steps); | 245 | Card::flipTo(x2,y2,steps); |
251 | #else | 246 | #else |
252 | int x1 = (int)x(); | 247 | int x1 = (int)x(); |
253 | int y1 = (int)y(); | 248 | int y1 = (int)y(); |
254 | double dx = x2 - x1; | 249 | double dx = x2 - x1; |
255 | double dy = y2 - y1; | 250 | double dy = y2 - y1; |
256 | 251 | ||
257 | flipping = TRUE; | 252 | flipping = TRUE; |
258 | destX = x2; | 253 | destX = x2; |
259 | destY = y2; | 254 | destY = y2; |
260 | animSteps = flipSteps; | 255 | animSteps = flipSteps; |
261 | setVelocity(dx/animSteps, dy/animSteps-flipLift); | 256 | setVelocity(dx/animSteps, dy/animSteps-flipLift); |
262 | setAnimated(TRUE); | 257 | setAnimated(TRUE); |
263 | #endif | 258 | #endif |
264 | } | 259 | } |
265 | 260 | ||
266 | 261 | ||
267 | void CanvasCard::advance(int stage) | 262 | void CanvasCard::advance(int stage) |
268 | { | 263 | { |
269 | if ( stage==1 ) { | 264 | if ( stage==1 ) { |
270 | if ( animSteps-- <= 0 ) { | 265 | if ( animSteps-- <= 0 ) { |
271 | scaleX = 1.0; | 266 | scaleX = 1.0; |
272 | scaleY = 1.0; | 267 | scaleY = 1.0; |
273 | flipping = FALSE; | 268 | flipping = FALSE; |
274 | setVelocity(0,0); | 269 | setVelocity(0,0); |
275 | setAnimated(FALSE); | 270 | setAnimated(FALSE); |
276 | move(destX,destY); // exact | 271 | move(destX,destY); // exact |
277 | } else { | 272 | } else { |
278 | if ( flipping ) { | 273 | if ( flipping ) { |
279 | if ( animSteps > flipSteps / 2 ) { | 274 | if ( animSteps > flipSteps / 2 ) { |
280 | // animSteps = flipSteps .. flipSteps/2 (flip up) -> 1..0 | 275 | // animSteps = flipSteps .. flipSteps/2 (flip up) -> 1..0 |
281 | scaleX = ((double)animSteps/flipSteps-0.5)*2; | 276 | scaleX = ((double)animSteps/flipSteps-0.5)*2; |
282 | } else { | 277 | } else { |
283 | // animSteps = flipSteps/2 .. 0 (flip down) -> 0..1 | 278 | // animSteps = flipSteps/2 .. 0 (flip down) -> 0..1 |
284 | scaleX = 1-((double)animSteps/flipSteps)*2; | 279 | scaleX = 1-((double)animSteps/flipSteps)*2; |
285 | } | 280 | } |
286 | if ( animSteps == flipSteps / 2-1 ) { | 281 | if ( animSteps == flipSteps / 2-1 ) { |
287 | setYVelocity(yVelocity()+flipLift*2); | 282 | setYVelocity(yVelocity()+flipLift*2); |
288 | setFace( !isFacing() ); | 283 | setFace( !isFacing() ); |
289 | } | 284 | } |
290 | } | 285 | } |
291 | } | 286 | } |
292 | } | 287 | } |
293 | QCanvasRectangle::advance(stage); | 288 | QCanvasRectangle::advance(stage); |
294 | } | 289 | } |
295 | 290 | ||
296 | 291 | ||
297 | void CanvasCard::animatedMove(int x2, int y2, int steps) | 292 | void CanvasCard::animatedMove(int x2, int y2, int steps) |
298 | { | 293 | { |
299 | destX = x2; | 294 | destX = x2; |
300 | destY = y2; | 295 | destY = y2; |
301 | 296 | ||
302 | double x1 = x(), y1 = y(), dx = x2 - x1, dy = y2 - y1; | 297 | double x1 = x(), y1 = y(), dx = x2 - x1, dy = y2 - y1; |
303 | 298 | ||
304 | // Ensure a good speed | 299 | // Ensure a good speed |
305 | while ( fabs(dx/steps)+fabs(dy/steps) < 5.0 && steps > 4 ) | 300 | while ( fabs(dx/steps)+fabs(dy/steps) < 5.0 && steps > 4 ) |
306 | steps--; | 301 | steps--; |
307 | 302 | ||
308 | setAnimated(TRUE); | 303 | setAnimated(TRUE); |
309 | setVelocity(dx/steps, dy/steps); | 304 | setVelocity(dx/steps, dy/steps); |
310 | 305 | ||
311 | animSteps = steps; | 306 | animSteps = steps; |
312 | } | 307 | } |
313 | 308 | ||
diff --git a/noncore/games/solitaire/canvascardgame.cpp b/noncore/games/solitaire/canvascardgame.cpp index 9ae2a23..ed5748e 100644 --- a/noncore/games/solitaire/canvascardgame.cpp +++ b/noncore/games/solitaire/canvascardgame.cpp | |||
@@ -1,388 +1,380 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "cardgame.h" | ||
22 | #include "canvasshapes.h" | ||
23 | #include "canvascard.h" | ||
24 | #include "canvascardgame.h" | 21 | #include "canvascardgame.h" |
25 | 22 | ||
26 | #include <qpe/resource.h> | ||
27 | #include <qpe/config.h> | ||
28 | 23 | ||
29 | #include <qmainwindow.h> | ||
30 | #include <qmenubar.h> | ||
31 | #include <qpainter.h> | ||
32 | #include <qgfx_qws.h> | 24 | #include <qgfx_qws.h> |
33 | 25 | ||
34 | #include <stdlib.h> | 26 | #include <stdlib.h> |
35 | #include <limits.h> | 27 | #include <limits.h> |
36 | #include <time.h> | 28 | #include <time.h> |
37 | #include <math.h> | 29 | #include <math.h> |
38 | 30 | ||
39 | 31 | ||
40 | extern int highestZ; | 32 | extern int highestZ; |
41 | 33 | ||
42 | 34 | ||
43 | class CanvasCardPile : public QCanvasRectangle | 35 | class CanvasCardPile : public QCanvasRectangle |
44 | { | 36 | { |
45 | public: | 37 | public: |
46 | CanvasCardPile( CanvasCardGame *ccg, QCanvas *canvas ) : QCanvasRectangle( canvas ), parent( ccg ) { | 38 | CanvasCardPile( CanvasCardGame *ccg, QCanvas *canvas ) : QCanvasRectangle( canvas ), parent( ccg ) { |
47 | pile = new QPixmap( 0, 0 ); | 39 | pile = new QPixmap( 0, 0 ); |
48 | pileHeight = 0; | 40 | pileHeight = 0; |
49 | firstCard = NULL; | 41 | firstCard = NULL; |
50 | } | 42 | } |
51 | 43 | ||
52 | void addCard( CanvasCard *card ); | 44 | void addCard( CanvasCard *card ); |
53 | void advance(int stage); | 45 | void advance(int stage); |
54 | void animatedMove() { animatedMove(savedX, savedY); } | 46 | void animatedMove() { animatedMove(savedX, savedY); } |
55 | void savePos(void) { savedX = (int)x(); savedY = (int)y(); } | 47 | void savePos(void) { savedX = (int)x(); savedY = (int)y(); } |
56 | void animatedMove(int x2, int y2, int steps = 7 ); | 48 | void animatedMove(int x2, int y2, int steps = 7 ); |
57 | 49 | ||
58 | protected: | 50 | protected: |
59 | virtual void draw( QPainter& p ); | 51 | virtual void draw( QPainter& p ); |
60 | 52 | ||
61 | private: | 53 | private: |
62 | CanvasCardGame *parent; | 54 | CanvasCardGame *parent; |
63 | QPixmap *pile; | 55 | QPixmap *pile; |
64 | QImage tempImage32; | 56 | QImage tempImage32; |
65 | CanvasCard *firstCard; | 57 | CanvasCard *firstCard; |
66 | int pileHeight; | 58 | int pileHeight; |
67 | int destX, destY; | 59 | int destX, destY; |
68 | int savedX, savedY; | 60 | int savedX, savedY; |
69 | int animSteps; | 61 | int animSteps; |
70 | }; | 62 | }; |
71 | 63 | ||
72 | 64 | ||
73 | void CanvasCardPile::addCard( CanvasCard *card ) | 65 | void CanvasCardPile::addCard( CanvasCard *card ) |
74 | { | 66 | { |
75 | int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13; | 67 | int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13; |
76 | int cardHeight = ( qt_screen->deviceWidth() < 200 ) ? 27 : 36; | 68 | int cardHeight = ( qt_screen->deviceWidth() < 200 ) ? 27 : 36; |
77 | int cardWidth = ( qt_screen->deviceWidth() < 200 ) ? 20 : 23; | 69 | int cardWidth = ( qt_screen->deviceWidth() < 200 ) ? 20 : 23; |
78 | 70 | ||
79 | if ( !firstCard ) | 71 | if ( !firstCard ) |
80 | firstCard = card; | 72 | firstCard = card; |
81 | 73 | ||
82 | int height = cardHeight + pileHeight * offsetDown; | 74 | int height = cardHeight + pileHeight * offsetDown; |
83 | setSize( cardWidth, height ); | 75 | setSize( cardWidth, height ); |
84 | pile->resize( cardWidth, height ); | 76 | pile->resize( cardWidth, height ); |
85 | QPainter p( pile ); | 77 | QPainter p( pile ); |
86 | p.translate( -card->x(), -card->y() + pileHeight * offsetDown ); | 78 | p.translate( -card->x(), -card->y() + pileHeight * offsetDown ); |
87 | card->draw( p ); | 79 | card->draw( p ); |
88 | pileHeight++; | 80 | pileHeight++; |
89 | 81 | ||
90 | QImage tempImage; | 82 | QImage tempImage; |
91 | tempImage = *pile; | 83 | tempImage = *pile; |
92 | tempImage32 = tempImage.convertDepth( 32 ); | 84 | tempImage32 = tempImage.convertDepth( 32 ); |
93 | tempImage32.setAlphaBuffer( TRUE ); | 85 | tempImage32.setAlphaBuffer( TRUE ); |
94 | for ( int i = 0; i < tempImage32.width(); i++ ) | 86 | for ( int i = 0; i < tempImage32.width(); i++ ) |
95 | for ( int j = 0; j < tempImage32.height(); j++ ) { | 87 | for ( int j = 0; j < tempImage32.height(); j++ ) { |
96 | QRgb col = tempImage32.pixel( i, j ); | 88 | QRgb col = tempImage32.pixel( i, j ); |
97 | int a = 255-j*220/tempImage32.height(); | 89 | int a = 255-j*220/tempImage32.height(); |
98 | QRgb alpha = qRgba( qRed( col ), qGreen( col ), qBlue( col ), a ); | 90 | QRgb alpha = qRgba( qRed( col ), qGreen( col ), qBlue( col ), a ); |
99 | tempImage32.setPixel( i, j, alpha ); | 91 | tempImage32.setPixel( i, j, alpha ); |
100 | } | 92 | } |
101 | 93 | ||
102 | QRgb alpha = qRgba( 0, 0, 0, 0 ); | 94 | QRgb alpha = qRgba( 0, 0, 0, 0 ); |
103 | tempImage32.setPixel( 1, 0, alpha ); | 95 | tempImage32.setPixel( 1, 0, alpha ); |
104 | tempImage32.setPixel( 0, 0, alpha ); | 96 | tempImage32.setPixel( 0, 0, alpha ); |
105 | tempImage32.setPixel( 0, 1, alpha ); | 97 | tempImage32.setPixel( 0, 1, alpha ); |
106 | 98 | ||
107 | tempImage32.setPixel( cardWidth - 2, 0, alpha ); | 99 | tempImage32.setPixel( cardWidth - 2, 0, alpha ); |
108 | tempImage32.setPixel( cardWidth - 1, 0, alpha ); | 100 | tempImage32.setPixel( cardWidth - 1, 0, alpha ); |
109 | tempImage32.setPixel( cardWidth - 1, 1, alpha ); | 101 | tempImage32.setPixel( cardWidth - 1, 1, alpha ); |
110 | height--; | 102 | height--; |
111 | tempImage32.setPixel( 1, height, alpha ); | 103 | tempImage32.setPixel( 1, height, alpha ); |
112 | tempImage32.setPixel( 0, height - 1, alpha ); | 104 | tempImage32.setPixel( 0, height - 1, alpha ); |
113 | tempImage32.setPixel( 0, height, alpha ); | 105 | tempImage32.setPixel( 0, height, alpha ); |
114 | 106 | ||
115 | tempImage32.setPixel( cardWidth - 2, height, alpha ); | 107 | tempImage32.setPixel( cardWidth - 2, height, alpha ); |
116 | tempImage32.setPixel( cardWidth - 1, height, alpha ); | 108 | tempImage32.setPixel( cardWidth - 1, height, alpha ); |
117 | tempImage32.setPixel( cardWidth - 1, height - 1, alpha ); | 109 | tempImage32.setPixel( cardWidth - 1, height - 1, alpha ); |
118 | } | 110 | } |
119 | 111 | ||
120 | 112 | ||
121 | void CanvasCardPile::advance(int stage) | 113 | void CanvasCardPile::advance(int stage) |
122 | { | 114 | { |
123 | if ( stage==1 ) { | 115 | if ( stage==1 ) { |
124 | if ( animSteps-- <= 0 ) { | 116 | if ( animSteps-- <= 0 ) { |
125 | CanvasCard *item = firstCard; | 117 | CanvasCard *item = firstCard; |
126 | while (item) { | 118 | while (item) { |
127 | item->show(); | 119 | item->show(); |
128 | item = (CanvasCard *)item->getCardPile()->cardInfront(item); | 120 | item = (CanvasCard *)item->getCardPile()->cardInfront(item); |
129 | } | 121 | } |
130 | setVelocity(0,0); | 122 | setVelocity(0,0); |
131 | setAnimated(FALSE); | 123 | setAnimated(FALSE); |
132 | parent->cancelMoving(); | 124 | parent->cancelMoving(); |
133 | hide(); | 125 | hide(); |
134 | move(destX,destY); // exact | 126 | move(destX,destY); // exact |
135 | } | 127 | } |
136 | } | 128 | } |
137 | QCanvasRectangle::advance(stage); | 129 | QCanvasRectangle::advance(stage); |
138 | } | 130 | } |
139 | 131 | ||
140 | 132 | ||
141 | void CanvasCardPile::animatedMove(int x2, int y2, int steps ) | 133 | void CanvasCardPile::animatedMove(int x2, int y2, int steps ) |
142 | { | 134 | { |
143 | destX = x2; | 135 | destX = x2; |
144 | destY = y2; | 136 | destY = y2; |
145 | 137 | ||
146 | double x1 = x(), y1 = y(), dx = x2 - x1, dy = y2 - y1; | 138 | double x1 = x(), y1 = y(), dx = x2 - x1, dy = y2 - y1; |
147 | 139 | ||
148 | // Ensure a good speed | 140 | // Ensure a good speed |
149 | while ( fabs(dx/steps)+fabs(dy/steps) < 5.0 && steps > 4 ) | 141 | while ( fabs(dx/steps)+fabs(dy/steps) < 5.0 && steps > 4 ) |
150 | steps--; | 142 | steps--; |
151 | 143 | ||
152 | setAnimated(TRUE); | 144 | setAnimated(TRUE); |
153 | setVelocity(dx/steps, dy/steps); | 145 | setVelocity(dx/steps, dy/steps); |
154 | 146 | ||
155 | animSteps = steps; | 147 | animSteps = steps; |
156 | } | 148 | } |
157 | 149 | ||
158 | 150 | ||
159 | void CanvasCardPile::draw( QPainter& p ) | 151 | void CanvasCardPile::draw( QPainter& p ) |
160 | { | 152 | { |
161 | int ix = (int)x(), iy = (int)y(); | 153 | int ix = (int)x(), iy = (int)y(); |
162 | p.drawImage( ix, iy, tempImage32 ); | 154 | p.drawImage( ix, iy, tempImage32 ); |
163 | } | 155 | } |
164 | 156 | ||
165 | 157 | ||
166 | CanvasCardGame::~CanvasCardGame() { | 158 | CanvasCardGame::~CanvasCardGame() { |
167 | // the deletion stuff should be fixed now and only deletes | 159 | // the deletion stuff should be fixed now and only deletes |
168 | // items created by this CardGame. I haven't verified there are zero | 160 | // items created by this CardGame. I haven't verified there are zero |
169 | // memory leaks yet | 161 | // memory leaks yet |
170 | if ( alphaCardPile ) | 162 | if ( alphaCardPile ) |
171 | delete alphaCardPile; | 163 | delete alphaCardPile; |
172 | } | 164 | } |
173 | 165 | ||
174 | 166 | ||
175 | void CanvasCardGame::gameWon() { | 167 | void CanvasCardGame::gameWon() { |
176 | 168 | ||
177 | srand(time(NULL)); | 169 | srand(time(NULL)); |
178 | 170 | ||
179 | QCanvasItemList list = canvas()->allItems(); | 171 | QCanvasItemList list = canvas()->allItems(); |
180 | QCanvasItemList::Iterator it = list.begin(); | 172 | QCanvasItemList::Iterator it = list.begin(); |
181 | 173 | ||
182 | for (; it != list.end(); ++it) { | 174 | for (; it != list.end(); ++it) { |
183 | if ( (*it)->rtti() == canvasCardId ) { | 175 | if ( (*it)->rtti() == canvasCardId ) { |
184 | // disperse the cards everywhere | 176 | // disperse the cards everywhere |
185 | int x = 300 - rand() % 1000; | 177 | int x = 300 - rand() % 1000; |
186 | int y = 300 + rand() % 200; | 178 | int y = 300 + rand() % 200; |
187 | ((CanvasCard *)*it)->animatedMove( x, y, 50 ); | 179 | ((CanvasCard *)*it)->animatedMove( x, y, 50 ); |
188 | } | 180 | } |
189 | } | 181 | } |
190 | } | 182 | } |
191 | 183 | ||
192 | 184 | ||
193 | void CanvasCardGame::contentsMousePressEvent(QMouseEvent *e) { | 185 | void CanvasCardGame::contentsMousePressEvent(QMouseEvent *e) { |
194 | 186 | ||
195 | if ( moving ) | 187 | if ( moving ) |
196 | return; | 188 | return; |
197 | 189 | ||
198 | QCanvasItemList l = canvas()->collisions( e->pos() ); | 190 | QCanvasItemList l = canvas()->collisions( e->pos() ); |
199 | 191 | ||
200 | for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) { | 192 | for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) { |
201 | 193 | ||
202 | if ( (*it)->rtti() == canvasCardId ) { | 194 | if ( (*it)->rtti() == canvasCardId ) { |
203 | 195 | ||
204 | moving = (CanvasCard *)*it; | 196 | moving = (CanvasCard *)*it; |
205 | 197 | ||
206 | if ( moving->animated() ) | 198 | if ( moving->animated() ) |
207 | return; | 199 | return; |
208 | 200 | ||
209 | cardXOff = (int)(e->pos().x() - moving->x()); | 201 | cardXOff = (int)(e->pos().x() - moving->x()); |
210 | cardYOff = (int)(e->pos().y() - moving->y()); | 202 | cardYOff = (int)(e->pos().y() - moving->y()); |
211 | 203 | ||
212 | if ( !mousePressCard( moving, e->pos() ) ) { | 204 | if ( !mousePressCard( moving, e->pos() ) ) { |
213 | CanvasCard *card = moving; | 205 | CanvasCard *card = moving; |
214 | 206 | ||
215 | if ( alphaCardPile ) | 207 | if ( alphaCardPile ) |
216 | delete alphaCardPile; | 208 | delete alphaCardPile; |
217 | 209 | ||
218 | alphaCardPile = new CanvasCardPile( this, canvas() ); | 210 | alphaCardPile = new CanvasCardPile( this, canvas() ); |
219 | alphaCardPile->move( card->x(), card->y() ); | 211 | alphaCardPile->move( card->x(), card->y() ); |
220 | alphaCardPile->savePos(); | 212 | alphaCardPile->savePos(); |
221 | alphaCardPile->show(); | 213 | alphaCardPile->show(); |
222 | 214 | ||
223 | while (card) { | 215 | while (card) { |
224 | alphaCardPile->addCard( card ); | 216 | alphaCardPile->addCard( card ); |
225 | card->hide(); | 217 | card->hide(); |
226 | card = (CanvasCard *)card->getCardPile()->cardInfront(card); | 218 | card = (CanvasCard *)card->getCardPile()->cardInfront(card); |
227 | } | 219 | } |
228 | 220 | ||
229 | alphaCardPile->setZ( INT_MAX ); | 221 | alphaCardPile->setZ( INT_MAX ); |
230 | 222 | ||
231 | moved = TRUE; | 223 | moved = TRUE; |
232 | } else { | 224 | } else { |
233 | if ( alphaCardPile ) | 225 | if ( alphaCardPile ) |
234 | alphaCardPile->hide(); | 226 | alphaCardPile->hide(); |
235 | } | 227 | } |
236 | return; | 228 | return; |
237 | } | 229 | } |
238 | } | 230 | } |
239 | 231 | ||
240 | mousePress( e->pos() ); | 232 | mousePress( e->pos() ); |
241 | } | 233 | } |
242 | 234 | ||
243 | /* | 235 | /* |
244 | // | 236 | // |
245 | // Should have some intelligent way to make double clicking on a | 237 | // Should have some intelligent way to make double clicking on a |
246 | // card send it to the most appropriate pile | 238 | // card send it to the most appropriate pile |
247 | // | 239 | // |
248 | void CanvasCardGame::contentsMouseDoubleClickEvent(QMouseEvent *e) { | 240 | void CanvasCardGame::contentsMouseDoubleClickEvent(QMouseEvent *e) { |
249 | QCanvasItemList l = canvas()->collisions( e->pos() ); | 241 | QCanvasItemList l = canvas()->collisions( e->pos() ); |
250 | for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) { | 242 | for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) { |
251 | if ( (*it)->rtti() == canvasCardId ) { | 243 | if ( (*it)->rtti() == canvasCardId ) { |
252 | CanvasCard *card = (CanvasCard *)*it; | 244 | CanvasCard *card = (CanvasCard *)*it; |
253 | 245 | ||
254 | if ( card->animated() ) | 246 | if ( card->animated() ) |
255 | return; | 247 | return; |
256 | 248 | ||
257 | if ( card->getCardPile()->isAllowedToBeMoved(card) ) { | 249 | if ( card->getCardPile()->isAllowedToBeMoved(card) ) { |
258 | if (card->getCardPile()->cardInfront(card) == NULL) { | 250 | if (card->getCardPile()->cardInfront(card) == NULL) { |
259 | CardPile *pile = first(); | 251 | CardPile *pile = first(); |
260 | if (pile && pile->isAllowedOnTop(card)) { | 252 | if (pile && pile->isAllowedOnTop(card)) { |
261 | // move card to this pile | 253 | // move card to this pile |
262 | return; | 254 | return; |
263 | } | 255 | } |
264 | } | 256 | } |
265 | } | 257 | } |
266 | } | 258 | } |
267 | } | 259 | } |
268 | } | 260 | } |
269 | */ | 261 | */ |
270 | 262 | ||
271 | void CanvasCardGame::contentsMouseMoveEvent(QMouseEvent *e) { | 263 | void CanvasCardGame::contentsMouseMoveEvent(QMouseEvent *e) { |
272 | 264 | ||
273 | QPoint p = e->pos(); | 265 | QPoint p = e->pos(); |
274 | 266 | ||
275 | if ( moving ) { | 267 | if ( moving ) { |
276 | 268 | ||
277 | moved = TRUE; | 269 | moved = TRUE; |
278 | 270 | ||
279 | if (moving->isFacing() != TRUE) | 271 | if (moving->isFacing() != TRUE) |
280 | return; | 272 | return; |
281 | 273 | ||
282 | int tx = (int)p.x() - cardXOff; | 274 | int tx = (int)p.x() - cardXOff; |
283 | int ty = (int)p.y() - cardYOff; | 275 | int ty = (int)p.y() - cardYOff; |
284 | 276 | ||
285 | if (snapOn == TRUE) { | 277 | if (snapOn == TRUE) { |
286 | CardPile *pile = closestPile( tx, ty, 50 ); | 278 | CardPile *pile = closestPile( tx, ty, 50 ); |
287 | if ( pile && pile->isAllowedOnTop( moving ) ) { | 279 | if ( pile && pile->isAllowedOnTop( moving ) ) { |
288 | QPoint p = pile->getHypertheticalNextCardPos(); | 280 | QPoint p = pile->getHypertheticalNextCardPos(); |
289 | if ( alphaCardPile ) | 281 | if ( alphaCardPile ) |
290 | alphaCardPile->move( p.x(), p.y() ); | 282 | alphaCardPile->move( p.x(), p.y() ); |
291 | return; | 283 | return; |
292 | } | 284 | } |
293 | } | 285 | } |
294 | 286 | ||
295 | if ( alphaCardPile ) | 287 | if ( alphaCardPile ) |
296 | alphaCardPile->move( tx, ty ); | 288 | alphaCardPile->move( tx, ty ); |
297 | } | 289 | } |
298 | 290 | ||
299 | } | 291 | } |
300 | 292 | ||
301 | 293 | ||
302 | void CanvasCardGame::contentsMouseReleaseEvent(QMouseEvent *e) | 294 | void CanvasCardGame::contentsMouseReleaseEvent(QMouseEvent *e) |
303 | { | 295 | { |
304 | QPoint p = e->pos(); | 296 | QPoint p = e->pos(); |
305 | 297 | ||
306 | Q_UNUSED(p); | 298 | Q_UNUSED(p); |
307 | 299 | ||
308 | if ( moving ) { | 300 | if ( moving ) { |
309 | 301 | ||
310 | CanvasCard *item = moving; | 302 | CanvasCard *item = moving; |
311 | 303 | ||
312 | if ( item->animated() ) | 304 | if ( item->animated() ) |
313 | return; | 305 | return; |
314 | 306 | ||
315 | if ( alphaCardPile ) | 307 | if ( alphaCardPile ) |
316 | if ( moved ) { | 308 | if ( moved ) { |
317 | 309 | ||
318 | CardPile *pile = closestPile((int)alphaCardPile->x(), (int)alphaCardPile->y(), 30); | 310 | CardPile *pile = closestPile((int)alphaCardPile->x(), (int)alphaCardPile->y(), 30); |
319 | 311 | ||
320 | if (pile && pile->isAllowedOnTop(item)) { | 312 | if (pile && pile->isAllowedOnTop(item)) { |
321 | CardPile *oldPile = item->getCardPile(); | 313 | CardPile *oldPile = item->getCardPile(); |
322 | Card *c = NULL; | 314 | Card *c = NULL; |
323 | if ( oldPile != pile) { | 315 | if ( oldPile != pile) { |
324 | while ( item ) { | 316 | while ( item ) { |
325 | item->show(); | 317 | item->show(); |
326 | if ( oldPile ) { | 318 | if ( oldPile ) { |
327 | c = oldPile->cardInfront(item); | 319 | c = oldPile->cardInfront(item); |
328 | oldPile->removeCard(item); | 320 | oldPile->removeCard(item); |
329 | } | 321 | } |
330 | item->setCardPile(pile); | 322 | item->setCardPile(pile); |
331 | //item->move( pile->getCardPos(item) ); | 323 | //item->move( pile->getCardPos(item) ); |
332 | pile->addCardToTop(item); | 324 | pile->addCardToTop(item); |
333 | QPoint p = pile->getCardPos(item); | 325 | QPoint p = pile->getCardPos(item); |
334 | item->setPos( p.x(), p.y(), highestZ ); | 326 | item->setPos( p.x(), p.y(), highestZ ); |
335 | highestZ++; | 327 | highestZ++; |
336 | checkUnusable(); // added for freecell to move card to discard pile | 328 | checkUnusable(); // added for freecell to move card to discard pile |
337 | 329 | ||
338 | if (item->getValue() == king && haveWeWon()) { | 330 | if (item->getValue() == king && haveWeWon()) { |
339 | alphaCardPile->hide(); | 331 | alphaCardPile->hide(); |
340 | gameWon(); | 332 | gameWon(); |
341 | moving = NULL; | 333 | moving = NULL; |
342 | return; | 334 | return; |
343 | } | 335 | } |
344 | 336 | ||
345 | if (oldPile) { | 337 | if (oldPile) { |
346 | item = (CanvasCard *)c; | 338 | item = (CanvasCard *)c; |
347 | } else { | 339 | } else { |
348 | item = NULL; | 340 | item = NULL; |
349 | } | 341 | } |
350 | } | 342 | } |
351 | alphaCardPile->hide(); | 343 | alphaCardPile->hide(); |
352 | moving = NULL; | 344 | moving = NULL; |
353 | return; | 345 | return; |
354 | } | 346 | } |
355 | } | 347 | } |
356 | 348 | ||
357 | alphaCardPile->animatedMove(); | 349 | alphaCardPile->animatedMove(); |
358 | } | 350 | } |
359 | } | 351 | } |
360 | 352 | ||
361 | moved = FALSE; | 353 | moved = FALSE; |
362 | } | 354 | } |
363 | 355 | ||
364 | 356 | ||
365 | void CanvasCardGame::readPile( Config& cfg, CardPile *pile, QString name, int& highestZ ) | 357 | void CanvasCardGame::readPile( Config& cfg, CardPile *pile, QString name, int& highestZ ) |
366 | { | 358 | { |
367 | cfg.setGroup( name ); | 359 | cfg.setGroup( name ); |
368 | int numberOfCards = cfg.readNumEntry("NumberOfCards", 0); | 360 | int numberOfCards = cfg.readNumEntry("NumberOfCards", 0); |
369 | Card *card = NULL; | 361 | Card *card = NULL; |
370 | 362 | ||
371 | for ( int i = 0; i < numberOfCards; i++ ) { | 363 | for ( int i = 0; i < numberOfCards; i++ ) { |
372 | QString cardStr; | 364 | QString cardStr; |
373 | cardStr.sprintf( "%i", i ); | 365 | cardStr.sprintf( "%i", i ); |
374 | int val = cfg.readNumEntry( "Card" + cardStr ); | 366 | int val = cfg.readNumEntry( "Card" + cardStr ); |
375 | bool facing = cfg.readBoolEntry( "CardFacing" + cardStr ); | 367 | bool facing = cfg.readBoolEntry( "CardFacing" + cardStr ); |
376 | 368 | ||
377 | card = cards[ val ]; | 369 | card = cards[ val ]; |
378 | card->setFace(facing); | 370 | card->setFace(facing); |
379 | card->setCardPile(pile); // cam: setCardPile has to happen bevor addCardToTop | 371 | card->setCardPile(pile); // cam: setCardPile has to happen bevor addCardToTop |
380 | pile->addCardToTop(card); // due to a empty pointer if you use cardAddedToTop | 372 | pile->addCardToTop(card); // due to a empty pointer if you use cardAddedToTop |
381 | QPoint p = pile->getCardPos( card ); | 373 | QPoint p = pile->getCardPos( card ); |
382 | card->setPos( p.x(), p.y(), highestZ ); | 374 | card->setPos( p.x(), p.y(), highestZ ); |
383 | card->showCard(); | 375 | card->showCard(); |
384 | highestZ++; | 376 | highestZ++; |
385 | } | 377 | } |
386 | } | 378 | } |
387 | 379 | ||
388 | 380 | ||
diff --git a/noncore/games/solitaire/canvascardwindow.cpp b/noncore/games/solitaire/canvascardwindow.cpp index c12344a..503bc92 100644 --- a/noncore/games/solitaire/canvascardwindow.cpp +++ b/noncore/games/solitaire/canvascardwindow.cpp | |||
@@ -1,315 +1,310 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "canvascardwindow.h" | 21 | #include "canvascardwindow.h" |
22 | #include "patiencecardgame.h" | ||
23 | #include "freecellcardgame.h" | 22 | #include "freecellcardgame.h" |
24 | #include "chicanecardgame.h" | 23 | #include "chicanecardgame.h" |
25 | #include "harpcardgame.h" | 24 | #include "harpcardgame.h" |
26 | #include "teeclubcardgame.h" | 25 | #include "teeclubcardgame.h" |
27 | 26 | ||
28 | #include <qpe/resource.h> | ||
29 | 27 | ||
30 | #include <qmainwindow.h> | ||
31 | #include <qpopupmenu.h> | ||
32 | #include <qstyle.h> | ||
33 | 28 | ||
34 | 29 | ||
35 | CanvasCardWindow::CanvasCardWindow(QWidget* parent, const char* name, WFlags f) : | 30 | CanvasCardWindow::CanvasCardWindow(QWidget* parent, const char* name, WFlags f) : |
36 | QMainWindow(parent, name, f), canvas(230, 260), snapOn(TRUE), cardBack(4), gameType(0), | 31 | QMainWindow(parent, name, f), canvas(230, 260), snapOn(TRUE), cardBack(4), gameType(0), |
37 | cardGame(NULL) | 32 | cardGame(NULL) |
38 | { | 33 | { |
39 | setIcon( Resource::loadPixmap( "cards" ) ); | 34 | setIcon( Resource::loadPixmap( "cards" ) ); |
40 | setCaption(tr("Patience")); | 35 | setCaption(tr("Patience")); |
41 | 36 | ||
42 | // Create Playing Area for Games | 37 | // Create Playing Area for Games |
43 | if ( QPixmap::defaultDepth() < 12 ) { | 38 | if ( QPixmap::defaultDepth() < 12 ) { |
44 | // canvas.setBackgroundColor(QColor(0x51, 0x74, 0x6B)); | 39 | // canvas.setBackgroundColor(QColor(0x51, 0x74, 0x6B)); |
45 | // canvas.setBackgroundColor(QColor(0x20, 0xb0, 0x50)); | 40 | // canvas.setBackgroundColor(QColor(0x20, 0xb0, 0x50)); |
46 | canvas.setBackgroundColor(QColor(0x08, 0x98, 0x2D)); | 41 | canvas.setBackgroundColor(QColor(0x08, 0x98, 0x2D)); |
47 | } else { | 42 | } else { |
48 | QPixmap bg; | 43 | QPixmap bg; |
49 | bg.convertFromImage( Resource::loadImage( "table_pattern" ), ThresholdDither ); | 44 | bg.convertFromImage( Resource::loadImage( "table_pattern" ), ThresholdDither ); |
50 | canvas.setBackgroundPixmap(bg); | 45 | canvas.setBackgroundPixmap(bg); |
51 | } | 46 | } |
52 | 47 | ||
53 | #if defined( QT_QWS_CASSIOPEIA ) | 48 | #if defined( QT_QWS_CASSIOPEIA ) |
54 | canvas.setAdvancePeriod(70); | 49 | canvas.setAdvancePeriod(70); |
55 | #else | 50 | #else |
56 | canvas.setAdvancePeriod(30); | 51 | canvas.setAdvancePeriod(30); |
57 | #endif | 52 | #endif |
58 | 53 | ||
59 | 54 | ||
60 | #ifdef _PATIENCE_USE_ACCELS_ | 55 | #ifdef _PATIENCE_USE_ACCELS_ |
61 | QMenuBar* menu = menuBar(); | 56 | QMenuBar* menu = menuBar(); |
62 | 57 | ||
63 | QPopupMenu* file = new QPopupMenu; | 58 | QPopupMenu* file = new QPopupMenu; |
64 | file->insertItem(tr("Patience"), this, SLOT(initPatience()), CTRL+Key_F); | 59 | file->insertItem(tr("Patience"), this, SLOT(initPatience()), CTRL+Key_F); |
65 | file->insertItem(tr("Freecell"), this, SLOT(initFreecell()), CTRL+Key_F); | 60 | file->insertItem(tr("Freecell"), this, SLOT(initFreecell()), CTRL+Key_F); |
66 | file->insertItem(tr("Chicane"), this, SLOT(initChicane()), CTRL+Key_F); | 61 | file->insertItem(tr("Chicane"), this, SLOT(initChicane()), CTRL+Key_F); |
67 | file->insertItem(tr("Harp"), this, SLOT(initHarp()), CTRL+Key_F); | 62 | file->insertItem(tr("Harp"), this, SLOT(initHarp()), CTRL+Key_F); |
68 | file->insertItem(tr("Teeclub"), this, SLOT(initTeeclub()), CTRL+Key_F); | 63 | file->insertItem(tr("Teeclub"), this, SLOT(initTeeclub()), CTRL+Key_F); |
69 | menu->insertItem(tr("&Game"), file); | 64 | menu->insertItem(tr("&Game"), file); |
70 | 65 | ||
71 | menu->insertSeparator(); | 66 | menu->insertSeparator(); |
72 | 67 | ||
73 | settings = new QPopupMenu; | 68 | settings = new QPopupMenu; |
74 | settings->insertItem(tr("&Change card backs"), this, SLOT(changeCardBacks()), Key_F2); | 69 | settings->insertItem(tr("&Change card backs"), this, SLOT(changeCardBacks()), Key_F2); |
75 | snap_id = settings->insertItem(tr("&Snap to position"), this, SLOT(snapToggle()), Key_F3); | 70 | snap_id = settings->insertItem(tr("&Snap to position"), this, SLOT(snapToggle()), Key_F3); |
76 | settings->setCheckable(TRUE); | 71 | settings->setCheckable(TRUE); |
77 | menu->insertItem(tr("&Settings"),settings); | 72 | menu->insertItem(tr("&Settings"),settings); |
78 | 73 | ||
79 | menu->insertSeparator(); | 74 | menu->insertSeparator(); |
80 | 75 | ||
81 | QPopupMenu* help = new QPopupMenu; | 76 | QPopupMenu* help = new QPopupMenu; |
82 | help->insertItem(tr("&About"), this, SLOT(help()), Key_F1); | 77 | help->insertItem(tr("&About"), this, SLOT(help()), Key_F1); |
83 | help->setItemChecked(dbf_id, TRUE); | 78 | help->setItemChecked(dbf_id, TRUE); |
84 | menu->insertItem(tr("&Help"),help); | 79 | menu->insertItem(tr("&Help"),help); |
85 | #else | 80 | #else |
86 | QMenuBar* menu = menuBar(); | 81 | QMenuBar* menu = menuBar(); |
87 | 82 | ||
88 | QPopupMenu* file = new QPopupMenu; | 83 | QPopupMenu* file = new QPopupMenu; |
89 | file->insertItem(tr("Patience"), this, SLOT(initPatience())); | 84 | file->insertItem(tr("Patience"), this, SLOT(initPatience())); |
90 | file->insertItem(tr("Freecell"), this, SLOT(initFreecell())); | 85 | file->insertItem(tr("Freecell"), this, SLOT(initFreecell())); |
91 | file->insertItem(tr("Chicane"), this, SLOT(initChicane())); | 86 | file->insertItem(tr("Chicane"), this, SLOT(initChicane())); |
92 | file->insertItem(tr("Harp"), this, SLOT(initHarp())); | 87 | file->insertItem(tr("Harp"), this, SLOT(initHarp())); |
93 | file->insertItem(tr("Teeclub"), this, SLOT(initTeeclub())); | 88 | file->insertItem(tr("Teeclub"), this, SLOT(initTeeclub())); |
94 | menu->insertItem(tr("Play"), file); | 89 | menu->insertItem(tr("Play"), file); |
95 | 90 | ||
96 | menu->insertSeparator(); | 91 | menu->insertSeparator(); |
97 | 92 | ||
98 | settings = new QPopupMenu; | 93 | settings = new QPopupMenu; |
99 | settings->setCheckable(TRUE); | 94 | settings->setCheckable(TRUE); |
100 | settings->insertItem(tr("Change card backs"), this, SLOT(changeCardBacks())); | 95 | settings->insertItem(tr("Change card backs"), this, SLOT(changeCardBacks())); |
101 | snap_id = settings->insertItem(tr("Snap to position"), this, SLOT(snapToggle())); | 96 | snap_id = settings->insertItem(tr("Snap to position"), this, SLOT(snapToggle())); |
102 | QString m; | 97 | QString m; |
103 | 98 | ||
104 | drawId = settings->insertItem(tr("Turn one card"), this, SLOT(drawnToggle())); | 99 | drawId = settings->insertItem(tr("Turn one card"), this, SLOT(drawnToggle())); |
105 | menu->insertItem(tr("Settings"),settings); | 100 | menu->insertItem(tr("Settings"),settings); |
106 | settings->setCheckable(TRUE); | 101 | settings->setCheckable(TRUE); |
107 | 102 | ||
108 | #endif | 103 | #endif |
109 | 104 | ||
110 | menu->show(); | 105 | menu->show(); |
111 | 106 | ||
112 | Config cfg( "Patience" ); | 107 | Config cfg( "Patience" ); |
113 | cfg.setGroup( "GlobalSettings" ); | 108 | cfg.setGroup( "GlobalSettings" ); |
114 | snapOn = cfg.readBoolEntry( "SnapOn", TRUE); | 109 | snapOn = cfg.readBoolEntry( "SnapOn", TRUE); |
115 | settings->setItemChecked(snap_id, snapOn); | 110 | settings->setItemChecked(snap_id, snapOn); |
116 | 111 | ||
117 | gameType = cfg.readNumEntry( "GameType", -1 ); | 112 | gameType = cfg.readNumEntry( "GameType", -1 ); |
118 | drawThree = cfg.readBoolEntry( "DrawThree", FALSE); | 113 | drawThree = cfg.readBoolEntry( "DrawThree", FALSE); |
119 | if ( gameType == 0 ) { | 114 | if ( gameType == 0 ) { |
120 | cardGame = new PatienceCardGame( &canvas, snapOn, this ); | 115 | cardGame = new PatienceCardGame( &canvas, snapOn, this ); |
121 | cardGame->setNumberToDraw(drawThree ? 3 : 1); | 116 | cardGame->setNumberToDraw(drawThree ? 3 : 1); |
122 | 117 | ||
123 | setCaption(tr("Patience")); | 118 | setCaption(tr("Patience")); |
124 | setCentralWidget(cardGame); | 119 | setCentralWidget(cardGame); |
125 | cardGame->readConfig( cfg ); | 120 | cardGame->readConfig( cfg ); |
126 | setCardBacks(); | 121 | setCardBacks(); |
127 | } else if ( gameType == 1 ) { | 122 | } else if ( gameType == 1 ) { |
128 | cardGame = new FreecellCardGame( &canvas, snapOn, this ); | 123 | cardGame = new FreecellCardGame( &canvas, snapOn, this ); |
129 | setCaption(tr("Freecell")); | 124 | setCaption(tr("Freecell")); |
130 | setCentralWidget(cardGame); | 125 | setCentralWidget(cardGame); |
131 | //cardGame->newGame(); // Until we know how to handle reading freecell config | 126 | //cardGame->newGame(); // Until we know how to handle reading freecell config |
132 | cardGame->readConfig( cfg ); | 127 | cardGame->readConfig( cfg ); |
133 | setCardBacks(); | 128 | setCardBacks(); |
134 | } else if ( gameType == 2 ) { | 129 | } else if ( gameType == 2 ) { |
135 | cardGame = new ChicaneCardGame( &canvas, snapOn, this ); | 130 | cardGame = new ChicaneCardGame( &canvas, snapOn, this ); |
136 | cardGame->setNumberToDraw(1); | 131 | cardGame->setNumberToDraw(1); |
137 | setCaption(tr("Chicane")); | 132 | setCaption(tr("Chicane")); |
138 | setCentralWidget(cardGame); | 133 | setCentralWidget(cardGame); |
139 | cardGame->readConfig( cfg ); | 134 | cardGame->readConfig( cfg ); |
140 | setCardBacks(); | 135 | setCardBacks(); |
141 | } else if ( gameType == 3 ) { | 136 | } else if ( gameType == 3 ) { |
142 | cardGame = new HarpCardGame( &canvas, snapOn, this ); | 137 | cardGame = new HarpCardGame( &canvas, snapOn, this ); |
143 | cardGame->setNumberToDraw(1); | 138 | cardGame->setNumberToDraw(1); |
144 | setCaption(tr("Harp")); | 139 | setCaption(tr("Harp")); |
145 | setCentralWidget(cardGame); | 140 | setCentralWidget(cardGame); |
146 | cardGame->readConfig( cfg ); | 141 | cardGame->readConfig( cfg ); |
147 | setCardBacks(); | 142 | setCardBacks(); |
148 | } else if ( gameType == 4 ) { | 143 | } else if ( gameType == 4 ) { |
149 | cardGame = new TeeclubCardGame( &canvas, snapOn, this ); | 144 | cardGame = new TeeclubCardGame( &canvas, snapOn, this ); |
150 | cardGame->setNumberToDraw(1); | 145 | cardGame->setNumberToDraw(1); |
151 | setCaption(tr("Teeclub")); | 146 | setCaption(tr("Teeclub")); |
152 | setCentralWidget(cardGame); | 147 | setCentralWidget(cardGame); |
153 | cardGame->readConfig( cfg ); | 148 | cardGame->readConfig( cfg ); |
154 | setCardBacks(); | 149 | setCardBacks(); |
155 | } else { | 150 | } else { |
156 | // Probably there isn't a config file or it is broken | 151 | // Probably there isn't a config file or it is broken |
157 | // Start a new game | 152 | // Start a new game |
158 | initPatience(); | 153 | initPatience(); |
159 | } | 154 | } |
160 | 155 | ||
161 | updateDraw(); | 156 | updateDraw(); |
162 | } | 157 | } |
163 | 158 | ||
164 | 159 | ||
165 | CanvasCardWindow::~CanvasCardWindow() | 160 | CanvasCardWindow::~CanvasCardWindow() |
166 | { | 161 | { |
167 | if (cardGame) { | 162 | if (cardGame) { |
168 | Config cfg("Patience"); | 163 | Config cfg("Patience"); |
169 | cfg.setGroup( "GlobalSettings" ); | 164 | cfg.setGroup( "GlobalSettings" ); |
170 | cfg.writeEntry( "GameType", gameType ); | 165 | cfg.writeEntry( "GameType", gameType ); |
171 | cfg.writeEntry( "SnapOn", snapOn ); | 166 | cfg.writeEntry( "SnapOn", snapOn ); |
172 | cfg.writeEntry( "DrawThree", drawThree); | 167 | cfg.writeEntry( "DrawThree", drawThree); |
173 | cfg.write(); | 168 | cfg.write(); |
174 | cardGame->writeConfig( cfg ); | 169 | cardGame->writeConfig( cfg ); |
175 | delete cardGame; | 170 | delete cardGame; |
176 | } | 171 | } |
177 | } | 172 | } |
178 | 173 | ||
179 | 174 | ||
180 | void CanvasCardWindow::resizeEvent(QResizeEvent *) | 175 | void CanvasCardWindow::resizeEvent(QResizeEvent *) |
181 | { | 176 | { |
182 | QSize s = centralWidget()->size(); | 177 | QSize s = centralWidget()->size(); |
183 | int fw = style().defaultFrameWidth(); | 178 | int fw = style().defaultFrameWidth(); |
184 | canvas.resize( s.width() - fw - 2, s.height() - fw - 2); | 179 | canvas.resize( s.width() - fw - 2, s.height() - fw - 2); |
185 | } | 180 | } |
186 | 181 | ||
187 | 182 | ||
188 | void CanvasCardWindow::initPatience() | 183 | void CanvasCardWindow::initPatience() |
189 | { | 184 | { |
190 | // Create New Game | 185 | // Create New Game |
191 | if ( cardGame ) | 186 | if ( cardGame ) |
192 | delete cardGame; | 187 | delete cardGame; |
193 | cardGame = new PatienceCardGame( &canvas, snapOn, this ); | 188 | cardGame = new PatienceCardGame( &canvas, snapOn, this ); |
194 | cardGame->setNumberToDraw(drawThree ? 3 : 1); | 189 | cardGame->setNumberToDraw(drawThree ? 3 : 1); |
195 | gameType = 0; | 190 | gameType = 0; |
196 | setCaption(tr("Patience")); | 191 | setCaption(tr("Patience")); |
197 | setCentralWidget(cardGame); | 192 | setCentralWidget(cardGame); |
198 | cardGame->newGame(); | 193 | cardGame->newGame(); |
199 | setCardBacks(); | 194 | setCardBacks(); |
200 | updateDraw(); | 195 | updateDraw(); |
201 | } | 196 | } |
202 | 197 | ||
203 | 198 | ||
204 | void CanvasCardWindow::initFreecell() | 199 | void CanvasCardWindow::initFreecell() |
205 | { | 200 | { |
206 | // Create New Game | 201 | // Create New Game |
207 | if ( cardGame ) { | 202 | if ( cardGame ) { |
208 | delete cardGame; | 203 | delete cardGame; |
209 | } | 204 | } |
210 | cardGame = new FreecellCardGame( &canvas, snapOn, this ); | 205 | cardGame = new FreecellCardGame( &canvas, snapOn, this ); |
211 | gameType = 1; | 206 | gameType = 1; |
212 | setCaption(tr("Freecell")); | 207 | setCaption(tr("Freecell")); |
213 | setCentralWidget(cardGame); | 208 | setCentralWidget(cardGame); |
214 | cardGame->newGame(); | 209 | cardGame->newGame(); |
215 | setCardBacks(); | 210 | setCardBacks(); |
216 | } | 211 | } |
217 | 212 | ||
218 | 213 | ||
219 | void CanvasCardWindow::initChicane() | 214 | void CanvasCardWindow::initChicane() |
220 | { | 215 | { |
221 | // Create New Game | 216 | // Create New Game |
222 | if ( cardGame ) { | 217 | if ( cardGame ) { |
223 | delete cardGame; | 218 | delete cardGame; |
224 | } | 219 | } |
225 | cardGame = new ChicaneCardGame( &canvas, snapOn, this ); | 220 | cardGame = new ChicaneCardGame( &canvas, snapOn, this ); |
226 | cardGame->setNumberToDraw(1); | 221 | cardGame->setNumberToDraw(1); |
227 | gameType = 2; | 222 | gameType = 2; |
228 | setCaption(tr("Chicane")); | 223 | setCaption(tr("Chicane")); |
229 | setCentralWidget(cardGame); | 224 | setCentralWidget(cardGame); |
230 | cardGame->newGame(); | 225 | cardGame->newGame(); |
231 | setCardBacks(); | 226 | setCardBacks(); |
232 | } | 227 | } |
233 | 228 | ||
234 | void CanvasCardWindow::initHarp() | 229 | void CanvasCardWindow::initHarp() |
235 | { | 230 | { |
236 | // Create New Game | 231 | // Create New Game |
237 | if ( cardGame ) { | 232 | if ( cardGame ) { |
238 | delete cardGame; | 233 | delete cardGame; |
239 | } | 234 | } |
240 | cardGame = new HarpCardGame( &canvas, snapOn, this ); | 235 | cardGame = new HarpCardGame( &canvas, snapOn, this ); |
241 | cardGame->setNumberToDraw(1); | 236 | cardGame->setNumberToDraw(1); |
242 | gameType = 3; | 237 | gameType = 3; |
243 | setCaption(tr("Harp")); | 238 | setCaption(tr("Harp")); |
244 | setCentralWidget(cardGame); | 239 | setCentralWidget(cardGame); |
245 | cardGame->newGame(); | 240 | cardGame->newGame(); |
246 | setCardBacks(); | 241 | setCardBacks(); |
247 | } | 242 | } |
248 | 243 | ||
249 | 244 | ||
250 | void CanvasCardWindow::initTeeclub() | 245 | void CanvasCardWindow::initTeeclub() |
251 | { | 246 | { |
252 | // Create New Game | 247 | // Create New Game |
253 | if ( cardGame ) { | 248 | if ( cardGame ) { |
254 | delete cardGame; | 249 | delete cardGame; |
255 | } | 250 | } |
256 | cardGame = new TeeclubCardGame( &canvas, snapOn, this ); | 251 | cardGame = new TeeclubCardGame( &canvas, snapOn, this ); |
257 | cardGame->setNumberToDraw(1); | 252 | cardGame->setNumberToDraw(1); |
258 | gameType = 4; | 253 | gameType = 4; |
259 | setCaption(tr("Teeclub")); | 254 | setCaption(tr("Teeclub")); |
260 | setCentralWidget(cardGame); | 255 | setCentralWidget(cardGame); |
261 | cardGame->newGame(); | 256 | cardGame->newGame(); |
262 | setCardBacks(); | 257 | setCardBacks(); |
263 | } | 258 | } |
264 | 259 | ||
265 | 260 | ||
266 | void CanvasCardWindow::snapToggle() | 261 | void CanvasCardWindow::snapToggle() |
267 | { | 262 | { |
268 | snapOn = !snapOn; | 263 | snapOn = !snapOn; |
269 | settings->setItemChecked(snap_id, snapOn); | 264 | settings->setItemChecked(snap_id, snapOn); |
270 | cardGame->toggleSnap(); | 265 | cardGame->toggleSnap(); |
271 | } | 266 | } |
272 | 267 | ||
273 | 268 | ||
274 | void CanvasCardWindow::drawnToggle() | 269 | void CanvasCardWindow::drawnToggle() |
275 | { | 270 | { |
276 | drawThree=!drawThree; | 271 | drawThree=!drawThree; |
277 | Config cfg( "Patience" ); | 272 | Config cfg( "Patience" ); |
278 | cfg.setGroup( "GlobalSettings" ); | 273 | cfg.setGroup( "GlobalSettings" ); |
279 | cardGame->toggleCardsDrawn(); | 274 | cardGame->toggleCardsDrawn(); |
280 | updateDraw(); | 275 | updateDraw(); |
281 | cfg.writeEntry( "DrawThree", drawThree); | 276 | cfg.writeEntry( "DrawThree", drawThree); |
282 | cfg.write(); | 277 | cfg.write(); |
283 | } | 278 | } |
284 | 279 | ||
285 | void CanvasCardWindow::updateDraw() { | 280 | void CanvasCardWindow::updateDraw() { |
286 | if(cardGame->cardsDrawn() == 3){ | 281 | if(cardGame->cardsDrawn() == 3){ |
287 | settings->changeItem(drawId, tr("Turn one card")); | 282 | settings->changeItem(drawId, tr("Turn one card")); |
288 | } else { | 283 | } else { |
289 | settings->changeItem(drawId, tr("Turn three cards")); | 284 | settings->changeItem(drawId, tr("Turn three cards")); |
290 | } | 285 | } |
291 | } | 286 | } |
292 | 287 | ||
293 | 288 | ||
294 | void CanvasCardWindow::setCardBacks() | 289 | void CanvasCardWindow::setCardBacks() |
295 | { | 290 | { |
296 | QCanvasItemList l = canvas.allItems(); | 291 | QCanvasItemList l = canvas.allItems(); |
297 | 292 | ||
298 | for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) { | 293 | for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) { |
299 | if ( (*it)->rtti() == canvasCardId ) | 294 | if ( (*it)->rtti() == canvasCardId ) |
300 | ((CanvasCard *)(*it))->setCardBack( cardBack ); | 295 | ((CanvasCard *)(*it))->setCardBack( cardBack ); |
301 | } | 296 | } |
302 | } | 297 | } |
303 | 298 | ||
304 | 299 | ||
305 | void CanvasCardWindow::changeCardBacks() | 300 | void CanvasCardWindow::changeCardBacks() |
306 | { | 301 | { |
307 | cardBack++; | 302 | cardBack++; |
308 | 303 | ||
309 | if (cardBack == 5) | 304 | if (cardBack == 5) |
310 | cardBack = 0; | 305 | cardBack = 0; |
311 | 306 | ||
312 | setCardBacks(); | 307 | setCardBacks(); |
313 | } | 308 | } |
314 | 309 | ||
315 | 310 | ||
diff --git a/noncore/games/solitaire/canvasshapes.cpp b/noncore/games/solitaire/canvasshapes.cpp index 6ccd4a4..011958d 100644 --- a/noncore/games/solitaire/canvasshapes.cpp +++ b/noncore/games/solitaire/canvasshapes.cpp | |||
@@ -1,114 +1,112 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include <qpainter.h> | ||
21 | #include <qcanvas.h> | ||
22 | #include <qgfx_qws.h> | 20 | #include <qgfx_qws.h> |
23 | #include "canvasshapes.h" | 21 | #include "canvasshapes.h" |
24 | 22 | ||
25 | 23 | ||
26 | CanvasRoundRect::CanvasRoundRect(int x, int y, QCanvas *canvas) : | 24 | CanvasRoundRect::CanvasRoundRect(int x, int y, QCanvas *canvas) : |
27 | QCanvasRectangle( x, y, ( qt_screen->deviceWidth() < 200 ) ? 20 : 23, ( qt_screen->deviceWidth() < 200 ) ? 27 : 36, canvas) | 25 | QCanvasRectangle( x, y, ( qt_screen->deviceWidth() < 200 ) ? 20 : 23, ( qt_screen->deviceWidth() < 200 ) ? 27 : 36, canvas) |
28 | { | 26 | { |
29 | setZ(0); | 27 | setZ(0); |
30 | show(); | 28 | show(); |
31 | } | 29 | } |
32 | 30 | ||
33 | 31 | ||
34 | void CanvasRoundRect::redraw() | 32 | void CanvasRoundRect::redraw() |
35 | { | 33 | { |
36 | hide(); | 34 | hide(); |
37 | show(); | 35 | show(); |
38 | } | 36 | } |
39 | 37 | ||
40 | 38 | ||
41 | void CanvasRoundRect::drawShape(QPainter &p) | 39 | void CanvasRoundRect::drawShape(QPainter &p) |
42 | { | 40 | { |
43 | if ( qt_screen->deviceWidth() < 200 ) | 41 | if ( qt_screen->deviceWidth() < 200 ) |
44 | p.drawRoundRect( (int)x() + 1, (int)y() + 1, 18, 25); | 42 | p.drawRoundRect( (int)x() + 1, (int)y() + 1, 18, 25); |
45 | else | 43 | else |
46 | p.drawRoundRect( (int)x(), (int)y(), 23, 36); | 44 | p.drawRoundRect( (int)x(), (int)y(), 23, 36); |
47 | } | 45 | } |
48 | 46 | ||
49 | 47 | ||
50 | CanvasCircleOrCross::CanvasCircleOrCross(int x, int y, QCanvas *canvas) : | 48 | CanvasCircleOrCross::CanvasCircleOrCross(int x, int y, QCanvas *canvas) : |
51 | QCanvasRectangle( x, y, 21, 21, canvas), circleShape(TRUE) | 49 | QCanvasRectangle( x, y, 21, 21, canvas), circleShape(TRUE) |
52 | { | 50 | { |
53 | show(); | 51 | show(); |
54 | } | 52 | } |
55 | 53 | ||
56 | 54 | ||
57 | void CanvasCircleOrCross::redraw() | 55 | void CanvasCircleOrCross::redraw() |
58 | { | 56 | { |
59 | hide(); | 57 | hide(); |
60 | show(); | 58 | show(); |
61 | } | 59 | } |
62 | 60 | ||
63 | 61 | ||
64 | void CanvasCircleOrCross::setCircle() | 62 | void CanvasCircleOrCross::setCircle() |
65 | { | 63 | { |
66 | circleShape = TRUE; | 64 | circleShape = TRUE; |
67 | redraw(); | 65 | redraw(); |
68 | } | 66 | } |
69 | 67 | ||
70 | 68 | ||
71 | void CanvasCircleOrCross::setCross() | 69 | void CanvasCircleOrCross::setCross() |
72 | { | 70 | { |
73 | circleShape = FALSE; | 71 | circleShape = FALSE; |
74 | redraw(); | 72 | redraw(); |
75 | } | 73 | } |
76 | 74 | ||
77 | 75 | ||
78 | void CanvasCircleOrCross::drawShape(QPainter &p) | 76 | void CanvasCircleOrCross::drawShape(QPainter &p) |
79 | { | 77 | { |
80 | if ( qt_screen->deviceWidth() < 200 ) { | 78 | if ( qt_screen->deviceWidth() < 200 ) { |
81 | int x1 = (int)x(), y1 = (int)y(); | 79 | int x1 = (int)x(), y1 = (int)y(); |
82 | // Green circle | 80 | // Green circle |
83 | if (circleShape == TRUE) { | 81 | if (circleShape == TRUE) { |
84 | p.setPen( QPen( QColor(0x10, 0xE0, 0x10), 1 ) ); | 82 | p.setPen( QPen( QColor(0x10, 0xE0, 0x10), 1 ) ); |
85 | p.drawEllipse( x1 - 1, y1 - 1, 17, 17); | 83 | p.drawEllipse( x1 - 1, y1 - 1, 17, 17); |
86 | p.drawEllipse( x1 - 1, y1 - 0, 17, 15); | 84 | p.drawEllipse( x1 - 1, y1 - 0, 17, 15); |
87 | p.drawEllipse( x1 + 0, y1 + 0, 15, 15); | 85 | p.drawEllipse( x1 + 0, y1 + 0, 15, 15); |
88 | p.drawEllipse( x1 + 1, y1 + 0, 13, 15); | 86 | p.drawEllipse( x1 + 1, y1 + 0, 13, 15); |
89 | p.drawEllipse( x1 + 1, y1 + 1, 13, 13); | 87 | p.drawEllipse( x1 + 1, y1 + 1, 13, 13); |
90 | // Red cross | 88 | // Red cross |
91 | } else { | 89 | } else { |
92 | p.setPen( QPen( QColor(0xE0, 0x10, 0x10), 4 ) ); | 90 | p.setPen( QPen( QColor(0xE0, 0x10, 0x10), 4 ) ); |
93 | p.drawLine( x1, y1, x1 + 14, y1 + 14); | 91 | p.drawLine( x1, y1, x1 + 14, y1 + 14); |
94 | p.drawLine( x1 + 14, y1, x1, y1 + 14); | 92 | p.drawLine( x1 + 14, y1, x1, y1 + 14); |
95 | } | 93 | } |
96 | } else { | 94 | } else { |
97 | int x1 = (int)x(), y1 = (int)y(); | 95 | int x1 = (int)x(), y1 = (int)y(); |
98 | // Green circle | 96 | // Green circle |
99 | if (circleShape == TRUE) { | 97 | if (circleShape == TRUE) { |
100 | p.setPen( QPen( QColor(0x10, 0xE0, 0x10), 1 ) ); | 98 | p.setPen( QPen( QColor(0x10, 0xE0, 0x10), 1 ) ); |
101 | p.drawEllipse( x1 - 1, y1 - 1, 21, 21); | 99 | p.drawEllipse( x1 - 1, y1 - 1, 21, 21); |
102 | p.drawEllipse( x1 - 1, y1 - 0, 21, 19); | 100 | p.drawEllipse( x1 - 1, y1 - 0, 21, 19); |
103 | p.drawEllipse( x1 + 0, y1 + 0, 19, 19); | 101 | p.drawEllipse( x1 + 0, y1 + 0, 19, 19); |
104 | p.drawEllipse( x1 + 1, y1 + 0, 17, 19); | 102 | p.drawEllipse( x1 + 1, y1 + 0, 17, 19); |
105 | p.drawEllipse( x1 + 1, y1 + 1, 17, 17); | 103 | p.drawEllipse( x1 + 1, y1 + 1, 17, 17); |
106 | // Red cross | 104 | // Red cross |
107 | } else { | 105 | } else { |
108 | p.setPen( QPen( QColor(0xE0, 0x10, 0x10), 5 ) ); | 106 | p.setPen( QPen( QColor(0xE0, 0x10, 0x10), 5 ) ); |
109 | p.drawLine( x1, y1, x1 + 20, y1 + 20); | 107 | p.drawLine( x1, y1, x1 + 20, y1 + 20); |
110 | p.drawLine( x1 + 20, y1, x1, y1 + 20); | 108 | p.drawLine( x1 + 20, y1, x1, y1 + 20); |
111 | } | 109 | } |
112 | } | 110 | } |
113 | } | 111 | } |
114 | 112 | ||
diff --git a/noncore/games/solitaire/card.cpp b/noncore/games/solitaire/card.cpp index 609e280..52e38ac 100644 --- a/noncore/games/solitaire/card.cpp +++ b/noncore/games/solitaire/card.cpp | |||
@@ -1,53 +1,50 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "card.h" | 21 | #include "card.h" |
22 | 22 | ||
23 | #include <qpe/config.h> | ||
24 | 23 | ||
25 | #include <qpoint.h> | ||
26 | #include <qlist.h> | ||
27 | 24 | ||
28 | /* | 25 | /* |
29 | Card( eValue v, eSuit s, bool f ) : | 26 | Card( eValue v, eSuit s, bool f ) : |
30 | val(v), suit(s), faceUp(f), showing(FALSE), ix(0), iy(0), iz(0), cardPile(NULL) { } | 27 | val(v), suit(s), faceUp(f), showing(FALSE), ix(0), iy(0), iz(0), cardPile(NULL) { } |
31 | virtual ~Card() { } | 28 | virtual ~Card() { } |
32 | eValue getValue() { return val; } | 29 | eValue getValue() { return val; } |
33 | eSuit getSuit() { return suit; } | 30 | eSuit getSuit() { return suit; } |
34 | CardPile *getCardPile() { return cardPile; } | 31 | CardPile *getCardPile() { return cardPile; } |
35 | bool isFacing() { return faceUp; } | 32 | bool isFacing() { return faceUp; } |
36 | bool isShowing() { return showing; } | 33 | bool isShowing() { return showing; } |
37 | bool isRed() { return ((suit == diamonds) || (suit == hearts)); } | 34 | bool isRed() { return ((suit == diamonds) || (suit == hearts)); } |
38 | int getX(void) { return ix; } | 35 | int getX(void) { return ix; } |
39 | int getY(void) { return iy; } | 36 | int getY(void) { return iy; } |
40 | int getZ(void) { return iz; } | 37 | int getZ(void) { return iz; } |
41 | void setCardPile(CardPile *p) { cardPile = p; } | 38 | void setCardPile(CardPile *p) { cardPile = p; } |
42 | void setFace(bool f) { faceUp = f; } | 39 | void setFace(bool f) { faceUp = f; } |
43 | void flip(void) { flipTo(getX(), getY()); } | 40 | void flip(void) { flipTo(getX(), getY()); } |
44 | virtual void setPos(int x, int y, int z) { ix = x; iy = y; iz = z; } | 41 | 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; } | 42 | virtual void move(int x, int y) { ix = x; iy = y; } |
46 | virtual void move(QPoint p) { ix = p.x(); iy = p.y(); } | 43 | 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); } | 44 | 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; } | 45 | virtual void showCard(void) { showing = TRUE; } |
49 | virtual void hideCard(void) { showing = FALSE; } | 46 | virtual void hideCard(void) { showing = FALSE; } |
50 | virtual void redraw(void) { } | 47 | virtual void redraw(void) { } |
51 | */ | 48 | */ |
52 | 49 | ||
53 | 50 | ||
diff --git a/noncore/games/solitaire/cardpile.cpp b/noncore/games/solitaire/cardpile.cpp index aace2e2..1d572be 100644 --- a/noncore/games/solitaire/cardpile.cpp +++ b/noncore/games/solitaire/cardpile.cpp | |||
@@ -1,115 +1,113 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "cardpile.h" | 21 | #include "cardpile.h" |
22 | #include "card.h" | 22 | #include "card.h" |
23 | 23 | ||
24 | #include <qpe/config.h> | 24 | #include <qpe/config.h> |
25 | #include <qpoint.h> | ||
26 | 25 | ||
27 | #include <qlist.h> | ||
28 | 26 | ||
29 | 27 | ||
30 | CardPile::CardPile(int x, int y) : pileX(x), pileY(y), dealing(FALSE), PileResize(FALSE) { | 28 | CardPile::CardPile(int x, int y) : pileX(x), pileY(y), dealing(FALSE), PileResize(FALSE) { |
31 | pileWidth = 0; | 29 | pileWidth = 0; |
32 | pileHeight = 0; | 30 | pileHeight = 0; |
33 | pileNextX = pileX; | 31 | pileNextX = pileX; |
34 | pileNextY = pileY; | 32 | pileNextY = pileY; |
35 | pileCenterX = x + pileWidth / 2; | 33 | pileCenterX = x + pileWidth / 2; |
36 | pileCenterY = y + pileHeight / 2; | 34 | pileCenterY = y + pileHeight / 2; |
37 | pileRadius = (pileWidth > pileHeight) ? pileWidth : pileHeight; | 35 | pileRadius = (pileWidth > pileHeight) ? pileWidth : pileHeight; |
38 | pileOffsetDown = 13; | 36 | pileOffsetDown = 13; |
39 | } | 37 | } |
40 | 38 | ||
41 | 39 | ||
42 | int CardPile::distanceFromPile(int x, int y) { | 40 | int CardPile::distanceFromPile(int x, int y) { |
43 | return (pileCenterX-x)*(pileCenterX-x)+(pileCenterY-y)*(pileCenterY-y); | 41 | return (pileCenterX-x)*(pileCenterX-x)+(pileCenterY-y)*(pileCenterY-y); |
44 | } | 42 | } |
45 | 43 | ||
46 | 44 | ||
47 | int CardPile::distanceFromNextPos(int x, int y) { | 45 | int CardPile::distanceFromNextPos(int x, int y) { |
48 | return (pileNextX-x)*(pileNextX-x)+(pileNextY-y)*(pileNextY-y); | 46 | return (pileNextX-x)*(pileNextX-x)+(pileNextY-y)*(pileNextY-y); |
49 | } | 47 | } |
50 | 48 | ||
51 | 49 | ||
52 | Card *CardPile::cardInfront(Card *c) { | 50 | Card *CardPile::cardInfront(Card *c) { |
53 | CardPile *p = c->getCardPile(); | 51 | CardPile *p = c->getCardPile(); |
54 | if (p) { | 52 | if (p) { |
55 | p->at(p->find(c)); | 53 | p->at(p->find(c)); |
56 | return p->next(); | 54 | return p->next(); |
57 | } else { | 55 | } else { |
58 | return NULL; | 56 | return NULL; |
59 | } | 57 | } |
60 | } | 58 | } |
61 | 59 | ||
62 | 60 | ||
63 | bool CardPile::kingOnTop() { | 61 | bool CardPile::kingOnTop() { |
64 | Card *top = cardOnTop(); | 62 | Card *top = cardOnTop(); |
65 | return top && top->getValue() == king; | 63 | return top && top->getValue() == king; |
66 | } | 64 | } |
67 | 65 | ||
68 | 66 | ||
69 | bool CardPile::addCardToTop(Card *c) { | 67 | bool CardPile::addCardToTop(Card *c) { |
70 | if (dealing || isAllowedOnTop(c)) { | 68 | if (dealing || isAllowedOnTop(c)) { |
71 | append((const Card *)c); | 69 | append((const Card *)c); |
72 | cardAddedToTop(c); | 70 | cardAddedToTop(c); |
73 | return TRUE; | 71 | return TRUE; |
74 | } | 72 | } |
75 | return FALSE; | 73 | return FALSE; |
76 | } | 74 | } |
77 | 75 | ||
78 | 76 | ||
79 | bool CardPile::addCardToBottom(Card *c) { | 77 | bool CardPile::addCardToBottom(Card *c) { |
80 | if (dealing || isAllowedOnBottom(c)) { | 78 | if (dealing || isAllowedOnBottom(c)) { |
81 | prepend((const Card *)c); | 79 | prepend((const Card *)c); |
82 | cardAddedToBottom(c); | 80 | cardAddedToBottom(c); |
83 | return TRUE; | 81 | return TRUE; |
84 | } | 82 | } |
85 | return FALSE; | 83 | return FALSE; |
86 | } | 84 | } |
87 | 85 | ||
88 | 86 | ||
89 | bool CardPile::removeCard(Card *c) { | 87 | bool CardPile::removeCard(Card *c) { |
90 | if (dealing || isAllowedToBeMoved(c)) { | 88 | if (dealing || isAllowedToBeMoved(c)) { |
91 | take(find(c)); | 89 | take(find(c)); |
92 | cardRemoved(c); | 90 | cardRemoved(c); |
93 | return TRUE; | 91 | return TRUE; |
94 | } | 92 | } |
95 | return FALSE; | 93 | return FALSE; |
96 | } | 94 | } |
97 | 95 | ||
98 | 96 | ||
99 | void CardPile::writeConfig( Config& cfg, QString name ) { | 97 | void CardPile::writeConfig( Config& cfg, QString name ) { |
100 | int numberOfCards = 0; | 98 | int numberOfCards = 0; |
101 | cfg.setGroup( name ); | 99 | cfg.setGroup( name ); |
102 | Card *card = cardOnBottom(); | 100 | Card *card = cardOnBottom(); |
103 | while ( card ) { | 101 | while ( card ) { |
104 | QString cardStr; | 102 | QString cardStr; |
105 | cardStr.sprintf( "%i", numberOfCards ); | 103 | cardStr.sprintf( "%i", numberOfCards ); |
106 | int val = (int)card->getValue()-1 + ((int)card->getSuit()-1)*13 + (int)card->getDeckNumber()*52; | 104 | int val = (int)card->getValue()-1 + ((int)card->getSuit()-1)*13 + (int)card->getDeckNumber()*52; |
107 | cfg.writeEntry( "Card" + cardStr, val ); | 105 | cfg.writeEntry( "Card" + cardStr, val ); |
108 | cfg.writeEntry( "CardFacing" + cardStr, card->isFacing() ); | 106 | cfg.writeEntry( "CardFacing" + cardStr, card->isFacing() ); |
109 | card = cardInfront( card ); | 107 | card = cardInfront( card ); |
110 | numberOfCards++; | 108 | numberOfCards++; |
111 | } | 109 | } |
112 | cfg.writeEntry("NumberOfCards", numberOfCards); | 110 | cfg.writeEntry("NumberOfCards", numberOfCards); |
113 | } | 111 | } |
114 | 112 | ||
115 | 113 | ||
diff --git a/noncore/games/solitaire/chicanecardgame.cpp b/noncore/games/solitaire/chicanecardgame.cpp index 6729a94..6c607b9 100644 --- a/noncore/games/solitaire/chicanecardgame.cpp +++ b/noncore/games/solitaire/chicanecardgame.cpp | |||
@@ -1,177 +1,176 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | ** | 19 | ** |
20 | ** created on base of patiencecardgame by cam (C.A.Mader) 2002 | 20 | ** created on base of patiencecardgame by cam (C.A.Mader) 2002 |
21 | ** Rules for this game: | 21 | ** Rules for this game: |
22 | **use 2 decks = 104 cards | 22 | **use 2 decks = 104 cards |
23 | **deal 8 rows with 3 hidden cards and one open card | 23 | **deal 8 rows with 3 hidden cards and one open card |
24 | ** append red to black and vice versa | 24 | ** append red to black and vice versa |
25 | **each card can be layed on a free place | 25 | **each card can be layed on a free place |
26 | **deal 8 cards at once | 26 | **deal 8 cards at once |
27 | ** | 27 | ** |
28 | **********************************************************************/ | 28 | **********************************************************************/ |
29 | #include <qgfx_qws.h> | ||
30 | #include "chicanecardgame.h" | 29 | #include "chicanecardgame.h" |
31 | 30 | ||
32 | 31 | ||
33 | extern int highestZ; | 32 | extern int highestZ; |
34 | 33 | ||
35 | 34 | ||
36 | ChicaneCardGame::ChicaneCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent, 2)// Use 2 Decks | 35 | ChicaneCardGame::ChicaneCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent, 2)// Use 2 Decks |
37 | { | 36 | { |
38 | highestZ = 0; | 37 | highestZ = 0; |
39 | 38 | ||
40 | for (int i = 0; i < 8; i++) { | 39 | for (int i = 0; i < 8; i++) { |
41 | discardPiles[i] = new ChicaneDiscardPile( 27 + i * 26, 10, canvas() ); | 40 | discardPiles[i] = new ChicaneDiscardPile( 27 + i * 26, 10, canvas() ); |
42 | addCardPile(discardPiles[i]); | 41 | addCardPile(discardPiles[i]); |
43 | } | 42 | } |
44 | for (int i = 0; i < 8; i++) { | 43 | for (int i = 0; i < 8; i++) { |
45 | workingPiles[i] = new ChicaneWorkingPile( 27 + i * 26, 50, canvas() ); | 44 | workingPiles[i] = new ChicaneWorkingPile( 27 + i * 26, 50, canvas() ); |
46 | addCardPile(workingPiles[i]); | 45 | addCardPile(workingPiles[i]); |
47 | } | 46 | } |
48 | faceDownDealingPile = new ChicaneFaceDownDeck( 2, 10, canvas() ); | 47 | faceDownDealingPile = new ChicaneFaceDownDeck( 2, 10, canvas() ); |
49 | } | 48 | } |
50 | 49 | ||
51 | 50 | ||
52 | void ChicaneCardGame::deal(void) | 51 | void ChicaneCardGame::deal(void) |
53 | { | 52 | { |
54 | highestZ = 1; | 53 | highestZ = 1; |
55 | int t = 0; | 54 | int t = 0; |
56 | 55 | ||
57 | beginDealing(); | 56 | beginDealing(); |
58 | 57 | ||
59 | for (int i = 0; i < 8; i++) { | 58 | for (int i = 0; i < 8; i++) { |
60 | for (int k = 0; k < 4; k++, t++) { | 59 | for (int k = 0; k < 4; k++, t++) { |
61 | Card *card = cards[t]; | 60 | Card *card = cards[t]; |
62 | workingPiles[i]->addCardToTop(card); | 61 | workingPiles[i]->addCardToTop(card); |
63 | card->setCardPile( workingPiles[i] ); | 62 | card->setCardPile( workingPiles[i] ); |
64 | card->setPos( 0, 0, highestZ ); | 63 | card->setPos( 0, 0, highestZ ); |
65 | card->setFace(k==3); | 64 | card->setFace(k==3); |
66 | card->move( workingPiles[i]->getCardPos( card ) ); | 65 | card->move( workingPiles[i]->getCardPos( card ) ); |
67 | card->showCard(); | 66 | card->showCard(); |
68 | highestZ++; | 67 | highestZ++; |
69 | } | 68 | } |
70 | } | 69 | } |
71 | 70 | ||
72 | for ( ; t < getNumberOfCards(); t++) { | 71 | for ( ; t < getNumberOfCards(); t++) { |
73 | Card *card = cards[t]; | 72 | Card *card = cards[t]; |
74 | faceDownDealingPile->addCardToTop(card); | 73 | faceDownDealingPile->addCardToTop(card); |
75 | card->setCardPile( faceDownDealingPile ); | 74 | card->setCardPile( faceDownDealingPile ); |
76 | QPoint p = faceDownDealingPile->getCardPos( card ); | 75 | QPoint p = faceDownDealingPile->getCardPos( card ); |
77 | card->setPos( p.x(), p.y(), highestZ ); | 76 | card->setPos( p.x(), p.y(), highestZ ); |
78 | card->showCard(); | 77 | card->showCard(); |
79 | highestZ++; | 78 | highestZ++; |
80 | } | 79 | } |
81 | 80 | ||
82 | endDealing(); | 81 | endDealing(); |
83 | } | 82 | } |
84 | 83 | ||
85 | 84 | ||
86 | void ChicaneCardGame::readConfig( Config& cfg ) | 85 | void ChicaneCardGame::readConfig( Config& cfg ) |
87 | { | 86 | { |
88 | cfg.setGroup("GameState"); | 87 | cfg.setGroup("GameState"); |
89 | 88 | ||
90 | // Create Cards, but don't shuffle or deal them yet | 89 | // Create Cards, but don't shuffle or deal them yet |
91 | createDeck(); | 90 | createDeck(); |
92 | 91 | ||
93 | // Move the cards to their piles (deal them to their previous places) | 92 | // Move the cards to their piles (deal them to their previous places) |
94 | beginDealing(); | 93 | beginDealing(); |
95 | 94 | ||
96 | highestZ = 1; | 95 | highestZ = 1; |
97 | 96 | ||
98 | for (int i = 0; i < 8; i++) { | 97 | for (int i = 0; i < 8; i++) { |
99 | QString pile; | 98 | QString pile; |
100 | pile.sprintf( "ChicaneDiscardPile%i", i ); | 99 | pile.sprintf( "ChicaneDiscardPile%i", i ); |
101 | readPile( cfg, discardPiles[i], pile, highestZ ); | 100 | readPile( cfg, discardPiles[i], pile, highestZ ); |
102 | } | 101 | } |
103 | 102 | ||
104 | for (int i = 0; i < 8; i++) { | 103 | for (int i = 0; i < 8; i++) { |
105 | QString pile; | 104 | QString pile; |
106 | pile.sprintf( "ChicaneWorkingPile%i", i ); | 105 | pile.sprintf( "ChicaneWorkingPile%i", i ); |
107 | readPile( cfg, workingPiles[i], pile, highestZ ); | 106 | readPile( cfg, workingPiles[i], pile, highestZ ); |
108 | } | 107 | } |
109 | 108 | ||
110 | readPile( cfg, faceDownDealingPile, "ChicaneFaceDownDealingPile", highestZ ); | 109 | readPile( cfg, faceDownDealingPile, "ChicaneFaceDownDealingPile", highestZ ); |
111 | 110 | ||
112 | highestZ++; | 111 | highestZ++; |
113 | 112 | ||
114 | endDealing(); | 113 | endDealing(); |
115 | } | 114 | } |
116 | 115 | ||
117 | 116 | ||
118 | void ChicaneCardGame::writeConfig( Config& cfg ) | 117 | void ChicaneCardGame::writeConfig( Config& cfg ) |
119 | { | 118 | { |
120 | cfg.setGroup("GameState"); | 119 | cfg.setGroup("GameState"); |
121 | for ( int i = 0; i < 8; i++ ) { | 120 | for ( int i = 0; i < 8; i++ ) { |
122 | QString pile; | 121 | QString pile; |
123 | pile.sprintf( "ChicaneDiscardPile%i", i ); | 122 | pile.sprintf( "ChicaneDiscardPile%i", i ); |
124 | discardPiles[i]->writeConfig( cfg, pile ); | 123 | discardPiles[i]->writeConfig( cfg, pile ); |
125 | } | 124 | } |
126 | for ( int i = 0; i < 8; i++ ) { | 125 | for ( int i = 0; i < 8; i++ ) { |
127 | QString pile; | 126 | QString pile; |
128 | pile.sprintf( "ChicaneWorkingPile%i", i ); | 127 | pile.sprintf( "ChicaneWorkingPile%i", i ); |
129 | workingPiles[i]->writeConfig( cfg, pile ); | 128 | workingPiles[i]->writeConfig( cfg, pile ); |
130 | } | 129 | } |
131 | faceDownDealingPile->writeConfig( cfg, "ChicaneFaceDownDealingPile" ); | 130 | faceDownDealingPile->writeConfig( cfg, "ChicaneFaceDownDealingPile" ); |
132 | } | 131 | } |
133 | 132 | ||
134 | 133 | ||
135 | bool ChicaneCardGame::mousePressCard( Card *card, QPoint p ) | 134 | bool ChicaneCardGame::mousePressCard( Card *card, QPoint p ) |
136 | { | 135 | { |
137 | Q_UNUSED(p); | 136 | Q_UNUSED(p); |
138 | 137 | ||
139 | CanvasCard *item = (CanvasCard *)card; | 138 | CanvasCard *item = (CanvasCard *)card; |
140 | if (item->isFacing() != TRUE) { | 139 | if (item->isFacing() != TRUE) { |
141 | // From facedown stack | 140 | // From facedown stack |
142 | if ((item->x() == 2) && ((int)item->y() == 10)) { // Deal a row of 8 cards | 141 | if ((item->x() == 2) && ((int)item->y() == 10)) { // Deal a row of 8 cards |
143 | // Move 8 cards, one to each workingPile | 142 | // Move 8 cards, one to each workingPile |
144 | beginDealing(); | 143 | beginDealing(); |
145 | for (int i=0; i<8 && faceDownDealingPile->cardOnTop(); i++) { | 144 | for (int i=0; i<8 && faceDownDealingPile->cardOnTop(); i++) { |
146 | CanvasCard *card = (CanvasCard *)faceDownDealingPile->cardOnTop(); | 145 | CanvasCard *card = (CanvasCard *)faceDownDealingPile->cardOnTop(); |
147 | card->setZ(highestZ); | 146 | card->setZ(highestZ); |
148 | highestZ++; | 147 | highestZ++; |
149 | faceDownDealingPile->removeCard(card); | 148 | faceDownDealingPile->removeCard(card); |
150 | workingPiles[i]->addCardToTop(card); | 149 | workingPiles[i]->addCardToTop(card); |
151 | card->setCardPile( workingPiles[i] ); | 150 | card->setCardPile( workingPiles[i] ); |
152 | card->setFace(FALSE); | 151 | card->setFace(FALSE); |
153 | QPoint p = workingPiles[i]->getCardPos(card); | 152 | QPoint p = workingPiles[i]->getCardPos(card); |
154 | card->flipTo( p.x(), p.y() ); | 153 | card->flipTo( p.x(), p.y() ); |
155 | } | 154 | } |
156 | endDealing(); | 155 | endDealing(); |
157 | } | 156 | } |
158 | moving = NULL; | 157 | moving = NULL; |
159 | moved = FALSE; | 158 | moved = FALSE; |
160 | 159 | ||
161 | return TRUE; | 160 | return TRUE; |
162 | } else if ( !card->getCardPile()->isAllowedToBeMoved(card) ) {// Don't allow unclean columns to be moved | 161 | } else if ( !card->getCardPile()->isAllowedToBeMoved(card) ) {// Don't allow unclean columns to be moved |
163 | moving = NULL; | 162 | moving = NULL; |
164 | return TRUE; | 163 | return TRUE; |
165 | } | 164 | } |
166 | 165 | ||
167 | return FALSE; | 166 | return FALSE; |
168 | } | 167 | } |
169 | 168 | ||
170 | 169 | ||
171 | 170 | ||
172 | void ChicaneCardGame::mousePress(QPoint p) | 171 | void ChicaneCardGame::mousePress(QPoint p) |
173 | { | 172 | { |
174 | Q_UNUSED(p); | 173 | Q_UNUSED(p); |
175 | } | 174 | } |
176 | 175 | ||
177 | 176 | ||
diff --git a/noncore/games/solitaire/freecellcardgame.cpp b/noncore/games/solitaire/freecellcardgame.cpp index aeb32fc..d474f4e 100644 --- a/noncore/games/solitaire/freecellcardgame.cpp +++ b/noncore/games/solitaire/freecellcardgame.cpp | |||
@@ -1,225 +1,224 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include <qgfx_qws.h> | ||
21 | #include "freecellcardgame.h" | 20 | #include "freecellcardgame.h" |
22 | 21 | ||
23 | 22 | ||
24 | extern int highestZ; | 23 | extern int highestZ; |
25 | int numberOfFreeCells = 4; | 24 | int numberOfFreeCells = 4; |
26 | 25 | ||
27 | 26 | ||
28 | FreecellCardGame::FreecellCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent) | 27 | FreecellCardGame::FreecellCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent) |
29 | { | 28 | { |
30 | numberOfFreeCells = 4; | 29 | numberOfFreeCells = 4; |
31 | highestZ = 0; | 30 | highestZ = 0; |
32 | 31 | ||
33 | int spaceBetweenPiles = ( qt_screen->deviceWidth() < 200 ) ? 21 : 28; | 32 | int spaceBetweenPiles = ( qt_screen->deviceWidth() < 200 ) ? 21 : 28; |
34 | int xOrigin = ( qt_screen->deviceWidth() < 200 ) ? 0 : 5; | 33 | int xOrigin = ( qt_screen->deviceWidth() < 200 ) ? 0 : 5; |
35 | int spacing = ( qt_screen->deviceWidth() < 200 ) ? 0 : 0; | 34 | int spacing = ( qt_screen->deviceWidth() < 200 ) ? 0 : 0; |
36 | 35 | ||
37 | for (int i = 0; i < 4; i++) { | 36 | for (int i = 0; i < 4; i++) { |
38 | freecellPiles[i] = new FreecellFreecellPile( xOrigin + i * spaceBetweenPiles, 10, canvas() ); | 37 | freecellPiles[i] = new FreecellFreecellPile( xOrigin + i * spaceBetweenPiles, 10, canvas() ); |
39 | addCardPile(freecellPiles[i]); | 38 | addCardPile(freecellPiles[i]); |
40 | } | 39 | } |
41 | for (int i = 0; i < 4; i++) { | 40 | for (int i = 0; i < 4; i++) { |
42 | discardPiles[i] = new FreecellDiscardPile( xOrigin + spacing + 6 + (i + 4) * spaceBetweenPiles, 10, canvas() ); | 41 | discardPiles[i] = new FreecellDiscardPile( xOrigin + spacing + 6 + (i + 4) * spaceBetweenPiles, 10, canvas() ); |
43 | addCardPile(discardPiles[i]); | 42 | addCardPile(discardPiles[i]); |
44 | } | 43 | } |
45 | for (int i = 0; i < 8; i++) { | 44 | for (int i = 0; i < 8; i++) { |
46 | workingPiles[i] = new FreecellWorkingPile( xOrigin + spacing + 2 + i * spaceBetweenPiles, 50, canvas() ); | 45 | workingPiles[i] = new FreecellWorkingPile( xOrigin + spacing + 2 + i * spaceBetweenPiles, 50, canvas() ); |
47 | addCardPile(workingPiles[i]); | 46 | addCardPile(workingPiles[i]); |
48 | } | 47 | } |
49 | } | 48 | } |
50 | 49 | ||
51 | 50 | ||
52 | void FreecellCardGame::deal(void) | 51 | void FreecellCardGame::deal(void) |
53 | { | 52 | { |
54 | highestZ = 1; | 53 | highestZ = 1; |
55 | 54 | ||
56 | beginDealing(); | 55 | beginDealing(); |
57 | 56 | ||
58 | for (int i = 0; i < 52; i++) { | 57 | for (int i = 0; i < 52; i++) { |
59 | Card *card = cards[i]; | 58 | Card *card = cards[i]; |
60 | card->setFace( TRUE ); | 59 | card->setFace( TRUE ); |
61 | card->setPos( 0, 0, highestZ ); | 60 | card->setPos( 0, 0, highestZ ); |
62 | card->setCardPile( workingPiles[i%8] ); | 61 | card->setCardPile( workingPiles[i%8] ); |
63 | workingPiles[i%8]->addCardToTop( card ); | 62 | workingPiles[i%8]->addCardToTop( card ); |
64 | card->move( workingPiles[i%8]->getCardPos( card ) ); | 63 | card->move( workingPiles[i%8]->getCardPos( card ) ); |
65 | card->showCard(); | 64 | card->showCard(); |
66 | highestZ++; | 65 | highestZ++; |
67 | } | 66 | } |
68 | 67 | ||
69 | endDealing(); | 68 | endDealing(); |
70 | } | 69 | } |
71 | 70 | ||
72 | // checks if smaller card with different color, that could be put on top on the | 71 | // checks if smaller card with different color, that could be put on top on the |
73 | // card, is present in working or freecell pile | 72 | // card, is present in working or freecell pile |
74 | bool FreecellCardGame::checkNeeded(Card *card) | 73 | bool FreecellCardGame::checkNeeded(Card *card) |
75 | { | 74 | { |
76 | if (card->getValue() > 2){ | 75 | if (card->getValue() > 2){ |
77 | int i; | 76 | int i; |
78 | Card *c; | 77 | Card *c; |
79 | for (i=0;i<4;i++){ | 78 | for (i=0;i<4;i++){ |
80 | c = freecellPiles[i]->cardOnBottom(); | 79 | c = freecellPiles[i]->cardOnBottom(); |
81 | if (c != NULL){ | 80 | if (c != NULL){ |
82 | if (card->isRed()!= c->isRed() && card->getValue()== c->getValue()+1){ | 81 | if (card->isRed()!= c->isRed() && card->getValue()== c->getValue()+1){ |
83 | return (false); | 82 | return (false); |
84 | } | 83 | } |
85 | } | 84 | } |
86 | } | 85 | } |
87 | for (i=0;i<8;i++){ | 86 | for (i=0;i<8;i++){ |
88 | c=workingPiles[i]->cardOnBottom(); | 87 | c=workingPiles[i]->cardOnBottom(); |
89 | while (c!=NULL){ | 88 | while (c!=NULL){ |
90 | if (card->isRed() != c->isRed()&& card->getValue() == c->getValue()+1) { | 89 | if (card->isRed() != c->isRed()&& card->getValue() == c->getValue()+1) { |
91 | return (false); | 90 | return (false); |
92 | } | 91 | } |
93 | c=workingPiles[i]->cardInfront(c); | 92 | c=workingPiles[i]->cardInfront(c); |
94 | } | 93 | } |
95 | } | 94 | } |
96 | } | 95 | } |
97 | return(true); | 96 | return(true); |
98 | } | 97 | } |
99 | 98 | ||
100 | // added to move cards, on which no card can be moved, to discard pile | 99 | // added to move cards, on which no card can be moved, to discard pile |
101 | void FreecellCardGame::checkUnusable() | 100 | void FreecellCardGame::checkUnusable() |
102 | { | 101 | { |
103 | int i,j; | 102 | int i,j; |
104 | //printf("void FreecellCardGame::checkUnusable()\n"); | 103 | //printf("void FreecellCardGame::checkUnusable()\n"); |
105 | Card *top_one; | 104 | Card *top_one; |
106 | for (i=0;i < 8;i++) | 105 | for (i=0;i < 8;i++) |
107 | { | 106 | { |
108 | top_one = workingPiles[i]->cardOnTop(); | 107 | top_one = workingPiles[i]->cardOnTop(); |
109 | if (top_one != NULL) | 108 | if (top_one != NULL) |
110 | { | 109 | { |
111 | j = 0; | 110 | j = 0; |
112 | while ((j < 4)) | 111 | while ((j < 4)) |
113 | { | 112 | { |
114 | if (discardPiles[j]->isAllowedOnTop(top_one)){ | 113 | if (discardPiles[j]->isAllowedOnTop(top_one)){ |
115 | if (checkNeeded(top_one)){ | 114 | if (checkNeeded(top_one)){ |
116 | top_one->setCardPile(discardPiles[j]); | 115 | top_one->setCardPile(discardPiles[j]); |
117 | workingPiles[i]->removeCard(top_one); | 116 | workingPiles[i]->removeCard(top_one); |
118 | // printf("k %d f work%d to disk%d on %d\n ",top_one->getValue(),i+1,j+1,highestZ); | 117 | // printf("k %d f work%d to disk%d on %d\n ",top_one->getValue(),i+1,j+1,highestZ); |
119 | discardPiles[j]->addCardToTop(top_one); | 118 | discardPiles[j]->addCardToTop(top_one); |
120 | top_one->setPos(discardPiles[j]->getX(),discardPiles[j]->getY(),highestZ); | 119 | top_one->setPos(discardPiles[j]->getX(),discardPiles[j]->getY(),highestZ); |
121 | highestZ++; | 120 | highestZ++; |
122 | j = 4; | 121 | j = 4; |
123 | checkUnusable(); | 122 | checkUnusable(); |
124 | } | 123 | } |
125 | } | 124 | } |
126 | j++; | 125 | j++; |
127 | } | 126 | } |
128 | } | 127 | } |
129 | } | 128 | } |
130 | for (i=0;i<4;i++){ | 129 | for (i=0;i<4;i++){ |
131 | top_one = freecellPiles[i]->cardOnTop(); | 130 | top_one = freecellPiles[i]->cardOnTop(); |
132 | if (top_one != NULL) | 131 | if (top_one != NULL) |
133 | { | 132 | { |
134 | j = 0; | 133 | j = 0; |
135 | while ((j < 4)) | 134 | while ((j < 4)) |
136 | { | 135 | { |
137 | if (discardPiles[j]->isAllowedOnTop(top_one)){ | 136 | if (discardPiles[j]->isAllowedOnTop(top_one)){ |
138 | if (checkNeeded(top_one)){ | 137 | if (checkNeeded(top_one)){ |
139 | top_one->setCardPile(discardPiles[j]); | 138 | top_one->setCardPile(discardPiles[j]); |
140 | freecellPiles[i]->removeCard(top_one); | 139 | freecellPiles[i]->removeCard(top_one); |
141 | // printf("k %d f work%d to disk%d on %d\n ",top_one->getValue(),i+1,j+1,highestZ); | 140 | // printf("k %d f work%d to disk%d on %d\n ",top_one->getValue(),i+1,j+1,highestZ); |
142 | discardPiles[j]->addCardToTop(top_one); | 141 | discardPiles[j]->addCardToTop(top_one); |
143 | top_one->setPos(discardPiles[j]->getX(),discardPiles[j]->getY(),highestZ); | 142 | top_one->setPos(discardPiles[j]->getX(),discardPiles[j]->getY(),highestZ); |
144 | highestZ++; | 143 | highestZ++; |
145 | j = 4; | 144 | j = 4; |
146 | checkUnusable(); | 145 | checkUnusable(); |
147 | } | 146 | } |
148 | } | 147 | } |
149 | j++; | 148 | j++; |
150 | } | 149 | } |
151 | } | 150 | } |
152 | } | 151 | } |
153 | } | 152 | } |
154 | 153 | ||
155 | 154 | ||
156 | bool FreecellCardGame::mousePressCard( Card *c, QPoint p ) | 155 | bool FreecellCardGame::mousePressCard( Card *c, QPoint p ) |
157 | { | 156 | { |
158 | Q_UNUSED(p); | 157 | Q_UNUSED(p); |
159 | 158 | ||
160 | if ( !c->getCardPile()->isAllowedToBeMoved(c) ) { | 159 | if ( !c->getCardPile()->isAllowedToBeMoved(c) ) { |
161 | moving = NULL; | 160 | moving = NULL; |
162 | return TRUE; | 161 | return TRUE; |
163 | } | 162 | } |
164 | 163 | ||
165 | return FALSE; | 164 | return FALSE; |
166 | } | 165 | } |
167 | 166 | ||
168 | 167 | ||
169 | void FreecellCardGame::readConfig( Config& cfg ) | 168 | void FreecellCardGame::readConfig( Config& cfg ) |
170 | { | 169 | { |
171 | cfg.setGroup("GameState"); | 170 | cfg.setGroup("GameState"); |
172 | 171 | ||
173 | // Create Cards, but don't shuffle or deal them yet | 172 | // Create Cards, but don't shuffle or deal them yet |
174 | createDeck(); | 173 | createDeck(); |
175 | 174 | ||
176 | // Move the cards to their piles (deal them to their previous places) | 175 | // Move the cards to their piles (deal them to their previous places) |
177 | beginDealing(); | 176 | beginDealing(); |
178 | 177 | ||
179 | highestZ = 1; | 178 | highestZ = 1; |
180 | 179 | ||
181 | for (int k = 0; k < 4; k++) { | 180 | for (int k = 0; k < 4; k++) { |
182 | QString pile; | 181 | QString pile; |
183 | pile.sprintf( "FreeCellPile%i", k ); | 182 | pile.sprintf( "FreeCellPile%i", k ); |
184 | readPile( cfg, freecellPiles[k], pile, highestZ ); | 183 | readPile( cfg, freecellPiles[k], pile, highestZ ); |
185 | } | 184 | } |
186 | 185 | ||
187 | for (int k = 0; k < 4; k++) { | 186 | for (int k = 0; k < 4; k++) { |
188 | QString pile; | 187 | QString pile; |
189 | pile.sprintf( "DiscardPile%i", k ); | 188 | pile.sprintf( "DiscardPile%i", k ); |
190 | readPile( cfg, discardPiles[k], pile, highestZ ); | 189 | readPile( cfg, discardPiles[k], pile, highestZ ); |
191 | } | 190 | } |
192 | 191 | ||
193 | for (int k = 0; k < 8; k++) { | 192 | for (int k = 0; k < 8; k++) { |
194 | QString pile; | 193 | QString pile; |
195 | pile.sprintf( "WorkingPile%i", k ); | 194 | pile.sprintf( "WorkingPile%i", k ); |
196 | readPile( cfg, workingPiles[k], pile, highestZ ); | 195 | readPile( cfg, workingPiles[k], pile, highestZ ); |
197 | } | 196 | } |
198 | 197 | ||
199 | highestZ++; | 198 | highestZ++; |
200 | 199 | ||
201 | endDealing(); | 200 | endDealing(); |
202 | } | 201 | } |
203 | 202 | ||
204 | 203 | ||
205 | void FreecellCardGame::writeConfig( Config& cfg ) | 204 | void FreecellCardGame::writeConfig( Config& cfg ) |
206 | { | 205 | { |
207 | cfg.setGroup("GameState"); | 206 | cfg.setGroup("GameState"); |
208 | for ( int i = 0; i < 4; i++ ) { | 207 | for ( int i = 0; i < 4; i++ ) { |
209 | QString pile; | 208 | QString pile; |
210 | pile.sprintf( "FreeCellPile%i", i ); | 209 | pile.sprintf( "FreeCellPile%i", i ); |
211 | freecellPiles[i]->writeConfig( cfg, pile ); | 210 | freecellPiles[i]->writeConfig( cfg, pile ); |
212 | } | 211 | } |
213 | for ( int i = 0; i < 4; i++ ) { | 212 | for ( int i = 0; i < 4; i++ ) { |
214 | QString pile; | 213 | QString pile; |
215 | pile.sprintf( "DiscardPile%i", i ); | 214 | pile.sprintf( "DiscardPile%i", i ); |
216 | discardPiles[i]->writeConfig( cfg, pile ); | 215 | discardPiles[i]->writeConfig( cfg, pile ); |
217 | } | 216 | } |
218 | for ( int i = 0; i < 8; i++ ) { | 217 | for ( int i = 0; i < 8; i++ ) { |
219 | QString pile; | 218 | QString pile; |
220 | pile.sprintf( "WorkingPile%i", i ); | 219 | pile.sprintf( "WorkingPile%i", i ); |
221 | workingPiles[i]->writeConfig( cfg, pile ); | 220 | workingPiles[i]->writeConfig( cfg, pile ); |
222 | } | 221 | } |
223 | } | 222 | } |
224 | 223 | ||
225 | 224 | ||
diff --git a/noncore/games/solitaire/harpcardgame.cpp b/noncore/games/solitaire/harpcardgame.cpp index 0711622..d13d73b 100644 --- a/noncore/games/solitaire/harpcardgame.cpp +++ b/noncore/games/solitaire/harpcardgame.cpp | |||
@@ -1,179 +1,178 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | ** | 19 | ** |
20 | ** created on base of patiencecardgame by cam (C.A.Mader) 2002 | 20 | ** created on base of patiencecardgame by cam (C.A.Mader) 2002 |
21 | ** Rules for this game: | 21 | ** Rules for this game: |
22 | ** use 2 decks = 104 cards | 22 | ** use 2 decks = 104 cards |
23 | ** deal 8 rows with one open card in the first place | 23 | ** deal 8 rows with one open card in the first place |
24 | ** one hidden and one open in the second place and so on | 24 | ** one hidden and one open in the second place and so on |
25 | ** append red to black and vice versa | 25 | ** append red to black and vice versa |
26 | ** each card can be layed on a free place | 26 | ** each card can be layed on a free place |
27 | ** deal 8 cards at once | 27 | ** deal 8 cards at once |
28 | ** | 28 | ** |
29 | ** | 29 | ** |
30 | **********************************************************************/ | 30 | **********************************************************************/ |
31 | #include <qgfx_qws.h> | ||
32 | #include "harpcardgame.h" | 31 | #include "harpcardgame.h" |
33 | 32 | ||
34 | 33 | ||
35 | extern int highestZ; | 34 | extern int highestZ; |
36 | 35 | ||
37 | 36 | ||
38 | HarpCardGame::HarpCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent, 2)// Use 2 Decks | 37 | HarpCardGame::HarpCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent, 2)// Use 2 Decks |
39 | { | 38 | { |
40 | highestZ = 0; | 39 | highestZ = 0; |
41 | 40 | ||
42 | for (int i = 0; i < 8; i++) { | 41 | for (int i = 0; i < 8; i++) { |
43 | discardPiles[i] = new HarpDiscardPile( 27 + i * 26, 10, canvas() ); | 42 | discardPiles[i] = new HarpDiscardPile( 27 + i * 26, 10, canvas() ); |
44 | addCardPile(discardPiles[i]); | 43 | addCardPile(discardPiles[i]); |
45 | } | 44 | } |
46 | for (int i = 0; i < 8; i++) { | 45 | for (int i = 0; i < 8; i++) { |
47 | workingPiles[i] = new HarpWorkingPile( 27 + i * 26, 50, canvas() ); | 46 | workingPiles[i] = new HarpWorkingPile( 27 + i * 26, 50, canvas() ); |
48 | addCardPile(workingPiles[i]); | 47 | addCardPile(workingPiles[i]); |
49 | } | 48 | } |
50 | faceDownDealingPile = new HarpFaceDownDeck( 2, 10, canvas() ); | 49 | faceDownDealingPile = new HarpFaceDownDeck( 2, 10, canvas() ); |
51 | } | 50 | } |
52 | 51 | ||
53 | 52 | ||
54 | void HarpCardGame::deal(void) | 53 | void HarpCardGame::deal(void) |
55 | { | 54 | { |
56 | highestZ = 1; | 55 | highestZ = 1; |
57 | int t = 0; | 56 | int t = 0; |
58 | 57 | ||
59 | beginDealing(); | 58 | beginDealing(); |
60 | 59 | ||
61 | for (int i = 0; i < 8; i++) { | 60 | for (int i = 0; i < 8; i++) { |
62 | for (int k = 0; k < i+1; k++, t++) { | 61 | for (int k = 0; k < i+1; k++, t++) { |
63 | Card *card = cards[t]; | 62 | Card *card = cards[t]; |
64 | workingPiles[i]->addCardToTop(card); | 63 | workingPiles[i]->addCardToTop(card); |
65 | card->setCardPile( workingPiles[i] ); | 64 | card->setCardPile( workingPiles[i] ); |
66 | card->setPos( 0, 0, highestZ ); | 65 | card->setPos( 0, 0, highestZ ); |
67 | card->setFace(k==i); | 66 | card->setFace(k==i); |
68 | card->move( workingPiles[i]->getCardPos( card ) ); | 67 | card->move( workingPiles[i]->getCardPos( card ) ); |
69 | card->showCard(); | 68 | card->showCard(); |
70 | highestZ++; | 69 | highestZ++; |
71 | } | 70 | } |
72 | } | 71 | } |
73 | 72 | ||
74 | for ( ; t < getNumberOfCards(); t++) { | 73 | for ( ; t < getNumberOfCards(); t++) { |
75 | Card *card = cards[t]; | 74 | Card *card = cards[t]; |
76 | faceDownDealingPile->addCardToTop(card); | 75 | faceDownDealingPile->addCardToTop(card); |
77 | card->setCardPile( faceDownDealingPile ); | 76 | card->setCardPile( faceDownDealingPile ); |
78 | QPoint p = faceDownDealingPile->getCardPos( card ); | 77 | QPoint p = faceDownDealingPile->getCardPos( card ); |
79 | card->setPos( p.x(), p.y(), highestZ ); | 78 | card->setPos( p.x(), p.y(), highestZ ); |
80 | card->showCard(); | 79 | card->showCard(); |
81 | highestZ++; | 80 | highestZ++; |
82 | } | 81 | } |
83 | 82 | ||
84 | endDealing(); | 83 | endDealing(); |
85 | } | 84 | } |
86 | 85 | ||
87 | 86 | ||
88 | void HarpCardGame::readConfig( Config& cfg ) | 87 | void HarpCardGame::readConfig( Config& cfg ) |
89 | { | 88 | { |
90 | cfg.setGroup("GameState"); | 89 | cfg.setGroup("GameState"); |
91 | 90 | ||
92 | // Create Cards, but don't shuffle or deal them yet | 91 | // Create Cards, but don't shuffle or deal them yet |
93 | createDeck(); | 92 | createDeck(); |
94 | 93 | ||
95 | // Move the cards to their piles (deal them to their previous places) | 94 | // Move the cards to their piles (deal them to their previous places) |
96 | beginDealing(); | 95 | beginDealing(); |
97 | 96 | ||
98 | highestZ = 1; | 97 | highestZ = 1; |
99 | 98 | ||
100 | for (int i = 0; i < 8; i++) { | 99 | for (int i = 0; i < 8; i++) { |
101 | QString pile; | 100 | QString pile; |
102 | pile.sprintf( "HarpDiscardPile%i", i ); | 101 | pile.sprintf( "HarpDiscardPile%i", i ); |
103 | readPile( cfg, discardPiles[i], pile, highestZ ); | 102 | readPile( cfg, discardPiles[i], pile, highestZ ); |
104 | } | 103 | } |
105 | 104 | ||
106 | for (int i = 0; i < 8; i++) { | 105 | for (int i = 0; i < 8; i++) { |
107 | QString pile; | 106 | QString pile; |
108 | pile.sprintf( "HarpWorkingPile%i", i ); | 107 | pile.sprintf( "HarpWorkingPile%i", i ); |
109 | readPile( cfg, workingPiles[i], pile, highestZ ); | 108 | readPile( cfg, workingPiles[i], pile, highestZ ); |
110 | } | 109 | } |
111 | 110 | ||
112 | readPile( cfg, faceDownDealingPile, "HarpFaceDownDealingPile", highestZ ); | 111 | readPile( cfg, faceDownDealingPile, "HarpFaceDownDealingPile", highestZ ); |
113 | 112 | ||
114 | highestZ++; | 113 | highestZ++; |
115 | 114 | ||
116 | endDealing(); | 115 | endDealing(); |
117 | } | 116 | } |
118 | 117 | ||
119 | 118 | ||
120 | void HarpCardGame::writeConfig( Config& cfg ) | 119 | void HarpCardGame::writeConfig( Config& cfg ) |
121 | { | 120 | { |
122 | cfg.setGroup("GameState"); | 121 | cfg.setGroup("GameState"); |
123 | for ( int i = 0; i < 8; i++ ) { | 122 | for ( int i = 0; i < 8; i++ ) { |
124 | QString pile; | 123 | QString pile; |
125 | pile.sprintf( "HarpDiscardPile%i", i ); | 124 | pile.sprintf( "HarpDiscardPile%i", i ); |
126 | discardPiles[i]->writeConfig( cfg, pile ); | 125 | discardPiles[i]->writeConfig( cfg, pile ); |
127 | } | 126 | } |
128 | for ( int i = 0; i < 8; i++ ) { | 127 | for ( int i = 0; i < 8; i++ ) { |
129 | QString pile; | 128 | QString pile; |
130 | pile.sprintf( "HarpWorkingPile%i", i ); | 129 | pile.sprintf( "HarpWorkingPile%i", i ); |
131 | workingPiles[i]->writeConfig( cfg, pile ); | 130 | workingPiles[i]->writeConfig( cfg, pile ); |
132 | } | 131 | } |
133 | faceDownDealingPile->writeConfig( cfg, "HarpFaceDownDealingPile" ); | 132 | faceDownDealingPile->writeConfig( cfg, "HarpFaceDownDealingPile" ); |
134 | } | 133 | } |
135 | 134 | ||
136 | 135 | ||
137 | bool HarpCardGame::mousePressCard( Card *card, QPoint p ) | 136 | bool HarpCardGame::mousePressCard( Card *card, QPoint p ) |
138 | { | 137 | { |
139 | Q_UNUSED(p); | 138 | Q_UNUSED(p); |
140 | 139 | ||
141 | CanvasCard *item = (CanvasCard *)card; | 140 | CanvasCard *item = (CanvasCard *)card; |
142 | if (item->isFacing() != TRUE) { | 141 | if (item->isFacing() != TRUE) { |
143 | // From facedown stack | 142 | // From facedown stack |
144 | if ((item->x() == 2) && ((int)item->y() == 10)) { // Deal a row of 8 cards | 143 | if ((item->x() == 2) && ((int)item->y() == 10)) { // Deal a row of 8 cards |
145 | // Move 8 cards, one to each workingPile | 144 | // Move 8 cards, one to each workingPile |
146 | beginDealing(); | 145 | beginDealing(); |
147 | for (int i=0; i<8 && faceDownDealingPile->cardOnTop(); i++) { | 146 | for (int i=0; i<8 && faceDownDealingPile->cardOnTop(); i++) { |
148 | CanvasCard *card = (CanvasCard *)faceDownDealingPile->cardOnTop(); | 147 | CanvasCard *card = (CanvasCard *)faceDownDealingPile->cardOnTop(); |
149 | card->setZ(highestZ); | 148 | card->setZ(highestZ); |
150 | highestZ++; | 149 | highestZ++; |
151 | faceDownDealingPile->removeCard(card); | 150 | faceDownDealingPile->removeCard(card); |
152 | workingPiles[i]->addCardToTop(card); | 151 | workingPiles[i]->addCardToTop(card); |
153 | card->setCardPile( workingPiles[i] ); | 152 | card->setCardPile( workingPiles[i] ); |
154 | card->setFace(FALSE); | 153 | card->setFace(FALSE); |
155 | QPoint p = workingPiles[i]->getCardPos(card); | 154 | QPoint p = workingPiles[i]->getCardPos(card); |
156 | card->flipTo( p.x(), p.y() ); | 155 | card->flipTo( p.x(), p.y() ); |
157 | } | 156 | } |
158 | endDealing(); | 157 | endDealing(); |
159 | } | 158 | } |
160 | moving = NULL; | 159 | moving = NULL; |
161 | moved = FALSE; | 160 | moved = FALSE; |
162 | 161 | ||
163 | return TRUE; | 162 | return TRUE; |
164 | } else if ( !card->getCardPile()->isAllowedToBeMoved(card) ) {// Don't allow unclean columns to be moved | 163 | } else if ( !card->getCardPile()->isAllowedToBeMoved(card) ) {// Don't allow unclean columns to be moved |
165 | moving = NULL; | 164 | moving = NULL; |
166 | return TRUE; | 165 | return TRUE; |
167 | } | 166 | } |
168 | 167 | ||
169 | return FALSE; | 168 | return FALSE; |
170 | } | 169 | } |
171 | 170 | ||
172 | 171 | ||
173 | 172 | ||
174 | void HarpCardGame::mousePress(QPoint p) | 173 | void HarpCardGame::mousePress(QPoint p) |
175 | { | 174 | { |
176 | Q_UNUSED(p); | 175 | Q_UNUSED(p); |
177 | } | 176 | } |
178 | 177 | ||
179 | 178 | ||
diff --git a/noncore/games/solitaire/main.cpp b/noncore/games/solitaire/main.cpp index bd3cf8b..9301171 100644 --- a/noncore/games/solitaire/main.cpp +++ b/noncore/games/solitaire/main.cpp | |||
@@ -1,26 +1,25 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "canvascardwindow.h" | 21 | #include "canvascardwindow.h" |
22 | 22 | ||
23 | #include <qpe/qpeapplication.h> | ||
24 | #include <opie/oapplicationfactory.h> | 23 | #include <opie/oapplicationfactory.h> |
25 | 24 | ||
26 | OPIE_EXPORT_APP( OApplicationFactory<CanvasCardWindow> ) \ No newline at end of file | 25 | OPIE_EXPORT_APP( OApplicationFactory<CanvasCardWindow> ) \ No newline at end of file |
diff --git a/noncore/games/solitaire/patiencecardgame.cpp b/noncore/games/solitaire/patiencecardgame.cpp index 96a599c..756577a 100644 --- a/noncore/games/solitaire/patiencecardgame.cpp +++ b/noncore/games/solitaire/patiencecardgame.cpp | |||
@@ -1,280 +1,279 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include <qgfx_qws.h> | ||
21 | #include "patiencecardgame.h" | 20 | #include "patiencecardgame.h" |
22 | 21 | ||
23 | 22 | ||
24 | int highestZ = 0; | 23 | int highestZ = 0; |
25 | 24 | ||
26 | 25 | ||
27 | PatienceCardGame::PatienceCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent) | 26 | PatienceCardGame::PatienceCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent) |
28 | { | 27 | { |
29 | numberOfTimesThroughDeck = 0; | 28 | numberOfTimesThroughDeck = 0; |
30 | highestZ = 0; | 29 | highestZ = 0; |
31 | 30 | ||
32 | if ( qt_screen->deviceWidth() < 200 ) | 31 | if ( qt_screen->deviceWidth() < 200 ) |
33 | { | 32 | { |
34 | circleCross = new CanvasCircleOrCross( 7, 16, canvas() ); | 33 | circleCross = new CanvasCircleOrCross( 7, 16, canvas() ); |
35 | rectangle = new CanvasRoundRect( 30, 10, canvas() ); | 34 | rectangle = new CanvasRoundRect( 30, 10, canvas() ); |
36 | 35 | ||
37 | for (int i = 0; i < 4; i++) | 36 | for (int i = 0; i < 4; i++) |
38 | { | 37 | { |
39 | discardPiles[i] = new PatienceDiscardPile( 78 + i * 23, 10, canvas() ); | 38 | discardPiles[i] = new PatienceDiscardPile( 78 + i * 23, 10, canvas() ); |
40 | addCardPile(discardPiles[i]); | 39 | addCardPile(discardPiles[i]); |
41 | } | 40 | } |
42 | for (int i = 0; i < 7; i++) | 41 | for (int i = 0; i < 7; i++) |
43 | { | 42 | { |
44 | workingPiles[i] = new PatienceWorkingPile( 5 + i * 23, 50, canvas() ); | 43 | workingPiles[i] = new PatienceWorkingPile( 5 + i * 23, 50, canvas() ); |
45 | addCardPile(workingPiles[i]); | 44 | addCardPile(workingPiles[i]); |
46 | } | 45 | } |
47 | faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() ); | 46 | faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() ); |
48 | faceUpDealingPile = new PatienceFaceUpDeck( 30, 10, canvas() ); | 47 | faceUpDealingPile = new PatienceFaceUpDeck( 30, 10, canvas() ); |
49 | } | 48 | } |
50 | else | 49 | else |
51 | { | 50 | { |
52 | circleCross = new CanvasCircleOrCross( 7, 18, canvas() ); | 51 | circleCross = new CanvasCircleOrCross( 7, 18, canvas() ); |
53 | rectangle = new CanvasRoundRect( 35, 10, canvas() ); | 52 | rectangle = new CanvasRoundRect( 35, 10, canvas() ); |
54 | 53 | ||
55 | for (int i = 0; i < 4; i++) | 54 | for (int i = 0; i < 4; i++) |
56 | { | 55 | { |
57 | discardPiles[i] = new PatienceDiscardPile( 110 + i * 30, 10, canvas() ); | 56 | discardPiles[i] = new PatienceDiscardPile( 110 + i * 30, 10, canvas() ); |
58 | addCardPile(discardPiles[i]); | 57 | addCardPile(discardPiles[i]); |
59 | } | 58 | } |
60 | for (int i = 0; i < 7; i++) | 59 | for (int i = 0; i < 7; i++) |
61 | { | 60 | { |
62 | workingPiles[i] = new PatienceWorkingPile( 10 + i * 30, 50, canvas() ); | 61 | workingPiles[i] = new PatienceWorkingPile( 10 + i * 30, 50, canvas() ); |
63 | addCardPile(workingPiles[i]); | 62 | addCardPile(workingPiles[i]); |
64 | } | 63 | } |
65 | faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() ); | 64 | faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() ); |
66 | faceUpDealingPile = new PatienceFaceUpDeck( 35, 10, canvas() ); | 65 | faceUpDealingPile = new PatienceFaceUpDeck( 35, 10, canvas() ); |
67 | } | 66 | } |
68 | } | 67 | } |
69 | 68 | ||
70 | 69 | ||
71 | PatienceCardGame::~PatienceCardGame() | 70 | PatienceCardGame::~PatienceCardGame() |
72 | { | 71 | { |
73 | delete circleCross; | 72 | delete circleCross; |
74 | delete rectangle; | 73 | delete rectangle; |
75 | delete faceDownDealingPile; | 74 | delete faceDownDealingPile; |
76 | delete faceUpDealingPile; | 75 | delete faceUpDealingPile; |
77 | } | 76 | } |
78 | 77 | ||
79 | 78 | ||
80 | void PatienceCardGame::deal(void) | 79 | void PatienceCardGame::deal(void) |
81 | { | 80 | { |
82 | highestZ = 1; | 81 | highestZ = 1; |
83 | int t = 0; | 82 | int t = 0; |
84 | 83 | ||
85 | beginDealing(); | 84 | beginDealing(); |
86 | 85 | ||
87 | for (int i = 0; i < 7; i++) | 86 | for (int i = 0; i < 7; i++) |
88 | { | 87 | { |
89 | cards[t]->setFace(TRUE); | 88 | cards[t]->setFace(TRUE); |
90 | for (int k = i; k < 7; k++, t++) | 89 | for (int k = i; k < 7; k++, t++) |
91 | { | 90 | { |
92 | Card *card = cards[t]; | 91 | Card *card = cards[t]; |
93 | workingPiles[k]->addCardToTop(card); | 92 | workingPiles[k]->addCardToTop(card); |
94 | card->setCardPile( workingPiles[k] ); | 93 | card->setCardPile( workingPiles[k] ); |
95 | QPoint p = workingPiles[k]->getCardPos( card ); | 94 | QPoint p = workingPiles[k]->getCardPos( card ); |
96 | card->setPos( p.x(), p.y(), highestZ ); | 95 | card->setPos( p.x(), p.y(), highestZ ); |
97 | card->showCard(); | 96 | card->showCard(); |
98 | highestZ++; | 97 | highestZ++; |
99 | } | 98 | } |
100 | } | 99 | } |
101 | 100 | ||
102 | for ( ; t < 52; t++) | 101 | for ( ; t < 52; t++) |
103 | { | 102 | { |
104 | Card *card = cards[t]; | 103 | Card *card = cards[t]; |
105 | faceDownDealingPile->addCardToTop(card); | 104 | faceDownDealingPile->addCardToTop(card); |
106 | card->setCardPile( faceDownDealingPile ); | 105 | card->setCardPile( faceDownDealingPile ); |
107 | QPoint p = faceDownDealingPile->getCardPos( card ); | 106 | QPoint p = faceDownDealingPile->getCardPos( card ); |
108 | card->setPos( p.x(), p.y(), highestZ ); | 107 | card->setPos( p.x(), p.y(), highestZ ); |
109 | card->showCard(); | 108 | card->showCard(); |
110 | highestZ++; | 109 | highestZ++; |
111 | } | 110 | } |
112 | 111 | ||
113 | endDealing(); | 112 | endDealing(); |
114 | } | 113 | } |
115 | 114 | ||
116 | 115 | ||
117 | void PatienceCardGame::readConfig( Config& cfg ) | 116 | void PatienceCardGame::readConfig( Config& cfg ) |
118 | { | 117 | { |
119 | cfg.setGroup("GameState"); | 118 | cfg.setGroup("GameState"); |
120 | 119 | ||
121 | // Do we have a config file to read in? | 120 | // Do we have a config file to read in? |
122 | if ( !cfg.hasKey("numberOfTimesThroughDeck") ) | 121 | if ( !cfg.hasKey("numberOfTimesThroughDeck") ) |
123 | { | 122 | { |
124 | // if not, create a new game | 123 | // if not, create a new game |
125 | newGame(); | 124 | newGame(); |
126 | return; | 125 | return; |
127 | } | 126 | } |
128 | // We have a config file, lets read it in and use it | 127 | // We have a config file, lets read it in and use it |
129 | 128 | ||
130 | // Create Cards, but don't shuffle or deal them yet | 129 | // Create Cards, but don't shuffle or deal them yet |
131 | createDeck(); | 130 | createDeck(); |
132 | 131 | ||
133 | // How many times through the deck have we been | 132 | // How many times through the deck have we been |
134 | numberOfTimesThroughDeck = cfg.readNumEntry("numberOfTimesThroughDeck"); | 133 | numberOfTimesThroughDeck = cfg.readNumEntry("numberOfTimesThroughDeck"); |
135 | 134 | ||
136 | // restore state to the circle/cross under the dealing pile | 135 | // restore state to the circle/cross under the dealing pile |
137 | if ( canTurnOverDeck() ) | 136 | if ( canTurnOverDeck() ) |
138 | circleCross->setCircle(); | 137 | circleCross->setCircle(); |
139 | else | 138 | else |
140 | circleCross->setCross(); | 139 | circleCross->setCross(); |
141 | 140 | ||
142 | // Move the cards to their piles (deal them to their previous places) | 141 | // Move the cards to their piles (deal them to their previous places) |
143 | beginDealing(); | 142 | beginDealing(); |
144 | 143 | ||
145 | highestZ = 1; | 144 | highestZ = 1; |
146 | 145 | ||
147 | for (int k = 0; k < 7; k++) | 146 | for (int k = 0; k < 7; k++) |
148 | { | 147 | { |
149 | QString pile; | 148 | QString pile; |
150 | pile.sprintf( "WorkingPile%i", k ); | 149 | pile.sprintf( "WorkingPile%i", k ); |
151 | readPile( cfg, workingPiles[k], pile, highestZ ); | 150 | readPile( cfg, workingPiles[k], pile, highestZ ); |
152 | } | 151 | } |
153 | 152 | ||
154 | for (int k = 0; k < 4; k++) | 153 | for (int k = 0; k < 4; k++) |
155 | { | 154 | { |
156 | QString pile; | 155 | QString pile; |
157 | pile.sprintf( "DiscardPile%i", k ); | 156 | pile.sprintf( "DiscardPile%i", k ); |
158 | readPile( cfg, discardPiles[k], pile, highestZ ); | 157 | readPile( cfg, discardPiles[k], pile, highestZ ); |
159 | } | 158 | } |
160 | 159 | ||
161 | readPile( cfg, faceDownDealingPile, "FaceDownDealingPile", highestZ ); | 160 | readPile( cfg, faceDownDealingPile, "FaceDownDealingPile", highestZ ); |
162 | readPile( cfg, faceUpDealingPile, "FaceUpDealingPile", highestZ ); | 161 | readPile( cfg, faceUpDealingPile, "FaceUpDealingPile", highestZ ); |
163 | 162 | ||
164 | highestZ++; | 163 | highestZ++; |
165 | 164 | ||
166 | endDealing(); | 165 | endDealing(); |
167 | } | 166 | } |
168 | 167 | ||
169 | 168 | ||
170 | void PatienceCardGame::writeConfig( Config& cfg ) | 169 | void PatienceCardGame::writeConfig( Config& cfg ) |
171 | { | 170 | { |
172 | cfg.setGroup("GameState"); | 171 | cfg.setGroup("GameState"); |
173 | cfg.writeEntry("numberOfTimesThroughDeck", numberOfTimesThroughDeck); | 172 | cfg.writeEntry("numberOfTimesThroughDeck", numberOfTimesThroughDeck); |
174 | 173 | ||
175 | for ( int i = 0; i < 7; i++ ) | 174 | for ( int i = 0; i < 7; i++ ) |
176 | { | 175 | { |
177 | QString pile; | 176 | QString pile; |
178 | pile.sprintf( "WorkingPile%i", i ); | 177 | pile.sprintf( "WorkingPile%i", i ); |
179 | workingPiles[i]->writeConfig( cfg, pile ); | 178 | workingPiles[i]->writeConfig( cfg, pile ); |
180 | } | 179 | } |
181 | for ( int i = 0; i < 4; i++ ) | 180 | for ( int i = 0; i < 4; i++ ) |
182 | { | 181 | { |
183 | QString pile; | 182 | QString pile; |
184 | pile.sprintf( "DiscardPile%i", i ); | 183 | pile.sprintf( "DiscardPile%i", i ); |
185 | discardPiles[i]->writeConfig( cfg, pile ); | 184 | discardPiles[i]->writeConfig( cfg, pile ); |
186 | } | 185 | } |
187 | faceDownDealingPile->writeConfig( cfg, "FaceDownDealingPile" ); | 186 | faceDownDealingPile->writeConfig( cfg, "FaceDownDealingPile" ); |
188 | faceUpDealingPile->writeConfig( cfg, "FaceUpDealingPile" ); | 187 | faceUpDealingPile->writeConfig( cfg, "FaceUpDealingPile" ); |
189 | } | 188 | } |
190 | 189 | ||
191 | 190 | ||
192 | bool PatienceCardGame::mousePressCard( Card *card, QPoint p ) | 191 | bool PatienceCardGame::mousePressCard( Card *card, QPoint p ) |
193 | { | 192 | { |
194 | Q_UNUSED(p); | 193 | Q_UNUSED(p); |
195 | 194 | ||
196 | CanvasCard *item = (CanvasCard *)card; | 195 | CanvasCard *item = (CanvasCard *)card; |
197 | if (item->isFacing() != TRUE) | 196 | if (item->isFacing() != TRUE) |
198 | { | 197 | { |
199 | // From facedown stack | 198 | // From facedown stack |
200 | if ((item->x() == 5) && ((int)item->y() == 10)) | 199 | if ((item->x() == 5) && ((int)item->y() == 10)) |
201 | { | 200 | { |
202 | item->setZ(highestZ); | 201 | item->setZ(highestZ); |
203 | highestZ++; | 202 | highestZ++; |
204 | 203 | ||
205 | // Added Code | 204 | // Added Code |
206 | faceDownDealingPile->removeCard(item); | 205 | faceDownDealingPile->removeCard(item); |
207 | faceUpDealingPile->addCardToTop(item); | 206 | faceUpDealingPile->addCardToTop(item); |
208 | item->setCardPile( faceUpDealingPile ); | 207 | item->setCardPile( faceUpDealingPile ); |
209 | 208 | ||
210 | if ( qt_screen->deviceWidth() < 200 ) | 209 | if ( qt_screen->deviceWidth() < 200 ) |
211 | item->flipTo( 30, (int)item->y() ); | 210 | item->flipTo( 30, (int)item->y() ); |
212 | else | 211 | else |
213 | item->flipTo( 35, (int)item->y() ); | 212 | item->flipTo( 35, (int)item->y() ); |
214 | } | 213 | } |
215 | else return FALSE; // <- was missing, caused facedown card to react | 214 | else return FALSE; // <- was missing, caused facedown card to react |
216 | // to clicking, which is wrong | 215 | // to clicking, which is wrong |
217 | moving = NULL; | 216 | moving = NULL; |
218 | moved = FALSE; | 217 | moved = FALSE; |
219 | 218 | ||
220 | // move two other cards if we flip three at a time | 219 | // move two other cards if we flip three at a time |
221 | int flipped = 1; | 220 | int flipped = 1; |
222 | QCanvasItemList l = canvas()->collisions( p ); | 221 | QCanvasItemList l = canvas()->collisions( p ); |
223 | for (QCanvasItemList::Iterator it = l.begin(); (it != l.end()) && (flipped != cardsDrawn()); ++it) | 222 | for (QCanvasItemList::Iterator it = l.begin(); (it != l.end()) && (flipped != cardsDrawn()); ++it) |
224 | { | 223 | { |
225 | if ( (*it)->rtti() == canvasCardId ) | 224 | if ( (*it)->rtti() == canvasCardId ) |
226 | { | 225 | { |
227 | CanvasCard *item = (CanvasCard *)*it; | 226 | CanvasCard *item = (CanvasCard *)*it; |
228 | if (item->animated()) | 227 | if (item->animated()) |
229 | continue; | 228 | continue; |
230 | item->setZ(highestZ); | 229 | item->setZ(highestZ); |
231 | highestZ++; | 230 | highestZ++; |
232 | flipped++; | 231 | flipped++; |
233 | 232 | ||
234 | // Added Code | 233 | // Added Code |
235 | faceDownDealingPile->removeCard(item); | 234 | faceDownDealingPile->removeCard(item); |
236 | faceUpDealingPile->addCardToTop(item); | 235 | faceUpDealingPile->addCardToTop(item); |
237 | item->setCardPile( faceUpDealingPile ); | 236 | item->setCardPile( faceUpDealingPile ); |
238 | 237 | ||
239 | if ( qt_screen->deviceWidth() < 200 ) | 238 | if ( qt_screen->deviceWidth() < 200 ) |
240 | item->flipTo( 30, (int)item->y(), 8 * flipped ); | 239 | item->flipTo( 30, (int)item->y(), 8 * flipped ); |
241 | else | 240 | else |
242 | item->flipTo( 35, (int)item->y(), 8 * flipped ); | 241 | item->flipTo( 35, (int)item->y(), 8 * flipped ); |
243 | } | 242 | } |
244 | } | 243 | } |
245 | 244 | ||
246 | return TRUE; | 245 | return TRUE; |
247 | } | 246 | } |
248 | 247 | ||
249 | return FALSE; | 248 | return FALSE; |
250 | } | 249 | } |
251 | 250 | ||
252 | 251 | ||
253 | void PatienceCardGame::mousePress(QPoint p) | 252 | void PatienceCardGame::mousePress(QPoint p) |
254 | { | 253 | { |
255 | if ( canTurnOverDeck() && | 254 | if ( canTurnOverDeck() && |
256 | (p.x() > 5) && (p.x() < 28) && | 255 | (p.x() > 5) && (p.x() < 28) && |
257 | (p.y() > 10) && (p.y() < 46) ) | 256 | (p.y() > 10) && (p.y() < 46) ) |
258 | { | 257 | { |
259 | 258 | ||
260 | beginDealing(); | 259 | beginDealing(); |
261 | Card *card = faceUpDealingPile->cardOnTop(); | 260 | Card *card = faceUpDealingPile->cardOnTop(); |
262 | while ( card ) | 261 | while ( card ) |
263 | { | 262 | { |
264 | card->setPos( 5, 10, highestZ ); | 263 | card->setPos( 5, 10, highestZ ); |
265 | card->setFace( FALSE ); | 264 | card->setFace( FALSE ); |
266 | faceUpDealingPile->removeCard( card ); | 265 | faceUpDealingPile->removeCard( card ); |
267 | faceDownDealingPile->addCardToTop( card ); | 266 | faceDownDealingPile->addCardToTop( card ); |
268 | card->setCardPile( faceDownDealingPile ); | 267 | card->setCardPile( faceDownDealingPile ); |
269 | card = faceUpDealingPile->cardOnTop(); | 268 | card = faceUpDealingPile->cardOnTop(); |
270 | highestZ++; | 269 | highestZ++; |
271 | } | 270 | } |
272 | endDealing(); | 271 | endDealing(); |
273 | 272 | ||
274 | throughDeck(); | 273 | throughDeck(); |
275 | 274 | ||
276 | moved = TRUE; | 275 | moved = TRUE; |
277 | } | 276 | } |
278 | } | 277 | } |
279 | 278 | ||
280 | 279 | ||
diff --git a/noncore/games/solitaire/teeclubcardgame.cpp b/noncore/games/solitaire/teeclubcardgame.cpp index 0941e0d..b1af757 100644 --- a/noncore/games/solitaire/teeclubcardgame.cpp +++ b/noncore/games/solitaire/teeclubcardgame.cpp | |||
@@ -1,202 +1,201 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | ** | 19 | ** |
20 | ** created on base of patiencecardgame by cam (C.A.Mader) 2002 | 20 | ** created on base of patiencecardgame by cam (C.A.Mader) 2002 |
21 | ** Rules for this game: | 21 | ** Rules for this game: |
22 | ** use 2 decks = 104 cards | 22 | ** use 2 decks = 104 cards |
23 | ** deal 9 rows with 5 open cards each | 23 | ** deal 9 rows with 5 open cards each |
24 | ** append one card to each other card which is one step higher | 24 | ** append one card to each other card which is one step higher |
25 | ** move only columns of cards which are equal in suit | 25 | ** move only columns of cards which are equal in suit |
26 | ** each card can be layed on a free place | 26 | ** each card can be layed on a free place |
27 | ** deal 1 card at once on the first pile | 27 | ** deal 1 card at once on the first pile |
28 | ** | 28 | ** |
29 | ** | 29 | ** |
30 | **********************************************************************/ | 30 | **********************************************************************/ |
31 | #include <qgfx_qws.h> | ||
32 | #include "teeclubcardgame.h" | 31 | #include "teeclubcardgame.h" |
33 | 32 | ||
34 | 33 | ||
35 | extern int highestZ; | 34 | extern int highestZ; |
36 | 35 | ||
37 | 36 | ||
38 | TeeclubCardGame::TeeclubCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent, 2)// Use 2 Decks | 37 | TeeclubCardGame::TeeclubCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent, 2)// Use 2 Decks |
39 | { | 38 | { |
40 | highestZ = 0; | 39 | highestZ = 0; |
41 | 40 | ||
42 | for (int i = 0; i < 8; i++) { | 41 | for (int i = 0; i < 8; i++) { |
43 | discardPiles[i] = new TeeclubDiscardPile( 27 + i * 26, 10, canvas() ); | 42 | discardPiles[i] = new TeeclubDiscardPile( 27 + i * 26, 10, canvas() ); |
44 | addCardPile(discardPiles[i]); | 43 | addCardPile(discardPiles[i]); |
45 | } | 44 | } |
46 | for (int i = 0; i < 9; i++) { | 45 | for (int i = 0; i < 9; i++) { |
47 | workingPiles[i] = new TeeclubWorkingPile( 2 + i * 26, 50, canvas() ); | 46 | workingPiles[i] = new TeeclubWorkingPile( 2 + i * 26, 50, canvas() ); |
48 | addCardPile(workingPiles[i]); | 47 | addCardPile(workingPiles[i]); |
49 | } | 48 | } |
50 | faceDownDealingPile = new TeeclubFaceDownDeck( 2, 10, canvas() ); | 49 | faceDownDealingPile = new TeeclubFaceDownDeck( 2, 10, canvas() ); |
51 | } | 50 | } |
52 | 51 | ||
53 | 52 | ||
54 | void TeeclubCardGame::deal(void) | 53 | void TeeclubCardGame::deal(void) |
55 | { | 54 | { |
56 | highestZ = 1; | 55 | highestZ = 1; |
57 | int t = 0; | 56 | int t = 0; |
58 | 57 | ||
59 | beginDealing(); | 58 | beginDealing(); |
60 | 59 | ||
61 | for (int i = 0; i < 9; i++) { | 60 | for (int i = 0; i < 9; i++) { |
62 | workingPiles[i]->setOffsetDown(13); | 61 | workingPiles[i]->setOffsetDown(13); |
63 | workingPiles[i]->beginPileResize(); | 62 | workingPiles[i]->beginPileResize(); |
64 | for (int k = 0; k < 5; k++, t++) { | 63 | for (int k = 0; k < 5; k++, t++) { |
65 | Card *card = cards[t]; | 64 | Card *card = cards[t]; |
66 | workingPiles[i]->addCardToTop(card); | 65 | workingPiles[i]->addCardToTop(card); |
67 | card->setCardPile( workingPiles[i] ); | 66 | card->setCardPile( workingPiles[i] ); |
68 | card->setPos( 0, 0, highestZ ); | 67 | card->setPos( 0, 0, highestZ ); |
69 | card->setFace(TRUE); | 68 | card->setFace(TRUE); |
70 | card->move( workingPiles[i]->getCardPos( card ) ); | 69 | card->move( workingPiles[i]->getCardPos( card ) ); |
71 | card->showCard(); | 70 | card->showCard(); |
72 | highestZ++; | 71 | highestZ++; |
73 | } | 72 | } |
74 | } | 73 | } |
75 | 74 | ||
76 | for ( ; t < getNumberOfCards(); t++) { | 75 | for ( ; t < getNumberOfCards(); t++) { |
77 | Card *card = cards[t]; | 76 | Card *card = cards[t]; |
78 | faceDownDealingPile->addCardToTop(card); | 77 | faceDownDealingPile->addCardToTop(card); |
79 | card->setCardPile( faceDownDealingPile ); | 78 | card->setCardPile( faceDownDealingPile ); |
80 | QPoint p = faceDownDealingPile->getCardPos( card ); | 79 | QPoint p = faceDownDealingPile->getCardPos( card ); |
81 | card->setPos( p.x(), p.y(), highestZ ); | 80 | card->setPos( p.x(), p.y(), highestZ ); |
82 | card->showCard(); | 81 | card->showCard(); |
83 | highestZ++; | 82 | highestZ++; |
84 | } | 83 | } |
85 | 84 | ||
86 | endDealing(); | 85 | endDealing(); |
87 | } | 86 | } |
88 | 87 | ||
89 | 88 | ||
90 | void TeeclubCardGame::resizePiles() | 89 | void TeeclubCardGame::resizePiles() |
91 | { | 90 | { |
92 | beginDealing(); | 91 | beginDealing(); |
93 | for (int i = 0; i < 9; i++) { | 92 | for (int i = 0; i < 9; i++) { |
94 | while ((workingPiles[i]->getCardPos(NULL).y() > 230) && (workingPiles[i]->getOffsetDown()>1)) { | 93 | while ((workingPiles[i]->getCardPos(NULL).y() > 230) && (workingPiles[i]->getOffsetDown()>1)) { |
95 | // resize the pile | 94 | // resize the pile |
96 | workingPiles[i]->setOffsetDown(workingPiles[i]->getOffsetDown()-1); | 95 | workingPiles[i]->setOffsetDown(workingPiles[i]->getOffsetDown()-1); |
97 | Card *card = workingPiles[i]->cardOnBottom(); | 96 | Card *card = workingPiles[i]->cardOnBottom(); |
98 | int p=0; | 97 | int p=0; |
99 | while (card != NULL) { | 98 | while (card != NULL) { |
100 | card->setPos( 0, 0, p++ ); | 99 | card->setPos( 0, 0, p++ ); |
101 | card->move( workingPiles[i]->getCardPos( card ) ); | 100 | card->move( workingPiles[i]->getCardPos( card ) ); |
102 | card = workingPiles[i]->cardInfront(card); | 101 | card = workingPiles[i]->cardInfront(card); |
103 | } | 102 | } |
104 | } | 103 | } |
105 | } | 104 | } |
106 | endDealing(); | 105 | endDealing(); |
107 | } | 106 | } |
108 | 107 | ||
109 | 108 | ||
110 | void TeeclubCardGame::readConfig( Config& cfg ) | 109 | void TeeclubCardGame::readConfig( Config& cfg ) |
111 | { | 110 | { |
112 | cfg.setGroup("GameState"); | 111 | cfg.setGroup("GameState"); |
113 | 112 | ||
114 | // Create Cards, but don't shuffle or deal them yet | 113 | // Create Cards, but don't shuffle or deal them yet |
115 | createDeck(); | 114 | createDeck(); |
116 | 115 | ||
117 | // Move the cards to their piles (deal them to their previous places) | 116 | // Move the cards to their piles (deal them to their previous places) |
118 | beginDealing(); | 117 | beginDealing(); |
119 | 118 | ||
120 | highestZ = 1; | 119 | highestZ = 1; |
121 | 120 | ||
122 | for (int i = 0; i < 8; i++) { | 121 | for (int i = 0; i < 8; i++) { |
123 | QString pile; | 122 | QString pile; |
124 | pile.sprintf( "TeeclubDiscardPile%i", i ); | 123 | pile.sprintf( "TeeclubDiscardPile%i", i ); |
125 | readPile( cfg, discardPiles[i], pile, highestZ ); | 124 | readPile( cfg, discardPiles[i], pile, highestZ ); |
126 | } | 125 | } |
127 | 126 | ||
128 | for (int i = 0; i < 9; i++) { | 127 | for (int i = 0; i < 9; i++) { |
129 | workingPiles[i]->endPileResize(); | 128 | workingPiles[i]->endPileResize(); |
130 | QString pile; | 129 | QString pile; |
131 | pile.sprintf( "TeeclubWorkingPile%i", i ); | 130 | pile.sprintf( "TeeclubWorkingPile%i", i ); |
132 | readPile( cfg, workingPiles[i], pile, highestZ ); | 131 | readPile( cfg, workingPiles[i], pile, highestZ ); |
133 | workingPiles[i]->beginPileResize(); | 132 | workingPiles[i]->beginPileResize(); |
134 | } | 133 | } |
135 | 134 | ||
136 | readPile( cfg, faceDownDealingPile, "TeeclubFaceDownDealingPile", highestZ ); | 135 | readPile( cfg, faceDownDealingPile, "TeeclubFaceDownDealingPile", highestZ ); |
137 | 136 | ||
138 | highestZ++; | 137 | highestZ++; |
139 | 138 | ||
140 | endDealing(); | 139 | endDealing(); |
141 | resizePiles(); | 140 | resizePiles(); |
142 | } | 141 | } |
143 | 142 | ||
144 | 143 | ||
145 | void TeeclubCardGame::writeConfig( Config& cfg ) | 144 | void TeeclubCardGame::writeConfig( Config& cfg ) |
146 | { | 145 | { |
147 | cfg.setGroup("GameState"); | 146 | cfg.setGroup("GameState"); |
148 | for ( int i = 0; i < 8; i++ ) { | 147 | for ( int i = 0; i < 8; i++ ) { |
149 | QString pile; | 148 | QString pile; |
150 | pile.sprintf( "TeeclubDiscardPile%i", i ); | 149 | pile.sprintf( "TeeclubDiscardPile%i", i ); |
151 | discardPiles[i]->writeConfig( cfg, pile ); | 150 | discardPiles[i]->writeConfig( cfg, pile ); |
152 | } | 151 | } |
153 | for ( int i = 0; i < 9; i++ ) { | 152 | for ( int i = 0; i < 9; i++ ) { |
154 | QString pile; | 153 | QString pile; |
155 | pile.sprintf( "TeeclubWorkingPile%i", i ); | 154 | pile.sprintf( "TeeclubWorkingPile%i", i ); |
156 | workingPiles[i]->writeConfig( cfg, pile ); | 155 | workingPiles[i]->writeConfig( cfg, pile ); |
157 | } | 156 | } |
158 | faceDownDealingPile->writeConfig( cfg, "TeeclubFaceDownDealingPile" ); | 157 | faceDownDealingPile->writeConfig( cfg, "TeeclubFaceDownDealingPile" ); |
159 | } | 158 | } |
160 | 159 | ||
161 | 160 | ||
162 | bool TeeclubCardGame::mousePressCard( Card *card, QPoint p ) | 161 | bool TeeclubCardGame::mousePressCard( Card *card, QPoint p ) |
163 | { | 162 | { |
164 | Q_UNUSED(p); | 163 | Q_UNUSED(p); |
165 | 164 | ||
166 | CanvasCard *item = (CanvasCard *)card; | 165 | CanvasCard *item = (CanvasCard *)card; |
167 | if (item->isFacing() != TRUE) { | 166 | if (item->isFacing() != TRUE) { |
168 | // From facedown stack | 167 | // From facedown stack |
169 | if ((item->x() == 2) && ((int)item->y() == 10)) { // Deal 1 card | 168 | if ((item->x() == 2) && ((int)item->y() == 10)) { // Deal 1 card |
170 | // Move 8 cards, one to each workingPile | 169 | // Move 8 cards, one to each workingPile |
171 | beginDealing(); | 170 | beginDealing(); |
172 | CanvasCard *card = (CanvasCard *)faceDownDealingPile->cardOnTop(); | 171 | CanvasCard *card = (CanvasCard *)faceDownDealingPile->cardOnTop(); |
173 | card->setZ(highestZ); | 172 | card->setZ(highestZ); |
174 | highestZ++; | 173 | highestZ++; |
175 | faceDownDealingPile->removeCard(card); | 174 | faceDownDealingPile->removeCard(card); |
176 | workingPiles[0]->addCardToTop(card); | 175 | workingPiles[0]->addCardToTop(card); |
177 | card->setCardPile( workingPiles[0] ); | 176 | card->setCardPile( workingPiles[0] ); |
178 | card->setFace(FALSE); | 177 | card->setFace(FALSE); |
179 | QPoint p = workingPiles[0]->getCardPos(card); | 178 | QPoint p = workingPiles[0]->getCardPos(card); |
180 | card->flipTo( p.x(), p.y() ); | 179 | card->flipTo( p.x(), p.y() ); |
181 | endDealing(); | 180 | endDealing(); |
182 | } | 181 | } |
183 | moving = NULL; | 182 | moving = NULL; |
184 | moved = FALSE; | 183 | moved = FALSE; |
185 | 184 | ||
186 | return TRUE; | 185 | return TRUE; |
187 | } else if ( !card->getCardPile()->isAllowedToBeMoved(card) ) {// Don't allow unclean columns to be moved | 186 | } else if ( !card->getCardPile()->isAllowedToBeMoved(card) ) {// Don't allow unclean columns to be moved |
188 | moving = NULL; | 187 | moving = NULL; |
189 | return TRUE; | 188 | return TRUE; |
190 | } | 189 | } |
191 | 190 | ||
192 | return FALSE; | 191 | return FALSE; |
193 | } | 192 | } |
194 | 193 | ||
195 | 194 | ||
196 | 195 | ||
197 | void TeeclubCardGame::mousePress(QPoint p) | 196 | void TeeclubCardGame::mousePress(QPoint p) |
198 | { | 197 | { |
199 | Q_UNUSED(p); | 198 | Q_UNUSED(p); |
200 | } | 199 | } |
201 | 200 | ||
202 | 201 | ||
diff --git a/noncore/games/tetrix/main.cpp b/noncore/games/tetrix/main.cpp index fcf4b33..bf1242f 100644 --- a/noncore/games/tetrix/main.cpp +++ b/noncore/games/tetrix/main.cpp | |||
@@ -1,28 +1,27 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "qtetrix.h" | 21 | #include "qtetrix.h" |
22 | 22 | ||
23 | #include <qpe/qpeapplication.h> | ||
24 | 23 | ||
25 | #include <opie/oapplicationfactory.h> | 24 | #include <opie/oapplicationfactory.h> |
26 | 25 | ||
27 | OPIE_EXPORT_APP( OApplicationFactory<QTetrix> ) | 26 | OPIE_EXPORT_APP( OApplicationFactory<QTetrix> ) |
28 | 27 | ||
diff --git a/noncore/games/tetrix/ohighscoredlg.cpp b/noncore/games/tetrix/ohighscoredlg.cpp index 7581f51..8d8079e 100644 --- a/noncore/games/tetrix/ohighscoredlg.cpp +++ b/noncore/games/tetrix/ohighscoredlg.cpp | |||
@@ -1,200 +1,199 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | begin : January 2003 | 2 | begin : January 2003 |
3 | copyright : ( C ) 2003 by Carsten Niehaus | 3 | copyright : ( C ) 2003 by Carsten Niehaus |
4 | email : cniehaus@handhelds.org | 4 | email : cniehaus@handhelds.org |
5 | **************************************************************************/ | 5 | **************************************************************************/ |
6 | 6 | ||
7 | /*************************************************************************** | 7 | /*************************************************************************** |
8 | * * | 8 | * * |
9 | * This program is free software; you can redistribute it and/or modify * | 9 | * This program is free software; you can redistribute it and/or modify * |
10 | * it under the terms of the GNU General Public License as published by * | 10 | * it under the terms of the GNU General Public License as published by * |
11 | * the Free Software Foundation; either version 2 of the License, or * | 11 | * the Free Software Foundation; either version 2 of the License, or * |
12 | * ( at your option ) any later version. * | 12 | * ( at your option ) any later version. * |
13 | * * | 13 | * * |
14 | **************************************************************************/ | 14 | **************************************************************************/ |
15 | 15 | ||
16 | #include <qdialog.h> | 16 | #include <qdialog.h> |
17 | #include <qpe/config.h> | ||
18 | #include <qlayout.h> | 17 | #include <qlayout.h> |
19 | #include <qpe/config.h> | ||
20 | #include <qpe/qpeapplication.h> | 18 | #include <qpe/qpeapplication.h> |
19 | #include <qpe/config.h> | ||
21 | 20 | ||
22 | #include <qstring.h> | 21 | #include <qstring.h> |
23 | #include <qhbox.h> | 22 | #include <qhbox.h> |
24 | #include <qvbox.h> | 23 | #include <qvbox.h> |
25 | #include <qlabel.h> | 24 | #include <qlabel.h> |
26 | #include <qlistview.h> | 25 | #include <qlistview.h> |
27 | #include <qlineedit.h> | 26 | #include <qlineedit.h> |
28 | 27 | ||
29 | #include "ohighscoredlg.h" | 28 | #include "ohighscoredlg.h" |
30 | 29 | ||
31 | OHighscore::OHighscore( int score , int playerLevel ) | 30 | OHighscore::OHighscore( int score , int playerLevel ) |
32 | { | 31 | { |
33 | pLevel = playerLevel; | 32 | pLevel = playerLevel; |
34 | getList(); | 33 | getList(); |
35 | checkIfItIsANewhighscore( score ); | 34 | checkIfItIsANewhighscore( score ); |
36 | } | 35 | } |
37 | 36 | ||
38 | OHighscore::~OHighscore() | 37 | OHighscore::~OHighscore() |
39 | { | 38 | { |
40 | std::list<t_playerData*>::iterator deleteIterator = playerData.begin(); | 39 | std::list<t_playerData*>::iterator deleteIterator = playerData.begin(); |
41 | for ( ; deleteIterator != playerData.end() ; deleteIterator++ ) | 40 | for ( ; deleteIterator != playerData.end() ; deleteIterator++ ) |
42 | { | 41 | { |
43 | delete ( *deleteIterator ); | 42 | delete ( *deleteIterator ); |
44 | } | 43 | } |
45 | } | 44 | } |
46 | 45 | ||
47 | void OHighscore::getList() | 46 | void OHighscore::getList() |
48 | { | 47 | { |
49 | Config cfg ( "tetrix" ); | 48 | Config cfg ( "tetrix" ); |
50 | cfg.setGroup( QString::number( 1 ) ); | 49 | cfg.setGroup( QString::number( 1 ) ); |
51 | lowest = cfg.readNumEntry( "Points" ); | 50 | lowest = cfg.readNumEntry( "Points" ); |
52 | playerData.clear(); | 51 | playerData.clear(); |
53 | 52 | ||
54 | int rest = 1;//for the filling up later | 53 | int rest = 1;//for the filling up later |
55 | 54 | ||
56 | for ( int i = 1 ; i < 11 ; i++ ) | 55 | for ( int i = 1 ; i < 11 ; i++ ) |
57 | { | 56 | { |
58 | if ( cfg.hasGroup( QString::number( i ) ) ) | 57 | if ( cfg.hasGroup( QString::number( i ) ) ) |
59 | { | 58 | { |
60 | cfg.setGroup( QString::number( i ) ); | 59 | cfg.setGroup( QString::number( i ) ); |
61 | int temp = cfg.readNumEntry( "Points" ); | 60 | int temp = cfg.readNumEntry( "Points" ); |
62 | 61 | ||
63 | t_playerData *pPlayerData = new t_playerData; | 62 | t_playerData *pPlayerData = new t_playerData; |
64 | pPlayerData->sName = cfg.readEntry( "Name" ); | 63 | pPlayerData->sName = cfg.readEntry( "Name" ); |
65 | pPlayerData->points = temp; | 64 | pPlayerData->points = temp; |
66 | pPlayerData->level = cfg.readNumEntry( "Level" ); | 65 | pPlayerData->level = cfg.readNumEntry( "Level" ); |
67 | 66 | ||
68 | playerData.push_back( pPlayerData ); | 67 | playerData.push_back( pPlayerData ); |
69 | 68 | ||
70 | if ( (temp < lowest) ) lowest = temp; | 69 | if ( (temp < lowest) ) lowest = temp; |
71 | rest++; | 70 | rest++; |
72 | } | 71 | } |
73 | } | 72 | } |
74 | 73 | ||
75 | //now I fill up the rest of the list | 74 | //now I fill up the rest of the list |
76 | if ( rest < 11 ) //only go in this loop if there are less than | 75 | if ( rest < 11 ) //only go in this loop if there are less than |
77 | //10 highscoreentries | 76 | //10 highscoreentries |
78 | { | 77 | { |
79 | lowest = 0; | 78 | lowest = 0; |
80 | for ( ; rest < 11 ; rest++ ) | 79 | for ( ; rest < 11 ; rest++ ) |
81 | { | 80 | { |
82 | t_playerData *pPlayerData = new t_playerData; | 81 | t_playerData *pPlayerData = new t_playerData; |
83 | pPlayerData->sName = tr( "empty"); | 82 | pPlayerData->sName = tr( "empty"); |
84 | pPlayerData->points = 0; | 83 | pPlayerData->points = 0; |
85 | pPlayerData->level = 0; | 84 | pPlayerData->level = 0; |
86 | 85 | ||
87 | playerData.push_back( pPlayerData ); | 86 | playerData.push_back( pPlayerData ); |
88 | } | 87 | } |
89 | } | 88 | } |
90 | 89 | ||
91 | } | 90 | } |
92 | 91 | ||
93 | void OHighscore::checkIfItIsANewhighscore( int points) | 92 | void OHighscore::checkIfItIsANewhighscore( int points) |
94 | { | 93 | { |
95 | if ( points > lowest ) | 94 | if ( points > lowest ) |
96 | isNewhighscore = true; | 95 | isNewhighscore = true; |
97 | else | 96 | else |
98 | isNewhighscore = false; | 97 | isNewhighscore = false; |
99 | } | 98 | } |
100 | 99 | ||
101 | void OHighscore::insertData( QString name , int punkte , int playerLevel ) | 100 | void OHighscore::insertData( QString name , int punkte , int playerLevel ) |
102 | { | 101 | { |
103 | Config cfg ( "tetrix" ); | 102 | Config cfg ( "tetrix" ); |
104 | int entryNumber = 1; | 103 | int entryNumber = 1; |
105 | std::list<t_playerData*>::iterator insertIterator = playerData.begin(); | 104 | std::list<t_playerData*>::iterator insertIterator = playerData.begin(); |
106 | while ( insertIterator != playerData.end() ) | 105 | while ( insertIterator != playerData.end() ) |
107 | { | 106 | { |
108 | if ( punkte > ( *insertIterator )->points ) | 107 | if ( punkte > ( *insertIterator )->points ) |
109 | { | 108 | { |
110 | t_playerData* temp = new t_playerData; | 109 | t_playerData* temp = new t_playerData; |
111 | temp->sName = name; | 110 | temp->sName = name; |
112 | temp->points = punkte; | 111 | temp->points = punkte; |
113 | temp->level = playerLevel; | 112 | temp->level = playerLevel; |
114 | playerData.insert( insertIterator , temp ); | 113 | playerData.insert( insertIterator , temp ); |
115 | 114 | ||
116 | //now we have to delete the last entry | 115 | //now we have to delete the last entry |
117 | insertIterator = playerData.end(); | 116 | insertIterator = playerData.end(); |
118 | insertIterator--; | 117 | insertIterator--; |
119 | //X delete *insertIterator; //memleak? | 118 | //X delete *insertIterator; //memleak? |
120 | playerData.erase( insertIterator ); | 119 | playerData.erase( insertIterator ); |
121 | 120 | ||
122 | ///////////////////////////////////////// | 121 | ///////////////////////////////////////// |
123 | //this block just rewrites the highscore | 122 | //this block just rewrites the highscore |
124 | insertIterator = playerData.begin(); | 123 | insertIterator = playerData.begin(); |
125 | while ( insertIterator != playerData.end() ) | 124 | while ( insertIterator != playerData.end() ) |
126 | { | 125 | { |
127 | cfg.setGroup( QString::number( entryNumber ) ); | 126 | cfg.setGroup( QString::number( entryNumber ) ); |
128 | cfg.writeEntry( "Name" , ( *insertIterator )->sName ); | 127 | cfg.writeEntry( "Name" , ( *insertIterator )->sName ); |
129 | cfg.writeEntry( "Points" , ( *insertIterator )->points ); | 128 | cfg.writeEntry( "Points" , ( *insertIterator )->points ); |
130 | cfg.writeEntry( "Level" , ( *insertIterator )->level ); | 129 | cfg.writeEntry( "Level" , ( *insertIterator )->level ); |
131 | entryNumber++; | 130 | entryNumber++; |
132 | insertIterator++; | 131 | insertIterator++; |
133 | } | 132 | } |
134 | //////////////////////////////////////// | 133 | //////////////////////////////////////// |
135 | 134 | ||
136 | return; | 135 | return; |
137 | } | 136 | } |
138 | insertIterator++; | 137 | insertIterator++; |
139 | } | 138 | } |
140 | } | 139 | } |
141 | 140 | ||
142 | QString OHighscore::getName() | 141 | QString OHighscore::getName() |
143 | { | 142 | { |
144 | QString name; | 143 | QString name; |
145 | QDialog *d = new QDialog ( this, 0, true ); | 144 | QDialog *d = new QDialog ( this, 0, true ); |
146 | d->setCaption( tr( "Enter your name!" )); | 145 | d->setCaption( tr( "Enter your name!" )); |
147 | QLineEdit *ed = new QLineEdit ( d ); | 146 | QLineEdit *ed = new QLineEdit ( d ); |
148 | ( new QVBoxLayout ( d, 3, 3 ))->addWidget ( ed ); | 147 | ( new QVBoxLayout ( d, 3, 3 ))->addWidget ( ed ); |
149 | ed->setFocus ( ); | 148 | ed->setFocus ( ); |
150 | 149 | ||
151 | if ( d->exec() == QDialog::Accepted ) { | 150 | if ( d->exec() == QDialog::Accepted ) { |
152 | name = ed->text(); | 151 | name = ed->text(); |
153 | } | 152 | } |
154 | //delete d; | 153 | //delete d; |
155 | return name; | 154 | return name; |
156 | } | 155 | } |
157 | 156 | ||
158 | OHighscoreDialog::OHighscoreDialog(OHighscore *highscore, QWidget *parent, const char *name, bool modal) : QDialog(parent, name, modal) | 157 | OHighscoreDialog::OHighscoreDialog(OHighscore *highscore, QWidget *parent, const char *name, bool modal) : QDialog(parent, name, modal) |
159 | { | 158 | { |
160 | hs_ = highscore; | 159 | hs_ = highscore; |
161 | setCaption( tr( "Highscores" ) ); | 160 | setCaption( tr( "Highscores" ) ); |
162 | vbox_layout = new QVBoxLayout( this, 4 , 4 ); | 161 | vbox_layout = new QVBoxLayout( this, 4 , 4 ); |
163 | list = new QListView( this ); | 162 | list = new QListView( this ); |
164 | list->setSorting( -1 ); | 163 | list->setSorting( -1 ); |
165 | list->addColumn( tr( "#" )); | 164 | list->addColumn( tr( "#" )); |
166 | list->addColumn( tr( "Name" )); | 165 | list->addColumn( tr( "Name" )); |
167 | list->addColumn( tr( "Points" )); | 166 | list->addColumn( tr( "Points" )); |
168 | list->addColumn( tr( "Level" )); | 167 | list->addColumn( tr( "Level" )); |
169 | 168 | ||
170 | createHighscoreListView(); | 169 | createHighscoreListView(); |
171 | 170 | ||
172 | vbox_layout->addWidget( list ); | 171 | vbox_layout->addWidget( list ); |
173 | QPEApplication::showDialog( this ); | 172 | QPEApplication::showDialog( this ); |
174 | } | 173 | } |
175 | 174 | ||
176 | void OHighscoreDialog::createHighscoreListView() | 175 | void OHighscoreDialog::createHighscoreListView() |
177 | { | 176 | { |
178 | int pos = 10; | 177 | int pos = 10; |
179 | int points_ = 0; | 178 | int points_ = 0; |
180 | int level_ = 0; | 179 | int level_ = 0; |
181 | 180 | ||
182 | std::list<t_playerData*>::reverse_iterator iListe = hs_->playerData.rbegin(); | 181 | std::list<t_playerData*>::reverse_iterator iListe = hs_->playerData.rbegin(); |
183 | 182 | ||
184 | for ( ; iListe != hs_->playerData.rend() ; ++iListe ) | 183 | for ( ; iListe != hs_->playerData.rend() ; ++iListe ) |
185 | { | 184 | { |
186 | QListViewItem *item = new QListViewItem( list ); | 185 | QListViewItem *item = new QListViewItem( list ); |
187 | item->setText( 0 , QString::number( pos ) ); //number | 186 | item->setText( 0 , QString::number( pos ) ); //number |
188 | item->setText( 1 , ( *iListe )->sName ); //name | 187 | item->setText( 1 , ( *iListe )->sName ); //name |
189 | if ( ( *iListe )->points == -1 ) | 188 | if ( ( *iListe )->points == -1 ) |
190 | points_ = 0; | 189 | points_ = 0; |
191 | else points_ = ( *iListe )->points; | 190 | else points_ = ( *iListe )->points; |
192 | if ( ( *iListe )->level == -1 ) | 191 | if ( ( *iListe )->level == -1 ) |
193 | level_ = 0; | 192 | level_ = 0; |
194 | else level_ = ( *iListe )->level; | 193 | else level_ = ( *iListe )->level; |
195 | item->setText( 2 , QString::number( points_ ) ); //points | 194 | item->setText( 2 , QString::number( points_ ) ); //points |
196 | item->setText( 3 , QString::number( level_ ) ); //level | 195 | item->setText( 3 , QString::number( level_ ) ); //level |
197 | pos--; | 196 | pos--; |
198 | } | 197 | } |
199 | } | 198 | } |
200 | 199 | ||
diff --git a/noncore/games/tetrix/qtetrix.cpp b/noncore/games/tetrix/qtetrix.cpp index 6d29c3f..20cf1a7 100644 --- a/noncore/games/tetrix/qtetrix.cpp +++ b/noncore/games/tetrix/qtetrix.cpp | |||
@@ -1,177 +1,174 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | 21 | ||
22 | #include "qtetrix.h" | 22 | #include "qtetrix.h" |
23 | 23 | ||
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | #include <qpe/config.h> | ||
26 | 25 | ||
27 | #include <qapplication.h> | ||
28 | #include <qlabel.h> | 26 | #include <qlabel.h> |
29 | #include <qdatetime.h> | 27 | #include <qdatetime.h> |
30 | #include <qlayout.h> | 28 | #include <qlayout.h> |
31 | #include <qstring.h> | ||
32 | 29 | ||
33 | #include "ohighscoredlg.h" | 30 | #include "ohighscoredlg.h" |
34 | 31 | ||
35 | 32 | ||
36 | void drawTetrixButton( QPainter *p, int x, int y, int w, int h, | 33 | void drawTetrixButton( QPainter *p, int x, int y, int w, int h, |
37 | const QColor *color ) | 34 | const QColor *color ) |
38 | { | 35 | { |
39 | QColor fc; | 36 | QColor fc; |
40 | if ( color ) { | 37 | if ( color ) { |
41 | QPointArray a; | 38 | QPointArray a; |
42 | a.setPoints( 3, x,y+h-1, x,y, x+w-1,y ); | 39 | a.setPoints( 3, x,y+h-1, x,y, x+w-1,y ); |
43 | p->setPen( color->light() ); | 40 | p->setPen( color->light() ); |
44 | p->drawPolyline( a ); | 41 | p->drawPolyline( a ); |
45 | a.setPoints( 3, x+1,y+h-1, x+w-1,y+h-1, x+w-1,y+1 ); | 42 | a.setPoints( 3, x+1,y+h-1, x+w-1,y+h-1, x+w-1,y+1 ); |
46 | p->setPen( color->dark() ); | 43 | p->setPen( color->dark() ); |
47 | p->drawPolyline( a ); | 44 | p->drawPolyline( a ); |
48 | x++; | 45 | x++; |
49 | y++; | 46 | y++; |
50 | w -= 2; | 47 | w -= 2; |
51 | h -= 2; | 48 | h -= 2; |
52 | fc = *color; | 49 | fc = *color; |
53 | } | 50 | } |
54 | else | 51 | else |
55 | fc = p->backgroundColor(); | 52 | fc = p->backgroundColor(); |
56 | p->fillRect( x, y, w, h, fc ); | 53 | p->fillRect( x, y, w, h, fc ); |
57 | } | 54 | } |
58 | 55 | ||
59 | 56 | ||
60 | ShowNextPiece::ShowNextPiece( QWidget *parent, const char *name ) | 57 | ShowNextPiece::ShowNextPiece( QWidget *parent, const char *name ) |
61 | : QFrame( parent, name ) | 58 | : QFrame( parent, name ) |
62 | { | 59 | { |
63 | setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 60 | setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
64 | xOffset = -1; // -1 until first resizeEvent. | 61 | xOffset = -1; // -1 until first resizeEvent. |
65 | } | 62 | } |
66 | 63 | ||
67 | void ShowNextPiece::resizeEvent( QResizeEvent *e ) | 64 | void ShowNextPiece::resizeEvent( QResizeEvent *e ) |
68 | { | 65 | { |
69 | QSize sz = e->size(); | 66 | QSize sz = e->size(); |
70 | blockWidth = (sz.width() - 3)/5; | 67 | blockWidth = (sz.width() - 3)/5; |
71 | blockHeight = (sz.height() - 3)/6; | 68 | blockHeight = (sz.height() - 3)/6; |
72 | xOffset = (sz.width() - 3)/5; | 69 | xOffset = (sz.width() - 3)/5; |
73 | yOffset = (sz.height() - 3)/6; | 70 | yOffset = (sz.height() - 3)/6; |
74 | } | 71 | } |
75 | 72 | ||
76 | 73 | ||
77 | void ShowNextPiece::paintEvent( QPaintEvent * ) | 74 | void ShowNextPiece::paintEvent( QPaintEvent * ) |
78 | { | 75 | { |
79 | QPainter p( this ); | 76 | QPainter p( this ); |
80 | drawFrame( &p ); | 77 | drawFrame( &p ); |
81 | p.end(); // explicit end() so any slots can paint too | 78 | p.end(); // explicit end() so any slots can paint too |
82 | emit update(); | 79 | emit update(); |
83 | } | 80 | } |
84 | 81 | ||
85 | 82 | ||
86 | void ShowNextPiece::drawNextSquare(int x, int y,QColor *color) | 83 | void ShowNextPiece::drawNextSquare(int x, int y,QColor *color) |
87 | { | 84 | { |
88 | if (xOffset == -1) // Before first resizeEvent? | 85 | if (xOffset == -1) // Before first resizeEvent? |
89 | return; | 86 | return; |
90 | 87 | ||
91 | QPainter paint; | 88 | QPainter paint; |
92 | paint.begin(this); | 89 | paint.begin(this); |
93 | drawTetrixButton( &paint, xOffset+x*blockWidth, yOffset+y*blockHeight, | 90 | drawTetrixButton( &paint, xOffset+x*blockWidth, yOffset+y*blockHeight, |
94 | blockWidth, blockHeight, color ); | 91 | blockWidth, blockHeight, color ); |
95 | paint.end(); | 92 | paint.end(); |
96 | } | 93 | } |
97 | 94 | ||
98 | 95 | ||
99 | QTetrix::QTetrix( QWidget *parent, const char *name, WFlags f ) | 96 | QTetrix::QTetrix( QWidget *parent, const char *name, WFlags f ) |
100 | : QMainWindow( parent, name, f ) | 97 | : QMainWindow( parent, name, f ) |
101 | { | 98 | { |
102 | setIcon( Resource::loadPixmap( "tetrix_icon" ) ); | 99 | setIcon( Resource::loadPixmap( "tetrix_icon" ) ); |
103 | setCaption( tr("Tetrix" ) ); | 100 | setCaption( tr("Tetrix" ) ); |
104 | 101 | ||
105 | QTime t = QTime::currentTime(); | 102 | QTime t = QTime::currentTime(); |
106 | TetrixPiece::setRandomSeed( (((double)t.hour())+t.minute()+t.second())/ | 103 | TetrixPiece::setRandomSeed( (((double)t.hour())+t.minute()+t.second())/ |
107 | (24+60+60) ); | 104 | (24+60+60) ); |
108 | 105 | ||
109 | QWidget *gameArea = new QWidget( this ); | 106 | QWidget *gameArea = new QWidget( this ); |
110 | setCentralWidget( gameArea ); | 107 | setCentralWidget( gameArea ); |
111 | 108 | ||
112 | QGridLayout *gl = new QGridLayout( gameArea, 5, 3, 8 ); | 109 | QGridLayout *gl = new QGridLayout( gameArea, 5, 3, 8 ); |
113 | 110 | ||
114 | QLabel *l; | 111 | QLabel *l; |
115 | l = new QLabel( tr("Next"), gameArea ); | 112 | l = new QLabel( tr("Next"), gameArea ); |
116 | gl->addWidget( l, 0, 0 ); | 113 | gl->addWidget( l, 0, 0 ); |
117 | showNext = new ShowNextPiece(gameArea); | 114 | showNext = new ShowNextPiece(gameArea); |
118 | showNext->setBackgroundColor(QColor(0,0,0)); | 115 | showNext->setBackgroundColor(QColor(0,0,0)); |
119 | gl->addWidget( showNext, 0, 1 ); | 116 | gl->addWidget( showNext, 0, 1 ); |
120 | 117 | ||
121 | l = new QLabel( tr("Score"), gameArea ); | 118 | l = new QLabel( tr("Score"), gameArea ); |
122 | gl->addWidget( l, 1, 0 ); | 119 | gl->addWidget( l, 1, 0 ); |
123 | showScore = new QLabel(gameArea); | 120 | showScore = new QLabel(gameArea); |
124 | gl->addWidget( showScore, 1, 1 ); | 121 | gl->addWidget( showScore, 1, 1 ); |
125 | l = new QLabel( tr("Level"), gameArea ); | 122 | l = new QLabel( tr("Level"), gameArea ); |
126 | gl->addWidget( l, 2, 0 ); | 123 | gl->addWidget( l, 2, 0 ); |
127 | showLevel = new QLabel(gameArea); | 124 | showLevel = new QLabel(gameArea); |
128 | gl->addWidget( showLevel, 2, 1 ); | 125 | gl->addWidget( showLevel, 2, 1 ); |
129 | l = new QLabel( tr("Removed"), gameArea ); | 126 | l = new QLabel( tr("Removed"), gameArea ); |
130 | gl->addWidget( l, 3, 0 ); | 127 | gl->addWidget( l, 3, 0 ); |
131 | showLines = new QLabel(gameArea); | 128 | showLines = new QLabel(gameArea); |
132 | gl->addWidget( showLines, 3, 1 ); | 129 | gl->addWidget( showLines, 3, 1 ); |
133 | 130 | ||
134 | board = new QTetrixBoard(gameArea); | 131 | board = new QTetrixBoard(gameArea); |
135 | board->setBackgroundColor(QColor(0,0,0)); | 132 | board->setBackgroundColor(QColor(0,0,0)); |
136 | board->setFixedWidth( 124 ); | 133 | board->setFixedWidth( 124 ); |
137 | gl->addMultiCellWidget( board, 0, 4, 2, 2 ); | 134 | gl->addMultiCellWidget( board, 0, 4, 2, 2 ); |
138 | gl->addColSpacing( 2, 100 ); | 135 | gl->addColSpacing( 2, 100 ); |
139 | gl->addColSpacing( 1, 35 ); | 136 | gl->addColSpacing( 1, 35 ); |
140 | gl->addRowSpacing( 0, 35 ); | 137 | gl->addRowSpacing( 0, 35 ); |
141 | 138 | ||
142 | QPushButton *pb = new QPushButton( tr("Start"), gameArea ); | 139 | QPushButton *pb = new QPushButton( tr("Start"), gameArea ); |
143 | pb->setFocusPolicy( NoFocus ); | 140 | pb->setFocusPolicy( NoFocus ); |
144 | connect( pb, SIGNAL( clicked() ), board, SLOT( start() ) ); | 141 | connect( pb, SIGNAL( clicked() ), board, SLOT( start() ) ); |
145 | gl->addMultiCellWidget( pb, 4, 4, 0, 1 ); | 142 | gl->addMultiCellWidget( pb, 4, 4, 0, 1 ); |
146 | 143 | ||
147 | connect( board, SIGNAL(gameOverSignal()), SLOT(gameOver()) ); | 144 | connect( board, SIGNAL(gameOverSignal()), SLOT(gameOver()) ); |
148 | connect( board, SIGNAL(drawNextSquareSignal(int,int,QColor*)), showNext, | 145 | connect( board, SIGNAL(drawNextSquareSignal(int,int,QColor*)), showNext, |
149 | SLOT(drawNextSquare(int,int,QColor*)) ); | 146 | SLOT(drawNextSquare(int,int,QColor*)) ); |
150 | connect( showNext, SIGNAL(update()), board, SLOT(updateNext()) ); | 147 | connect( showNext, SIGNAL(update()), board, SLOT(updateNext()) ); |
151 | connect( board, SIGNAL(updateScoreSignal(int)), showScore, | 148 | connect( board, SIGNAL(updateScoreSignal(int)), showScore, |
152 | SLOT(setNum(int)) ); | 149 | SLOT(setNum(int)) ); |
153 | connect( board, SIGNAL(updateLevelSignal(int)), showLevel, | 150 | connect( board, SIGNAL(updateLevelSignal(int)), showLevel, |
154 | SLOT(setNum(int))); | 151 | SLOT(setNum(int))); |
155 | connect( board, SIGNAL(updateRemovedSignal(int)), showLines, | 152 | connect( board, SIGNAL(updateRemovedSignal(int)), showLines, |
156 | SLOT(setNum(int))); | 153 | SLOT(setNum(int))); |
157 | 154 | ||
158 | showScore->setNum( 0 ); | 155 | showScore->setNum( 0 ); |
159 | showLevel->setNum( 0 ); | 156 | showLevel->setNum( 0 ); |
160 | showLines->setNum( 0 ); | 157 | showLines->setNum( 0 ); |
161 | board->revealNextPiece(TRUE); | 158 | board->revealNextPiece(TRUE); |
162 | board->setFocusPolicy( StrongFocus ); | 159 | board->setFocusPolicy( StrongFocus ); |
163 | } | 160 | } |
164 | 161 | ||
165 | void QTetrix::gameOver() | 162 | void QTetrix::gameOver() |
166 | { | 163 | { |
167 | OHighscore *hs = new OHighscore( showScore->text().toInt() , showLevel->text().toInt() ); | 164 | OHighscore *hs = new OHighscore( showScore->text().toInt() , showLevel->text().toInt() ); |
168 | if ( hs->isNewhighscore ) | 165 | if ( hs->isNewhighscore ) |
169 | hs->insertData( hs->getName(), showScore->text().toInt() , showLevel->text().toInt() ); | 166 | hs->insertData( hs->getName(), showScore->text().toInt() , showLevel->text().toInt() ); |
170 | OHighscoreDialog hscdlg( hs, this, "OHighscoreDialog", true ); | 167 | OHighscoreDialog hscdlg( hs, this, "OHighscoreDialog", true ); |
171 | hscdlg.exec(); | 168 | hscdlg.exec(); |
172 | } | 169 | } |
173 | 170 | ||
174 | void QTetrix::quit() | 171 | void QTetrix::quit() |
175 | { | 172 | { |
176 | close(); | 173 | close(); |
177 | } | 174 | } |
diff --git a/noncore/games/tetrix/qtetrixb.cpp b/noncore/games/tetrix/qtetrixb.cpp index 521f171..3c179df 100644 --- a/noncore/games/tetrix/qtetrixb.cpp +++ b/noncore/games/tetrix/qtetrixb.cpp | |||
@@ -1,251 +1,249 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | 21 | ||
22 | #include "qtetrixb.h" | 22 | #include "qtetrixb.h" |
23 | #include "qtetrix.h" | 23 | #include "qtetrix.h" |
24 | #include <qtimer.h> | 24 | #include <qtimer.h> |
25 | #include <qkeycode.h> | ||
26 | #include <qpainter.h> | ||
27 | 25 | ||
28 | const int waitAfterLineTime = 500; | 26 | const int waitAfterLineTime = 500; |
29 | 27 | ||
30 | QTetrixBoard::QTetrixBoard( QWidget *p, const char *name ) | 28 | QTetrixBoard::QTetrixBoard( QWidget *p, const char *name ) |
31 | : QFrame( p, name ) | 29 | : QFrame( p, name ) |
32 | { | 30 | { |
33 | setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 31 | setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
34 | paint = 0; | 32 | paint = 0; |
35 | timer = new QTimer(this); | 33 | timer = new QTimer(this); |
36 | connect( timer, SIGNAL(timeout()), SLOT(timeout()) ); | 34 | connect( timer, SIGNAL(timeout()), SLOT(timeout()) ); |
37 | 35 | ||
38 | colors[0].setRgb(200,100,100); | 36 | colors[0].setRgb(200,100,100); |
39 | colors[1].setRgb(100,200,100); | 37 | colors[1].setRgb(100,200,100); |
40 | colors[2].setRgb(100,100,200); | 38 | colors[2].setRgb(100,100,200); |
41 | colors[3].setRgb(200,200,100); | 39 | colors[3].setRgb(200,200,100); |
42 | colors[4].setRgb(200,100,200); | 40 | colors[4].setRgb(200,100,200); |
43 | colors[5].setRgb(100,200,200); | 41 | colors[5].setRgb(100,200,200); |
44 | colors[6].setRgb(218,170, 0); | 42 | colors[6].setRgb(218,170, 0); |
45 | 43 | ||
46 | xOffset = -1; // -1 until a resizeEvent is received. | 44 | xOffset = -1; // -1 until a resizeEvent is received. |
47 | blockWidth = 20; | 45 | blockWidth = 20; |
48 | yOffset = 30; | 46 | yOffset = 30; |
49 | blockHeight = 20; | 47 | blockHeight = 20; |
50 | noGame = TRUE; | 48 | noGame = TRUE; |
51 | isPaused = FALSE; | 49 | isPaused = FALSE; |
52 | waitingAfterLine = FALSE; | 50 | waitingAfterLine = FALSE; |
53 | updateTimeoutTime(); // Sets timeoutTime | 51 | updateTimeoutTime(); // Sets timeoutTime |
54 | } | 52 | } |
55 | 53 | ||
56 | void QTetrixBoard::startGame(int gameType,int fillRandomLines) | 54 | void QTetrixBoard::startGame(int gameType,int fillRandomLines) |
57 | { | 55 | { |
58 | if ( isPaused ) | 56 | if ( isPaused ) |
59 | return; // ignore if game is paused | 57 | return; // ignore if game is paused |
60 | noGame = FALSE; | 58 | noGame = FALSE; |
61 | GenericTetrix::startGame( gameType, fillRandomLines ); | 59 | GenericTetrix::startGame( gameType, fillRandomLines ); |
62 | // Note that the timer is started by updateLevel! | 60 | // Note that the timer is started by updateLevel! |
63 | } | 61 | } |
64 | 62 | ||
65 | 63 | ||
66 | void QTetrixBoard::pause() | 64 | void QTetrixBoard::pause() |
67 | { | 65 | { |
68 | if ( noGame ) // game not active | 66 | if ( noGame ) // game not active |
69 | return; | 67 | return; |
70 | isPaused = !isPaused; | 68 | isPaused = !isPaused; |
71 | if ( isPaused ) { | 69 | if ( isPaused ) { |
72 | timer->stop(); | 70 | timer->stop(); |
73 | hideBoard(); | 71 | hideBoard(); |
74 | } | 72 | } |
75 | else | 73 | else |
76 | timer->start(timeoutTime); | 74 | timer->start(timeoutTime); |
77 | update(); | 75 | update(); |
78 | } | 76 | } |
79 | 77 | ||
80 | 78 | ||
81 | void QTetrixBoard::drawSquare(int x,int y,int value) | 79 | void QTetrixBoard::drawSquare(int x,int y,int value) |
82 | { | 80 | { |
83 | if (xOffset == -1) // Before first resizeEvent? | 81 | if (xOffset == -1) // Before first resizeEvent? |
84 | return; | 82 | return; |
85 | 83 | ||
86 | const int X = xOffset + x*blockWidth; | 84 | const int X = xOffset + x*blockWidth; |
87 | const int Y = yOffset + (y - 1)*blockHeight; | 85 | const int Y = yOffset + (y - 1)*blockHeight; |
88 | 86 | ||
89 | bool localPainter = paint == 0; | 87 | bool localPainter = paint == 0; |
90 | QPainter *p; | 88 | QPainter *p; |
91 | if ( localPainter ) | 89 | if ( localPainter ) |
92 | p = new QPainter( this ); | 90 | p = new QPainter( this ); |
93 | else | 91 | else |
94 | p = paint; | 92 | p = paint; |
95 | drawTetrixButton( p, X, Y, blockWidth, blockHeight, | 93 | drawTetrixButton( p, X, Y, blockWidth, blockHeight, |
96 | value == 0 ? 0 : &colors[value-1] ); | 94 | value == 0 ? 0 : &colors[value-1] ); |
97 | /* | 95 | /* |
98 | if ( value != 0 ) { | 96 | if ( value != 0 ) { |
99 | QColor tc, bc; | 97 | QColor tc, bc; |
100 | tc = colors[value-1].light(); | 98 | tc = colors[value-1].light(); |
101 | bc = colors[value-1].dark(); | 99 | bc = colors[value-1].dark(); |
102 | p->drawShadePanel( X, Y, blockWidth, blockHeight, | 100 | p->drawShadePanel( X, Y, blockWidth, blockHeight, |
103 | tc, bc, 1, colors[value-1], TRUE ); | 101 | tc, bc, 1, colors[value-1], TRUE ); |
104 | } | 102 | } |
105 | else | 103 | else |
106 | p->fillRect( X, Y, blockWidth, blockHeight, backgroundColor() ); | 104 | p->fillRect( X, Y, blockWidth, blockHeight, backgroundColor() ); |
107 | */ | 105 | */ |
108 | if ( localPainter ) | 106 | if ( localPainter ) |
109 | delete p; | 107 | delete p; |
110 | } | 108 | } |
111 | 109 | ||
112 | void QTetrixBoard::drawNextSquare( int x, int y, int value ) | 110 | void QTetrixBoard::drawNextSquare( int x, int y, int value ) |
113 | { | 111 | { |
114 | if ( value == 0 ) | 112 | if ( value == 0 ) |
115 | emit drawNextSquareSignal (x, y, 0 ); | 113 | emit drawNextSquareSignal (x, y, 0 ); |
116 | else | 114 | else |
117 | emit drawNextSquareSignal( x, y, &colors[value-1] ); | 115 | emit drawNextSquareSignal( x, y, &colors[value-1] ); |
118 | } | 116 | } |
119 | 117 | ||
120 | void QTetrixBoard::updateRemoved( int noOfLines ) | 118 | void QTetrixBoard::updateRemoved( int noOfLines ) |
121 | { | 119 | { |
122 | if ( noOfLines > 0 ) { | 120 | if ( noOfLines > 0 ) { |
123 | timer->stop(); | 121 | timer->stop(); |
124 | timer->start( waitAfterLineTime ); | 122 | timer->start( waitAfterLineTime ); |
125 | waitingAfterLine = TRUE; | 123 | waitingAfterLine = TRUE; |
126 | } | 124 | } |
127 | emit updateRemovedSignal( noOfLines ); | 125 | emit updateRemovedSignal( noOfLines ); |
128 | } | 126 | } |
129 | 127 | ||
130 | void QTetrixBoard::updateScore( int newScore ) | 128 | void QTetrixBoard::updateScore( int newScore ) |
131 | { | 129 | { |
132 | emit updateScoreSignal( newScore ); | 130 | emit updateScoreSignal( newScore ); |
133 | } | 131 | } |
134 | 132 | ||
135 | void QTetrixBoard::updateLevel( int newLevel ) | 133 | void QTetrixBoard::updateLevel( int newLevel ) |
136 | { | 134 | { |
137 | timer->stop(); | 135 | timer->stop(); |
138 | updateTimeoutTime(); | 136 | updateTimeoutTime(); |
139 | timer->start( timeoutTime ); | 137 | timer->start( timeoutTime ); |
140 | emit updateLevelSignal( newLevel ); | 138 | emit updateLevelSignal( newLevel ); |
141 | } | 139 | } |
142 | 140 | ||
143 | void QTetrixBoard::pieceDropped(int) | 141 | void QTetrixBoard::pieceDropped(int) |
144 | { | 142 | { |
145 | if ( waitingAfterLine ) // give player a break if a line has been removed | 143 | if ( waitingAfterLine ) // give player a break if a line has been removed |
146 | return; | 144 | return; |
147 | newPiece(); | 145 | newPiece(); |
148 | } | 146 | } |
149 | 147 | ||
150 | void QTetrixBoard::gameOver() | 148 | void QTetrixBoard::gameOver() |
151 | { | 149 | { |
152 | timer->stop(); | 150 | timer->stop(); |
153 | noGame = TRUE; | 151 | noGame = TRUE; |
154 | emit gameOverSignal(); | 152 | emit gameOverSignal(); |
155 | } | 153 | } |
156 | 154 | ||
157 | void QTetrixBoard::timeout() | 155 | void QTetrixBoard::timeout() |
158 | { | 156 | { |
159 | if ( waitingAfterLine ) { | 157 | if ( waitingAfterLine ) { |
160 | timer->stop(); | 158 | timer->stop(); |
161 | waitingAfterLine = FALSE; | 159 | waitingAfterLine = FALSE; |
162 | newPiece(); | 160 | newPiece(); |
163 | timer->start( timeoutTime ); | 161 | timer->start( timeoutTime ); |
164 | } else { | 162 | } else { |
165 | oneLineDown(); | 163 | oneLineDown(); |
166 | } | 164 | } |
167 | } | 165 | } |
168 | 166 | ||
169 | void QTetrixBoard::drawContents( QPainter *p ) | 167 | void QTetrixBoard::drawContents( QPainter *p ) |
170 | { | 168 | { |
171 | const char *text = "Press \"Pause\""; | 169 | const char *text = "Press \"Pause\""; |
172 | QRect r = contentsRect(); | 170 | QRect r = contentsRect(); |
173 | paint = p; // set widget painter | 171 | paint = p; // set widget painter |
174 | if ( isPaused ) { | 172 | if ( isPaused ) { |
175 | p->drawText( r, AlignCenter | AlignVCenter, text ); | 173 | p->drawText( r, AlignCenter | AlignVCenter, text ); |
176 | return; | 174 | return; |
177 | } | 175 | } |
178 | int x1,y1,x2,y2; | 176 | int x1,y1,x2,y2; |
179 | x1 = (r.left() - xOffset) / blockWidth; | 177 | x1 = (r.left() - xOffset) / blockWidth; |
180 | if (x1 < 0) | 178 | if (x1 < 0) |
181 | x1 = 0; | 179 | x1 = 0; |
182 | if (x1 >= boardWidth()) | 180 | if (x1 >= boardWidth()) |
183 | x1 = boardWidth() - 1; | 181 | x1 = boardWidth() - 1; |
184 | 182 | ||
185 | x2 = (r.right() - xOffset) / blockWidth; | 183 | x2 = (r.right() - xOffset) / blockWidth; |
186 | if (x2 < 0) | 184 | if (x2 < 0) |
187 | x2 = 0; | 185 | x2 = 0; |
188 | if (x2 >= boardWidth()) | 186 | if (x2 >= boardWidth()) |
189 | x2 = boardWidth() - 1; | 187 | x2 = boardWidth() - 1; |
190 | 188 | ||
191 | y1 = (r.top() - yOffset) / blockHeight; | 189 | y1 = (r.top() - yOffset) / blockHeight; |
192 | if (y1 < 0) | 190 | if (y1 < 0) |
193 | y1 = 0; | 191 | y1 = 0; |
194 | if (y1 >= boardHeight()) | 192 | if (y1 >= boardHeight()) |
195 | y1 = boardHeight() - 1; | 193 | y1 = boardHeight() - 1; |
196 | 194 | ||
197 | y2 = (r.bottom() - yOffset) / blockHeight; | 195 | y2 = (r.bottom() - yOffset) / blockHeight; |
198 | if (y2 < 0) | 196 | if (y2 < 0) |
199 | y2 = 0; | 197 | y2 = 0; |
200 | if (y2 >= boardHeight()) | 198 | if (y2 >= boardHeight()) |
201 | y2 = boardHeight() - 1; | 199 | y2 = boardHeight() - 1; |
202 | 200 | ||
203 | updateBoard( x1, y1, x2, y2, TRUE ); | 201 | updateBoard( x1, y1, x2, y2, TRUE ); |
204 | paint = 0; // reset widget painter | 202 | paint = 0; // reset widget painter |
205 | return; | 203 | return; |
206 | } | 204 | } |
207 | 205 | ||
208 | void QTetrixBoard::resizeEvent(QResizeEvent *e) | 206 | void QTetrixBoard::resizeEvent(QResizeEvent *e) |
209 | { | 207 | { |
210 | QSize sz = e->size(); | 208 | QSize sz = e->size(); |
211 | blockWidth = (sz.width() - 2)/10; | 209 | blockWidth = (sz.width() - 2)/10; |
212 | blockHeight = (sz.height() - 2)/22; | 210 | blockHeight = (sz.height() - 2)/22; |
213 | xOffset = 1; | 211 | xOffset = 1; |
214 | //yOffset = 1; | 212 | //yOffset = 1; |
215 | yOffset = (sz.height() - 2) - (blockHeight *22); | 213 | yOffset = (sz.height() - 2) - (blockHeight *22); |
216 | } | 214 | } |
217 | 215 | ||
218 | void QTetrixBoard::keyPressEvent( QKeyEvent *e ) | 216 | void QTetrixBoard::keyPressEvent( QKeyEvent *e ) |
219 | { | 217 | { |
220 | if ( noGame || isPaused || waitingAfterLine ) | 218 | if ( noGame || isPaused || waitingAfterLine ) |
221 | return; | 219 | return; |
222 | switch( e->key() ) { | 220 | switch( e->key() ) { |
223 | case Key_Left : | 221 | case Key_Left : |
224 | moveLeft(); | 222 | moveLeft(); |
225 | break; | 223 | break; |
226 | case Key_Right : | 224 | case Key_Right : |
227 | moveRight(); | 225 | moveRight(); |
228 | break; | 226 | break; |
229 | case Key_Down : | 227 | case Key_Down : |
230 | // rotateRight(); | 228 | // rotateRight(); |
231 | dropDown(); | 229 | dropDown(); |
232 | break; | 230 | break; |
233 | case Key_Up : | 231 | case Key_Up : |
234 | rotateLeft(); | 232 | rotateLeft(); |
235 | break; | 233 | break; |
236 | case Key_Space : | 234 | case Key_Space : |
237 | dropDown(); | 235 | dropDown(); |
238 | break; | 236 | break; |
239 | case Key_D : | 237 | case Key_D : |
240 | oneLineDown(); | 238 | oneLineDown(); |
241 | break; | 239 | break; |
242 | default: | 240 | default: |
243 | return; | 241 | return; |
244 | } | 242 | } |
245 | e->accept(); | 243 | e->accept(); |
246 | } | 244 | } |
247 | 245 | ||
248 | void QTetrixBoard::updateTimeoutTime() | 246 | void QTetrixBoard::updateTimeoutTime() |
249 | { | 247 | { |
250 | timeoutTime = 1000/(1 + getLevel()); | 248 | timeoutTime = 1000/(1 + getLevel()); |
251 | } | 249 | } |
diff --git a/noncore/games/tictac/main.cpp b/noncore/games/tictac/main.cpp index cfff683..9aafe4c 100644 --- a/noncore/games/tictac/main.cpp +++ b/noncore/games/tictac/main.cpp | |||
@@ -1,13 +1,12 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of an example program for Qt. This example | 4 | ** This file is part of an example program for Qt. This example |
5 | ** program may be used, distributed and modified without limitation. | 5 | ** program may be used, distributed and modified without limitation. |
6 | ** | 6 | ** |
7 | *****************************************************************************/ | 7 | *****************************************************************************/ |
8 | 8 | ||
9 | #include <qpe/qpeapplication.h> | ||
10 | #include <opie/oapplicationfactory.h> | 9 | #include <opie/oapplicationfactory.h> |
11 | #include "tictac.h" | 10 | #include "tictac.h" |
12 | 11 | ||
13 | OPIE_EXPORT_APP( OApplicationFactory<TicTacToe> ) | 12 | OPIE_EXPORT_APP( OApplicationFactory<TicTacToe> ) |
diff --git a/noncore/games/tictac/tictac.cpp b/noncore/games/tictac/tictac.cpp index 9de3b58..12ce35f 100644 --- a/noncore/games/tictac/tictac.cpp +++ b/noncore/games/tictac/tictac.cpp | |||
@@ -1,382 +1,378 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | ** tictac.cpp,v 1.3.8.1 2003/08/29 06:50:40 harlekin Exp | 2 | ** tictac.cpp,v 1.3.8.1 2003/08/29 06:50:40 harlekin Exp |
3 | ** | 3 | ** |
4 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. | 4 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. |
5 | ** | 5 | ** |
6 | ** This file is part of an example program for Qt. This example | 6 | ** This file is part of an example program for Qt. This example |
7 | ** program may be used, distributed and modified without limitation. | 7 | ** program may be used, distributed and modified without limitation. |
8 | ** | 8 | ** |
9 | *****************************************************************************/ | 9 | *****************************************************************************/ |
10 | 10 | ||
11 | #include "tictac.h" | 11 | #include "tictac.h" |
12 | #include <qpe/qpeapplication.h> | 12 | #include <qpe/qpeapplication.h> |
13 | #include <qpainter.h> | ||
14 | #include <qdrawutil.h> | 13 | #include <qdrawutil.h> |
15 | #include <qcombobox.h> | 14 | #include <qcombobox.h> |
16 | #include <qcheckbox.h> | ||
17 | #include <qlabel.h> | 15 | #include <qlabel.h> |
18 | #include <qlayout.h> | 16 | #include <qlayout.h> |
19 | #include <stdlib.h> // rand() function | 17 | #include <stdlib.h> // rand() function |
20 | #include <qdatetime.h> // seed for rand() | ||
21 | #include <qstringlist.h> //needed for proper internationalization | ||
22 | 18 | ||
23 | 19 | ||
24 | //*************************************************************************** | 20 | //*************************************************************************** |
25 | //* TicTacButton member functions | 21 | //* TicTacButton member functions |
26 | //*************************************************************************** | 22 | //*************************************************************************** |
27 | 23 | ||
28 | // -------------------------------------------------------------------------- | 24 | // -------------------------------------------------------------------------- |
29 | // Creates a TicTacButton | 25 | // Creates a TicTacButton |
30 | // | 26 | // |
31 | 27 | ||
32 | TicTacButton::TicTacButton( QWidget *parent ) : QPushButton( parent ) | 28 | TicTacButton::TicTacButton( QWidget *parent ) : QPushButton( parent ) |
33 | { | 29 | { |
34 | t = Blank; // initial type | 30 | t = Blank; // initial type |
35 | } | 31 | } |
36 | 32 | ||
37 | // -------------------------------------------------------------------------- | 33 | // -------------------------------------------------------------------------- |
38 | // Paints TicTacButton | 34 | // Paints TicTacButton |
39 | // | 35 | // |
40 | 36 | ||
41 | void TicTacButton::drawButtonLabel( QPainter *p ) | 37 | void TicTacButton::drawButtonLabel( QPainter *p ) |
42 | { | 38 | { |
43 | QRect r = rect(); | 39 | QRect r = rect(); |
44 | p->setPen( QPen( white,2 ) ); // set fat pen | 40 | p->setPen( QPen( white,2 ) ); // set fat pen |
45 | if ( t == Circle ) { | 41 | if ( t == Circle ) { |
46 | p->drawEllipse( r.left()+4, r.top()+4, r.width()-8, r.height()-8 ); | 42 | p->drawEllipse( r.left()+4, r.top()+4, r.width()-8, r.height()-8 ); |
47 | } else if ( t == Cross ) { // draw cross | 43 | } else if ( t == Cross ) { // draw cross |
48 | p->drawLine( r.topLeft() +QPoint(4,4), r.bottomRight()-QPoint(4,4)); | 44 | p->drawLine( r.topLeft() +QPoint(4,4), r.bottomRight()-QPoint(4,4)); |
49 | p->drawLine( r.bottomLeft()+QPoint(4,-4),r.topRight() -QPoint(4,-4)); | 45 | p->drawLine( r.bottomLeft()+QPoint(4,-4),r.topRight() -QPoint(4,-4)); |
50 | } | 46 | } |
51 | } | 47 | } |
52 | 48 | ||
53 | 49 | ||
54 | //*************************************************************************** | 50 | //*************************************************************************** |
55 | //* TicTacGameBoard member functions | 51 | //* TicTacGameBoard member functions |
56 | //*************************************************************************** | 52 | //*************************************************************************** |
57 | 53 | ||
58 | // -------------------------------------------------------------------------- | 54 | // -------------------------------------------------------------------------- |
59 | // Creates a game board with N x N buttons and connects the "clicked()" | 55 | // Creates a game board with N x N buttons and connects the "clicked()" |
60 | // signal of all buttons to the "buttonClicked()" slot. | 56 | // signal of all buttons to the "buttonClicked()" slot. |
61 | // | 57 | // |
62 | 58 | ||
63 | TicTacGameBoard::TicTacGameBoard( int n, QWidget *parent, const char *name ) | 59 | TicTacGameBoard::TicTacGameBoard( int n, QWidget *parent, const char *name ) |
64 | : QWidget( parent, name ) | 60 | : QWidget( parent, name ) |
65 | { | 61 | { |
66 | QPEApplication::showWidget( this ); | 62 | QPEApplication::showWidget( this ); |
67 | st = Init; // initial state | 63 | st = Init; // initial state |
68 | nBoard = n; | 64 | nBoard = n; |
69 | n *= n; // make square | 65 | n *= n; // make square |
70 | comp_starts = FALSE; // human starts | 66 | comp_starts = FALSE; // human starts |
71 | buttons = new TicTacButtons(n); // create real buttons | 67 | buttons = new TicTacButtons(n); // create real buttons |
72 | btArray = new TicTacArray(n); // create button model | 68 | btArray = new TicTacArray(n); // create button model |
73 | QGridLayout * grid = new QGridLayout( this, 3, 3, 4 ); | 69 | QGridLayout * grid = new QGridLayout( this, 3, 3, 4 ); |
74 | QPalette p( blue ); | 70 | QPalette p( blue ); |
75 | for ( int i=0; i<n; i++ ) { // create and connect buttons | 71 | for ( int i=0; i<n; i++ ) { // create and connect buttons |
76 | TicTacButton *ttb = new TicTacButton( this ); | 72 | TicTacButton *ttb = new TicTacButton( this ); |
77 | ttb->setPalette( p ); | 73 | ttb->setPalette( p ); |
78 | ttb->setEnabled( FALSE ); | 74 | ttb->setEnabled( FALSE ); |
79 | connect( ttb, SIGNAL(clicked()), SLOT(buttonClicked()) ); | 75 | connect( ttb, SIGNAL(clicked()), SLOT(buttonClicked()) ); |
80 | grid->addWidget( ttb, i%3, i/3 ); | 76 | grid->addWidget( ttb, i%3, i/3 ); |
81 | buttons->insert( i, ttb ); | 77 | buttons->insert( i, ttb ); |
82 | btArray->at(i) = TicTacButton::Blank; // initial button type | 78 | btArray->at(i) = TicTacButton::Blank; // initial button type |
83 | } | 79 | } |
84 | QTime t = QTime::currentTime(); // set random seed | 80 | QTime t = QTime::currentTime(); // set random seed |
85 | srand( t.hour()*12+t.minute()*60+t.second()*60 ); | 81 | srand( t.hour()*12+t.minute()*60+t.second()*60 ); |
86 | } | 82 | } |
87 | 83 | ||
88 | TicTacGameBoard::~TicTacGameBoard() | 84 | TicTacGameBoard::~TicTacGameBoard() |
89 | { | 85 | { |
90 | delete buttons; | 86 | delete buttons; |
91 | delete btArray; | 87 | delete btArray; |
92 | } | 88 | } |
93 | 89 | ||
94 | 90 | ||
95 | // -------------------------------------------------------------------------- | 91 | // -------------------------------------------------------------------------- |
96 | // TicTacGameBoard::computerStarts( bool v ) | 92 | // TicTacGameBoard::computerStarts( bool v ) |
97 | // | 93 | // |
98 | // Computer starts if v=TRUE. The human starts by default. | 94 | // Computer starts if v=TRUE. The human starts by default. |
99 | // | 95 | // |
100 | 96 | ||
101 | void TicTacGameBoard::computerStarts( bool v ) | 97 | void TicTacGameBoard::computerStarts( bool v ) |
102 | { | 98 | { |
103 | comp_starts = v; | 99 | comp_starts = v; |
104 | } | 100 | } |
105 | 101 | ||
106 | 102 | ||
107 | // -------------------------------------------------------------------------- | 103 | // -------------------------------------------------------------------------- |
108 | // TicTacGameBoard::newGame() | 104 | // TicTacGameBoard::newGame() |
109 | // | 105 | // |
110 | // Clears the game board and prepares for a new game | 106 | // Clears the game board and prepares for a new game |
111 | // | 107 | // |
112 | 108 | ||
113 | void TicTacGameBoard::newGame() | 109 | void TicTacGameBoard::newGame() |
114 | { | 110 | { |
115 | st = HumansTurn; | 111 | st = HumansTurn; |
116 | for ( int i=0; i<nBoard*nBoard; i++ ) | 112 | for ( int i=0; i<nBoard*nBoard; i++ ) |
117 | btArray->at(i) = TicTacButton::Blank; | 113 | btArray->at(i) = TicTacButton::Blank; |
118 | if ( comp_starts ) | 114 | if ( comp_starts ) |
119 | computerMove(); | 115 | computerMove(); |
120 | else | 116 | else |
121 | updateButtons(); | 117 | updateButtons(); |
122 | } | 118 | } |
123 | 119 | ||
124 | 120 | ||
125 | // -------------------------------------------------------------------------- | 121 | // -------------------------------------------------------------------------- |
126 | // TicTacGameBoard::buttonClicked() - SLOT | 122 | // TicTacGameBoard::buttonClicked() - SLOT |
127 | // | 123 | // |
128 | // This slot is activated when a TicTacButton emits the signal "clicked()", | 124 | // This slot is activated when a TicTacButton emits the signal "clicked()", |
129 | // i.e. the user has clicked on a TicTacButton. | 125 | // i.e. the user has clicked on a TicTacButton. |
130 | // | 126 | // |
131 | 127 | ||
132 | void TicTacGameBoard::buttonClicked() | 128 | void TicTacGameBoard::buttonClicked() |
133 | { | 129 | { |
134 | if ( st != HumansTurn ) // not ready | 130 | if ( st != HumansTurn ) // not ready |
135 | return; | 131 | return; |
136 | int i = buttons->findRef( (TicTacButton*)sender() ); | 132 | int i = buttons->findRef( (TicTacButton*)sender() ); |
137 | TicTacButton *b = buttons->at(i); // get piece that was pressed | 133 | TicTacButton *b = buttons->at(i); // get piece that was pressed |
138 | if ( b->type() == TicTacButton::Blank ) { // empty piece? | 134 | if ( b->type() == TicTacButton::Blank ) { // empty piece? |
139 | btArray->at(i) = TicTacButton::Circle; | 135 | btArray->at(i) = TicTacButton::Circle; |
140 | updateButtons(); | 136 | updateButtons(); |
141 | if ( checkBoard( btArray ) == 0 ) // not a winning move? | 137 | if ( checkBoard( btArray ) == 0 ) // not a winning move? |
142 | computerMove(); | 138 | computerMove(); |
143 | int s = checkBoard( btArray ); | 139 | int s = checkBoard( btArray ); |
144 | if ( s ) { // any winners yet? | 140 | if ( s ) { // any winners yet? |
145 | st = s == TicTacButton::Circle ? HumanWon : ComputerWon; | 141 | st = s == TicTacButton::Circle ? HumanWon : ComputerWon; |
146 | emit finished(); | 142 | emit finished(); |
147 | } | 143 | } |
148 | } | 144 | } |
149 | } | 145 | } |
150 | 146 | ||
151 | 147 | ||
152 | // -------------------------------------------------------------------------- | 148 | // -------------------------------------------------------------------------- |
153 | // TicTacGameBoard::updateButtons() | 149 | // TicTacGameBoard::updateButtons() |
154 | // | 150 | // |
155 | // Updates all buttons that have changed state | 151 | // Updates all buttons that have changed state |
156 | // | 152 | // |
157 | 153 | ||
158 | void TicTacGameBoard::updateButtons() | 154 | void TicTacGameBoard::updateButtons() |
159 | { | 155 | { |
160 | for ( int i=0; i<nBoard*nBoard; i++ ) { | 156 | for ( int i=0; i<nBoard*nBoard; i++ ) { |
161 | if ( buttons->at(i)->type() != btArray->at(i) ) | 157 | if ( buttons->at(i)->type() != btArray->at(i) ) |
162 | buttons->at(i)->setType( (TicTacButton::Type)btArray->at(i) ); | 158 | buttons->at(i)->setType( (TicTacButton::Type)btArray->at(i) ); |
163 | buttons->at(i)->setEnabled( buttons->at(i)->type() == | 159 | buttons->at(i)->setEnabled( buttons->at(i)->type() == |
164 | TicTacButton::Blank ); | 160 | TicTacButton::Blank ); |
165 | } | 161 | } |
166 | } | 162 | } |
167 | 163 | ||
168 | 164 | ||
169 | // -------------------------------------------------------------------------- | 165 | // -------------------------------------------------------------------------- |
170 | // TicTacGameBoard::checkBoard() | 166 | // TicTacGameBoard::checkBoard() |
171 | // | 167 | // |
172 | // Checks if one of the players won the game, works for any board size. | 168 | // Checks if one of the players won the game, works for any board size. |
173 | // | 169 | // |
174 | // Returns: | 170 | // Returns: |
175 | // - TicTacButton::Cross if the player with X buttons won | 171 | // - TicTacButton::Cross if the player with X buttons won |
176 | // - TicTacButton::Circle if the player with O buttons won | 172 | // - TicTacButton::Circle if the player with O buttons won |
177 | // - Zero (0) if there is no winner yet | 173 | // - Zero (0) if there is no winner yet |
178 | // | 174 | // |
179 | 175 | ||
180 | int TicTacGameBoard::checkBoard( TicTacArray *a ) | 176 | int TicTacGameBoard::checkBoard( TicTacArray *a ) |
181 | { | 177 | { |
182 | int t = 0; | 178 | int t = 0; |
183 | int row, col; | 179 | int row, col; |
184 | bool won = FALSE; | 180 | bool won = FALSE; |
185 | for ( row=0; row<nBoard && !won; row++ ) { // check horizontal | 181 | for ( row=0; row<nBoard && !won; row++ ) { // check horizontal |
186 | t = a->at(row*nBoard); | 182 | t = a->at(row*nBoard); |
187 | if ( t == TicTacButton::Blank ) | 183 | if ( t == TicTacButton::Blank ) |
188 | continue; | 184 | continue; |
189 | col = 1; | 185 | col = 1; |
190 | while ( col<nBoard && a->at(row*nBoard+col) == t ) | 186 | while ( col<nBoard && a->at(row*nBoard+col) == t ) |
191 | col++; | 187 | col++; |
192 | if ( col == nBoard ) | 188 | if ( col == nBoard ) |
193 | won = TRUE; | 189 | won = TRUE; |
194 | } | 190 | } |
195 | for ( col=0; col<nBoard && !won; col++ ) { // check vertical | 191 | for ( col=0; col<nBoard && !won; col++ ) { // check vertical |
196 | t = a->at(col); | 192 | t = a->at(col); |
197 | if ( t == TicTacButton::Blank ) | 193 | if ( t == TicTacButton::Blank ) |
198 | continue; | 194 | continue; |
199 | row = 1; | 195 | row = 1; |
200 | while ( row<nBoard && a->at(row*nBoard+col) == t ) | 196 | while ( row<nBoard && a->at(row*nBoard+col) == t ) |
201 | row++; | 197 | row++; |
202 | if ( row == nBoard ) | 198 | if ( row == nBoard ) |
203 | won = TRUE; | 199 | won = TRUE; |
204 | } | 200 | } |
205 | if ( !won ) { // check diagonal top left | 201 | if ( !won ) { // check diagonal top left |
206 | t = a->at(0); // to bottom right | 202 | t = a->at(0); // to bottom right |
207 | if ( t != TicTacButton::Blank ) { | 203 | if ( t != TicTacButton::Blank ) { |
208 | int i = 1; | 204 | int i = 1; |
209 | while ( i<nBoard && a->at(i*nBoard+i) == t ) | 205 | while ( i<nBoard && a->at(i*nBoard+i) == t ) |
210 | i++; | 206 | i++; |
211 | if ( i == nBoard ) | 207 | if ( i == nBoard ) |
212 | won = TRUE; | 208 | won = TRUE; |
213 | } | 209 | } |
214 | } | 210 | } |
215 | if ( !won ) { // check diagonal bottom left | 211 | if ( !won ) { // check diagonal bottom left |
216 | int j = nBoard-1; // to top right | 212 | int j = nBoard-1; // to top right |
217 | int i = 0; | 213 | int i = 0; |
218 | t = a->at(i+j*nBoard); | 214 | t = a->at(i+j*nBoard); |
219 | if ( t != TicTacButton::Blank ) { | 215 | if ( t != TicTacButton::Blank ) { |
220 | i++; j--; | 216 | i++; j--; |
221 | while ( i<nBoard && a->at(i+j*nBoard) == t ) { | 217 | while ( i<nBoard && a->at(i+j*nBoard) == t ) { |
222 | i++; j--; | 218 | i++; j--; |
223 | } | 219 | } |
224 | if ( i == nBoard ) | 220 | if ( i == nBoard ) |
225 | won = TRUE; | 221 | won = TRUE; |
226 | } | 222 | } |
227 | } | 223 | } |
228 | if ( !won ) // no winner | 224 | if ( !won ) // no winner |
229 | t = 0; | 225 | t = 0; |
230 | return t; | 226 | return t; |
231 | } | 227 | } |
232 | 228 | ||
233 | 229 | ||
234 | // -------------------------------------------------------------------------- | 230 | // -------------------------------------------------------------------------- |
235 | // TicTacGameBoard::computerMove() | 231 | // TicTacGameBoard::computerMove() |
236 | // | 232 | // |
237 | // Puts a piece on the game board. Very, very simple. | 233 | // Puts a piece on the game board. Very, very simple. |
238 | // | 234 | // |
239 | 235 | ||
240 | void TicTacGameBoard::computerMove() | 236 | void TicTacGameBoard::computerMove() |
241 | { | 237 | { |
242 | int numButtons = nBoard*nBoard; | 238 | int numButtons = nBoard*nBoard; |
243 | int *altv = new int[numButtons]; // buttons alternatives | 239 | int *altv = new int[numButtons]; // buttons alternatives |
244 | int altc = 0; | 240 | int altc = 0; |
245 | int stopHuman = -1; | 241 | int stopHuman = -1; |
246 | TicTacArray a = btArray->copy(); | 242 | TicTacArray a = btArray->copy(); |
247 | int i; | 243 | int i; |
248 | for ( i=0; i<numButtons; i++ ) { // try all positions | 244 | for ( i=0; i<numButtons; i++ ) { // try all positions |
249 | if ( a[i] != TicTacButton::Blank ) // already a piece there | 245 | if ( a[i] != TicTacButton::Blank ) // already a piece there |
250 | continue; | 246 | continue; |
251 | a[i] = TicTacButton::Cross; // test if computer wins | 247 | a[i] = TicTacButton::Cross; // test if computer wins |
252 | if ( checkBoard(&a) == a[i] ) { // computer will win | 248 | if ( checkBoard(&a) == a[i] ) { // computer will win |
253 | st = ComputerWon; | 249 | st = ComputerWon; |
254 | stopHuman = -1; | 250 | stopHuman = -1; |
255 | break; | 251 | break; |
256 | } | 252 | } |
257 | a[i] = TicTacButton::Circle; // test if human wins | 253 | a[i] = TicTacButton::Circle; // test if human wins |
258 | if ( checkBoard(&a) == a[i] ) { // oops... | 254 | if ( checkBoard(&a) == a[i] ) { // oops... |
259 | stopHuman = i; // remember position | 255 | stopHuman = i; // remember position |
260 | a[i] = TicTacButton::Blank; // restore button | 256 | a[i] = TicTacButton::Blank; // restore button |
261 | continue; // computer still might win | 257 | continue; // computer still might win |
262 | } | 258 | } |
263 | a[i] = TicTacButton::Blank; // restore button | 259 | a[i] = TicTacButton::Blank; // restore button |
264 | altv[altc++] = i; // remember alternative | 260 | altv[altc++] = i; // remember alternative |
265 | } | 261 | } |
266 | if ( stopHuman >= 0 ) // must stop human from winning | 262 | if ( stopHuman >= 0 ) // must stop human from winning |
267 | a[stopHuman] = TicTacButton::Cross; | 263 | a[stopHuman] = TicTacButton::Cross; |
268 | else if ( i == numButtons ) { // tried all alternatives | 264 | else if ( i == numButtons ) { // tried all alternatives |
269 | if ( altc > 0 ) // set random piece | 265 | if ( altc > 0 ) // set random piece |
270 | a[altv[rand()%(altc--)]] = TicTacButton::Cross; | 266 | a[altv[rand()%(altc--)]] = TicTacButton::Cross; |
271 | if ( altc == 0 ) { // no more blanks | 267 | if ( altc == 0 ) { // no more blanks |
272 | st = NobodyWon; | 268 | st = NobodyWon; |
273 | emit finished(); | 269 | emit finished(); |
274 | } | 270 | } |
275 | } | 271 | } |
276 | *btArray = a; // update model | 272 | *btArray = a; // update model |
277 | updateButtons(); // update buttons | 273 | updateButtons(); // update buttons |
278 | delete[] altv; | 274 | delete[] altv; |
279 | } | 275 | } |
280 | 276 | ||
281 | 277 | ||
282 | //*************************************************************************** | 278 | //*************************************************************************** |
283 | //* TicTacToe member functions | 279 | //* TicTacToe member functions |
284 | //*************************************************************************** | 280 | //*************************************************************************** |
285 | 281 | ||
286 | // -------------------------------------------------------------------------- | 282 | // -------------------------------------------------------------------------- |
287 | // Creates a game widget with a game board and two push buttons, and connects | 283 | // Creates a game widget with a game board and two push buttons, and connects |
288 | // signals of child widgets to slots. | 284 | // signals of child widgets to slots. |
289 | // | 285 | // |
290 | 286 | ||
291 | TicTacToe::TicTacToe( QWidget *parent, const char *name, WFlags fl ) | 287 | TicTacToe::TicTacToe( QWidget *parent, const char *name, WFlags fl ) |
292 | : QWidget( parent, name, fl ) | 288 | : QWidget( parent, name, fl ) |
293 | { | 289 | { |
294 | QVBoxLayout * l = new QVBoxLayout( this, 6 ); | 290 | QVBoxLayout * l = new QVBoxLayout( this, 6 ); |
295 | 291 | ||
296 | // Create a message label | 292 | // Create a message label |
297 | boardSize = 3; | 293 | boardSize = 3; |
298 | 294 | ||
299 | message = new QLabel( this ); | 295 | message = new QLabel( this ); |
300 | message->setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); | 296 | message->setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); |
301 | message->setAlignment( AlignCenter ); | 297 | message->setAlignment( AlignCenter ); |
302 | l->addWidget( message ); | 298 | l->addWidget( message ); |
303 | 299 | ||
304 | // Create the game board and connect the signal finished() to this | 300 | // Create the game board and connect the signal finished() to this |
305 | // gameOver() slot | 301 | // gameOver() slot |
306 | 302 | ||
307 | board = new TicTacGameBoard( boardSize, this ); | 303 | board = new TicTacGameBoard( boardSize, this ); |
308 | connect( board, SIGNAL(finished()), SLOT(gameOver()) ); | 304 | connect( board, SIGNAL(finished()), SLOT(gameOver()) ); |
309 | l->addWidget( board ); | 305 | l->addWidget( board ); |
310 | 306 | ||
311 | // Create a horizontal frame line | 307 | // Create a horizontal frame line |
312 | 308 | ||
313 | QFrame *line = new QFrame( this ); | 309 | QFrame *line = new QFrame( this ); |
314 | line->setFrameStyle( QFrame::HLine | QFrame::Sunken ); | 310 | line->setFrameStyle( QFrame::HLine | QFrame::Sunken ); |
315 | l->addWidget( line ); | 311 | l->addWidget( line ); |
316 | 312 | ||
317 | // Create the combo box for deciding who should start, and | 313 | // Create the combo box for deciding who should start, and |
318 | // connect its clicked() signals to the buttonClicked() slot | 314 | // connect its clicked() signals to the buttonClicked() slot |
319 | 315 | ||
320 | whoStarts = new QComboBox( this ); | 316 | whoStarts = new QComboBox( this ); |
321 | whoStarts->insertItem( tr( "Computer starts" ) ); | 317 | whoStarts->insertItem( tr( "Computer starts" ) ); |
322 | whoStarts->insertItem( tr( "Human starts" ) ); | 318 | whoStarts->insertItem( tr( "Human starts" ) ); |
323 | l->addWidget( whoStarts ); | 319 | l->addWidget( whoStarts ); |
324 | 320 | ||
325 | // Create the push buttons and connect their clicked() signals | 321 | // Create the push buttons and connect their clicked() signals |
326 | // to this right slots. | 322 | // to this right slots. |
327 | 323 | ||
328 | newGame = new QPushButton( tr( "Play!" ), this ); | 324 | newGame = new QPushButton( tr( "Play!" ), this ); |
329 | connect( newGame, SIGNAL(clicked()), SLOT(newGameClicked()) ); | 325 | connect( newGame, SIGNAL(clicked()), SLOT(newGameClicked()) ); |
330 | quit = new QPushButton( tr( "Quit" ), this ); | 326 | quit = new QPushButton( tr( "Quit" ), this ); |
331 | connect( quit, SIGNAL(clicked()), qApp, SLOT(quit()) ); | 327 | connect( quit, SIGNAL(clicked()), qApp, SLOT(quit()) ); |
332 | QHBoxLayout * b = new QHBoxLayout; | 328 | QHBoxLayout * b = new QHBoxLayout; |
333 | l->addLayout( b ); | 329 | l->addLayout( b ); |
334 | b->addWidget( newGame ); | 330 | b->addWidget( newGame ); |
335 | b->addWidget( quit ); | 331 | b->addWidget( quit ); |
336 | QPEApplication::showWidget( this ); | 332 | QPEApplication::showWidget( this ); |
337 | newState(); | 333 | newState(); |
338 | } | 334 | } |
339 | 335 | ||
340 | 336 | ||
341 | // -------------------------------------------------------------------------- | 337 | // -------------------------------------------------------------------------- |
342 | // TicTacToe::newGameClicked() - SLOT | 338 | // TicTacToe::newGameClicked() - SLOT |
343 | // | 339 | // |
344 | // This slot is activated when the new game button is clicked. | 340 | // This slot is activated when the new game button is clicked. |
345 | // | 341 | // |
346 | 342 | ||
347 | void TicTacToe::newGameClicked() | 343 | void TicTacToe::newGameClicked() |
348 | { | 344 | { |
349 | board->computerStarts( whoStarts->currentItem() == 0 ); | 345 | board->computerStarts( whoStarts->currentItem() == 0 ); |
350 | board->newGame(); | 346 | board->newGame(); |
351 | newState(); | 347 | newState(); |
352 | } | 348 | } |
353 | 349 | ||
354 | 350 | ||
355 | // -------------------------------------------------------------------------- | 351 | // -------------------------------------------------------------------------- |
356 | // TicTacToe::gameOver() - SLOT | 352 | // TicTacToe::gameOver() - SLOT |
357 | // | 353 | // |
358 | // This slot is activated when the TicTacGameBoard emits the signal | 354 | // This slot is activated when the TicTacGameBoard emits the signal |
359 | // "finished()", i.e. when a player has won or when it is a draw. | 355 | // "finished()", i.e. when a player has won or when it is a draw. |
360 | // | 356 | // |
361 | 357 | ||
362 | void TicTacToe::gameOver() | 358 | void TicTacToe::gameOver() |
363 | { | 359 | { |
364 | newState(); // update text box | 360 | newState(); // update text box |
365 | } | 361 | } |
366 | 362 | ||
367 | 363 | ||
368 | // -------------------------------------------------------------------------- | 364 | // -------------------------------------------------------------------------- |
369 | // Updates the message to reflect a new state. | 365 | // Updates the message to reflect a new state. |
370 | // | 366 | // |
371 | 367 | ||
372 | void TicTacToe::newState() | 368 | void TicTacToe::newState() |
373 | { | 369 | { |
374 | QStringList msg; | 370 | QStringList msg; |
375 | msg << tr( "Click Play to start") | 371 | msg << tr( "Click Play to start") |
376 | << tr("Make your move") | 372 | << tr("Make your move") |
377 | << tr("You won!") | 373 | << tr("You won!") |
378 | << tr("Computer won!") | 374 | << tr("Computer won!") |
379 | << tr("It's a draw"); | 375 | << tr("It's a draw"); |
380 | message->setText( msg[board->state()] ); | 376 | message->setText( msg[board->state()] ); |
381 | return; | 377 | return; |
382 | } | 378 | } |
diff --git a/noncore/games/wordgame/main.cpp b/noncore/games/wordgame/main.cpp index f32acff..eb3e2f2 100644 --- a/noncore/games/wordgame/main.cpp +++ b/noncore/games/wordgame/main.cpp | |||
@@ -1,28 +1,27 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "wordgame.h" | 21 | #include "wordgame.h" |
22 | 22 | ||
23 | #include <qpe/qpeapplication.h> | ||
24 | #include <opie/oapplicationfactory.h> | 23 | #include <opie/oapplicationfactory.h> |
25 | 24 | ||
26 | 25 | ||
27 | OPIE_EXPORT_APP( OApplicationFactory<WordGame> ) | 26 | OPIE_EXPORT_APP( OApplicationFactory<WordGame> ) |
28 | 27 | ||
diff --git a/noncore/games/wordgame/wordgame.cpp b/noncore/games/wordgame/wordgame.cpp index c01551d..43a54f8 100644 --- a/noncore/games/wordgame/wordgame.cpp +++ b/noncore/games/wordgame/wordgame.cpp | |||
@@ -1,561 +1,552 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | 21 | ||
22 | #include "wordgame.h" | 22 | #include "wordgame.h" |
23 | 23 | ||
24 | #include <qpe/applnk.h> | ||
25 | #include <qpe/global.h> | 24 | #include <qpe/global.h> |
26 | #include <qpe/filemanager.h> | ||
27 | #include <qpe/resource.h> | 25 | #include <qpe/resource.h> |
28 | #include <qpe/config.h> | 26 | #include <qpe/config.h> |
29 | 27 | ||
30 | #include <qapplication.h> | 28 | #include <qapplication.h> |
31 | #include <qmessagebox.h> | 29 | #include <qmessagebox.h> |
32 | #include <qcombobox.h> | 30 | #include <qcombobox.h> |
33 | #include <qdatetime.h> | ||
34 | #include <qfileinfo.h> | ||
35 | #include <qfile.h> | ||
36 | #include <qdir.h> | 31 | #include <qdir.h> |
37 | #include <qiconset.h> | ||
38 | #include <qlabel.h> | ||
39 | #include <qlineedit.h> | 32 | #include <qlineedit.h> |
40 | #include <qpushbutton.h> | 33 | #include <qpushbutton.h> |
41 | #include <qtextstream.h> | 34 | #include <qtextstream.h> |
42 | #include <qtimer.h> | 35 | #include <qtimer.h> |
43 | #include <qpe/qpetoolbar.h> | 36 | #include <qpe/qpetoolbar.h> |
44 | #include <qtoolbutton.h> | 37 | #include <qtoolbutton.h> |
45 | #include <qvbox.h> | 38 | #include <qvbox.h> |
46 | #include <qwidgetstack.h> | 39 | #include <qwidgetstack.h> |
47 | #include <qpainter.h> | ||
48 | #include <qlayout.h> | 40 | #include <qlayout.h> |
49 | #include <qregexp.h> | ||
50 | 41 | ||
51 | #include <stdlib.h> | 42 | #include <stdlib.h> |
52 | #include <unistd.h> | 43 | #include <unistd.h> |
53 | #include <pwd.h> | 44 | #include <pwd.h> |
54 | #include <sys/types.h> | 45 | #include <sys/types.h> |
55 | 46 | ||
56 | enum RuleEffects { | 47 | enum RuleEffects { |
57 | Multiplier=15, | 48 | Multiplier=15, |
58 | MultiplyAll=64, | 49 | MultiplyAll=64, |
59 | Start=128 | 50 | Start=128 |
60 | }; | 51 | }; |
61 | 52 | ||
62 | static int tile_smallw = 16; | 53 | static int tile_smallw = 16; |
63 | static int tile_smallh = 16; | 54 | static int tile_smallh = 16; |
64 | static int tile_bigw = 22; | 55 | static int tile_bigw = 22; |
65 | static int tile_bigh = 22; | 56 | static int tile_bigh = 22; |
66 | static int tile_stweak = -2; | 57 | static int tile_stweak = -2; |
67 | static int tile_btweak = -1; | 58 | static int tile_btweak = -1; |
68 | 59 | ||
69 | static const int rack_tiles=7; | 60 | static const int rack_tiles=7; |
70 | 61 | ||
71 | const char* sampleWGR= | 62 | const char* sampleWGR= |
72 | "wordgame_shapes\n" | 63 | "wordgame_shapes\n" |
73 | "15 15\n" | 64 | "15 15\n" |
74 | "400001040100004\n" | 65 | "400001040100004\n" |
75 | "030000000000030\n" | 66 | "030000000000030\n" |
76 | "002002000200200\n" | 67 | "002002000200200\n" |
77 | "000300020003000\n" | 68 | "000300020003000\n" |
78 | "000020000020000\n" | 69 | "000020000020000\n" |
79 | "102001000100201\n" | 70 | "102001000100201\n" |
80 | "000000202000000\n" | 71 | "000000202000000\n" |
81 | "400200050002004\n" | 72 | "400200050002004\n" |
82 | "000000202000000\n" | 73 | "000000202000000\n" |
83 | "102001000100201\n" | 74 | "102001000100201\n" |
84 | "000020000020000\n" | 75 | "000020000020000\n" |
85 | "000300020003000\n" | 76 | "000300020003000\n" |
86 | "002002000200200\n" | 77 | "002002000200200\n" |
87 | "030000000000030\n" | 78 | "030000000000030\n" |
88 | "400001040100004\n" | 79 | "400001040100004\n" |
89 | "1 2 3 66 67 194 100 0\n" | 80 | "1 2 3 66 67 194 100 0\n" |
90 | "1 j 8\n" | 81 | "1 j 8\n" |
91 | "1 q 7\n" | 82 | "1 q 7\n" |
92 | "1 x 6\n" | 83 | "1 x 6\n" |
93 | "1 z 6\n" | 84 | "1 z 6\n" |
94 | "1 w 4\n" | 85 | "1 w 4\n" |
95 | "1 k 4\n" | 86 | "1 k 4\n" |
96 | "1 v 3\n" | 87 | "1 v 3\n" |
97 | "1 f 3\n" | 88 | "1 f 3\n" |
98 | "2 y 3\n" | 89 | "2 y 3\n" |
99 | "2 h 2\n" | 90 | "2 h 2\n" |
100 | "2 b 2\n" | 91 | "2 b 2\n" |
101 | "2 m 2\n" | 92 | "2 m 2\n" |
102 | "3 p 2\n" | 93 | "3 p 2\n" |
103 | "3 g 2\n" | 94 | "3 g 2\n" |
104 | "3 u 2\n" | 95 | "3 u 2\n" |
105 | "4 d 2\n" | 96 | "4 d 2\n" |
106 | "4 c 2\n" | 97 | "4 c 2\n" |
107 | "5 l 1\n" | 98 | "5 l 1\n" |
108 | "5 o 1\n" | 99 | "5 o 1\n" |
109 | "7 t 1\n" | 100 | "7 t 1\n" |
110 | "7 n 1\n" | 101 | "7 n 1\n" |
111 | "7 a 1\n" | 102 | "7 a 1\n" |
112 | "7 r 1\n" | 103 | "7 r 1\n" |
113 | "8 s 1\n" | 104 | "8 s 1\n" |
114 | "8 i 1\n" | 105 | "8 i 1\n" |
115 | "11 e 1\n" | 106 | "11 e 1\n" |
116 | "0\n"; | 107 | "0\n"; |
117 | 108 | ||
118 | WordGame::WordGame( QWidget* parent, const char* name, WFlags fl ) : | 109 | WordGame::WordGame( QWidget* parent, const char* name, WFlags fl ) : |
119 | QMainWindow(parent, name, fl) | 110 | QMainWindow(parent, name, fl) |
120 | { | 111 | { |
121 | if ( qApp->desktop()->width() < 240 ) { | 112 | if ( qApp->desktop()->width() < 240 ) { |
122 | tile_smallw = 10; | 113 | tile_smallw = 10; |
123 | tile_smallh = 10; | 114 | tile_smallh = 10; |
124 | tile_bigw = 16; | 115 | tile_bigw = 16; |
125 | tile_bigh = 16; | 116 | tile_bigh = 16; |
126 | tile_stweak = 0; | 117 | tile_stweak = 0; |
127 | tile_btweak = 0; | 118 | tile_btweak = 0; |
128 | } | 119 | } |
129 | 120 | ||
130 | setIcon( Resource::loadPixmap( "wordgame/WordGame.png" ) ); | 121 | setIcon( Resource::loadPixmap( "wordgame/WordGame.png" ) ); |
131 | setCaption( tr("Word Game") ); | 122 | setCaption( tr("Word Game") ); |
132 | 123 | ||
133 | setToolBarsMovable( FALSE ); | 124 | setToolBarsMovable( FALSE ); |
134 | vbox = new QVBox(this); | 125 | vbox = new QVBox(this); |
135 | 126 | ||
136 | setCentralWidget(vbox); | 127 | setCentralWidget(vbox); |
137 | toolbar = new QToolBar(this); | 128 | toolbar = new QToolBar(this); |
138 | addToolBar(toolbar, Bottom); | 129 | addToolBar(toolbar, Bottom); |
139 | reset = new QToolButton(Resource::loadPixmap("back"), tr("Back"), "", this, SLOT(resetTurn()), toolbar); | 130 | reset = new QToolButton(Resource::loadPixmap("back"), tr("Back"), "", this, SLOT(resetTurn()), toolbar); |
140 | done = new QToolButton(Resource::loadPixmap("done"), tr("Done"), "", this, SLOT(endTurn()), toolbar); | 131 | done = new QToolButton(Resource::loadPixmap("done"), tr("Done"), "", this, SLOT(endTurn()), toolbar); |
141 | scoreinfo = new ScoreInfo(toolbar); | 132 | scoreinfo = new ScoreInfo(toolbar); |
142 | scoreinfo->setFont(QFont("Helvetica",10)); | 133 | scoreinfo->setFont(QFont("Helvetica",10)); |
143 | new QToolButton(Resource::loadPixmap("finish"), tr("Close"), "", this, SLOT(endGame()), toolbar); | 134 | new QToolButton(Resource::loadPixmap("finish"), tr("Close"), "", this, SLOT(endGame()), toolbar); |
144 | toolbar->setStretchableWidget(scoreinfo); | 135 | toolbar->setStretchableWidget(scoreinfo); |
145 | 136 | ||
146 | cpu = 0; | 137 | cpu = 0; |
147 | board = 0; | 138 | board = 0; |
148 | bag = 0; | 139 | bag = 0; |
149 | racks = 0; | 140 | racks = 0; |
150 | 141 | ||
151 | aiheart = new QTimer(this); | 142 | aiheart = new QTimer(this); |
152 | connect(aiheart, SIGNAL(timeout()), this, SLOT(think())); | 143 | connect(aiheart, SIGNAL(timeout()), this, SLOT(think())); |
153 | 144 | ||
154 | readConfig(); | 145 | readConfig(); |
155 | } | 146 | } |
156 | 147 | ||
157 | WordGame::~WordGame() | 148 | WordGame::~WordGame() |
158 | { | 149 | { |
159 | writeConfig(); | 150 | writeConfig(); |
160 | } | 151 | } |
161 | 152 | ||
162 | void WordGame::writeConfig() | 153 | void WordGame::writeConfig() |
163 | { | 154 | { |
164 | Config cfg("WordGame"); | 155 | Config cfg("WordGame"); |
165 | cfg.setGroup("Game"); | 156 | cfg.setGroup("Game"); |
166 | cfg.writeEntry("NameList",namelist,';'); | 157 | cfg.writeEntry("NameList",namelist,';'); |
167 | cfg.writeEntry("CurrentPlayer",gameover ? 0 : player+1); | 158 | cfg.writeEntry("CurrentPlayer",gameover ? 0 : player+1); |
168 | if ( !gameover ) { | 159 | if ( !gameover ) { |
169 | cfg.writeEntry("Rules",rules); | 160 | cfg.writeEntry("Rules",rules); |
170 | bag->writeConfig(cfg); | 161 | bag->writeConfig(cfg); |
171 | board->writeConfig(cfg); | 162 | board->writeConfig(cfg); |
172 | scoreinfo->writeConfig(cfg); | 163 | scoreinfo->writeConfig(cfg); |
173 | } | 164 | } |
174 | for (int p=0; p<nplayers; p++) { | 165 | for (int p=0; p<nplayers; p++) { |
175 | cfg.setGroup("Player"+QString::number(p+1)); | 166 | cfg.setGroup("Player"+QString::number(p+1)); |
176 | if ( gameover ) cfg.clearGroup(); else rack(p)->writeConfig(cfg); | 167 | if ( gameover ) cfg.clearGroup(); else rack(p)->writeConfig(cfg); |
177 | } | 168 | } |
178 | } | 169 | } |
179 | 170 | ||
180 | void WordGame::readConfig() | 171 | void WordGame::readConfig() |
181 | { | 172 | { |
182 | Config cfg("WordGame"); | 173 | Config cfg("WordGame"); |
183 | cfg.setGroup("Game"); | 174 | cfg.setGroup("Game"); |
184 | int currentplayer = cfg.readNumEntry("CurrentPlayer",0); | 175 | int currentplayer = cfg.readNumEntry("CurrentPlayer",0); |
185 | QStringList pnames = cfg.readListEntry("NameList",';'); | 176 | QStringList pnames = cfg.readListEntry("NameList",';'); |
186 | if ( currentplayer ) { | 177 | if ( currentplayer ) { |
187 | gameover = FALSE; | 178 | gameover = FALSE; |
188 | rules = cfg.readEntry("Rules"); | 179 | rules = cfg.readEntry("Rules"); |
189 | if ( rules.find("x-wordgamerules") >= 0 ) { | 180 | if ( rules.find("x-wordgamerules") >= 0 ) { |
190 | // rules files moved | 181 | // rules files moved |
191 | rules = "Sample.rules"; | 182 | rules = "Sample.rules"; |
192 | } | 183 | } |
193 | if ( loadRules(rules) ) { | 184 | if ( loadRules(rules) ) { |
194 | startGame(pnames); | 185 | startGame(pnames); |
195 | bag->readConfig(cfg); | 186 | bag->readConfig(cfg); |
196 | board->readConfig(cfg); | 187 | board->readConfig(cfg); |
197 | scoreinfo->readConfig(cfg); | 188 | scoreinfo->readConfig(cfg); |
198 | for (int p=0; p<nplayers; p++) { | 189 | for (int p=0; p<nplayers; p++) { |
199 | cfg.setGroup("Player"+QString::number(p+1)); | 190 | cfg.setGroup("Player"+QString::number(p+1)); |
200 | rack(p)->readConfig(cfg); | 191 | rack(p)->readConfig(cfg); |
201 | } | 192 | } |
202 | player=currentplayer-1; | 193 | player=currentplayer-1; |
203 | readyRack(player); | 194 | readyRack(player); |
204 | return; | 195 | return; |
205 | } | 196 | } |
206 | } | 197 | } |
207 | // fall-back | 198 | // fall-back |
208 | openGameSelector(pnames); | 199 | openGameSelector(pnames); |
209 | } | 200 | } |
210 | 201 | ||
211 | void WordGame::openGameSelector(const QStringList& initnames) | 202 | void WordGame::openGameSelector(const QStringList& initnames) |
212 | { | 203 | { |
213 | toolbar->hide(); | 204 | toolbar->hide(); |
214 | gameover = FALSE; | 205 | gameover = FALSE; |
215 | 206 | ||
216 | delete board; | 207 | delete board; |
217 | board = 0; | 208 | board = 0; |
218 | delete racks; | 209 | delete racks; |
219 | racks = 0; | 210 | racks = 0; |
220 | 211 | ||
221 | delete cpu; | 212 | delete cpu; |
222 | cpu = 0; | 213 | cpu = 0; |
223 | 214 | ||
224 | newgame = new NewGame(vbox); | 215 | newgame = new NewGame(vbox); |
225 | 216 | ||
226 | //Rules rules(this); | 217 | //Rules rules(this); |
227 | //connect(game.editrules, SIGNAL(clicked()), &rules, SLOT(editRules())); | 218 | //connect(game.editrules, SIGNAL(clicked()), &rules, SLOT(editRules())); |
228 | //connect(&rules, SIGNAL(rulesChanged()), &game, SLOT(updateRuleSets())); | 219 | //connect(&rules, SIGNAL(rulesChanged()), &game, SLOT(updateRuleSets())); |
229 | struct passwd* n = getpwuid(getuid()); | 220 | struct passwd* n = getpwuid(getuid()); |
230 | QString playername = n ? n->pw_name : ""; | 221 | QString playername = n ? n->pw_name : ""; |
231 | if ( playername.isEmpty() ) { | 222 | if ( playername.isEmpty() ) { |
232 | playername = "Player"; | 223 | playername = "Player"; |
233 | } | 224 | } |
234 | newgame->player0->changeItem(playername,0); | 225 | newgame->player0->changeItem(playername,0); |
235 | newgame->player1->setCurrentItem(1); | 226 | newgame->player1->setCurrentItem(1); |
236 | newgame->updateRuleSets(); | 227 | newgame->updateRuleSets(); |
237 | newgame->show(); | 228 | newgame->show(); |
238 | 229 | ||
239 | connect(newgame->buttonOk, SIGNAL(clicked()), this, SLOT(startGame())); | 230 | connect(newgame->buttonOk, SIGNAL(clicked()), this, SLOT(startGame())); |
240 | } | 231 | } |
241 | 232 | ||
242 | void WordGame::startGame() | 233 | void WordGame::startGame() |
243 | { | 234 | { |
244 | rules = newgame->ruleslist[newgame->rules->currentItem()]; | 235 | rules = newgame->ruleslist[newgame->rules->currentItem()]; |
245 | if ( loadRules(rules) ) { | 236 | if ( loadRules(rules) ) { |
246 | QStringList names; | 237 | QStringList names; |
247 | names.append(newgame->player0->currentText()); | 238 | names.append(newgame->player0->currentText()); |
248 | names.append(newgame->player1->currentText()); | 239 | names.append(newgame->player1->currentText()); |
249 | names.append(newgame->player2->currentText()); | 240 | names.append(newgame->player2->currentText()); |
250 | names.append(newgame->player3->currentText()); | 241 | names.append(newgame->player3->currentText()); |
251 | names.append(newgame->player4->currentText()); | 242 | names.append(newgame->player4->currentText()); |
252 | names.append(newgame->player5->currentText()); | 243 | names.append(newgame->player5->currentText()); |
253 | delete newgame; | 244 | delete newgame; |
254 | startGame(names); | 245 | startGame(names); |
255 | } else { | 246 | } else { |
256 | // error... | 247 | // error... |
257 | delete newgame; | 248 | delete newgame; |
258 | close(); | 249 | close(); |
259 | } | 250 | } |
260 | } | 251 | } |
261 | 252 | ||
262 | void WordGame::startGame(const QStringList& playerlist) | 253 | void WordGame::startGame(const QStringList& playerlist) |
263 | { | 254 | { |
264 | toolbar->show(); | 255 | toolbar->show(); |
265 | racks = new QWidgetStack(vbox); | 256 | racks = new QWidgetStack(vbox); |
266 | racks->setFixedHeight(TileItem::bigHeight()+2); | 257 | racks->setFixedHeight(TileItem::bigHeight()+2); |
267 | namelist.clear(); | 258 | namelist.clear(); |
268 | nplayers=0; | 259 | nplayers=0; |
269 | for (QStringList::ConstIterator it=playerlist.begin(); it!=playerlist.end(); ++it) | 260 | for (QStringList::ConstIterator it=playerlist.begin(); it!=playerlist.end(); ++it) |
270 | addPlayer(*it); | 261 | addPlayer(*it); |
271 | scoreinfo->init(namelist); | 262 | scoreinfo->init(namelist); |
272 | 263 | ||
273 | if ( nplayers ) { | 264 | if ( nplayers ) { |
274 | player=0; | 265 | player=0; |
275 | readyRack(player); | 266 | readyRack(player); |
276 | } | 267 | } |
277 | 268 | ||
278 | board->show(); | 269 | board->show(); |
279 | racks->show(); | 270 | racks->show(); |
280 | } | 271 | } |
281 | 272 | ||
282 | bool WordGame::loadRules(const QString &name) | 273 | bool WordGame::loadRules(const QString &name) |
283 | { | 274 | { |
284 | QString filename = Global::applicationFileName( "wordgame", name ); | 275 | QString filename = Global::applicationFileName( "wordgame", name ); |
285 | QFile file( filename ); | 276 | QFile file( filename ); |
286 | if ( !file.open( IO_ReadOnly ) ) | 277 | if ( !file.open( IO_ReadOnly ) ) |
287 | return FALSE; | 278 | return FALSE; |
288 | 279 | ||
289 | QTextStream ts( &file ); | 280 | QTextStream ts( &file ); |
290 | 281 | ||
291 | QString title = name; | 282 | QString title = name; |
292 | title.truncate( title.length() - 6 ); | 283 | title.truncate( title.length() - 6 ); |
293 | //setCaption( title ); | 284 | //setCaption( title ); |
294 | 285 | ||
295 | QString shapepixmap; | 286 | QString shapepixmap; |
296 | ts >> shapepixmap; | 287 | ts >> shapepixmap; |
297 | int htiles,vtiles; | 288 | int htiles,vtiles; |
298 | ts >> htiles >> vtiles; | 289 | ts >> htiles >> vtiles; |
299 | 290 | ||
300 | if ( htiles < 3 || vtiles < 3 ) | 291 | if ( htiles < 3 || vtiles < 3 ) |
301 | return FALSE; | 292 | return FALSE; |
302 | 293 | ||
303 | QString rule_shapes; | 294 | QString rule_shapes; |
304 | for (int i=0; i<vtiles; i++) { | 295 | for (int i=0; i<vtiles; i++) { |
305 | QString line; | 296 | QString line; |
306 | ts >> line; | 297 | ts >> line; |
307 | rule_shapes += line; | 298 | rule_shapes += line; |
308 | } | 299 | } |
309 | static int rule_effects[12]; | 300 | static int rule_effects[12]; |
310 | int re=0,e; | 301 | int re=0,e; |
311 | ts >> e; | 302 | ts >> e; |
312 | while ( e && re < 10 ) { | 303 | while ( e && re < 10 ) { |
313 | rule_effects[re] = e; | 304 | rule_effects[re] = e; |
314 | if ( re++ < 10 ) ts >> e; | 305 | if ( re++ < 10 ) ts >> e; |
315 | } | 306 | } |
316 | 307 | ||
317 | QImage shim = Resource::loadImage("wordgame/wordgame_shapes"); | 308 | QImage shim = Resource::loadImage("wordgame/wordgame_shapes"); |
318 | shim = shim.smoothScale((re-1)*TileItem::smallWidth(),TileItem::smallHeight()); | 309 | shim = shim.smoothScale((re-1)*TileItem::smallWidth(),TileItem::smallHeight()); |
319 | QPixmap bgshapes; | 310 | QPixmap bgshapes; |
320 | bgshapes.convertFromImage(shim); | 311 | bgshapes.convertFromImage(shim); |
321 | 312 | ||
322 | rule_effects[re++] = 100; // default bonus | 313 | rule_effects[re++] = 100; // default bonus |
323 | board = new Board(bgshapes, htiles, vtiles, vbox); | 314 | board = new Board(bgshapes, htiles, vtiles, vbox); |
324 | board->setRules(rule_shapes, rule_effects); | 315 | board->setRules(rule_shapes, rule_effects); |
325 | connect(board, SIGNAL(temporaryScore(int)), scoreinfo, SLOT(showTemporaryScore(int))); | 316 | connect(board, SIGNAL(temporaryScore(int)), scoreinfo, SLOT(showTemporaryScore(int))); |
326 | 317 | ||
327 | bag = new Bag; | 318 | bag = new Bag; |
328 | 319 | ||
329 | int count; | 320 | int count; |
330 | ts >> count; | 321 | ts >> count; |
331 | while ( count ) { | 322 | while ( count ) { |
332 | QString text; | 323 | QString text; |
333 | int value; | 324 | int value; |
334 | ts >> text >> value; | 325 | ts >> text >> value; |
335 | if ( text == "_" ) | 326 | if ( text == "_" ) |
336 | text = ""; | 327 | text = ""; |
337 | 328 | ||
338 | Tile t(text, value); | 329 | Tile t(text, value); |
339 | for (int n=count; n--; ) | 330 | for (int n=count; n--; ) |
340 | bag->add(t); | 331 | bag->add(t); |
341 | 332 | ||
342 | ts >> count; | 333 | ts >> count; |
343 | } | 334 | } |
344 | 335 | ||
345 | return TRUE; | 336 | return TRUE; |
346 | } | 337 | } |
347 | 338 | ||
348 | 339 | ||
349 | NewGame::NewGame(QWidget* parent) : | 340 | NewGame::NewGame(QWidget* parent) : |
350 | NewGameBase(parent) | 341 | NewGameBase(parent) |
351 | { | 342 | { |
352 | } | 343 | } |
353 | 344 | ||
354 | void NewGame::updateRuleSets() | 345 | void NewGame::updateRuleSets() |
355 | { | 346 | { |
356 | rules->clear(); | 347 | rules->clear(); |
357 | 348 | ||
358 | QString rulesDir = Global::applicationFileName( "wordgame", "" ); | 349 | QString rulesDir = Global::applicationFileName( "wordgame", "" ); |
359 | QDir dir( rulesDir, "*.rules" ); | 350 | QDir dir( rulesDir, "*.rules" ); |
360 | ruleslist = dir.entryList(); | 351 | ruleslist = dir.entryList(); |
361 | if ( ruleslist.isEmpty() ) { | 352 | if ( ruleslist.isEmpty() ) { |
362 | // Provide a sample | 353 | // Provide a sample |
363 | QFile file( rulesDir + "Sample.rules" ); | 354 | QFile file( rulesDir + "Sample.rules" ); |
364 | if ( file.open( IO_WriteOnly ) ) { | 355 | if ( file.open( IO_WriteOnly ) ) { |
365 | file.writeBlock( sampleWGR, strlen(sampleWGR) ); | 356 | file.writeBlock( sampleWGR, strlen(sampleWGR) ); |
366 | file.close(); | 357 | file.close(); |
367 | updateRuleSets(); | 358 | updateRuleSets(); |
368 | } | 359 | } |
369 | return; | 360 | return; |
370 | } | 361 | } |
371 | int newest=0; | 362 | int newest=0; |
372 | int newest_age=INT_MAX; | 363 | int newest_age=INT_MAX; |
373 | QDateTime now = QDateTime::currentDateTime(); | 364 | QDateTime now = QDateTime::currentDateTime(); |
374 | QStringList::Iterator it; | 365 | QStringList::Iterator it; |
375 | for ( it = ruleslist.begin(); it != ruleslist.end(); ++it ) { | 366 | for ( it = ruleslist.begin(); it != ruleslist.end(); ++it ) { |
376 | QFileInfo fi((*it)); | 367 | QFileInfo fi((*it)); |
377 | int age = fi.lastModified().secsTo(now); | 368 | int age = fi.lastModified().secsTo(now); |
378 | QString name = *it; | 369 | QString name = *it; |
379 | name.truncate( name.length()-6 ); // remove extension | 370 | name.truncate( name.length()-6 ); // remove extension |
380 | rules->insertItem( name ); | 371 | rules->insertItem( name ); |
381 | if ( age < newest_age ) { | 372 | if ( age < newest_age ) { |
382 | newest_age = age; | 373 | newest_age = age; |
383 | newest = rules->count()-1; | 374 | newest = rules->count()-1; |
384 | } | 375 | } |
385 | } | 376 | } |
386 | rules->setCurrentItem(newest); | 377 | rules->setCurrentItem(newest); |
387 | } | 378 | } |
388 | 379 | ||
389 | Rules::Rules(QWidget* parent) : | 380 | Rules::Rules(QWidget* parent) : |
390 | RulesBase(parent,0,TRUE) | 381 | RulesBase(parent,0,TRUE) |
391 | { | 382 | { |
392 | } | 383 | } |
393 | 384 | ||
394 | void Rules::editRules() | 385 | void Rules::editRules() |
395 | { | 386 | { |
396 | if ( exec() ) { | 387 | if ( exec() ) { |
397 | // ### create a new set of rules | 388 | // ### create a new set of rules |
398 | emit rulesChanged(); | 389 | emit rulesChanged(); |
399 | } | 390 | } |
400 | } | 391 | } |
401 | 392 | ||
402 | void Rules::deleteRuleSet() | 393 | void Rules::deleteRuleSet() |
403 | { | 394 | { |
404 | // ### delete existing rule set | 395 | // ### delete existing rule set |
405 | emit rulesChanged(); | 396 | emit rulesChanged(); |
406 | } | 397 | } |
407 | 398 | ||
408 | void WordGame::addPlayer(const QString& name) | 399 | void WordGame::addPlayer(const QString& name) |
409 | { | 400 | { |
410 | if ( !name.isEmpty() ) { | 401 | if ( !name.isEmpty() ) { |
411 | int colon = name.find(':'); | 402 | int colon = name.find(':'); |
412 | int cpu = (colon >=0 && name.left(2) == "AI") ? name.mid(2,1).toInt() : 0; | 403 | int cpu = (colon >=0 && name.left(2) == "AI") ? name.mid(2,1).toInt() : 0; |
413 | addPlayer(name,cpu); | 404 | addPlayer(name,cpu); |
414 | } | 405 | } |
415 | } | 406 | } |
416 | 407 | ||
417 | void WordGame::addPlayer(const QString& name, int cpu) | 408 | void WordGame::addPlayer(const QString& name, int cpu) |
418 | { | 409 | { |
419 | Rack* r = new Rack(rack_tiles,racks); | 410 | Rack* r = new Rack(rack_tiles,racks); |
420 | r->setPlayerName(name); | 411 | r->setPlayerName(name); |
421 | r->setComputerization(cpu); | 412 | r->setComputerization(cpu); |
422 | racks->addWidget(r, nplayers); | 413 | racks->addWidget(r, nplayers); |
423 | refillRack(nplayers); | 414 | refillRack(nplayers); |
424 | namelist.append(name); | 415 | namelist.append(name); |
425 | 416 | ||
426 | ++nplayers; | 417 | ++nplayers; |
427 | } | 418 | } |
428 | 419 | ||
429 | void WordGame::nextPlayer() | 420 | void WordGame::nextPlayer() |
430 | { | 421 | { |
431 | if ( !refillRack(player) ) { | 422 | if ( !refillRack(player) ) { |
432 | endGame(); | 423 | endGame(); |
433 | } else { | 424 | } else { |
434 | player = (player+1)%nplayers; | 425 | player = (player+1)%nplayers; |
435 | scoreinfo->setBoldOne(player); | 426 | scoreinfo->setBoldOne(player); |
436 | readyRack(player); | 427 | readyRack(player); |
437 | } | 428 | } |
438 | } | 429 | } |
439 | 430 | ||
440 | bool WordGame::mayEndGame() | 431 | bool WordGame::mayEndGame() |
441 | { | 432 | { |
442 | int out=-1; | 433 | int out=-1; |
443 | int i; | 434 | int i; |
444 | for (i=0; i<nplayers; i++) | 435 | for (i=0; i<nplayers; i++) |
445 | if ( !rack(i)->count() ) | 436 | if ( !rack(i)->count() ) |
446 | out = i; | 437 | out = i; |
447 | if ( out<0 ) { | 438 | if ( out<0 ) { |
448 | if ( QMessageBox::warning(this,tr("End game"), | 439 | if ( QMessageBox::warning(this,tr("End game"), |
449 | tr("Do you want to end the game early?"), | 440 | tr("Do you want to end the game early?"), |
450 | tr("Yes"), tr("No") )!=0 ) | 441 | tr("Yes"), tr("No") )!=0 ) |
451 | { | 442 | { |
452 | return FALSE; | 443 | return FALSE; |
453 | } | 444 | } |
454 | } | 445 | } |
455 | return TRUE; | 446 | return TRUE; |
456 | } | 447 | } |
457 | 448 | ||
458 | void WordGame::endGame() | 449 | void WordGame::endGame() |
459 | { | 450 | { |
460 | if ( gameover ) { | 451 | if ( gameover ) { |
461 | close(); | 452 | close(); |
462 | return; | 453 | return; |
463 | } | 454 | } |
464 | 455 | ||
465 | if ( !mayEndGame() ) | 456 | if ( !mayEndGame() ) |
466 | return; | 457 | return; |
467 | int out=-1; | 458 | int out=-1; |
468 | int totalleft=0; | 459 | int totalleft=0; |
469 | int i; | 460 | int i; |
470 | for (i=0; i<nplayers; i++) { | 461 | for (i=0; i<nplayers; i++) { |
471 | Rack* r = rack(i); | 462 | Rack* r = rack(i); |
472 | int c = r->count(); | 463 | int c = r->count(); |
473 | if ( c ) { | 464 | if ( c ) { |
474 | int lose=0; | 465 | int lose=0; |
475 | for ( int j=0; j<c; j++ ) | 466 | for ( int j=0; j<c; j++ ) |
476 | lose += r->tileRef(j)->value(); | 467 | lose += r->tileRef(j)->value(); |
477 | totalleft += lose; | 468 | totalleft += lose; |
478 | scoreinfo->addScore(i,-lose); | 469 | scoreinfo->addScore(i,-lose); |
479 | } else { | 470 | } else { |
480 | out = i; | 471 | out = i; |
481 | } | 472 | } |
482 | } | 473 | } |
483 | int highest=0; | 474 | int highest=0; |
484 | int winner=0; | 475 | int winner=0; |
485 | for (i=0; i<nplayers; i++) { | 476 | for (i=0; i<nplayers; i++) { |
486 | int s = scoreinfo->playerScore(i); | 477 | int s = scoreinfo->playerScore(i); |
487 | if ( s > highest ) { | 478 | if ( s > highest ) { |
488 | highest = s; | 479 | highest = s; |
489 | winner = i; | 480 | winner = i; |
490 | } | 481 | } |
491 | } | 482 | } |
492 | if ( out >= 0 ) | 483 | if ( out >= 0 ) |
493 | scoreinfo->addScore(out,totalleft); | 484 | scoreinfo->addScore(out,totalleft); |
494 | scoreinfo->setBoldOne(winner); | 485 | scoreinfo->setBoldOne(winner); |
495 | gameover = TRUE; | 486 | gameover = TRUE; |
496 | done->setEnabled(TRUE); | 487 | done->setEnabled(TRUE); |
497 | reset->setEnabled(FALSE); | 488 | reset->setEnabled(FALSE); |
498 | } | 489 | } |
499 | 490 | ||
500 | void WordGame::endTurn() | 491 | void WordGame::endTurn() |
501 | { | 492 | { |
502 | if ( gameover ) { | 493 | if ( gameover ) { |
503 | openGameSelector(namelist); | 494 | openGameSelector(namelist); |
504 | } else { | 495 | } else { |
505 | if ( board->checkTurn() ) { | 496 | if ( board->checkTurn() ) { |
506 | if ( board->turnScore() >= 0 ) { | 497 | if ( board->turnScore() >= 0 ) { |
507 | scoreinfo->addScore(player,board->turnScore()); | 498 | scoreinfo->addScore(player,board->turnScore()); |
508 | board->finalizeTurn(); | 499 | board->finalizeTurn(); |
509 | } else { | 500 | } else { |
510 | QApplication::beep(); | 501 | QApplication::beep(); |
511 | } | 502 | } |
512 | nextPlayer(); | 503 | nextPlayer(); |
513 | } | 504 | } |
514 | } | 505 | } |
515 | } | 506 | } |
516 | 507 | ||
517 | void WordGame::resetTurn() | 508 | void WordGame::resetTurn() |
518 | { | 509 | { |
519 | board->resetRack(); | 510 | board->resetRack(); |
520 | } | 511 | } |
521 | 512 | ||
522 | void WordGame::passTurn() | 513 | void WordGame::passTurn() |
523 | { | 514 | { |
524 | // ######## trade? | 515 | // ######## trade? |
525 | nextPlayer(); | 516 | nextPlayer(); |
526 | } | 517 | } |
527 | 518 | ||
528 | bool WordGame::refillRack(int i) | 519 | bool WordGame::refillRack(int i) |
529 | { | 520 | { |
530 | Rack* r = rack(i); | 521 | Rack* r = rack(i); |
531 | while ( !bag->isEmpty() && !r->isFull() ) { | 522 | while ( !bag->isEmpty() && !r->isFull() ) { |
532 | r->addTile(bag->takeRandom()); | 523 | r->addTile(bag->takeRandom()); |
533 | } | 524 | } |
534 | return r->count() != 0; | 525 | return r->count() != 0; |
535 | } | 526 | } |
536 | 527 | ||
537 | void WordGame::readyRack(int i) | 528 | void WordGame::readyRack(int i) |
538 | { | 529 | { |
539 | Rack* r = rack(i); | 530 | Rack* r = rack(i); |
540 | racks->raiseWidget(i); | 531 | racks->raiseWidget(i); |
541 | board->setCurrentRack(r); | 532 | board->setCurrentRack(r); |
542 | 533 | ||
543 | done->setEnabled( !r->computerized() ); | 534 | done->setEnabled( !r->computerized() ); |
544 | reset->setEnabled( !r->computerized() ); | 535 | reset->setEnabled( !r->computerized() ); |
545 | 536 | ||
546 | if ( r->computerized() ) { | 537 | if ( r->computerized() ) { |
547 | cpu = new ComputerPlayer(board, r); | 538 | cpu = new ComputerPlayer(board, r); |
548 | aiheart->start(0); | 539 | aiheart->start(0); |
549 | } | 540 | } |
550 | } | 541 | } |
551 | 542 | ||
552 | Rack* WordGame::rack(int i) const | 543 | Rack* WordGame::rack(int i) const |
553 | { | 544 | { |
554 | return (Rack*)racks->widget(i); | 545 | return (Rack*)racks->widget(i); |
555 | } | 546 | } |
556 | 547 | ||
557 | void WordGame::think() | 548 | void WordGame::think() |
558 | { | 549 | { |
559 | if ( !cpu->step() ) { | 550 | if ( !cpu->step() ) { |
560 | delete cpu; | 551 | delete cpu; |
561 | cpu = 0; | 552 | cpu = 0; |
diff --git a/noncore/games/zlines/ballpainter.cpp b/noncore/games/zlines/ballpainter.cpp index c2b34e1..622ec29 100644 --- a/noncore/games/zlines/ballpainter.cpp +++ b/noncore/games/zlines/ballpainter.cpp | |||
@@ -1,135 +1,132 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | ballpainter.cpp - description | 2 | ballpainter.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Fri May 19 2000 | 4 | begin : Fri May 19 2000 |
5 | copyright : (C) 2000 by Roman Merzlyakov | 5 | copyright : (C) 2000 by Roman Merzlyakov |
6 | email : roman@sbrf.barrt.ru | 6 | email : roman@sbrf.barrt.ru |
7 | copyright : (C) 2000 by Roman Razilov | 7 | copyright : (C) 2000 by Roman Razilov |
8 | email : Roman.Razilov@gmx.de | 8 | email : Roman.Razilov@gmx.de |
9 | ***************************************************************************/ | 9 | ***************************************************************************/ |
10 | 10 | ||
11 | /*************************************************************************** | 11 | /*************************************************************************** |
12 | * * | 12 | * * |
13 | * This program is free software; you can redistribute it and/or modify * | 13 | * This program is free software; you can redistribute it and/or modify * |
14 | * it under the terms of the GNU General Public License as published by * | 14 | * it under the terms of the GNU General Public License as published by * |
15 | * the Free Software Foundation; either version 2 of the License, or * | 15 | * the Free Software Foundation; either version 2 of the License, or * |
16 | * (at your option) any later version. * | 16 | * (at your option) any later version. * |
17 | * * | 17 | * * |
18 | ***************************************************************************/ | 18 | ***************************************************************************/ |
19 | 19 | ||
20 | #include <qpe/resource.h> | 20 | #include <qpe/resource.h> |
21 | 21 | ||
22 | #include <qapplication.h> | ||
23 | #include "ballpainter.h" | 22 | #include "ballpainter.h" |
24 | //#include "shotcounter.h" | 23 | //#include "shotcounter.h" |
25 | #include <qpainter.h> | 24 | #include <qpainter.h> |
26 | #include "linesboard.h" | ||
27 | //#include <qcolor.h> | 25 | //#include <qcolor.h> |
28 | #include <qjpegio.h> | ||
29 | 26 | ||
30 | 27 | ||
31 | #define PIXSIZE 21 | 28 | #define PIXSIZE 21 |
32 | 29 | ||
33 | int colorLinesArr[NCOLORS] = | 30 | int colorLinesArr[NCOLORS] = |
34 | {0x0000ff, 0x00ff00, 0xff0000, 0x00ffff, 0xff00ff, 0xffff00, 0x005080}; | 31 | {0x0000ff, 0x00ff00, 0xff0000, 0x00ffff, 0xff00ff, 0xffff00, 0x005080}; |
35 | // 0x00bbggrr | 32 | // 0x00bbggrr |
36 | // red , green , blue , yellow , violet , cyan , brown | 33 | // red , green , blue , yellow , violet , cyan , brown |
37 | 34 | ||
38 | 35 | ||
39 | 36 | ||
40 | BallPainter::BallPainter() | 37 | BallPainter::BallPainter() |
41 | : QObject() | 38 | : QObject() |
42 | { | 39 | { |
43 | createPixmap(); | 40 | createPixmap(); |
44 | } | 41 | } |
45 | 42 | ||
46 | BallPainter::~BallPainter() | 43 | BallPainter::~BallPainter() |
47 | { | 44 | { |
48 | } | 45 | } |
49 | 46 | ||
50 | QPixmap* BallPainter::pixmap( enum Pixmaps pix ) | 47 | QPixmap* BallPainter::pixmap( enum Pixmaps pix ) |
51 | { | 48 | { |
52 | QString name; | 49 | QString name; |
53 | switch(pix) { | 50 | switch(pix) { |
54 | case Field: | 51 | case Field: |
55 | name = QString::fromLatin1("zlines/field"); | 52 | name = QString::fromLatin1("zlines/field"); |
56 | break; | 53 | break; |
57 | case Balls: | 54 | case Balls: |
58 | name = QString::fromLatin1("zlines/balls"); | 55 | name = QString::fromLatin1("zlines/balls"); |
59 | break; | 56 | break; |
60 | case Fire: | 57 | case Fire: |
61 | name = QString::fromLatin1("zlines/fire"); | 58 | name = QString::fromLatin1("zlines/fire"); |
62 | break; | 59 | break; |
63 | } | 60 | } |
64 | 61 | ||
65 | return new QPixmap(Resource::loadPixmap(name) ); | 62 | return new QPixmap(Resource::loadPixmap(name) ); |
66 | } | 63 | } |
67 | 64 | ||
68 | void BallPainter::createPixmap() | 65 | void BallPainter::createPixmap() |
69 | { | 66 | { |
70 | // warning( kapp->kde_datadir() +"/klines/data/balls.bmp"); | 67 | // warning( kapp->kde_datadir() +"/klines/data/balls.bmp"); |
71 | backgroundPix = pixmap(Field); | 68 | backgroundPix = pixmap(Field); |
72 | QPixmap *balls = pixmap(Balls); | 69 | QPixmap *balls = pixmap(Balls); |
73 | QPixmap *fire = pixmap(Fire); | 70 | QPixmap *fire = pixmap(Fire); |
74 | if (balls->isNull() ||backgroundPix->isNull() || fire->isNull() ) | 71 | if (balls->isNull() ||backgroundPix->isNull() || fire->isNull() ) |
75 | fatal("Cannot open data files.\nHave you correctly installed klines?"); | 72 | fatal("Cannot open data files.\nHave you correctly installed klines?"); |
76 | 73 | ||
77 | warning("Pixsize %i", PIXSIZE); | 74 | warning("Pixsize %i", PIXSIZE); |
78 | for(int c=0; c<NCOLORS; c++) | 75 | for(int c=0; c<NCOLORS; c++) |
79 | { | 76 | { |
80 | for(int t=0; t<PIXTIME + FIREBALLS + BOOMBALLS + 1 ; t++) | 77 | for(int t=0; t<PIXTIME + FIREBALLS + BOOMBALLS + 1 ; t++) |
81 | { | 78 | { |
82 | imgCash[c][t] = new QPixmap(CELLSIZE, CELLSIZE); | 79 | imgCash[c][t] = new QPixmap(CELLSIZE, CELLSIZE); |
83 | QPainter p(imgCash[c][t]); | 80 | QPainter p(imgCash[c][t]); |
84 | p.drawPixmap(0,0,(*backgroundPix),0,0,CELLSIZE,CELLSIZE); | 81 | p.drawPixmap(0,0,(*backgroundPix),0,0,CELLSIZE,CELLSIZE); |
85 | p.drawPixmap(1,1,(*balls),t*PIXSIZE,c*PIXSIZE,PIXSIZE,PIXSIZE); | 82 | p.drawPixmap(1,1,(*balls),t*PIXSIZE,c*PIXSIZE,PIXSIZE,PIXSIZE); |
86 | } | 83 | } |
87 | for(int t=0; t < FIREPIX ; t++) | 84 | for(int t=0; t < FIREPIX ; t++) |
88 | { | 85 | { |
89 | firePix[t] = new QPixmap(CELLSIZE, CELLSIZE); | 86 | firePix[t] = new QPixmap(CELLSIZE, CELLSIZE); |
90 | QPainter p(firePix[t]); | 87 | QPainter p(firePix[t]); |
91 | p.drawPixmap(0,0,(*backgroundPix),0,0,CELLSIZE,CELLSIZE); | 88 | p.drawPixmap(0,0,(*backgroundPix),0,0,CELLSIZE,CELLSIZE); |
92 | p.drawPixmap(1,1,(*fire),t*PIXSIZE,0,PIXSIZE,PIXSIZE); | 89 | p.drawPixmap(1,1,(*fire),t*PIXSIZE,0,PIXSIZE,PIXSIZE); |
93 | } | 90 | } |
94 | } | 91 | } |
95 | delete balls; | 92 | delete balls; |
96 | delete fire; | 93 | delete fire; |
97 | } | 94 | } |
98 | 95 | ||
99 | 96 | ||
100 | QPixmap* BallPainter::GetBall(int color, int animstep, int panim) | 97 | QPixmap* BallPainter::GetBall(int color, int animstep, int panim) |
101 | { | 98 | { |
102 | // return backgroundPix; | 99 | // return backgroundPix; |
103 | 100 | ||
104 | if( (color<0) || (color>=NCOLORS) || (animstep<0) || color == NOBALL ) | 101 | if( (color<0) || (color>=NCOLORS) || (animstep<0) || color == NOBALL ) |
105 | { | 102 | { |
106 | // warning("BallPainter::Background"); | 103 | // warning("BallPainter::Background"); |
107 | return backgroundPix; | 104 | return backgroundPix; |
108 | } | 105 | } |
109 | if ( panim == ANIM_JUMP ) | 106 | if ( panim == ANIM_JUMP ) |
110 | { | 107 | { |
111 | if ( ( animstep < 0 ) || ( animstep >= PIXTIME ) ) | 108 | if ( ( animstep < 0 ) || ( animstep >= PIXTIME ) ) |
112 | return backgroundPix; | 109 | return backgroundPix; |
113 | else | 110 | else |
114 | return imgCash[color][animstep]; | 111 | return imgCash[color][animstep]; |
115 | } | 112 | } |
116 | else if ( panim == ANIM_BURN ) | 113 | else if ( panim == ANIM_BURN ) |
117 | { | 114 | { |
118 | if ( animstep < FIREBALLS ) | 115 | if ( animstep < FIREBALLS ) |
119 | return imgCash[color][animstep + PIXTIME + BOOMBALLS + 1]; | 116 | return imgCash[color][animstep + PIXTIME + BOOMBALLS + 1]; |
120 | else if ( animstep < FIREBALLS + FIREPIX ) | 117 | else if ( animstep < FIREBALLS + FIREPIX ) |
121 | return firePix[animstep - FIREBALLS]; | 118 | return firePix[animstep - FIREBALLS]; |
122 | } | 119 | } |
123 | else if ( panim == ANIM_BORN ) | 120 | else if ( panim == ANIM_BORN ) |
124 | { | 121 | { |
125 | if ( animstep < BOOMBALLS ) | 122 | if ( animstep < BOOMBALLS ) |
126 | return imgCash[color][animstep + PIXTIME]; | 123 | return imgCash[color][animstep + PIXTIME]; |
127 | else | 124 | else |
128 | return imgCash[color][NORMALBALL]; | 125 | return imgCash[color][NORMALBALL]; |
129 | } | 126 | } |
130 | // rest is not imlemented yet | 127 | // rest is not imlemented yet |
131 | return imgCash[color][NORMALBALL]; | 128 | return imgCash[color][NORMALBALL]; |
132 | 129 | ||
133 | } | 130 | } |
134 | 131 | ||
135 | 132 | ||
diff --git a/noncore/games/zlines/field.cpp b/noncore/games/zlines/field.cpp index 2a87739..0adf4ac 100644 --- a/noncore/games/zlines/field.cpp +++ b/noncore/games/zlines/field.cpp | |||
@@ -1,132 +1,131 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | field.cpp - description | 2 | field.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Fri May 19 2000 | 4 | begin : Fri May 19 2000 |
5 | copyright : (C) 2000 by Roman Merzlyakov | 5 | copyright : (C) 2000 by Roman Merzlyakov |
6 | email : roman@sbrf.barrt.ru | 6 | email : roman@sbrf.barrt.ru |
7 | copyright : (C) 2000 by Roman Razilov | 7 | copyright : (C) 2000 by Roman Razilov |
8 | email : Roman.Razilov@gmx.de | 8 | email : Roman.Razilov@gmx.de |
9 | ***************************************************************************/ | 9 | ***************************************************************************/ |
10 | 10 | ||
11 | /*************************************************************************** | 11 | /*************************************************************************** |
12 | * * | 12 | * * |
13 | * This program is free software; you can redistribute it and/or modify * | 13 | * This program is free software; you can redistribute it and/or modify * |
14 | * it under the terms of the GNU General Public License as published by * | 14 | * it under the terms of the GNU General Public License as published by * |
15 | * the Free Software Foundation; either version 2 of the License, or * | 15 | * the Free Software Foundation; either version 2 of the License, or * |
16 | * (at your option) any later version. * | 16 | * (at your option) any later version. * |
17 | * * | 17 | * * |
18 | ***************************************************************************/ | 18 | ***************************************************************************/ |
19 | #include <stdlib.h> | 19 | #include <stdlib.h> |
20 | #include "cfg.h" | ||
21 | #include "field.h" | 20 | #include "field.h" |
22 | 21 | ||
23 | Field::Field(QWidget* parent, const char* name) | 22 | Field::Field(QWidget* parent, const char* name) |
24 | : QWidget( parent, name ) | 23 | : QWidget( parent, name ) |
25 | { | 24 | { |
26 | clearField(); | 25 | clearField(); |
27 | } | 26 | } |
28 | 27 | ||
29 | Field::~Field() | 28 | Field::~Field() |
30 | { | 29 | { |
31 | } | 30 | } |
32 | 31 | ||
33 | void Field::clearField() | 32 | void Field::clearField() |
34 | { | 33 | { |
35 | for(int y=0; y<NUMCELLSH; y++) | 34 | for(int y=0; y<NUMCELLSH; y++) |
36 | for(int x=0; x<NUMCELLSW; x++) | 35 | for(int x=0; x<NUMCELLSW; x++) |
37 | field[y][x].clear(); | 36 | field[y][x].clear(); |
38 | } | 37 | } |
39 | void Field::clearAnim() | 38 | void Field::clearAnim() |
40 | { | 39 | { |
41 | for(int y=0; y<NUMCELLSH; y++) | 40 | for(int y=0; y<NUMCELLSH; y++) |
42 | for(int x=0; x<NUMCELLSW; x++) | 41 | for(int x=0; x<NUMCELLSW; x++) |
43 | field[y][x].setAnim( ANIM_NO ); | 42 | field[y][x].setAnim( ANIM_NO ); |
44 | } | 43 | } |
45 | int Field::deleteAnimatedBalls() | 44 | int Field::deleteAnimatedBalls() |
46 | { | 45 | { |
47 | int deleted = 0; | 46 | int deleted = 0; |
48 | for(int y=0; y<NUMCELLSH; y++) | 47 | for(int y=0; y<NUMCELLSH; y++) |
49 | for(int x=0; x<NUMCELLSW; x++) | 48 | for(int x=0; x<NUMCELLSW; x++) |
50 | { | 49 | { |
51 | if ( field[y][x].getAnim() != ANIM_NO ) | 50 | if ( field[y][x].getAnim() != ANIM_NO ) |
52 | { | 51 | { |
53 | deleted++; | 52 | deleted++; |
54 | field[y][x].clear(); | 53 | field[y][x].clear(); |
55 | } | 54 | } |
56 | } | 55 | } |
57 | return deleted; | 56 | return deleted; |
58 | } | 57 | } |
59 | 58 | ||
60 | bool Field::checkBounds(int x, int y) | 59 | bool Field::checkBounds(int x, int y) |
61 | { | 60 | { |
62 | return (x>=0) && (x<NUMCELLSW) && (y>=0) && (y<NUMCELLSH); | 61 | return (x>=0) && (x<NUMCELLSW) && (y>=0) && (y<NUMCELLSH); |
63 | } | 62 | } |
64 | 63 | ||
65 | void Field::putBall(int x, int y, int color) | 64 | void Field::putBall(int x, int y, int color) |
66 | { | 65 | { |
67 | if( checkBounds(x,y) ) | 66 | if( checkBounds(x,y) ) |
68 | field[y][x].setColor(color); | 67 | field[y][x].setColor(color); |
69 | } | 68 | } |
70 | /* | 69 | /* |
71 | void Field::putBall(int x, int y, char color) | 70 | void Field::putBall(int x, int y, char color) |
72 | { | 71 | { |
73 | if( checkBounds(x,y) ){ | 72 | if( checkBounds(x,y) ){ |
74 | field[y][x].setColor(color); | 73 | field[y][x].setColor(color); |
75 | erase5Balls(); | 74 | erase5Balls(); |
76 | repaint(FALSE); | 75 | repaint(FALSE); |
77 | } | 76 | } |
78 | }*/ | 77 | }*/ |
79 | void Field::moveBall(int xa, int ya, int xb, int yb) | 78 | void Field::moveBall(int xa, int ya, int xb, int yb) |
80 | { | 79 | { |
81 | if( checkBounds(xa,ya) && checkBounds(xb,yb) && | 80 | if( checkBounds(xa,ya) && checkBounds(xb,yb) && |
82 | field[yb][xb].isFree() && ( xa != xb || ya != yb) ) { | 81 | field[yb][xb].isFree() && ( xa != xb || ya != yb) ) { |
83 | field[yb][xb].moveBall(field[ya][xa]); | 82 | field[yb][xb].moveBall(field[ya][xa]); |
84 | } | 83 | } |
85 | } | 84 | } |
86 | 85 | ||
87 | int Field::getBall(int x, int y) | 86 | int Field::getBall(int x, int y) |
88 | { | 87 | { |
89 | if( checkBounds(x,y) ) | 88 | if( checkBounds(x,y) ) |
90 | return field[y][x].getColor(); | 89 | return field[y][x].getColor(); |
91 | else | 90 | else |
92 | return NOBALL; | 91 | return NOBALL; |
93 | } | 92 | } |
94 | int Field::getAnim(int x, int y) | 93 | int Field::getAnim(int x, int y) |
95 | { | 94 | { |
96 | if( checkBounds(x,y) ) | 95 | if( checkBounds(x,y) ) |
97 | return field[y][x].getAnim(); | 96 | return field[y][x].getAnim(); |
98 | else | 97 | else |
99 | return NOBALL; | 98 | return NOBALL; |
100 | } | 99 | } |
101 | void Field::setAnim(int x, int y, int anim) | 100 | void Field::setAnim(int x, int y, int anim) |
102 | { | 101 | { |
103 | if( checkBounds(x,y) ) | 102 | if( checkBounds(x,y) ) |
104 | field[y][x].setAnim( anim ); | 103 | field[y][x].setAnim( anim ); |
105 | } | 104 | } |
106 | 105 | ||
107 | void Field::removeBall(int x, int y ) | 106 | void Field::removeBall(int x, int y ) |
108 | { | 107 | { |
109 | if( checkBounds(x,y) ) field[y][x].clear(); | 108 | if( checkBounds(x,y) ) field[y][x].clear(); |
110 | } | 109 | } |
111 | 110 | ||
112 | int Field::freeSpace() | 111 | int Field::freeSpace() |
113 | { | 112 | { |
114 | int s = 0; | 113 | int s = 0; |
115 | for(int y=0; y<NUMCELLSH; y++) | 114 | for(int y=0; y<NUMCELLSH; y++) |
116 | for(int x=0; x<NUMCELLSW; x++) | 115 | for(int x=0; x<NUMCELLSW; x++) |
117 | if(field[y][x].isFree()) s++; | 116 | if(field[y][x].isFree()) s++; |
118 | return s; | 117 | return s; |
119 | } | 118 | } |
120 | void Field::saveUndo() | 119 | void Field::saveUndo() |
121 | { | 120 | { |
122 | void clearAnim(); | 121 | void clearAnim(); |
123 | for(int y=0; y<NUMCELLSH; y++) | 122 | for(int y=0; y<NUMCELLSH; y++) |
124 | for(int x=0; x<NUMCELLSW; x++) | 123 | for(int x=0; x<NUMCELLSW; x++) |
125 | field_undo[y][x] = field[y][x]; | 124 | field_undo[y][x] = field[y][x]; |
126 | } | 125 | } |
127 | void Field::restoreUndo() | 126 | void Field::restoreUndo() |
128 | { | 127 | { |
129 | for(int y=0; y<NUMCELLSH; y++) | 128 | for(int y=0; y<NUMCELLSH; y++) |
130 | for(int x=0; x<NUMCELLSW; x++) | 129 | for(int x=0; x<NUMCELLSW; x++) |
131 | field[y][x] = field_undo[y][x]; | 130 | field[y][x] = field_undo[y][x]; |
132 | } | 131 | } |
diff --git a/noncore/games/zlines/klines.cpp b/noncore/games/zlines/klines.cpp index 02ff0db..76c94e2 100644 --- a/noncore/games/zlines/klines.cpp +++ b/noncore/games/zlines/klines.cpp | |||
@@ -1,214 +1,205 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | klines.cpp - description | 2 | klines.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Fri May 19 2000 | 4 | begin : Fri May 19 2000 |
5 | copyright : (C) 2000 by Roman Merzlyakov | 5 | copyright : (C) 2000 by Roman Merzlyakov |
6 | email : roman@sbrf.barrt.ru | 6 | email : roman@sbrf.barrt.ru |
7 | copyright : (C) 2000 by Roman Razilov | 7 | copyright : (C) 2000 by Roman Razilov |
8 | email : Roman.Razilov@gmx.de | 8 | email : Roman.Razilov@gmx.de |
9 | ***************************************************************************/ | 9 | ***************************************************************************/ |
10 | 10 | ||
11 | /*************************************************************************** | 11 | /*************************************************************************** |
12 | * * | 12 | * * |
13 | * This program is free software; you can redistribute it and/or modify * | 13 | * This program is free software; you can redistribute it and/or modify * |
14 | * it under the terms of the GNU General Public License as published by * | 14 | * it under the terms of the GNU General Public License as published by * |
15 | * the Free Software Foundation; either version 2 of the License, or * | 15 | * the Free Software Foundation; either version 2 of the License, or * |
16 | * (at your option) any later version. * | 16 | * (at your option) any later version. * |
17 | * * | 17 | * * |
18 | ***************************************************************************/ | 18 | ***************************************************************************/ |
19 | /* changes | 19 | /* changes |
20 | 21.05.2000 Roman Razilov Menu game/Next | 20 | 21.05.2000 Roman Razilov Menu game/Next |
21 | */ | 21 | */ |
22 | // | 22 | // |
23 | // The implementation of the KLines widget | 23 | // The implementation of the KLines widget |
24 | // | 24 | // |
25 | 25 | ||
26 | #include <qkeycode.h> | ||
27 | #include <qlabel.h> | ||
28 | #include <qpushbutton.h> | ||
29 | #include <qtooltip.h> | ||
30 | #include <qstring.h> | ||
31 | #include <stdlib.h> | 26 | #include <stdlib.h> |
32 | #include <unistd.h> | 27 | #include <unistd.h> |
33 | #include <time.h> | 28 | #include <time.h> |
34 | 29 | ||
35 | #include <qapplication.h> | 30 | #include <qapplication.h> |
36 | #include <qmenubar.h> | ||
37 | #include <qpopupmenu.h> | ||
38 | 31 | ||
39 | 32 | ||
40 | #include "cfg.h" | ||
41 | #include <qstatusbar.h> | ||
42 | #include "klines.h" | 33 | #include "klines.h" |
43 | 34 | ||
44 | 35 | ||
45 | /* | 36 | /* |
46 | Creates the KLines widget and sets saved options (if any). | 37 | Creates the KLines widget and sets saved options (if any). |
47 | */ | 38 | */ |
48 | 39 | ||
49 | KLines::KLines(QWidget *par, const char* n, WFlags fl) : QMainWindow(par,n,fl) | 40 | KLines::KLines(QWidget *par, const char* n, WFlags fl) : QMainWindow(par,n,fl) |
50 | { | 41 | { |
51 | time_t t; | 42 | time_t t; |
52 | time(&t); | 43 | time(&t); |
53 | srand((unsigned int)t + getpid()); | 44 | srand((unsigned int)t + getpid()); |
54 | 45 | ||
55 | setCaption(QString("ZLines")); | 46 | setCaption(QString("ZLines")); |
56 | 47 | ||
57 | mwidget = new MainWidget(this); | 48 | mwidget = new MainWidget(this); |
58 | setCentralWidget( mwidget ); | 49 | setCentralWidget( mwidget ); |
59 | 50 | ||
60 | lsb = mwidget->GetLsb(); | 51 | lsb = mwidget->GetLsb(); |
61 | lPrompt = mwidget->GetPrompt(); | 52 | lPrompt = mwidget->GetPrompt(); |
62 | 53 | ||
63 | menu = menuBar(); | 54 | menu = menuBar(); |
64 | game = new QPopupMenu; | 55 | game = new QPopupMenu; |
65 | edit = new QPopupMenu; | 56 | edit = new QPopupMenu; |
66 | 57 | ||
67 | game->insertItem(tr("&New game"), this, SLOT(stopGame()), CTRL+Key_N ); | 58 | game->insertItem(tr("&New game"), this, SLOT(stopGame()), CTRL+Key_N ); |
68 | game->insertSeparator(); | 59 | game->insertSeparator(); |
69 | game->insertItem(tr("Ne&xt"), this, SLOT(makeTurn()), Key_N ); | 60 | game->insertItem(tr("Ne&xt"), this, SLOT(makeTurn()), Key_N ); |
70 | game->insertSeparator(); | 61 | game->insertSeparator(); |
71 | idMenuPrompt = game->insertItem( tr("&Show next"), this, SLOT(switchPrompt()), CTRL+Key_P ); | 62 | idMenuPrompt = game->insertItem( tr("&Show next"), this, SLOT(switchPrompt()), CTRL+Key_P ); |
72 | game->setCheckable(true); | 63 | game->setCheckable(true); |
73 | game->setItemChecked(idMenuPrompt, lPrompt->getState()); | 64 | game->setItemChecked(idMenuPrompt, lPrompt->getState()); |
74 | game->insertSeparator(); | 65 | game->insertSeparator(); |
75 | game->insertItem(tr("&Quit"), qApp, SLOT(quit()), CTRL+Key_Q ); | 66 | game->insertItem(tr("&Quit"), qApp, SLOT(quit()), CTRL+Key_Q ); |
76 | 67 | ||
77 | idMenuUndo = edit->insertItem(tr("Und&o"), this, SLOT(undo()), CTRL+Key_Z ); | 68 | idMenuUndo = edit->insertItem(tr("Und&o"), this, SLOT(undo()), CTRL+Key_Z ); |
78 | 69 | ||
79 | menu->insertItem( tr("&Game"), game ); | 70 | menu->insertItem( tr("&Game"), game ); |
80 | menu->insertItem( tr("&Edit"), edit ); | 71 | menu->insertItem( tr("&Edit"), edit ); |
81 | 72 | ||
82 | menu->show(); | 73 | menu->show(); |
83 | 74 | ||
84 | score = 0; | 75 | score = 0; |
85 | prev_score = 0; | 76 | prev_score = 0; |
86 | 77 | ||
87 | mwidget->setMessage(tr("Points: 0")); | 78 | mwidget->setMessage(tr("Points: 0")); |
88 | 79 | ||
89 | startGame(); | 80 | startGame(); |
90 | } | 81 | } |
91 | 82 | ||
92 | /* | 83 | /* |
93 | Saves the options and destroys the KLines widget. | 84 | Saves the options and destroys the KLines widget. |
94 | */ | 85 | */ |
95 | 86 | ||
96 | KLines::~KLines() | 87 | KLines::~KLines() |
97 | { | 88 | { |
98 | } | 89 | } |
99 | 90 | ||
100 | /* | 91 | /* |
101 | Resize event of the KLines widget. | 92 | Resize event of the KLines widget. |
102 | */ | 93 | */ |
103 | 94 | ||
104 | void KLines::resizeEvent( QResizeEvent *e ) | 95 | void KLines::resizeEvent( QResizeEvent *e ) |
105 | { | 96 | { |
106 | QMainWindow::resizeEvent(e); | 97 | QMainWindow::resizeEvent(e); |
107 | } | 98 | } |
108 | 99 | ||
109 | void KLines::setMinSize() | 100 | void KLines::setMinSize() |
110 | { | 101 | { |
111 | // setMinimumSize( gr->wHint(), gr->hHint() + menu->height() + stat->height() + | 102 | // setMinimumSize( gr->wHint(), gr->hHint() + menu->height() + stat->height() + |
112 | // tool->height() ); | 103 | // tool->height() ); |
113 | } | 104 | } |
114 | 105 | ||
115 | void KLines::startGame() | 106 | void KLines::startGame() |
116 | { | 107 | { |
117 | score = 0; | 108 | score = 0; |
118 | prev_score = 0; | 109 | prev_score = 0; |
119 | bUndo=TRUE; | 110 | bUndo=TRUE; |
120 | 111 | ||
121 | lsb->clearField(); | 112 | lsb->clearField(); |
122 | generateRandomBalls(); | 113 | generateRandomBalls(); |
123 | placeBalls(); | 114 | placeBalls(); |
124 | generateRandomBalls(); | 115 | generateRandomBalls(); |
125 | edit->setItemEnabled(idMenuUndo, FALSE ); | 116 | edit->setItemEnabled(idMenuUndo, FALSE ); |
126 | updateStat(); | 117 | updateStat(); |
127 | } | 118 | } |
128 | void KLines::stopGame() | 119 | void KLines::stopGame() |
129 | { | 120 | { |
130 | debug("Klines::stopGame"); | 121 | debug("Klines::stopGame"); |
131 | endGame(); | 122 | endGame(); |
132 | } | 123 | } |
133 | 124 | ||
134 | void KLines::searchBallsLine() | 125 | void KLines::searchBallsLine() |
135 | { | 126 | { |
136 | } | 127 | } |
137 | 128 | ||
138 | void KLines::generateRandomBalls() | 129 | void KLines::generateRandomBalls() |
139 | { | 130 | { |
140 | 131 | ||
141 | for( int i = 0 ; i < BALLSDROP ; i++ ) | 132 | for( int i = 0 ; i < BALLSDROP ; i++ ) |
142 | { | 133 | { |
143 | nextBalls_undo[i] = nextBalls[i]; | 134 | nextBalls_undo[i] = nextBalls[i]; |
144 | nextBalls[i] = bUndo ? | 135 | nextBalls[i] = bUndo ? |
145 | rand() % NCOLORS: | 136 | rand() % NCOLORS: |
146 | nextBalls_redo[i]; | 137 | nextBalls_redo[i]; |
147 | } | 138 | } |
148 | lPrompt->SetBalls(nextBalls); | 139 | lPrompt->SetBalls(nextBalls); |
149 | } | 140 | } |
150 | 141 | ||
151 | void KLines::placeBalls() | 142 | void KLines::placeBalls() |
152 | { | 143 | { |
153 | lsb->placeBalls(nextBalls); | 144 | lsb->placeBalls(nextBalls); |
154 | debug("exit from placeBalls"); | 145 | debug("exit from placeBalls"); |
155 | } | 146 | } |
156 | 147 | ||
157 | void KLines::undo() | 148 | void KLines::undo() |
158 | { | 149 | { |
159 | debug("Undo"); | 150 | debug("Undo"); |
160 | if (!bUndo) | 151 | if (!bUndo) |
161 | return; | 152 | return; |
162 | for( int i = 0 ; i < BALLSDROP ; i++ ) | 153 | for( int i = 0 ; i < BALLSDROP ; i++ ) |
163 | { | 154 | { |
164 | nextBalls_redo[i] = nextBalls[i]; | 155 | nextBalls_redo[i] = nextBalls[i]; |
165 | nextBalls[i] = nextBalls_undo[i]; | 156 | nextBalls[i] = nextBalls_undo[i]; |
166 | } | 157 | } |
167 | lPrompt->SetBalls(nextBalls); | 158 | lPrompt->SetBalls(nextBalls); |
168 | lsb->undo(); | 159 | lsb->undo(); |
169 | switchUndo(FALSE); | 160 | switchUndo(FALSE); |
170 | } | 161 | } |
171 | 162 | ||
172 | void KLines::makeTurn() | 163 | void KLines::makeTurn() |
173 | { | 164 | { |
174 | placeBalls(); | 165 | placeBalls(); |
175 | generateRandomBalls(); | 166 | generateRandomBalls(); |
176 | switchUndo(TRUE); | 167 | switchUndo(TRUE); |
177 | } | 168 | } |
178 | 169 | ||
179 | void KLines::addScore(int ballsErased) | 170 | void KLines::addScore(int ballsErased) |
180 | { if(ballsErased >= 5){ | 171 | { if(ballsErased >= 5){ |
181 | score += 2*ballsErased*ballsErased - 20*ballsErased + 60 ; | 172 | score += 2*ballsErased*ballsErased - 20*ballsErased + 60 ; |
182 | if( !lPrompt->getState() ) score+= 1; | 173 | if( !lPrompt->getState() ) score+= 1; |
183 | updateStat(); | 174 | updateStat(); |
184 | }; | 175 | }; |
185 | } | 176 | } |
186 | 177 | ||
187 | void KLines::updateStat() | 178 | void KLines::updateStat() |
188 | { | 179 | { |
189 | mwidget->setMessage(tr(" Score: %1 ").arg(score)); | 180 | mwidget->setMessage(tr(" Score: %1 ").arg(score)); |
190 | } | 181 | } |
191 | 182 | ||
192 | void KLines::endGame() | 183 | void KLines::endGame() |
193 | { | 184 | { |
194 | startGame(); | 185 | startGame(); |
195 | } | 186 | } |
196 | 187 | ||
197 | void KLines::switchPrompt() | 188 | void KLines::switchPrompt() |
198 | { | 189 | { |
199 | lPrompt->setPrompt(!lPrompt->getState()); | 190 | lPrompt->setPrompt(!lPrompt->getState()); |
200 | game->setItemChecked(idMenuPrompt, lPrompt->getState()); | 191 | game->setItemChecked(idMenuPrompt, lPrompt->getState()); |
201 | } | 192 | } |
202 | 193 | ||
203 | void KLines::switchUndo(bool bu) | 194 | void KLines::switchUndo(bool bu) |
204 | { | 195 | { |
205 | bUndo = bu; | 196 | bUndo = bu; |
206 | edit->setItemEnabled(idMenuUndo, bUndo ); | 197 | edit->setItemEnabled(idMenuUndo, bUndo ); |
207 | } | 198 | } |
208 | 199 | ||
209 | void KLines::help() | 200 | void KLines::help() |
210 | { | 201 | { |
211 | // KApplication::getKApplication()->invokeHTMLHelp("", ""); | 202 | // KApplication::getKApplication()->invokeHTMLHelp("", ""); |
212 | } | 203 | } |
213 | 204 | ||
214 | 205 | ||
diff --git a/noncore/games/zlines/linesboard.cpp b/noncore/games/zlines/linesboard.cpp index 0965b2c..1e59aeb 100644 --- a/noncore/games/zlines/linesboard.cpp +++ b/noncore/games/zlines/linesboard.cpp | |||
@@ -1,534 +1,531 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | linesboard.cpp - description | 2 | linesboard.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Fri May 19 2000 | 4 | begin : Fri May 19 2000 |
5 | copyright : (C) 2000 by Roman Merzlyakov | 5 | copyright : (C) 2000 by Roman Merzlyakov |
6 | email : roman@sbrf.barrt.ru | 6 | email : roman@sbrf.barrt.ru |
7 | copyright : (C) 2000 by Roman Razilov | 7 | copyright : (C) 2000 by Roman Razilov |
8 | email : Roman.Razilov@gmx.de | 8 | email : Roman.Razilov@gmx.de |
9 | ***************************************************************************/ | 9 | ***************************************************************************/ |
10 | 10 | ||
11 | /*************************************************************************** | 11 | /*************************************************************************** |
12 | * * | 12 | * * |
13 | * This program is free software; you can redistribute it and/or modify * | 13 | * This program is free software; you can redistribute it and/or modify * |
14 | * it under the terms of the GNU General Public License as published by * | 14 | * it under the terms of the GNU General Public License as published by * |
15 | * the Free Software Foundation; either version 2 of the License, or * | 15 | * the Free Software Foundation; either version 2 of the License, or * |
16 | * (at your option) any later version. * | 16 | * (at your option) any later version. * |
17 | * * | 17 | * * |
18 | ***************************************************************************/ | 18 | ***************************************************************************/ |
19 | #include <qpainter.h> | 19 | #include <qpainter.h> |
20 | #include <qpixmap.h> | ||
21 | #include <qcolor.h> | ||
22 | #include <qkeycode.h> | ||
23 | #include <stdlib.h> | 20 | #include <stdlib.h> |
24 | 21 | ||
25 | #include "linesboard.h" | 22 | #include "linesboard.h" |
26 | 23 | ||
27 | /* | 24 | /* |
28 | Constructs a LinesBoard widget. | 25 | Constructs a LinesBoard widget. |
29 | */ | 26 | */ |
30 | 27 | ||
31 | LinesBoard::LinesBoard( BallPainter * abPainter, QWidget* parent, const char* name ) | 28 | LinesBoard::LinesBoard( BallPainter * abPainter, QWidget* parent, const char* name ) |
32 | : Field( parent, name ) | 29 | : Field( parent, name ) |
33 | { | 30 | { |
34 | anim = ANIM_NO; | 31 | anim = ANIM_NO; |
35 | // waypos = 0; | 32 | // waypos = 0; |
36 | // waylen = 0; | 33 | // waylen = 0; |
37 | // jumpingRow = -1; | 34 | // jumpingRow = -1; |
38 | // jumpingCol = -1; | 35 | // jumpingCol = -1; |
39 | painting = 0; | 36 | painting = 0; |
40 | way = new Waypoints[NUMCELLSW*NUMCELLSH]; | 37 | way = new Waypoints[NUMCELLSW*NUMCELLSH]; |
41 | 38 | ||
42 | bPainter = abPainter; | 39 | bPainter = abPainter; |
43 | 40 | ||
44 | setFocusPolicy( NoFocus ); | 41 | setFocusPolicy( NoFocus ); |
45 | setBackgroundColor( gray ); | 42 | setBackgroundColor( gray ); |
46 | 43 | ||
47 | setMouseTracking( FALSE ); | 44 | setMouseTracking( FALSE ); |
48 | setFixedSize(wHint(), hHint()); | 45 | setFixedSize(wHint(), hHint()); |
49 | 46 | ||
50 | timer = new QTimer(this); | 47 | timer = new QTimer(this); |
51 | connect( timer, SIGNAL(timeout()), SLOT(timerSlot()) ); | 48 | connect( timer, SIGNAL(timeout()), SLOT(timerSlot()) ); |
52 | timer->start( TIMERCLOCK, FALSE ); | 49 | timer->start( TIMERCLOCK, FALSE ); |
53 | 50 | ||
54 | } | 51 | } |
55 | 52 | ||
56 | /* | 53 | /* |
57 | Destructor: deallocates memory for contents | 54 | Destructor: deallocates memory for contents |
58 | */ | 55 | */ |
59 | 56 | ||
60 | LinesBoard::~LinesBoard() | 57 | LinesBoard::~LinesBoard() |
61 | { | 58 | { |
62 | // debug("stop"); | 59 | // debug("stop"); |
63 | timer->stop(); | 60 | timer->stop(); |
64 | delete timer; | 61 | delete timer; |
65 | delete []way; | 62 | delete []way; |
66 | } | 63 | } |
67 | 64 | ||
68 | 65 | ||
69 | void LinesBoard::placeBalls(int pnextBalls[BALLSDROP]) | 66 | void LinesBoard::placeBalls(int pnextBalls[BALLSDROP]) |
70 | { | 67 | { |
71 | debug("LinesBoard::placeBalls( )"); | 68 | debug("LinesBoard::placeBalls( )"); |
72 | for(int i=0; i < BALLSDROP; i++){ | 69 | for(int i=0; i < BALLSDROP; i++){ |
73 | nextBalls[i] = pnextBalls[i]; | 70 | nextBalls[i] = pnextBalls[i]; |
74 | } | 71 | } |
75 | nextBallToPlace = 0; | 72 | nextBallToPlace = 0; |
76 | placeBall(); | 73 | placeBall(); |
77 | debug("LinesBoard::placeBalls End "); | 74 | debug("LinesBoard::placeBalls End "); |
78 | } | 75 | } |
79 | void LinesBoard::placeBall( ) | 76 | void LinesBoard::placeBall( ) |
80 | { | 77 | { |
81 | int color = nextBalls[nextBallToPlace]; | 78 | int color = nextBalls[nextBallToPlace]; |
82 | debug("LinesBoard::placeBall( ) color=%i, nextBallToPlace = %i", color, nextBallToPlace); | 79 | debug("LinesBoard::placeBall( ) color=%i, nextBallToPlace = %i", color, nextBallToPlace); |
83 | char* xx = (char*)malloc( sizeof(char)*NUMCELLSW*NUMCELLSH ); | 80 | char* xx = (char*)malloc( sizeof(char)*NUMCELLSW*NUMCELLSH ); |
84 | char* yy = (char*)malloc( sizeof(char)*NUMCELLSW*NUMCELLSH ); | 81 | char* yy = (char*)malloc( sizeof(char)*NUMCELLSW*NUMCELLSH ); |
85 | // int nb=3; | 82 | // int nb=3; |
86 | // if( freeSpace() < 3) nb = freeSpace(); | 83 | // if( freeSpace() < 3) nb = freeSpace(); |
87 | int empty=0; | 84 | int empty=0; |
88 | for(int y=0; y<NUMCELLSH; y++) | 85 | for(int y=0; y<NUMCELLSH; y++) |
89 | for(int x=0; x<NUMCELLSW; x++) | 86 | for(int x=0; x<NUMCELLSW; x++) |
90 | if( getBall(x,y) == NOBALL ) | 87 | if( getBall(x,y) == NOBALL ) |
91 | { | 88 | { |
92 | xx[empty] = x; | 89 | xx[empty] = x; |
93 | yy[empty] = y; | 90 | yy[empty] = y; |
94 | empty++; | 91 | empty++; |
95 | }; | 92 | }; |
96 | // debug("empty = %i",empty); | 93 | // debug("empty = %i",empty); |
97 | if ( empty > 0) | 94 | if ( empty > 0) |
98 | { | 95 | { |
99 | int pos = rand()%empty; | 96 | int pos = rand()%empty; |
100 | putBall( xx[pos], yy[pos], color ); | 97 | putBall( xx[pos], yy[pos], color ); |
101 | clearAnim(); | 98 | clearAnim(); |
102 | setAnim( xx[pos], yy[pos], ANIM_BORN ); | 99 | setAnim( xx[pos], yy[pos], ANIM_BORN ); |
103 | nextBallToPlace++; | 100 | nextBallToPlace++; |
104 | AnimStart(ANIM_BORN); | 101 | AnimStart(ANIM_BORN); |
105 | free(xx); | 102 | free(xx); |
106 | free(yy); | 103 | free(yy); |
107 | } | 104 | } |
108 | else | 105 | else |
109 | { | 106 | { |
110 | free(xx); | 107 | free(xx); |
111 | free(yy); | 108 | free(yy); |
112 | emit endGame(); | 109 | emit endGame(); |
113 | } | 110 | } |
114 | debug("LinesBoard::placeBall END"); | 111 | debug("LinesBoard::placeBall END"); |
115 | } | 112 | } |
116 | 113 | ||
117 | 114 | ||
118 | /*id LinesBoard::doAfterBalls() { | 115 | /*id LinesBoard::doAfterBalls() { |
119 | erase5Balls(); | 116 | erase5Balls(); |
120 | repaint(FALSE); | 117 | repaint(FALSE); |
121 | } | 118 | } |
122 | */ | 119 | */ |
123 | /* | 120 | /* |
124 | Sets the size of the table | 121 | Sets the size of the table |
125 | */ | 122 | */ |
126 | 123 | ||
127 | int LinesBoard::width() { return CELLSIZE * NUMCELLSW; } | 124 | int LinesBoard::width() { return CELLSIZE * NUMCELLSW; } |
128 | int LinesBoard::height() { return CELLSIZE * NUMCELLSH; } | 125 | int LinesBoard::height() { return CELLSIZE * NUMCELLSH; } |
129 | int LinesBoard::wHint() { return width(); } | 126 | int LinesBoard::wHint() { return width(); } |
130 | int LinesBoard::hHint() { return height(); } | 127 | int LinesBoard::hHint() { return height(); } |
131 | 128 | ||
132 | 129 | ||
133 | 130 | ||
134 | void LinesBoard::paintEvent( QPaintEvent* ) | 131 | void LinesBoard::paintEvent( QPaintEvent* ) |
135 | { | 132 | { |
136 | // debug("LinesBoard::paintEvent "); | 133 | // debug("LinesBoard::paintEvent "); |
137 | QPixmap pixmap(width(), height()); | 134 | QPixmap pixmap(width(), height()); |
138 | QPainter paint(&pixmap, this); | 135 | QPainter paint(&pixmap, this); |
139 | 136 | ||
140 | for( int y=0; y < NUMCELLSH; y++ ){ | 137 | for( int y=0; y < NUMCELLSH; y++ ){ |
141 | for( int x=0; x < NUMCELLSW; x++ ){ | 138 | for( int x=0; x < NUMCELLSW; x++ ){ |
142 | if( getBall(x,y) == NOBALL ) | 139 | if( getBall(x,y) == NOBALL ) |
143 | { | 140 | { |
144 | // debug("draw empty %i %i", x, y ); | 141 | // debug("draw empty %i %i", x, y ); |
145 | paint.drawPixmap(x*CELLSIZE, y*CELLSIZE, *(bPainter->GetBackgroundPix()) ); | 142 | paint.drawPixmap(x*CELLSIZE, y*CELLSIZE, *(bPainter->GetBackgroundPix()) ); |
146 | } | 143 | } |
147 | else | 144 | else |
148 | { | 145 | { |
149 | // debug("draw empty %i %i %c", x, y, getBall(x,y) ); | 146 | // debug("draw empty %i %i %c", x, y, getBall(x,y) ); |
150 | paint.drawPixmap(x*CELLSIZE, y*CELLSIZE, | 147 | paint.drawPixmap(x*CELLSIZE, y*CELLSIZE, |
151 | *(bPainter->GetBall(getBall(x,y),animstep,getAnim(x,y)))); | 148 | *(bPainter->GetBall(getBall(x,y),animstep,getAnim(x,y)))); |
152 | } | 149 | } |
153 | } | 150 | } |
154 | } | 151 | } |
155 | 152 | ||
156 | bitBlt(this, 0,0, &pixmap, 0,0, width(), height(), CopyROP); | 153 | bitBlt(this, 0,0, &pixmap, 0,0, width(), height(), CopyROP); |
157 | } | 154 | } |
158 | 155 | ||
159 | /* | 156 | /* |
160 | Handles mouse press events for the LinesBoard widget. | 157 | Handles mouse press events for the LinesBoard widget. |
161 | */ | 158 | */ |
162 | void LinesBoard::mousePressEvent( QMouseEvent* e ) | 159 | void LinesBoard::mousePressEvent( QMouseEvent* e ) |
163 | { | 160 | { |
164 | debug("LinesBoard::mousePressEvent START"); | 161 | debug("LinesBoard::mousePressEvent START"); |
165 | int curRow = e->y() / CELLSIZE; | 162 | int curRow = e->y() / CELLSIZE; |
166 | int curCol = e->x() / CELLSIZE; | 163 | int curCol = e->x() / CELLSIZE; |
167 | //debug | 164 | //debug |
168 | debug("Mouse pressed: curRow=%i, curCol=%i", curRow, curCol); | 165 | debug("Mouse pressed: curRow=%i, curCol=%i", curRow, curCol); |
169 | 166 | ||
170 | //check range | 167 | //check range |
171 | if (!checkBounds( curCol, curRow ) ) | 168 | if (!checkBounds( curCol, curRow ) ) |
172 | return; | 169 | return; |
173 | // if( running || anim != ANIM_NO ) return; | 170 | // if( running || anim != ANIM_NO ) return; |
174 | if(anim != ANIM_JUMP && anim != ANIM_NO) return; | 171 | if(anim != ANIM_JUMP && anim != ANIM_NO) return; |
175 | if ( anim == ANIM_JUMP ) | 172 | if ( anim == ANIM_JUMP ) |
176 | { | 173 | { |
177 | if ( getBall(curCol,curRow) == NOBALL ) | 174 | if ( getBall(curCol,curRow) == NOBALL ) |
178 | { | 175 | { |
179 | if(existPath(jumpingCol, jumpingRow, curCol, curRow)) | 176 | if(existPath(jumpingCol, jumpingRow, curCol, curRow)) |
180 | { | 177 | { |
181 | saveUndo(); | 178 | saveUndo(); |
182 | AnimStart(ANIM_RUN); | 179 | AnimStart(ANIM_RUN); |
183 | } | 180 | } |
184 | } | 181 | } |
185 | else | 182 | else |
186 | AnimJump(curCol,curRow); | 183 | AnimJump(curCol,curRow); |
187 | } | 184 | } |
188 | else | 185 | else |
189 | AnimJump(curCol,curRow); | 186 | AnimJump(curCol,curRow); |
190 | debug("LinesBoard::mousePressEvent END"); | 187 | debug("LinesBoard::mousePressEvent END"); |
191 | } | 188 | } |
192 | void LinesBoard::AnimJump(int x, int y ) { | 189 | void LinesBoard::AnimJump(int x, int y ) { |
193 | debug("LinesBoard::AnimJump( %i,%i)", x,y ); | 190 | debug("LinesBoard::AnimJump( %i,%i)", x,y ); |
194 | if ( getBall(x,y) != NOBALL ) | 191 | if ( getBall(x,y) != NOBALL ) |
195 | if (!( anim == ANIM_JUMP && jumpingCol == x && jumpingRow == y )) | 192 | if (!( anim == ANIM_JUMP && jumpingCol == x && jumpingRow == y )) |
196 | if ( AnimEnd() ) | 193 | if ( AnimEnd() ) |
197 | { | 194 | { |
198 | clearAnim(); | 195 | clearAnim(); |
199 | setAnim(x,y,ANIM_JUMP); | 196 | setAnim(x,y,ANIM_JUMP); |
200 | jumpingCol = x; | 197 | jumpingCol = x; |
201 | jumpingRow = y; | 198 | jumpingRow = y; |
202 | AnimStart(ANIM_JUMP); | 199 | AnimStart(ANIM_JUMP); |
203 | } | 200 | } |
204 | debug("LinesBoard::AnimJump END"); | 201 | debug("LinesBoard::AnimJump END"); |
205 | } | 202 | } |
206 | void LinesBoard::AnimStart(int panim) { | 203 | void LinesBoard::AnimStart(int panim) { |
207 | debug("LinesBoard::AnimStart( %i )", panim); | 204 | debug("LinesBoard::AnimStart( %i )", panim); |
208 | if (anim != ANIM_NO) | 205 | if (anim != ANIM_NO) |
209 | AnimEnd(); | 206 | AnimEnd(); |
210 | animstep = 0; | 207 | animstep = 0; |
211 | animdelaystart = 1; | 208 | animdelaystart = 1; |
212 | switch(panim) { | 209 | switch(panim) { |
213 | case ANIM_NO: | 210 | case ANIM_NO: |
214 | break; | 211 | break; |
215 | case ANIM_BORN: | 212 | case ANIM_BORN: |
216 | debug("LinesBoard::AnimStart( ANIM_BORN )"); | 213 | debug("LinesBoard::AnimStart( ANIM_BORN )"); |
217 | animdelaystart=1; | 214 | animdelaystart=1; |
218 | animmax = BOOMBALLS; | 215 | animmax = BOOMBALLS; |
219 | break; | 216 | break; |
220 | case ANIM_JUMP: | 217 | case ANIM_JUMP: |
221 | direction = -1; | 218 | direction = -1; |
222 | animstep = 4; | 219 | animstep = 4; |
223 | animmax = PIXTIME -1; | 220 | animmax = PIXTIME -1; |
224 | break; | 221 | break; |
225 | case ANIM_RUN: | 222 | case ANIM_RUN: |
226 | animdelaystart=3; | 223 | animdelaystart=3; |
227 | // do first step on next timer; | 224 | // do first step on next timer; |
228 | animdelaycount = 0; | 225 | animdelaycount = 0; |
229 | // animmax already set | 226 | // animmax already set |
230 | break; | 227 | break; |
231 | case ANIM_BURN: | 228 | case ANIM_BURN: |
232 | animdelaystart=1; | 229 | animdelaystart=1; |
233 | animmax = FIREBALLS + FIREPIX - 1; | 230 | animmax = FIREBALLS + FIREPIX - 1; |
234 | break; | 231 | break; |
235 | default: | 232 | default: |
236 | ; | 233 | ; |
237 | } | 234 | } |
238 | anim = panim; | 235 | anim = panim; |
239 | animdelaycount = animdelaystart; | 236 | animdelaycount = animdelaystart; |
240 | debug("LinesBoard::AnimStart END"); | 237 | debug("LinesBoard::AnimStart END"); |
241 | } | 238 | } |
242 | int LinesBoard::AnimEnd( ) | 239 | int LinesBoard::AnimEnd( ) |
243 | { | 240 | { |
244 | debug("LinesBoard::AnimEnd( %i )",anim ); | 241 | debug("LinesBoard::AnimEnd( %i )",anim ); |
245 | if (anim == ANIM_NO ) return true; | 242 | if (anim == ANIM_NO ) return true; |
246 | int oldanim = anim; | 243 | int oldanim = anim; |
247 | anim = ANIM_NO; | 244 | anim = ANIM_NO; |
248 | if (oldanim == ANIM_RUN) { | 245 | if (oldanim == ANIM_RUN) { |
249 | if (animstep != animmax) { | 246 | if (animstep != animmax) { |
250 | moveBall(way[animstep].x,way[animstep].y,way[animmax].x,way[animmax].y); | 247 | moveBall(way[animstep].x,way[animstep].y,way[animmax].x,way[animmax].y); |
251 | } | 248 | } |
252 | if ( erase5Balls() == 0 ) { | 249 | if ( erase5Balls() == 0 ) { |
253 | // debug("end turn"); | 250 | // debug("end turn"); |
254 | emit endTurn(); | 251 | emit endTurn(); |
255 | debug("LinesBoard::AnimEnd END true 1"); | 252 | debug("LinesBoard::AnimEnd END true 1"); |
256 | return true; | 253 | return true; |
257 | } | 254 | } |
258 | else | 255 | else |
259 | debug("LinesBoard::AnimEnd END false 2"); | 256 | debug("LinesBoard::AnimEnd END false 2"); |
260 | return false; | 257 | return false; |
261 | } else if ( oldanim == ANIM_BURN ) | 258 | } else if ( oldanim == ANIM_BURN ) |
262 | { | 259 | { |
263 | emit eraseLine( deleteAnimatedBalls() ); | 260 | emit eraseLine( deleteAnimatedBalls() ); |
264 | repaint(FALSE); | 261 | repaint(FALSE); |
265 | if ( nextBallToPlace < BALLSDROP ) | 262 | if ( nextBallToPlace < BALLSDROP ) |
266 | { | 263 | { |
267 | placeBall(); | 264 | placeBall(); |
268 | // continue with born | 265 | // continue with born |
269 | debug("LinesBoard::AnimEnd END false 3"); | 266 | debug("LinesBoard::AnimEnd END false 3"); |
270 | return false; | 267 | return false; |
271 | } | 268 | } |
272 | else | 269 | else |
273 | { | 270 | { |
274 | // emit endTurn(); | 271 | // emit endTurn(); |
275 | debug("LinesBoard::AnimEnd END true 4"); | 272 | debug("LinesBoard::AnimEnd END true 4"); |
276 | return true; | 273 | return true; |
277 | } | 274 | } |
278 | } else if ( oldanim == ANIM_BORN ) | 275 | } else if ( oldanim == ANIM_BORN ) |
279 | { | 276 | { |
280 | if ( erase5Balls() == 0 ) | 277 | if ( erase5Balls() == 0 ) |
281 | { | 278 | { |
282 | if ( freeSpace() > 0) | 279 | if ( freeSpace() > 0) |
283 | { | 280 | { |
284 | if ( nextBallToPlace < BALLSDROP ) | 281 | if ( nextBallToPlace < BALLSDROP ) |
285 | { | 282 | { |
286 | placeBall(); | 283 | placeBall(); |
287 | debug("LinesBoard::AnimEnd END false 5"); | 284 | debug("LinesBoard::AnimEnd END false 5"); |
288 | return false; | 285 | return false; |
289 | } | 286 | } |
290 | else | 287 | else |
291 | { | 288 | { |
292 | debug("LinesBoard::AnimEnd END true 6"); | 289 | debug("LinesBoard::AnimEnd END true 6"); |
293 | return true; | 290 | return true; |
294 | } | 291 | } |
295 | } | 292 | } |
296 | else | 293 | else |
297 | { | 294 | { |
298 | debug("emit endGame"); | 295 | debug("emit endGame"); |
299 | emit endGame(); | 296 | emit endGame(); |
300 | debug("LinesBoard::AnimEnd END false 7"); | 297 | debug("LinesBoard::AnimEnd END false 7"); |
301 | return false; | 298 | return false; |
302 | } | 299 | } |
303 | } | 300 | } |
304 | else | 301 | else |
305 | { | 302 | { |
306 | // wait for user input | 303 | // wait for user input |
307 | debug("LinesBoard::AnimEnd END true 8"); | 304 | debug("LinesBoard::AnimEnd END true 8"); |
308 | return true; | 305 | return true; |
309 | } | 306 | } |
310 | } | 307 | } |
311 | else | 308 | else |
312 | { | 309 | { |
313 | debug("LinesBoard::AnimEnd END true"); | 310 | debug("LinesBoard::AnimEnd END true"); |
314 | return true; | 311 | return true; |
315 | } | 312 | } |
316 | return true; | 313 | return true; |
317 | } | 314 | } |
318 | void LinesBoard::AnimNext() { | 315 | void LinesBoard::AnimNext() { |
319 | if ( anim != ANIM_NO ) | 316 | if ( anim != ANIM_NO ) |
320 | { | 317 | { |
321 | debug("LinesBoard::AnimNext( ) anim %i animstep %i",anim,animstep); | 318 | debug("LinesBoard::AnimNext( ) anim %i animstep %i",anim,animstep); |
322 | if ( anim == ANIM_JUMP ) { | 319 | if ( anim == ANIM_JUMP ) { |
323 | if ( (direction > 0 && animstep == animmax) || ( direction < 0 && animstep == 0)) | 320 | if ( (direction > 0 && animstep == animmax) || ( direction < 0 && animstep == 0)) |
324 | direction = -direction; | 321 | direction = -direction; |
325 | animstep += direction; | 322 | animstep += direction; |
326 | repaint(FALSE); | 323 | repaint(FALSE); |
327 | } else { | 324 | } else { |
328 | if ( animstep >= animmax ) | 325 | if ( animstep >= animmax ) |
329 | AnimEnd(); | 326 | AnimEnd(); |
330 | else { | 327 | else { |
331 | animdelaycount--; | 328 | animdelaycount--; |
332 | if (animdelaycount <= 0) { | 329 | if (animdelaycount <= 0) { |
333 | debug("LinesBoard::AnimNext step %i", animstep); | 330 | debug("LinesBoard::AnimNext step %i", animstep); |
334 | if ( anim == ANIM_RUN ) | 331 | if ( anim == ANIM_RUN ) |
335 | moveBall(way[animstep].x,way[animstep].y,way[animstep+1].x,way[animstep+1].y); | 332 | moveBall(way[animstep].x,way[animstep].y,way[animstep+1].x,way[animstep+1].y); |
336 | animstep++; | 333 | animstep++; |
337 | animdelaycount = animdelaystart; | 334 | animdelaycount = animdelaystart; |
338 | repaint( FALSE ); | 335 | repaint( FALSE ); |
339 | } | 336 | } |
340 | } | 337 | } |
341 | } | 338 | } |
342 | debug("LinesBoard::AnimNext END"); | 339 | debug("LinesBoard::AnimNext END"); |
343 | } | 340 | } |
344 | } | 341 | } |
345 | int LinesBoard::getAnim( int x, int y ) | 342 | int LinesBoard::getAnim( int x, int y ) |
346 | { | 343 | { |
347 | // debug("LinesBoard::getAnim( %i,%i )",x,y); | 344 | // debug("LinesBoard::getAnim( %i,%i )",x,y); |
348 | return (( Field::getAnim(x,y) != ANIM_NO )? anim : ANIM_NO); | 345 | return (( Field::getAnim(x,y) != ANIM_NO )? anim : ANIM_NO); |
349 | } | 346 | } |
350 | 347 | ||
351 | void LinesBoard::timerSlot() | 348 | void LinesBoard::timerSlot() |
352 | { | 349 | { |
353 | // debug("LinesBoard::Timer() anim = %i",anim ); | 350 | // debug("LinesBoard::Timer() anim = %i",anim ); |
354 | AnimNext(); | 351 | AnimNext(); |
355 | } | 352 | } |
356 | 353 | ||
357 | int LinesBoard::erase5Balls() | 354 | int LinesBoard::erase5Balls() |
358 | { | 355 | { |
359 | //debug | 356 | //debug |
360 | debug("LinesBoard::erase5Balls()"); | 357 | debug("LinesBoard::erase5Balls()"); |
361 | 358 | ||
362 | int nb=5; // minimum balls for erasure | 359 | int nb=5; // minimum balls for erasure |
363 | 360 | ||
364 | bool bit_erase[NUMCELLSH][NUMCELLSW]; //bool array for balls, that must be erased | 361 | bool bit_erase[NUMCELLSH][NUMCELLSW]; //bool array for balls, that must be erased |
365 | for(int y=0; y<NUMCELLSH; y++) | 362 | for(int y=0; y<NUMCELLSH; y++) |
366 | for(int x=0; x<NUMCELLSW; x++) | 363 | for(int x=0; x<NUMCELLSW; x++) |
367 | bit_erase[y][x] = false; | 364 | bit_erase[y][x] = false; |
368 | 365 | ||
369 | int color,newcolor; | 366 | int color,newcolor; |
370 | int count; | 367 | int count; |
371 | //for horisontal | 368 | //for horisontal |
372 | //debug("entering to horiz"); | 369 | //debug("entering to horiz"); |
373 | 370 | ||
374 | for(int y=0; y<NUMCELLSH; y++) { | 371 | for(int y=0; y<NUMCELLSH; y++) { |
375 | count = 1; | 372 | count = 1; |
376 | color = NOBALL; | 373 | color = NOBALL; |
377 | for(int x=0; x<NUMCELLSW; x++){ | 374 | for(int x=0; x<NUMCELLSW; x++){ |
378 | if ( (newcolor = getBall(x,y)) == color) { | 375 | if ( (newcolor = getBall(x,y)) == color) { |
379 | if ( color != NOBALL) { | 376 | if ( color != NOBALL) { |
380 | count++; | 377 | count++; |
381 | if ( count >= nb ) | 378 | if ( count >= nb ) |
382 | if ( count == nb ) | 379 | if ( count == nb ) |
383 | for (int i = 0; i < nb; i++) | 380 | for (int i = 0; i < nb; i++) |
384 | bit_erase[y][x-i] = true; | 381 | bit_erase[y][x-i] = true; |
385 | else bit_erase[y][x] = true; | 382 | else bit_erase[y][x] = true; |
386 | } | 383 | } |
387 | } else { | 384 | } else { |
388 | color = newcolor; | 385 | color = newcolor; |
389 | count = 1; | 386 | count = 1; |
390 | } | 387 | } |
391 | } | 388 | } |
392 | } | 389 | } |
393 | 390 | ||
394 | //for vertical | 391 | //for vertical |
395 | //debug("entering to vert"); | 392 | //debug("entering to vert"); |
396 | for(int x=0; x<NUMCELLSW; x++) { | 393 | for(int x=0; x<NUMCELLSW; x++) { |
397 | count = 0; | 394 | count = 0; |
398 | color = NOBALL; | 395 | color = NOBALL; |
399 | for(int y=0; y<NUMCELLSH; y++){ | 396 | for(int y=0; y<NUMCELLSH; y++){ |
400 | if ( (newcolor = getBall(x,y)) == color) { | 397 | if ( (newcolor = getBall(x,y)) == color) { |
401 | if ( color != NOBALL) { | 398 | if ( color != NOBALL) { |
402 | count++; | 399 | count++; |
403 | if ( count >= nb ) | 400 | if ( count >= nb ) |
404 | if ( count == nb ) | 401 | if ( count == nb ) |
405 | for (int i = 0; i < nb; i++) | 402 | for (int i = 0; i < nb; i++) |
406 | bit_erase[y-i][x] = true; | 403 | bit_erase[y-i][x] = true; |
407 | else bit_erase[y][x] = true; | 404 | else bit_erase[y][x] = true; |
408 | } | 405 | } |
409 | } else { | 406 | } else { |
410 | color = newcolor; | 407 | color = newcolor; |
411 | count = 1; | 408 | count = 1; |
412 | } | 409 | } |
413 | } | 410 | } |
414 | } | 411 | } |
415 | 412 | ||
416 | 413 | ||
417 | // debug("entering to diag1"); | 414 | // debug("entering to diag1"); |
418 | //for left-down to rigth-up diagonal | 415 | //for left-down to rigth-up diagonal |
419 | for ( int xs = NUMCELLSW-1,ys = NUMCELLSH-nb; xs >= nb-1; ) { | 416 | for ( int xs = NUMCELLSW-1,ys = NUMCELLSH-nb; xs >= nb-1; ) { |
420 | count = 0; | 417 | count = 0; |
421 | color = NOBALL; | 418 | color = NOBALL; |
422 | for ( int x = xs, y = ys; x >= 0 && y < NUMCELLSH; x--, y++ ) { | 419 | for ( int x = xs, y = ys; x >= 0 && y < NUMCELLSH; x--, y++ ) { |
423 | if ( (newcolor = getBall(x,y)) == color) { | 420 | if ( (newcolor = getBall(x,y)) == color) { |
424 | if ( color != NOBALL) { | 421 | if ( color != NOBALL) { |
425 | count++; | 422 | count++; |
426 | if ( count >= nb ) | 423 | if ( count >= nb ) |
427 | if ( count == nb ) | 424 | if ( count == nb ) |
428 | for (int i = 0; i < nb; i++) | 425 | for (int i = 0; i < nb; i++) |
429 | bit_erase[y-i][x+i] = true; | 426 | bit_erase[y-i][x+i] = true; |
430 | else bit_erase[y][x] = true; | 427 | else bit_erase[y][x] = true; |
431 | } | 428 | } |
432 | } else { | 429 | } else { |
433 | color = newcolor; | 430 | color = newcolor; |
434 | count = 1; | 431 | count = 1; |
435 | } | 432 | } |
436 | } | 433 | } |
437 | if ( ys > 0 ) ys--; else xs--; | 434 | if ( ys > 0 ) ys--; else xs--; |
438 | } | 435 | } |
439 | 436 | ||
440 | //debug("entering to diag2"); | 437 | //debug("entering to diag2"); |
441 | 438 | ||
442 | //for left-up to rigth-down diagonal | 439 | //for left-up to rigth-down diagonal |
443 | for ( int xs = 0,ys = NUMCELLSH-nb; xs <= NUMCELLSW-nb; ) | 440 | for ( int xs = 0,ys = NUMCELLSH-nb; xs <= NUMCELLSW-nb; ) |
444 | { | 441 | { |
445 | count = 0; | 442 | count = 0; |
446 | color = NOBALL; | 443 | color = NOBALL; |
447 | for ( int x = xs, y = ys; x < NUMCELLSW && y < NUMCELLSH; x++, y++ ) | 444 | for ( int x = xs, y = ys; x < NUMCELLSW && y < NUMCELLSH; x++, y++ ) |
448 | { | 445 | { |
449 | if ( (newcolor = getBall(x,y)) == color) | 446 | if ( (newcolor = getBall(x,y)) == color) |
450 | { | 447 | { |
451 | if ( color != NOBALL) | 448 | if ( color != NOBALL) |
452 | { | 449 | { |
453 | count++; | 450 | count++; |
454 | if ( count >= nb ) | 451 | if ( count >= nb ) |
455 | if ( count == nb ) | 452 | if ( count == nb ) |
456 | for (int i = 0; i < nb; i++) | 453 | for (int i = 0; i < nb; i++) |
457 | bit_erase[y-i][x-i] = true; | 454 | bit_erase[y-i][x-i] = true; |
458 | else | 455 | else |
459 | bit_erase[y][x] = true; | 456 | bit_erase[y][x] = true; |
460 | } | 457 | } |
461 | } | 458 | } |
462 | else | 459 | else |
463 | { | 460 | { |
464 | color = newcolor; | 461 | color = newcolor; |
465 | count = 1; | 462 | count = 1; |
466 | } | 463 | } |
467 | } | 464 | } |
468 | if ( ys > 0 ) ys--; else xs++; | 465 | if ( ys > 0 ) ys--; else xs++; |
469 | } | 466 | } |
470 | 467 | ||
471 | //remove all lines balls, that more than nb | 468 | //remove all lines balls, that more than nb |
472 | int cb=0; | 469 | int cb=0; |
473 | for(int y=0; y < NUMCELLSH; y++) | 470 | for(int y=0; y < NUMCELLSH; y++) |
474 | for(int x=0; x < NUMCELLSW; x++) | 471 | for(int x=0; x < NUMCELLSW; x++) |
475 | { | 472 | { |
476 | if (bit_erase[y][x]) | 473 | if (bit_erase[y][x]) |
477 | { | 474 | { |
478 | setAnim(x,y,ANIM_YES); | 475 | setAnim(x,y,ANIM_YES); |
479 | cb++; | 476 | cb++; |
480 | } | 477 | } |
481 | else | 478 | else |
482 | { | 479 | { |
483 | setAnim(x,y,ANIM_NO); | 480 | setAnim(x,y,ANIM_NO); |
484 | } | 481 | } |
485 | } | 482 | } |
486 | //debug | 483 | //debug |
487 | debug("LinesBoard::erase5Balls marked %i balls", cb); | 484 | debug("LinesBoard::erase5Balls marked %i balls", cb); |
488 | if ( cb > 0 ) | 485 | if ( cb > 0 ) |
489 | { | 486 | { |
490 | AnimStart(ANIM_BURN); | 487 | AnimStart(ANIM_BURN); |
491 | //emit eraseLine(cb); | 488 | //emit eraseLine(cb); |
492 | } | 489 | } |
493 | 490 | ||
494 | //debug | 491 | //debug |
495 | debug("LinesBoard::erase5Balls END"); | 492 | debug("LinesBoard::erase5Balls END"); |
496 | return cb; | 493 | return cb; |
497 | } | 494 | } |
498 | 495 | ||
499 | 496 | ||
500 | #define GO_EMPTY 4 | 497 | #define GO_EMPTY 4 |
501 | #define GO_A 5 | 498 | #define GO_A 5 |
502 | #define GO_B 6 | 499 | #define GO_B 6 |
503 | #define GO_BALL 7 | 500 | #define GO_BALL 7 |
504 | 501 | ||
505 | bool LinesBoard::existPath(int bx, int by, int ax, int ay) | 502 | bool LinesBoard::existPath(int bx, int by, int ax, int ay) |
506 | { | 503 | { |
507 | debug("LinesBoard::existPath( %i, %i, %i, %i )", bx, by, ax, ay); | 504 | debug("LinesBoard::existPath( %i, %i, %i, %i )", bx, by, ax, ay); |
508 | int dx[4]={1,-1, 0, 0}; | 505 | int dx[4]={1,-1, 0, 0}; |
509 | int dy[4]={0, 0, 1,-1}; | 506 | int dy[4]={0, 0, 1,-1}; |
510 | 507 | ||
511 | // debug("path %i %i %i %i",bx,by,ax,ay); | 508 | // debug("path %i %i %i %i",bx,by,ax,ay); |
512 | if (getBall(ax,ay) != NOBALL) | 509 | if (getBall(ax,ay) != NOBALL) |
513 | return false; | 510 | return false; |
514 | 511 | ||
515 | char pf[NUMCELLSH][NUMCELLSW]; | 512 | char pf[NUMCELLSH][NUMCELLSW]; |
516 | for(int y=0; y<NUMCELLSH; y++) | 513 | for(int y=0; y<NUMCELLSH; y++) |
517 | for(int x=0; x<NUMCELLSW; x++) | 514 | for(int x=0; x<NUMCELLSW; x++) |
518 | pf[y][x] = (getBall(x,y) == NOBALL) ? GO_EMPTY:GO_BALL; | 515 | pf[y][x] = (getBall(x,y) == NOBALL) ? GO_EMPTY:GO_BALL; |
519 | 516 | ||
520 | Waypoints lastchanged[2][NUMCELLSH*NUMCELLSW]; | 517 | Waypoints lastchanged[2][NUMCELLSH*NUMCELLSW]; |
521 | 518 | ||
522 | int lastChangedCount[2]; | 519 | int lastChangedCount[2]; |
523 | int currentchanged = 0; | 520 | int currentchanged = 0; |
524 | int nextchanged = 1; | 521 | int nextchanged = 1; |
525 | lastchanged[currentchanged][0].x = ax; | 522 | lastchanged[currentchanged][0].x = ax; |
526 | lastchanged[currentchanged][0].y = ay; | 523 | lastchanged[currentchanged][0].y = ay; |
527 | lastChangedCount[currentchanged] = 1; | 524 | lastChangedCount[currentchanged] = 1; |
528 | pf[ay][ax]=GO_A; | 525 | pf[ay][ax]=GO_A; |
529 | pf[by][bx]=GO_B; | 526 | pf[by][bx]=GO_B; |
530 | 527 | ||
531 | // int expanded; | 528 | // int expanded; |
532 | bool B_reached = false; | 529 | bool B_reached = false; |
533 | 530 | ||
534 | do | 531 | do |
diff --git a/noncore/games/zlines/main.cpp b/noncore/games/zlines/main.cpp index ff41f95..238e7d3 100644 --- a/noncore/games/zlines/main.cpp +++ b/noncore/games/zlines/main.cpp | |||
@@ -1,30 +1,29 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | main.cpp - description | 2 | main.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Fri May 19 2000 | 4 | begin : Fri May 19 2000 |
5 | copyright : (C) 2000 by Roman Merzlyakov | 5 | copyright : (C) 2000 by Roman Merzlyakov |
6 | email : roman@sbrf.barrt.ru | 6 | email : roman@sbrf.barrt.ru |
7 | copyright : (C) 2000 by Roman Razilov | 7 | copyright : (C) 2000 by Roman Razilov |
8 | email : Roman.Razilov@gmx.de | 8 | email : Roman.Razilov@gmx.de |
9 | ***************************************************************************/ | 9 | ***************************************************************************/ |
10 | 10 | ||
11 | /*************************************************************************** | 11 | /*************************************************************************** |
12 | * * | 12 | * * |
13 | * This program is free software; you can redistribute it and/or modify * | 13 | * This program is free software; you can redistribute it and/or modify * |
14 | * it under the terms of the GNU General Public License as published by * | 14 | * it under the terms of the GNU General Public License as published by * |
15 | * the Free Software Foundation; either version 2 of the License, or * | 15 | * the Free Software Foundation; either version 2 of the License, or * |
16 | * (at your option) any later version. * | 16 | * (at your option) any later version. * |
17 | * * | 17 | * * |
18 | ***************************************************************************/ | 18 | ***************************************************************************/ |
19 | /* | 19 | /* |
20 | * Roman Razilov 2000-05-19 debug dummmy | 20 | * Roman Razilov 2000-05-19 debug dummmy |
21 | * Roman Razilov 2000-05-21 qimgio | 21 | * Roman Razilov 2000-05-21 qimgio |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <qglobal.h> | ||
25 | 24 | ||
26 | 25 | ||
27 | #include <opie/oapplicationfactory.h> | 26 | #include <opie/oapplicationfactory.h> |
28 | #include "klines.h" | 27 | #include "klines.h" |
29 | 28 | ||
30 | OPIE_EXPORT_APP( OApplicationFactory<KLines> ) | 29 | OPIE_EXPORT_APP( OApplicationFactory<KLines> ) |
diff --git a/noncore/games/zlines/mwidget.cpp b/noncore/games/zlines/mwidget.cpp index 6641fa2..211d3d3 100644 --- a/noncore/games/zlines/mwidget.cpp +++ b/noncore/games/zlines/mwidget.cpp | |||
@@ -1,84 +1,83 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | mwidget.cpp - description | 2 | mwidget.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Fri May 19 2000 | 4 | begin : Fri May 19 2000 |
5 | copyright : (C) 2000 by Roman Merzlyakov | 5 | copyright : (C) 2000 by Roman Merzlyakov |
6 | email : roman@sbrf.barrt.ru | 6 | email : roman@sbrf.barrt.ru |
7 | copyright : (C) 2000 by Roman Razilov | 7 | copyright : (C) 2000 by Roman Razilov |
8 | email : Roman.Razilov@gmx.de | 8 | email : Roman.Razilov@gmx.de |
9 | ***************************************************************************/ | 9 | ***************************************************************************/ |
10 | 10 | ||
11 | /*************************************************************************** | 11 | /*************************************************************************** |
12 | * * | 12 | * * |
13 | * This program is free software; you can redistribute it and/or modify * | 13 | * This program is free software; you can redistribute it and/or modify * |
14 | * it under the terms of the GNU General Public License as published by * | 14 | * it under the terms of the GNU General Public License as published by * |
15 | * the Free Software Foundation; either version 2 of the License, or * | 15 | * the Free Software Foundation; either version 2 of the License, or * |
16 | * (at your option) any later version. * | 16 | * (at your option) any later version. * |
17 | * * | 17 | * * |
18 | ***************************************************************************/ | 18 | ***************************************************************************/ |
19 | #include "mwidget.h" | 19 | #include "mwidget.h" |
20 | #include <qlayout.h> | 20 | #include <qlayout.h> |
21 | #include "ballpainter.h" | ||
22 | #include <qhbox.h> | 21 | #include <qhbox.h> |
23 | #include <qlabel.h> | 22 | #include <qlabel.h> |
24 | 23 | ||
25 | MainWidget::MainWidget( QWidget* parent, const char* name ) | 24 | MainWidget::MainWidget( QWidget* parent, const char* name ) |
26 | : QFrame( parent, name ) | 25 | : QFrame( parent, name ) |
27 | { | 26 | { |
28 | BallPainter *bPainter = new BallPainter(); | 27 | BallPainter *bPainter = new BallPainter(); |
29 | 28 | ||
30 | QGridLayout *Form1Layout = new QGridLayout( this ); | 29 | QGridLayout *Form1Layout = new QGridLayout( this ); |
31 | Form1Layout->setSpacing( 4 ); | 30 | Form1Layout->setSpacing( 4 ); |
32 | Form1Layout->setMargin( 4 ); | 31 | Form1Layout->setMargin( 4 ); |
33 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); | 32 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); |
34 | Form1Layout->addItem( spacer, 0, 0 ); | 33 | Form1Layout->addItem( spacer, 0, 0 ); |
35 | 34 | ||
36 | lsb = new LinesBoard(bPainter, this); | 35 | lsb = new LinesBoard(bPainter, this); |
37 | 36 | ||
38 | Form1Layout->addWidget( lsb, 0, 1 ); | 37 | Form1Layout->addWidget( lsb, 0, 1 ); |
39 | QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); | 38 | QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); |
40 | Form1Layout->addItem( spacer_2, 0, 2 ); | 39 | Form1Layout->addItem( spacer_2, 0, 2 ); |
41 | 40 | ||
42 | QHBox *bottom=new QHBox(this); | 41 | QHBox *bottom=new QHBox(this); |
43 | 42 | ||
44 | mPoints=new QLabel(bottom); | 43 | mPoints=new QLabel(bottom); |
45 | bottom->setStretchFactor(mPoints, 2); | 44 | bottom->setStretchFactor(mPoints, 2); |
46 | 45 | ||
47 | lPrompt = new LinesPrompt(bPainter, bottom); | 46 | lPrompt = new LinesPrompt(bPainter, bottom); |
48 | 47 | ||
49 | Form1Layout->addWidget( bottom, 1, 1 ); | 48 | Form1Layout->addWidget( bottom, 1, 1 ); |
50 | QSpacerItem* spacer_3 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); | 49 | QSpacerItem* spacer_3 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); |
51 | Form1Layout->addItem( spacer_3, 2, 1 ); | 50 | Form1Layout->addItem( spacer_3, 2, 1 ); |
52 | 51 | ||
53 | 52 | ||
54 | connect(lsb, SIGNAL(endTurn()), parent, SLOT(makeTurn())); | 53 | connect(lsb, SIGNAL(endTurn()), parent, SLOT(makeTurn())); |
55 | connect(lsb, SIGNAL(eraseLine(int)), parent, SLOT(addScore(int))); | 54 | connect(lsb, SIGNAL(eraseLine(int)), parent, SLOT(addScore(int))); |
56 | connect(lsb, SIGNAL(endGame()), parent, SLOT(stopGame())); | 55 | connect(lsb, SIGNAL(endGame()), parent, SLOT(stopGame())); |
57 | 56 | ||
58 | connect(lPrompt, SIGNAL(PromptPressed()), parent, SLOT(switchPrompt())); | 57 | connect(lPrompt, SIGNAL(PromptPressed()), parent, SLOT(switchPrompt())); |
59 | 58 | ||
60 | } | 59 | } |
61 | 60 | ||
62 | void MainWidget::setMessage(const QString &message) | 61 | void MainWidget::setMessage(const QString &message) |
63 | { | 62 | { |
64 | mPoints->setText(message); | 63 | mPoints->setText(message); |
65 | } | 64 | } |
66 | 65 | ||
67 | 66 | ||
68 | /* | 67 | /* |
69 | Destructor: deallocates memory for contents | 68 | Destructor: deallocates memory for contents |
70 | */ | 69 | */ |
71 | 70 | ||
72 | MainWidget::~MainWidget() | 71 | MainWidget::~MainWidget() |
73 | { | 72 | { |
74 | } | 73 | } |
75 | 74 | ||
76 | LinesBoard * MainWidget::GetLsb() | 75 | LinesBoard * MainWidget::GetLsb() |
77 | { | 76 | { |
78 | return lsb; | 77 | return lsb; |
79 | } | 78 | } |
80 | 79 | ||
81 | LinesPrompt * MainWidget::GetPrompt() | 80 | LinesPrompt * MainWidget::GetPrompt() |
82 | { | 81 | { |
83 | return lPrompt; | 82 | return lPrompt; |
84 | } | 83 | } |
diff --git a/noncore/games/zsame/StoneWidget.cpp b/noncore/games/zsame/StoneWidget.cpp index 49fa1a4..646fc9c 100644 --- a/noncore/games/zsame/StoneWidget.cpp +++ b/noncore/games/zsame/StoneWidget.cpp | |||
@@ -1,350 +1,345 @@ | |||
1 | /* | 1 | /* |
2 | * ksame 0.4 - simple Game | 2 | * ksame 0.4 - simple Game |
3 | * Copyright (C) 1997,1998 Marcus Kreutzberger | 3 | * Copyright (C) 1997,1998 Marcus Kreutzberger |
4 | * | 4 | * |
5 | * This program is free software; you can redistribute it and/or modify | 5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by | 6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation; either version 2 of the License, or | 7 | * the Free Software Foundation; either version 2 of the License, or |
8 | * (at your option) any later version. | 8 | * (at your option) any later version. |
9 | * | 9 | * |
10 | * This program is distributed in the hope that it will be useful, | 10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. | 13 | * GNU General Public License for more details. |
14 | * | 14 | * |
15 | * You should have received a copy of the GNU General Public License | 15 | * You should have received a copy of the GNU General Public License |
16 | * along with this program; if not, write to the Free Software | 16 | * along with this program; if not, write to the Free Software |
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | * | 18 | * |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <stdio.h> | 21 | #include <stdio.h> |
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | 23 | ||
24 | #include <qpainter.h> | ||
25 | #include <qpixmap.h> | ||
26 | #include <qbitmap.h> | ||
27 | #include <qimage.h> | ||
28 | #include <qcursor.h> | ||
29 | 24 | ||
30 | 25 | ||
31 | #include <qpe/resource.h> | 26 | #include <qpe/resource.h> |
32 | 27 | ||
33 | #include <time.h> | 28 | #include <time.h> |
34 | #include <assert.h> | 29 | #include <assert.h> |
35 | 30 | ||
36 | #include "StoneWidget.h" | 31 | #include "StoneWidget.h" |
37 | 32 | ||
38 | 33 | ||
39 | 34 | ||
40 | struct StoneSlice { | 35 | struct StoneSlice { |
41 | QPixmap stone; | 36 | QPixmap stone; |
42 | }; | 37 | }; |
43 | 38 | ||
44 | 39 | ||
45 | StoneWidget::StoneWidget( QWidget *parent, int x, int y ) | 40 | StoneWidget::StoneWidget( QWidget *parent, int x, int y ) |
46 | : QWidget(parent,"StoneWidget"), stonefield(x,y) | 41 | : QWidget(parent,"StoneWidget"), stonefield(x,y) |
47 | { | 42 | { |
48 | // setBackgroundPixmap(QPixmap(locate("wallpaper", "Time-For-Lunch-2.jpg"))); | 43 | // setBackgroundPixmap(QPixmap(locate("wallpaper", "Time-For-Lunch-2.jpg"))); |
49 | // QPixmap stonemap(locate("appdata", "stones.png")); | 44 | // QPixmap stonemap(locate("appdata", "stones.png")); |
50 | 45 | ||
51 | QPixmap stonemap = Resource::loadPixmap("zsame/stones" ); | 46 | QPixmap stonemap = Resource::loadPixmap("zsame/stones" ); |
52 | assert(!stonemap.isNull()); | 47 | assert(!stonemap.isNull()); |
53 | 48 | ||
54 | slice=0; | 49 | slice=0; |
55 | maxslices=30; | 50 | maxslices=30; |
56 | maxcolors=4; | 51 | maxcolors=4; |
57 | 52 | ||
58 | sizex=x; | 53 | sizex=x; |
59 | sizey=y; | 54 | sizey=y; |
60 | 55 | ||
61 | stone_width=stonemap.width()/(maxslices+1); | 56 | stone_width=stonemap.width()/(maxslices+1); |
62 | stone_height=stonemap.height()/maxcolors; | 57 | stone_height=stonemap.height()/maxcolors; |
63 | 58 | ||
64 | map = new StoneSlice*[maxcolors]; | 59 | map = new StoneSlice*[maxcolors]; |
65 | QBitmap mask; | 60 | QBitmap mask; |
66 | for (int c = 0; c < maxcolors; c++) { | 61 | for (int c = 0; c < maxcolors; c++) { |
67 | map[c] = new StoneSlice[maxslices]; | 62 | map[c] = new StoneSlice[maxslices]; |
68 | 63 | ||
69 | for (int s = 0; s < maxslices; s++) { | 64 | for (int s = 0; s < maxslices; s++) { |
70 | map[c][s].stone.resize(stone_width, stone_height); | 65 | map[c][s].stone.resize(stone_width, stone_height); |
71 | assert(!map[c][s].stone.isNull()); | 66 | assert(!map[c][s].stone.isNull()); |
72 | bitBlt(&map[c][s].stone, 0, 0, | 67 | bitBlt(&map[c][s].stone, 0, 0, |
73 | &stonemap, stone_width * s, | 68 | &stonemap, stone_width * s, |
74 | c*stone_height, | 69 | c*stone_height, |
75 | stone_width,stone_height,CopyROP,false); | 70 | stone_width,stone_height,CopyROP,false); |
76 | QImage im = map[c][s].stone.convertToImage(); | 71 | QImage im = map[c][s].stone.convertToImage(); |
77 | mask = im.createHeuristicMask(); | 72 | mask = im.createHeuristicMask(); |
78 | map[c][s].stone.setMask(mask); | 73 | map[c][s].stone.setMask(mask); |
79 | } | 74 | } |
80 | } | 75 | } |
81 | 76 | ||
82 | field_height=stone_height*sizey; | 77 | field_height=stone_height*sizey; |
83 | field_width=stone_width*sizex; | 78 | field_width=stone_width*sizex; |
84 | 79 | ||
85 | setMouseTracking(true); | 80 | setMouseTracking(true); |
86 | 81 | ||
87 | // QColor c(115,115,115); | 82 | // QColor c(115,115,115); |
88 | // setBackgroundColor(c); | 83 | // setBackgroundColor(c); |
89 | 84 | ||
90 | // emit s_sizechanged(); | 85 | // emit s_sizechanged(); |
91 | startTimer( 100 ); | 86 | startTimer( 100 ); |
92 | history.setAutoDelete(true); | 87 | history.setAutoDelete(true); |
93 | } | 88 | } |
94 | 89 | ||
95 | StoneWidget::~StoneWidget() { | 90 | StoneWidget::~StoneWidget() { |
96 | for (int c = 0; c < maxcolors; c++) { | 91 | for (int c = 0; c < maxcolors; c++) { |
97 | delete [] map[c]; | 92 | delete [] map[c]; |
98 | } | 93 | } |
99 | delete [] map; | 94 | delete [] map; |
100 | 95 | ||
101 | setMouseTracking(false); | 96 | setMouseTracking(false); |
102 | killTimers(); | 97 | killTimers(); |
103 | } | 98 | } |
104 | 99 | ||
105 | unsigned int | 100 | unsigned int |
106 | StoneWidget::board() { | 101 | StoneWidget::board() { |
107 | return stonefield.getBoard(); | 102 | return stonefield.getBoard(); |
108 | } | 103 | } |
109 | 104 | ||
110 | int | 105 | int |
111 | StoneWidget::score() { | 106 | StoneWidget::score() { |
112 | return stonefield.getScore(); | 107 | return stonefield.getScore(); |
113 | } | 108 | } |
114 | 109 | ||
115 | int | 110 | int |
116 | StoneWidget::marked() { | 111 | StoneWidget::marked() { |
117 | return stonefield.getMarked(); | 112 | return stonefield.getMarked(); |
118 | } | 113 | } |
119 | 114 | ||
120 | QSize | 115 | QSize |
121 | StoneWidget::size() { | 116 | StoneWidget::size() { |
122 | return QSize(sizex,sizey); | 117 | return QSize(sizex,sizey); |
123 | } | 118 | } |
124 | 119 | ||
125 | int | 120 | int |
126 | StoneWidget::colors() { | 121 | StoneWidget::colors() { |
127 | return stonefield.getColors(); | 122 | return stonefield.getColors(); |
128 | } | 123 | } |
129 | 124 | ||
130 | QSize | 125 | QSize |
131 | StoneWidget::sizeHint () const { | 126 | StoneWidget::sizeHint () const { |
132 | return QSize(field_width,field_height); | 127 | return QSize(field_width,field_height); |
133 | } | 128 | } |
134 | 129 | ||
135 | void | 130 | void |
136 | StoneWidget::newGame(unsigned int board,int colors) { | 131 | StoneWidget::newGame(unsigned int board,int colors) { |
137 | stonefield.newGame(board,colors); | 132 | stonefield.newGame(board,colors); |
138 | history.clear(); | 133 | history.clear(); |
139 | modified= false; | 134 | modified= false; |
140 | emit s_newgame(); | 135 | emit s_newgame(); |
141 | emit s_colors(stonefield.getColors()); | 136 | emit s_colors(stonefield.getColors()); |
142 | emit s_board(stonefield.getBoard()); | 137 | emit s_board(stonefield.getBoard()); |
143 | } | 138 | } |
144 | 139 | ||
145 | void | 140 | void |
146 | StoneWidget::reset() { | 141 | StoneWidget::reset() { |
147 | stonefield.reset(); | 142 | stonefield.reset(); |
148 | history.clear(); | 143 | history.clear(); |
149 | emit s_newgame(); | 144 | emit s_newgame(); |
150 | } | 145 | } |
151 | 146 | ||
152 | void | 147 | void |
153 | StoneWidget::unmark() { | 148 | StoneWidget::unmark() { |
154 | stonefield.unmark(); | 149 | stonefield.unmark(); |
155 | emit s_marked(0); | 150 | emit s_marked(0); |
156 | } | 151 | } |
157 | 152 | ||
158 | bool StoneWidget::undoPossible() const { | 153 | bool StoneWidget::undoPossible() const { |
159 | if (stonefield.isGameover()) return false; | 154 | if (stonefield.isGameover()) return false; |
160 | return stonefield.undoPossible(); | 155 | return stonefield.undoPossible(); |
161 | } | 156 | } |
162 | 157 | ||
163 | int | 158 | int |
164 | StoneWidget::undo(int count) { | 159 | StoneWidget::undo(int count) { |
165 | if (stonefield.isGameover()) return 0; | 160 | if (stonefield.isGameover()) return 0; |
166 | 161 | ||
167 | int ret_val=stonefield.undo(count); | 162 | int ret_val=stonefield.undo(count); |
168 | 163 | ||
169 | QPoint p=mapFromGlobal(cursor().pos()); | 164 | QPoint p=mapFromGlobal(cursor().pos()); |
170 | int x=p.x(); | 165 | int x=p.x(); |
171 | int y=p.y(); | 166 | int y=p.y(); |
172 | if (x<0||y<0||x>=field_width||y>=field_height) { | 167 | if (x<0||y<0||x>=field_width||y>=field_height) { |
173 | emit s_score(stonefield.getMarked()); | 168 | emit s_score(stonefield.getMarked()); |
174 | return ret_val; | 169 | return ret_val; |
175 | } | 170 | } |
176 | 171 | ||
177 | int marked=stonefield.mark(x/stone_width,y/stone_height); | 172 | int marked=stonefield.mark(x/stone_width,y/stone_height); |
178 | emit s_marked(marked); | 173 | emit s_marked(marked); |
179 | slice=0; | 174 | slice=0; |
180 | emit s_score(stonefield.getScore()); | 175 | emit s_score(stonefield.getScore()); |
181 | modified= (stonefield.getScore()>0); | 176 | modified= (stonefield.getScore()>0); |
182 | return ret_val; | 177 | return ret_val; |
183 | } | 178 | } |
184 | 179 | ||
185 | bool StoneWidget::isGameover() { | 180 | bool StoneWidget::isGameover() { |
186 | return stonefield.isGameover(); | 181 | return stonefield.isGameover(); |
187 | } | 182 | } |
188 | 183 | ||
189 | bool StoneWidget::hasBonus() { | 184 | bool StoneWidget::hasBonus() { |
190 | return stonefield.gotBonus(); // don't ask me why the names differ... ;-| [hlm] | 185 | return stonefield.gotBonus(); // don't ask me why the names differ... ;-| [hlm] |
191 | } | 186 | } |
192 | 187 | ||
193 | bool StoneWidget::isOriginalBoard() { | 188 | bool StoneWidget::isOriginalBoard() { |
194 | return !modified; | 189 | return !modified; |
195 | } | 190 | } |
196 | 191 | ||
197 | void StoneWidget::readProperties(Config *) { | 192 | void StoneWidget::readProperties(Config *) { |
198 | /* Q_ASSERT(conf); | 193 | /* Q_ASSERT(conf); |
199 | 194 | ||
200 | history.clear(); | 195 | history.clear(); |
201 | 196 | ||
202 | if (!conf->hasKey("Board")|| | 197 | if (!conf->hasKey("Board")|| |
203 | !conf->hasKey("Colors")|| | 198 | !conf->hasKey("Colors")|| |
204 | !conf->hasKey("Stones")) { | 199 | !conf->hasKey("Stones")) { |
205 | return; | 200 | return; |
206 | } | 201 | } |
207 | newGame(conf->readNumEntry("Board"),conf->readNumEntry("Colors")); | 202 | newGame(conf->readNumEntry("Board"),conf->readNumEntry("Colors")); |
208 | 203 | ||
209 | QStrList list; | 204 | QStrList list; |
210 | conf->readListEntry("Stones",list); | 205 | conf->readListEntry("Stones",list); |
211 | 206 | ||
212 | for (const char *item=list.first();item;item=list.next()) { | 207 | for (const char *item=list.first();item;item=list.next()) { |
213 | int x=-1,y=-1; | 208 | int x=-1,y=-1; |
214 | if (sscanf(item,"%02X%02X",&x,&y)!=2) break; | 209 | if (sscanf(item,"%02X%02X",&x,&y)!=2) break; |
215 | history.append(new QPoint(x,y)); | 210 | history.append(new QPoint(x,y)); |
216 | stonefield.remove(x,y); | 211 | stonefield.remove(x,y); |
217 | } | 212 | } |
218 | */ | 213 | */ |
219 | } | 214 | } |
220 | 215 | ||
221 | 216 | ||
222 | void | 217 | void |
223 | StoneWidget::saveProperties(Config *) { | 218 | StoneWidget::saveProperties(Config *) { |
224 | /* | 219 | /* |
225 | Q_ASSERT(conf); | 220 | Q_ASSERT(conf); |
226 | 221 | ||
227 | QStrList list(true); | 222 | QStrList list(true); |
228 | QString tmp; | 223 | QString tmp; |
229 | 224 | ||
230 | for (QPoint *item=history.first();item;item=history.next()) { | 225 | for (QPoint *item=history.first();item;item=history.next()) { |
231 | tmp.sprintf("%02X%02X",item->x(),item->y()); | 226 | tmp.sprintf("%02X%02X",item->x(),item->y()); |
232 | list.append(tmp.ascii()); | 227 | list.append(tmp.ascii()); |
233 | } | 228 | } |
234 | 229 | ||
235 | conf->writeEntry("Stones",list); | 230 | conf->writeEntry("Stones",list); |
236 | conf->writeEntry("Board",stonefield.getBoard()); | 231 | conf->writeEntry("Board",stonefield.getBoard()); |
237 | conf->writeEntry("Colors",stonefield.getColors()); | 232 | conf->writeEntry("Colors",stonefield.getColors()); |
238 | */ | 233 | */ |
239 | } | 234 | } |
240 | 235 | ||
241 | void | 236 | void |
242 | StoneWidget::timerEvent( QTimerEvent * ) { | 237 | StoneWidget::timerEvent( QTimerEvent * ) { |
243 | QPoint p=mapFromGlobal(cursor().pos()); | 238 | QPoint p=mapFromGlobal(cursor().pos()); |
244 | int x=p.x(); | 239 | int x=p.x(); |
245 | int y=p.y(); | 240 | int y=p.y(); |
246 | if (x<0||y<0||x>=field_width||y>=field_height) | 241 | if (x<0||y<0||x>=field_width||y>=field_height) |
247 | stonefield.unmark(); | 242 | stonefield.unmark(); |
248 | slice=(slice+1)%maxslices; | 243 | slice=(slice+1)%maxslices; |
249 | paintEvent(0); | 244 | paintEvent(0); |
250 | } | 245 | } |
251 | 246 | ||
252 | void | 247 | void |
253 | StoneWidget::paintEvent( QPaintEvent *e ) { | 248 | StoneWidget::paintEvent( QPaintEvent *e ) { |
254 | 249 | ||
255 | Stone *stone=stonefield.getField(); | 250 | Stone *stone=stonefield.getField(); |
256 | 251 | ||
257 | for (int y=0;y<sizey;y++) { | 252 | for (int y=0;y<sizey;y++) { |
258 | int cy = y * stone_height; | 253 | int cy = y * stone_height; |
259 | 254 | ||
260 | for (int x=0;x<sizex;x++) { | 255 | for (int x=0;x<sizex;x++) { |
261 | int cx = stone_width * x; | 256 | int cx = stone_width * x; |
262 | 257 | ||
263 | bool redraw=stone->marked||stone->changed; | 258 | bool redraw=stone->marked||stone->changed; |
264 | 259 | ||
265 | if (!redraw&&e) { | 260 | if (!redraw&&e) { |
266 | QRect r(cx,cy,stone_width,stone_height); | 261 | QRect r(cx,cy,stone_width,stone_height); |
267 | redraw=r.intersects(e->rect()); | 262 | redraw=r.intersects(e->rect()); |
268 | } | 263 | } |
269 | if (redraw) { | 264 | if (redraw) { |
270 | stone->changed=false; | 265 | stone->changed=false; |
271 | if (stone->color) { | 266 | if (stone->color) { |
272 | 267 | ||
273 | int tslice = stone->marked?slice:0; | 268 | int tslice = stone->marked?slice:0; |
274 | bitBlt(this,cx,cy, | 269 | bitBlt(this,cx,cy, |
275 | &map[stone->color-1][tslice].stone, | 270 | &map[stone->color-1][tslice].stone, |
276 | 0, 0, | 271 | 0, 0, |
277 | stone_width,stone_height,CopyROP,FALSE); | 272 | stone_width,stone_height,CopyROP,FALSE); |
278 | 273 | ||
279 | } else { | 274 | } else { |
280 | erase(cx, cy, stone_width, stone_height); | 275 | erase(cx, cy, stone_width, stone_height); |
281 | } | 276 | } |
282 | } | 277 | } |
283 | stone++; // naechster Stein. | 278 | stone++; // naechster Stein. |
284 | } | 279 | } |
285 | } | 280 | } |
286 | } | 281 | } |
287 | 282 | ||
288 | void | 283 | void |
289 | StoneWidget::mousePressEvent ( QMouseEvent *e) { | 284 | StoneWidget::mousePressEvent ( QMouseEvent *e) { |
290 | 285 | ||
291 | if (stonefield.isGameover()) return; | 286 | if (stonefield.isGameover()) return; |
292 | 287 | ||
293 | int x=e->pos().x(); | 288 | int x=e->pos().x(); |
294 | int y=e->pos().y(); | 289 | int y=e->pos().y(); |
295 | if (x<0||y<0||x>=field_width||y>=field_height) return; | 290 | if (x<0||y<0||x>=field_width||y>=field_height) return; |
296 | 291 | ||
297 | int sx=x/stone_width; | 292 | int sx=x/stone_width; |
298 | int sy=y/stone_height; | 293 | int sy=y/stone_height; |
299 | 294 | ||
300 | int mar =stonefield.mark(sx, sy); | 295 | int mar =stonefield.mark(sx, sy); |
301 | 296 | ||
302 | if ( mar != -1 ) { | 297 | if ( mar != -1 ) { |
303 | myMoveEvent(e); | 298 | myMoveEvent(e); |
304 | return; | 299 | return; |
305 | } | 300 | } |
306 | 301 | ||
307 | 302 | ||
308 | if (stonefield.remove(sx, sy)) { | 303 | if (stonefield.remove(sx, sy)) { |
309 | history.append(new QPoint(sx, sy)); | 304 | history.append(new QPoint(sx, sy)); |
310 | 305 | ||
311 | emit s_remove(sx, sy); | 306 | emit s_remove(sx, sy); |
312 | 307 | ||
313 | stonefield.mark(sx,sy); | 308 | stonefield.mark(sx,sy); |
314 | emit s_marked(stonefield.getMarked()); | 309 | emit s_marked(stonefield.getMarked()); |
315 | modified= true; | 310 | modified= true; |
316 | 311 | ||
317 | emit s_score(stonefield.getScore()); | 312 | emit s_score(stonefield.getScore()); |
318 | if (stonefield.isGameover()) emit s_gameover(); | 313 | if (stonefield.isGameover()) emit s_gameover(); |
319 | } | 314 | } |
320 | } | 315 | } |
321 | 316 | ||
322 | void | 317 | void |
323 | StoneWidget::myMoveEvent ( QMouseEvent *e) | 318 | StoneWidget::myMoveEvent ( QMouseEvent *e) |
324 | { | 319 | { |
325 | return; | 320 | return; |
326 | 321 | ||
327 | if (stonefield.isGameover()) { | 322 | if (stonefield.isGameover()) { |
328 | stonefield.unmark(); | 323 | stonefield.unmark(); |
329 | emit s_marked(0); | 324 | emit s_marked(0); |
330 | return; | 325 | return; |
331 | } | 326 | } |
332 | 327 | ||
333 | int x=e->pos().x(); | 328 | int x=e->pos().x(); |
334 | int y=e->pos().y(); | 329 | int y=e->pos().y(); |
335 | if (x<0||y<0||x>=field_width||y>=field_height) return; | 330 | if (x<0||y<0||x>=field_width||y>=field_height) return; |
336 | 331 | ||
337 | int marked=stonefield.mark(x/stone_width,y/stone_height); | 332 | int marked=stonefield.mark(x/stone_width,y/stone_height); |
338 | if (marked>=0) { | 333 | if (marked>=0) { |
339 | emit s_marked(marked); | 334 | emit s_marked(marked); |
340 | slice=0; | 335 | slice=0; |
341 | } | 336 | } |
342 | } | 337 | } |
343 | 338 | ||
344 | 339 | ||
345 | 340 | ||
346 | 341 | ||
347 | 342 | ||
348 | 343 | ||
349 | 344 | ||
350 | 345 | ||
diff --git a/noncore/games/zsame/ZSameWidget.cpp b/noncore/games/zsame/ZSameWidget.cpp index 5001b55..45a877f 100644 --- a/noncore/games/zsame/ZSameWidget.cpp +++ b/noncore/games/zsame/ZSameWidget.cpp | |||
@@ -1,250 +1,243 @@ | |||
1 | /* Yo Emacs, this is -*- C++ -*- */ | 1 | /* Yo Emacs, this is -*- C++ -*- */ |
2 | /* | 2 | /* |
3 | * ksame 0.4 - simple Game | 3 | * ksame 0.4 - simple Game |
4 | * Copyright (C) 1997,1998 Marcus Kreutzberger | 4 | * Copyright (C) 1997,1998 Marcus Kreutzberger |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or modify | 6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by | 7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or | 8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. | 9 | * (at your option) any later version. |
10 | * | 10 | * |
11 | * This program is distributed in the hope that it will be useful, | 11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. | 14 | * GNU General Public License for more details. |
15 | * | 15 | * |
16 | * You should have received a copy of the GNU General Public License | 16 | * You should have received a copy of the GNU General Public License |
17 | * along with this program; if not, write to the Free Software | 17 | * along with this program; if not, write to the Free Software |
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 | * | 19 | * |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <stdio.h> | 22 | #include <stdio.h> |
23 | 23 | ||
24 | #include <qwidget.h> | ||
25 | #include <qpushbutton.h> | ||
26 | #include <qpixmap.h> | ||
27 | #include <qvbox.h> | ||
28 | #include <qpopupmenu.h> | ||
29 | #include <qtoolbar.h> | 24 | #include <qtoolbar.h> |
30 | #include <qmenubar.h> | 25 | #include <qmenubar.h> |
31 | 26 | ||
32 | #include <qapplication.h> | 27 | #include <qapplication.h> |
33 | #include <qaction.h> | 28 | #include <qaction.h> |
34 | #include <qmessagebox.h> | 29 | #include <qmessagebox.h> |
35 | 30 | ||
36 | #include <qpe/resource.h> | 31 | #include <qpe/resource.h> |
37 | #include <opie/oapplicationfactory.h> | 32 | #include <opie/oapplicationfactory.h> |
38 | #include <kapplication.h> | 33 | #include <kapplication.h> |
39 | 34 | ||
40 | 35 | ||
41 | #include "ZSameWidget.h" | 36 | #include "ZSameWidget.h" |
42 | #include "StoneWidget.h" | ||
43 | #include "version.h" | ||
44 | 37 | ||
45 | static int default_colors=3; | 38 | static int default_colors=3; |
46 | 39 | ||
47 | #define i18n tr | 40 | #define i18n tr |
48 | 41 | ||
49 | 42 | ||
50 | OPIE_EXPORT_APP( OApplicationFactory<ZSameWidget> ) | 43 | OPIE_EXPORT_APP( OApplicationFactory<ZSameWidget> ) |
51 | 44 | ||
52 | 45 | ||
53 | 46 | ||
54 | ZSameWidget::ZSameWidget( QWidget* parent, const char* name, WFlags fl ) | 47 | ZSameWidget::ZSameWidget( QWidget* parent, const char* name, WFlags fl ) |
55 | : QMainWindow( parent, name, fl ) | 48 | : QMainWindow( parent, name, fl ) |
56 | { | 49 | { |
57 | setCaption(tr("ZSame")); | 50 | setCaption(tr("ZSame")); |
58 | 51 | ||
59 | setToolBarsMovable( false ); | 52 | setToolBarsMovable( false ); |
60 | QToolBar* con = new QToolBar( this ); | 53 | QToolBar* con = new QToolBar( this ); |
61 | con->setHorizontalStretchable( true ); | 54 | con->setHorizontalStretchable( true ); |
62 | QMenuBar* mb = new QMenuBar( con ); | 55 | QMenuBar* mb = new QMenuBar( con ); |
63 | QToolBar* tb = new QToolBar( this ); | 56 | QToolBar* tb = new QToolBar( this ); |
64 | 57 | ||
65 | QPopupMenu* fileMenu = new QPopupMenu( this ); | 58 | QPopupMenu* fileMenu = new QPopupMenu( this ); |
66 | 59 | ||
67 | QAction* a = new QAction(tr("New Game"), Resource::loadIconSet("new") , | 60 | QAction* a = new QAction(tr("New Game"), Resource::loadIconSet("new") , |
68 | QString::null, 0, this, "new_icon"); | 61 | QString::null, 0, this, "new_icon"); |
69 | a->addTo( fileMenu ); | 62 | a->addTo( fileMenu ); |
70 | a->addTo( tb ); | 63 | a->addTo( tb ); |
71 | connect(a, SIGNAL(activated()), this, SLOT(m_new())); | 64 | connect(a, SIGNAL(activated()), this, SLOT(m_new())); |
72 | 65 | ||
73 | a = new QAction(tr("Restart This Board"), Resource::loadIconSet("redo"), | 66 | a = new QAction(tr("Restart This Board"), Resource::loadIconSet("redo"), |
74 | QString::null, 0, this, "restart_board" ); | 67 | QString::null, 0, this, "restart_board" ); |
75 | a->addTo( fileMenu ); | 68 | a->addTo( fileMenu ); |
76 | connect( a, SIGNAL(activated()), this, SLOT(m_restart())); | 69 | connect( a, SIGNAL(activated()), this, SLOT(m_restart())); |
77 | restart = a; | 70 | restart = a; |
78 | 71 | ||
79 | a = new QAction( tr("Undo"), Resource::loadIconSet("undo"), | 72 | a = new QAction( tr("Undo"), Resource::loadIconSet("undo"), |
80 | QString::null, 0, this, "undo_action" ); | 73 | QString::null, 0, this, "undo_action" ); |
81 | a->addTo( fileMenu ); | 74 | a->addTo( fileMenu ); |
82 | a->addTo( tb ); | 75 | a->addTo( tb ); |
83 | connect( a, SIGNAL(activated()), this, SLOT(m_undo())); | 76 | connect( a, SIGNAL(activated()), this, SLOT(m_undo())); |
84 | 77 | ||
85 | a = new QAction(tr("Quit"), Resource::loadIconSet("quit_icon"), | 78 | a = new QAction(tr("Quit"), Resource::loadIconSet("quit_icon"), |
86 | QString::null, 0, this, "quit_action"); | 79 | QString::null, 0, this, "quit_action"); |
87 | a->addTo( fileMenu ); | 80 | a->addTo( fileMenu ); |
88 | a->addTo( tb ); | 81 | a->addTo( tb ); |
89 | connect(a, SIGNAL(activated()), this, SLOT(m_quit())); | 82 | connect(a, SIGNAL(activated()), this, SLOT(m_quit())); |
90 | 83 | ||
91 | mb->insertItem(tr("Game" ), fileMenu ); | 84 | mb->insertItem(tr("Game" ), fileMenu ); |
92 | 85 | ||
93 | int foo[2]; | 86 | int foo[2]; |
94 | desktop_widget(foo); | 87 | desktop_widget(foo); |
95 | stone = new StoneWidget(this,foo[0],foo[1]); | 88 | stone = new StoneWidget(this,foo[0],foo[1]); |
96 | 89 | ||
97 | connect( stone, SIGNAL(s_gameover()), this, SLOT(gameover())); | 90 | connect( stone, SIGNAL(s_gameover()), this, SLOT(gameover())); |
98 | 91 | ||
99 | connect( stone, SIGNAL(s_colors(int)), this, SLOT(setColors(int))); | 92 | connect( stone, SIGNAL(s_colors(int)), this, SLOT(setColors(int))); |
100 | connect( stone, SIGNAL(s_board(int)), this, SLOT(setBoard(int))); | 93 | connect( stone, SIGNAL(s_board(int)), this, SLOT(setBoard(int))); |
101 | connect( stone, SIGNAL(s_marked(int)), this, SLOT(setMarked(int))); | 94 | connect( stone, SIGNAL(s_marked(int)), this, SLOT(setMarked(int))); |
102 | connect( stone, SIGNAL(s_score(int)), this, SLOT(setScore(int))); | 95 | connect( stone, SIGNAL(s_score(int)), this, SLOT(setScore(int))); |
103 | connect( stone, SIGNAL(s_remove(int,int)), this, SLOT(stonesRemoved(int,int))); | 96 | connect( stone, SIGNAL(s_remove(int,int)), this, SLOT(stonesRemoved(int,int))); |
104 | 97 | ||
105 | connect(stone, SIGNAL(s_sizechanged()), this, SLOT(sizeChanged())); | 98 | connect(stone, SIGNAL(s_sizechanged()), this, SLOT(sizeChanged())); |
106 | 99 | ||
107 | sizeChanged(); | 100 | sizeChanged(); |
108 | setCentralWidget(stone); | 101 | setCentralWidget(stone); |
109 | 102 | ||
110 | 103 | ||
111 | setScore(0); | 104 | setScore(0); |
112 | } | 105 | } |
113 | 106 | ||
114 | ZSameWidget::~ZSameWidget() { | 107 | ZSameWidget::~ZSameWidget() { |
115 | 108 | ||
116 | } | 109 | } |
117 | 110 | ||
118 | void ZSameWidget::readProperties(Config *conf) { | 111 | void ZSameWidget::readProperties(Config *conf) { |
119 | /* | 112 | /* |
120 | Q_ASSERT(conf); | 113 | Q_ASSERT(conf); |
121 | stone->readProperties(conf); | 114 | stone->readProperties(conf); |
122 | */ | 115 | */ |
123 | } | 116 | } |
124 | 117 | ||
125 | void ZSameWidget::saveProperties(Config *conf) { | 118 | void ZSameWidget::saveProperties(Config *conf) { |
126 | /* | 119 | /* |
127 | Q_ASSERT(conf); | 120 | Q_ASSERT(conf); |
128 | stone->saveProperties(conf); | 121 | stone->saveProperties(conf); |
129 | conf->sync(); | 122 | conf->sync(); |
130 | */ | 123 | */ |
131 | } | 124 | } |
132 | 125 | ||
133 | void ZSameWidget::sizeChanged() { | 126 | void ZSameWidget::sizeChanged() { |
134 | //stone->setFixedSize(stone->sizeHint()); | 127 | //stone->setFixedSize(stone->sizeHint()); |
135 | } | 128 | } |
136 | 129 | ||
137 | void ZSameWidget::newGame(unsigned int board,int colors) { | 130 | void ZSameWidget::newGame(unsigned int board,int colors) { |
138 | while (board>=1000000) board-=1000000; | 131 | while (board>=1000000) board-=1000000; |
139 | // kdDebug() << "newgame board " << board << " colors " << colors << endl; | 132 | // kdDebug() << "newgame board " << board << " colors " << colors << endl; |
140 | stone->newGame(board,colors); | 133 | stone->newGame(board,colors); |
141 | setScore(0); | 134 | setScore(0); |
142 | } | 135 | } |
143 | 136 | ||
144 | bool ZSameWidget::confirmAbort() { | 137 | bool ZSameWidget::confirmAbort() { |
145 | return stone->isGameover() || | 138 | return stone->isGameover() || |
146 | stone->isOriginalBoard() || | 139 | stone->isOriginalBoard() || |
147 | (QMessageBox::warning(this, i18n("Resign"), i18n("<qt>Do you want to resign?</qt>"), | 140 | (QMessageBox::warning(this, i18n("Resign"), i18n("<qt>Do you want to resign?</qt>"), |
148 | QMessageBox::Yes, | 141 | QMessageBox::Yes, |
149 | QMessageBox::No|QMessageBox::Default|QMessageBox::Escape, 0) == QMessageBox::Yes ); | 142 | QMessageBox::No|QMessageBox::Default|QMessageBox::Escape, 0) == QMessageBox::Yes ); |
150 | } | 143 | } |
151 | 144 | ||
152 | void ZSameWidget::m_new() { | 145 | void ZSameWidget::m_new() { |
153 | if (confirmAbort()) | 146 | if (confirmAbort()) |
154 | newGame(_random(),default_colors); | 147 | newGame(_random(),default_colors); |
155 | 148 | ||
156 | } | 149 | } |
157 | 150 | ||
158 | void ZSameWidget::m_restart() { | 151 | void ZSameWidget::m_restart() { |
159 | if (confirmAbort()) | 152 | if (confirmAbort()) |
160 | newGame(stone->board(),default_colors); | 153 | newGame(stone->board(),default_colors); |
161 | } | 154 | } |
162 | 155 | ||
163 | void ZSameWidget::m_load() { | 156 | void ZSameWidget::m_load() { |
164 | // kdDebug() << "menu load not supported" << endl; | 157 | // kdDebug() << "menu load not supported" << endl; |
165 | } | 158 | } |
166 | 159 | ||
167 | void ZSameWidget::m_save() { | 160 | void ZSameWidget::m_save() { |
168 | // kdDebug() << "menu save not supported" << endl; | 161 | // kdDebug() << "menu save not supported" << endl; |
169 | } | 162 | } |
170 | 163 | ||
171 | void ZSameWidget::m_undo() { | 164 | void ZSameWidget::m_undo() { |
172 | //Q_ASSERT(stone); | 165 | //Q_ASSERT(stone); |
173 | stone->undo(); | 166 | stone->undo(); |
174 | } | 167 | } |
175 | 168 | ||
176 | 169 | ||
177 | void ZSameWidget::m_showhs() { | 170 | void ZSameWidget::m_showhs() { |
178 | /* Q_ASSERT(stone); | 171 | /* Q_ASSERT(stone); |
179 | stone->unmark(); | 172 | stone->unmark(); |
180 | KScoreDialog d(KScoreDialog::Name | KScoreDialog::Score, this); | 173 | KScoreDialog d(KScoreDialog::Name | KScoreDialog::Score, this); |
181 | d.addField(Board, i18n("Board"), "Board"); | 174 | d.addField(Board, i18n("Board"), "Board"); |
182 | d.exec(); | 175 | d.exec(); |
183 | */ | 176 | */ |
184 | } | 177 | } |
185 | 178 | ||
186 | void ZSameWidget::m_quit() { | 179 | void ZSameWidget::m_quit() { |
187 | // Q_ASSERT(stone); | 180 | // Q_ASSERT(stone); |
188 | stone->unmark(); | 181 | stone->unmark(); |
189 | qApp->quit(); | 182 | qApp->quit(); |
190 | // delete this; | 183 | // delete this; |
191 | } | 184 | } |
192 | 185 | ||
193 | void ZSameWidget::m_tglboard() { | 186 | void ZSameWidget::m_tglboard() { |
194 | //kdDebug() << "toggled" << endl; | 187 | //kdDebug() << "toggled" << endl; |
195 | } | 188 | } |
196 | 189 | ||
197 | 190 | ||
198 | void ZSameWidget::setColors(int colors) { | 191 | void ZSameWidget::setColors(int colors) { |
199 | //status->changeItem(i18n("%1 Colors").arg(colors),1); | 192 | //status->changeItem(i18n("%1 Colors").arg(colors),1); |
200 | } | 193 | } |
201 | 194 | ||
202 | void ZSameWidget::setBoard(int board) { | 195 | void ZSameWidget::setBoard(int board) { |
203 | //status->changeItem(i18n("Board: %1").arg(board, 6), 2); | 196 | //status->changeItem(i18n("Board: %1").arg(board, 6), 2); |
204 | } | 197 | } |
205 | 198 | ||
206 | void ZSameWidget::setMarked(int m) { | 199 | void ZSameWidget::setMarked(int m) { |
207 | // status->changeItem(i18n("Marked: %1").arg(m, 6),3); | 200 | // status->changeItem(i18n("Marked: %1").arg(m, 6),3); |
208 | } | 201 | } |
209 | 202 | ||
210 | void ZSameWidget::stonesRemoved(int,int) { | 203 | void ZSameWidget::stonesRemoved(int,int) { |
211 | //KNotifyClient::event("stones removed", | 204 | //KNotifyClient::event("stones removed", |
212 | // i18n("%1 stones removed.").arg(stone->marked())); | 205 | // i18n("%1 stones removed.").arg(stone->marked())); |
213 | } | 206 | } |
214 | 207 | ||
215 | void ZSameWidget::setScore(int score) { | 208 | void ZSameWidget::setScore(int score) { |
216 | // status->changeItem(i18n("Score: %1").arg(score, 6),4); | 209 | // status->changeItem(i18n("Score: %1").arg(score, 6),4); |
217 | // undo->setEnabled(stone->undoPossible()); | 210 | // undo->setEnabled(stone->undoPossible()); |
218 | // restart->setEnabled(!stone->isOriginalBoard()); | 211 | // restart->setEnabled(!stone->isOriginalBoard()); |
219 | } | 212 | } |
220 | 213 | ||
221 | void ZSameWidget::gameover() { | 214 | void ZSameWidget::gameover() { |
222 | // kdDebug() << "GameOver" << endl; | 215 | // kdDebug() << "GameOver" << endl; |
223 | if (stone->hasBonus()) { | 216 | if (stone->hasBonus()) { |
224 | QMessageBox::information(this,i18n("Game won"), | 217 | QMessageBox::information(this,i18n("Game won"), |
225 | i18n("<qt>You even removed the last stone, great job! " | 218 | i18n("<qt>You even removed the last stone, great job! " |
226 | "This gave you a score of %1 in total.</qt>").arg(stone->score())); | 219 | "This gave you a score of %1 in total.</qt>").arg(stone->score())); |
227 | } else { | 220 | } else { |
228 | QMessageBox::information(this,i18n("Game over"), | 221 | QMessageBox::information(this,i18n("Game over"), |
229 | i18n("<qt>There are no more removeable stones. " | 222 | i18n("<qt>There are no more removeable stones. " |
230 | "You got a score of %1 in total.</qt>").arg(stone->score())); | 223 | "You got a score of %1 in total.</qt>").arg(stone->score())); |
231 | } | 224 | } |
232 | stone->unmark(); | 225 | stone->unmark(); |
233 | } | 226 | } |
234 | 227 | ||
235 | void ZSameWidget::desktop_widget(int *f)const{ | 228 | void ZSameWidget::desktop_widget(int *f)const{ |
236 | 229 | ||
237 | QWidget* wid = QApplication::desktop(); | 230 | QWidget* wid = QApplication::desktop(); |
238 | /* width > height landscape mode */ | 231 | /* width > height landscape mode */ |
239 | if ( wid->width() > wid->height() ) { | 232 | if ( wid->width() > wid->height() ) { |
240 | f[0]=15; | 233 | f[0]=15; |
241 | f[1]=9; | 234 | f[1]=9; |
242 | } | 235 | } |
243 | /* normal */ | 236 | /* normal */ |
244 | else{ | 237 | else{ |
245 | f[0]=12; | 238 | f[0]=12; |
246 | f[1]=13; | 239 | f[1]=13; |
247 | } | 240 | } |
248 | } | 241 | } |
249 | 242 | ||
250 | 243 | ||