summaryrefslogtreecommitdiff
path: root/noncore/games/backgammon/backgammon.cpp
Unidiff
Diffstat (limited to 'noncore/games/backgammon/backgammon.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/backgammon/backgammon.cpp131
1 files changed, 31 insertions, 100 deletions
diff --git a/noncore/games/backgammon/backgammon.cpp b/noncore/games/backgammon/backgammon.cpp
index 38ccb49..c40f462 100644
--- a/noncore/games/backgammon/backgammon.cpp
+++ b/noncore/games/backgammon/backgammon.cpp
@@ -1,51 +1,31 @@
1#include "backgammon.h" 1#include "backgammon.h"
2 2
3#include "aidialog.h" 3#include "aidialog.h"
4#include "displaydialog.h"
5#include "filedialog.h" 4#include "filedialog.h"
6#include "playerdialog.h" 5#include "playerdialog.h"
7#include "rulesdialog.h" 6#include "rulesdialog.h"
8#include "themedialog.h" 7#include "themedialog.h"
9 8
10#include <qdatetime.h> 9#include <qdatetime.h>
11#include <qfile.h> 10#include <qfile.h>
11#include <qlayout.h>
12#include <qmessagebox.h> 12#include <qmessagebox.h>
13#include <qstring.h> 13#include <qstring.h>
14#include <qtimer.h> 14#include <qtimer.h>
15#include <qmainwindow.h>
15#include <qpe/qpeapplication.h> 16#include <qpe/qpeapplication.h>
16#include <qpe/config.h> 17#include <qpe/config.h>
17#include <qpe/qpemenubar.h> 18#include <qpe/qpemenubar.h>
18#include <qpe/resource.h> 19#include <qpe/resource.h>
19 20
20#include <stdlib.h> 21#include <stdlib.h>
21 22
22BackGammonView::BackGammonView(QCanvas* canvas,QWidget* parent)
23 :QCanvasView(canvas,parent)
24{
25 //do nothing
26}
27
28
29
30BackGammonView::~BackGammonView()
31{
32 //do nothing
33}
34
35
36
37void BackGammonView::contentsMousePressEvent(QMouseEvent* e)
38{
39 int x=e->x();
40 int y=e->y();
41 emit mouse(x,y);
42}
43 23
44BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl) 24BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl)
45 : QWidget(parent, name, fl) 25 : QMainWindow(parent, name, fl)
46{ 26{
47 if (!name) setName("BackGammon"); 27 if (!name) setName("BackGammon");
48 setCaption("Backgammon"); 28 setCaption("Backgammon");
49 setIcon( Resource::loadPixmap( "backgammon" ) ); 29 setIcon( Resource::loadPixmap( "backgammon" ) );
50 //general counter varaible 30 //general counter varaible
51 int a=0; 31 int a=0;
@@ -93,27 +73,12 @@ BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl)
93 ai.expose=conf.readNumEntry("expose",1); 73 ai.expose=conf.readNumEntry("expose",1);
94 ai.protect=conf.readNumEntry("protect",5); 74 ai.protect=conf.readNumEntry("protect",5);
95 ai.safe=conf.readNumEntry("safe",3); 75 ai.safe=conf.readNumEntry("safe",3);
96 ai.empty=conf.readNumEntry("empty",2); 76 ai.empty=conf.readNumEntry("empty",2);
97 move->setAISettings(ai); 77 move->setAISettings(ai);
98 78
99 //non qte styles are smaller
100 conf.setGroup("display");
101 display.small=conf.readBoolEntry("small",false);
102 display.warning=conf.readBoolEntry("warning",true);
103 non_qte=display.small;
104 if(display.warning)
105 {
106 Config test("qpe");
107 test.setGroup("Appearance");
108 if(test.readEntry("Style")!="QPE")
109 {
110 displaySettings();
111 }
112 }
113 offset=(non_qte) ? 5 : 0;
114 79
115 //get the theme component names 80 //get the theme component names
116 Config theme(theme_file,Config::File); 81 Config theme(theme_file,Config::File);
117 if(!theme.isValid()) 82 if(!theme.isValid())
118 { 83 {
119 qDebug("theme file does not exist"); 84 qDebug("theme file does not exist");
@@ -160,32 +125,27 @@ BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl)
160 125
161 QPopupMenu* optionmenu=new QPopupMenu(this); 126 QPopupMenu* optionmenu=new QPopupMenu(this);
162 optionmenu->insertItem("Player",this,SLOT(playerselect())); 127 optionmenu->insertItem("Player",this,SLOT(playerselect()));
163 optionmenu->insertSeparator(); 128 optionmenu->insertSeparator();
164 optionmenu->insertItem("AI",this,SLOT(modify_AI())); 129 optionmenu->insertItem("AI",this,SLOT(modify_AI()));
165 optionmenu->insertItem("Rules",this,SLOT(setrules())); 130 optionmenu->insertItem("Rules",this,SLOT(setrules()));
166 optionmenu->insertItem("Display",this,SLOT(displaySettings()));
167 menuBar->insertItem("Options",optionmenu); 131 menuBar->insertItem("Options",optionmenu);
168 132
169 //status bar 133 QWidget* mainarea=new QWidget(this);
170 message=new QLabel("<b>Backgammon</b>",this); 134 setCentralWidget(mainarea);
171 message->setGeometry(0,260,237,20);
172 message->setAlignment(AlignHCenter);
173
174 //the main area 135 //the main area
175 area=new QCanvas(235-2*offset,235-2*offset); 136 QBoxLayout* layout=new QBoxLayout(mainarea,QBoxLayout::TopToBottom);
176 boardview=new BackGammonView(area,this); 137 area=new QCanvas(235,235);
138 boardview=new BackGammonView(area,mainarea);
139 boardview->setMaximumHeight(240);
140 layout->addWidget(boardview);
177 connect(boardview,SIGNAL(mouse(int,int)),this,SLOT(mouse(int,int))); 141 connect(boardview,SIGNAL(mouse(int,int)),this,SLOT(mouse(int,int)));
178 if(non_qte) 142 //status bar
179 { 143 message=new QLabel("<b>Backgammon</b>",mainarea);
180 boardview->setGeometry(5,20,229,229); 144 message->setAlignment(AlignHCenter);
181 } 145 layout->addWidget(message);
182 else
183 {
184 boardview->setGeometry(1,20,237,237);
185 }
186 146
187 //the marker 147 //the marker
188 marker_current=new QCanvasRectangle(area); 148 marker_current=new QCanvasRectangle(area);
189 marker_current->setBrush(QColor(0,0,255)); 149 marker_current->setBrush(QColor(0,0,255));
190 marker_current->setSize(15,5); 150 marker_current->setSize(15,5);
191 marker_current->setZ(1); 151 marker_current->setZ(1);
@@ -245,73 +205,65 @@ BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl)
245 205
246 206
247 for(a=0;a<7;a++) 207 for(a=0;a<7;a++)
248 { 208 {
249 QImage dicebgA=dicebgA_all.copy(a*25,0,25,25); 209 QImage dicebgA=dicebgA_all.copy(a*25,0,25,25);
250 diceA1[a]=new CanvasImageItem(dicebgA,area); 210 diceA1[a]=new CanvasImageItem(dicebgA,area);
251 diceA1[a]->setX(5-offset); 211 diceA1[a]->setX(5);
252 diceA1[a]->setY(205-2*offset); 212 diceA1[a]->setY(205-2);
253 diceA1[a]->setZ(1); 213 diceA1[a]->setZ(1);
254 diceA1[a]->setSize(25,25); 214 diceA1[a]->setSize(25,25);
255 diceA2[a]=new CanvasImageItem(dicebgA,area); 215 diceA2[a]=new CanvasImageItem(dicebgA,area);
256 diceA2[a]->setX(35-offset); 216 diceA2[a]->setX(35);
257 diceA2[a]->setY(205-2*offset); 217 diceA2[a]->setY(205-2);
258 diceA2[a]->setZ(1); 218 diceA2[a]->setZ(1);
259 diceA2[a]->setSize(25,25); 219 diceA2[a]->setSize(25,25);
260 220
261 QImage dicebgB=dicebgB_all.copy(a*25,0,25,25); 221 QImage dicebgB=dicebgB_all.copy(a*25,0,25,25);
262 diceB1[a]=new CanvasImageItem(dicebgB,area); 222 diceB1[a]=new CanvasImageItem(dicebgB,area);
263 diceB1[a]->setX(175-offset); 223 diceB1[a]->setX(175);
264 diceB1[a]->setY(205-2*offset); 224 diceB1[a]->setY(205-2);
265 diceB1[a]->setZ(1); 225 diceB1[a]->setZ(1);
266 diceB1[a]->setSize(25,25); 226 diceB1[a]->setSize(25,25);
267 diceB2[a]=new CanvasImageItem(dicebgB,area); 227 diceB2[a]=new CanvasImageItem(dicebgB,area);
268 diceB2[a]->setX(205-offset); 228 diceB2[a]->setX(205);
269 diceB2[a]->setY(205-2*offset); 229 diceB2[a]->setY(205-2);
270 diceB2[a]->setZ(1); 230 diceB2[a]->setZ(1);
271 diceB2[a]->setSize(25,25); 231 diceB2[a]->setSize(25,25);
272 232
273 /* 233 /*
274 if(a<6) 234 if(a<6)
275 { 235 {
276 QImage oddsbg=oddsbg_all.copy(a*15,0,15,15); 236 QImage oddsbg=oddsbg_all.copy(a*15,0,15,15);
277 oddsDice[a]=new CanvasImageItem(oddsbg,area); 237 oddsDice[a]=new CanvasImageItem(oddsbg,area);
278 oddsDice[a]->setX(110-offset); 238 oddsDice[a]->setX(110);
279 oddsDice[a]->setY(210-2*offset); 239 oddsDice[a]->setY(210-2);
280 oddsDice[a]->setZ(1); 240 oddsDice[a]->setZ(1);
281 oddsDice[a]->setSize(15,15); 241 oddsDice[a]->setSize(15,15);
282 oddsDice[a]->hide(); 242 oddsDice[a]->hide();
283 } 243 }
284 */ 244 */
285 } 245 }
286 //oddsDice[0]->show(); 246 //oddsDice[0]->show();
287 247
288 //set the board 248 //set the board
289 QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name)); 249 QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name));
290 if(non_qte)
291 {
292 boardbg=boardbg.copy(offset,offset,235-2*offset,200-2*offset);
293 }
294 board=new CanvasImageItem(boardbg,area); 250 board=new CanvasImageItem(boardbg,area);
295 board->setX(0); 251 board->setX(0);
296 board->setY(0); 252 board->setY(0);
297 board->setZ(0); 253 board->setZ(0);
298 board->setSize(235-2*offset,200-2*offset); 254 board->setSize(235-2,200-2);
299 board->show(); 255 board->show();
300 256
301 //the table 257 //the table
302 QImage tablebg(Resource::loadImage("backgammon/table/"+table_name)); 258 QImage tablebg(Resource::loadImage("backgammon/table/"+table_name));
303 if(non_qte)
304 {
305 tablebg=tablebg.copy(offset,0,235-offset,200);
306 }
307 table=new CanvasImageItem(tablebg,area); 259 table=new CanvasImageItem(tablebg,area);
308 table->setX(0); 260 table->setX(0);
309 table->setY(200-2*offset); 261 table->setY(200-2);
310 table->setZ(0); 262 table->setZ(0);
311 table->setSize(235-2*offset,20); 263 table->setSize(235-2,20);
312 table->show(); 264 table->show();
313 265
314 //the no move marker 266 //the no move marker
315 QImage nomovebg(Resource::loadImage("backgammon/no_move")); 267 QImage nomovebg(Resource::loadImage("backgammon/no_move"));
316 nomove_marker=new CanvasImageItem(nomovebg,area); 268 nomove_marker=new CanvasImageItem(nomovebg,area);
317 nomove_marker->setX(0); 269 nomove_marker->setX(0);
@@ -596,30 +548,17 @@ void BackGammon::setrules()
596 conf.setGroup("rules"); 548 conf.setGroup("rules");
597 conf.writeEntry("move_with_pieces_out",rules.move_with_pieces_out); 549 conf.writeEntry("move_with_pieces_out",rules.move_with_pieces_out);
598 conf.writeEntry("nice_dice",rules.generous_dice); 550 conf.writeEntry("nice_dice",rules.generous_dice);
599 move->setRules(rules); 551 move->setRules(rules);
600} 552}
601 553
602void BackGammon::displaySettings()
603{
604 DisplayDialog* displaydialog=new DisplayDialog(this);
605 displaydialog->setDisplaySettings(display);
606 if(!displaydialog->exec())
607 return;
608 display=displaydialog->getDisplaySettings();
609 Config conf("backgammon");
610 conf.setGroup("display");
611 conf.writeEntry("small",display.small);
612 conf.writeEntry("warning",display.warning);
613 QMessageBox::warning(this,"Backgammon","changed display settings will\nonly take place after game has\nbeen restarted","OK");
614}
615 554
616void BackGammon::draw() 555void BackGammon::draw()
617{ 556{
618 Pieces pieces; 557 Pieces pieces;
619 move->position(pieces,non_qte); 558 move->position(pieces);
620 for(int a=0;a<15;a++) 559 for(int a=0;a<15;a++)
621 { 560 {
622 if(!pieces.player1[a].side) 561 if(!pieces.player1[a].side)
623 { 562 {
624 p1[a]->setX(pieces.player1[a].x); 563 p1[a]->setX(pieces.player1[a].x);
625 p1[a]->setY(pieces.player1[a].y); 564 p1[a]->setY(pieces.player1[a].y);
@@ -666,29 +605,29 @@ void BackGammon::mouse(int x,int y)
666 { 605 {
667 if((player==1 && player1_auto) || (player==2 && player2_auto)) 606 if((player==1 && player1_auto) || (player==2 && player2_auto))
668 return; 607 return;
669 608
670 Marker marker; 609 Marker marker;
671 610
672 move->boardpressed(x,y,marker,non_qte); 611 move->boardpressed(x,y,marker);
673 if(marker.visible_current) 612 if(marker.visible_current)
674 { 613 {
675 marker_current->setX(marker.x_current-offset); 614 marker_current->setX(marker.x_current);
676 marker_current->setY(marker.y_current); 615 marker_current->setY(marker.y_current);
677 marker_current->show(); 616 marker_current->show();
678 } 617 }
679 else 618 else
680 { 619 {
681 marker_current->hide(); 620 marker_current->hide();
682 } 621 }
683 622
684 for(int a=0;a<4;a++) 623 for(int a=0;a<4;a++)
685 { 624 {
686 if(marker.visible_next[a]) 625 if(marker.visible_next[a])
687 { 626 {
688 marker_next[a]->setX(marker.x_next[a]-offset); 627 marker_next[a]->setX(marker.x_next[a]);
689 marker_next[a]->setY(marker.y_next[a]); 628 marker_next[a]->setY(marker.y_next[a]);
690 marker_next[a]->show(); 629 marker_next[a]->show();
691 } 630 }
692 else 631 else
693 { 632 {
694 marker_next[a]->hide(); 633 marker_next[a]->hide();
@@ -982,23 +921,15 @@ void BackGammon::autoroll_dice2()
982 mouse(170,210); 921 mouse(170,210);
983} 922}
984 923
985void BackGammon::applytheme() 924void BackGammon::applytheme()
986{ 925{
987 QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name)); 926 QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name));
988 if(non_qte)
989 {
990 boardbg=boardbg.copy(offset,offset,235-2*offset,200-2*offset);
991 }
992 board->setImage(boardbg); 927 board->setImage(boardbg);
993 928
994 QImage tablebg(Resource::loadImage("backgammon/table/"+table_name)); 929 QImage tablebg(Resource::loadImage("backgammon/table/"+table_name));
995 if(non_qte)
996 {
997 tablebg=tablebg.copy(offset,0,235-offset,200);
998 }
999 table->setImage(tablebg); 930 table->setImage(tablebg);
1000 931
1001 QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name)); 932 QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name));
1002 QImage piece_1_front=piece_1_all.copy(0,0,15,15); 933 QImage piece_1_front=piece_1_all.copy(0,0,15,15);
1003 QImage piece_1_side=piece_1_all.copy(0,15,15,5); 934 QImage piece_1_side=piece_1_all.copy(0,15,15,5);
1004 935