summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/backgammon/backgammon.cpp131
-rw-r--r--noncore/games/backgammon/backgammon.h32
-rw-r--r--noncore/games/backgammon/backgammonview.cpp14
-rw-r--r--noncore/games/backgammon/backgammonview.h10
-rw-r--r--noncore/games/backgammon/definition.cpp1
-rw-r--r--noncore/games/backgammon/displaydialog.cpp89
-rw-r--r--noncore/games/backgammon/displaydialog.h30
-rw-r--r--noncore/games/backgammon/moveengine.cpp2
-rw-r--r--noncore/games/backgammon/moveengine.h2
-rw-r--r--noncore/games/backgammon/rulesdialog.h1
10 files changed, 56 insertions, 256 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,1043 +1,974 @@
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;
52 //the game engine 32 //the game engine
53 move=new MoveEngine(); 33 move=new MoveEngine();
54 34
55 //load the default theme 35 //load the default theme
56 Config conf("backgammon"); 36 Config conf("backgammon");
57 if(!conf.isValid()) 37 if(!conf.isValid())
58 { 38 {
59 qDebug("config file does not exist"); 39 qDebug("config file does not exist");
60 conf.setGroup("general"); 40 conf.setGroup("general");
61 conf.writeEntry("theme","default"); 41 conf.writeEntry("theme","default");
62 conf.setGroup("rules"); 42 conf.setGroup("rules");
63 conf.writeEntry("move_with_pieces_out",false); 43 conf.writeEntry("move_with_pieces_out",false);
64 conf.writeEntry("nice_dice",false); 44 conf.writeEntry("nice_dice",false);
65 conf.setGroup("display"); 45 conf.setGroup("display");
66 conf.writeEntry("small",false); 46 conf.writeEntry("small",false);
67 conf.writeEntry("warning",true); 47 conf.writeEntry("warning",true);
68 conf.setGroup("ai"); 48 conf.setGroup("ai");
69 conf.writeEntry("rescue",6); 49 conf.writeEntry("rescue",6);
70 conf.writeEntry("eliminate",4); 50 conf.writeEntry("eliminate",4);
71 conf.writeEntry("expose",1); 51 conf.writeEntry("expose",1);
72 conf.writeEntry("protect",5); 52 conf.writeEntry("protect",5);
73 conf.writeEntry("safe",3); 53 conf.writeEntry("safe",3);
74 conf.writeEntry("empty",2); 54 conf.writeEntry("empty",2);
75 55
76 } 56 }
77 conf.setGroup("general"); 57 conf.setGroup("general");
78 theme_name=conf.readEntry("theme","default"); 58 theme_name=conf.readEntry("theme","default");
79 QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; 59 QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme";
80 60
81 //the rules 61 //the rules
82 conf.setGroup("rules"); 62 conf.setGroup("rules");
83 rules.move_with_pieces_out=conf.readBoolEntry("move_with_pieces_out",false); 63 rules.move_with_pieces_out=conf.readBoolEntry("move_with_pieces_out",false);
84 rules.generous_dice=conf.readBoolEntry("nice_dice",false); 64 rules.generous_dice=conf.readBoolEntry("nice_dice",false);
85 65
86 move->setRules(rules); 66 move->setRules(rules);
87 67
88 //get the AI settings 68 //get the AI settings
89 AISettings ai; 69 AISettings ai;
90 conf.setGroup("ai"); 70 conf.setGroup("ai");
91 ai.rescue=conf.readNumEntry("rescue",6); 71 ai.rescue=conf.readNumEntry("rescue",6);
92 ai.eliminate=conf.readNumEntry("eliminate",4); 72 ai.eliminate=conf.readNumEntry("eliminate",4);
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");
120 theme.setGroup("theme"); 85 theme.setGroup("theme");
121 theme.writeEntry("board","casino_board_1"); 86 theme.writeEntry("board","casino_board_1");
122 theme.writeEntry("pieces1","casino_pieces_blue"); 87 theme.writeEntry("pieces1","casino_pieces_blue");
123 theme.writeEntry("pieces2","casino_pieces_white"); 88 theme.writeEntry("pieces2","casino_pieces_white");
124 theme.writeEntry("dice1","casino_dice"); 89 theme.writeEntry("dice1","casino_dice");
125 theme.writeEntry("dice2","casino_dice"); 90 theme.writeEntry("dice2","casino_dice");
126 theme.writeEntry("table","casino_table_green"); 91 theme.writeEntry("table","casino_table_green");
127 theme.writeEntry("odds","casino_odds"); 92 theme.writeEntry("odds","casino_odds");
128 } 93 }
129 theme.setGroup("theme"); 94 theme.setGroup("theme");
130 board_name=theme.readEntry("board","casino_board_1"); 95 board_name=theme.readEntry("board","casino_board_1");
131 piecesA_name=theme.readEntry("pieces1","casino_pieces_blue"); 96 piecesA_name=theme.readEntry("pieces1","casino_pieces_blue");
132 piecesB_name=theme.readEntry("pieces2","casino_pieces_white"); 97 piecesB_name=theme.readEntry("pieces2","casino_pieces_white");
133 diceA_name=theme.readEntry("dice1","casino_dice"); 98 diceA_name=theme.readEntry("dice1","casino_dice");
134 diceB_name=theme.readEntry("dice2","casino_dice"); 99 diceB_name=theme.readEntry("dice2","casino_dice");
135 table_name=theme.readEntry("table","casino_table_green"); 100 table_name=theme.readEntry("table","casino_table_green");
136 odds_name=theme.readEntry("odds","casino_odds"); 101 odds_name=theme.readEntry("odds","casino_odds");
137 102
138 103
139 //the menu 104 //the menu
140 QPEMenuBar* menuBar = new QPEMenuBar(this); 105 QPEMenuBar* menuBar = new QPEMenuBar(this);
141 106
142 QPopupMenu* gamemenu= new QPopupMenu(this); 107 QPopupMenu* gamemenu= new QPopupMenu(this);
143 gamemenu->insertItem("New",this,SLOT(newgame())); 108 gamemenu->insertItem("New",this,SLOT(newgame()));
144 gamemenu->insertSeparator(); 109 gamemenu->insertSeparator();
145 gamemenu->insertItem("Load",this,SLOT(loadgame())); 110 gamemenu->insertItem("Load",this,SLOT(loadgame()));
146 gamemenu->insertItem("Save",this,SLOT(savegame())); 111 gamemenu->insertItem("Save",this,SLOT(savegame()));
147 gamemenu->insertSeparator(); 112 gamemenu->insertSeparator();
148 gamemenu->insertItem("Delete",this,SLOT(deletegame())); 113 gamemenu->insertItem("Delete",this,SLOT(deletegame()));
149 menuBar->insertItem("Game",gamemenu); 114 menuBar->insertItem("Game",gamemenu);
150 115
151 QPopupMenu* thememenu= new QPopupMenu(this); 116 QPopupMenu* thememenu= new QPopupMenu(this);
152 thememenu->insertItem("New",this,SLOT(newtheme())); 117 thememenu->insertItem("New",this,SLOT(newtheme()));
153 thememenu->insertSeparator(); 118 thememenu->insertSeparator();
154 thememenu->insertItem("Load",this,SLOT(loadtheme())); 119 thememenu->insertItem("Load",this,SLOT(loadtheme()));
155 thememenu->insertItem("Save",this,SLOT(savetheme())); 120 thememenu->insertItem("Save",this,SLOT(savetheme()));
156 thememenu->insertSeparator(); 121 thememenu->insertSeparator();
157 thememenu->insertItem("Default",this,SLOT(themedefault())); 122 thememenu->insertItem("Default",this,SLOT(themedefault()));
158 thememenu->insertItem("Delete",this,SLOT(deletetheme())); 123 thememenu->insertItem("Delete",this,SLOT(deletetheme()));
159 menuBar->insertItem("Theme",thememenu); 124 menuBar->insertItem("Theme",thememenu);
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);
192 152
193 for(a=0;a<4;a++) 153 for(a=0;a<4;a++)
194 { 154 {
195 marker_next[a]=new QCanvasRectangle(area); 155 marker_next[a]=new QCanvasRectangle(area);
196 marker_next[a]->setBrush(QColor(0,255,0)); 156 marker_next[a]->setBrush(QColor(0,255,0));
197 marker_next[a]->setSize(15,5); 157 marker_next[a]->setSize(15,5);
198 marker_next[a]->setZ(1); 158 marker_next[a]->setZ(1);
199 } 159 }
200 160
201 connect(move,SIGNAL(done_dice1()),this,SLOT(done_dice1())); 161 connect(move,SIGNAL(done_dice1()),this,SLOT(done_dice1()));
202 connect(move,SIGNAL(done_dice2()),this,SLOT(done_dice2())); 162 connect(move,SIGNAL(done_dice2()),this,SLOT(done_dice2()));
203 connect(move,SIGNAL(done_dice3()),this,SLOT(done_dice3())); 163 connect(move,SIGNAL(done_dice3()),this,SLOT(done_dice3()));
204 connect(move,SIGNAL(done_dice4()),this,SLOT(done_dice4())); 164 connect(move,SIGNAL(done_dice4()),this,SLOT(done_dice4()));
205 connect(move,SIGNAL(nomove()),this,SLOT(nomove())); 165 connect(move,SIGNAL(nomove()),this,SLOT(nomove()));
206 connect(move,SIGNAL(player_finished(int)),this,SLOT(finished(int))); 166 connect(move,SIGNAL(player_finished(int)),this,SLOT(finished(int)));
207 167
208 //the pieces 168 //the pieces
209 p1=new CanvasImageItem*[15]; 169 p1=new CanvasImageItem*[15];
210 p1_side=new CanvasImageItem*[15]; 170 p1_side=new CanvasImageItem*[15];
211 QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name)); 171 QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name));
212 QImage piece_1_front=piece_1_all.copy(0,0,15,15); 172 QImage piece_1_front=piece_1_all.copy(0,0,15,15);
213 QImage piece_1_side=piece_1_all.copy(0,15,15,5); 173 QImage piece_1_side=piece_1_all.copy(0,15,15,5);
214 174
215 p2=new CanvasImageItem*[15]; 175 p2=new CanvasImageItem*[15];
216 p2_side=new CanvasImageItem*[15]; 176 p2_side=new CanvasImageItem*[15];
217 QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name)); 177 QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name));
218 QImage piece_2_front=piece_2_all.copy(0,0,15,15); 178 QImage piece_2_front=piece_2_all.copy(0,0,15,15);
219 QImage piece_2_side=piece_2_all.copy(0,15,15,5); 179 QImage piece_2_side=piece_2_all.copy(0,15,15,5);
220 180
221 181
222 for(a=0;a<15;a++) 182 for(a=0;a<15;a++)
223 { 183 {
224 p1[a]=new CanvasImageItem(piece_1_front,area); 184 p1[a]=new CanvasImageItem(piece_1_front,area);
225 p1[a]->setSize(15,15); 185 p1[a]->setSize(15,15);
226 p1_side[a]=new CanvasImageItem(piece_1_side,area); 186 p1_side[a]=new CanvasImageItem(piece_1_side,area);
227 p1_side[a]->setSize(15,5); 187 p1_side[a]->setSize(15,5);
228 188
229 p2[a]=new CanvasImageItem(piece_2_front,area); 189 p2[a]=new CanvasImageItem(piece_2_front,area);
230 p2[a]->setSize(15,15); 190 p2[a]->setSize(15,15);
231 p2_side[a]=new CanvasImageItem(piece_2_side,area); 191 p2_side[a]=new CanvasImageItem(piece_2_side,area);
232 p2_side[a]->setSize(15,5); 192 p2_side[a]->setSize(15,5);
233 } 193 }
234 draw(); 194 draw();
235 195
236 //the dice 196 //the dice
237 QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name)); 197 QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name));
238 diceA1=new CanvasImageItem*[7]; 198 diceA1=new CanvasImageItem*[7];
239 diceA2=new CanvasImageItem*[7]; 199 diceA2=new CanvasImageItem*[7];
240 QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name)); 200 QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name));
241 diceB1=new CanvasImageItem*[7]; 201 diceB1=new CanvasImageItem*[7];
242 diceB2=new CanvasImageItem*[7]; 202 diceB2=new CanvasImageItem*[7];
243 QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name)); 203 QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name));
244 //oddsDice=new CanvasImageItem*[6]; 204 //oddsDice=new CanvasImageItem*[6];
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);
318 nomove_marker->setY(200); 270 nomove_marker->setY(200);
319 nomove_marker->setZ(2); 271 nomove_marker->setZ(2);
320 nomove_marker->hide(); 272 nomove_marker->hide();
321 273
322 //default human against computer 274 //default human against computer
323 player1_auto=false; 275 player1_auto=false;
324 player2_auto=true; 276 player2_auto=true;
325 //start new game 277 //start new game
326 newgame(); 278 newgame();
327} 279}
328 280
329BackGammon::~BackGammon() 281BackGammon::~BackGammon()
330{ 282{
331 //DESTRUCTOR 283 //DESTRUCTOR
332} 284}
333 285
334void BackGammon::newgame() 286void BackGammon::newgame()
335{ 287{
336 gameFinished=false; 288 gameFinished=false;
337 QDateTime now=QDateTime::currentDateTime(); 289 QDateTime now=QDateTime::currentDateTime();
338 game_name=now.date().toString()+"_"+now.time().toString(); 290 game_name=now.date().toString()+"_"+now.time().toString();
339 move->reset(); 291 move->reset();
340 draw(); 292 draw();
341 diceA1_value=7; 293 diceA1_value=7;
342 diceA2_value=7; 294 diceA2_value=7;
343 diceA3_value=7; 295 diceA3_value=7;
344 diceA4_value=7; 296 diceA4_value=7;
345 diceB1_value=7; 297 diceB1_value=7;
346 diceB2_value=7; 298 diceB2_value=7;
347 diceB3_value=7; 299 diceB3_value=7;
348 diceB4_value=7; 300 diceB4_value=7;
349 showdice(); 301 showdice();
350 player=2; 302 player=2;
351 dice1_played=true; 303 dice1_played=true;
352 dice2_played=true; 304 dice2_played=true;
353 dice3_played=true; 305 dice3_played=true;
354 dice4_played=true; 306 dice4_played=true;
355 dice_rolled=false; 307 dice_rolled=false;
356 setplayer(); 308 setplayer();
357 area->update(); 309 area->update();
358} 310}
359 311
360void BackGammon::playerselect() 312void BackGammon::playerselect()
361{ 313{
362 PlayerDialog* playerdialog=new PlayerDialog(this); 314 PlayerDialog* playerdialog=new PlayerDialog(this);
363 playerdialog->setAuto1(player1_auto); 315 playerdialog->setAuto1(player1_auto);
364 playerdialog->setAuto2(player2_auto); 316 playerdialog->setAuto2(player2_auto);
365 if(!playerdialog->exec()) 317 if(!playerdialog->exec())
366 return; 318 return;
367 player1_auto=playerdialog->getAuto1(); 319 player1_auto=playerdialog->getAuto1();
368 player2_auto=playerdialog->getAuto2(); 320 player2_auto=playerdialog->getAuto2();
369} 321}
370 322
371void BackGammon::loadgame() 323void BackGammon::loadgame()
372{ 324{
373 FileDialog* file=new FileDialog(this,"Load Game",".game"); 325 FileDialog* file=new FileDialog(this,"Load Game",".game");
374 if(!file->exec()) 326 if(!file->exec())
375 return; 327 return;
376 328
377 game_name=file->filename(); 329 game_name=file->filename();
378 QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; 330 QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game";
379 331
380 Config game(game_file,Config::File); 332 Config game(game_file,Config::File);
381 game.setGroup("dice"); 333 game.setGroup("dice");
382 diceA1_value=game.readNumEntry("diceA1_value"); 334 diceA1_value=game.readNumEntry("diceA1_value");
383 diceA2_value=game.readNumEntry("diceA2_value"); 335 diceA2_value=game.readNumEntry("diceA2_value");
384 diceA3_value=game.readNumEntry("diceA3_value"); 336 diceA3_value=game.readNumEntry("diceA3_value");
385 diceA4_value=game.readNumEntry("diceA4_value"); 337 diceA4_value=game.readNumEntry("diceA4_value");
386 diceB1_value=game.readNumEntry("diceB1_value"); 338 diceB1_value=game.readNumEntry("diceB1_value");
387 diceB2_value=game.readNumEntry("diceB2_value"); 339 diceB2_value=game.readNumEntry("diceB2_value");
388 diceB3_value=game.readNumEntry("diceB3_value"); 340 diceB3_value=game.readNumEntry("diceB3_value");
389 diceB4_value=game.readNumEntry("diceB4_value"); 341 diceB4_value=game.readNumEntry("diceB4_value");
390 player=game.readNumEntry("player"); 342 player=game.readNumEntry("player");
391 dice1_played=game.readBoolEntry("dice1_played"); 343 dice1_played=game.readBoolEntry("dice1_played");
392 dice2_played=game.readBoolEntry("dice2_played"); 344 dice2_played=game.readBoolEntry("dice2_played");
393 dice3_played=game.readBoolEntry("dice3_played"); 345 dice3_played=game.readBoolEntry("dice3_played");
394 dice4_played=game.readBoolEntry("dice4_played"); 346 dice4_played=game.readBoolEntry("dice4_played");
395 dice_rolled=game.readBoolEntry("dice_rolled"); 347 dice_rolled=game.readBoolEntry("dice_rolled");
396 player1_auto=game.readBoolEntry("player1_auto"); 348 player1_auto=game.readBoolEntry("player1_auto");
397 player2_auto=game.readBoolEntry("player2_auto"); 349 player2_auto=game.readBoolEntry("player2_auto");
398 350
399 game.setGroup("pieces"); 351 game.setGroup("pieces");
400 QString label; 352 QString label;
401 LoadSave load; 353 LoadSave load;
402 for(int a=0;a<28;a++) 354 for(int a=0;a<28;a++)
403 { 355 {
404 label.setNum(a); 356 label.setNum(a);
405 load.pop[a].total = game.readNumEntry(label,0); 357 load.pop[a].total = game.readNumEntry(label,0);
406 } 358 }
407 359
408 move->loadGame(load); 360 move->loadGame(load);
409 setplayer(); 361 setplayer();
410 showdice(); 362 showdice();
411 draw(); 363 draw();
412 area->update(); 364 area->update();
413} 365}
414 366
415void BackGammon::savegame() 367void BackGammon::savegame()
416{ 368{
417 QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; 369 QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game";
418 370
419 Config game(game_file,Config::File); 371 Config game(game_file,Config::File);
420 game.setGroup("dice"); 372 game.setGroup("dice");
421 game.writeEntry("diceA1_value",diceA1_value); 373 game.writeEntry("diceA1_value",diceA1_value);
422 game.writeEntry("diceA2_value",diceA2_value); 374 game.writeEntry("diceA2_value",diceA2_value);
423 game.writeEntry("diceA3_value",diceA3_value); 375 game.writeEntry("diceA3_value",diceA3_value);
424 game.writeEntry("diceA4_value",diceA4_value); 376 game.writeEntry("diceA4_value",diceA4_value);
425 game.writeEntry("diceB1_value",diceB1_value); 377 game.writeEntry("diceB1_value",diceB1_value);
426 game.writeEntry("diceB2_value",diceB3_value); 378 game.writeEntry("diceB2_value",diceB3_value);
427 game.writeEntry("diceB3_value",diceB4_value); 379 game.writeEntry("diceB3_value",diceB4_value);
428 game.writeEntry("diceB4_value",diceB4_value); 380 game.writeEntry("diceB4_value",diceB4_value);
429 game.writeEntry("player",player); 381 game.writeEntry("player",player);
430 game.writeEntry("dice1_played",dice1_played); 382 game.writeEntry("dice1_played",dice1_played);
431 game.writeEntry("dice2_played",dice2_played); 383 game.writeEntry("dice2_played",dice2_played);
432 game.writeEntry("dice3_played",dice3_played); 384 game.writeEntry("dice3_played",dice3_played);
433 game.writeEntry("dice4_played",dice4_played); 385 game.writeEntry("dice4_played",dice4_played);
434 game.writeEntry("dice_rolled",dice_rolled); 386 game.writeEntry("dice_rolled",dice_rolled);
435 game.writeEntry("player1_auto",player1_auto); 387 game.writeEntry("player1_auto",player1_auto);
436 game.writeEntry("player2_auto",player2_auto); 388 game.writeEntry("player2_auto",player2_auto);
437 389
438 game.setGroup("pieces"); 390 game.setGroup("pieces");
439 QString label; 391 QString label;
440 LoadSave save=move->saveGame(); 392 LoadSave save=move->saveGame();
441 for(int a=0;a<28;a++) 393 for(int a=0;a<28;a++)
442 { 394 {
443 label.setNum(a); 395 label.setNum(a);
444 game.writeEntry(label,save.pop[a].total); 396 game.writeEntry(label,save.pop[a].total);
445 } 397 }
446 QMessageBox::information(this,"Backgammon","Game saved","OK"); 398 QMessageBox::information(this,"Backgammon","Game saved","OK");
447} 399}
448 400
449void BackGammon::deletegame() 401void BackGammon::deletegame()
450{ 402{
451 FileDialog* file=new FileDialog(this,"Delete Game",".game"); 403 FileDialog* file=new FileDialog(this,"Delete Game",".game");
452 if(!file->exec()) 404 if(!file->exec())
453 return; 405 return;
454 406
455 game_name=file->filename(); 407 game_name=file->filename();
456 QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; 408 QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game";
457 409
458 if(!QMessageBox::warning(this,"Backgammon","deleted game\n"+game_name+" ?","OK","Cancel")) 410 if(!QMessageBox::warning(this,"Backgammon","deleted game\n"+game_name+" ?","OK","Cancel"))
459 { 411 {
460 QFile(game_file).remove(); 412 QFile(game_file).remove();
461 } 413 }
462} 414}
463 415
464 416
465void BackGammon::newtheme() 417void BackGammon::newtheme()
466{ 418{
467 ThemeDialog* theme=new ThemeDialog(this); 419 ThemeDialog* theme=new ThemeDialog(this);
468 420
469 ImageNames names; 421 ImageNames names;
470 names.theme=theme_name; 422 names.theme=theme_name;
471 names.board=board_name; 423 names.board=board_name;
472 names.pieces1=piecesA_name; 424 names.pieces1=piecesA_name;
473 names.pieces2=piecesB_name; 425 names.pieces2=piecesB_name;
474 names.dice1=diceA_name; 426 names.dice1=diceA_name;
475 names.dice2=diceB_name; 427 names.dice2=diceB_name;
476 names.odds=odds_name; 428 names.odds=odds_name;
477 names.table=table_name; 429 names.table=table_name;
478 430
479 theme->setCurrent(names); 431 theme->setCurrent(names);
480 if(!theme->exec()) 432 if(!theme->exec())
481 return; 433 return;
482 434
483 names=theme->getNames(); 435 names=theme->getNames();
484 theme_name=names.theme; 436 theme_name=names.theme;
485 board_name=names.board; 437 board_name=names.board;
486 piecesA_name=names.pieces1; 438 piecesA_name=names.pieces1;
487 piecesB_name=names.pieces2; 439 piecesB_name=names.pieces2;
488 diceA_name=names.dice1; 440 diceA_name=names.dice1;
489 diceB_name=names.dice2; 441 diceB_name=names.dice2;
490 odds_name=names.odds; 442 odds_name=names.odds;
491 table_name=names.table; 443 table_name=names.table;
492 444
493 applytheme(); 445 applytheme();
494} 446}
495 447
496void BackGammon::loadtheme() 448void BackGammon::loadtheme()
497{ 449{
498 FileDialog* file=new FileDialog(this,"Load Theme",".theme"); 450 FileDialog* file=new FileDialog(this,"Load Theme",".theme");
499 if(!file->exec()) 451 if(!file->exec())
500 return; 452 return;
501 453
502 theme_name=file->filename(); 454 theme_name=file->filename();
503 QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; 455 QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme";
504 456
505 Config theme(theme_file,Config::File); 457 Config theme(theme_file,Config::File);
506 theme.setGroup("theme"); 458 theme.setGroup("theme");
507 board_name=theme.readEntry("board","board_1"); 459 board_name=theme.readEntry("board","board_1");
508 piecesA_name=theme.readEntry("pieces1","pieces_1"); 460 piecesA_name=theme.readEntry("pieces1","pieces_1");
509 piecesB_name=theme.readEntry("pieces2","pieces_2"); 461 piecesB_name=theme.readEntry("pieces2","pieces_2");
510 diceA_name=theme.readEntry("dice1","dice_1"); 462 diceA_name=theme.readEntry("dice1","dice_1");
511 diceB_name=theme.readEntry("dice2","dice_2"); 463 diceB_name=theme.readEntry("dice2","dice_2");
512 table_name=theme.readEntry("table","table_1"); 464 table_name=theme.readEntry("table","table_1");
513 odds_name=theme.readEntry("odds","odds_1"); 465 odds_name=theme.readEntry("odds","odds_1");
514 466
515 applytheme(); 467 applytheme();
516 468
517} 469}
518 470
519void BackGammon::savetheme() 471void BackGammon::savetheme()
520{ 472{
521 if(theme_name=="default") 473 if(theme_name=="default")
522 { 474 {
523 QMessageBox::information(this,"Backgammon","Sorry\nCannot overwrite default.theme","OK"); 475 QMessageBox::information(this,"Backgammon","Sorry\nCannot overwrite default.theme","OK");
524 return; 476 return;
525 } 477 }
526 QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; 478 QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme";
527 if(QMessageBox::information(this,"Backgammon","Save Theme\n"+theme_name,"Yes","No")) 479 if(QMessageBox::information(this,"Backgammon","Save Theme\n"+theme_name,"Yes","No"))
528 return; 480 return;
529 481
530 Config theme(theme_file,Config::File); 482 Config theme(theme_file,Config::File);
531 theme.setGroup("theme"); 483 theme.setGroup("theme");
532 theme.writeEntry("board",board_name); 484 theme.writeEntry("board",board_name);
533 theme.writeEntry("pieces1",piecesA_name); 485 theme.writeEntry("pieces1",piecesA_name);
534 theme.writeEntry("pieces2",piecesB_name); 486 theme.writeEntry("pieces2",piecesB_name);
535 theme.writeEntry("dice1",diceA_name); 487 theme.writeEntry("dice1",diceA_name);
536 theme.writeEntry("dice2",diceB_name); 488 theme.writeEntry("dice2",diceB_name);
537 theme.writeEntry("table",table_name); 489 theme.writeEntry("table",table_name);
538 theme.writeEntry("odds",odds_name); 490 theme.writeEntry("odds",odds_name);
539 491
540} 492}
541 493
542void BackGammon::themedefault() 494void BackGammon::themedefault()
543{ 495{
544 if(QMessageBox::information(this,"Backgammon","Make Theme\n"+theme_name+"\nthe default theme","Yes","No")) 496 if(QMessageBox::information(this,"Backgammon","Make Theme\n"+theme_name+"\nthe default theme","Yes","No"))
545 return; 497 return;
546 498
547 Config conf("backgammon"); 499 Config conf("backgammon");
548 conf.setGroup("general"); 500 conf.setGroup("general");
549 conf.writeEntry("theme",theme_name); 501 conf.writeEntry("theme",theme_name);
550} 502}
551 503
552void BackGammon::deletetheme() 504void BackGammon::deletetheme()
553{ 505{
554 FileDialog* file=new FileDialog(this,"Delete Theme",".theme"); 506 FileDialog* file=new FileDialog(this,"Delete Theme",".theme");
555 if(!file->exec()) 507 if(!file->exec())
556 return; 508 return;
557 509
558 theme_name=file->filename(); 510 theme_name=file->filename();
559 QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; 511 QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme";
560 512
561 if(!QMessageBox::warning(this,"Backgammon","deleted theme "+theme_name+" ?","OK","Cancel")) 513 if(!QMessageBox::warning(this,"Backgammon","deleted theme "+theme_name+" ?","OK","Cancel"))
562 { 514 {
563 QFile(theme_file).remove(); 515 QFile(theme_file).remove();
564 } 516 }
565} 517}
566 518
567void BackGammon::modify_AI() 519void BackGammon::modify_AI()
568{ 520{
569 AI_Dialog* ai_mod=new AI_Dialog(this,"Load Theme",".theme"); 521 AI_Dialog* ai_mod=new AI_Dialog(this,"Load Theme",".theme");
570 ai_mod->setAISettings(move->getAISettings()); 522 ai_mod->setAISettings(move->getAISettings());
571 if(!ai_mod->exec()) 523 if(!ai_mod->exec())
572 return; 524 return;
573 525
574 //get the AI settings 526 //get the AI settings
575 AISettings ai=ai_mod->getAISettings(); 527 AISettings ai=ai_mod->getAISettings();
576 move->setAISettings(ai); 528 move->setAISettings(ai);
577 //write new settings to conf file 529 //write new settings to conf file
578 Config conf("backgammon"); 530 Config conf("backgammon");
579 conf.setGroup("ai"); 531 conf.setGroup("ai");
580 conf.writeEntry("rescue",ai.rescue); 532 conf.writeEntry("rescue",ai.rescue);
581 conf.writeEntry("eliminate",ai.eliminate); 533 conf.writeEntry("eliminate",ai.eliminate);
582 conf.writeEntry("expose",ai.expose); 534 conf.writeEntry("expose",ai.expose);
583 conf.writeEntry("protect",ai.protect); 535 conf.writeEntry("protect",ai.protect);
584 conf.writeEntry("safe",ai.safe); 536 conf.writeEntry("safe",ai.safe);
585 conf.writeEntry("empty",ai.empty); 537 conf.writeEntry("empty",ai.empty);
586} 538}
587 539
588void BackGammon::setrules() 540void BackGammon::setrules()
589{ 541{
590 RulesDialog* rulesdialog=new RulesDialog(this,"Load Theme",".theme"); 542 RulesDialog* rulesdialog=new RulesDialog(this,"Load Theme",".theme");
591 rulesdialog->setRules(rules); 543 rulesdialog->setRules(rules);
592 if(!rulesdialog->exec()) 544 if(!rulesdialog->exec())
593 return; 545 return;
594 rules=rulesdialog->getRules(); 546 rules=rulesdialog->getRules();
595 Config conf("backgammon"); 547 Config conf("backgammon");
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);
626 p1[a]->setZ(pieces.player1[a].z); 565 p1[a]->setZ(pieces.player1[a].z);
627 p1[a]->show(); 566 p1[a]->show();
628 p1_side[a]->hide(); 567 p1_side[a]->hide();
629 } 568 }
630 else 569 else
631 { 570 {
632 p1_side[a]->setX(pieces.player1[a].x); 571 p1_side[a]->setX(pieces.player1[a].x);
633 p1_side[a]->setY(pieces.player1[a].y); 572 p1_side[a]->setY(pieces.player1[a].y);
634 p1_side[a]->setZ(pieces.player1[a].z); 573 p1_side[a]->setZ(pieces.player1[a].z);
635 p1_side[a]->show(); 574 p1_side[a]->show();
636 p1[a]->hide(); 575 p1[a]->hide();
637 } 576 }
638 577
639 if(!pieces.player2[a].side) 578 if(!pieces.player2[a].side)
640 { 579 {
641 p2[a]->setX(pieces.player2[a].x); 580 p2[a]->setX(pieces.player2[a].x);
642 p2[a]->setY(pieces.player2[a].y); 581 p2[a]->setY(pieces.player2[a].y);
643 p2[a]->setZ(pieces.player2[a].z); 582 p2[a]->setZ(pieces.player2[a].z);
644 p2[a]->show(); 583 p2[a]->show();
645 p2_side[a]->hide(); 584 p2_side[a]->hide();
646 } 585 }
647 else 586 else
648 { 587 {
649 p2_side[a]->setX(pieces.player2[a].x); 588 p2_side[a]->setX(pieces.player2[a].x);
650 p2_side[a]->setY(pieces.player2[a].y); 589 p2_side[a]->setY(pieces.player2[a].y);
651 p2_side[a]->setZ(pieces.player2[a].z); 590 p2_side[a]->setZ(pieces.player2[a].z);
652 p2_side[a]->show(); 591 p2_side[a]->show();
653 p2[a]->hide(); 592 p2[a]->hide();
654 } 593 }
655 } 594 }
656} 595}
657 596
658void BackGammon::mouse(int x,int y) 597void BackGammon::mouse(int x,int y)
659{ 598{
660 if(gameFinished) 599 if(gameFinished)
661 { 600 {
662 newgame(); 601 newgame();
663 return; 602 return;
664 } 603 }
665 if(y<=200) //move pieces 604 if(y<=200) //move pieces
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();
695 } 634 }
696 } 635 }
697 area->update(); 636 area->update();
698 } 637 }
699 else //roll dice 638 else //roll dice
700 { 639 {
701 if(x>=10 && x<=65 && player==1 && !dice_rolled) 640 if(x>=10 && x<=65 && player==1 && !dice_rolled)
702 { 641 {
703 dice1_played=false; 642 dice1_played=false;
704 dice2_played=false; 643 dice2_played=false;
705 dice3_played=false; 644 dice3_played=false;
706 dice4_played=false; 645 dice4_played=false;
707 dice_rolled=true; 646 dice_rolled=true;
708 srand(QTime::currentTime().msec()); 647 srand(QTime::currentTime().msec());
709 diceA1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); 648 diceA1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0));
710 diceA2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); 649 diceA2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0));
711 if(diceA1_value==diceA2_value) 650 if(diceA1_value==diceA2_value)
712 { 651 {
713 diceA3_value=diceA1_value; 652 diceA3_value=diceA1_value;
714 diceA4_value=diceA1_value; 653 diceA4_value=diceA1_value;
715 } 654 }
716 else 655 else
717 { 656 {
718 diceA3_value=7; 657 diceA3_value=7;
719 dice3_played=true; 658 dice3_played=true;
720 diceA4_value=7; 659 diceA4_value=7;
721 dice4_played=true; 660 dice4_played=true;
722 } 661 }
723 showdice(); 662 showdice();
724 area->update(); 663 area->update();
725 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); 664 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto);
726 665
727 } 666 }
728 else if(x>=160 && x<=225 && player==2 && !dice_rolled) 667 else if(x>=160 && x<=225 && player==2 && !dice_rolled)
729 { 668 {
730 dice1_played=false; 669 dice1_played=false;
731 dice2_played=false; 670 dice2_played=false;
732 dice3_played=false; 671 dice3_played=false;
733 dice4_played=false; 672 dice4_played=false;
734 dice_rolled=true; 673 dice_rolled=true;
735 srand(QTime::currentTime().msec()); 674 srand(QTime::currentTime().msec());
736 diceB1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); 675 diceB1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0));
737 diceB2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); 676 diceB2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0));
738 if(diceB1_value==diceB2_value) 677 if(diceB1_value==diceB2_value)
739 { 678 {
740 diceB3_value=diceB1_value; 679 diceB3_value=diceB1_value;
741 diceB4_value=diceB1_value; 680 diceB4_value=diceB1_value;
742 } 681 }
743 else 682 else
744 { 683 {
745 diceB3_value=7; 684 diceB3_value=7;
746 dice3_played=true; 685 dice3_played=true;
747 diceB4_value=7; 686 diceB4_value=7;
748 dice4_played=true; 687 dice4_played=true;
749 } 688 }
750 showdice(); 689 showdice();
751 area->update(); 690 area->update();
752 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); 691 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto);
753 } 692 }
754 } 693 }
755} 694}
756 695
757void BackGammon::done_dice1() 696void BackGammon::done_dice1()
758{ 697{
759 dice1_played=true; 698 dice1_played=true;
760 if(player==1) 699 if(player==1)
761 diceA1_value=7; 700 diceA1_value=7;
762 else 701 else
763 diceB1_value=7; 702 diceB1_value=7;
764 setplayer(); 703 setplayer();
765 showdice(); 704 showdice();
766 draw(); 705 draw();
767 area->update(); 706 area->update();
768 if(!dice2_played || !dice3_played || !dice4_played) 707 if(!dice2_played || !dice3_played || !dice4_played)
769 { 708 {
770 if(player==1) 709 if(player==1)
771 { 710 {
772 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); 711 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto);
773 } 712 }
774 else 713 else
775 { 714 {
776 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); 715 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto);
777 } 716 }
778 } 717 }
779} 718}
780 719
781void BackGammon::done_dice2() 720void BackGammon::done_dice2()
782{ 721{
783 dice2_played=true; 722 dice2_played=true;
784 if(player==1) 723 if(player==1)
785 diceA2_value=7; 724 diceA2_value=7;
786 else 725 else
787 diceB2_value=7; 726 diceB2_value=7;
788 setplayer(); 727 setplayer();
789 showdice(); 728 showdice();
790 draw(); 729 draw();
791 area->update(); 730 area->update();
792 if(!dice1_played || !dice3_played || !dice4_played) 731 if(!dice1_played || !dice3_played || !dice4_played)
793 { 732 {
794 if(player==1) 733 if(player==1)
795 { 734 {
796 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); 735 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto);
797 } 736 }
798 else 737 else
799 { 738 {
800 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); 739 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto);
801 } 740 }
802 } 741 }
803} 742}
804 743
805 744
806void BackGammon::done_dice3() 745void BackGammon::done_dice3()
807{ 746{
808 dice3_played=true; 747 dice3_played=true;
809 if(player==1) 748 if(player==1)
810 diceA3_value=7; 749 diceA3_value=7;
811 else 750 else
812 diceB3_value=7; 751 diceB3_value=7;
813 setplayer(); 752 setplayer();
814 showdice(); 753 showdice();
815 draw(); 754 draw();
816 area->update(); 755 area->update();
817 if(!dice1_played || !dice2_played || !dice4_played) 756 if(!dice1_played || !dice2_played || !dice4_played)
818 { 757 {
819 if(player==1) 758 if(player==1)
820 { 759 {
821 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); 760 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto);
822 } 761 }
823 else 762 else
824 { 763 {
825 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); 764 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto);
826 } 765 }
827 } 766 }
828} 767}
829 768
830 769
831void BackGammon::done_dice4() 770void BackGammon::done_dice4()
832{ 771{
833 dice4_played=true; 772 dice4_played=true;
834 if(player==1) 773 if(player==1)
835 diceA4_value=7; 774 diceA4_value=7;
836 else 775 else
837 diceB4_value=7; 776 diceB4_value=7;
838 setplayer(); 777 setplayer();
839 showdice(); 778 showdice();
840 draw(); 779 draw();
841 area->update(); 780 area->update();
842 if(!dice1_played || !dice2_played || !dice3_played) 781 if(!dice1_played || !dice2_played || !dice3_played)
843 { 782 {
844 if(player==1) 783 if(player==1)
845 { 784 {
846 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); 785 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto);
847 } 786 }
848 else 787 else
849 { 788 {
850 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); 789 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto);
851 } 790 }
852 } 791 }
853} 792}
854 793
855 794
856void BackGammon::nomove() 795void BackGammon::nomove()
857{ 796{
858 if(player==1) 797 if(player==1)
859 nomove_marker->setX(0); 798 nomove_marker->setX(0);
860 else 799 else
861 nomove_marker->setX(170); 800 nomove_marker->setX(170);
862 nomove_marker->show(); 801 nomove_marker->show();
863 message->setText("<b>no move</b>"); 802 message->setText("<b>no move</b>");
864 dice1_played=true; 803 dice1_played=true;
865 dice2_played=true; 804 dice2_played=true;
866 dice3_played=true; 805 dice3_played=true;
867 dice4_played=true; 806 dice4_played=true;
868 if(player==1) 807 if(player==1)
869 { 808 {
870 diceA1_value=7; 809 diceA1_value=7;
871 diceA2_value=7; 810 diceA2_value=7;
872 diceA3_value=7; 811 diceA3_value=7;
873 diceA4_value=7; 812 diceA4_value=7;
874 } 813 }
875 else 814 else
876 { 815 {
877 diceB1_value=7; 816 diceB1_value=7;
878 diceB2_value=7; 817 diceB2_value=7;
879 diceB3_value=7; 818 diceB3_value=7;
880 diceB4_value=7; 819 diceB4_value=7;
881 } 820 }
882 area->update(); 821 area->update();
883 QTimer::singleShot(2000,this,SLOT(nomove2())); 822 QTimer::singleShot(2000,this,SLOT(nomove2()));
884} 823}
885 824
886void BackGammon::nomove2() 825void BackGammon::nomove2()
887{ 826{
888 nomove_marker->hide(); 827 nomove_marker->hide();
889 setplayer(); 828 setplayer();
890 showdice(); 829 showdice();
891 draw(); 830 draw();
892 area->update(); 831 area->update();
893} 832}
894 833
895void BackGammon::finished(int theplayer) 834void BackGammon::finished(int theplayer)
896{ 835{
897 nomove_marker->hide(); 836 nomove_marker->hide();
898 if(theplayer==1) 837 if(theplayer==1)
899 message->setText("<b>Player 1 wins. Click on board for new game.</b>"); 838 message->setText("<b>Player 1 wins. Click on board for new game.</b>");
900 else 839 else
901 message->setText("<b>Player 2 wins. Click on board for new game.</b>"); 840 message->setText("<b>Player 2 wins. Click on board for new game.</b>");
902 diceA1_value=7; 841 diceA1_value=7;
903 diceA2_value=7; 842 diceA2_value=7;
904 diceB1_value=7; 843 diceB1_value=7;
905 diceB2_value=7; 844 diceB2_value=7;
906 player=0; 845 player=0;
907 showdice(); 846 showdice();
908 draw(); 847 draw();
909 area->update(); 848 area->update();
910 gameFinished=true; 849 gameFinished=true;
911} 850}
912 851
913void BackGammon::showdice() 852void BackGammon::showdice()
914{ 853{
915 int value_diceA1=diceA1_value-1; 854 int value_diceA1=diceA1_value-1;
916 if(diceA1_value==7 && diceA3_value!=7) 855 if(diceA1_value==7 && diceA3_value!=7)
917 value_diceA1=diceA3_value-1; 856 value_diceA1=diceA3_value-1;
918 857
919 int value_diceA2=diceA2_value-1; 858 int value_diceA2=diceA2_value-1;
920 if(diceA2_value==7 && diceA4_value!=7) 859 if(diceA2_value==7 && diceA4_value!=7)
921 value_diceA2=diceA4_value-1; 860 value_diceA2=diceA4_value-1;
922 861
923 int value_diceB1=diceB1_value-1; 862 int value_diceB1=diceB1_value-1;
924 if(diceB1_value==7 && diceB3_value!=7) 863 if(diceB1_value==7 && diceB3_value!=7)
925 value_diceB1=diceB3_value-1; 864 value_diceB1=diceB3_value-1;
926 865
927 int value_diceB2=diceB2_value-1; 866 int value_diceB2=diceB2_value-1;
928 if(diceB2_value==7 && diceB4_value!=7) 867 if(diceB2_value==7 && diceB4_value!=7)
929 value_diceB2=diceB4_value-1; 868 value_diceB2=diceB4_value-1;
930 869
931 for(int index=0;index<7;index++) 870 for(int index=0;index<7;index++)
932 { 871 {
933 if(value_diceA1==index) 872 if(value_diceA1==index)
934 diceA1[index]->show(); 873 diceA1[index]->show();
935 else 874 else
936 diceA1[index]->hide(); 875 diceA1[index]->hide();
937 876
938 if(value_diceA2==index) 877 if(value_diceA2==index)
939 diceA2[index]->show(); 878 diceA2[index]->show();
940 else 879 else
941 diceA2[index]->hide(); 880 diceA2[index]->hide();
942 881
943 if(value_diceB1==index) 882 if(value_diceB1==index)
944 diceB1[index]->show(); 883 diceB1[index]->show();
945 else 884 else
946 diceB1[index]->hide(); 885 diceB1[index]->hide();
947 886
948 if(value_diceB2==index) 887 if(value_diceB2==index)
949 diceB2[index]->show(); 888 diceB2[index]->show();
950 else 889 else
951 diceB2[index]->hide(); 890 diceB2[index]->hide();
952 } 891 }
953} 892}
954 893
955void BackGammon::setplayer() 894void BackGammon::setplayer()
956{ 895{
957 if(dice1_played && dice2_played && dice3_played && dice4_played && player==1) 896 if(dice1_played && dice2_played && dice3_played && dice4_played && player==1)
958 { 897 {
959 message->setText("<b>P2 turn</b>"); 898 message->setText("<b>P2 turn</b>");
960 dice_rolled=false; 899 dice_rolled=false;
961 player=2; 900 player=2;
962 if(player2_auto) 901 if(player2_auto)
963 QTimer::singleShot(2000,this,SLOT(autoroll_dice2())); 902 QTimer::singleShot(2000,this,SLOT(autoroll_dice2()));
964 } 903 }
965 else if(dice1_played && dice2_played && dice3_played && dice4_played && player==2) 904 else if(dice1_played && dice2_played && dice3_played && dice4_played && player==2)
966 { 905 {
967 message->setText("<b>P1 turn</b>"); 906 message->setText("<b>P1 turn</b>");
968 dice_rolled=false; 907 dice_rolled=false;
969 player=1; 908 player=1;
970 if(player1_auto) 909 if(player1_auto)
971 QTimer::singleShot(2000,this,SLOT(autoroll_dice1())); 910 QTimer::singleShot(2000,this,SLOT(autoroll_dice1()));
972 } 911 }
973} 912}
974 913
975void BackGammon::autoroll_dice1() 914void BackGammon::autoroll_dice1()
976{ 915{
977 mouse(20,210); 916 mouse(20,210);
978} 917}
979 918
980void BackGammon::autoroll_dice2() 919void BackGammon::autoroll_dice2()
981{ 920{
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
1005 QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name)); 936 QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name));
1006 QImage piece_2_front=piece_2_all.copy(0,0,15,15); 937 QImage piece_2_front=piece_2_all.copy(0,0,15,15);
1007 QImage piece_2_side=piece_2_all.copy(0,15,15,5); 938 QImage piece_2_side=piece_2_all.copy(0,15,15,5);
1008 939
1009 int a=0; 940 int a=0;
1010 for(a=0;a<15;a++) 941 for(a=0;a<15;a++)
1011 { 942 {
1012 p1[a]->setImage(piece_1_front); 943 p1[a]->setImage(piece_1_front);
1013 p1_side[a]->setImage(piece_1_side); 944 p1_side[a]->setImage(piece_1_side);
1014 945
1015 p2[a]->setImage(piece_2_front); 946 p2[a]->setImage(piece_2_front);
1016 p2_side[a]->setImage(piece_2_side); 947 p2_side[a]->setImage(piece_2_side);
1017 } 948 }
1018 draw(); 949 draw();
1019 950
1020 QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name)); 951 QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name));
1021 QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name)); 952 QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name));
1022 QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name)); 953 QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name));
1023 954
1024 for(a=0;a<7;a++) 955 for(a=0;a<7;a++)
1025 { 956 {
1026 QImage dicebgA=dicebgA_all.copy(a*25,0,25,25); 957 QImage dicebgA=dicebgA_all.copy(a*25,0,25,25);
1027 diceA1[a]->setImage(dicebgA); 958 diceA1[a]->setImage(dicebgA);
1028 diceA2[a]->setImage(dicebgA); 959 diceA2[a]->setImage(dicebgA);
1029 960
1030 QImage dicebgB=dicebgB_all.copy(a*25,0,25,25); 961 QImage dicebgB=dicebgB_all.copy(a*25,0,25,25);
1031 diceB1[a]->setImage(dicebgB); 962 diceB1[a]->setImage(dicebgB);
1032 diceB2[a]->setImage(dicebgB); 963 diceB2[a]->setImage(dicebgB);
1033 /* 964 /*
1034 if(a<6) 965 if(a<6)
1035 { 966 {
1036 QImage oddsbg=oddsbg_all.copy(a*15,0,15,15); 967 QImage oddsbg=oddsbg_all.copy(a*15,0,15,15);
1037 oddsDice[a]->setImage(oddsbg); 968 oddsDice[a]->setImage(oddsbg);
1038 } 969 }
1039 */ 970 */
1040 } 971 }
1041} 972}
1042 973
1043 974
diff --git a/noncore/games/backgammon/backgammon.h b/noncore/games/backgammon/backgammon.h
index 40dbaba..e3276f1 100644
--- a/noncore/games/backgammon/backgammon.h
+++ b/noncore/games/backgammon/backgammon.h
@@ -1,134 +1,120 @@
1#ifndef BACKGAMMON_H 1#ifndef BACKGAMMON_H
2#define BACKGAMMON_H 2#define BACKGAMMON_H
3 3
4#include "backgammonview.h"
4#include "canvasimageitem.h" 5#include "canvasimageitem.h"
5#include "definition.h"
6//#include "rulesdialog.h" 6//#include "rulesdialog.h"
7#include "moveengine.h" 7#include "moveengine.h"
8 8
9#include <qcanvas.h> 9
10#include <qlabel.h> 10#include <qlabel.h>
11#include <qlineedit.h> 11#include <qmainwindow.h>
12#include <qwidget.h> 12//#include <qwidget.h>
13 13
14 14
15class BackGammonView : public QCanvasView
16{
17 Q_OBJECT
18public:
19 BackGammonView(QCanvas* canvas,QWidget* parent);
20 ~BackGammonView();
21signals:
22 void mouse(int,int);
23private:
24 void contentsMousePressEvent(QMouseEvent* e);
25};
26 15
27class BackGammon : public QWidget 16
17class BackGammon : public QMainWindow
28{ 18{
29 Q_OBJECT 19 Q_OBJECT
30private: 20private:
31 //GUI 21 //GUI
32 //is the style not qte ?
33 bool non_qte;
34 int offset;
35 //the "status" bar 22 //the "status" bar
36 QLineEdit* inputfield; 23 QLabel* message;
37 //the main drawing area 24 //the main drawing area
38 QCanvas* area; 25 QCanvas* area;
39 BackGammonView* boardview; 26 BackGammonView* boardview;
40 CanvasImageItem* board; 27 CanvasImageItem* board;
41 CanvasImageItem* table; 28 CanvasImageItem* table;
42 CanvasImageItem** p1; 29 CanvasImageItem** p1;
43 CanvasImageItem** p2; 30 CanvasImageItem** p2;
44 CanvasImageItem** p1_side; 31 CanvasImageItem** p1_side;
45 CanvasImageItem** p2_side; 32 CanvasImageItem** p2_side;
46 33
47 CanvasImageItem** diceA1; 34 CanvasImageItem** diceA1;
48 CanvasImageItem** diceA2; 35 CanvasImageItem** diceA2;
49 CanvasImageItem** diceB1; 36 CanvasImageItem** diceB1;
50 CanvasImageItem** diceB2; 37 CanvasImageItem** diceB2;
51 //CanvasImageItem** oddsDice; 38 //CanvasImageItem** oddsDice;
52 CanvasImageItem* nomove_marker; 39 CanvasImageItem* nomove_marker;
53 40
54 QCanvasRectangle* marker_current; 41 QCanvasRectangle* marker_current;
55 QCanvasRectangle* marker_next[4]; 42 QCanvasRectangle* marker_next[4];
56 QLabel* message; 43
57 //ENGINE 44 //ENGINE
58 MoveEngine* move; 45 MoveEngine* move;
59 //the dice values 46 //the dice values
60 int diceA1_value; 47 int diceA1_value;
61 int diceA2_value; 48 int diceA2_value;
62 int diceA3_value; 49 int diceA3_value;
63 int diceA4_value; 50 int diceA4_value;
64 int diceB1_value; 51 int diceB1_value;
65 int diceB2_value; 52 int diceB2_value;
66 int diceB3_value; 53 int diceB3_value;
67 int diceB4_value; 54 int diceB4_value;
68 55
69 int player; 56 int player;
70 bool dice1_played; 57 bool dice1_played;
71 bool dice2_played; 58 bool dice2_played;
72 bool dice3_played; 59 bool dice3_played;
73 bool dice4_played; 60 bool dice4_played;
74 bool dice_rolled; 61 bool dice_rolled;
75 //computer opponent 62 //computer opponent
76 bool player1_auto; 63 bool player1_auto;
77 bool player2_auto; 64 bool player2_auto;
78 65
79 //the images; 66 //the images;
80 QString theme_name; 67 QString theme_name;
81 QString board_name; 68 QString board_name;
82 QString piecesA_name; 69 QString piecesA_name;
83 QString piecesB_name; 70 QString piecesB_name;
84 QString diceA_name; 71 QString diceA_name;
85 QString diceB_name; 72 QString diceB_name;
86 QString odds_name; 73 QString odds_name;
87 QString table_name; 74 QString table_name;
88 75
89 //save game 76 //save game
90 QString game_name; 77 QString game_name;
91 78
92 //the rules 79 //the rules
93 Rules rules; 80 Rules rules;
94 81
95 //display settings 82 //display settings
96 Display display; 83 Display display;
97 //is the game finished ? 84 //is the game finished ?
98 bool gameFinished; 85 bool gameFinished;
99 86
100public: 87public:
101 BackGammon( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); 88 BackGammon( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
102 ~BackGammon(); 89 ~BackGammon();
103private slots: 90private slots:
104 void newgame(); 91 void newgame();
105 void playerselect(); 92 void playerselect();
106 void loadgame(); 93 void loadgame();
107 void savegame(); 94 void savegame();
108 void deletegame(); 95 void deletegame();
109 void newtheme(); 96 void newtheme();
110 void loadtheme(); 97 void loadtheme();
111 void savetheme(); 98 void savetheme();
112 void themedefault(); 99 void themedefault();
113 void deletetheme(); 100 void deletetheme();
114 void modify_AI(); 101 void modify_AI();
115 void setrules(); 102 void setrules();
116 void displaySettings();
117 void mouse(int x,int y); 103 void mouse(int x,int y);
118 void done_dice1(); 104 void done_dice1();
119 void done_dice2(); 105 void done_dice2();
120 void done_dice3(); 106 void done_dice3();
121 void done_dice4(); 107 void done_dice4();
122 void nomove(); 108 void nomove();
123 void nomove2(); 109 void nomove2();
124 void finished(int theplayer); 110 void finished(int theplayer);
125 void autoroll_dice1(); 111 void autoroll_dice1();
126 void autoroll_dice2(); 112 void autoroll_dice2();
127private: 113private:
128 void draw(); 114 void draw();
129 void showdice(); 115 void showdice();
130 void setplayer(); 116 void setplayer();
131 void applytheme(); 117 void applytheme();
132}; 118};
133 119
134#endif //BACKGAMMON_H 120#endif //BACKGAMMON_H
diff --git a/noncore/games/backgammon/backgammonview.cpp b/noncore/games/backgammon/backgammonview.cpp
index ecbc12b..6ee8f10 100644
--- a/noncore/games/backgammon/backgammonview.cpp
+++ b/noncore/games/backgammon/backgammonview.cpp
@@ -1,17 +1,23 @@
1#include "backgammonview.h" 1#include "backgammonview.h"
2 2
3BackGammonView::BackGammonView(QCanvas* canvas,QWidget* parent) 3BackGammonView::BackGammonView(QCanvas* canvas,QWidget* parent)
4 :QCanvasView(canvas,parent) 4 :QCanvasView(canvas,parent)
5{ 5{
6 //do nothing
6} 7}
7 8
9
10
8BackGammonView::~BackGammonView() 11BackGammonView::~BackGammonView()
9{ 12{
13 //do nothing
10} 14}
11 15
16
17
12void BackGammonView::contentsMousePressEvent(QMouseEvent* e) 18void BackGammonView::contentsMousePressEvent(QMouseEvent* e)
13{ 19{
14 int x=e->x(); 20 int x=e->x();
15 int y=e->y(); 21 int y=e->y();
16 //emit mousepressed(x,y); 22 emit mouse(x,y);
17} \ No newline at end of file 23}
diff --git a/noncore/games/backgammon/backgammonview.h b/noncore/games/backgammon/backgammonview.h
index e50f2b0..52508e2 100644
--- a/noncore/games/backgammon/backgammonview.h
+++ b/noncore/games/backgammon/backgammonview.h
@@ -1,18 +1,18 @@
1#ifndef BACKGAMMONVIEW_H 1#ifndef BACKGAMMON_VIEW_H
2#define BACKGAMMONVIEW_H 2#define BACKGAMMON_VIEW_H
3 3
4#include <qcanvas.h> 4#include <qcanvas.h>
5 5
6class BackGammonView : public QCanvasView 6class BackGammonView : public QCanvasView
7{ 7{
8 Q_OBJECT 8 Q_OBJECT
9public: 9public:
10 BackGammonView(QCanvas* canvas,QWidget* parent); 10 BackGammonView(QCanvas* canvas,QWidget* parent);
11 ~BackGammonView(); 11 ~BackGammonView();
12signals: 12signals:
13 //void mousepressed(int,int); 13 void mouse(int,int);
14private: 14private:
15 void contentsMousePressEvent(QMouseEvent* e); 15 void contentsMousePressEvent(QMouseEvent* e);
16}; 16};
17 17
18#endif //BACKGAMMONVIEW_H \ No newline at end of file 18#endif //BACKGAMMON_VIEW_H \ No newline at end of file
diff --git a/noncore/games/backgammon/definition.cpp b/noncore/games/backgammon/definition.cpp
index 9e0029d..c036319 100644
--- a/noncore/games/backgammon/definition.cpp
+++ b/noncore/games/backgammon/definition.cpp
@@ -1,3 +1,2 @@
1#include "definition.h" 1#include "definition.h"
2 2
3static bool debug=false;
diff --git a/noncore/games/backgammon/displaydialog.cpp b/noncore/games/backgammon/displaydialog.cpp
deleted file mode 100644
index 8b97545..0000000
--- a/noncore/games/backgammon/displaydialog.cpp
+++ b/dev/null
@@ -1,89 +0,0 @@
1#include "displaydialog.h"
2
3#include <qgroupbox.h>
4#include <qlabel.h>
5
6DisplayDialog::DisplayDialog(QWidget* parent,const char* name,bool modal,WFlags f)
7 : QDialog(parent,name,modal,f)
8{
9 setCaption("Display Configuration");
10 QLabel* header=new QLabel("<b>Change the display settings</b>",this);
11 header->setGeometry(10,10,200,20);
12
13 //
14 QGroupBox* settings_frame=new QGroupBox("Settings",this);
15 settings_frame->setGeometry(10,10,220,120);
16
17 small_box=new QRadioButton("Big display, e.g. for QPE Style",settings_frame);
18 small_box->setGeometry(10,20,200,20);
19 connect(small_box,SIGNAL(clicked()),this,SLOT(small_clicked()));
20
21 big_box=new QRadioButton("Small display, e.g. for Windows Style",settings_frame);
22 big_box->setGeometry(10,50,200,20);
23 connect(big_box,SIGNAL(clicked()),this,SLOT(big_clicked()));
24
25 //
26 QGroupBox* warning_frame=new QGroupBox("Warning",this);
27 warning_frame->setGeometry(10,140,220,120);
28
29 warning_box=new QCheckBox("show style warning",warning_frame);
30 warning_box->setGeometry(10,20,200,20);
31 connect(warning_box,SIGNAL(clicked()),this,SLOT(warning_clicked()));
32
33 QLabel* warning_help=new QLabel("show style warning at statup if the system style is not QPE\nif not set to small you may have\nscrollbars on the palying area",warning_frame);
34 warning_help->setGeometry(10,50,200,60);
35
36 showMaximized();
37}
38
39
40DisplayDialog::~DisplayDialog()
41{
42}
43
44void DisplayDialog::big_clicked()
45{
46 big_box->setChecked(true);
47 small_box->setChecked(false);
48}
49
50void DisplayDialog::small_clicked()
51{
52 big_box->setChecked(false);
53 small_box->setChecked(true);
54}
55
56void DisplayDialog::warning_clicked()
57{
58}
59
60void DisplayDialog::setDisplaySettings(const Display& display)
61{
62 if(!display.small)
63 {
64 big_box->setChecked(false);
65 small_box->setChecked(true);
66 }
67 else
68 {
69 big_box->setChecked(true);
70 small_box->setChecked(false);
71 }
72 if(display.warning)
73 warning_box->setChecked(true);
74 else
75 warning_box->setChecked(false);
76
77}
78
79Display DisplayDialog::getDisplaySettings()
80{
81 Display display;
82 display.small=!small_box->isChecked();
83 display.warning=warning_box->isChecked();
84 return display;
85}
86
87
88
89
diff --git a/noncore/games/backgammon/displaydialog.h b/noncore/games/backgammon/displaydialog.h
deleted file mode 100644
index 26b77f0..0000000
--- a/noncore/games/backgammon/displaydialog.h
+++ b/dev/null
@@ -1,30 +0,0 @@
1#ifndef DISPLAYDLAOG_H
2#define DISPLAYDLAOG_H
3
4#include <qcheckbox.h>
5#include <qdialog.h>
6#include <qradiobutton.h>
7
8#include "definition.h"
9
10
11class DisplayDialog : public QDialog
12{
13 Q_OBJECT
14private:
15 QRadioButton* small_box;
16 QRadioButton* big_box;
17 QCheckBox* warning_box;
18public:
19 DisplayDialog(QWidget* parent=0,const char* name=0,bool modal=TRUE,WFlags f=0);
20 ~DisplayDialog();
21private slots:
22 void big_clicked();
23 void small_clicked();
24 void warning_clicked();
25public:
26 void setDisplaySettings(const Display& display);
27 Display getDisplaySettings();
28};
29
30#endif //DISPLAYDLAOG_H
diff --git a/noncore/games/backgammon/moveengine.cpp b/noncore/games/backgammon/moveengine.cpp
index 8106b3f..009c449 100644
--- a/noncore/games/backgammon/moveengine.cpp
+++ b/noncore/games/backgammon/moveengine.cpp
@@ -1,392 +1,390 @@
1#include "moveengine.h" 1#include "moveengine.h"
2 2
3#include <qmessagebox.h> 3#include <qmessagebox.h>
4 4
5#include <qtimer.h> 5#include <qtimer.h>
6 6
7#include <stdlib.h>
8
9MoveEngine::MoveEngine() 7MoveEngine::MoveEngine()
10 : QObject() 8 : QObject()
11{ 9{
12 int offset=7; 10 int offset=7;
13 int a=0; //counter variable 11 int a=0; //counter variable
14 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}; 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};
15 for(a=0;a<26;a++) 13 for(a=0;a<26;a++)
16 { 14 {
17 x_coord[a]=xfill[a]; 15 x_coord[a]=xfill[a];
18 } 16 }
19 17
20 int yfill[]={10,25,40,55,70,10+offset,25+offset,40+offset,55+offset,25,40,55, 25+offset,40+offset,40}; 18 int yfill[]={10,25,40,55,70,10+offset,25+offset,40+offset,55+offset,25,40,55, 25+offset,40+offset,40};
21 int zfill[]={1,1,1,1,1,2,2,2,2,3,3,3,4,4,5}; 19 int zfill[]={1,1,1,1,1,2,2,2,2,3,3,3,4,4,5};
22 for(a=0;a<15;a++) 20 for(a=0;a<15;a++)
23 { 21 {
24 yup_coord[a]=yfill[a]; 22 yup_coord[a]=yfill[a];
25 ylow_coord[a]=185-(yfill[a]); 23 ylow_coord[a]=185-(yfill[a]);
26 z_coord[a]=zfill[a]; 24 z_coord[a]=zfill[a];
27 } 25 }
28 for(a=0;a<5;a++) 26 for(a=0;a<5;a++)
29 { 27 {
30 if(a<3) 28 if(a<3)
31 { 29 {
32 x_fin1[a]=65+a*15; 30 x_fin1[a]=65+a*15;
33 x_fin2[a]=155-a*15; 31 x_fin2[a]=155-a*15;
34 } 32 }
35 y_fin[a]=225-a*5; 33 y_fin[a]=225-a*5;
36 } 34 }
37 z_fin=1; 35 z_fin=1;
38 36
39 reset(); 37 reset();
40} 38}
41 39
42MoveEngine::~MoveEngine() 40MoveEngine::~MoveEngine()
43{} 41{}
44 42
45void MoveEngine::position(Pieces& pieces,bool non_qte) 43void MoveEngine::position(Pieces& pieces,bool non_qte)
46{ 44{
47 int player1_counter=0; 45 int player1_counter=0;
48 int player2_counter=0; 46 int player2_counter=0;
49 47
50 //non qte styles are smaller !! 48 //non qte styles are smaller !!
51 int offset=(non_qte) ? 5 : 0; 49 int offset=(non_qte) ? 5 : 0;
52 50
53 for(int a=0;a<28;a++) 51 for(int a=0;a<28;a++)
54 { 52 {
55 for(int b=0;b<abs(population[a].total);b++) 53 for(int b=0;b<abs(population[a].total);b++)
56 { 54 {
57 if(population[a].total>0) //player 1 pieces 55 if(population[a].total>0) //player 1 pieces
58 { 56 {
59 pieces.player1[player1_counter].x=x_coord[a]-offset; 57 pieces.player1[player1_counter].x=x_coord[a]-offset;
60 if(a>=0 && a<13) 58 if(a>=0 && a<13)
61 { 59 {
62 pieces.player1[player1_counter].y=yup_coord[b]-offset; 60 pieces.player1[player1_counter].y=yup_coord[b]-offset;
63 pieces.player1[player1_counter].z=z_coord[b]; 61 pieces.player1[player1_counter].z=z_coord[b];
64 pieces.player1[player1_counter].side=false; 62 pieces.player1[player1_counter].side=false;
65 player1_counter++; 63 player1_counter++;
66 } 64 }
67 else if(a>12 && a<26) 65 else if(a>12 && a<26)
68 { 66 {
69 pieces.player1[player1_counter].y=ylow_coord[b]-offset; 67 pieces.player1[player1_counter].y=ylow_coord[b]-offset;
70 pieces.player1[player1_counter].z=z_coord[b]; 68 pieces.player1[player1_counter].z=z_coord[b];
71 pieces.player1[player1_counter].side=false; 69 pieces.player1[player1_counter].side=false;
72 player1_counter++; 70 player1_counter++;
73 } 71 }
74 else if(a==26) 72 else if(a==26)
75 { 73 {
76 if(b<5) 74 if(b<5)
77 { 75 {
78 pieces.player1[player1_counter].x=x_fin1[0]-offset; 76 pieces.player1[player1_counter].x=x_fin1[0]-offset;
79 pieces.player1[player1_counter].y=y_fin[b]-offset; 77 pieces.player1[player1_counter].y=y_fin[b]-offset;
80 pieces.player1[player1_counter].z=z_fin; 78 pieces.player1[player1_counter].z=z_fin;
81 } 79 }
82 else if(b>=5 && b<10) 80 else if(b>=5 && b<10)
83 { 81 {
84 pieces.player1[player1_counter].x=x_fin1[1]-offset; 82 pieces.player1[player1_counter].x=x_fin1[1]-offset;
85 pieces.player1[player1_counter].y=y_fin[b-5]-offset; 83 pieces.player1[player1_counter].y=y_fin[b-5]-offset;
86 pieces.player1[player1_counter].z=z_fin; 84 pieces.player1[player1_counter].z=z_fin;
87 } 85 }
88 else 86 else
89 { 87 {
90 pieces.player1[player1_counter].x=x_fin1[2]-offset; 88 pieces.player1[player1_counter].x=x_fin1[2]-offset;
91 pieces.player1[player1_counter].y=y_fin[b-10]-offset; 89 pieces.player1[player1_counter].y=y_fin[b-10]-offset;
92 pieces.player1[player1_counter].z=z_fin; 90 pieces.player1[player1_counter].z=z_fin;
93 } 91 }
94 pieces.player1[player1_counter].side=true; 92 pieces.player1[player1_counter].side=true;
95 player1_counter++; 93 player1_counter++;
96 94
97 } 95 }
98 } 96 }
99 97
100 else if(population[a].total<0) //player 2 pieces 98 else if(population[a].total<0) //player 2 pieces
101 { 99 {
102 pieces.player2[player2_counter].x=x_coord[a]-offset; 100 pieces.player2[player2_counter].x=x_coord[a]-offset;
103 if(a>=0 && a<13) 101 if(a>=0 && a<13)
104 { 102 {
105 pieces.player2[player2_counter].y=yup_coord[b]-offset; 103 pieces.player2[player2_counter].y=yup_coord[b]-offset;
106 pieces.player2[player2_counter].z=z_coord[b]; 104 pieces.player2[player2_counter].z=z_coord[b];
107 pieces.player2[player2_counter].side=false; 105 pieces.player2[player2_counter].side=false;
108 player2_counter++; 106 player2_counter++;
109 } 107 }
110 else if(a>12 && a<26) 108 else if(a>12 && a<26)
111 { 109 {
112 pieces.player2[player2_counter].y=ylow_coord[b]-offset; 110 pieces.player2[player2_counter].y=ylow_coord[b]-offset;
113 pieces.player2[player2_counter].z=z_coord[b]; 111 pieces.player2[player2_counter].z=z_coord[b];
114 pieces.player2[player2_counter].side=false; 112 pieces.player2[player2_counter].side=false;
115 player2_counter++; 113 player2_counter++;
116 } 114 }
117 else if(a==27) 115 else if(a==27)
118 { 116 {
119 if(b<5) 117 if(b<5)
120 { 118 {
121 pieces.player2[player2_counter].x=x_fin2[0]-offset; 119 pieces.player2[player2_counter].x=x_fin2[0]-offset;
122 pieces.player2[player2_counter].y=y_fin[b]-offset; 120 pieces.player2[player2_counter].y=y_fin[b]-offset;
123 pieces.player2[player2_counter].z=z_fin; 121 pieces.player2[player2_counter].z=z_fin;
124 } 122 }
125 else if(b>=5 && b<10) 123 else if(b>=5 && b<10)
126 { 124 {
127 pieces.player2[player2_counter].x=x_fin2[1]-offset; 125 pieces.player2[player2_counter].x=x_fin2[1]-offset;
128 pieces.player2[player2_counter].y=y_fin[b-5]-offset; 126 pieces.player2[player2_counter].y=y_fin[b-5]-offset;
129 pieces.player2[player2_counter].z=z_fin; 127 pieces.player2[player2_counter].z=z_fin;
130 } 128 }
131 else 129 else
132 { 130 {
133 pieces.player2[player2_counter].x=x_fin2[2]-offset; 131 pieces.player2[player2_counter].x=x_fin2[2]-offset;
134 pieces.player2[player2_counter].y=y_fin[b-10]-offset; 132 pieces.player2[player2_counter].y=y_fin[b-10]-offset;
135 pieces.player2[player2_counter].z=z_fin; 133 pieces.player2[player2_counter].z=z_fin;
136 } 134 }
137 pieces.player2[player2_counter].side=true; 135 pieces.player2[player2_counter].side=true;
138 player2_counter++; 136 player2_counter++;
139 137
140 } 138 }
141 } 139 }
142 } 140 }
143 } 141 }
144} 142}
145 143
146void MoveEngine::diceroll(const int& newplayer,const int& face1,const int& face2,const int& face3,const int& face4,bool computer) 144void MoveEngine::diceroll(const int& newplayer,const int& face1,const int& face2,const int& face3,const int& face4,bool computer)
147{ 145{
148 checkstate(); 146 checkstate();
149 player=newplayer; 147 player=newplayer;
150 otherplayer=(player==1) ? 2 : 1; 148 otherplayer=(player==1) ? 2 : 1;
151 dice[0]=face1; 149 dice[0]=face1;
152 dice[1]=face2; 150 dice[1]=face2;
153 dice[2]=face3; 151 dice[2]=face3;
154 dice[3]=face4; 152 dice[3]=face4;
155 marker_current=-1; 153 marker_current=-1;
156 if(getPossibleMoves()==0) 154 if(getPossibleMoves()==0)
157 { 155 {
158 emit nomove(); 156 emit nomove();
159 return; // player will be changed 157 return; // player will be changed
160 } 158 }
161 if(!computer) 159 if(!computer)
162 return; //human intervention required 160 return; //human intervention required
163 161
164 QTimer::singleShot(2000,this,SLOT(automove())); 162 QTimer::singleShot(2000,this,SLOT(automove()));
165} 163}
166 164
167 165
168void MoveEngine::automove() 166void MoveEngine::automove()
169{ 167{
170 //the maximimum possibility 168 //the maximimum possibility
171 int maxpos=0; 169 int maxpos=0;
172 //the position in the moves array 170 //the position in the moves array
173 int from=-1; 171 int from=-1;
174 int to=-1; 172 int to=-1;
175 //dice1 or dice 2 ?? 173 //dice1 or dice 2 ??
176 int index_dice=0; 174 int index_dice=0;
177 for(int counter=0;counter<26;counter++) 175 for(int counter=0;counter<26;counter++)
178 { 176 {
179 int a=(player==1) ? counter : 25-counter; 177 int a=(player==1) ? counter : 25-counter;
180 for(int b=0;b<4;b++) 178 for(int b=0;b<4;b++)
181 { 179 {
182 if(moves[a].weight[b]>maxpos) 180 if(moves[a].weight[b]>maxpos)
183 { 181 {
184 maxpos=moves[a].weight[b]; 182 maxpos=moves[a].weight[b];
185 from=a; 183 from=a;
186 to=moves[a].to[b]; 184 to=moves[a].to[b];
187 index_dice=b+1; 185 index_dice=b+1;
188 } 186 }
189 } 187 }
190 } 188 }
191 move(from,to,index_dice); 189 move(from,to,index_dice);
192} 190}
193 191
194 192
195void MoveEngine::boardpressed(const int& x,const int& y,Marker& marker,bool non_qte) 193void MoveEngine::boardpressed(const int& x,const int& y,Marker& marker,bool non_qte)
196{ 194{
197 //get the position of the mouse click 195 //get the position of the mouse click
198 bool upper=true; 196 bool upper=true;
199 bool found=false; 197 bool found=false;
200 198
201 int offset=(non_qte) ? 5 : 0; 199 int offset=(non_qte) ? 5 : 0;
202 200
203 if(y<=85) // board slots 0 to 12 201 if(y<=85) // board slots 0 to 12
204 marker.y_current=0; 202 marker.y_current=0;
205 else if(y>=105) //board slots 13 to 25 203 else if(y>=105) //board slots 13 to 25
206 { 204 {
207 marker.y_current=195-2*offset; 205 marker.y_current=195-2*offset;
208 upper=false; 206 upper=false;
209 } 207 }
210 208
211 int index=13; // the clicked board slot 209 int index=13; // the clicked board slot
212 210
213 while(index<25 && !found) 211 while(index<25 && !found)
214 { 212 {
215 if(x>=x_coord[index] && x<x_coord[index+1]) 213 if(x>=x_coord[index] && x<x_coord[index+1])
216 { 214 {
217 marker.x_current=x_coord[index]; 215 marker.x_current=x_coord[index];
218 found=true; 216 found=true;
219 ; 217 ;
220 } 218 }
221 else 219 else
222 { 220 {
223 index++; 221 index++;
224 } 222 }
225 } 223 }
226 if(!found) 224 if(!found)
227 { 225 {
228 marker.x_current=x_coord[25]; 226 marker.x_current=x_coord[25];
229 index=25; 227 index=25;
230 } 228 }
231 if(upper) 229 if(upper)
232 { 230 {
233 index=25-index; 231 index=25-index;
234 } 232 }
235 233
236 int a=0; 234 int a=0;
237 int usedice=-1; 235 int usedice=-1;
238 int dice_value=7; 236 int dice_value=7;
239 for(a=0;a<4;a++) 237 for(a=0;a<4;a++)
240 { 238 {
241 if(index==marker_next[a] && marker_next[a]!=-1 && dice_value>dice[a]) 239 if(index==marker_next[a] && marker_next[a]!=-1 && dice_value>dice[a])
242 { 240 {
243 usedice=a; 241 usedice=a;
244 dice_value=dice[0]; 242 dice_value=dice[0];
245 } 243 }
246 } 244 }
247 if(usedice!=-1) 245 if(usedice!=-1)
248 { 246 {
249 move(marker_current,marker_next[usedice],usedice+1); 247 move(marker_current,marker_next[usedice],usedice+1);
250 nomarker(marker); 248 nomarker(marker);
251 return; 249 return;
252 250
253 } 251 }
254 252
255 253
256 if(dice[0]==7 && dice[1]==7 && dice[2]==7 && dice[3]==7) //no dice rolled 254 if(dice[0]==7 && dice[1]==7 && dice[2]==7 && dice[3]==7) //no dice rolled
257 { 255 {
258 nomarker(marker); 256 nomarker(marker);
259 return; 257 return;
260 } 258 }
261 else if(fieldColor(index)==player) 259 else if(fieldColor(index)==player)
262 { 260 {
263 marker.visible_current=true; 261 marker.visible_current=true;
264 marker_current=index; 262 marker_current=index;
265 } 263 }
266 else 264 else
267 { 265 {
268 nomarker(marker); 266 nomarker(marker);
269 return; 267 return;
270 } 268 }
271 269
272 for(a=0;a<4;a++) 270 for(a=0;a<4;a++)
273 { 271 {
274 if(moves[index].weight[a]>0) 272 if(moves[index].weight[a]>0)
275 { 273 {
276 int nextfield=moves[index].to[a]; 274 int nextfield=moves[index].to[a];
277 marker.x_next[a]=x_coord[nextfield]; 275 marker.x_next[a]=x_coord[nextfield];
278 marker_next[a]=nextfield; 276 marker_next[a]=nextfield;
279 if(nextfield<13) //upper half 277 if(nextfield<13) //upper half
280 marker.y_next[a]=0; 278 marker.y_next[a]=0;
281 else //lower half 279 else //lower half
282 marker.y_next[a]=195-2*offset; 280 marker.y_next[a]=195-2*offset;
283 marker.visible_next[a]=true; 281 marker.visible_next[a]=true;
284 } 282 }
285 else 283 else
286 { 284 {
287 marker.x_next[a]=0; 285 marker.x_next[a]=0;
288 marker.y_next[a]=0; 286 marker.y_next[a]=0;
289 marker_next[a]=-1; 287 marker_next[a]=-1;
290 marker.visible_next[a]=false; 288 marker.visible_next[a]=false;
291 } 289 }
292 } 290 }
293 return; 291 return;
294} 292}
295 293
296void MoveEngine::reset() 294void MoveEngine::reset()
297{ 295{
298 int a=0; 296 int a=0;
299 for(a=0;a<28;a++) 297 for(a=0;a<28;a++)
300 { 298 {
301 population[a].total=0; 299 population[a].total=0;
302 } 300 }
303 301
304 int p1_index[]={1,1,12,12,12,12,12,17,17,17,19,19,19,19,19}; 302 int p1_index[]={1,1,12,12,12,12,12,17,17,17,19,19,19,19,19};
305 int p2_index[]={24,24,13,13,13,13,13,8,8,8,6,6,6,6,6}; 303 int p2_index[]={24,24,13,13,13,13,13,8,8,8,6,6,6,6,6};
306 //int p1_index[]={19,20,21,22,22,23,23,18,18,23,24,24,24,24,24}; 304 //int p1_index[]={19,20,21,22,22,23,23,18,18,23,24,24,24,24,24};
307 //int p2_index[]={6,5,4,3,3,2,2,2,2,2,1,7,7,1,1}; 305 //int p2_index[]={6,5,4,3,3,2,2,2,2,2,1,7,7,1,1};
308 for(a=0;a<15;a++) 306 for(a=0;a<15;a++)
309 { 307 {
310 population[p1_index[a]].total++; 308 population[p1_index[a]].total++;
311 population[p2_index[a]].total--; 309 population[p2_index[a]].total--;
312 } 310 }
313 311
314 player=0; 312 player=0;
315 dice[0]=7; 313 dice[0]=7;
316 dice[1]=7; 314 dice[1]=7;
317 dice[2]=7; 315 dice[2]=7;
318 dice[3]=7; 316 dice[3]=7;
319 317
320 marker_current=-1; 318 marker_current=-1;
321 marker_next[0]=-1; 319 marker_next[0]=-1;
322 marker_next[1]=-1; 320 marker_next[1]=-1;
323 marker_next[2]=-1; 321 marker_next[2]=-1;
324 marker_next[3]=-1; 322 marker_next[3]=-1;
325 //allclear[0]==false; 323 //allclear[0]==false;
326 allclear[1]=false; 324 allclear[1]=false;
327 allclear[2]=false; 325 allclear[2]=false;
328 last_piece[1]=0; 326 last_piece[1]=0;
329 last_piece[2]=25; 327 last_piece[2]=25;
330} 328}
331 329
332void MoveEngine::loadGame(const LoadSave& load) 330void MoveEngine::loadGame(const LoadSave& load)
333{ 331{
334 for(int a=0;a<28;a++) 332 for(int a=0;a<28;a++)
335 { 333 {
336 population[a].total=load.pop[a].total; 334 population[a].total=load.pop[a].total;
337 } 335 }
338 checkstate(); 336 checkstate();
339} 337}
340 338
341LoadSave MoveEngine::saveGame() 339LoadSave MoveEngine::saveGame()
342{ 340{
343 LoadSave save; 341 LoadSave save;
344 for(int a=0;a<28;a++) 342 for(int a=0;a<28;a++)
345 { 343 {
346 save.pop[a].total=population[a].total; 344 save.pop[a].total=population[a].total;
347 } 345 }
348 return save; 346 return save;
349} 347}
350 348
351AISettings MoveEngine::getAISettings() 349AISettings MoveEngine::getAISettings()
352{ 350{
353 return ai; 351 return ai;
354} 352}
355 353
356void MoveEngine::setAISettings(const AISettings& new_ai) 354void MoveEngine::setAISettings(const AISettings& new_ai)
357{ 355{
358 ai=new_ai; 356 ai=new_ai;
359} 357}
360 358
361void MoveEngine::setRules(Rules rules) 359void MoveEngine::setRules(Rules rules)
362{ 360{
363 move_with_pieces_out=rules.move_with_pieces_out; 361 move_with_pieces_out=rules.move_with_pieces_out;
364 nice_dice=rules.generous_dice; 362 nice_dice=rules.generous_dice;
365} 363}
366 364
367 365
368int MoveEngine::getPossibleMoves() 366int MoveEngine::getPossibleMoves()
369{ 367{
370 int homezone[]={0,25,0}; 368 int homezone[]={0,25,0};
371 int lastToHomeZone=abs(last_piece[player]-homezone[player]); 369 int lastToHomeZone=abs(last_piece[player]-homezone[player]);
372 for(int field=0;field<26;field++) 370 for(int field=0;field<26;field++)
373 { 371 {
374 372
375 for(int b=0;b<4;b++) 373 for(int b=0;b<4;b++)
376 { 374 {
377 int dice_tmp=dice[b]; 375 int dice_tmp=dice[b];
378 if(dice[b]!=7 && dice[b]> lastToHomeZone) 376 if(dice[b]!=7 && dice[b]> lastToHomeZone)
379 dice_tmp=lastToHomeZone; 377 dice_tmp=lastToHomeZone;
380 378
381 int nextfield=(player==1) ? field+dice_tmp : field-dice_tmp; 379 int nextfield=(player==1) ? field+dice_tmp : field-dice_tmp;
382 380
383 if(nice_dice) 381 if(nice_dice)
384 { 382 {
385 if(player==1 && nextfield>homezone[1]) 383 if(player==1 && nextfield>homezone[1])
386 nextfield=homezone[1]; 384 nextfield=homezone[1];
387 else if(player==2 && nextfield<homezone[2]) 385 else if(player==2 && nextfield<homezone[2])
388 nextfield=homezone[2]; 386 nextfield=homezone[2];
389 } 387 }
390 388
391 moves[field].weight[b]=0; 389 moves[field].weight[b]=0;
392 moves[field].to[b]=nextfield; 390 moves[field].to[b]=nextfield;
diff --git a/noncore/games/backgammon/moveengine.h b/noncore/games/backgammon/moveengine.h
index a2d4a52..4c39a04 100644
--- a/noncore/games/backgammon/moveengine.h
+++ b/noncore/games/backgammon/moveengine.h
@@ -1,76 +1,76 @@
1#ifndef MOVEENGINE_H 1#ifndef MOVEENGINE_H
2#define MOVEENGINE_H 2#define MOVEENGINE_H
3 3
4#include <qobject.h>
5#include "definition.h" 4#include "definition.h"
5#include <qobject.h>
6 6
7class MoveEngine : public QObject 7class MoveEngine : public QObject
8{ 8{
9 Q_OBJECT 9 Q_OBJECT
10private: 10private:
11 //normal pieses 11 //normal pieses
12 int x_coord[26]; //26 posssible x-positions or piece is not on the board 12 int x_coord[26]; //26 posssible x-positions or piece is not on the board
13 int yup_coord[15]; // the 15 posssible y-positions on the upper half of the board 13 int yup_coord[15]; // the 15 posssible y-positions on the upper half of the board
14 int ylow_coord[15]; // the 15 posssible y-positions on the lower half of the board 14 int ylow_coord[15]; // the 15 posssible y-positions on the lower half of the board
15 int z_coord[15]; //the 15 possible z-positionson the board 15 int z_coord[15]; //the 15 possible z-positionson the board
16 //finshed pieces 16 //finshed pieces
17 int x_fin1[3]; 17 int x_fin1[3];
18 int x_fin2[3]; 18 int x_fin2[3];
19 int y_fin[5]; 19 int y_fin[5];
20 int z_fin; 20 int z_fin;
21 //the board population 21 //the board population
22 // |12|11|10|09|08|07|06|05|04|03|02|01|00| 22 // |12|11|10|09|08|07|06|05|04|03|02|01|00|
23 // ======================================= 23 // =======================================
24 // |13|14|15|16|17|18|19|20|21|22|23|24|25| 24 // |13|14|15|16|17|18|19|20|21|22|23|24|25|
25 // endzones 26 player1, 27 player 2 25 // endzones 26 player1, 27 player 2
26 Population population[28]; 26 Population population[28];
27 AISettings ai; 27 AISettings ai;
28 //move information 28 //move information
29 int player; 29 int player;
30 int otherplayer; 30 int otherplayer;
31 int dice[4]; 31 int dice[4];
32 //index of the markers 32 //index of the markers
33 int marker_current; 33 int marker_current;
34 int marker_next[4]; 34 int marker_next[4];
35 //player pieces are all in the end zone 35 //player pieces are all in the end zone
36 bool allclear[3]; 36 bool allclear[3];
37 //player must bring pieces back into game 37 //player must bring pieces back into game
38 bool pieces_out[3]; 38 bool pieces_out[3];
39 bool move_with_pieces_out; 39 bool move_with_pieces_out;
40 //player can rescue pieces with dice bigger than move, even if there are poeces "behind" it 40 //player can rescue pieces with dice bigger than move, even if there are poeces "behind" it
41 bool nice_dice; 41 bool nice_dice;
42 int last_piece[3]; 42 int last_piece[3];
43 //possible moves 43 //possible moves
44 Possiblilites moves[26]; 44 Possiblilites moves[26];
45public: 45public:
46public: 46public:
47 MoveEngine(); 47 MoveEngine();
48 ~MoveEngine(); 48 ~MoveEngine();
49signals: 49signals:
50 void done_dice1(); 50 void done_dice1();
51 void done_dice2(); 51 void done_dice2();
52 void done_dice3(); 52 void done_dice3();
53 void done_dice4(); 53 void done_dice4();
54 void nomove(); 54 void nomove();
55 void player_finished(int); 55 void player_finished(int);
56private slots: 56private slots:
57 void automove(); 57 void automove();
58public: 58public:
59 void position(Pieces& pieces,bool non_qte=false); 59 void position(Pieces& pieces,bool non_qte=false);
60 void diceroll(const int& player,const int& face1,const int& face2,const int& face3,const int& face4,bool computer); 60 void diceroll(const int& player,const int& face1,const int& face2,const int& face3,const int& face4,bool computer);
61 void boardpressed(const int& x,const int& y,Marker& marker,bool non_qte=false); 61 void boardpressed(const int& x,const int& y,Marker& marker,bool non_qte=false);
62 void reset(); 62 void reset();
63 void loadGame(const LoadSave& load); 63 void loadGame(const LoadSave& load);
64 LoadSave saveGame(); 64 LoadSave saveGame();
65 AISettings getAISettings(); 65 AISettings getAISettings();
66 void setAISettings(const AISettings& new_ai); 66 void setAISettings(const AISettings& new_ai);
67 void setRules(Rules rules); 67 void setRules(Rules rules);
68private: 68private:
69 int getPossibleMoves(); 69 int getPossibleMoves();
70 void move(const int& from, int to, const int& dice); 70 void move(const int& from, int to, const int& dice);
71 void checkstate(); 71 void checkstate();
72 void nomarker(Marker& marker); 72 void nomarker(Marker& marker);
73 int fieldColor(const int& index) const; 73 int fieldColor(const int& index) const;
74}; 74};
75 75
76#endif //MOVEENGINE_H 76#endif //MOVEENGINE_H
diff --git a/noncore/games/backgammon/rulesdialog.h b/noncore/games/backgammon/rulesdialog.h
index 9269a0e..f11a28c 100644
--- a/noncore/games/backgammon/rulesdialog.h
+++ b/noncore/games/backgammon/rulesdialog.h
@@ -1,27 +1,26 @@
1#ifndef RULESDIALOG_H_ 1#ifndef RULESDIALOG_H_
2#define RULESDIALOG_H_ 2#define RULESDIALOG_H_
3 3
4#include <qcheckbox.h> 4#include <qcheckbox.h>
5#include <qdialog.h> 5#include <qdialog.h>
6#include "definition.h" 6#include "definition.h"
7 7
8
9class RulesDialog : public QDialog 8class RulesDialog : public QDialog
10{ 9{
11 Q_OBJECT 10 Q_OBJECT
12private: 11private:
13 QCheckBox* pieces_out; 12 QCheckBox* pieces_out;
14 QCheckBox* nice_dice; 13 QCheckBox* nice_dice;
15 Rules rules; 14 Rules rules;
16public: 15public:
17 RulesDialog(QWidget* parent=0,const char* name=0,bool modal=TRUE,WFlags f=0); 16 RulesDialog(QWidget* parent=0,const char* name=0,bool modal=TRUE,WFlags f=0);
18 ~RulesDialog(); 17 ~RulesDialog();
19private slots: 18private slots:
20 void pieces_out_clicked(); 19 void pieces_out_clicked();
21 void nice_dice_clicked(); 20 void nice_dice_clicked();
22public: 21public:
23 void setRules(const Rules& new_rules); 22 void setRules(const Rules& new_rules);
24 Rules getRules(); 23 Rules getRules();
25}; 24};
26 25
27#endif //RULESDIALOG_H 26#endif //RULESDIALOG_H