author | waspe <waspe> | 2003-06-05 06:48:39 (UTC) |
---|---|---|
committer | waspe <waspe> | 2003-06-05 06:48:39 (UTC) |
commit | 2f3202871135e2efc67c0cdef9b93d4c4953f372 (patch) (unidiff) | |
tree | a988198fdf08bd48d98a961a2194b59177af7013 | |
parent | b72cce3813dfb64fd6d1920961b236c8e27bd27b (diff) | |
download | opie-2f3202871135e2efc67c0cdef9b93d4c4953f372.zip opie-2f3202871135e2efc67c0cdef9b93d4c4953f372.tar.gz opie-2f3202871135e2efc67c0cdef9b93d4c4953f372.tar.bz2 |
backround of canvas now in syscolor
-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,974 +1,976 @@ | |||
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++) |
394 | { | 396 | { |
395 | label.setNum(a); | 397 | label.setNum(a); |
396 | game.writeEntry(label,save.pop[a].total); | 398 | game.writeEntry(label,save.pop[a].total); |
397 | } | 399 | } |
398 | QMessageBox::information(this,"Backgammon","Game saved","OK"); | 400 | QMessageBox::information(this,"Backgammon","Game saved","OK"); |
399 | } | 401 | } |
400 | 402 | ||
401 | void BackGammon::deletegame() | 403 | void BackGammon::deletegame() |
402 | { | 404 | { |
403 | FileDialog* file=new FileDialog(this,"Delete Game",".game"); | 405 | FileDialog* file=new FileDialog(this,"Delete Game",".game"); |
404 | if(!file->exec()) | 406 | if(!file->exec()) |
405 | return; | 407 | return; |
406 | 408 | ||
407 | game_name=file->filename(); | 409 | game_name=file->filename(); |
408 | QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; | 410 | QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; |
409 | 411 | ||
410 | if(!QMessageBox::warning(this,"Backgammon","deleted game\n"+game_name+" ?","OK","Cancel")) | 412 | if(!QMessageBox::warning(this,"Backgammon","deleted game\n"+game_name+" ?","OK","Cancel")) |
411 | { | 413 | { |
412 | QFile(game_file).remove(); | 414 | QFile(game_file).remove(); |
413 | } | 415 | } |
414 | } | 416 | } |
415 | 417 | ||
416 | 418 | ||
417 | void BackGammon::newtheme() | 419 | void BackGammon::newtheme() |
418 | { | 420 | { |
419 | ThemeDialog* theme=new ThemeDialog(this); | 421 | ThemeDialog* theme=new ThemeDialog(this); |
420 | 422 | ||
421 | ImageNames names; | 423 | ImageNames names; |
422 | names.theme=theme_name; | 424 | names.theme=theme_name; |
423 | names.board=board_name; | 425 | names.board=board_name; |
424 | names.pieces1=piecesA_name; | 426 | names.pieces1=piecesA_name; |
425 | names.pieces2=piecesB_name; | 427 | names.pieces2=piecesB_name; |
426 | names.dice1=diceA_name; | 428 | names.dice1=diceA_name; |
427 | names.dice2=diceB_name; | 429 | names.dice2=diceB_name; |
428 | names.odds=odds_name; | 430 | names.odds=odds_name; |
429 | names.table=table_name; | 431 | names.table=table_name; |
430 | 432 | ||
431 | theme->setCurrent(names); | 433 | theme->setCurrent(names); |
432 | if(!theme->exec()) | 434 | if(!theme->exec()) |
433 | return; | 435 | return; |
434 | 436 | ||
435 | names=theme->getNames(); | 437 | names=theme->getNames(); |
436 | theme_name=names.theme; | 438 | theme_name=names.theme; |
437 | board_name=names.board; | 439 | board_name=names.board; |
438 | piecesA_name=names.pieces1; | 440 | piecesA_name=names.pieces1; |
439 | piecesB_name=names.pieces2; | 441 | piecesB_name=names.pieces2; |
440 | diceA_name=names.dice1; | 442 | diceA_name=names.dice1; |
441 | diceB_name=names.dice2; | 443 | diceB_name=names.dice2; |
442 | odds_name=names.odds; | 444 | odds_name=names.odds; |
443 | table_name=names.table; | 445 | table_name=names.table; |
444 | 446 | ||
445 | applytheme(); | 447 | applytheme(); |
446 | } | 448 | } |
447 | 449 | ||
448 | void BackGammon::loadtheme() | 450 | void BackGammon::loadtheme() |
449 | { | 451 | { |
450 | FileDialog* file=new FileDialog(this,"Load Theme",".theme"); | 452 | FileDialog* file=new FileDialog(this,"Load Theme",".theme"); |
451 | if(!file->exec()) | 453 | if(!file->exec()) |
452 | return; | 454 | return; |
453 | 455 | ||
454 | theme_name=file->filename(); | 456 | theme_name=file->filename(); |
455 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; | 457 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; |
456 | 458 | ||
457 | Config theme(theme_file,Config::File); | 459 | Config theme(theme_file,Config::File); |
458 | theme.setGroup("theme"); | 460 | theme.setGroup("theme"); |
459 | board_name=theme.readEntry("board","board_1"); | 461 | board_name=theme.readEntry("board","board_1"); |
460 | piecesA_name=theme.readEntry("pieces1","pieces_1"); | 462 | piecesA_name=theme.readEntry("pieces1","pieces_1"); |
461 | piecesB_name=theme.readEntry("pieces2","pieces_2"); | 463 | piecesB_name=theme.readEntry("pieces2","pieces_2"); |
462 | diceA_name=theme.readEntry("dice1","dice_1"); | 464 | diceA_name=theme.readEntry("dice1","dice_1"); |
463 | diceB_name=theme.readEntry("dice2","dice_2"); | 465 | diceB_name=theme.readEntry("dice2","dice_2"); |
464 | table_name=theme.readEntry("table","table_1"); | 466 | table_name=theme.readEntry("table","table_1"); |
465 | odds_name=theme.readEntry("odds","odds_1"); | 467 | odds_name=theme.readEntry("odds","odds_1"); |
466 | 468 | ||
467 | applytheme(); | 469 | applytheme(); |
468 | 470 | ||
469 | } | 471 | } |
470 | 472 | ||
471 | void BackGammon::savetheme() | 473 | void BackGammon::savetheme() |
472 | { | 474 | { |
473 | if(theme_name=="default") | 475 | if(theme_name=="default") |
474 | { | 476 | { |
475 | QMessageBox::information(this,"Backgammon","Sorry\nCannot overwrite default.theme","OK"); | 477 | QMessageBox::information(this,"Backgammon","Sorry\nCannot overwrite default.theme","OK"); |
476 | return; | 478 | return; |
477 | } | 479 | } |
478 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; | 480 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; |
479 | if(QMessageBox::information(this,"Backgammon","Save Theme\n"+theme_name,"Yes","No")) | 481 | if(QMessageBox::information(this,"Backgammon","Save Theme\n"+theme_name,"Yes","No")) |
480 | return; | 482 | return; |
481 | 483 | ||
482 | Config theme(theme_file,Config::File); | 484 | Config theme(theme_file,Config::File); |
483 | theme.setGroup("theme"); | 485 | theme.setGroup("theme"); |
484 | theme.writeEntry("board",board_name); | 486 | theme.writeEntry("board",board_name); |
485 | theme.writeEntry("pieces1",piecesA_name); | 487 | theme.writeEntry("pieces1",piecesA_name); |
486 | theme.writeEntry("pieces2",piecesB_name); | 488 | theme.writeEntry("pieces2",piecesB_name); |
487 | theme.writeEntry("dice1",diceA_name); | 489 | theme.writeEntry("dice1",diceA_name); |
488 | theme.writeEntry("dice2",diceB_name); | 490 | theme.writeEntry("dice2",diceB_name); |
489 | theme.writeEntry("table",table_name); | 491 | theme.writeEntry("table",table_name); |
490 | theme.writeEntry("odds",odds_name); | 492 | theme.writeEntry("odds",odds_name); |
491 | 493 | ||
492 | } | 494 | } |
493 | 495 | ||
494 | void BackGammon::themedefault() | 496 | void BackGammon::themedefault() |
495 | { | 497 | { |
496 | if(QMessageBox::information(this,"Backgammon","Make Theme\n"+theme_name+"\nthe default theme","Yes","No")) | 498 | if(QMessageBox::information(this,"Backgammon","Make Theme\n"+theme_name+"\nthe default theme","Yes","No")) |
497 | return; | 499 | return; |
498 | 500 | ||
499 | Config conf("backgammon"); | 501 | Config conf("backgammon"); |
500 | conf.setGroup("general"); | 502 | conf.setGroup("general"); |
501 | conf.writeEntry("theme",theme_name); | 503 | conf.writeEntry("theme",theme_name); |
502 | } | 504 | } |
503 | 505 | ||
504 | void BackGammon::deletetheme() | 506 | void BackGammon::deletetheme() |
505 | { | 507 | { |
506 | FileDialog* file=new FileDialog(this,"Delete Theme",".theme"); | 508 | FileDialog* file=new FileDialog(this,"Delete Theme",".theme"); |
507 | if(!file->exec()) | 509 | if(!file->exec()) |
508 | return; | 510 | return; |
509 | 511 | ||
510 | theme_name=file->filename(); | 512 | theme_name=file->filename(); |
511 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; | 513 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; |
512 | 514 | ||
513 | if(!QMessageBox::warning(this,tr( "Backgammon" ),tr( "deleted theme %1?").arg(theme_name),tr( "OK" ),tr( "Cancel" ))) | 515 | if(!QMessageBox::warning(this,tr( "Backgammon" ),tr( "deleted theme %1?").arg(theme_name),tr( "OK" ),tr( "Cancel" ))) |
514 | { | 516 | { |
515 | QFile(theme_file).remove(); | 517 | QFile(theme_file).remove(); |
516 | } | 518 | } |
517 | } | 519 | } |
518 | 520 | ||
519 | void BackGammon::modify_AI() | 521 | void BackGammon::modify_AI() |
520 | { | 522 | { |
521 | AI_Dialog* ai_mod=new AI_Dialog(this,tr( "Load Theme" ),".theme"); | 523 | AI_Dialog* ai_mod=new AI_Dialog(this,tr( "Load Theme" ),".theme"); |
522 | ai_mod->setAISettings(move->getAISettings()); | 524 | ai_mod->setAISettings(move->getAISettings()); |
523 | if(!ai_mod->exec()) | 525 | if(!ai_mod->exec()) |
524 | return; | 526 | return; |
525 | 527 | ||
526 | //get the AI settings | 528 | //get the AI settings |
527 | AISettings ai=ai_mod->getAISettings(); | 529 | AISettings ai=ai_mod->getAISettings(); |
528 | move->setAISettings(ai); | 530 | move->setAISettings(ai); |
529 | //write new settings to conf file | 531 | //write new settings to conf file |
530 | Config conf("backgammon"); | 532 | Config conf("backgammon"); |
531 | conf.setGroup("ai"); | 533 | conf.setGroup("ai"); |
532 | conf.writeEntry("rescue",ai.rescue); | 534 | conf.writeEntry("rescue",ai.rescue); |
533 | conf.writeEntry("eliminate",ai.eliminate); | 535 | conf.writeEntry("eliminate",ai.eliminate); |
534 | conf.writeEntry("expose",ai.expose); | 536 | conf.writeEntry("expose",ai.expose); |
535 | conf.writeEntry("protect",ai.protect); | 537 | conf.writeEntry("protect",ai.protect); |
536 | conf.writeEntry("safe",ai.safe); | 538 | conf.writeEntry("safe",ai.safe); |
537 | conf.writeEntry("empty",ai.empty); | 539 | conf.writeEntry("empty",ai.empty); |
538 | } | 540 | } |
539 | 541 | ||
540 | void BackGammon::setrules() | 542 | void BackGammon::setrules() |
541 | { | 543 | { |
542 | RulesDialog* rulesdialog=new RulesDialog(this,tr( "Load Theme" ),".theme"); | 544 | RulesDialog* rulesdialog=new RulesDialog(this,tr( "Load Theme" ),".theme"); |
543 | rulesdialog->setRules(rules); | 545 | rulesdialog->setRules(rules); |
544 | if(!rulesdialog->exec()) | 546 | if(!rulesdialog->exec()) |
545 | return; | 547 | return; |
546 | rules=rulesdialog->getRules(); | 548 | rules=rulesdialog->getRules(); |
547 | Config conf("backgammon"); | 549 | Config conf("backgammon"); |
548 | conf.setGroup("rules"); | 550 | conf.setGroup("rules"); |
549 | conf.writeEntry("move_with_pieces_out",rules.move_with_pieces_out); | 551 | conf.writeEntry("move_with_pieces_out",rules.move_with_pieces_out); |
550 | conf.writeEntry("nice_dice",rules.generous_dice); | 552 | conf.writeEntry("nice_dice",rules.generous_dice); |
551 | move->setRules(rules); | 553 | move->setRules(rules); |
552 | } | 554 | } |
553 | 555 | ||
554 | 556 | ||
555 | void BackGammon::draw() | 557 | void BackGammon::draw() |
556 | { | 558 | { |
557 | Pieces pieces; | 559 | Pieces pieces; |
558 | move->position(pieces); | 560 | move->position(pieces); |
559 | for(int a=0;a<15;a++) | 561 | for(int a=0;a<15;a++) |
560 | { | 562 | { |
561 | if(!pieces.player1[a].side) | 563 | if(!pieces.player1[a].side) |
562 | { | 564 | { |
563 | p1[a]->setX(pieces.player1[a].x); | 565 | p1[a]->setX(pieces.player1[a].x); |
564 | p1[a]->setY(pieces.player1[a].y); | 566 | p1[a]->setY(pieces.player1[a].y); |
565 | p1[a]->setZ(pieces.player1[a].z); | 567 | p1[a]->setZ(pieces.player1[a].z); |
566 | p1[a]->show(); | 568 | p1[a]->show(); |
567 | p1_side[a]->hide(); | 569 | p1_side[a]->hide(); |
568 | } | 570 | } |
569 | else | 571 | else |
570 | { | 572 | { |
571 | p1_side[a]->setX(pieces.player1[a].x); | 573 | p1_side[a]->setX(pieces.player1[a].x); |
572 | p1_side[a]->setY(pieces.player1[a].y); | 574 | p1_side[a]->setY(pieces.player1[a].y); |
573 | p1_side[a]->setZ(pieces.player1[a].z); | 575 | p1_side[a]->setZ(pieces.player1[a].z); |
574 | p1_side[a]->show(); | 576 | p1_side[a]->show(); |
575 | p1[a]->hide(); | 577 | p1[a]->hide(); |
576 | } | 578 | } |
577 | 579 | ||
578 | if(!pieces.player2[a].side) | 580 | if(!pieces.player2[a].side) |
579 | { | 581 | { |
580 | p2[a]->setX(pieces.player2[a].x); | 582 | p2[a]->setX(pieces.player2[a].x); |
581 | p2[a]->setY(pieces.player2[a].y); | 583 | p2[a]->setY(pieces.player2[a].y); |
582 | p2[a]->setZ(pieces.player2[a].z); | 584 | p2[a]->setZ(pieces.player2[a].z); |
583 | p2[a]->show(); | 585 | p2[a]->show(); |
584 | p2_side[a]->hide(); | 586 | p2_side[a]->hide(); |
585 | } | 587 | } |
586 | else | 588 | else |
587 | { | 589 | { |
588 | p2_side[a]->setX(pieces.player2[a].x); | 590 | p2_side[a]->setX(pieces.player2[a].x); |
589 | p2_side[a]->setY(pieces.player2[a].y); | 591 | p2_side[a]->setY(pieces.player2[a].y); |
590 | p2_side[a]->setZ(pieces.player2[a].z); | 592 | p2_side[a]->setZ(pieces.player2[a].z); |
591 | p2_side[a]->show(); | 593 | p2_side[a]->show(); |
592 | p2[a]->hide(); | 594 | p2[a]->hide(); |
593 | } | 595 | } |
594 | } | 596 | } |
595 | } | 597 | } |
596 | 598 | ||
597 | void BackGammon::mouse(int x,int y) | 599 | void BackGammon::mouse(int x,int y) |
598 | { | 600 | { |
599 | if(gameFinished) | 601 | if(gameFinished) |
600 | { | 602 | { |
601 | newgame(); | 603 | newgame(); |
602 | return; | 604 | return; |
603 | } | 605 | } |
604 | if(y<=200) //move pieces | 606 | if(y<=200) //move pieces |
605 | { | 607 | { |
606 | if((player==1 && player1_auto) || (player==2 && player2_auto)) | 608 | if((player==1 && player1_auto) || (player==2 && player2_auto)) |
607 | return; | 609 | return; |
608 | 610 | ||
609 | Marker marker; | 611 | Marker marker; |
610 | 612 | ||
611 | move->boardpressed(x,y,marker); | 613 | move->boardpressed(x,y,marker); |
612 | if(marker.visible_current) | 614 | if(marker.visible_current) |
613 | { | 615 | { |
614 | marker_current->setX(marker.x_current); | 616 | marker_current->setX(marker.x_current); |
615 | marker_current->setY(marker.y_current); | 617 | marker_current->setY(marker.y_current); |
616 | marker_current->show(); | 618 | marker_current->show(); |
617 | } | 619 | } |
618 | else | 620 | else |
619 | { | 621 | { |
620 | marker_current->hide(); | 622 | marker_current->hide(); |
621 | } | 623 | } |
622 | 624 | ||
623 | for(int a=0;a<4;a++) | 625 | for(int a=0;a<4;a++) |
624 | { | 626 | { |
625 | if(marker.visible_next[a]) | 627 | if(marker.visible_next[a]) |
626 | { | 628 | { |
627 | marker_next[a]->setX(marker.x_next[a]); | 629 | marker_next[a]->setX(marker.x_next[a]); |
628 | marker_next[a]->setY(marker.y_next[a]); | 630 | marker_next[a]->setY(marker.y_next[a]); |
629 | marker_next[a]->show(); | 631 | marker_next[a]->show(); |
630 | } | 632 | } |
631 | else | 633 | else |
632 | { | 634 | { |
633 | marker_next[a]->hide(); | 635 | marker_next[a]->hide(); |
634 | } | 636 | } |
635 | } | 637 | } |
636 | area->update(); | 638 | area->update(); |
637 | } | 639 | } |
638 | else //roll dice | 640 | else //roll dice |
639 | { | 641 | { |
640 | if(x>=10 && x<=65 && player==1 && !dice_rolled) | 642 | if(x>=10 && x<=65 && player==1 && !dice_rolled) |
641 | { | 643 | { |
642 | dice1_played=false; | 644 | dice1_played=false; |
643 | dice2_played=false; | 645 | dice2_played=false; |
644 | dice3_played=false; | 646 | dice3_played=false; |
645 | dice4_played=false; | 647 | dice4_played=false; |
646 | dice_rolled=true; | 648 | dice_rolled=true; |
647 | srand(QTime::currentTime().msec()); | 649 | srand(QTime::currentTime().msec()); |
648 | diceA1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); | 650 | diceA1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); |
649 | diceA2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); | 651 | diceA2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); |
650 | if(diceA1_value==diceA2_value) | 652 | if(diceA1_value==diceA2_value) |
651 | { | 653 | { |
652 | diceA3_value=diceA1_value; | 654 | diceA3_value=diceA1_value; |
653 | diceA4_value=diceA1_value; | 655 | diceA4_value=diceA1_value; |
654 | } | 656 | } |
655 | else | 657 | else |
656 | { | 658 | { |
657 | diceA3_value=7; | 659 | diceA3_value=7; |
658 | dice3_played=true; | 660 | dice3_played=true; |
659 | diceA4_value=7; | 661 | diceA4_value=7; |
660 | dice4_played=true; | 662 | dice4_played=true; |
661 | } | 663 | } |
662 | showdice(); | 664 | showdice(); |
663 | area->update(); | 665 | area->update(); |
664 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); | 666 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); |
665 | 667 | ||
666 | } | 668 | } |
667 | else if(x>=160 && x<=225 && player==2 && !dice_rolled) | 669 | else if(x>=160 && x<=225 && player==2 && !dice_rolled) |
668 | { | 670 | { |
669 | dice1_played=false; | 671 | dice1_played=false; |
670 | dice2_played=false; | 672 | dice2_played=false; |
671 | dice3_played=false; | 673 | dice3_played=false; |
672 | dice4_played=false; | 674 | dice4_played=false; |
673 | dice_rolled=true; | 675 | dice_rolled=true; |
674 | srand(QTime::currentTime().msec()); | 676 | srand(QTime::currentTime().msec()); |
675 | diceB1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); | 677 | diceB1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); |
676 | diceB2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); | 678 | diceB2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); |
677 | if(diceB1_value==diceB2_value) | 679 | if(diceB1_value==diceB2_value) |
678 | { | 680 | { |
679 | diceB3_value=diceB1_value; | 681 | diceB3_value=diceB1_value; |
680 | diceB4_value=diceB1_value; | 682 | diceB4_value=diceB1_value; |
681 | } | 683 | } |
682 | else | 684 | else |
683 | { | 685 | { |
684 | diceB3_value=7; | 686 | diceB3_value=7; |
685 | dice3_played=true; | 687 | dice3_played=true; |
686 | diceB4_value=7; | 688 | diceB4_value=7; |
687 | dice4_played=true; | 689 | dice4_played=true; |
688 | } | 690 | } |
689 | showdice(); | 691 | showdice(); |
690 | area->update(); | 692 | area->update(); |
691 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); | 693 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); |
692 | } | 694 | } |
693 | } | 695 | } |
694 | } | 696 | } |
695 | 697 | ||
696 | void BackGammon::done_dice1() | 698 | void BackGammon::done_dice1() |
697 | { | 699 | { |
698 | dice1_played=true; | 700 | dice1_played=true; |
699 | if(player==1) | 701 | if(player==1) |
700 | diceA1_value=7; | 702 | diceA1_value=7; |
701 | else | 703 | else |
702 | diceB1_value=7; | 704 | diceB1_value=7; |
703 | setplayer(); | 705 | setplayer(); |
704 | showdice(); | 706 | showdice(); |
705 | draw(); | 707 | draw(); |
706 | area->update(); | 708 | area->update(); |
707 | if(!dice2_played || !dice3_played || !dice4_played) | 709 | if(!dice2_played || !dice3_played || !dice4_played) |
708 | { | 710 | { |
709 | if(player==1) | 711 | if(player==1) |
710 | { | 712 | { |
711 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); | 713 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); |
712 | } | 714 | } |
713 | else | 715 | else |
714 | { | 716 | { |
715 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); | 717 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); |
716 | } | 718 | } |
717 | } | 719 | } |
718 | } | 720 | } |
719 | 721 | ||
720 | void BackGammon::done_dice2() | 722 | void BackGammon::done_dice2() |
721 | { | 723 | { |
722 | dice2_played=true; | 724 | dice2_played=true; |
723 | if(player==1) | 725 | if(player==1) |
724 | diceA2_value=7; | 726 | diceA2_value=7; |
725 | else | 727 | else |
726 | diceB2_value=7; | 728 | diceB2_value=7; |
727 | setplayer(); | 729 | setplayer(); |
728 | showdice(); | 730 | showdice(); |
729 | draw(); | 731 | draw(); |
730 | area->update(); | 732 | area->update(); |
731 | if(!dice1_played || !dice3_played || !dice4_played) | 733 | if(!dice1_played || !dice3_played || !dice4_played) |
732 | { | 734 | { |
733 | if(player==1) | 735 | if(player==1) |
734 | { | 736 | { |
735 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); | 737 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); |
736 | } | 738 | } |
737 | else | 739 | else |
738 | { | 740 | { |
739 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); | 741 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); |
740 | } | 742 | } |
741 | } | 743 | } |
742 | } | 744 | } |
743 | 745 | ||
744 | 746 | ||
745 | void BackGammon::done_dice3() | 747 | void BackGammon::done_dice3() |
746 | { | 748 | { |
747 | dice3_played=true; | 749 | dice3_played=true; |
748 | if(player==1) | 750 | if(player==1) |
749 | diceA3_value=7; | 751 | diceA3_value=7; |
750 | else | 752 | else |
751 | diceB3_value=7; | 753 | diceB3_value=7; |
752 | setplayer(); | 754 | setplayer(); |
753 | showdice(); | 755 | showdice(); |
754 | draw(); | 756 | draw(); |
755 | area->update(); | 757 | area->update(); |
756 | if(!dice1_played || !dice2_played || !dice4_played) | 758 | if(!dice1_played || !dice2_played || !dice4_played) |
757 | { | 759 | { |
758 | if(player==1) | 760 | if(player==1) |
759 | { | 761 | { |
760 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); | 762 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); |
761 | } | 763 | } |
762 | else | 764 | else |
763 | { | 765 | { |
764 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); | 766 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); |
765 | } | 767 | } |
766 | } | 768 | } |
767 | } | 769 | } |
768 | 770 | ||
769 | 771 | ||
770 | void BackGammon::done_dice4() | 772 | void BackGammon::done_dice4() |
771 | { | 773 | { |
772 | dice4_played=true; | 774 | dice4_played=true; |
773 | if(player==1) | 775 | if(player==1) |
774 | diceA4_value=7; | 776 | diceA4_value=7; |
775 | else | 777 | else |
776 | diceB4_value=7; | 778 | diceB4_value=7; |
777 | setplayer(); | 779 | setplayer(); |
778 | showdice(); | 780 | showdice(); |
779 | draw(); | 781 | draw(); |
780 | area->update(); | 782 | area->update(); |
781 | if(!dice1_played || !dice2_played || !dice3_played) | 783 | if(!dice1_played || !dice2_played || !dice3_played) |
782 | { | 784 | { |
783 | if(player==1) | 785 | if(player==1) |
784 | { | 786 | { |
785 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); | 787 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); |
786 | } | 788 | } |
787 | else | 789 | else |
788 | { | 790 | { |
789 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); | 791 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); |
790 | } | 792 | } |
791 | } | 793 | } |
792 | } | 794 | } |
793 | 795 | ||
794 | 796 | ||
795 | void BackGammon::nomove() | 797 | void BackGammon::nomove() |
796 | { | 798 | { |
797 | if(player==1) | 799 | if(player==1) |
798 | nomove_marker->setX(0); | 800 | nomove_marker->setX(0); |
799 | else | 801 | else |
800 | nomove_marker->setX(170); | 802 | nomove_marker->setX(170); |
801 | nomove_marker->show(); | 803 | nomove_marker->show(); |
802 | message->setText(tr( "<b>no move</b>" )); | 804 | message->setText(tr( "<b>no move</b>" )); |
803 | dice1_played=true; | 805 | dice1_played=true; |
804 | dice2_played=true; | 806 | dice2_played=true; |
805 | dice3_played=true; | 807 | dice3_played=true; |
806 | dice4_played=true; | 808 | dice4_played=true; |
807 | if(player==1) | 809 | if(player==1) |
808 | { | 810 | { |
809 | diceA1_value=7; | 811 | diceA1_value=7; |
810 | diceA2_value=7; | 812 | diceA2_value=7; |
811 | diceA3_value=7; | 813 | diceA3_value=7; |
812 | diceA4_value=7; | 814 | diceA4_value=7; |
813 | } | 815 | } |
814 | else | 816 | else |
815 | { | 817 | { |
816 | diceB1_value=7; | 818 | diceB1_value=7; |
817 | diceB2_value=7; | 819 | diceB2_value=7; |
818 | diceB3_value=7; | 820 | diceB3_value=7; |
819 | diceB4_value=7; | 821 | diceB4_value=7; |
820 | } | 822 | } |
821 | area->update(); | 823 | area->update(); |
822 | QTimer::singleShot(2000,this,SLOT(nomove2())); | 824 | QTimer::singleShot(2000,this,SLOT(nomove2())); |
823 | } | 825 | } |
824 | 826 | ||
825 | void BackGammon::nomove2() | 827 | void BackGammon::nomove2() |
826 | { | 828 | { |
827 | nomove_marker->hide(); | 829 | nomove_marker->hide(); |
828 | setplayer(); | 830 | setplayer(); |
829 | showdice(); | 831 | showdice(); |
830 | draw(); | 832 | draw(); |
831 | area->update(); | 833 | area->update(); |
832 | } | 834 | } |
833 | 835 | ||
834 | void BackGammon::finished(int theplayer) | 836 | void BackGammon::finished(int theplayer) |
835 | { | 837 | { |
836 | nomove_marker->hide(); | 838 | nomove_marker->hide(); |
837 | if(theplayer==1) | 839 | if(theplayer==1) |
838 | message->setText(tr( "<b>Player 1 wins. Click on board for new game.</b>" )); | 840 | message->setText(tr( "<b>Player 1 wins. Click on board for new game.</b>" )); |
839 | else | 841 | else |
840 | message->setText(tr( "<b>Player 2 wins. Click on board for new game.</b>" )); | 842 | message->setText(tr( "<b>Player 2 wins. Click on board for new game.</b>" )); |
841 | diceA1_value=7; | 843 | diceA1_value=7; |
842 | diceA2_value=7; | 844 | diceA2_value=7; |
843 | diceB1_value=7; | 845 | diceB1_value=7; |
844 | diceB2_value=7; | 846 | diceB2_value=7; |
845 | player=0; | 847 | player=0; |
846 | showdice(); | 848 | showdice(); |
847 | draw(); | 849 | draw(); |
848 | area->update(); | 850 | area->update(); |
849 | gameFinished=true; | 851 | gameFinished=true; |
850 | } | 852 | } |
851 | 853 | ||
852 | void BackGammon::showdice() | 854 | void BackGammon::showdice() |
853 | { | 855 | { |
854 | int value_diceA1=diceA1_value-1; | 856 | int value_diceA1=diceA1_value-1; |
855 | if(diceA1_value==7 && diceA3_value!=7) | 857 | if(diceA1_value==7 && diceA3_value!=7) |
856 | value_diceA1=diceA3_value-1; | 858 | value_diceA1=diceA3_value-1; |
857 | 859 | ||
858 | int value_diceA2=diceA2_value-1; | 860 | int value_diceA2=diceA2_value-1; |
859 | if(diceA2_value==7 && diceA4_value!=7) | 861 | if(diceA2_value==7 && diceA4_value!=7) |
860 | value_diceA2=diceA4_value-1; | 862 | value_diceA2=diceA4_value-1; |
861 | 863 | ||
862 | int value_diceB1=diceB1_value-1; | 864 | int value_diceB1=diceB1_value-1; |
863 | if(diceB1_value==7 && diceB3_value!=7) | 865 | if(diceB1_value==7 && diceB3_value!=7) |
864 | value_diceB1=diceB3_value-1; | 866 | value_diceB1=diceB3_value-1; |
865 | 867 | ||
866 | int value_diceB2=diceB2_value-1; | 868 | int value_diceB2=diceB2_value-1; |
867 | if(diceB2_value==7 && diceB4_value!=7) | 869 | if(diceB2_value==7 && diceB4_value!=7) |
868 | value_diceB2=diceB4_value-1; | 870 | value_diceB2=diceB4_value-1; |
869 | 871 | ||
870 | for(int index=0;index<7;index++) | 872 | for(int index=0;index<7;index++) |
871 | { | 873 | { |
872 | if(value_diceA1==index) | 874 | if(value_diceA1==index) |
873 | diceA1[index]->show(); | 875 | diceA1[index]->show(); |
874 | else | 876 | else |
875 | diceA1[index]->hide(); | 877 | diceA1[index]->hide(); |
876 | 878 | ||
877 | if(value_diceA2==index) | 879 | if(value_diceA2==index) |
878 | diceA2[index]->show(); | 880 | diceA2[index]->show(); |
879 | else | 881 | else |
880 | diceA2[index]->hide(); | 882 | diceA2[index]->hide(); |
881 | 883 | ||
882 | if(value_diceB1==index) | 884 | if(value_diceB1==index) |
883 | diceB1[index]->show(); | 885 | diceB1[index]->show(); |
884 | else | 886 | else |
885 | diceB1[index]->hide(); | 887 | diceB1[index]->hide(); |
886 | 888 | ||
887 | if(value_diceB2==index) | 889 | if(value_diceB2==index) |
888 | diceB2[index]->show(); | 890 | diceB2[index]->show(); |
889 | else | 891 | else |
890 | diceB2[index]->hide(); | 892 | diceB2[index]->hide(); |
891 | } | 893 | } |
892 | } | 894 | } |
893 | 895 | ||
894 | void BackGammon::setplayer() | 896 | void BackGammon::setplayer() |
895 | { | 897 | { |
896 | if(dice1_played && dice2_played && dice3_played && dice4_played && player==1) | 898 | if(dice1_played && dice2_played && dice3_played && dice4_played && player==1) |
897 | { | 899 | { |
898 | message->setText(tr( "<b>P2 turn</b>", "P means player" )); | 900 | message->setText(tr( "<b>P2 turn</b>", "P means player" )); |
899 | dice_rolled=false; | 901 | dice_rolled=false; |
900 | player=2; | 902 | player=2; |
901 | if(player2_auto) | 903 | if(player2_auto) |
902 | QTimer::singleShot(2000,this,SLOT(autoroll_dice2())); | 904 | QTimer::singleShot(2000,this,SLOT(autoroll_dice2())); |
903 | } | 905 | } |
904 | else if(dice1_played && dice2_played && dice3_played && dice4_played && player==2) | 906 | else if(dice1_played && dice2_played && dice3_played && dice4_played && player==2) |
905 | { | 907 | { |
906 | message->setText(tr( "<b>P1 turn</b>", "P means player" )); | 908 | message->setText(tr( "<b>P1 turn</b>", "P means player" )); |
907 | dice_rolled=false; | 909 | dice_rolled=false; |
908 | player=1; | 910 | player=1; |
909 | if(player1_auto) | 911 | if(player1_auto) |
910 | QTimer::singleShot(2000,this,SLOT(autoroll_dice1())); | 912 | QTimer::singleShot(2000,this,SLOT(autoroll_dice1())); |
911 | } | 913 | } |
912 | } | 914 | } |
913 | 915 | ||
914 | void BackGammon::autoroll_dice1() | 916 | void BackGammon::autoroll_dice1() |
915 | { | 917 | { |
916 | mouse(20,210); | 918 | mouse(20,210); |
917 | } | 919 | } |
918 | 920 | ||
919 | void BackGammon::autoroll_dice2() | 921 | void BackGammon::autoroll_dice2() |
920 | { | 922 | { |
921 | mouse(170,210); | 923 | mouse(170,210); |
922 | } | 924 | } |
923 | 925 | ||
924 | void BackGammon::applytheme() | 926 | void BackGammon::applytheme() |
925 | { | 927 | { |
926 | QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name)); | 928 | QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name)); |
927 | board->setImage(boardbg); | 929 | board->setImage(boardbg); |
928 | 930 | ||
929 | QImage tablebg(Resource::loadImage("backgammon/table/"+table_name)); | 931 | QImage tablebg(Resource::loadImage("backgammon/table/"+table_name)); |
930 | table->setImage(tablebg); | 932 | table->setImage(tablebg); |
931 | 933 | ||
932 | QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name)); | 934 | QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name)); |
933 | QImage piece_1_front=piece_1_all.copy(0,0,15,15); | 935 | QImage piece_1_front=piece_1_all.copy(0,0,15,15); |
934 | QImage piece_1_side=piece_1_all.copy(0,15,15,5); | 936 | QImage piece_1_side=piece_1_all.copy(0,15,15,5); |
935 | 937 | ||
936 | QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name)); | 938 | QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name)); |
937 | QImage piece_2_front=piece_2_all.copy(0,0,15,15); | 939 | QImage piece_2_front=piece_2_all.copy(0,0,15,15); |
938 | QImage piece_2_side=piece_2_all.copy(0,15,15,5); | 940 | QImage piece_2_side=piece_2_all.copy(0,15,15,5); |
939 | 941 | ||
940 | int a=0; | 942 | int a=0; |
941 | for(a=0;a<15;a++) | 943 | for(a=0;a<15;a++) |
942 | { | 944 | { |
943 | p1[a]->setImage(piece_1_front); | 945 | p1[a]->setImage(piece_1_front); |
944 | p1_side[a]->setImage(piece_1_side); | 946 | p1_side[a]->setImage(piece_1_side); |
945 | 947 | ||
946 | p2[a]->setImage(piece_2_front); | 948 | p2[a]->setImage(piece_2_front); |
947 | p2_side[a]->setImage(piece_2_side); | 949 | p2_side[a]->setImage(piece_2_side); |
948 | } | 950 | } |
949 | draw(); | 951 | draw(); |
950 | 952 | ||
951 | QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name)); | 953 | QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name)); |
952 | QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name)); | 954 | QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name)); |
953 | QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name)); | 955 | QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name)); |
954 | 956 | ||
955 | for(a=0;a<7;a++) | 957 | for(a=0;a<7;a++) |
956 | { | 958 | { |
957 | QImage dicebgA=dicebgA_all.copy(a*25,0,25,25); | 959 | QImage dicebgA=dicebgA_all.copy(a*25,0,25,25); |
958 | diceA1[a]->setImage(dicebgA); | 960 | diceA1[a]->setImage(dicebgA); |
959 | diceA2[a]->setImage(dicebgA); | 961 | diceA2[a]->setImage(dicebgA); |
960 | 962 | ||
961 | QImage dicebgB=dicebgB_all.copy(a*25,0,25,25); | 963 | QImage dicebgB=dicebgB_all.copy(a*25,0,25,25); |
962 | diceB1[a]->setImage(dicebgB); | 964 | diceB1[a]->setImage(dicebgB); |
963 | diceB2[a]->setImage(dicebgB); | 965 | diceB2[a]->setImage(dicebgB); |
964 | /* | 966 | /* |
965 | if(a<6) | 967 | if(a<6) |
966 | { | 968 | { |
967 | QImage oddsbg=oddsbg_all.copy(a*15,0,15,15); | 969 | QImage oddsbg=oddsbg_all.copy(a*15,0,15,15); |
968 | oddsDice[a]->setImage(oddsbg); | 970 | oddsDice[a]->setImage(oddsbg); |
969 | } | 971 | } |
970 | */ | 972 | */ |
971 | } | 973 | } |
972 | } | 974 | } |
973 | 975 | ||
974 | 976 | ||
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 |