Diffstat (limited to 'noncore/games/kcheckers/kcheckers.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/kcheckers/kcheckers.cpp | 440 |
1 files changed, 322 insertions, 118 deletions
diff --git a/noncore/games/kcheckers/kcheckers.cpp b/noncore/games/kcheckers/kcheckers.cpp index 3df744e..c2eba0d 100644 --- a/noncore/games/kcheckers/kcheckers.cpp +++ b/noncore/games/kcheckers/kcheckers.cpp | |||
@@ -2,21 +2,29 @@ | |||
2 | #include <qimage.h> | 2 | #include <qimage.h> |
3 | #include <qframe.h> | 3 | #include <qframe.h> |
4 | #include <qlayout.h> | 4 | #include <qlayout.h> |
5 | #include <qmenubar.h> | 5 | #include <qmenubar.h> |
6 | #include <qtoolbar.h> | ||
7 | #include <qpe/config.h> | ||
6 | #include <qwhatsthis.h> | 8 | #include <qwhatsthis.h> |
9 | #include <qtoolbutton.h> | ||
7 | #include <qmessagebox.h> | 10 | #include <qmessagebox.h> |
8 | #include <qapplication.h> | 11 | #include <qapplication.h> |
9 | 12 | ||
10 | #include "kcheckers.h" | 13 | #include "kcheckers.h" |
11 | #include "echeckers.h" | 14 | #include "echeckers.h" |
12 | #include "rcheckers.h" | 15 | #include "rcheckers.h" |
13 | 16 | ||
14 | #include "pics/exit.xpm" | ||
15 | #include "pics/logo.xpm" | 17 | #include "pics/logo.xpm" |
18 | #include "pics/undo.xpm" | ||
19 | #include "pics/exit.xpm" | ||
20 | #include "pics/help.xpm" | ||
16 | #include "pics/wood1.xpm" | 21 | #include "pics/wood1.xpm" |
17 | #include "pics/wood2.xpm" | 22 | #include "pics/wood2.xpm" |
18 | #include "pics/wood3.xpm" | 23 | #include "pics/wood3.xpm" |
24 | #include "pics/green1.xpm" | ||
25 | #include "pics/green2.xpm" | ||
26 | #include "pics/green3.xpm" | ||
19 | #include "pics/marble1.xpm" | 27 | #include "pics/marble1.xpm" |
20 | #include "pics/marble2.xpm" | 28 | #include "pics/marble2.xpm" |
21 | #include "pics/marble3.xpm" | 29 | #include "pics/marble3.xpm" |
22 | #include "pics/biglogo.xpm" | 30 | #include "pics/biglogo.xpm" |
@@ -26,92 +34,148 @@ | |||
26 | #include "pics/king_white.xpm" | 34 | #include "pics/king_white.xpm" |
27 | #include "pics/contexthelp.xpm" | 35 | #include "pics/contexthelp.xpm" |
28 | 36 | ||
29 | 37 | ||
38 | QString KCheckers::enNumeration="1 2 3 4 5 6 7 8 9 1011121314151617181920212223242526272829303132"; | ||
39 | QString KCheckers::ruNumeration="B8D8F8H8A7C7E7G7B6D6F6H6A5C5E5G5B4D4F4H4A3C3E3G3B2D2F2H2A1C1E1G1"; | ||
40 | |||
30 | const int KCheckers::t[]={6,7,8,9,11,12,13,14,17,18,19,20,22,23, | 41 | const int KCheckers::t[]={6,7,8,9,11,12,13,14,17,18,19,20,22,23, |
31 | 24,25,28,29,30,31,33,34,35,36,39,40,41,42,44,45,46,47}; | 42 | 24,25,28,29,30,31,33,34,35,36,39,40,41,42,44,45,46,47}; |
32 | 43 | ||
44 | |||
33 | KCheckers::KCheckers():QMainWindow(0,0,WStyle_DialogBorder) | 45 | KCheckers::KCheckers():QMainWindow(0,0,WStyle_DialogBorder) |
34 | { | 46 | { |
35 | setCaption("KCheckers"); | 47 | setCaption("KCheckers"); |
36 | setIcon(QPixmap(biglogo)); | 48 | setIcon(QPixmap(biglogo_xpm)); |
37 | showMaximized(); | 49 | |
50 | setToolBarsMovable(false); | ||
51 | |||
52 | // Make a menubar | ||
53 | |||
54 | gameMenu=new QPopupMenu; | ||
55 | CHECK_PTR(gameMenu); | ||
38 | 56 | ||
39 | QPopupMenu* gameMenu=new QPopupMenu; | 57 | gameMenu->insertItem(QPixmap(logo_xpm),tr("&New"),this,SLOT(newGame()),CTRL+Key_N); |
40 | gameMenu->insertItem(QPixmap(logo),tr("New"),this,SLOT(newGame())); | ||
41 | gameMenu->insertSeparator(); | 58 | gameMenu->insertSeparator(); |
42 | gameMenu->insertItem(QPixmap(exit),tr("Quit"),qApp,SLOT(quit())); | 59 | undoID=gameMenu->insertItem(QPixmap(undo_xpm),tr("&Undo Move"),this,SLOT(undoMove()),CTRL+Key_Z); |
60 | gameMenu->insertSeparator(); | ||
61 | gameMenu->insertItem(QPixmap(exit_xpm),tr("&Quit"),qApp,SLOT(closeAllWindows()),CTRL+Key_Q); | ||
43 | 62 | ||
44 | skillMenu=new QPopupMenu; | 63 | skillMenu=new QPopupMenu; |
64 | CHECK_PTR(skillMenu); | ||
45 | 65 | ||
46 | skillMenu->insertItem(tr("Beginner"),this,SLOT(setSkillBeginner()),0,BEGINNER); | 66 | skillMenu->insertItem(tr("&Beginner"),this,SLOT(setSkillBeginner()),CTRL+Key_1,BEGINNER); |
47 | skillMenu->insertItem(tr("Novice"), this,SLOT(setSkillNovice()), 0,NOVICE); | 67 | skillMenu->insertItem(tr("&Novice"), this,SLOT(setSkillNovice()), CTRL+Key_2,NOVICE); |
48 | skillMenu->insertItem(tr("Average"), this,SLOT(setSkillAverage()), 0,AVERAGE); | 68 | skillMenu->insertItem(tr("&Average"), this,SLOT(setSkillAverage()), CTRL+Key_3,AVERAGE); |
49 | skillMenu->insertItem(tr("Good"), this,SLOT(setSkillGood()), 0,GOOD); | 69 | skillMenu->insertItem(tr("&Good"), this,SLOT(setSkillGood()), CTRL+Key_4,GOOD); |
50 | skillMenu->insertItem(tr("Expert"), this,SLOT(setSkillExpert()), 0,EXPERT); | 70 | skillMenu->insertItem(tr("&Expert"), this,SLOT(setSkillExpert()), CTRL+Key_5,EXPERT); |
51 | skillMenu->insertItem(tr("Master"), this,SLOT(setSkillMaster()), 0,MASTER); | 71 | skillMenu->insertItem(tr("&Master"), this,SLOT(setSkillMaster()), CTRL+Key_6,MASTER); |
52 | 72 | ||
53 | optionsMenu=new QPopupMenu; | 73 | optionsMenu=new QPopupMenu; |
74 | CHECK_PTR(optionsMenu); | ||
54 | 75 | ||
55 | optionsMenu->insertItem(tr("English Rules"),this,SLOT(setRulesEnglish()),0,ENGLISH); | 76 | numID=optionsMenu->insertItem(tr("&Show Numeration"),this,SLOT(showNumeration())); |
56 | optionsMenu->insertItem(tr("Russian Rules"),this,SLOT(setRulesRussian()),0,RUSSIAN); | 77 | optionsMenu->insertSeparator(); |
78 | optionsMenu->insertItem(tr("&English Rules"),this,SLOT(setRulesEnglish()),0,ENGLISH); | ||
79 | optionsMenu->insertItem(tr("&Russian Rules"),this,SLOT(setRulesRussian()),0,RUSSIAN); | ||
57 | optionsMenu->insertSeparator(); | 80 | optionsMenu->insertSeparator(); |
58 | optionsMenu->insertItem(tr("Marble Board"),this,SLOT(setPatternMarble()),0,MARBLE); | 81 | optionsMenu->insertItem(tr("&Green Board"), this,SLOT(setPatternGreen()), 0,GREEN); |
59 | optionsMenu->insertItem(tr("Wooden Board"),this,SLOT(setPatternWood()), 0,WOOD); | 82 | optionsMenu->insertItem(tr("&Marble Board"),this,SLOT(setPatternMarble()),0,MARBLE); |
83 | optionsMenu->insertItem(tr("&Wooden Board"),this,SLOT(setPatternWooden()),0,WOODEN); | ||
60 | 84 | ||
61 | QPopupMenu* helpMenu=new QPopupMenu; | 85 | QPopupMenu* helpMenu=new QPopupMenu; |
86 | CHECK_PTR(helpMenu); | ||
62 | 87 | ||
63 | helpMenu->insertItem(QPixmap(contexthelp),tr("What's This"),this,SLOT(whatsThis())); | 88 | helpMenu->insertItem(QPixmap(contexthelp_xpm),tr("What's This"),this,SLOT(whatsThis()),SHIFT+Key_F1); |
89 | helpMenu->insertItem(QPixmap(help_xpm),tr("&Rules of Play"),this,SLOT(help()),Key_F1); | ||
64 | helpMenu->insertSeparator(); | 90 | helpMenu->insertSeparator(); |
65 | helpMenu->insertItem(QPixmap(logo),tr("About KCheckers"),this,SLOT(about())); | 91 | helpMenu->insertItem(QPixmap(logo_xpm),tr("&About KCheckers"),this,SLOT(about())); |
66 | helpMenu->insertItem(tr("About &Qt"),this,SLOT(aboutQt())); | 92 | helpMenu->insertItem(tr("About &Qt"),this,SLOT(aboutQt())); |
67 | 93 | ||
68 | menuBar()->insertItem(tr("Game"), gameMenu); | 94 | QToolBar* menuToolBar=new QToolBar(this); |
69 | menuBar()->insertItem(tr("Skill"), skillMenu); | 95 | CHECK_PTR(menuToolBar); |
70 | menuBar()->insertItem(tr("Options"),optionsMenu); | 96 | QMenuBar* menuBar=new QMenuBar(menuToolBar); |
71 | menuBar()->insertItem(tr("Help"), helpMenu); | 97 | CHECK_PTR(menuBar); |
72 | 98 | ||
73 | skill=NOVICE; | 99 | menuBar->insertItem(tr("&Game"), gameMenu); |
74 | skillMenu->setItemChecked(skill,true); | 100 | menuBar->insertItem(tr("&Skill"), skillMenu); |
101 | menuBar->insertItem(tr("&Options"),optionsMenu); | ||
102 | menuBar->insertItem(tr("&Help"), helpMenu); | ||
75 | 103 | ||
76 | rules=ENGLISH; | 104 | // Restore a settings |
105 | |||
106 | readConfig(); | ||
107 | |||
108 | skillMenu->setItemChecked(skill,true); | ||
77 | optionsMenu->setItemChecked(rules,true); | 109 | optionsMenu->setItemChecked(rules,true); |
110 | optionsMenu->setItemChecked(numID,false); | ||
78 | 111 | ||
79 | pattern=WOOD; | 112 | // Make a toolbar |
80 | optionsMenu->setItemChecked(pattern,true); | 113 | |
114 | QToolBar* emptyToolBar=new QToolBar(this); | ||
115 | emptyToolBar->setHorizontalStretchable(true); | ||
116 | |||
117 | QToolBar* toolBar=new QToolBar(this); | ||
118 | CHECK_PTR(toolBar); | ||
119 | |||
120 | QSize buttonSize(24,24); | ||
121 | |||
122 | QToolButton* gameButton=new QToolButton(QPixmap(logo_xpm),tr(" New Game ") ,"",this,SLOT(newGame()),toolBar); | ||
123 | CHECK_PTR(gameButton); | ||
124 | gameButton->setMinimumSize(buttonSize); | ||
125 | |||
126 | undoButton=new QToolButton(QPixmap(undo_xpm),tr(" Undo Move "),"",this,SLOT(undoMove()),toolBar); | ||
127 | CHECK_PTR(undoButton); | ||
128 | undoButton->setMinimumSize(buttonSize); | ||
81 | 129 | ||
82 | imageMan1=new QImage(man_black); | 130 | QToolButton* helpButton=new QToolButton(QPixmap(help_xpm),tr(" Rules of Play "),"",this,SLOT(help()),toolBar); |
83 | imageMan2=new QImage(man_white); | 131 | CHECK_PTR(helpButton); |
84 | imageKing1=new QImage(king_black); | 132 | helpButton->setMinimumSize(buttonSize); |
85 | imageKing2=new QImage(king_white); | ||
86 | 133 | ||
87 | imageWood1=new QImage(wood1); | 134 | // Make a checkers board |
88 | imageWood2=new QImage(wood2); | ||
89 | imageWood3=new QImage(wood3); | ||
90 | imageMarble1=new QImage(marble1); | ||
91 | imageMarble2=new QImage(marble2); | ||
92 | imageMarble3=new QImage(marble3); | ||
93 | 135 | ||
94 | imagePat1=imageWood1; | 136 | imageMan1=new QImage(man_black_xpm); CHECK_PTR(imageMan1); |
95 | imagePat2=imageWood2; | 137 | imageMan2=new QImage(man_white_xpm); CHECK_PTR(imageMan2); |
96 | imageFrame=imageWood3; | 138 | imageKing1=new QImage(king_black_xpm); CHECK_PTR(imageKing1); |
139 | imageKing2=new QImage(king_white_xpm); CHECK_PTR(imageKing2); | ||
140 | |||
141 | imageWood1=new QImage(wood1_xpm); CHECK_PTR(imageWood1); | ||
142 | imageWood2=new QImage(wood2_xpm); CHECK_PTR(imageWood2); | ||
143 | imageWood3=new QImage(wood3_xpm); CHECK_PTR(imageWood3); | ||
144 | imageGreen1=new QImage(green1_xpm); CHECK_PTR(imageGreen1); | ||
145 | imageGreen2=new QImage(green2_xpm); CHECK_PTR(imageGreen2); | ||
146 | imageGreen3=new QImage(green3_xpm); CHECK_PTR(imageGreen3); | ||
147 | imageMarble1=new QImage(marble1_xpm); CHECK_PTR(imageMarble1); | ||
148 | imageMarble2=new QImage(marble2_xpm); CHECK_PTR(imageMarble2); | ||
149 | imageMarble3=new QImage(marble3_xpm); CHECK_PTR(imageMarble3); | ||
97 | 150 | ||
98 | QWidget* centralWidget=new QWidget(this); | 151 | QWidget* centralWidget=new QWidget(this); |
99 | setCentralWidget(centralWidget); | 152 | setCentralWidget(centralWidget); |
100 | 153 | ||
101 | QFrame* frame=new QFrame(centralWidget); | 154 | QFrame* frame=new QFrame(centralWidget); |
155 | CHECK_PTR(frame); | ||
102 | frame->setFrameStyle(QFrame::Box|QFrame::Plain); | 156 | frame->setFrameStyle(QFrame::Box|QFrame::Plain); |
103 | frame->setFixedSize(SIZE*8+2,SIZE*8+2); | 157 | frame->setFixedSize(SIZE*8+2,SIZE*8+2); |
104 | 158 | ||
159 | statusLabel = new QLabel(centralWidget); | ||
160 | statusLabel->setAlignment(Qt::AlignHCenter); | ||
161 | |||
105 | QVBoxLayout* vlayout=new QVBoxLayout(centralWidget); | 162 | QVBoxLayout* vlayout=new QVBoxLayout(centralWidget); |
106 | vlayout->addWidget(frame); | ||
107 | 163 | ||
108 | statusLabel = new QLabel(centralWidget); | 164 | vlayout->addStretch(); |
165 | vlayout->addWidget(frame); | ||
166 | vlayout->addStretch(); | ||
109 | vlayout->addWidget(statusLabel); | 167 | vlayout->addWidget(statusLabel); |
168 | vlayout->addStretch(); | ||
110 | 169 | ||
111 | for(int i=0;i<64;i++) field[i]=new Field(frame,i); | 170 | for(int i=0;i<64;i++) |
171 | { | ||
172 | field[i]=new Field(frame,i); | ||
173 | CHECK_PTR(field[i]); | ||
174 | } | ||
112 | 175 | ||
113 | QGridLayout* grid=new QGridLayout(frame,8,8,1,0); | 176 | QGridLayout* grid=new QGridLayout(frame,8,8,1,0); |
177 | CHECK_PTR(grid); | ||
114 | 178 | ||
115 | for(int i=0;i<4;i++) | 179 | for(int i=0;i<4;i++) |
116 | { | 180 | { |
117 | for(int k=0;k<4;k++) | 181 | for(int k=0;k<4;k++) |
@@ -125,15 +189,73 @@ KCheckers::KCheckers():QMainWindow(0,0,WStyle_DialogBorder) | |||
125 | 189 | ||
126 | for(int i=0;i<32;i++) | 190 | for(int i=0;i<32;i++) |
127 | connect(field[i],SIGNAL(click(int)),this,SLOT(click(int))); | 191 | connect(field[i],SIGNAL(click(int)),this,SLOT(click(int))); |
128 | 192 | ||
193 | selected=false; | ||
194 | |||
195 | setPattern(pattern); | ||
196 | |||
197 | QWhatsThis::add(frame,"A checkers board"); | ||
198 | |||
129 | userFirst=false; | 199 | userFirst=false; |
130 | 200 | ||
131 | game=NULL; | 201 | game=NULL; |
132 | newGame(); | 202 | newGame(); |
133 | } | 203 | } |
134 | 204 | ||
135 | 205 | ||
206 | void KCheckers::readConfig() | ||
207 | { | ||
208 | Config config("KCheckers"); | ||
209 | config.setGroup("KCheckers"); | ||
210 | QString entry; | ||
211 | |||
212 | entry=config.readEntry("skill","novice"); | ||
213 | if(entry=="beginner") skill=BEGINNER; | ||
214 | else if(entry=="average") skill=AVERAGE; | ||
215 | else if(entry=="good") skill=GOOD; | ||
216 | else if(entry=="expert") skill=EXPERT; | ||
217 | else if(entry=="master") skill=MASTER; | ||
218 | else skill=NOVICE; | ||
219 | |||
220 | entry=config.readEntry("rules","english"); | ||
221 | if(entry=="russian") rules=RUSSIAN; | ||
222 | else rules=ENGLISH; | ||
223 | |||
224 | entry=config.readEntry("theme","wooden"); | ||
225 | if(entry=="green") pattern=GREEN; | ||
226 | else if(entry=="marble") pattern=MARBLE; | ||
227 | else pattern=WOODEN; | ||
228 | } | ||
229 | |||
230 | |||
231 | void KCheckers::closeEvent(QCloseEvent* event) | ||
232 | { | ||
233 | Config config("KCheckers"); | ||
234 | config.setGroup("KCheckers"); | ||
235 | QString entry; | ||
236 | |||
237 | if(skill==BEGINNER) entry="beginner"; | ||
238 | if(skill==NOVICE) entry="novice"; | ||
239 | if(skill==AVERAGE) entry="average"; | ||
240 | if(skill==GOOD) entry="good"; | ||
241 | if(skill==EXPERT) entry="expert"; | ||
242 | if(skill==MASTER) entry="master"; | ||
243 | config.writeEntry("skill",entry); | ||
244 | |||
245 | if(rules==ENGLISH) entry="english"; | ||
246 | if(rules==RUSSIAN) entry="russian"; | ||
247 | config.writeEntry("rules",entry); | ||
248 | |||
249 | if(pattern==GREEN) entry="green"; | ||
250 | if(pattern==MARBLE) entry="marble"; | ||
251 | if(pattern==WOODEN) entry="wooden"; | ||
252 | config.writeEntry("theme",entry); | ||
253 | |||
254 | event->accept(); | ||
255 | } | ||
256 | |||
257 | |||
136 | void KCheckers::setSkill(int set) | 258 | void KCheckers::setSkill(int set) |
137 | { | 259 | { |
138 | skillMenu->setItemChecked(skill,false); | 260 | skillMenu->setItemChecked(skill,false); |
139 | 261 | ||
@@ -164,37 +286,130 @@ void KCheckers::setPattern(int set) | |||
164 | optionsMenu->setItemChecked(pattern,true); | 286 | optionsMenu->setItemChecked(pattern,true); |
165 | 287 | ||
166 | switch(pattern) | 288 | switch(pattern) |
167 | { | 289 | { |
290 | case GREEN: | ||
291 | imagePat1=imageGreen1; | ||
292 | imagePat2=imageGreen2; | ||
293 | imageFrame=imageGreen3; | ||
294 | break; | ||
168 | case MARBLE: | 295 | case MARBLE: |
169 | imagePat1=imageMarble1; | 296 | imagePat1=imageMarble1; |
170 | imagePat2=imageMarble2; | 297 | imagePat2=imageMarble2; |
171 | imageFrame=imageMarble3; | 298 | imageFrame=imageMarble3; |
172 | break; | 299 | break; |
173 | case WOOD: | 300 | case WOODEN: |
174 | imagePat1=imageWood1; | 301 | imagePat1=imageWood1; |
175 | imagePat2=imageWood2; | 302 | imagePat2=imageWood2; |
176 | imageFrame=imageWood3; | 303 | imageFrame=imageWood3; |
177 | } | 304 | } |
178 | 305 | ||
179 | drawBoard(); | 306 | for(int i=0; i<32;i++) field[i]->setPattern(imagePat2); |
307 | for(int i=32;i<64;i++) field[i]->setPattern(imagePat1); | ||
308 | |||
309 | if(selected) field[from]->setFrame(imageFrame); | ||
310 | } | ||
311 | |||
180 | 312 | ||
181 | if(selected) field[from]->draw(imageFrame); | 313 | void KCheckers::showNumeration() |
314 | { | ||
315 | if(optionsMenu->isItemChecked(numID)) | ||
316 | { | ||
317 | optionsMenu->setItemChecked(numID,false); | ||
318 | for(int i=0;i<32;i++) field[i]->setLabel(""); | ||
319 | } | ||
320 | else | ||
321 | { | ||
322 | optionsMenu->setItemChecked(numID,true); | ||
323 | drawNumeration(); | ||
324 | } | ||
325 | } | ||
326 | |||
327 | |||
328 | void KCheckers::drawNumeration() | ||
329 | { | ||
330 | if(rules==ENGLISH) | ||
331 | { | ||
332 | if(userFirst) | ||
333 | for(int i=0;i<32;i++) | ||
334 | field[i]->setLabel(enNumeration.mid(i*2,2)); | ||
335 | else | ||
336 | for(int i=0;i<32;i++) | ||
337 | field[i]->setLabel(enNumeration.mid(62-i*2,2)); | ||
338 | } | ||
339 | else | ||
340 | { | ||
341 | if(userFirst) | ||
342 | for(int i=0;i<32;i++) | ||
343 | field[i]->setLabel(ruNumeration.mid(i*2,2)); | ||
344 | else | ||
345 | for(int i=0;i<32;i++) | ||
346 | field[i]->setLabel(ruNumeration.mid(62-i*2,2)); | ||
347 | } | ||
348 | } | ||
349 | |||
350 | |||
351 | void KCheckers::drawBoard(int i) | ||
352 | { | ||
353 | switch(game->board[t[i]]) | ||
354 | { | ||
355 | case MAN1: | ||
356 | field[i]->setPicture(imageMan1); | ||
357 | break; | ||
358 | case MAN2: | ||
359 | field[i]->setPicture(imageMan2); | ||
360 | break; | ||
361 | case KING1: | ||
362 | field[i]->setPicture(imageKing1); | ||
363 | break; | ||
364 | case KING2: | ||
365 | field[i]->setPicture(imageKing2); | ||
366 | break; | ||
367 | default: | ||
368 | field[i]->setPicture(NULL); | ||
369 | } | ||
370 | } | ||
371 | |||
372 | |||
373 | void KCheckers::help() | ||
374 | { | ||
375 | QMessageBox::information(this,"Rules of Play", | ||
376 | "In the beginning of game you have\n" | ||
377 | "12 checkers (men).\n" | ||
378 | "The men move forward only.\n" | ||
379 | "The men can capture:\n" | ||
380 | "- by jumping forward only (english\n" | ||
381 | " rules);\n" | ||
382 | "- by jumping forward or backward\n" | ||
383 | " (russian rules).\n" | ||
384 | "A man which reaches the far side of\n" | ||
385 | "the board becomes a king.\n" | ||
386 | "The kings move forward or\n" | ||
387 | "backward:\n" | ||
388 | "- to one square only (english rules);\n" | ||
389 | "- to any number of squares (russian\n" | ||
390 | " rules).\n" | ||
391 | "The kings capture by jumping\n" | ||
392 | "forward or backward.\n" | ||
393 | "Whenever a player is able to make a\n" | ||
394 | "capture he must do so.", | ||
395 | QMessageBox::Ok|QMessageBox::Default); | ||
182 | } | 396 | } |
183 | 397 | ||
184 | 398 | ||
185 | void KCheckers::about() | 399 | void KCheckers::about() |
186 | { | 400 | { |
187 | QMessageBox::about(this, "About", | 401 | QMessageBox::about(this,"About KCheckers", |
188 | "KCheckers, a board game. Ver 0.2\n" | 402 | "KCheckers, a board game. Ver 0.3\n" |
189 | "(C) 2002, A. Peredri <andi@ukr.net>\n\n" | 403 | "(C) 2002, A. Peredri <andi@ukr.net>\n\n" |
190 | "http://kcheckers.tuxfamily.org\n\n" | 404 | "http://kcheckers.tuxfamily.org\n\n" |
191 | "Opie version by S.Prud'homme\n" | 405 | "Contributors:\n" |
192 | "<prudhomme@laposte.net>\n\n" | 406 | "S. Rosen <srosen@erols.com>\n\n" |
193 | "http://opie.handhelds.org\n\n" | 407 | "Qtopia version: S.Prud'homme\n" |
194 | "This program is distributed under the\n" | 408 | "<prudhomme@laposte.net>\n\n" |
195 | "terms of the GNU General Public\n" | 409 | "This program is distributed under the\n" |
196 | "License."); | 410 | "terms of the GNU General Public\n" |
411 | "License."); | ||
197 | } | 412 | } |
198 | 413 | ||
199 | 414 | ||
200 | void KCheckers::aboutQt() | 415 | void KCheckers::aboutQt() |
@@ -204,57 +419,59 @@ void KCheckers::aboutQt() | |||
204 | 419 | ||
205 | 420 | ||
206 | void KCheckers::newGame() | 421 | void KCheckers::newGame() |
207 | { | 422 | { |
208 | if(game) | 423 | if(game) delete game; |
209 | { | ||
210 | delete game; | ||
211 | QWhatsThis::remove(this); | ||
212 | } | ||
213 | 424 | ||
214 | switch(rules) | 425 | switch(rules) |
215 | { | 426 | { |
216 | case ENGLISH: | 427 | case ENGLISH: |
217 | game=new ECheckers(skill); | 428 | game=new ECheckers(skill); |
218 | QWhatsThis::add(this, | 429 | CHECK_PTR(game); |
219 | "<b>Rules of English Checkers</b>" | ||
220 | "<ul>" | ||
221 | "<li>In the beginning of game you have<br>12 checkers (men)." | ||
222 | "<li>Men move forward only." | ||
223 | "<li>Men capture by jumping forward only." | ||
224 | "<li>A man which reaches the far side of<br>the board becomes a king." | ||
225 | "<li>Kings move forward or backward to<br>one square." | ||
226 | "<li>Kings capture by jumping forward or<br>backward." | ||
227 | "<li>Whenever a player is able to make<br> a capture he must do so." | ||
228 | "</ul>"); | ||
229 | break; | 430 | break; |
431 | |||
230 | case RUSSIAN: | 432 | case RUSSIAN: |
231 | game=new RCheckers(skill); | 433 | game=new RCheckers(skill); |
232 | QWhatsThis::add(this, | 434 | CHECK_PTR(game); |
233 | "<b>Rules of Russian Checkers</b>" | ||
234 | "<ul>" | ||
235 | "<li>In the beginning of game you have<br> 12 checkers (men)." | ||
236 | "<li>Men move forward only." | ||
237 | "<li>Men capture by jumping forward or<br>backward." | ||
238 | "<li>A man which reaches the far side of<br> the board becomes a king." | ||
239 | "<li>Kings move forward or backward to<br>any number of squares." | ||
240 | "<li>Kings capture by jumping forward or<br>backward." | ||
241 | "<li>Whenever a player is able to make<br> a capture he must do so." | ||
242 | "</ul>"); | ||
243 | } | 435 | } |
244 | 436 | ||
245 | selected=false; | 437 | unselect(); |
246 | gameOver=false; | 438 | gameOver=false; |
247 | 439 | ||
440 | gameMenu->setItemEnabled(undoID,false); | ||
441 | undoButton->setEnabled(false); | ||
442 | |||
248 | colorChange(); | 443 | colorChange(); |
249 | drawBoard(); | 444 | |
445 | for(int i=0;i<32;i++) drawBoard(i); | ||
446 | if(optionsMenu->isItemChecked(numID)) drawNumeration(); | ||
250 | 447 | ||
251 | if(!userFirst) compGo(); | 448 | if(!userFirst) compGo(); |
252 | 449 | ||
253 | statusLabel->setText(tr("Go!")); | 450 | statusLabel->setText(tr("Go!")); |
254 | } | 451 | } |
255 | 452 | ||
256 | 453 | ||
454 | // Undo the last computer and user moves | ||
455 | |||
456 | void KCheckers::undoMove() | ||
457 | { | ||
458 | for(int i=0;i<32;i++) | ||
459 | { | ||
460 | game->board[t[i]]=undoBoard[i]; | ||
461 | drawBoard(i); | ||
462 | } | ||
463 | |||
464 | unselect(); | ||
465 | gameOver=false; | ||
466 | |||
467 | gameMenu->setItemEnabled(undoID,false); | ||
468 | undoButton->setEnabled(false); | ||
469 | |||
470 | statusLabel->setText(tr("Go!")); | ||
471 | } | ||
472 | |||
473 | |||
257 | void KCheckers::colorChange() | 474 | void KCheckers::colorChange() |
258 | { | 475 | { |
259 | userFirst=!userFirst; | 476 | userFirst=!userFirst; |
260 | 477 | ||
@@ -267,54 +484,44 @@ void KCheckers::colorChange() | |||
267 | imageKing2=image; | 484 | imageKing2=image; |
268 | } | 485 | } |
269 | 486 | ||
270 | 487 | ||
271 | void KCheckers::drawBoard() | 488 | void KCheckers::unselect() |
272 | { | 489 | { |
273 | // Drawing of start position | 490 | if(selected) field[from]->setFrame(NULL); |
274 | for(int i=0;i<32;i++) | 491 | selected=false; |
275 | { | ||
276 | field[i]->draw(imagePat2); | ||
277 | if(game->getBoard(t[i])==MAN1) field[i]->draw(imageMan1); | ||
278 | else if(game->getBoard(t[i])==MAN2) field[i]->draw(imageMan2); | ||
279 | else if(game->getBoard(t[i])==KING1) field[i]->draw(imageKing1); | ||
280 | else if(game->getBoard(t[i])==KING2) field[i]->draw(imageKing2); | ||
281 | } | ||
282 | |||
283 | for(int i=32;i<64;i++) field[i]->draw(imagePat1); | ||
284 | } | 492 | } |
285 | 493 | ||
286 | 494 | ||
287 | void KCheckers::click(int fieldNumber) | 495 | void KCheckers::click(int fieldNumber) |
288 | { | 496 | { |
289 | if(gameOver) return; | 497 | if(gameOver) return; |
290 | switch(game->getBoard(t[fieldNumber])) | 498 | switch(game->board[t[fieldNumber]]) |
291 | { | 499 | { |
292 | case MAN1: | 500 | case MAN1: |
293 | case KING1: | 501 | case KING1: |
294 | // User selected | 502 | // User selected |
295 | if(!selected) | 503 | if(!selected) |
296 | { | 504 | { |
297 | from=fieldNumber; | 505 | from=fieldNumber; |
298 | selected=true; | 506 | selected=true; |
299 | field[fieldNumber]->draw(imageFrame); | 507 | field[fieldNumber]->setFrame(imageFrame); |
300 | return; | 508 | return; |
301 | } | 509 | } |
302 | // User reselected | 510 | // User reselected |
303 | else | 511 | else |
304 | { | 512 | { |
305 | field[from]->draw(imagePat2); | 513 | field[from]->setFrame(NULL); |
306 | if(game->getBoard(t[from])==MAN1) field[from]->draw(imageMan1); | ||
307 | else field[from]->draw(imageKing1); | ||
308 | from=fieldNumber; | 514 | from=fieldNumber; |
309 | field[fieldNumber]->draw(imageFrame); | 515 | field[fieldNumber]->setFrame(imageFrame); |
310 | return; | 516 | return; |
311 | } | 517 | } |
312 | case FREE: | 518 | case FREE: |
313 | if(!selected) return; | 519 | if(!selected) return; |
314 | 520 | ||
315 | if(!userGo(fieldNumber)) return; | 521 | if(!userGo(fieldNumber)) return; |
316 | selected=false; | 522 | |
523 | unselect(); | ||
317 | 524 | ||
318 | if(!(game->checkMove2() || game->checkCapture2())) | 525 | if(!(game->checkMove2() || game->checkCapture2())) |
319 | { | 526 | { |
320 | gameOver=true; | 527 | gameOver=true; |
@@ -339,44 +546,41 @@ void KCheckers::click(int fieldNumber) | |||
339 | 546 | ||
340 | void KCheckers::compGo() | 547 | void KCheckers::compGo() |
341 | { | 548 | { |
342 | int save[32]; | 549 | int save[32]; |
343 | for(int i=0;i<32;i++) save[i]=game->getBoard(t[i]); | 550 | for(int i=0;i<32;i++) save[i]=game->board[t[i]]; |
344 | 551 | ||
345 | game->go2(); | 552 | game->go2(); |
346 | 553 | ||
347 | for(int i=0;i<32;i++) | 554 | for(int i=0;i<32;i++) |
348 | { | 555 | { |
349 | if(game->getBoard(t[i])==save[i]) continue; | 556 | if(game->board[t[i]]==save[i]) continue; |
350 | field[i]->draw(imagePat2); | 557 | drawBoard(i); |
351 | if(game->getBoard(t[i])==MAN1) field[i]->draw(imageMan1); | ||
352 | else if(game->getBoard(t[i])==MAN2) field[i]->draw(imageMan2); | ||
353 | else if(game->getBoard(t[i])==KING1) field[i]->draw(imageKing1); | ||
354 | else if(game->getBoard(t[i])==KING2) field[i]->draw(imageKing2); | ||
355 | } | 558 | } |
356 | } | 559 | } |
357 | 560 | ||
358 | 561 | ||
359 | bool KCheckers::userGo(int to) | 562 | bool KCheckers::userGo(int to) |
360 | { | 563 | { |
361 | int save[32]; | 564 | int save[32]; |
362 | for(int i=0;i<32;i++) save[i]=game->getBoard(t[i]); | 565 | for(int i=0;i<32;i++) save[i]=game->board[t[i]]; |
363 | 566 | ||
364 | if(!game->go1(t[from],t[to])) | 567 | if(!game->go1(t[from],t[to])) |
365 | { | 568 | { |
366 | statusLabel->setText(tr("Incorrect course.")); | 569 | statusLabel->setText(tr("Incorrect course.")); |
367 | return false; | 570 | return false; |
368 | } | 571 | } |
369 | 572 | ||
573 | for(int i=0;i<32;i++) undoBoard[i]=save[i]; | ||
574 | gameMenu->setItemEnabled(undoID,true); | ||
575 | undoButton->setEnabled(true); | ||
576 | |||
370 | for(int i=0;i<32;i++) | 577 | for(int i=0;i<32;i++) |
371 | { | 578 | { |
372 | if(game->getBoard(t[i])==save[i]) continue; | 579 | if(game->board[t[i]]==save[i]) continue; |
373 | field[i]->draw(imagePat2); | 580 | drawBoard(i); |
374 | if(game->getBoard(t[i])==MAN1) field[i]->draw(imageMan1); | ||
375 | else if(game->getBoard(t[i])==MAN2) field[i]->draw(imageMan2); | ||
376 | else if(game->getBoard(t[i])==KING1) field[i]->draw(imageKing1); | ||
377 | else if(game->getBoard(t[i])==KING2) field[i]->draw(imageKing2); | ||
378 | } | 581 | } |
582 | |||
379 | return true; | 583 | return true; |
380 | } | 584 | } |
381 | 585 | ||
382 | 586 | ||