-rw-r--r-- | noncore/games/backgammon/backgammon.cpp | 2 | ||||
-rw-r--r-- | noncore/games/backgammon/backgammon.h | 1 |
2 files changed, 2 insertions, 1 deletions
diff --git a/noncore/games/backgammon/backgammon.cpp b/noncore/games/backgammon/backgammon.cpp index 06523f1..db1a058 100644 --- a/noncore/games/backgammon/backgammon.cpp +++ b/noncore/games/backgammon/backgammon.cpp | |||
@@ -1,393 +1,395 @@ | |||
1 | #include "backgammon.h" | 1 | #include "backgammon.h" |
2 | 2 | ||
3 | #include "aidialog.h" | 3 | #include "aidialog.h" |
4 | #include "filedialog.h" | 4 | #include "filedialog.h" |
5 | #include "playerdialog.h" | 5 | #include "playerdialog.h" |
6 | #include "rulesdialog.h" | 6 | #include "rulesdialog.h" |
7 | #include "themedialog.h" | 7 | #include "themedialog.h" |
8 | 8 | ||
9 | #include <qdatetime.h> | 9 | #include <qdatetime.h> |
10 | #include <qfile.h> | 10 | #include <qfile.h> |
11 | #include <qlayout.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 <qmainwindow.h> |
16 | #include <qpe/qpeapplication.h> | 16 | #include <qpe/qpeapplication.h> |
17 | #include <qpe/config.h> | 17 | #include <qpe/config.h> |
18 | #include <qpe/qpemenubar.h> | 18 | #include <qpe/qpemenubar.h> |
19 | #include <qpe/resource.h> | 19 | #include <qpe/resource.h> |
20 | 20 | ||
21 | #include <stdlib.h> | 21 | #include <stdlib.h> |
22 | 22 | ||
23 | 23 | ||
24 | BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl) | 24 | BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl) |
25 | : QMainWindow(parent, name, fl) | 25 | : QMainWindow(parent, name, fl) |
26 | { | 26 | { |
27 | if (!name) setName("BackGammon"); | 27 | if (!name) setName("BackGammon"); |
28 | setCaption(tr( "Backgammon") ); | 28 | setCaption(tr( "Backgammon") ); |
29 | setIcon( Resource::loadPixmap( "backgammon" ) ); | 29 | setIcon( Resource::loadPixmap( "backgammon" ) ); |
30 | //general counter varaible | 30 | //general counter varaible |
31 | int a=0; | 31 | int a=0; |
32 | //the game engine | 32 | //the game engine |
33 | move=new MoveEngine(); | 33 | move=new MoveEngine(); |
34 | 34 | ||
35 | //load the default theme | 35 | //load the default theme |
36 | Config conf("backgammon"); | 36 | Config conf("backgammon"); |
37 | if(!conf.isValid()) | 37 | if(!conf.isValid()) |
38 | { | 38 | { |
39 | qDebug("config file does not exist"); | 39 | qDebug("config file does not exist"); |
40 | conf.setGroup("general"); | 40 | conf.setGroup("general"); |
41 | conf.writeEntry("theme","default"); | 41 | conf.writeEntry("theme","default"); |
42 | conf.setGroup("rules"); | 42 | conf.setGroup("rules"); |
43 | conf.writeEntry("move_with_pieces_out",false); | 43 | conf.writeEntry("move_with_pieces_out",false); |
44 | conf.writeEntry("nice_dice",false); | 44 | conf.writeEntry("nice_dice",false); |
45 | conf.setGroup("display"); | 45 | conf.setGroup("display"); |
46 | conf.writeEntry("small",false); | 46 | conf.writeEntry("small",false); |
47 | conf.writeEntry("warning",true); | 47 | conf.writeEntry("warning",true); |
48 | conf.setGroup("ai"); | 48 | conf.setGroup("ai"); |
49 | conf.writeEntry("rescue",6); | 49 | conf.writeEntry("rescue",6); |
50 | conf.writeEntry("eliminate",4); | 50 | conf.writeEntry("eliminate",4); |
51 | conf.writeEntry("expose",1); | 51 | conf.writeEntry("expose",1); |
52 | conf.writeEntry("protect",5); | 52 | conf.writeEntry("protect",5); |
53 | conf.writeEntry("safe",3); | 53 | conf.writeEntry("safe",3); |
54 | conf.writeEntry("empty",2); | 54 | conf.writeEntry("empty",2); |
55 | 55 | ||
56 | } | 56 | } |
57 | conf.setGroup("general"); | 57 | conf.setGroup("general"); |
58 | theme_name=conf.readEntry("theme","default"); | 58 | theme_name=conf.readEntry("theme","default"); |
59 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; | 59 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; |
60 | 60 | ||
61 | //the rules | 61 | //the rules |
62 | conf.setGroup("rules"); | 62 | conf.setGroup("rules"); |
63 | 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); |
64 | rules.generous_dice=conf.readBoolEntry("nice_dice",false); | 64 | rules.generous_dice=conf.readBoolEntry("nice_dice",false); |
65 | 65 | ||
66 | move->setRules(rules); | 66 | move->setRules(rules); |
67 | 67 | ||
68 | //get the AI settings | 68 | //get the AI settings |
69 | AISettings ai; | 69 | AISettings ai; |
70 | conf.setGroup("ai"); | 70 | conf.setGroup("ai"); |
71 | ai.rescue=conf.readNumEntry("rescue",6); | 71 | ai.rescue=conf.readNumEntry("rescue",6); |
72 | ai.eliminate=conf.readNumEntry("eliminate",4); | 72 | ai.eliminate=conf.readNumEntry("eliminate",4); |
73 | ai.expose=conf.readNumEntry("expose",1); | 73 | ai.expose=conf.readNumEntry("expose",1); |
74 | ai.protect=conf.readNumEntry("protect",5); | 74 | ai.protect=conf.readNumEntry("protect",5); |
75 | ai.safe=conf.readNumEntry("safe",3); | 75 | ai.safe=conf.readNumEntry("safe",3); |
76 | ai.empty=conf.readNumEntry("empty",2); | 76 | ai.empty=conf.readNumEntry("empty",2); |
77 | move->setAISettings(ai); | 77 | move->setAISettings(ai); |
78 | 78 | ||
79 | 79 | ||
80 | //get the theme component names | 80 | //get the theme component names |
81 | Config theme(theme_file,Config::File); | 81 | Config theme(theme_file,Config::File); |
82 | if(!theme.isValid()) | 82 | if(!theme.isValid()) |
83 | { | 83 | { |
84 | qDebug("theme file does not exist"); | 84 | qDebug("theme file does not exist"); |
85 | theme.setGroup("theme"); | 85 | theme.setGroup("theme"); |
86 | theme.writeEntry("board","casino_board_1"); | 86 | theme.writeEntry("board","casino_board_1"); |
87 | theme.writeEntry("pieces1","casino_pieces_blue"); | 87 | theme.writeEntry("pieces1","casino_pieces_blue"); |
88 | theme.writeEntry("pieces2","casino_pieces_white"); | 88 | theme.writeEntry("pieces2","casino_pieces_white"); |
89 | theme.writeEntry("dice1","casino_dice"); | 89 | theme.writeEntry("dice1","casino_dice"); |
90 | theme.writeEntry("dice2","casino_dice"); | 90 | theme.writeEntry("dice2","casino_dice"); |
91 | theme.writeEntry("table","casino_table_green"); | 91 | theme.writeEntry("table","casino_table_green"); |
92 | theme.writeEntry("odds","casino_odds"); | 92 | theme.writeEntry("odds","casino_odds"); |
93 | } | 93 | } |
94 | theme.setGroup("theme"); | 94 | theme.setGroup("theme"); |
95 | board_name=theme.readEntry("board","casino_board_1"); | 95 | board_name=theme.readEntry("board","casino_board_1"); |
96 | piecesA_name=theme.readEntry("pieces1","casino_pieces_blue"); | 96 | piecesA_name=theme.readEntry("pieces1","casino_pieces_blue"); |
97 | piecesB_name=theme.readEntry("pieces2","casino_pieces_white"); | 97 | piecesB_name=theme.readEntry("pieces2","casino_pieces_white"); |
98 | diceA_name=theme.readEntry("dice1","casino_dice"); | 98 | diceA_name=theme.readEntry("dice1","casino_dice"); |
99 | diceB_name=theme.readEntry("dice2","casino_dice"); | 99 | diceB_name=theme.readEntry("dice2","casino_dice"); |
100 | table_name=theme.readEntry("table","casino_table_green"); | 100 | table_name=theme.readEntry("table","casino_table_green"); |
101 | odds_name=theme.readEntry("odds","casino_odds"); | 101 | odds_name=theme.readEntry("odds","casino_odds"); |
102 | 102 | ||
103 | 103 | ||
104 | //the menu | 104 | //the menu |
105 | QPEMenuBar* menuBar = new QPEMenuBar(this); | 105 | QPEMenuBar* menuBar = new QPEMenuBar(this); |
106 | 106 | ||
107 | QPopupMenu* gamemenu= new QPopupMenu(this); | 107 | QPopupMenu* gamemenu= new QPopupMenu(this); |
108 | gamemenu->insertItem(tr( "New" ),this,SLOT(newgame())); | 108 | gamemenu->insertItem(tr( "New" ),this,SLOT(newgame())); |
109 | gamemenu->insertSeparator(); | 109 | gamemenu->insertSeparator(); |
110 | gamemenu->insertItem(tr( "Load" ),this,SLOT(loadgame())); | 110 | gamemenu->insertItem(tr( "Load" ),this,SLOT(loadgame())); |
111 | gamemenu->insertItem(tr( "Save" ),this,SLOT(savegame())); | 111 | gamemenu->insertItem(tr( "Save" ),this,SLOT(savegame())); |
112 | gamemenu->insertSeparator(); | 112 | gamemenu->insertSeparator(); |
113 | gamemenu->insertItem(tr( "Delete" ),this,SLOT(deletegame())); | 113 | gamemenu->insertItem(tr( "Delete" ),this,SLOT(deletegame())); |
114 | menuBar->insertItem(tr( "Game" ),gamemenu); | 114 | menuBar->insertItem(tr( "Game" ),gamemenu); |
115 | 115 | ||
116 | QPopupMenu* thememenu= new QPopupMenu(this); | 116 | QPopupMenu* thememenu= new QPopupMenu(this); |
117 | thememenu->insertItem(tr( "New" ),this,SLOT(newtheme())); | 117 | thememenu->insertItem(tr( "New" ),this,SLOT(newtheme())); |
118 | thememenu->insertSeparator(); | 118 | thememenu->insertSeparator(); |
119 | thememenu->insertItem(tr( "Load"),this,SLOT(loadtheme())); | 119 | thememenu->insertItem(tr( "Load"),this,SLOT(loadtheme())); |
120 | thememenu->insertItem(tr( "Save" ),this,SLOT(savetheme())); | 120 | thememenu->insertItem(tr( "Save" ),this,SLOT(savetheme())); |
121 | thememenu->insertSeparator(); | 121 | thememenu->insertSeparator(); |
122 | thememenu->insertItem(tr( "Default"),this,SLOT(themedefault())); | 122 | thememenu->insertItem(tr( "Default"),this,SLOT(themedefault())); |
123 | thememenu->insertItem(tr( "Delete" ),this,SLOT(deletetheme())); | 123 | thememenu->insertItem(tr( "Delete" ),this,SLOT(deletetheme())); |
124 | menuBar->insertItem(tr( "Theme" ),thememenu); | 124 | menuBar->insertItem(tr( "Theme" ),thememenu); |
125 | 125 | ||
126 | QPopupMenu* optionmenu=new QPopupMenu(this); | 126 | QPopupMenu* optionmenu=new QPopupMenu(this); |
127 | optionmenu->insertItem(tr( "Player" ),this,SLOT(playerselect())); | 127 | optionmenu->insertItem(tr( "Player" ),this,SLOT(playerselect())); |
128 | optionmenu->insertSeparator(); | 128 | optionmenu->insertSeparator(); |
129 | optionmenu->insertItem(tr( "AI" ),this,SLOT(modify_AI())); | 129 | optionmenu->insertItem(tr( "AI" ),this,SLOT(modify_AI())); |
130 | optionmenu->insertItem(tr( "Rules" ),this,SLOT(setrules())); | 130 | optionmenu->insertItem(tr( "Rules" ),this,SLOT(setrules())); |
131 | menuBar->insertItem(tr( "Options"),optionmenu); | 131 | menuBar->insertItem(tr( "Options"),optionmenu); |
132 | 132 | ||
133 | QWidget* mainarea=new QWidget(this); | 133 | QWidget* mainarea=new QWidget(this); |
134 | setCentralWidget(mainarea); | 134 | setCentralWidget(mainarea); |
135 | //the main area | 135 | //the main area |
136 | QBoxLayout* layout=new QBoxLayout(mainarea,QBoxLayout::TopToBottom); | 136 | QBoxLayout* layout=new QBoxLayout(mainarea,QBoxLayout::TopToBottom); |
137 | area=new QCanvas(235,235); | 137 | area=new QCanvas(235,235); |
138 | QColor bgColor=palette().color(QPalette::Normal,QColorGroup::Background); | ||
139 | area->setBackgroundColor(bgColor); | ||
138 | boardview=new BackGammonView(area,mainarea); | 140 | boardview=new BackGammonView(area,mainarea); |
139 | boardview->setMaximumHeight(240); | 141 | boardview->setMaximumHeight(240); |
140 | layout->addWidget(boardview); | 142 | layout->addWidget(boardview); |
141 | connect(boardview,SIGNAL(mouse(int,int)),this,SLOT(mouse(int,int))); | 143 | connect(boardview,SIGNAL(mouse(int,int)),this,SLOT(mouse(int,int))); |
142 | //status bar | 144 | //status bar |
143 | message=new QLabel("<b>Backgammon</b>",mainarea); | 145 | message=new QLabel("<b>Backgammon</b>",mainarea); |
144 | message->setAlignment(AlignHCenter); | 146 | message->setAlignment(AlignHCenter); |
145 | layout->addWidget(message); | 147 | layout->addWidget(message); |
146 | 148 | ||
147 | //the marker | 149 | //the marker |
148 | marker_current=new QCanvasRectangle(area); | 150 | marker_current=new QCanvasRectangle(area); |
149 | marker_current->setBrush(QColor(0,0,255)); | 151 | marker_current->setBrush(QColor(0,0,255)); |
150 | marker_current->setSize(15,5); | 152 | marker_current->setSize(15,5); |
151 | marker_current->setZ(1); | 153 | marker_current->setZ(1); |
152 | 154 | ||
153 | for(a=0;a<4;a++) | 155 | for(a=0;a<4;a++) |
154 | { | 156 | { |
155 | marker_next[a]=new QCanvasRectangle(area); | 157 | marker_next[a]=new QCanvasRectangle(area); |
156 | marker_next[a]->setBrush(QColor(0,255,0)); | 158 | marker_next[a]->setBrush(QColor(0,255,0)); |
157 | marker_next[a]->setSize(15,5); | 159 | marker_next[a]->setSize(15,5); |
158 | marker_next[a]->setZ(1); | 160 | marker_next[a]->setZ(1); |
159 | } | 161 | } |
160 | 162 | ||
161 | connect(move,SIGNAL(done_dice1()),this,SLOT(done_dice1())); | 163 | connect(move,SIGNAL(done_dice1()),this,SLOT(done_dice1())); |
162 | connect(move,SIGNAL(done_dice2()),this,SLOT(done_dice2())); | 164 | connect(move,SIGNAL(done_dice2()),this,SLOT(done_dice2())); |
163 | connect(move,SIGNAL(done_dice3()),this,SLOT(done_dice3())); | 165 | connect(move,SIGNAL(done_dice3()),this,SLOT(done_dice3())); |
164 | connect(move,SIGNAL(done_dice4()),this,SLOT(done_dice4())); | 166 | connect(move,SIGNAL(done_dice4()),this,SLOT(done_dice4())); |
165 | connect(move,SIGNAL(nomove()),this,SLOT(nomove())); | 167 | connect(move,SIGNAL(nomove()),this,SLOT(nomove())); |
166 | connect(move,SIGNAL(player_finished(int)),this,SLOT(finished(int))); | 168 | connect(move,SIGNAL(player_finished(int)),this,SLOT(finished(int))); |
167 | 169 | ||
168 | //the pieces | 170 | //the pieces |
169 | p1=new CanvasImageItem*[15]; | 171 | p1=new CanvasImageItem*[15]; |
170 | p1_side=new CanvasImageItem*[15]; | 172 | p1_side=new CanvasImageItem*[15]; |
171 | QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name)); | 173 | QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name)); |
172 | QImage piece_1_front=piece_1_all.copy(0,0,15,15); | 174 | QImage piece_1_front=piece_1_all.copy(0,0,15,15); |
173 | QImage piece_1_side=piece_1_all.copy(0,15,15,5); | 175 | QImage piece_1_side=piece_1_all.copy(0,15,15,5); |
174 | 176 | ||
175 | p2=new CanvasImageItem*[15]; | 177 | p2=new CanvasImageItem*[15]; |
176 | p2_side=new CanvasImageItem*[15]; | 178 | p2_side=new CanvasImageItem*[15]; |
177 | QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name)); | 179 | QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name)); |
178 | QImage piece_2_front=piece_2_all.copy(0,0,15,15); | 180 | QImage piece_2_front=piece_2_all.copy(0,0,15,15); |
179 | QImage piece_2_side=piece_2_all.copy(0,15,15,5); | 181 | QImage piece_2_side=piece_2_all.copy(0,15,15,5); |
180 | 182 | ||
181 | 183 | ||
182 | for(a=0;a<15;a++) | 184 | for(a=0;a<15;a++) |
183 | { | 185 | { |
184 | p1[a]=new CanvasImageItem(piece_1_front,area); | 186 | p1[a]=new CanvasImageItem(piece_1_front,area); |
185 | p1[a]->setSize(15,15); | 187 | p1[a]->setSize(15,15); |
186 | p1_side[a]=new CanvasImageItem(piece_1_side,area); | 188 | p1_side[a]=new CanvasImageItem(piece_1_side,area); |
187 | p1_side[a]->setSize(15,5); | 189 | p1_side[a]->setSize(15,5); |
188 | 190 | ||
189 | p2[a]=new CanvasImageItem(piece_2_front,area); | 191 | p2[a]=new CanvasImageItem(piece_2_front,area); |
190 | p2[a]->setSize(15,15); | 192 | p2[a]->setSize(15,15); |
191 | p2_side[a]=new CanvasImageItem(piece_2_side,area); | 193 | p2_side[a]=new CanvasImageItem(piece_2_side,area); |
192 | p2_side[a]->setSize(15,5); | 194 | p2_side[a]->setSize(15,5); |
193 | } | 195 | } |
194 | draw(); | 196 | draw(); |
195 | 197 | ||
196 | //the dice | 198 | //the dice |
197 | QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name)); | 199 | QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name)); |
198 | diceA1=new CanvasImageItem*[7]; | 200 | diceA1=new CanvasImageItem*[7]; |
199 | diceA2=new CanvasImageItem*[7]; | 201 | diceA2=new CanvasImageItem*[7]; |
200 | QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name)); | 202 | QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name)); |
201 | diceB1=new CanvasImageItem*[7]; | 203 | diceB1=new CanvasImageItem*[7]; |
202 | diceB2=new CanvasImageItem*[7]; | 204 | diceB2=new CanvasImageItem*[7]; |
203 | QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name)); | 205 | QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name)); |
204 | //oddsDice=new CanvasImageItem*[6]; | 206 | //oddsDice=new CanvasImageItem*[6]; |
205 | 207 | ||
206 | 208 | ||
207 | for(a=0;a<7;a++) | 209 | for(a=0;a<7;a++) |
208 | { | 210 | { |
209 | QImage dicebgA=dicebgA_all.copy(a*25,0,25,25); | 211 | QImage dicebgA=dicebgA_all.copy(a*25,0,25,25); |
210 | diceA1[a]=new CanvasImageItem(dicebgA,area); | 212 | diceA1[a]=new CanvasImageItem(dicebgA,area); |
211 | diceA1[a]->setX(5); | 213 | diceA1[a]->setX(5); |
212 | diceA1[a]->setY(205-2); | 214 | diceA1[a]->setY(205-2); |
213 | diceA1[a]->setZ(1); | 215 | diceA1[a]->setZ(1); |
214 | diceA1[a]->setSize(25,25); | 216 | diceA1[a]->setSize(25,25); |
215 | diceA2[a]=new CanvasImageItem(dicebgA,area); | 217 | diceA2[a]=new CanvasImageItem(dicebgA,area); |
216 | diceA2[a]->setX(35); | 218 | diceA2[a]->setX(35); |
217 | diceA2[a]->setY(205-2); | 219 | diceA2[a]->setY(205-2); |
218 | diceA2[a]->setZ(1); | 220 | diceA2[a]->setZ(1); |
219 | diceA2[a]->setSize(25,25); | 221 | diceA2[a]->setSize(25,25); |
220 | 222 | ||
221 | QImage dicebgB=dicebgB_all.copy(a*25,0,25,25); | 223 | QImage dicebgB=dicebgB_all.copy(a*25,0,25,25); |
222 | diceB1[a]=new CanvasImageItem(dicebgB,area); | 224 | diceB1[a]=new CanvasImageItem(dicebgB,area); |
223 | diceB1[a]->setX(175); | 225 | diceB1[a]->setX(175); |
224 | diceB1[a]->setY(205-2); | 226 | diceB1[a]->setY(205-2); |
225 | diceB1[a]->setZ(1); | 227 | diceB1[a]->setZ(1); |
226 | diceB1[a]->setSize(25,25); | 228 | diceB1[a]->setSize(25,25); |
227 | diceB2[a]=new CanvasImageItem(dicebgB,area); | 229 | diceB2[a]=new CanvasImageItem(dicebgB,area); |
228 | diceB2[a]->setX(205); | 230 | diceB2[a]->setX(205); |
229 | diceB2[a]->setY(205-2); | 231 | diceB2[a]->setY(205-2); |
230 | diceB2[a]->setZ(1); | 232 | diceB2[a]->setZ(1); |
231 | diceB2[a]->setSize(25,25); | 233 | diceB2[a]->setSize(25,25); |
232 | 234 | ||
233 | /* | 235 | /* |
234 | if(a<6) | 236 | if(a<6) |
235 | { | 237 | { |
236 | QImage oddsbg=oddsbg_all.copy(a*15,0,15,15); | 238 | QImage oddsbg=oddsbg_all.copy(a*15,0,15,15); |
237 | oddsDice[a]=new CanvasImageItem(oddsbg,area); | 239 | oddsDice[a]=new CanvasImageItem(oddsbg,area); |
238 | oddsDice[a]->setX(110); | 240 | oddsDice[a]->setX(110); |
239 | oddsDice[a]->setY(210-2); | 241 | oddsDice[a]->setY(210-2); |
240 | oddsDice[a]->setZ(1); | 242 | oddsDice[a]->setZ(1); |
241 | oddsDice[a]->setSize(15,15); | 243 | oddsDice[a]->setSize(15,15); |
242 | oddsDice[a]->hide(); | 244 | oddsDice[a]->hide(); |
243 | } | 245 | } |
244 | */ | 246 | */ |
245 | } | 247 | } |
246 | //oddsDice[0]->show(); | 248 | //oddsDice[0]->show(); |
247 | 249 | ||
248 | //set the board | 250 | //set the board |
249 | QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name)); | 251 | QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name)); |
250 | board=new CanvasImageItem(boardbg,area); | 252 | board=new CanvasImageItem(boardbg,area); |
251 | board->setX(0); | 253 | board->setX(0); |
252 | board->setY(0); | 254 | board->setY(0); |
253 | board->setZ(0); | 255 | board->setZ(0); |
254 | board->setSize(235-2,200-2); | 256 | board->setSize(235-2,200-2); |
255 | board->show(); | 257 | board->show(); |
256 | 258 | ||
257 | //the table | 259 | //the table |
258 | QImage tablebg(Resource::loadImage("backgammon/table/"+table_name)); | 260 | QImage tablebg(Resource::loadImage("backgammon/table/"+table_name)); |
259 | table=new CanvasImageItem(tablebg,area); | 261 | table=new CanvasImageItem(tablebg,area); |
260 | table->setX(0); | 262 | table->setX(0); |
261 | table->setY(200-2); | 263 | table->setY(200-2); |
262 | table->setZ(0); | 264 | table->setZ(0); |
263 | table->setSize(235-2,20); | 265 | table->setSize(235-2,20); |
264 | table->show(); | 266 | table->show(); |
265 | 267 | ||
266 | //the no move marker | 268 | //the no move marker |
267 | QImage nomovebg(Resource::loadImage("backgammon/no_move")); | 269 | QImage nomovebg(Resource::loadImage("backgammon/no_move")); |
268 | nomove_marker=new CanvasImageItem(nomovebg,area); | 270 | nomove_marker=new CanvasImageItem(nomovebg,area); |
269 | nomove_marker->setX(0); | 271 | nomove_marker->setX(0); |
270 | nomove_marker->setY(200); | 272 | nomove_marker->setY(200); |
271 | nomove_marker->setZ(2); | 273 | nomove_marker->setZ(2); |
272 | nomove_marker->hide(); | 274 | nomove_marker->hide(); |
273 | 275 | ||
274 | //default human against computer | 276 | //default human against computer |
275 | player1_auto=false; | 277 | player1_auto=false; |
276 | player2_auto=true; | 278 | player2_auto=true; |
277 | //start new game | 279 | //start new game |
278 | newgame(); | 280 | newgame(); |
279 | } | 281 | } |
280 | 282 | ||
281 | BackGammon::~BackGammon() | 283 | BackGammon::~BackGammon() |
282 | { | 284 | { |
283 | //DESTRUCTOR | 285 | //DESTRUCTOR |
284 | } | 286 | } |
285 | 287 | ||
286 | void BackGammon::newgame() | 288 | void BackGammon::newgame() |
287 | { | 289 | { |
288 | gameFinished=false; | 290 | gameFinished=false; |
289 | QDateTime now=QDateTime::currentDateTime(); | 291 | QDateTime now=QDateTime::currentDateTime(); |
290 | game_name=now.date().toString()+"_"+now.time().toString(); | 292 | game_name=now.date().toString()+"_"+now.time().toString(); |
291 | move->reset(); | 293 | move->reset(); |
292 | draw(); | 294 | draw(); |
293 | diceA1_value=7; | 295 | diceA1_value=7; |
294 | diceA2_value=7; | 296 | diceA2_value=7; |
295 | diceA3_value=7; | 297 | diceA3_value=7; |
296 | diceA4_value=7; | 298 | diceA4_value=7; |
297 | diceB1_value=7; | 299 | diceB1_value=7; |
298 | diceB2_value=7; | 300 | diceB2_value=7; |
299 | diceB3_value=7; | 301 | diceB3_value=7; |
300 | diceB4_value=7; | 302 | diceB4_value=7; |
301 | showdice(); | 303 | showdice(); |
302 | player=2; | 304 | player=2; |
303 | dice1_played=true; | 305 | dice1_played=true; |
304 | dice2_played=true; | 306 | dice2_played=true; |
305 | dice3_played=true; | 307 | dice3_played=true; |
306 | dice4_played=true; | 308 | dice4_played=true; |
307 | dice_rolled=false; | 309 | dice_rolled=false; |
308 | setplayer(); | 310 | setplayer(); |
309 | area->update(); | 311 | area->update(); |
310 | } | 312 | } |
311 | 313 | ||
312 | void BackGammon::playerselect() | 314 | void BackGammon::playerselect() |
313 | { | 315 | { |
314 | PlayerDialog* playerdialog=new PlayerDialog(this); | 316 | PlayerDialog* playerdialog=new PlayerDialog(this); |
315 | playerdialog->setAuto1(player1_auto); | 317 | playerdialog->setAuto1(player1_auto); |
316 | playerdialog->setAuto2(player2_auto); | 318 | playerdialog->setAuto2(player2_auto); |
317 | if(!playerdialog->exec()) | 319 | if(!playerdialog->exec()) |
318 | return; | 320 | return; |
319 | player1_auto=playerdialog->getAuto1(); | 321 | player1_auto=playerdialog->getAuto1(); |
320 | player2_auto=playerdialog->getAuto2(); | 322 | player2_auto=playerdialog->getAuto2(); |
321 | } | 323 | } |
322 | 324 | ||
323 | void BackGammon::loadgame() | 325 | void BackGammon::loadgame() |
324 | { | 326 | { |
325 | FileDialog* file=new FileDialog(this,"Load Game",".game"); | 327 | FileDialog* file=new FileDialog(this,"Load Game",".game"); |
326 | if(!file->exec()) | 328 | if(!file->exec()) |
327 | return; | 329 | return; |
328 | 330 | ||
329 | game_name=file->filename(); | 331 | game_name=file->filename(); |
330 | QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; | 332 | QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; |
331 | 333 | ||
332 | Config game(game_file,Config::File); | 334 | Config game(game_file,Config::File); |
333 | game.setGroup("dice"); | 335 | game.setGroup("dice"); |
334 | diceA1_value=game.readNumEntry("diceA1_value"); | 336 | diceA1_value=game.readNumEntry("diceA1_value"); |
335 | diceA2_value=game.readNumEntry("diceA2_value"); | 337 | diceA2_value=game.readNumEntry("diceA2_value"); |
336 | diceA3_value=game.readNumEntry("diceA3_value"); | 338 | diceA3_value=game.readNumEntry("diceA3_value"); |
337 | diceA4_value=game.readNumEntry("diceA4_value"); | 339 | diceA4_value=game.readNumEntry("diceA4_value"); |
338 | diceB1_value=game.readNumEntry("diceB1_value"); | 340 | diceB1_value=game.readNumEntry("diceB1_value"); |
339 | diceB2_value=game.readNumEntry("diceB2_value"); | 341 | diceB2_value=game.readNumEntry("diceB2_value"); |
340 | diceB3_value=game.readNumEntry("diceB3_value"); | 342 | diceB3_value=game.readNumEntry("diceB3_value"); |
341 | diceB4_value=game.readNumEntry("diceB4_value"); | 343 | diceB4_value=game.readNumEntry("diceB4_value"); |
342 | player=game.readNumEntry("player"); | 344 | player=game.readNumEntry("player"); |
343 | dice1_played=game.readBoolEntry("dice1_played"); | 345 | dice1_played=game.readBoolEntry("dice1_played"); |
344 | dice2_played=game.readBoolEntry("dice2_played"); | 346 | dice2_played=game.readBoolEntry("dice2_played"); |
345 | dice3_played=game.readBoolEntry("dice3_played"); | 347 | dice3_played=game.readBoolEntry("dice3_played"); |
346 | dice4_played=game.readBoolEntry("dice4_played"); | 348 | dice4_played=game.readBoolEntry("dice4_played"); |
347 | dice_rolled=game.readBoolEntry("dice_rolled"); | 349 | dice_rolled=game.readBoolEntry("dice_rolled"); |
348 | player1_auto=game.readBoolEntry("player1_auto"); | 350 | player1_auto=game.readBoolEntry("player1_auto"); |
349 | player2_auto=game.readBoolEntry("player2_auto"); | 351 | player2_auto=game.readBoolEntry("player2_auto"); |
350 | 352 | ||
351 | game.setGroup("pieces"); | 353 | game.setGroup("pieces"); |
352 | QString label; | 354 | QString label; |
353 | LoadSave load; | 355 | LoadSave load; |
354 | for(int a=0;a<28;a++) | 356 | for(int a=0;a<28;a++) |
355 | { | 357 | { |
356 | label.setNum(a); | 358 | label.setNum(a); |
357 | load.pop[a].total = game.readNumEntry(label,0); | 359 | load.pop[a].total = game.readNumEntry(label,0); |
358 | } | 360 | } |
359 | 361 | ||
360 | move->loadGame(load); | 362 | move->loadGame(load); |
361 | setplayer(); | 363 | setplayer(); |
362 | showdice(); | 364 | showdice(); |
363 | draw(); | 365 | draw(); |
364 | area->update(); | 366 | area->update(); |
365 | } | 367 | } |
366 | 368 | ||
367 | void BackGammon::savegame() | 369 | void BackGammon::savegame() |
368 | { | 370 | { |
369 | QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; | 371 | QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; |
370 | 372 | ||
371 | Config game(game_file,Config::File); | 373 | Config game(game_file,Config::File); |
372 | game.setGroup("dice"); | 374 | game.setGroup("dice"); |
373 | game.writeEntry("diceA1_value",diceA1_value); | 375 | game.writeEntry("diceA1_value",diceA1_value); |
374 | game.writeEntry("diceA2_value",diceA2_value); | 376 | game.writeEntry("diceA2_value",diceA2_value); |
375 | game.writeEntry("diceA3_value",diceA3_value); | 377 | game.writeEntry("diceA3_value",diceA3_value); |
376 | game.writeEntry("diceA4_value",diceA4_value); | 378 | game.writeEntry("diceA4_value",diceA4_value); |
377 | game.writeEntry("diceB1_value",diceB1_value); | 379 | game.writeEntry("diceB1_value",diceB1_value); |
378 | game.writeEntry("diceB2_value",diceB3_value); | 380 | game.writeEntry("diceB2_value",diceB3_value); |
379 | game.writeEntry("diceB3_value",diceB4_value); | 381 | game.writeEntry("diceB3_value",diceB4_value); |
380 | game.writeEntry("diceB4_value",diceB4_value); | 382 | game.writeEntry("diceB4_value",diceB4_value); |
381 | game.writeEntry("player",player); | 383 | game.writeEntry("player",player); |
382 | game.writeEntry("dice1_played",dice1_played); | 384 | game.writeEntry("dice1_played",dice1_played); |
383 | game.writeEntry("dice2_played",dice2_played); | 385 | game.writeEntry("dice2_played",dice2_played); |
384 | game.writeEntry("dice3_played",dice3_played); | 386 | game.writeEntry("dice3_played",dice3_played); |
385 | game.writeEntry("dice4_played",dice4_played); | 387 | game.writeEntry("dice4_played",dice4_played); |
386 | game.writeEntry("dice_rolled",dice_rolled); | 388 | game.writeEntry("dice_rolled",dice_rolled); |
387 | game.writeEntry("player1_auto",player1_auto); | 389 | game.writeEntry("player1_auto",player1_auto); |
388 | game.writeEntry("player2_auto",player2_auto); | 390 | game.writeEntry("player2_auto",player2_auto); |
389 | 391 | ||
390 | game.setGroup("pieces"); | 392 | game.setGroup("pieces"); |
391 | QString label; | 393 | QString label; |
392 | LoadSave save=move->saveGame(); | 394 | LoadSave save=move->saveGame(); |
393 | for(int a=0;a<28;a++) | 395 | for(int a=0;a<28;a++) |
diff --git a/noncore/games/backgammon/backgammon.h b/noncore/games/backgammon/backgammon.h index e3276f1..d803489 100644 --- a/noncore/games/backgammon/backgammon.h +++ b/noncore/games/backgammon/backgammon.h | |||
@@ -1,120 +1,119 @@ | |||
1 | #ifndef BACKGAMMON_H | 1 | #ifndef BACKGAMMON_H |
2 | #define BACKGAMMON_H | 2 | #define BACKGAMMON_H |
3 | 3 | ||
4 | #include "backgammonview.h" | 4 | #include "backgammonview.h" |
5 | #include "canvasimageitem.h" | 5 | #include "canvasimageitem.h" |
6 | //#include "rulesdialog.h" | 6 | //#include "rulesdialog.h" |
7 | #include "moveengine.h" | 7 | #include "moveengine.h" |
8 | 8 | ||
9 | 9 | ||
10 | #include <qlabel.h> | 10 | #include <qlabel.h> |
11 | #include <qmainwindow.h> | 11 | #include <qmainwindow.h> |
12 | //#include <qwidget.h> | 12 | //#include <qwidget.h> |
13 | 13 | ||
14 | 14 | ||
15 | 15 | ||
16 | 16 | ||
17 | class BackGammon : public QMainWindow | 17 | class BackGammon : public QMainWindow |
18 | { | 18 | { |
19 | Q_OBJECT | 19 | Q_OBJECT |
20 | private: | 20 | private: |
21 | //GUI | ||
22 | //the "status" bar | 21 | //the "status" bar |
23 | QLabel* message; | 22 | QLabel* message; |
24 | //the main drawing area | 23 | //the main drawing area |
25 | QCanvas* area; | 24 | QCanvas* area; |
26 | BackGammonView* boardview; | 25 | BackGammonView* boardview; |
27 | CanvasImageItem* board; | 26 | CanvasImageItem* board; |
28 | CanvasImageItem* table; | 27 | CanvasImageItem* table; |
29 | CanvasImageItem** p1; | 28 | CanvasImageItem** p1; |
30 | CanvasImageItem** p2; | 29 | CanvasImageItem** p2; |
31 | CanvasImageItem** p1_side; | 30 | CanvasImageItem** p1_side; |
32 | CanvasImageItem** p2_side; | 31 | CanvasImageItem** p2_side; |
33 | 32 | ||
34 | CanvasImageItem** diceA1; | 33 | CanvasImageItem** diceA1; |
35 | CanvasImageItem** diceA2; | 34 | CanvasImageItem** diceA2; |
36 | CanvasImageItem** diceB1; | 35 | CanvasImageItem** diceB1; |
37 | CanvasImageItem** diceB2; | 36 | CanvasImageItem** diceB2; |
38 | //CanvasImageItem** oddsDice; | 37 | //CanvasImageItem** oddsDice; |
39 | CanvasImageItem* nomove_marker; | 38 | CanvasImageItem* nomove_marker; |
40 | 39 | ||
41 | QCanvasRectangle* marker_current; | 40 | QCanvasRectangle* marker_current; |
42 | QCanvasRectangle* marker_next[4]; | 41 | QCanvasRectangle* marker_next[4]; |
43 | 42 | ||
44 | //ENGINE | 43 | //ENGINE |
45 | MoveEngine* move; | 44 | MoveEngine* move; |
46 | //the dice values | 45 | //the dice values |
47 | int diceA1_value; | 46 | int diceA1_value; |
48 | int diceA2_value; | 47 | int diceA2_value; |
49 | int diceA3_value; | 48 | int diceA3_value; |
50 | int diceA4_value; | 49 | int diceA4_value; |
51 | int diceB1_value; | 50 | int diceB1_value; |
52 | int diceB2_value; | 51 | int diceB2_value; |
53 | int diceB3_value; | 52 | int diceB3_value; |
54 | int diceB4_value; | 53 | int diceB4_value; |
55 | 54 | ||
56 | int player; | 55 | int player; |
57 | bool dice1_played; | 56 | bool dice1_played; |
58 | bool dice2_played; | 57 | bool dice2_played; |
59 | bool dice3_played; | 58 | bool dice3_played; |
60 | bool dice4_played; | 59 | bool dice4_played; |
61 | bool dice_rolled; | 60 | bool dice_rolled; |
62 | //computer opponent | 61 | //computer opponent |
63 | bool player1_auto; | 62 | bool player1_auto; |
64 | bool player2_auto; | 63 | bool player2_auto; |
65 | 64 | ||
66 | //the images; | 65 | //the images; |
67 | QString theme_name; | 66 | QString theme_name; |
68 | QString board_name; | 67 | QString board_name; |
69 | QString piecesA_name; | 68 | QString piecesA_name; |
70 | QString piecesB_name; | 69 | QString piecesB_name; |
71 | QString diceA_name; | 70 | QString diceA_name; |
72 | QString diceB_name; | 71 | QString diceB_name; |
73 | QString odds_name; | 72 | QString odds_name; |
74 | QString table_name; | 73 | QString table_name; |
75 | 74 | ||
76 | //save game | 75 | //save game |
77 | QString game_name; | 76 | QString game_name; |
78 | 77 | ||
79 | //the rules | 78 | //the rules |
80 | Rules rules; | 79 | Rules rules; |
81 | 80 | ||
82 | //display settings | 81 | //display settings |
83 | Display display; | 82 | Display display; |
84 | //is the game finished ? | 83 | //is the game finished ? |
85 | bool gameFinished; | 84 | bool gameFinished; |
86 | 85 | ||
87 | public: | 86 | public: |
88 | BackGammon( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | 87 | BackGammon( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
89 | ~BackGammon(); | 88 | ~BackGammon(); |
90 | private slots: | 89 | private slots: |
91 | void newgame(); | 90 | void newgame(); |
92 | void playerselect(); | 91 | void playerselect(); |
93 | void loadgame(); | 92 | void loadgame(); |
94 | void savegame(); | 93 | void savegame(); |
95 | void deletegame(); | 94 | void deletegame(); |
96 | void newtheme(); | 95 | void newtheme(); |
97 | void loadtheme(); | 96 | void loadtheme(); |
98 | void savetheme(); | 97 | void savetheme(); |
99 | void themedefault(); | 98 | void themedefault(); |
100 | void deletetheme(); | 99 | void deletetheme(); |
101 | void modify_AI(); | 100 | void modify_AI(); |
102 | void setrules(); | 101 | void setrules(); |
103 | void mouse(int x,int y); | 102 | void mouse(int x,int y); |
104 | void done_dice1(); | 103 | void done_dice1(); |
105 | void done_dice2(); | 104 | void done_dice2(); |
106 | void done_dice3(); | 105 | void done_dice3(); |
107 | void done_dice4(); | 106 | void done_dice4(); |
108 | void nomove(); | 107 | void nomove(); |
109 | void nomove2(); | 108 | void nomove2(); |
110 | void finished(int theplayer); | 109 | void finished(int theplayer); |
111 | void autoroll_dice1(); | 110 | void autoroll_dice1(); |
112 | void autoroll_dice2(); | 111 | void autoroll_dice2(); |
113 | private: | 112 | private: |
114 | void draw(); | 113 | void draw(); |
115 | void showdice(); | 114 | void showdice(); |
116 | void setplayer(); | 115 | void setplayer(); |
117 | void applytheme(); | 116 | void applytheme(); |
118 | }; | 117 | }; |
119 | 118 | ||
120 | #endif //BACKGAMMON_H | 119 | #endif //BACKGAMMON_H |