-rw-r--r-- | noncore/games/backgammon/aidialog.cpp | 44 | ||||
-rw-r--r-- | noncore/games/backgammon/backgammon.cpp | 48 |
2 files changed, 46 insertions, 46 deletions
diff --git a/noncore/games/backgammon/aidialog.cpp b/noncore/games/backgammon/aidialog.cpp index 9642ca5..7dfe403 100644 --- a/noncore/games/backgammon/aidialog.cpp +++ b/noncore/games/backgammon/aidialog.cpp | |||
@@ -1,211 +1,211 @@ | |||
1 | #include "aidialog.h" | 1 | #include "aidialog.h" |
2 | 2 | ||
3 | #include <qgroupbox.h> | 3 | #include <qgroupbox.h> |
4 | 4 | ||
5 | 5 | ||
6 | AI_Dialog::AI_Dialog(QWidget* parent,const char* name,bool modal,WFlags f) | 6 | AI_Dialog::AI_Dialog(QWidget* parent,const char* name,bool modal,WFlags f) |
7 | : QDialog(parent,name,modal,f) | 7 | : QDialog(parent,name,modal,f) |
8 | { | 8 | { |
9 | setCaption("AI Configuration"); | 9 | setCaption("AI Configuration"); |
10 | 10 | ||
11 | QGroupBox* settings=new QGroupBox("Settings",this); | 11 | QGroupBox* settings=new QGroupBox(tr( "Settings" ),this); |
12 | settings->setGeometry(10,5,220,170); | 12 | settings->setGeometry(10,5,220,170); |
13 | 13 | ||
14 | QLabel* rescue_label=new QLabel("<b>Rescue</b>",settings); | 14 | QLabel* rescue_label=new QLabel(tr( "<b>Rescue</b>" ),settings); |
15 | rescue_label->setGeometry(50,20,50,20); | 15 | rescue_label->setGeometry(50,20,50,20); |
16 | rescue=new QSpinBox(0,6,1,settings); | 16 | rescue=new QSpinBox(0,6,1,settings); |
17 | rescue->setGeometry(100,20,40,20); | 17 | rescue->setGeometry(100,20,40,20); |
18 | QPushButton* rescuehelp=new QPushButton("?",settings); | 18 | QPushButton* rescuehelp=new QPushButton(tr( "?" ),settings); |
19 | rescuehelp->setGeometry(140,20,20,20); | 19 | rescuehelp->setGeometry(140,20,20,20); |
20 | connect(rescuehelp,SIGNAL(pressed()),this,SLOT(rescuehelp_pressed())); | 20 | connect(rescuehelp,SIGNAL(pressed()),this,SLOT(rescuehelp_pressed())); |
21 | connect(rescuehelp,SIGNAL(released()),this,SLOT(rescuehelp_released())); | 21 | connect(rescuehelp,SIGNAL(released()),this,SLOT(rescuehelp_released())); |
22 | 22 | ||
23 | QLabel* eliminate_label=new QLabel("<b>Eliminate</b>",settings); | 23 | QLabel* eliminate_label=new QLabel(tr( "<b>Eliminate</b>" ),settings); |
24 | eliminate_label->setGeometry(50,40,50,20); | 24 | eliminate_label->setGeometry(50,40,50,20); |
25 | eliminate=new QSpinBox(0,6,1,settings); | 25 | eliminate=new QSpinBox(0,6,1,settings); |
26 | eliminate->setGeometry(100,40,40,20); | 26 | eliminate->setGeometry(100,40,40,20); |
27 | QPushButton* eliminatehelp=new QPushButton("?",settings); | 27 | QPushButton* eliminatehelp=new QPushButton(tr( "?" ),settings); |
28 | eliminatehelp->setGeometry(140,40,20,20); | 28 | eliminatehelp->setGeometry(140,40,20,20); |
29 | connect(eliminatehelp,SIGNAL(pressed()),this,SLOT(eliminatehelp_pressed())); | 29 | connect(eliminatehelp,SIGNAL(pressed()),this,SLOT(eliminatehelp_pressed())); |
30 | connect(eliminatehelp,SIGNAL(released()),this,SLOT(eliminatehelp_released())); | 30 | connect(eliminatehelp,SIGNAL(released()),this,SLOT(eliminatehelp_released())); |
31 | 31 | ||
32 | QLabel* expose_label=new QLabel("<b>Expose</b>",settings); | 32 | QLabel* expose_label=new QLabel(tr( "<b>Expose</b>" ),settings); |
33 | expose_label->setGeometry(50,60,50,20); | 33 | expose_label->setGeometry(50,60,50,20); |
34 | expose=new QSpinBox(0,6,1,settings); | 34 | expose=new QSpinBox(0,6,1,settings); |
35 | expose->setGeometry(100,60,40,20); | 35 | expose->setGeometry(100,60,40,20); |
36 | QPushButton* exposeehelp=new QPushButton("?",settings); | 36 | QPushButton* exposeehelp=new QPushButton(tr( "?" ),settings); |
37 | exposeehelp->setGeometry(140,60,20,20); | 37 | exposeehelp->setGeometry(140,60,20,20); |
38 | connect(exposeehelp,SIGNAL(pressed()),this,SLOT(exposehelp_pressed())); | 38 | connect(exposeehelp,SIGNAL(pressed()),this,SLOT(exposehelp_pressed())); |
39 | connect(exposeehelp,SIGNAL(released()),this,SLOT(exposehelp_released())); | 39 | connect(exposeehelp,SIGNAL(released()),this,SLOT(exposehelp_released())); |
40 | 40 | ||
41 | QLabel* protect_label=new QLabel("<b>Protect</b>",settings); | 41 | QLabel* protect_label=new QLabel(tr( "<b>Protect</b>" ),settings); |
42 | protect_label->setGeometry(50,80,50,20); | 42 | protect_label->setGeometry(50,80,50,20); |
43 | protect=new QSpinBox(0,6,1,settings); | 43 | protect=new QSpinBox(0,6,1,settings); |
44 | protect->setGeometry(100,80,40,20); | 44 | protect->setGeometry(100,80,40,20); |
45 | QPushButton* protecthelp=new QPushButton("?",settings); | 45 | QPushButton* protecthelp=new QPushButton(tr( "?" ),settings); |
46 | protecthelp->setGeometry(140,80,20,20); | 46 | protecthelp->setGeometry(140,80,20,20); |
47 | connect(protecthelp,SIGNAL(pressed()),this,SLOT(protecthelp_pressed())); | 47 | connect(protecthelp,SIGNAL(pressed()),this,SLOT(protecthelp_pressed())); |
48 | connect(protecthelp,SIGNAL(released()),this,SLOT(protecthelp_released())); | 48 | connect(protecthelp,SIGNAL(released()),this,SLOT(protecthelp_released())); |
49 | 49 | ||
50 | QLabel* safe_label=new QLabel("<b>Safe</b>",settings); | 50 | QLabel* safe_label=new QLabel(tr( "<b>Safe</b>" ),settings); |
51 | safe_label->setGeometry(50,100,50,20); | 51 | safe_label->setGeometry(50,100,50,20); |
52 | safe=new QSpinBox(0,6,1,settings); | 52 | safe=new QSpinBox(0,6,1,settings); |
53 | safe->setGeometry(100,100,40,20); | 53 | safe->setGeometry(100,100,40,20); |
54 | QPushButton* safeehelp=new QPushButton("?",settings); | 54 | QPushButton* safeehelp=new QPushButton(tr( "?" ),settings); |
55 | safeehelp->setGeometry(140,100,20,20); | 55 | safeehelp->setGeometry(140,100,20,20); |
56 | connect(safeehelp,SIGNAL(pressed()),this,SLOT(safehelp_pressed())); | 56 | connect(safeehelp,SIGNAL(pressed()),this,SLOT(safehelp_pressed())); |
57 | connect(safeehelp,SIGNAL(released()),this,SLOT(safehelp_released())); | 57 | connect(safeehelp,SIGNAL(released()),this,SLOT(safehelp_released())); |
58 | 58 | ||
59 | QLabel* empty_label=new QLabel("<b>Empty</b>",settings); | 59 | QLabel* empty_label=new QLabel(tr( "<b>Empty</b>" ),settings); |
60 | empty_label->setGeometry(50,120,50,20); | 60 | empty_label->setGeometry(50,120,50,20); |
61 | empty=new QSpinBox(0,6,1,settings); | 61 | empty=new QSpinBox(0,6,1,settings); |
62 | empty->setGeometry(100,120,40,20); | 62 | empty->setGeometry(100,120,40,20); |
63 | QPushButton* emptyhelp=new QPushButton("?",settings); | 63 | QPushButton* emptyhelp=new QPushButton(tr( "?" ),settings); |
64 | emptyhelp->setGeometry(140,120,20,20); | 64 | emptyhelp->setGeometry(140,120,20,20); |
65 | connect(emptyhelp,SIGNAL(pressed()),this,SLOT(emptyhelp_pressed())); | 65 | connect(emptyhelp,SIGNAL(pressed()),this,SLOT(emptyhelp_pressed())); |
66 | connect(emptyhelp,SIGNAL(released()),this,SLOT(emptyhelp_released())); | 66 | connect(emptyhelp,SIGNAL(released()),this,SLOT(emptyhelp_released())); |
67 | 67 | ||
68 | defaultvalues=new QPushButton("Default Values",settings); | 68 | defaultvalues=new QPushButton(tr( "Default Values" ),settings); |
69 | defaultvalues->setGeometry(60,140,90,20); | 69 | defaultvalues->setGeometry(60,140,90,20); |
70 | connect(defaultvalues,SIGNAL(clicked()),this,SLOT(setDefaultValues())); | 70 | connect(defaultvalues,SIGNAL(clicked()),this,SLOT(setDefaultValues())); |
71 | 71 | ||
72 | QGroupBox* helpbox=new QGroupBox("Help",this); | 72 | QGroupBox* helpbox=new QGroupBox(tr( "Help" ),this); |
73 | helpbox->setGeometry(10,185,220,90); | 73 | helpbox->setGeometry(10,185,220,90); |
74 | 74 | ||
75 | help=new QLabel(helpbox); | 75 | help=new QLabel(helpbox); |
76 | help->setGeometry(10,15,200,65); | 76 | help->setGeometry(10,15,200,65); |
77 | 77 | ||
78 | setHelpText(); | 78 | setHelpText(); |
79 | showMaximized(); | 79 | showMaximized(); |
80 | } | 80 | } |
81 | 81 | ||
82 | 82 | ||
83 | AI_Dialog::~AI_Dialog() | 83 | AI_Dialog::~AI_Dialog() |
84 | { | 84 | { |
85 | } | 85 | } |
86 | 86 | ||
87 | void AI_Dialog::rescuehelp_pressed() | 87 | void AI_Dialog::rescuehelp_pressed() |
88 | { | 88 | { |
89 | setHelpText("rescue"); | 89 | setHelpText("rescue"); |
90 | } | 90 | } |
91 | 91 | ||
92 | void AI_Dialog::rescuehelp_released() | 92 | void AI_Dialog::rescuehelp_released() |
93 | { | 93 | { |
94 | setHelpText(); | 94 | setHelpText(); |
95 | } | 95 | } |
96 | 96 | ||
97 | void AI_Dialog::eliminatehelp_pressed() | 97 | void AI_Dialog::eliminatehelp_pressed() |
98 | { | 98 | { |
99 | setHelpText("eliminate"); | 99 | setHelpText("eliminate"); |
100 | } | 100 | } |
101 | 101 | ||
102 | void AI_Dialog::eliminatehelp_released() | 102 | void AI_Dialog::eliminatehelp_released() |
103 | { | 103 | { |
104 | setHelpText(); | 104 | setHelpText(); |
105 | } | 105 | } |
106 | 106 | ||
107 | void AI_Dialog::exposehelp_pressed() | 107 | void AI_Dialog::exposehelp_pressed() |
108 | { | 108 | { |
109 | setHelpText("expose"); | 109 | setHelpText("expose"); |
110 | } | 110 | } |
111 | 111 | ||
112 | void AI_Dialog::exposehelp_released() | 112 | void AI_Dialog::exposehelp_released() |
113 | { | 113 | { |
114 | setHelpText(); | 114 | setHelpText(); |
115 | } | 115 | } |
116 | 116 | ||
117 | void AI_Dialog::protecthelp_pressed() | 117 | void AI_Dialog::protecthelp_pressed() |
118 | { | 118 | { |
119 | setHelpText("protect"); | 119 | setHelpText("protect"); |
120 | } | 120 | } |
121 | 121 | ||
122 | void AI_Dialog::protecthelp_released() | 122 | void AI_Dialog::protecthelp_released() |
123 | { | 123 | { |
124 | setHelpText(); | 124 | setHelpText(); |
125 | } | 125 | } |
126 | 126 | ||
127 | void AI_Dialog::safehelp_pressed() | 127 | void AI_Dialog::safehelp_pressed() |
128 | { | 128 | { |
129 | setHelpText("safe"); | 129 | setHelpText("safe"); |
130 | } | 130 | } |
131 | 131 | ||
132 | void AI_Dialog::safehelp_released() | 132 | void AI_Dialog::safehelp_released() |
133 | { | 133 | { |
134 | setHelpText(); | 134 | setHelpText(); |
135 | } | 135 | } |
136 | 136 | ||
137 | void AI_Dialog::emptyhelp_pressed() | 137 | void AI_Dialog::emptyhelp_pressed() |
138 | { | 138 | { |
139 | setHelpText("empty"); | 139 | setHelpText("empty"); |
140 | } | 140 | } |
141 | 141 | ||
142 | void AI_Dialog::emptyhelp_released() | 142 | void AI_Dialog::emptyhelp_released() |
143 | { | 143 | { |
144 | setHelpText(); | 144 | setHelpText(); |
145 | } | 145 | } |
146 | 146 | ||
147 | 147 | ||
148 | 148 | ||
149 | void AI_Dialog::setDefaultValues() | 149 | void AI_Dialog::setDefaultValues() |
150 | { | 150 | { |
151 | rescue->setValue(6); | 151 | rescue->setValue(6); |
152 | eliminate->setValue(4); | 152 | eliminate->setValue(4); |
153 | expose->setValue(1); | 153 | expose->setValue(1); |
154 | protect->setValue(5); | 154 | protect->setValue(5); |
155 | safe->setValue(3); | 155 | safe->setValue(3); |
156 | empty->setValue(2); | 156 | empty->setValue(2); |
157 | } | 157 | } |
158 | 158 | ||
159 | void AI_Dialog::setAISettings(const AISettings& values) | 159 | void AI_Dialog::setAISettings(const AISettings& values) |
160 | { | 160 | { |
161 | rescue->setValue(values.rescue); | 161 | rescue->setValue(values.rescue); |
162 | eliminate->setValue(values.eliminate); | 162 | eliminate->setValue(values.eliminate); |
163 | expose->setValue(values.expose); | 163 | expose->setValue(values.expose); |
164 | protect->setValue(values.protect); | 164 | protect->setValue(values.protect); |
165 | safe->setValue(values.safe); | 165 | safe->setValue(values.safe); |
166 | empty->setValue(values.empty); | 166 | empty->setValue(values.empty); |
167 | } | 167 | } |
168 | 168 | ||
169 | AISettings AI_Dialog::getAISettings() | 169 | AISettings AI_Dialog::getAISettings() |
170 | { | 170 | { |
171 | AISettings ai; | 171 | AISettings ai; |
172 | ai.rescue=rescue->value(); | 172 | ai.rescue=rescue->value(); |
173 | ai.eliminate=eliminate->value(); | 173 | ai.eliminate=eliminate->value(); |
174 | ai.expose=expose->value(); | 174 | ai.expose=expose->value(); |
175 | ai.protect=protect->value(); | 175 | ai.protect=protect->value(); |
176 | ai.safe= safe->value(); | 176 | ai.safe= safe->value(); |
177 | ai.empty=empty->value(); | 177 | ai.empty=empty->value(); |
178 | return ai; | 178 | return ai; |
179 | } | 179 | } |
180 | 180 | ||
181 | void AI_Dialog::setHelpText(const QString& type) | 181 | void AI_Dialog::setHelpText(const QString& type) |
182 | { | 182 | { |
183 | if(type=="rescue") | 183 | if(type=="rescue") |
184 | { | 184 | { |
185 | help->setText("Bring the pieces out of the endzone"); | 185 | help->setText(tr( "Bring the pieces out of the endzone" )); |
186 | } | 186 | } |
187 | else if(type=="eliminate") | 187 | else if(type=="eliminate") |
188 | { | 188 | { |
189 | help->setText("Eliminate an opponents piece"); | 189 | help->setText(tr( "Eliminate an opponents piece" )); |
190 | } | 190 | } |
191 | else if(type=="expose") | 191 | else if(type=="expose") |
192 | { | 192 | { |
193 | help->setText("Expose you own pieces.\nAfter such a move only one piece will remain in the slot"); | 193 | help->setText(tr( "Expose you own pieces.\nAfter such a move only one piece will remain in the slot") ); |
194 | } | 194 | } |
195 | else if(type=="protect") | 195 | else if(type=="protect") |
196 | { | 196 | { |
197 | help->setText("Protect a single piece by\nputting another one in this slot"); | 197 | help->setText(tr( "Protect a single piece by\nputting another one in this slot" )); |
198 | } | 198 | } |
199 | else if(type=="safe") | 199 | else if(type=="safe") |
200 | { | 200 | { |
201 | help->setText("Move piece to a slot already\noccupied by the player"); | 201 | help->setText(tr( "Move piece to a slot already\noccupied by the player" )); |
202 | } | 202 | } |
203 | else if(type=="empty") | 203 | else if(type=="empty") |
204 | { | 204 | { |
205 | help->setText("Move piece to an empty slot"); | 205 | help->setText(tr( "Move piece to an empty slot") ); |
206 | } | 206 | } |
207 | else | 207 | else |
208 | { | 208 | { |
209 | help->setText("Press and hold the ? buttton\nnext to a field for help"); | 209 | help->setText(tr( "Press and hold the ? buttton\nnext to a field for help") ); |
210 | } | 210 | } |
211 | } | 211 | } |
diff --git a/noncore/games/backgammon/backgammon.cpp b/noncore/games/backgammon/backgammon.cpp index c40f462..06523f1 100644 --- a/noncore/games/backgammon/backgammon.cpp +++ b/noncore/games/backgammon/backgammon.cpp | |||
@@ -1,974 +1,974 @@ | |||
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("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("New",this,SLOT(newgame())); | 108 | gamemenu->insertItem(tr( "New" ),this,SLOT(newgame())); |
109 | gamemenu->insertSeparator(); | 109 | gamemenu->insertSeparator(); |
110 | gamemenu->insertItem("Load",this,SLOT(loadgame())); | 110 | gamemenu->insertItem(tr( "Load" ),this,SLOT(loadgame())); |
111 | gamemenu->insertItem("Save",this,SLOT(savegame())); | 111 | gamemenu->insertItem(tr( "Save" ),this,SLOT(savegame())); |
112 | gamemenu->insertSeparator(); | 112 | gamemenu->insertSeparator(); |
113 | gamemenu->insertItem("Delete",this,SLOT(deletegame())); | 113 | gamemenu->insertItem(tr( "Delete" ),this,SLOT(deletegame())); |
114 | menuBar->insertItem("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("New",this,SLOT(newtheme())); | 117 | thememenu->insertItem(tr( "New" ),this,SLOT(newtheme())); |
118 | thememenu->insertSeparator(); | 118 | thememenu->insertSeparator(); |
119 | thememenu->insertItem("Load",this,SLOT(loadtheme())); | 119 | thememenu->insertItem(tr( "Load"),this,SLOT(loadtheme())); |
120 | thememenu->insertItem("Save",this,SLOT(savetheme())); | 120 | thememenu->insertItem(tr( "Save" ),this,SLOT(savetheme())); |
121 | thememenu->insertSeparator(); | 121 | thememenu->insertSeparator(); |
122 | thememenu->insertItem("Default",this,SLOT(themedefault())); | 122 | thememenu->insertItem(tr( "Default"),this,SLOT(themedefault())); |
123 | thememenu->insertItem("Delete",this,SLOT(deletetheme())); | 123 | thememenu->insertItem(tr( "Delete" ),this,SLOT(deletetheme())); |
124 | menuBar->insertItem("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("Player",this,SLOT(playerselect())); | 127 | optionmenu->insertItem(tr( "Player" ),this,SLOT(playerselect())); |
128 | optionmenu->insertSeparator(); | 128 | optionmenu->insertSeparator(); |
129 | optionmenu->insertItem("AI",this,SLOT(modify_AI())); | 129 | optionmenu->insertItem(tr( "AI" ),this,SLOT(modify_AI())); |
130 | optionmenu->insertItem("Rules",this,SLOT(setrules())); | 130 | optionmenu->insertItem(tr( "Rules" ),this,SLOT(setrules())); |
131 | menuBar->insertItem("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 | boardview=new BackGammonView(area,mainarea); | 138 | boardview=new BackGammonView(area,mainarea); |
139 | boardview->setMaximumHeight(240); | 139 | boardview->setMaximumHeight(240); |
140 | layout->addWidget(boardview); | 140 | layout->addWidget(boardview); |
141 | connect(boardview,SIGNAL(mouse(int,int)),this,SLOT(mouse(int,int))); | 141 | connect(boardview,SIGNAL(mouse(int,int)),this,SLOT(mouse(int,int))); |
142 | //status bar | 142 | //status bar |
143 | message=new QLabel("<b>Backgammon</b>",mainarea); | 143 | message=new QLabel("<b>Backgammon</b>",mainarea); |
144 | message->setAlignment(AlignHCenter); | 144 | message->setAlignment(AlignHCenter); |
145 | layout->addWidget(message); | 145 | layout->addWidget(message); |
146 | 146 | ||
147 | //the marker | 147 | //the marker |
148 | marker_current=new QCanvasRectangle(area); | 148 | marker_current=new QCanvasRectangle(area); |
149 | marker_current->setBrush(QColor(0,0,255)); | 149 | marker_current->setBrush(QColor(0,0,255)); |
150 | marker_current->setSize(15,5); | 150 | marker_current->setSize(15,5); |
151 | marker_current->setZ(1); | 151 | marker_current->setZ(1); |
152 | 152 | ||
153 | for(a=0;a<4;a++) | 153 | for(a=0;a<4;a++) |
154 | { | 154 | { |
155 | marker_next[a]=new QCanvasRectangle(area); | 155 | marker_next[a]=new QCanvasRectangle(area); |
156 | marker_next[a]->setBrush(QColor(0,255,0)); | 156 | marker_next[a]->setBrush(QColor(0,255,0)); |
157 | marker_next[a]->setSize(15,5); | 157 | marker_next[a]->setSize(15,5); |
158 | marker_next[a]->setZ(1); | 158 | marker_next[a]->setZ(1); |
159 | } | 159 | } |
160 | 160 | ||
161 | connect(move,SIGNAL(done_dice1()),this,SLOT(done_dice1())); | 161 | connect(move,SIGNAL(done_dice1()),this,SLOT(done_dice1())); |
162 | connect(move,SIGNAL(done_dice2()),this,SLOT(done_dice2())); | 162 | connect(move,SIGNAL(done_dice2()),this,SLOT(done_dice2())); |
163 | connect(move,SIGNAL(done_dice3()),this,SLOT(done_dice3())); | 163 | connect(move,SIGNAL(done_dice3()),this,SLOT(done_dice3())); |
164 | connect(move,SIGNAL(done_dice4()),this,SLOT(done_dice4())); | 164 | connect(move,SIGNAL(done_dice4()),this,SLOT(done_dice4())); |
165 | connect(move,SIGNAL(nomove()),this,SLOT(nomove())); | 165 | connect(move,SIGNAL(nomove()),this,SLOT(nomove())); |
166 | connect(move,SIGNAL(player_finished(int)),this,SLOT(finished(int))); | 166 | connect(move,SIGNAL(player_finished(int)),this,SLOT(finished(int))); |
167 | 167 | ||
168 | //the pieces | 168 | //the pieces |
169 | p1=new CanvasImageItem*[15]; | 169 | p1=new CanvasImageItem*[15]; |
170 | p1_side=new CanvasImageItem*[15]; | 170 | p1_side=new CanvasImageItem*[15]; |
171 | QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name)); | 171 | QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name)); |
172 | QImage piece_1_front=piece_1_all.copy(0,0,15,15); | 172 | QImage piece_1_front=piece_1_all.copy(0,0,15,15); |
173 | QImage piece_1_side=piece_1_all.copy(0,15,15,5); | 173 | QImage piece_1_side=piece_1_all.copy(0,15,15,5); |
174 | 174 | ||
175 | p2=new CanvasImageItem*[15]; | 175 | p2=new CanvasImageItem*[15]; |
176 | p2_side=new CanvasImageItem*[15]; | 176 | p2_side=new CanvasImageItem*[15]; |
177 | QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name)); | 177 | QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name)); |
178 | QImage piece_2_front=piece_2_all.copy(0,0,15,15); | 178 | QImage piece_2_front=piece_2_all.copy(0,0,15,15); |
179 | QImage piece_2_side=piece_2_all.copy(0,15,15,5); | 179 | QImage piece_2_side=piece_2_all.copy(0,15,15,5); |
180 | 180 | ||
181 | 181 | ||
182 | for(a=0;a<15;a++) | 182 | for(a=0;a<15;a++) |
183 | { | 183 | { |
184 | p1[a]=new CanvasImageItem(piece_1_front,area); | 184 | p1[a]=new CanvasImageItem(piece_1_front,area); |
185 | p1[a]->setSize(15,15); | 185 | p1[a]->setSize(15,15); |
186 | p1_side[a]=new CanvasImageItem(piece_1_side,area); | 186 | p1_side[a]=new CanvasImageItem(piece_1_side,area); |
187 | p1_side[a]->setSize(15,5); | 187 | p1_side[a]->setSize(15,5); |
188 | 188 | ||
189 | p2[a]=new CanvasImageItem(piece_2_front,area); | 189 | p2[a]=new CanvasImageItem(piece_2_front,area); |
190 | p2[a]->setSize(15,15); | 190 | p2[a]->setSize(15,15); |
191 | p2_side[a]=new CanvasImageItem(piece_2_side,area); | 191 | p2_side[a]=new CanvasImageItem(piece_2_side,area); |
192 | p2_side[a]->setSize(15,5); | 192 | p2_side[a]->setSize(15,5); |
193 | } | 193 | } |
194 | draw(); | 194 | draw(); |
195 | 195 | ||
196 | //the dice | 196 | //the dice |
197 | QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name)); | 197 | QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name)); |
198 | diceA1=new CanvasImageItem*[7]; | 198 | diceA1=new CanvasImageItem*[7]; |
199 | diceA2=new CanvasImageItem*[7]; | 199 | diceA2=new CanvasImageItem*[7]; |
200 | QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name)); | 200 | QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name)); |
201 | diceB1=new CanvasImageItem*[7]; | 201 | diceB1=new CanvasImageItem*[7]; |
202 | diceB2=new CanvasImageItem*[7]; | 202 | diceB2=new CanvasImageItem*[7]; |
203 | QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name)); | 203 | QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name)); |
204 | //oddsDice=new CanvasImageItem*[6]; | 204 | //oddsDice=new CanvasImageItem*[6]; |
205 | 205 | ||
206 | 206 | ||
207 | for(a=0;a<7;a++) | 207 | for(a=0;a<7;a++) |
208 | { | 208 | { |
209 | QImage dicebgA=dicebgA_all.copy(a*25,0,25,25); | 209 | QImage dicebgA=dicebgA_all.copy(a*25,0,25,25); |
210 | diceA1[a]=new CanvasImageItem(dicebgA,area); | 210 | diceA1[a]=new CanvasImageItem(dicebgA,area); |
211 | diceA1[a]->setX(5); | 211 | diceA1[a]->setX(5); |
212 | diceA1[a]->setY(205-2); | 212 | diceA1[a]->setY(205-2); |
213 | diceA1[a]->setZ(1); | 213 | diceA1[a]->setZ(1); |
214 | diceA1[a]->setSize(25,25); | 214 | diceA1[a]->setSize(25,25); |
215 | diceA2[a]=new CanvasImageItem(dicebgA,area); | 215 | diceA2[a]=new CanvasImageItem(dicebgA,area); |
216 | diceA2[a]->setX(35); | 216 | diceA2[a]->setX(35); |
217 | diceA2[a]->setY(205-2); | 217 | diceA2[a]->setY(205-2); |
218 | diceA2[a]->setZ(1); | 218 | diceA2[a]->setZ(1); |
219 | diceA2[a]->setSize(25,25); | 219 | diceA2[a]->setSize(25,25); |
220 | 220 | ||
221 | QImage dicebgB=dicebgB_all.copy(a*25,0,25,25); | 221 | QImage dicebgB=dicebgB_all.copy(a*25,0,25,25); |
222 | diceB1[a]=new CanvasImageItem(dicebgB,area); | 222 | diceB1[a]=new CanvasImageItem(dicebgB,area); |
223 | diceB1[a]->setX(175); | 223 | diceB1[a]->setX(175); |
224 | diceB1[a]->setY(205-2); | 224 | diceB1[a]->setY(205-2); |
225 | diceB1[a]->setZ(1); | 225 | diceB1[a]->setZ(1); |
226 | diceB1[a]->setSize(25,25); | 226 | diceB1[a]->setSize(25,25); |
227 | diceB2[a]=new CanvasImageItem(dicebgB,area); | 227 | diceB2[a]=new CanvasImageItem(dicebgB,area); |
228 | diceB2[a]->setX(205); | 228 | diceB2[a]->setX(205); |
229 | diceB2[a]->setY(205-2); | 229 | diceB2[a]->setY(205-2); |
230 | diceB2[a]->setZ(1); | 230 | diceB2[a]->setZ(1); |
231 | diceB2[a]->setSize(25,25); | 231 | diceB2[a]->setSize(25,25); |
232 | 232 | ||
233 | /* | 233 | /* |
234 | if(a<6) | 234 | if(a<6) |
235 | { | 235 | { |
236 | QImage oddsbg=oddsbg_all.copy(a*15,0,15,15); | 236 | QImage oddsbg=oddsbg_all.copy(a*15,0,15,15); |
237 | oddsDice[a]=new CanvasImageItem(oddsbg,area); | 237 | oddsDice[a]=new CanvasImageItem(oddsbg,area); |
238 | oddsDice[a]->setX(110); | 238 | oddsDice[a]->setX(110); |
239 | oddsDice[a]->setY(210-2); | 239 | oddsDice[a]->setY(210-2); |
240 | oddsDice[a]->setZ(1); | 240 | oddsDice[a]->setZ(1); |
241 | oddsDice[a]->setSize(15,15); | 241 | oddsDice[a]->setSize(15,15); |
242 | oddsDice[a]->hide(); | 242 | oddsDice[a]->hide(); |
243 | } | 243 | } |
244 | */ | 244 | */ |
245 | } | 245 | } |
246 | //oddsDice[0]->show(); | 246 | //oddsDice[0]->show(); |
247 | 247 | ||
248 | //set the board | 248 | //set the board |
249 | QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name)); | 249 | QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name)); |
250 | board=new CanvasImageItem(boardbg,area); | 250 | board=new CanvasImageItem(boardbg,area); |
251 | board->setX(0); | 251 | board->setX(0); |
252 | board->setY(0); | 252 | board->setY(0); |
253 | board->setZ(0); | 253 | board->setZ(0); |
254 | board->setSize(235-2,200-2); | 254 | board->setSize(235-2,200-2); |
255 | board->show(); | 255 | board->show(); |
256 | 256 | ||
257 | //the table | 257 | //the table |
258 | QImage tablebg(Resource::loadImage("backgammon/table/"+table_name)); | 258 | QImage tablebg(Resource::loadImage("backgammon/table/"+table_name)); |
259 | table=new CanvasImageItem(tablebg,area); | 259 | table=new CanvasImageItem(tablebg,area); |
260 | table->setX(0); | 260 | table->setX(0); |
261 | table->setY(200-2); | 261 | table->setY(200-2); |
262 | table->setZ(0); | 262 | table->setZ(0); |
263 | table->setSize(235-2,20); | 263 | table->setSize(235-2,20); |
264 | table->show(); | 264 | table->show(); |
265 | 265 | ||
266 | //the no move marker | 266 | //the no move marker |
267 | QImage nomovebg(Resource::loadImage("backgammon/no_move")); | 267 | QImage nomovebg(Resource::loadImage("backgammon/no_move")); |
268 | nomove_marker=new CanvasImageItem(nomovebg,area); | 268 | nomove_marker=new CanvasImageItem(nomovebg,area); |
269 | nomove_marker->setX(0); | 269 | nomove_marker->setX(0); |
270 | nomove_marker->setY(200); | 270 | nomove_marker->setY(200); |
271 | nomove_marker->setZ(2); | 271 | nomove_marker->setZ(2); |
272 | nomove_marker->hide(); | 272 | nomove_marker->hide(); |
273 | 273 | ||
274 | //default human against computer | 274 | //default human against computer |
275 | player1_auto=false; | 275 | player1_auto=false; |
276 | player2_auto=true; | 276 | player2_auto=true; |
277 | //start new game | 277 | //start new game |
278 | newgame(); | 278 | newgame(); |
279 | } | 279 | } |
280 | 280 | ||
281 | BackGammon::~BackGammon() | 281 | BackGammon::~BackGammon() |
282 | { | 282 | { |
283 | //DESTRUCTOR | 283 | //DESTRUCTOR |
284 | } | 284 | } |
285 | 285 | ||
286 | void BackGammon::newgame() | 286 | void BackGammon::newgame() |
287 | { | 287 | { |
288 | gameFinished=false; | 288 | gameFinished=false; |
289 | QDateTime now=QDateTime::currentDateTime(); | 289 | QDateTime now=QDateTime::currentDateTime(); |
290 | game_name=now.date().toString()+"_"+now.time().toString(); | 290 | game_name=now.date().toString()+"_"+now.time().toString(); |
291 | move->reset(); | 291 | move->reset(); |
292 | draw(); | 292 | draw(); |
293 | diceA1_value=7; | 293 | diceA1_value=7; |
294 | diceA2_value=7; | 294 | diceA2_value=7; |
295 | diceA3_value=7; | 295 | diceA3_value=7; |
296 | diceA4_value=7; | 296 | diceA4_value=7; |
297 | diceB1_value=7; | 297 | diceB1_value=7; |
298 | diceB2_value=7; | 298 | diceB2_value=7; |
299 | diceB3_value=7; | 299 | diceB3_value=7; |
300 | diceB4_value=7; | 300 | diceB4_value=7; |
301 | showdice(); | 301 | showdice(); |
302 | player=2; | 302 | player=2; |
303 | dice1_played=true; | 303 | dice1_played=true; |
304 | dice2_played=true; | 304 | dice2_played=true; |
305 | dice3_played=true; | 305 | dice3_played=true; |
306 | dice4_played=true; | 306 | dice4_played=true; |
307 | dice_rolled=false; | 307 | dice_rolled=false; |
308 | setplayer(); | 308 | setplayer(); |
309 | area->update(); | 309 | area->update(); |
310 | } | 310 | } |
311 | 311 | ||
312 | void BackGammon::playerselect() | 312 | void BackGammon::playerselect() |
313 | { | 313 | { |
314 | PlayerDialog* playerdialog=new PlayerDialog(this); | 314 | PlayerDialog* playerdialog=new PlayerDialog(this); |
315 | playerdialog->setAuto1(player1_auto); | 315 | playerdialog->setAuto1(player1_auto); |
316 | playerdialog->setAuto2(player2_auto); | 316 | playerdialog->setAuto2(player2_auto); |
317 | if(!playerdialog->exec()) | 317 | if(!playerdialog->exec()) |
318 | return; | 318 | return; |
319 | player1_auto=playerdialog->getAuto1(); | 319 | player1_auto=playerdialog->getAuto1(); |
320 | player2_auto=playerdialog->getAuto2(); | 320 | player2_auto=playerdialog->getAuto2(); |
321 | } | 321 | } |
322 | 322 | ||
323 | void BackGammon::loadgame() | 323 | void BackGammon::loadgame() |
324 | { | 324 | { |
325 | FileDialog* file=new FileDialog(this,"Load Game",".game"); | 325 | FileDialog* file=new FileDialog(this,"Load Game",".game"); |
326 | if(!file->exec()) | 326 | if(!file->exec()) |
327 | return; | 327 | return; |
328 | 328 | ||
329 | game_name=file->filename(); | 329 | game_name=file->filename(); |
330 | QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; | 330 | QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; |
331 | 331 | ||
332 | Config game(game_file,Config::File); | 332 | Config game(game_file,Config::File); |
333 | game.setGroup("dice"); | 333 | game.setGroup("dice"); |
334 | diceA1_value=game.readNumEntry("diceA1_value"); | 334 | diceA1_value=game.readNumEntry("diceA1_value"); |
335 | diceA2_value=game.readNumEntry("diceA2_value"); | 335 | diceA2_value=game.readNumEntry("diceA2_value"); |
336 | diceA3_value=game.readNumEntry("diceA3_value"); | 336 | diceA3_value=game.readNumEntry("diceA3_value"); |
337 | diceA4_value=game.readNumEntry("diceA4_value"); | 337 | diceA4_value=game.readNumEntry("diceA4_value"); |
338 | diceB1_value=game.readNumEntry("diceB1_value"); | 338 | diceB1_value=game.readNumEntry("diceB1_value"); |
339 | diceB2_value=game.readNumEntry("diceB2_value"); | 339 | diceB2_value=game.readNumEntry("diceB2_value"); |
340 | diceB3_value=game.readNumEntry("diceB3_value"); | 340 | diceB3_value=game.readNumEntry("diceB3_value"); |
341 | diceB4_value=game.readNumEntry("diceB4_value"); | 341 | diceB4_value=game.readNumEntry("diceB4_value"); |
342 | player=game.readNumEntry("player"); | 342 | player=game.readNumEntry("player"); |
343 | dice1_played=game.readBoolEntry("dice1_played"); | 343 | dice1_played=game.readBoolEntry("dice1_played"); |
344 | dice2_played=game.readBoolEntry("dice2_played"); | 344 | dice2_played=game.readBoolEntry("dice2_played"); |
345 | dice3_played=game.readBoolEntry("dice3_played"); | 345 | dice3_played=game.readBoolEntry("dice3_played"); |
346 | dice4_played=game.readBoolEntry("dice4_played"); | 346 | dice4_played=game.readBoolEntry("dice4_played"); |
347 | dice_rolled=game.readBoolEntry("dice_rolled"); | 347 | dice_rolled=game.readBoolEntry("dice_rolled"); |
348 | player1_auto=game.readBoolEntry("player1_auto"); | 348 | player1_auto=game.readBoolEntry("player1_auto"); |
349 | player2_auto=game.readBoolEntry("player2_auto"); | 349 | player2_auto=game.readBoolEntry("player2_auto"); |
350 | 350 | ||
351 | game.setGroup("pieces"); | 351 | game.setGroup("pieces"); |
352 | QString label; | 352 | QString label; |
353 | LoadSave load; | 353 | LoadSave load; |
354 | for(int a=0;a<28;a++) | 354 | for(int a=0;a<28;a++) |
355 | { | 355 | { |
356 | label.setNum(a); | 356 | label.setNum(a); |
357 | load.pop[a].total = game.readNumEntry(label,0); | 357 | load.pop[a].total = game.readNumEntry(label,0); |
358 | } | 358 | } |
359 | 359 | ||
360 | move->loadGame(load); | 360 | move->loadGame(load); |
361 | setplayer(); | 361 | setplayer(); |
362 | showdice(); | 362 | showdice(); |
363 | draw(); | 363 | draw(); |
364 | area->update(); | 364 | area->update(); |
365 | } | 365 | } |
366 | 366 | ||
367 | void BackGammon::savegame() | 367 | void BackGammon::savegame() |
368 | { | 368 | { |
369 | QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; | 369 | QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; |
370 | 370 | ||
371 | Config game(game_file,Config::File); | 371 | Config game(game_file,Config::File); |
372 | game.setGroup("dice"); | 372 | game.setGroup("dice"); |
373 | game.writeEntry("diceA1_value",diceA1_value); | 373 | game.writeEntry("diceA1_value",diceA1_value); |
374 | game.writeEntry("diceA2_value",diceA2_value); | 374 | game.writeEntry("diceA2_value",diceA2_value); |
375 | game.writeEntry("diceA3_value",diceA3_value); | 375 | game.writeEntry("diceA3_value",diceA3_value); |
376 | game.writeEntry("diceA4_value",diceA4_value); | 376 | game.writeEntry("diceA4_value",diceA4_value); |
377 | game.writeEntry("diceB1_value",diceB1_value); | 377 | game.writeEntry("diceB1_value",diceB1_value); |
378 | game.writeEntry("diceB2_value",diceB3_value); | 378 | game.writeEntry("diceB2_value",diceB3_value); |
379 | game.writeEntry("diceB3_value",diceB4_value); | 379 | game.writeEntry("diceB3_value",diceB4_value); |
380 | game.writeEntry("diceB4_value",diceB4_value); | 380 | game.writeEntry("diceB4_value",diceB4_value); |
381 | game.writeEntry("player",player); | 381 | game.writeEntry("player",player); |
382 | game.writeEntry("dice1_played",dice1_played); | 382 | game.writeEntry("dice1_played",dice1_played); |
383 | game.writeEntry("dice2_played",dice2_played); | 383 | game.writeEntry("dice2_played",dice2_played); |
384 | game.writeEntry("dice3_played",dice3_played); | 384 | game.writeEntry("dice3_played",dice3_played); |
385 | game.writeEntry("dice4_played",dice4_played); | 385 | game.writeEntry("dice4_played",dice4_played); |
386 | game.writeEntry("dice_rolled",dice_rolled); | 386 | game.writeEntry("dice_rolled",dice_rolled); |
387 | game.writeEntry("player1_auto",player1_auto); | 387 | game.writeEntry("player1_auto",player1_auto); |
388 | game.writeEntry("player2_auto",player2_auto); | 388 | game.writeEntry("player2_auto",player2_auto); |
389 | 389 | ||
390 | game.setGroup("pieces"); | 390 | game.setGroup("pieces"); |
391 | QString label; | 391 | QString label; |
392 | LoadSave save=move->saveGame(); | 392 | LoadSave save=move->saveGame(); |
393 | for(int a=0;a<28;a++) | 393 | for(int a=0;a<28;a++) |
394 | { | 394 | { |
395 | label.setNum(a); | 395 | label.setNum(a); |
396 | game.writeEntry(label,save.pop[a].total); | 396 | game.writeEntry(label,save.pop[a].total); |
397 | } | 397 | } |
398 | QMessageBox::information(this,"Backgammon","Game saved","OK"); | 398 | QMessageBox::information(this,"Backgammon","Game saved","OK"); |
399 | } | 399 | } |
400 | 400 | ||
401 | void BackGammon::deletegame() | 401 | void BackGammon::deletegame() |
402 | { | 402 | { |
403 | FileDialog* file=new FileDialog(this,"Delete Game",".game"); | 403 | FileDialog* file=new FileDialog(this,"Delete Game",".game"); |
404 | if(!file->exec()) | 404 | if(!file->exec()) |
405 | return; | 405 | return; |
406 | 406 | ||
407 | game_name=file->filename(); | 407 | game_name=file->filename(); |
408 | QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; | 408 | QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; |
409 | 409 | ||
410 | if(!QMessageBox::warning(this,"Backgammon","deleted game\n"+game_name+" ?","OK","Cancel")) | 410 | if(!QMessageBox::warning(this,"Backgammon","deleted game\n"+game_name+" ?","OK","Cancel")) |
411 | { | 411 | { |
412 | QFile(game_file).remove(); | 412 | QFile(game_file).remove(); |
413 | } | 413 | } |
414 | } | 414 | } |
415 | 415 | ||
416 | 416 | ||
417 | void BackGammon::newtheme() | 417 | void BackGammon::newtheme() |
418 | { | 418 | { |
419 | ThemeDialog* theme=new ThemeDialog(this); | 419 | ThemeDialog* theme=new ThemeDialog(this); |
420 | 420 | ||
421 | ImageNames names; | 421 | ImageNames names; |
422 | names.theme=theme_name; | 422 | names.theme=theme_name; |
423 | names.board=board_name; | 423 | names.board=board_name; |
424 | names.pieces1=piecesA_name; | 424 | names.pieces1=piecesA_name; |
425 | names.pieces2=piecesB_name; | 425 | names.pieces2=piecesB_name; |
426 | names.dice1=diceA_name; | 426 | names.dice1=diceA_name; |
427 | names.dice2=diceB_name; | 427 | names.dice2=diceB_name; |
428 | names.odds=odds_name; | 428 | names.odds=odds_name; |
429 | names.table=table_name; | 429 | names.table=table_name; |
430 | 430 | ||
431 | theme->setCurrent(names); | 431 | theme->setCurrent(names); |
432 | if(!theme->exec()) | 432 | if(!theme->exec()) |
433 | return; | 433 | return; |
434 | 434 | ||
435 | names=theme->getNames(); | 435 | names=theme->getNames(); |
436 | theme_name=names.theme; | 436 | theme_name=names.theme; |
437 | board_name=names.board; | 437 | board_name=names.board; |
438 | piecesA_name=names.pieces1; | 438 | piecesA_name=names.pieces1; |
439 | piecesB_name=names.pieces2; | 439 | piecesB_name=names.pieces2; |
440 | diceA_name=names.dice1; | 440 | diceA_name=names.dice1; |
441 | diceB_name=names.dice2; | 441 | diceB_name=names.dice2; |
442 | odds_name=names.odds; | 442 | odds_name=names.odds; |
443 | table_name=names.table; | 443 | table_name=names.table; |
444 | 444 | ||
445 | applytheme(); | 445 | applytheme(); |
446 | } | 446 | } |
447 | 447 | ||
448 | void BackGammon::loadtheme() | 448 | void BackGammon::loadtheme() |
449 | { | 449 | { |
450 | FileDialog* file=new FileDialog(this,"Load Theme",".theme"); | 450 | FileDialog* file=new FileDialog(this,"Load Theme",".theme"); |
451 | if(!file->exec()) | 451 | if(!file->exec()) |
452 | return; | 452 | return; |
453 | 453 | ||
454 | theme_name=file->filename(); | 454 | theme_name=file->filename(); |
455 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; | 455 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; |
456 | 456 | ||
457 | Config theme(theme_file,Config::File); | 457 | Config theme(theme_file,Config::File); |
458 | theme.setGroup("theme"); | 458 | theme.setGroup("theme"); |
459 | board_name=theme.readEntry("board","board_1"); | 459 | board_name=theme.readEntry("board","board_1"); |
460 | piecesA_name=theme.readEntry("pieces1","pieces_1"); | 460 | piecesA_name=theme.readEntry("pieces1","pieces_1"); |
461 | piecesB_name=theme.readEntry("pieces2","pieces_2"); | 461 | piecesB_name=theme.readEntry("pieces2","pieces_2"); |
462 | diceA_name=theme.readEntry("dice1","dice_1"); | 462 | diceA_name=theme.readEntry("dice1","dice_1"); |
463 | diceB_name=theme.readEntry("dice2","dice_2"); | 463 | diceB_name=theme.readEntry("dice2","dice_2"); |
464 | table_name=theme.readEntry("table","table_1"); | 464 | table_name=theme.readEntry("table","table_1"); |
465 | odds_name=theme.readEntry("odds","odds_1"); | 465 | odds_name=theme.readEntry("odds","odds_1"); |
466 | 466 | ||
467 | applytheme(); | 467 | applytheme(); |
468 | 468 | ||
469 | } | 469 | } |
470 | 470 | ||
471 | void BackGammon::savetheme() | 471 | void BackGammon::savetheme() |
472 | { | 472 | { |
473 | if(theme_name=="default") | 473 | if(theme_name=="default") |
474 | { | 474 | { |
475 | QMessageBox::information(this,"Backgammon","Sorry\nCannot overwrite default.theme","OK"); | 475 | QMessageBox::information(this,"Backgammon","Sorry\nCannot overwrite default.theme","OK"); |
476 | return; | 476 | return; |
477 | } | 477 | } |
478 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; | 478 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; |
479 | if(QMessageBox::information(this,"Backgammon","Save Theme\n"+theme_name,"Yes","No")) | 479 | if(QMessageBox::information(this,"Backgammon","Save Theme\n"+theme_name,"Yes","No")) |
480 | return; | 480 | return; |
481 | 481 | ||
482 | Config theme(theme_file,Config::File); | 482 | Config theme(theme_file,Config::File); |
483 | theme.setGroup("theme"); | 483 | theme.setGroup("theme"); |
484 | theme.writeEntry("board",board_name); | 484 | theme.writeEntry("board",board_name); |
485 | theme.writeEntry("pieces1",piecesA_name); | 485 | theme.writeEntry("pieces1",piecesA_name); |
486 | theme.writeEntry("pieces2",piecesB_name); | 486 | theme.writeEntry("pieces2",piecesB_name); |
487 | theme.writeEntry("dice1",diceA_name); | 487 | theme.writeEntry("dice1",diceA_name); |
488 | theme.writeEntry("dice2",diceB_name); | 488 | theme.writeEntry("dice2",diceB_name); |
489 | theme.writeEntry("table",table_name); | 489 | theme.writeEntry("table",table_name); |
490 | theme.writeEntry("odds",odds_name); | 490 | theme.writeEntry("odds",odds_name); |
491 | 491 | ||
492 | } | 492 | } |
493 | 493 | ||
494 | void BackGammon::themedefault() | 494 | void BackGammon::themedefault() |
495 | { | 495 | { |
496 | if(QMessageBox::information(this,"Backgammon","Make Theme\n"+theme_name+"\nthe default theme","Yes","No")) | 496 | if(QMessageBox::information(this,"Backgammon","Make Theme\n"+theme_name+"\nthe default theme","Yes","No")) |
497 | return; | 497 | return; |
498 | 498 | ||
499 | Config conf("backgammon"); | 499 | Config conf("backgammon"); |
500 | conf.setGroup("general"); | 500 | conf.setGroup("general"); |
501 | conf.writeEntry("theme",theme_name); | 501 | conf.writeEntry("theme",theme_name); |
502 | } | 502 | } |
503 | 503 | ||
504 | void BackGammon::deletetheme() | 504 | void BackGammon::deletetheme() |
505 | { | 505 | { |
506 | FileDialog* file=new FileDialog(this,"Delete Theme",".theme"); | 506 | FileDialog* file=new FileDialog(this,"Delete Theme",".theme"); |
507 | if(!file->exec()) | 507 | if(!file->exec()) |
508 | return; | 508 | return; |
509 | 509 | ||
510 | theme_name=file->filename(); | 510 | theme_name=file->filename(); |
511 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; | 511 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; |
512 | 512 | ||
513 | if(!QMessageBox::warning(this,"Backgammon","deleted theme "+theme_name+" ?","OK","Cancel")) | 513 | if(!QMessageBox::warning(this,tr( "Backgammon" ),tr( "deleted theme %1?").arg(theme_name),tr( "OK" ),tr( "Cancel" ))) |
514 | { | 514 | { |
515 | QFile(theme_file).remove(); | 515 | QFile(theme_file).remove(); |
516 | } | 516 | } |
517 | } | 517 | } |
518 | 518 | ||
519 | void BackGammon::modify_AI() | 519 | void BackGammon::modify_AI() |
520 | { | 520 | { |
521 | AI_Dialog* ai_mod=new AI_Dialog(this,"Load Theme",".theme"); | 521 | AI_Dialog* ai_mod=new AI_Dialog(this,tr( "Load Theme" ),".theme"); |
522 | ai_mod->setAISettings(move->getAISettings()); | 522 | ai_mod->setAISettings(move->getAISettings()); |
523 | if(!ai_mod->exec()) | 523 | if(!ai_mod->exec()) |
524 | return; | 524 | return; |
525 | 525 | ||
526 | //get the AI settings | 526 | //get the AI settings |
527 | AISettings ai=ai_mod->getAISettings(); | 527 | AISettings ai=ai_mod->getAISettings(); |
528 | move->setAISettings(ai); | 528 | move->setAISettings(ai); |
529 | //write new settings to conf file | 529 | //write new settings to conf file |
530 | Config conf("backgammon"); | 530 | Config conf("backgammon"); |
531 | conf.setGroup("ai"); | 531 | conf.setGroup("ai"); |
532 | conf.writeEntry("rescue",ai.rescue); | 532 | conf.writeEntry("rescue",ai.rescue); |
533 | conf.writeEntry("eliminate",ai.eliminate); | 533 | conf.writeEntry("eliminate",ai.eliminate); |
534 | conf.writeEntry("expose",ai.expose); | 534 | conf.writeEntry("expose",ai.expose); |
535 | conf.writeEntry("protect",ai.protect); | 535 | conf.writeEntry("protect",ai.protect); |
536 | conf.writeEntry("safe",ai.safe); | 536 | conf.writeEntry("safe",ai.safe); |
537 | conf.writeEntry("empty",ai.empty); | 537 | conf.writeEntry("empty",ai.empty); |
538 | } | 538 | } |
539 | 539 | ||
540 | void BackGammon::setrules() | 540 | void BackGammon::setrules() |
541 | { | 541 | { |
542 | RulesDialog* rulesdialog=new RulesDialog(this,"Load Theme",".theme"); | 542 | RulesDialog* rulesdialog=new RulesDialog(this,tr( "Load Theme" ),".theme"); |
543 | rulesdialog->setRules(rules); | 543 | rulesdialog->setRules(rules); |
544 | if(!rulesdialog->exec()) | 544 | if(!rulesdialog->exec()) |
545 | return; | 545 | return; |
546 | rules=rulesdialog->getRules(); | 546 | rules=rulesdialog->getRules(); |
547 | Config conf("backgammon"); | 547 | Config conf("backgammon"); |
548 | conf.setGroup("rules"); | 548 | conf.setGroup("rules"); |
549 | conf.writeEntry("move_with_pieces_out",rules.move_with_pieces_out); | 549 | conf.writeEntry("move_with_pieces_out",rules.move_with_pieces_out); |
550 | conf.writeEntry("nice_dice",rules.generous_dice); | 550 | conf.writeEntry("nice_dice",rules.generous_dice); |
551 | move->setRules(rules); | 551 | move->setRules(rules); |
552 | } | 552 | } |
553 | 553 | ||
554 | 554 | ||
555 | void BackGammon::draw() | 555 | void BackGammon::draw() |
556 | { | 556 | { |
557 | Pieces pieces; | 557 | Pieces pieces; |
558 | move->position(pieces); | 558 | move->position(pieces); |
559 | for(int a=0;a<15;a++) | 559 | for(int a=0;a<15;a++) |
560 | { | 560 | { |
561 | if(!pieces.player1[a].side) | 561 | if(!pieces.player1[a].side) |
562 | { | 562 | { |
563 | p1[a]->setX(pieces.player1[a].x); | 563 | p1[a]->setX(pieces.player1[a].x); |
564 | p1[a]->setY(pieces.player1[a].y); | 564 | p1[a]->setY(pieces.player1[a].y); |
565 | p1[a]->setZ(pieces.player1[a].z); | 565 | p1[a]->setZ(pieces.player1[a].z); |
566 | p1[a]->show(); | 566 | p1[a]->show(); |
567 | p1_side[a]->hide(); | 567 | p1_side[a]->hide(); |
568 | } | 568 | } |
569 | else | 569 | else |
570 | { | 570 | { |
571 | p1_side[a]->setX(pieces.player1[a].x); | 571 | p1_side[a]->setX(pieces.player1[a].x); |
572 | p1_side[a]->setY(pieces.player1[a].y); | 572 | p1_side[a]->setY(pieces.player1[a].y); |
573 | p1_side[a]->setZ(pieces.player1[a].z); | 573 | p1_side[a]->setZ(pieces.player1[a].z); |
574 | p1_side[a]->show(); | 574 | p1_side[a]->show(); |
575 | p1[a]->hide(); | 575 | p1[a]->hide(); |
576 | } | 576 | } |
577 | 577 | ||
578 | if(!pieces.player2[a].side) | 578 | if(!pieces.player2[a].side) |
579 | { | 579 | { |
580 | p2[a]->setX(pieces.player2[a].x); | 580 | p2[a]->setX(pieces.player2[a].x); |
581 | p2[a]->setY(pieces.player2[a].y); | 581 | p2[a]->setY(pieces.player2[a].y); |
582 | p2[a]->setZ(pieces.player2[a].z); | 582 | p2[a]->setZ(pieces.player2[a].z); |
583 | p2[a]->show(); | 583 | p2[a]->show(); |
584 | p2_side[a]->hide(); | 584 | p2_side[a]->hide(); |
585 | } | 585 | } |
586 | else | 586 | else |
587 | { | 587 | { |
588 | p2_side[a]->setX(pieces.player2[a].x); | 588 | p2_side[a]->setX(pieces.player2[a].x); |
589 | p2_side[a]->setY(pieces.player2[a].y); | 589 | p2_side[a]->setY(pieces.player2[a].y); |
590 | p2_side[a]->setZ(pieces.player2[a].z); | 590 | p2_side[a]->setZ(pieces.player2[a].z); |
591 | p2_side[a]->show(); | 591 | p2_side[a]->show(); |
592 | p2[a]->hide(); | 592 | p2[a]->hide(); |
593 | } | 593 | } |
594 | } | 594 | } |
595 | } | 595 | } |
596 | 596 | ||
597 | void BackGammon::mouse(int x,int y) | 597 | void BackGammon::mouse(int x,int y) |
598 | { | 598 | { |
599 | if(gameFinished) | 599 | if(gameFinished) |
600 | { | 600 | { |
601 | newgame(); | 601 | newgame(); |
602 | return; | 602 | return; |
603 | } | 603 | } |
604 | if(y<=200) //move pieces | 604 | if(y<=200) //move pieces |
605 | { | 605 | { |
606 | if((player==1 && player1_auto) || (player==2 && player2_auto)) | 606 | if((player==1 && player1_auto) || (player==2 && player2_auto)) |
607 | return; | 607 | return; |
608 | 608 | ||
609 | Marker marker; | 609 | Marker marker; |
610 | 610 | ||
611 | move->boardpressed(x,y,marker); | 611 | move->boardpressed(x,y,marker); |
612 | if(marker.visible_current) | 612 | if(marker.visible_current) |
613 | { | 613 | { |
614 | marker_current->setX(marker.x_current); | 614 | marker_current->setX(marker.x_current); |
615 | marker_current->setY(marker.y_current); | 615 | marker_current->setY(marker.y_current); |
616 | marker_current->show(); | 616 | marker_current->show(); |
617 | } | 617 | } |
618 | else | 618 | else |
619 | { | 619 | { |
620 | marker_current->hide(); | 620 | marker_current->hide(); |
621 | } | 621 | } |
622 | 622 | ||
623 | for(int a=0;a<4;a++) | 623 | for(int a=0;a<4;a++) |
624 | { | 624 | { |
625 | if(marker.visible_next[a]) | 625 | if(marker.visible_next[a]) |
626 | { | 626 | { |
627 | marker_next[a]->setX(marker.x_next[a]); | 627 | marker_next[a]->setX(marker.x_next[a]); |
628 | marker_next[a]->setY(marker.y_next[a]); | 628 | marker_next[a]->setY(marker.y_next[a]); |
629 | marker_next[a]->show(); | 629 | marker_next[a]->show(); |
630 | } | 630 | } |
631 | else | 631 | else |
632 | { | 632 | { |
633 | marker_next[a]->hide(); | 633 | marker_next[a]->hide(); |
634 | } | 634 | } |
635 | } | 635 | } |
636 | area->update(); | 636 | area->update(); |
637 | } | 637 | } |
638 | else //roll dice | 638 | else //roll dice |
639 | { | 639 | { |
640 | if(x>=10 && x<=65 && player==1 && !dice_rolled) | 640 | if(x>=10 && x<=65 && player==1 && !dice_rolled) |
641 | { | 641 | { |
642 | dice1_played=false; | 642 | dice1_played=false; |
643 | dice2_played=false; | 643 | dice2_played=false; |
644 | dice3_played=false; | 644 | dice3_played=false; |
645 | dice4_played=false; | 645 | dice4_played=false; |
646 | dice_rolled=true; | 646 | dice_rolled=true; |
647 | srand(QTime::currentTime().msec()); | 647 | srand(QTime::currentTime().msec()); |
648 | diceA1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); | 648 | diceA1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); |
649 | diceA2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); | 649 | diceA2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); |
650 | if(diceA1_value==diceA2_value) | 650 | if(diceA1_value==diceA2_value) |
651 | { | 651 | { |
652 | diceA3_value=diceA1_value; | 652 | diceA3_value=diceA1_value; |
653 | diceA4_value=diceA1_value; | 653 | diceA4_value=diceA1_value; |
654 | } | 654 | } |
655 | else | 655 | else |
656 | { | 656 | { |
657 | diceA3_value=7; | 657 | diceA3_value=7; |
658 | dice3_played=true; | 658 | dice3_played=true; |
659 | diceA4_value=7; | 659 | diceA4_value=7; |
660 | dice4_played=true; | 660 | dice4_played=true; |
661 | } | 661 | } |
662 | showdice(); | 662 | showdice(); |
663 | area->update(); | 663 | area->update(); |
664 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); | 664 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); |
665 | 665 | ||
666 | } | 666 | } |
667 | else if(x>=160 && x<=225 && player==2 && !dice_rolled) | 667 | else if(x>=160 && x<=225 && player==2 && !dice_rolled) |
668 | { | 668 | { |
669 | dice1_played=false; | 669 | dice1_played=false; |
670 | dice2_played=false; | 670 | dice2_played=false; |
671 | dice3_played=false; | 671 | dice3_played=false; |
672 | dice4_played=false; | 672 | dice4_played=false; |
673 | dice_rolled=true; | 673 | dice_rolled=true; |
674 | srand(QTime::currentTime().msec()); | 674 | srand(QTime::currentTime().msec()); |
675 | diceB1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); | 675 | diceB1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); |
676 | diceB2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); | 676 | diceB2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); |
677 | if(diceB1_value==diceB2_value) | 677 | if(diceB1_value==diceB2_value) |
678 | { | 678 | { |
679 | diceB3_value=diceB1_value; | 679 | diceB3_value=diceB1_value; |
680 | diceB4_value=diceB1_value; | 680 | diceB4_value=diceB1_value; |
681 | } | 681 | } |
682 | else | 682 | else |
683 | { | 683 | { |
684 | diceB3_value=7; | 684 | diceB3_value=7; |
685 | dice3_played=true; | 685 | dice3_played=true; |
686 | diceB4_value=7; | 686 | diceB4_value=7; |
687 | dice4_played=true; | 687 | dice4_played=true; |
688 | } | 688 | } |
689 | showdice(); | 689 | showdice(); |
690 | area->update(); | 690 | area->update(); |
691 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); | 691 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); |
692 | } | 692 | } |
693 | } | 693 | } |
694 | } | 694 | } |
695 | 695 | ||
696 | void BackGammon::done_dice1() | 696 | void BackGammon::done_dice1() |
697 | { | 697 | { |
698 | dice1_played=true; | 698 | dice1_played=true; |
699 | if(player==1) | 699 | if(player==1) |
700 | diceA1_value=7; | 700 | diceA1_value=7; |
701 | else | 701 | else |
702 | diceB1_value=7; | 702 | diceB1_value=7; |
703 | setplayer(); | 703 | setplayer(); |
704 | showdice(); | 704 | showdice(); |
705 | draw(); | 705 | draw(); |
706 | area->update(); | 706 | area->update(); |
707 | if(!dice2_played || !dice3_played || !dice4_played) | 707 | if(!dice2_played || !dice3_played || !dice4_played) |
708 | { | 708 | { |
709 | if(player==1) | 709 | if(player==1) |
710 | { | 710 | { |
711 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); | 711 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); |
712 | } | 712 | } |
713 | else | 713 | else |
714 | { | 714 | { |
715 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); | 715 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); |
716 | } | 716 | } |
717 | } | 717 | } |
718 | } | 718 | } |
719 | 719 | ||
720 | void BackGammon::done_dice2() | 720 | void BackGammon::done_dice2() |
721 | { | 721 | { |
722 | dice2_played=true; | 722 | dice2_played=true; |
723 | if(player==1) | 723 | if(player==1) |
724 | diceA2_value=7; | 724 | diceA2_value=7; |
725 | else | 725 | else |
726 | diceB2_value=7; | 726 | diceB2_value=7; |
727 | setplayer(); | 727 | setplayer(); |
728 | showdice(); | 728 | showdice(); |
729 | draw(); | 729 | draw(); |
730 | area->update(); | 730 | area->update(); |
731 | if(!dice1_played || !dice3_played || !dice4_played) | 731 | if(!dice1_played || !dice3_played || !dice4_played) |
732 | { | 732 | { |
733 | if(player==1) | 733 | if(player==1) |
734 | { | 734 | { |
735 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); | 735 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); |
736 | } | 736 | } |
737 | else | 737 | else |
738 | { | 738 | { |
739 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); | 739 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); |
740 | } | 740 | } |
741 | } | 741 | } |
742 | } | 742 | } |
743 | 743 | ||
744 | 744 | ||
745 | void BackGammon::done_dice3() | 745 | void BackGammon::done_dice3() |
746 | { | 746 | { |
747 | dice3_played=true; | 747 | dice3_played=true; |
748 | if(player==1) | 748 | if(player==1) |
749 | diceA3_value=7; | 749 | diceA3_value=7; |
750 | else | 750 | else |
751 | diceB3_value=7; | 751 | diceB3_value=7; |
752 | setplayer(); | 752 | setplayer(); |
753 | showdice(); | 753 | showdice(); |
754 | draw(); | 754 | draw(); |
755 | area->update(); | 755 | area->update(); |
756 | if(!dice1_played || !dice2_played || !dice4_played) | 756 | if(!dice1_played || !dice2_played || !dice4_played) |
757 | { | 757 | { |
758 | if(player==1) | 758 | if(player==1) |
759 | { | 759 | { |
760 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); | 760 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); |
761 | } | 761 | } |
762 | else | 762 | else |
763 | { | 763 | { |
764 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); | 764 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); |
765 | } | 765 | } |
766 | } | 766 | } |
767 | } | 767 | } |
768 | 768 | ||
769 | 769 | ||
770 | void BackGammon::done_dice4() | 770 | void BackGammon::done_dice4() |
771 | { | 771 | { |
772 | dice4_played=true; | 772 | dice4_played=true; |
773 | if(player==1) | 773 | if(player==1) |
774 | diceA4_value=7; | 774 | diceA4_value=7; |
775 | else | 775 | else |
776 | diceB4_value=7; | 776 | diceB4_value=7; |
777 | setplayer(); | 777 | setplayer(); |
778 | showdice(); | 778 | showdice(); |
779 | draw(); | 779 | draw(); |
780 | area->update(); | 780 | area->update(); |
781 | if(!dice1_played || !dice2_played || !dice3_played) | 781 | if(!dice1_played || !dice2_played || !dice3_played) |
782 | { | 782 | { |
783 | if(player==1) | 783 | if(player==1) |
784 | { | 784 | { |
785 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); | 785 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); |
786 | } | 786 | } |
787 | else | 787 | else |
788 | { | 788 | { |
789 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); | 789 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); |
790 | } | 790 | } |
791 | } | 791 | } |
792 | } | 792 | } |
793 | 793 | ||
794 | 794 | ||
795 | void BackGammon::nomove() | 795 | void BackGammon::nomove() |
796 | { | 796 | { |
797 | if(player==1) | 797 | if(player==1) |
798 | nomove_marker->setX(0); | 798 | nomove_marker->setX(0); |
799 | else | 799 | else |
800 | nomove_marker->setX(170); | 800 | nomove_marker->setX(170); |
801 | nomove_marker->show(); | 801 | nomove_marker->show(); |
802 | message->setText("<b>no move</b>"); | 802 | message->setText(tr( "<b>no move</b>" )); |
803 | dice1_played=true; | 803 | dice1_played=true; |
804 | dice2_played=true; | 804 | dice2_played=true; |
805 | dice3_played=true; | 805 | dice3_played=true; |
806 | dice4_played=true; | 806 | dice4_played=true; |
807 | if(player==1) | 807 | if(player==1) |
808 | { | 808 | { |
809 | diceA1_value=7; | 809 | diceA1_value=7; |
810 | diceA2_value=7; | 810 | diceA2_value=7; |
811 | diceA3_value=7; | 811 | diceA3_value=7; |
812 | diceA4_value=7; | 812 | diceA4_value=7; |
813 | } | 813 | } |
814 | else | 814 | else |
815 | { | 815 | { |
816 | diceB1_value=7; | 816 | diceB1_value=7; |
817 | diceB2_value=7; | 817 | diceB2_value=7; |
818 | diceB3_value=7; | 818 | diceB3_value=7; |
819 | diceB4_value=7; | 819 | diceB4_value=7; |
820 | } | 820 | } |
821 | area->update(); | 821 | area->update(); |
822 | QTimer::singleShot(2000,this,SLOT(nomove2())); | 822 | QTimer::singleShot(2000,this,SLOT(nomove2())); |
823 | } | 823 | } |
824 | 824 | ||
825 | void BackGammon::nomove2() | 825 | void BackGammon::nomove2() |
826 | { | 826 | { |
827 | nomove_marker->hide(); | 827 | nomove_marker->hide(); |
828 | setplayer(); | 828 | setplayer(); |
829 | showdice(); | 829 | showdice(); |
830 | draw(); | 830 | draw(); |
831 | area->update(); | 831 | area->update(); |
832 | } | 832 | } |
833 | 833 | ||
834 | void BackGammon::finished(int theplayer) | 834 | void BackGammon::finished(int theplayer) |
835 | { | 835 | { |
836 | nomove_marker->hide(); | 836 | nomove_marker->hide(); |
837 | if(theplayer==1) | 837 | if(theplayer==1) |
838 | message->setText("<b>Player 1 wins. Click on board for new game.</b>"); | 838 | message->setText(tr( "<b>Player 1 wins. Click on board for new game.</b>" )); |
839 | else | 839 | else |
840 | message->setText("<b>Player 2 wins. Click on board for new game.</b>"); | 840 | message->setText(tr( "<b>Player 2 wins. Click on board for new game.</b>" )); |
841 | diceA1_value=7; | 841 | diceA1_value=7; |
842 | diceA2_value=7; | 842 | diceA2_value=7; |
843 | diceB1_value=7; | 843 | diceB1_value=7; |
844 | diceB2_value=7; | 844 | diceB2_value=7; |
845 | player=0; | 845 | player=0; |
846 | showdice(); | 846 | showdice(); |
847 | draw(); | 847 | draw(); |
848 | area->update(); | 848 | area->update(); |
849 | gameFinished=true; | 849 | gameFinished=true; |
850 | } | 850 | } |
851 | 851 | ||
852 | void BackGammon::showdice() | 852 | void BackGammon::showdice() |
853 | { | 853 | { |
854 | int value_diceA1=diceA1_value-1; | 854 | int value_diceA1=diceA1_value-1; |
855 | if(diceA1_value==7 && diceA3_value!=7) | 855 | if(diceA1_value==7 && diceA3_value!=7) |
856 | value_diceA1=diceA3_value-1; | 856 | value_diceA1=diceA3_value-1; |
857 | 857 | ||
858 | int value_diceA2=diceA2_value-1; | 858 | int value_diceA2=diceA2_value-1; |
859 | if(diceA2_value==7 && diceA4_value!=7) | 859 | if(diceA2_value==7 && diceA4_value!=7) |
860 | value_diceA2=diceA4_value-1; | 860 | value_diceA2=diceA4_value-1; |
861 | 861 | ||
862 | int value_diceB1=diceB1_value-1; | 862 | int value_diceB1=diceB1_value-1; |
863 | if(diceB1_value==7 && diceB3_value!=7) | 863 | if(diceB1_value==7 && diceB3_value!=7) |
864 | value_diceB1=diceB3_value-1; | 864 | value_diceB1=diceB3_value-1; |
865 | 865 | ||
866 | int value_diceB2=diceB2_value-1; | 866 | int value_diceB2=diceB2_value-1; |
867 | if(diceB2_value==7 && diceB4_value!=7) | 867 | if(diceB2_value==7 && diceB4_value!=7) |
868 | value_diceB2=diceB4_value-1; | 868 | value_diceB2=diceB4_value-1; |
869 | 869 | ||
870 | for(int index=0;index<7;index++) | 870 | for(int index=0;index<7;index++) |
871 | { | 871 | { |
872 | if(value_diceA1==index) | 872 | if(value_diceA1==index) |
873 | diceA1[index]->show(); | 873 | diceA1[index]->show(); |
874 | else | 874 | else |
875 | diceA1[index]->hide(); | 875 | diceA1[index]->hide(); |
876 | 876 | ||
877 | if(value_diceA2==index) | 877 | if(value_diceA2==index) |
878 | diceA2[index]->show(); | 878 | diceA2[index]->show(); |
879 | else | 879 | else |
880 | diceA2[index]->hide(); | 880 | diceA2[index]->hide(); |
881 | 881 | ||
882 | if(value_diceB1==index) | 882 | if(value_diceB1==index) |
883 | diceB1[index]->show(); | 883 | diceB1[index]->show(); |
884 | else | 884 | else |
885 | diceB1[index]->hide(); | 885 | diceB1[index]->hide(); |
886 | 886 | ||
887 | if(value_diceB2==index) | 887 | if(value_diceB2==index) |
888 | diceB2[index]->show(); | 888 | diceB2[index]->show(); |
889 | else | 889 | else |
890 | diceB2[index]->hide(); | 890 | diceB2[index]->hide(); |
891 | } | 891 | } |
892 | } | 892 | } |
893 | 893 | ||
894 | void BackGammon::setplayer() | 894 | void BackGammon::setplayer() |
895 | { | 895 | { |
896 | if(dice1_played && dice2_played && dice3_played && dice4_played && player==1) | 896 | if(dice1_played && dice2_played && dice3_played && dice4_played && player==1) |
897 | { | 897 | { |
898 | message->setText("<b>P2 turn</b>"); | 898 | message->setText(tr( "<b>P2 turn</b>", "P means player" )); |
899 | dice_rolled=false; | 899 | dice_rolled=false; |
900 | player=2; | 900 | player=2; |
901 | if(player2_auto) | 901 | if(player2_auto) |
902 | QTimer::singleShot(2000,this,SLOT(autoroll_dice2())); | 902 | QTimer::singleShot(2000,this,SLOT(autoroll_dice2())); |
903 | } | 903 | } |
904 | else if(dice1_played && dice2_played && dice3_played && dice4_played && player==2) | 904 | else if(dice1_played && dice2_played && dice3_played && dice4_played && player==2) |
905 | { | 905 | { |
906 | message->setText("<b>P1 turn</b>"); | 906 | message->setText(tr( "<b>P1 turn</b>", "P means player" )); |
907 | dice_rolled=false; | 907 | dice_rolled=false; |
908 | player=1; | 908 | player=1; |
909 | if(player1_auto) | 909 | if(player1_auto) |
910 | QTimer::singleShot(2000,this,SLOT(autoroll_dice1())); | 910 | QTimer::singleShot(2000,this,SLOT(autoroll_dice1())); |
911 | } | 911 | } |
912 | } | 912 | } |
913 | 913 | ||
914 | void BackGammon::autoroll_dice1() | 914 | void BackGammon::autoroll_dice1() |
915 | { | 915 | { |
916 | mouse(20,210); | 916 | mouse(20,210); |
917 | } | 917 | } |
918 | 918 | ||
919 | void BackGammon::autoroll_dice2() | 919 | void BackGammon::autoroll_dice2() |
920 | { | 920 | { |
921 | mouse(170,210); | 921 | mouse(170,210); |
922 | } | 922 | } |
923 | 923 | ||
924 | void BackGammon::applytheme() | 924 | void BackGammon::applytheme() |
925 | { | 925 | { |
926 | QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name)); | 926 | QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name)); |
927 | board->setImage(boardbg); | 927 | board->setImage(boardbg); |
928 | 928 | ||
929 | QImage tablebg(Resource::loadImage("backgammon/table/"+table_name)); | 929 | QImage tablebg(Resource::loadImage("backgammon/table/"+table_name)); |
930 | table->setImage(tablebg); | 930 | table->setImage(tablebg); |
931 | 931 | ||
932 | QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name)); | 932 | QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name)); |
933 | QImage piece_1_front=piece_1_all.copy(0,0,15,15); | 933 | QImage piece_1_front=piece_1_all.copy(0,0,15,15); |
934 | QImage piece_1_side=piece_1_all.copy(0,15,15,5); | 934 | QImage piece_1_side=piece_1_all.copy(0,15,15,5); |
935 | 935 | ||
936 | QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name)); | 936 | QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name)); |
937 | QImage piece_2_front=piece_2_all.copy(0,0,15,15); | 937 | QImage piece_2_front=piece_2_all.copy(0,0,15,15); |
938 | QImage piece_2_side=piece_2_all.copy(0,15,15,5); | 938 | QImage piece_2_side=piece_2_all.copy(0,15,15,5); |
939 | 939 | ||
940 | int a=0; | 940 | int a=0; |
941 | for(a=0;a<15;a++) | 941 | for(a=0;a<15;a++) |
942 | { | 942 | { |
943 | p1[a]->setImage(piece_1_front); | 943 | p1[a]->setImage(piece_1_front); |
944 | p1_side[a]->setImage(piece_1_side); | 944 | p1_side[a]->setImage(piece_1_side); |
945 | 945 | ||
946 | p2[a]->setImage(piece_2_front); | 946 | p2[a]->setImage(piece_2_front); |
947 | p2_side[a]->setImage(piece_2_side); | 947 | p2_side[a]->setImage(piece_2_side); |
948 | } | 948 | } |
949 | draw(); | 949 | draw(); |
950 | 950 | ||
951 | QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name)); | 951 | QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name)); |
952 | QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name)); | 952 | QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name)); |
953 | QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name)); | 953 | QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name)); |
954 | 954 | ||
955 | for(a=0;a<7;a++) | 955 | for(a=0;a<7;a++) |
956 | { | 956 | { |
957 | QImage dicebgA=dicebgA_all.copy(a*25,0,25,25); | 957 | QImage dicebgA=dicebgA_all.copy(a*25,0,25,25); |
958 | diceA1[a]->setImage(dicebgA); | 958 | diceA1[a]->setImage(dicebgA); |
959 | diceA2[a]->setImage(dicebgA); | 959 | diceA2[a]->setImage(dicebgA); |
960 | 960 | ||
961 | QImage dicebgB=dicebgB_all.copy(a*25,0,25,25); | 961 | QImage dicebgB=dicebgB_all.copy(a*25,0,25,25); |
962 | diceB1[a]->setImage(dicebgB); | 962 | diceB1[a]->setImage(dicebgB); |
963 | diceB2[a]->setImage(dicebgB); | 963 | diceB2[a]->setImage(dicebgB); |
964 | /* | 964 | /* |
965 | if(a<6) | 965 | if(a<6) |
966 | { | 966 | { |
967 | QImage oddsbg=oddsbg_all.copy(a*15,0,15,15); | 967 | QImage oddsbg=oddsbg_all.copy(a*15,0,15,15); |
968 | oddsDice[a]->setImage(oddsbg); | 968 | oddsDice[a]->setImage(oddsbg); |
969 | } | 969 | } |
970 | */ | 970 | */ |
971 | } | 971 | } |
972 | } | 972 | } |
973 | 973 | ||
974 | 974 | ||