summaryrefslogtreecommitdiff
authorwaspe <waspe>2003-03-30 11:30:54 (UTC)
committer waspe <waspe>2003-03-30 11:30:54 (UTC)
commit3065a1c13bec5d0b101bec48ff666d45a02ce8a6 (patch) (unidiff)
treef8fe8d3eba81ef4e371c12f530be9cd4debc895b
parent87ba3646367397e149979a8477a33239cb341e99 (diff)
downloadopie-3065a1c13bec5d0b101bec48ff666d45a02ce8a6.zip
opie-3065a1c13bec5d0b101bec48ff666d45a02ce8a6.tar.gz
opie-3065a1c13bec5d0b101bec48ff666d45a02ce8a6.tar.bz2
*** empty log message ***
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--apps/Games/backgammon.desktop6
-rwxr-xr-xhelp/en/html/backgammon.html71
-rw-r--r--noncore/games/backgammon/aidialog.cpp211
-rw-r--r--noncore/games/backgammon/aidialog.h48
-rw-r--r--noncore/games/backgammon/backgammon.control9
-rw-r--r--noncore/games/backgammon/backgammon.cpp1043
-rw-r--r--noncore/games/backgammon/backgammon.h134
-rw-r--r--noncore/games/backgammon/backgammon.pro34
-rw-r--r--noncore/games/backgammon/backgammonview.cpp17
-rw-r--r--noncore/games/backgammon/backgammonview.h18
-rw-r--r--noncore/games/backgammon/canvasimageitem.cpp23
-rw-r--r--noncore/games/backgammon/canvasimageitem.h21
-rw-r--r--noncore/games/backgammon/config.in4
-rw-r--r--noncore/games/backgammon/definition.cpp3
-rw-r--r--noncore/games/backgammon/definition.h74
-rw-r--r--noncore/games/backgammon/displaydialog.cpp89
-rw-r--r--noncore/games/backgammon/displaydialog.h30
-rw-r--r--noncore/games/backgammon/filedialog.cpp64
-rw-r--r--noncore/games/backgammon/filedialog.h30
-rw-r--r--noncore/games/backgammon/main.cpp14
-rw-r--r--noncore/games/backgammon/moveengine.cpp558
-rw-r--r--noncore/games/backgammon/moveengine.h76
-rw-r--r--noncore/games/backgammon/playerdialog.cpp114
-rw-r--r--noncore/games/backgammon/playerdialog.h35
-rw-r--r--noncore/games/backgammon/rulesdialog.cpp77
-rw-r--r--noncore/games/backgammon/rulesdialog.h27
-rw-r--r--noncore/games/backgammon/themedialog.cpp163
-rw-r--r--noncore/games/backgammon/themedialog.h42
-rw-r--r--pics/backgammon/backgammon.pngbin0 -> 901 bytes
-rw-r--r--pics/backgammon/boards/casino_board_1.pngbin0 -> 93063 bytes
-rwxr-xr-xpics/backgammon/dice/casino_dice.pngbin0 -> 3905 bytes
-rwxr-xr-xpics/backgammon/no_move.pngbin0 -> 360 bytes
-rw-r--r--pics/backgammon/odds/casino_odds.pngbin0 -> 1153 bytes
-rwxr-xr-xpics/backgammon/pieces/casino_pieces_blue.pngbin0 -> 997 bytes
-rwxr-xr-xpics/backgammon/pieces/casino_pieces_white.pngbin0 -> 983 bytes
-rw-r--r--pics/backgammon/table/casino_table_green.pngbin0 -> 7894 bytes
36 files changed, 3035 insertions, 0 deletions
diff --git a/apps/Games/backgammon.desktop b/apps/Games/backgammon.desktop
new file mode 100644
index 0000000..a61be25
--- a/dev/null
+++ b/apps/Games/backgammon.desktop
@@ -0,0 +1,6 @@
1[Desktop Entry]
2Comment=Backgammon
3Exec=backgammon
4Icon=backgammon/backgammon
5Type=Application
6Name=BackGammon
diff --git a/help/en/html/backgammon.html b/help/en/html/backgammon.html
new file mode 100755
index 0000000..886a901
--- a/dev/null
+++ b/help/en/html/backgammon.html
@@ -0,0 +1,71 @@
1<html>
2<head>
3<title>Backgammon</title>
4</head>
5<body>
6
7<a name="top"></a>
8<b><u>Backgammon</u></b><br>
9version 0.9.5<br>
10relased under GPL<br>
11(c) Ralf Waspe 2002/2003<br>
12rwaspe@web.de<br>
13<hr>
14<ul>
15<li><a href="#how">How the game works</a></li>
16<li><a href="#game">The Game menu</a></li>
17<li><a href="#theme">The Theme menu</a></li>
18<li><a href="#options">The Options menu</a></li>
19<li><a href="#todo">ToDo List</a></li>
20</ul>
21<a href="#top">top</a><br>
22<hr>
23
24<a name="how"><b>How the game works</b><br></a>
25If you don not know the rules of backgammon try google : "backgammon rules" <br>
26Details on how this game works soon<br>
27<a href="#top">top</a><br>
28<hr>
29
30<a name="game"><b>The Game menu</b><br></a>
31<ul>
32<li><b>new</b><br>
33start a new game</li>
34<li><b>load</b><br>
35load a previusly saved game here</li>
36<li><b>save</b><br>
37save the current game.<br>
38The game will be named automatically with the current date and time</li>
39<li><b>delete</b><br>
40delete a saved game</li>
41</ul>
42<a href="#top">top</a><br>
43<hr>
44
45<a name="theme"><b>The Theme menu</b><br></a>
46<ul>
47<li><b>new</b><br>
48create a new theme or alter an existing one based on the componts save on your z.<br>
49make sure to give it a unique name, so you do not overwrite an existing theme !</li>
50<li><b>load</b><br>
51load a theme</li>
52<li><b>save</b><br>
53save the current theme<br>
54<li><b>default</b><br>
55make the current theme the default theme (the one that gets loaded when you start the game)</li>
56<li><b>delete</b><br>
57delete a theme (the theme with the name default can not be deleted)</li>
58</ul>
59<a href="#top">top</a><br>
60<hr>
61
62<a name="options"><b>The Options menu</b><br></a>
63blah<br>
64<a href="#top">top</a><br>
65<hr>
66
67<a name="todo"><b>ToDo list</b><br></a>
68eliminate bugs<br>
69<a href="#top">top</a><br>
70</body>
71</html>
diff --git a/noncore/games/backgammon/aidialog.cpp b/noncore/games/backgammon/aidialog.cpp
new file mode 100644
index 0000000..9642ca5
--- a/dev/null
+++ b/noncore/games/backgammon/aidialog.cpp
@@ -0,0 +1,211 @@
1#include "aidialog.h"
2
3#include <qgroupbox.h>
4
5
6AI_Dialog::AI_Dialog(QWidget* parent,const char* name,bool modal,WFlags f)
7 : QDialog(parent,name,modal,f)
8{
9 setCaption("AI Configuration");
10
11 QGroupBox* settings=new QGroupBox("Settings",this);
12 settings->setGeometry(10,5,220,170);
13
14 QLabel* rescue_label=new QLabel("<b>Rescue</b>",settings);
15 rescue_label->setGeometry(50,20,50,20);
16 rescue=new QSpinBox(0,6,1,settings);
17 rescue->setGeometry(100,20,40,20);
18 QPushButton* rescuehelp=new QPushButton("?",settings);
19 rescuehelp->setGeometry(140,20,20,20);
20 connect(rescuehelp,SIGNAL(pressed()),this,SLOT(rescuehelp_pressed()));
21 connect(rescuehelp,SIGNAL(released()),this,SLOT(rescuehelp_released()));
22
23 QLabel* eliminate_label=new QLabel("<b>Eliminate</b>",settings);
24 eliminate_label->setGeometry(50,40,50,20);
25 eliminate=new QSpinBox(0,6,1,settings);
26 eliminate->setGeometry(100,40,40,20);
27 QPushButton* eliminatehelp=new QPushButton("?",settings);
28 eliminatehelp->setGeometry(140,40,20,20);
29 connect(eliminatehelp,SIGNAL(pressed()),this,SLOT(eliminatehelp_pressed()));
30 connect(eliminatehelp,SIGNAL(released()),this,SLOT(eliminatehelp_released()));
31
32 QLabel* expose_label=new QLabel("<b>Expose</b>",settings);
33 expose_label->setGeometry(50,60,50,20);
34 expose=new QSpinBox(0,6,1,settings);
35 expose->setGeometry(100,60,40,20);
36 QPushButton* exposeehelp=new QPushButton("?",settings);
37 exposeehelp->setGeometry(140,60,20,20);
38 connect(exposeehelp,SIGNAL(pressed()),this,SLOT(exposehelp_pressed()));
39 connect(exposeehelp,SIGNAL(released()),this,SLOT(exposehelp_released()));
40
41 QLabel* protect_label=new QLabel("<b>Protect</b>",settings);
42 protect_label->setGeometry(50,80,50,20);
43 protect=new QSpinBox(0,6,1,settings);
44 protect->setGeometry(100,80,40,20);
45 QPushButton* protecthelp=new QPushButton("?",settings);
46 protecthelp->setGeometry(140,80,20,20);
47 connect(protecthelp,SIGNAL(pressed()),this,SLOT(protecthelp_pressed()));
48 connect(protecthelp,SIGNAL(released()),this,SLOT(protecthelp_released()));
49
50 QLabel* safe_label=new QLabel("<b>Safe</b>",settings);
51 safe_label->setGeometry(50,100,50,20);
52 safe=new QSpinBox(0,6,1,settings);
53 safe->setGeometry(100,100,40,20);
54 QPushButton* safeehelp=new QPushButton("?",settings);
55 safeehelp->setGeometry(140,100,20,20);
56 connect(safeehelp,SIGNAL(pressed()),this,SLOT(safehelp_pressed()));
57 connect(safeehelp,SIGNAL(released()),this,SLOT(safehelp_released()));
58
59 QLabel* empty_label=new QLabel("<b>Empty</b>",settings);
60 empty_label->setGeometry(50,120,50,20);
61 empty=new QSpinBox(0,6,1,settings);
62 empty->setGeometry(100,120,40,20);
63 QPushButton* emptyhelp=new QPushButton("?",settings);
64 emptyhelp->setGeometry(140,120,20,20);
65 connect(emptyhelp,SIGNAL(pressed()),this,SLOT(emptyhelp_pressed()));
66 connect(emptyhelp,SIGNAL(released()),this,SLOT(emptyhelp_released()));
67
68 defaultvalues=new QPushButton("Default Values",settings);
69 defaultvalues->setGeometry(60,140,90,20);
70 connect(defaultvalues,SIGNAL(clicked()),this,SLOT(setDefaultValues()));
71
72 QGroupBox* helpbox=new QGroupBox("Help",this);
73 helpbox->setGeometry(10,185,220,90);
74
75 help=new QLabel(helpbox);
76 help->setGeometry(10,15,200,65);
77
78 setHelpText();
79 showMaximized();
80}
81
82
83AI_Dialog::~AI_Dialog()
84{
85}
86
87void AI_Dialog::rescuehelp_pressed()
88{
89 setHelpText("rescue");
90}
91
92void AI_Dialog::rescuehelp_released()
93{
94 setHelpText();
95}
96
97void AI_Dialog::eliminatehelp_pressed()
98{
99 setHelpText("eliminate");
100}
101
102void AI_Dialog::eliminatehelp_released()
103{
104 setHelpText();
105}
106
107void AI_Dialog::exposehelp_pressed()
108{
109 setHelpText("expose");
110}
111
112void AI_Dialog::exposehelp_released()
113{
114 setHelpText();
115}
116
117void AI_Dialog::protecthelp_pressed()
118{
119 setHelpText("protect");
120}
121
122void AI_Dialog::protecthelp_released()
123{
124 setHelpText();
125}
126
127void AI_Dialog::safehelp_pressed()
128{
129 setHelpText("safe");
130}
131
132void AI_Dialog::safehelp_released()
133{
134 setHelpText();
135}
136
137void AI_Dialog::emptyhelp_pressed()
138{
139 setHelpText("empty");
140}
141
142void AI_Dialog::emptyhelp_released()
143{
144 setHelpText();
145}
146
147
148
149void AI_Dialog::setDefaultValues()
150{
151 rescue->setValue(6);
152 eliminate->setValue(4);
153 expose->setValue(1);
154 protect->setValue(5);
155 safe->setValue(3);
156 empty->setValue(2);
157}
158
159void AI_Dialog::setAISettings(const AISettings& values)
160{
161 rescue->setValue(values.rescue);
162 eliminate->setValue(values.eliminate);
163 expose->setValue(values.expose);
164 protect->setValue(values.protect);
165 safe->setValue(values.safe);
166 empty->setValue(values.empty);
167}
168
169AISettings AI_Dialog::getAISettings()
170{
171 AISettings ai;
172 ai.rescue=rescue->value();
173 ai.eliminate=eliminate->value();
174 ai.expose=expose->value();
175 ai.protect=protect->value();
176 ai.safe= safe->value();
177 ai.empty=empty->value();
178 return ai;
179}
180
181void AI_Dialog::setHelpText(const QString& type)
182{
183 if(type=="rescue")
184 {
185 help->setText("Bring the pieces out of the endzone");
186 }
187 else if(type=="eliminate")
188 {
189 help->setText("Eliminate an opponents piece");
190 }
191 else if(type=="expose")
192 {
193 help->setText("Expose you own pieces.\nAfter such a move only one piece will remain in the slot");
194 }
195 else if(type=="protect")
196 {
197 help->setText("Protect a single piece by\nputting another one in this slot");
198 }
199 else if(type=="safe")
200 {
201 help->setText("Move piece to a slot already\noccupied by the player");
202 }
203 else if(type=="empty")
204 {
205 help->setText("Move piece to an empty slot");
206 }
207 else
208 {
209 help->setText("Press and hold the ? buttton\nnext to a field for help");
210 }
211}
diff --git a/noncore/games/backgammon/aidialog.h b/noncore/games/backgammon/aidialog.h
new file mode 100644
index 0000000..2597f8b
--- a/dev/null
+++ b/noncore/games/backgammon/aidialog.h
@@ -0,0 +1,48 @@
1#ifndef AIDIALOG_H_
2#define AIDIALOG_H_
3
4#include "moveengine.h"
5
6#include <qdialog.h>
7#include <qlabel.h>
8#include <qpushbutton.h>
9#include <qspinbox.h>
10
11class AI_Dialog : public QDialog
12{
13 Q_OBJECT
14private:
15 //GUI stuff
16 QPushButton* defaultvalues;
17 QSpinBox* rescue;
18 QSpinBox* eliminate;
19 QSpinBox* expose;
20 QSpinBox* protect;
21 QSpinBox* safe;
22 QSpinBox* empty;
23 QLabel* help;
24public:
25 AI_Dialog(QWidget* parent=0,const char* name=0,bool modal=TRUE,WFlags f=0);
26 ~AI_Dialog();
27private slots:
28 void rescuehelp_pressed();
29 void rescuehelp_released();
30 void eliminatehelp_pressed();
31 void eliminatehelp_released();
32 void exposehelp_pressed();
33 void exposehelp_released();
34 void protecthelp_pressed();
35 void protecthelp_released();
36 void safehelp_pressed();
37 void safehelp_released();
38 void emptyhelp_pressed();
39 void emptyhelp_released();
40 void setDefaultValues();
41public:
42 void setAISettings(const AISettings& values);
43 AISettings getAISettings();
44private:
45 void setHelpText(const QString& type="default");
46};
47
48#endif //AIDIALOG_H
diff --git a/noncore/games/backgammon/backgammon.control b/noncore/games/backgammon/backgammon.control
new file mode 100644
index 0000000..528a8c3
--- a/dev/null
+++ b/noncore/games/backgammon/backgammon.control
@@ -0,0 +1,9 @@
1Files: bin/backgammon apps/Games/backgammon.desktop pics/backgammon help/en/html/backgammon.html
2Priority: optional
3Section: opie/games
4Maintainer: Ralf Waspe <rwaspe@web.de>
5Architecture: arm
6Version: $QPE_VERSION-$SUB_VERSION
7Depends: opie-base
8Description: Backgammon Game
9 A Backgammon game for the Opie environment.
diff --git a/noncore/games/backgammon/backgammon.cpp b/noncore/games/backgammon/backgammon.cpp
new file mode 100644
index 0000000..38ccb49
--- a/dev/null
+++ b/noncore/games/backgammon/backgammon.cpp
@@ -0,0 +1,1043 @@
1#include "backgammon.h"
2
3#include "aidialog.h"
4#include "displaydialog.h"
5#include "filedialog.h"
6#include "playerdialog.h"
7#include "rulesdialog.h"
8#include "themedialog.h"
9
10#include <qdatetime.h>
11#include <qfile.h>
12#include <qmessagebox.h>
13#include <qstring.h>
14#include <qtimer.h>
15#include <qpe/qpeapplication.h>
16#include <qpe/config.h>
17#include <qpe/qpemenubar.h>
18#include <qpe/resource.h>
19
20#include <stdlib.h>
21
22BackGammonView::BackGammonView(QCanvas* canvas,QWidget* parent)
23 :QCanvasView(canvas,parent)
24{
25 //do nothing
26}
27
28
29
30BackGammonView::~BackGammonView()
31{
32 //do nothing
33}
34
35
36
37void BackGammonView::contentsMousePressEvent(QMouseEvent* e)
38{
39 int x=e->x();
40 int y=e->y();
41 emit mouse(x,y);
42}
43
44BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl)
45 : QWidget(parent, name, fl)
46{
47 if (!name) setName("BackGammon");
48 setCaption("Backgammon");
49 setIcon( Resource::loadPixmap( "backgammon" ) );
50 //general counter varaible
51 int a=0;
52 //the game engine
53 move=new MoveEngine();
54
55 //load the default theme
56 Config conf("backgammon");
57 if(!conf.isValid())
58 {
59 qDebug("config file does not exist");
60 conf.setGroup("general");
61 conf.writeEntry("theme","default");
62 conf.setGroup("rules");
63 conf.writeEntry("move_with_pieces_out",false);
64 conf.writeEntry("nice_dice",false);
65 conf.setGroup("display");
66 conf.writeEntry("small",false);
67 conf.writeEntry("warning",true);
68 conf.setGroup("ai");
69 conf.writeEntry("rescue",6);
70 conf.writeEntry("eliminate",4);
71 conf.writeEntry("expose",1);
72 conf.writeEntry("protect",5);
73 conf.writeEntry("safe",3);
74 conf.writeEntry("empty",2);
75
76 }
77 conf.setGroup("general");
78 theme_name=conf.readEntry("theme","default");
79 QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme";
80
81 //the rules
82 conf.setGroup("rules");
83 rules.move_with_pieces_out=conf.readBoolEntry("move_with_pieces_out",false);
84 rules.generous_dice=conf.readBoolEntry("nice_dice",false);
85
86 move->setRules(rules);
87
88 //get the AI settings
89 AISettings ai;
90 conf.setGroup("ai");
91 ai.rescue=conf.readNumEntry("rescue",6);
92 ai.eliminate=conf.readNumEntry("eliminate",4);
93 ai.expose=conf.readNumEntry("expose",1);
94 ai.protect=conf.readNumEntry("protect",5);
95 ai.safe=conf.readNumEntry("safe",3);
96 ai.empty=conf.readNumEntry("empty",2);
97 move->setAISettings(ai);
98
99 //non qte styles are smaller
100 conf.setGroup("display");
101 display.small=conf.readBoolEntry("small",false);
102 display.warning=conf.readBoolEntry("warning",true);
103 non_qte=display.small;
104 if(display.warning)
105 {
106 Config test("qpe");
107 test.setGroup("Appearance");
108 if(test.readEntry("Style")!="QPE")
109 {
110 displaySettings();
111 }
112 }
113 offset=(non_qte) ? 5 : 0;
114
115 //get the theme component names
116 Config theme(theme_file,Config::File);
117 if(!theme.isValid())
118 {
119 qDebug("theme file does not exist");
120 theme.setGroup("theme");
121 theme.writeEntry("board","casino_board_1");
122 theme.writeEntry("pieces1","casino_pieces_blue");
123 theme.writeEntry("pieces2","casino_pieces_white");
124 theme.writeEntry("dice1","casino_dice");
125 theme.writeEntry("dice2","casino_dice");
126 theme.writeEntry("table","casino_table_green");
127 theme.writeEntry("odds","casino_odds");
128 }
129 theme.setGroup("theme");
130 board_name=theme.readEntry("board","casino_board_1");
131 piecesA_name=theme.readEntry("pieces1","casino_pieces_blue");
132 piecesB_name=theme.readEntry("pieces2","casino_pieces_white");
133 diceA_name=theme.readEntry("dice1","casino_dice");
134 diceB_name=theme.readEntry("dice2","casino_dice");
135 table_name=theme.readEntry("table","casino_table_green");
136 odds_name=theme.readEntry("odds","casino_odds");
137
138
139 //the menu
140 QPEMenuBar* menuBar = new QPEMenuBar(this);
141
142 QPopupMenu* gamemenu= new QPopupMenu(this);
143 gamemenu->insertItem("New",this,SLOT(newgame()));
144 gamemenu->insertSeparator();
145 gamemenu->insertItem("Load",this,SLOT(loadgame()));
146 gamemenu->insertItem("Save",this,SLOT(savegame()));
147 gamemenu->insertSeparator();
148 gamemenu->insertItem("Delete",this,SLOT(deletegame()));
149 menuBar->insertItem("Game",gamemenu);
150
151 QPopupMenu* thememenu= new QPopupMenu(this);
152 thememenu->insertItem("New",this,SLOT(newtheme()));
153 thememenu->insertSeparator();
154 thememenu->insertItem("Load",this,SLOT(loadtheme()));
155 thememenu->insertItem("Save",this,SLOT(savetheme()));
156 thememenu->insertSeparator();
157 thememenu->insertItem("Default",this,SLOT(themedefault()));
158 thememenu->insertItem("Delete",this,SLOT(deletetheme()));
159 menuBar->insertItem("Theme",thememenu);
160
161 QPopupMenu* optionmenu=new QPopupMenu(this);
162 optionmenu->insertItem("Player",this,SLOT(playerselect()));
163 optionmenu->insertSeparator();
164 optionmenu->insertItem("AI",this,SLOT(modify_AI()));
165 optionmenu->insertItem("Rules",this,SLOT(setrules()));
166 optionmenu->insertItem("Display",this,SLOT(displaySettings()));
167 menuBar->insertItem("Options",optionmenu);
168
169 //status bar
170 message=new QLabel("<b>Backgammon</b>",this);
171 message->setGeometry(0,260,237,20);
172 message->setAlignment(AlignHCenter);
173
174 //the main area
175 area=new QCanvas(235-2*offset,235-2*offset);
176 boardview=new BackGammonView(area,this);
177 connect(boardview,SIGNAL(mouse(int,int)),this,SLOT(mouse(int,int)));
178 if(non_qte)
179 {
180 boardview->setGeometry(5,20,229,229);
181 }
182 else
183 {
184 boardview->setGeometry(1,20,237,237);
185 }
186
187 //the marker
188 marker_current=new QCanvasRectangle(area);
189 marker_current->setBrush(QColor(0,0,255));
190 marker_current->setSize(15,5);
191 marker_current->setZ(1);
192
193 for(a=0;a<4;a++)
194 {
195 marker_next[a]=new QCanvasRectangle(area);
196 marker_next[a]->setBrush(QColor(0,255,0));
197 marker_next[a]->setSize(15,5);
198 marker_next[a]->setZ(1);
199 }
200
201 connect(move,SIGNAL(done_dice1()),this,SLOT(done_dice1()));
202 connect(move,SIGNAL(done_dice2()),this,SLOT(done_dice2()));
203 connect(move,SIGNAL(done_dice3()),this,SLOT(done_dice3()));
204 connect(move,SIGNAL(done_dice4()),this,SLOT(done_dice4()));
205 connect(move,SIGNAL(nomove()),this,SLOT(nomove()));
206 connect(move,SIGNAL(player_finished(int)),this,SLOT(finished(int)));
207
208 //the pieces
209 p1=new CanvasImageItem*[15];
210 p1_side=new CanvasImageItem*[15];
211 QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name));
212 QImage piece_1_front=piece_1_all.copy(0,0,15,15);
213 QImage piece_1_side=piece_1_all.copy(0,15,15,5);
214
215 p2=new CanvasImageItem*[15];
216 p2_side=new CanvasImageItem*[15];
217 QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name));
218 QImage piece_2_front=piece_2_all.copy(0,0,15,15);
219 QImage piece_2_side=piece_2_all.copy(0,15,15,5);
220
221
222 for(a=0;a<15;a++)
223 {
224 p1[a]=new CanvasImageItem(piece_1_front,area);
225 p1[a]->setSize(15,15);
226 p1_side[a]=new CanvasImageItem(piece_1_side,area);
227 p1_side[a]->setSize(15,5);
228
229 p2[a]=new CanvasImageItem(piece_2_front,area);
230 p2[a]->setSize(15,15);
231 p2_side[a]=new CanvasImageItem(piece_2_side,area);
232 p2_side[a]->setSize(15,5);
233 }
234 draw();
235
236 //the dice
237 QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name));
238 diceA1=new CanvasImageItem*[7];
239 diceA2=new CanvasImageItem*[7];
240 QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name));
241 diceB1=new CanvasImageItem*[7];
242 diceB2=new CanvasImageItem*[7];
243 QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name));
244 //oddsDice=new CanvasImageItem*[6];
245
246
247 for(a=0;a<7;a++)
248 {
249 QImage dicebgA=dicebgA_all.copy(a*25,0,25,25);
250 diceA1[a]=new CanvasImageItem(dicebgA,area);
251 diceA1[a]->setX(5-offset);
252 diceA1[a]->setY(205-2*offset);
253 diceA1[a]->setZ(1);
254 diceA1[a]->setSize(25,25);
255 diceA2[a]=new CanvasImageItem(dicebgA,area);
256 diceA2[a]->setX(35-offset);
257 diceA2[a]->setY(205-2*offset);
258 diceA2[a]->setZ(1);
259 diceA2[a]->setSize(25,25);
260
261 QImage dicebgB=dicebgB_all.copy(a*25,0,25,25);
262 diceB1[a]=new CanvasImageItem(dicebgB,area);
263 diceB1[a]->setX(175-offset);
264 diceB1[a]->setY(205-2*offset);
265 diceB1[a]->setZ(1);
266 diceB1[a]->setSize(25,25);
267 diceB2[a]=new CanvasImageItem(dicebgB,area);
268 diceB2[a]->setX(205-offset);
269 diceB2[a]->setY(205-2*offset);
270 diceB2[a]->setZ(1);
271 diceB2[a]->setSize(25,25);
272
273 /*
274 if(a<6)
275 {
276 QImage oddsbg=oddsbg_all.copy(a*15,0,15,15);
277 oddsDice[a]=new CanvasImageItem(oddsbg,area);
278 oddsDice[a]->setX(110-offset);
279 oddsDice[a]->setY(210-2*offset);
280 oddsDice[a]->setZ(1);
281 oddsDice[a]->setSize(15,15);
282 oddsDice[a]->hide();
283 }
284 */
285 }
286 //oddsDice[0]->show();
287
288 //set the board
289 QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name));
290 if(non_qte)
291 {
292 boardbg=boardbg.copy(offset,offset,235-2*offset,200-2*offset);
293 }
294 board=new CanvasImageItem(boardbg,area);
295 board->setX(0);
296 board->setY(0);
297 board->setZ(0);
298 board->setSize(235-2*offset,200-2*offset);
299 board->show();
300
301 //the table
302 QImage tablebg(Resource::loadImage("backgammon/table/"+table_name));
303 if(non_qte)
304 {
305 tablebg=tablebg.copy(offset,0,235-offset,200);
306 }
307 table=new CanvasImageItem(tablebg,area);
308 table->setX(0);
309 table->setY(200-2*offset);
310 table->setZ(0);
311 table->setSize(235-2*offset,20);
312 table->show();
313
314 //the no move marker
315 QImage nomovebg(Resource::loadImage("backgammon/no_move"));
316 nomove_marker=new CanvasImageItem(nomovebg,area);
317 nomove_marker->setX(0);
318 nomove_marker->setY(200);
319 nomove_marker->setZ(2);
320 nomove_marker->hide();
321
322 //default human against computer
323 player1_auto=false;
324 player2_auto=true;
325 //start new game
326 newgame();
327}
328
329BackGammon::~BackGammon()
330{
331 //DESTRUCTOR
332}
333
334void BackGammon::newgame()
335{
336 gameFinished=false;
337 QDateTime now=QDateTime::currentDateTime();
338 game_name=now.date().toString()+"_"+now.time().toString();
339 move->reset();
340 draw();
341 diceA1_value=7;
342 diceA2_value=7;
343 diceA3_value=7;
344 diceA4_value=7;
345 diceB1_value=7;
346 diceB2_value=7;
347 diceB3_value=7;
348 diceB4_value=7;
349 showdice();
350 player=2;
351 dice1_played=true;
352 dice2_played=true;
353 dice3_played=true;
354 dice4_played=true;
355 dice_rolled=false;
356 setplayer();
357 area->update();
358}
359
360void BackGammon::playerselect()
361{
362 PlayerDialog* playerdialog=new PlayerDialog(this);
363 playerdialog->setAuto1(player1_auto);
364 playerdialog->setAuto2(player2_auto);
365 if(!playerdialog->exec())
366 return;
367 player1_auto=playerdialog->getAuto1();
368 player2_auto=playerdialog->getAuto2();
369}
370
371void BackGammon::loadgame()
372{
373 FileDialog* file=new FileDialog(this,"Load Game",".game");
374 if(!file->exec())
375 return;
376
377 game_name=file->filename();
378 QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game";
379
380 Config game(game_file,Config::File);
381 game.setGroup("dice");
382 diceA1_value=game.readNumEntry("diceA1_value");
383 diceA2_value=game.readNumEntry("diceA2_value");
384 diceA3_value=game.readNumEntry("diceA3_value");
385 diceA4_value=game.readNumEntry("diceA4_value");
386 diceB1_value=game.readNumEntry("diceB1_value");
387 diceB2_value=game.readNumEntry("diceB2_value");
388 diceB3_value=game.readNumEntry("diceB3_value");
389 diceB4_value=game.readNumEntry("diceB4_value");
390 player=game.readNumEntry("player");
391 dice1_played=game.readBoolEntry("dice1_played");
392 dice2_played=game.readBoolEntry("dice2_played");
393 dice3_played=game.readBoolEntry("dice3_played");
394 dice4_played=game.readBoolEntry("dice4_played");
395 dice_rolled=game.readBoolEntry("dice_rolled");
396 player1_auto=game.readBoolEntry("player1_auto");
397 player2_auto=game.readBoolEntry("player2_auto");
398
399 game.setGroup("pieces");
400 QString label;
401 LoadSave load;
402 for(int a=0;a<28;a++)
403 {
404 label.setNum(a);
405 load.pop[a].total = game.readNumEntry(label,0);
406 }
407
408 move->loadGame(load);
409 setplayer();
410 showdice();
411 draw();
412 area->update();
413}
414
415void BackGammon::savegame()
416{
417 QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game";
418
419 Config game(game_file,Config::File);
420 game.setGroup("dice");
421 game.writeEntry("diceA1_value",diceA1_value);
422 game.writeEntry("diceA2_value",diceA2_value);
423 game.writeEntry("diceA3_value",diceA3_value);
424 game.writeEntry("diceA4_value",diceA4_value);
425 game.writeEntry("diceB1_value",diceB1_value);
426 game.writeEntry("diceB2_value",diceB3_value);
427 game.writeEntry("diceB3_value",diceB4_value);
428 game.writeEntry("diceB4_value",diceB4_value);
429 game.writeEntry("player",player);
430 game.writeEntry("dice1_played",dice1_played);
431 game.writeEntry("dice2_played",dice2_played);
432 game.writeEntry("dice3_played",dice3_played);
433 game.writeEntry("dice4_played",dice4_played);
434 game.writeEntry("dice_rolled",dice_rolled);
435 game.writeEntry("player1_auto",player1_auto);
436 game.writeEntry("player2_auto",player2_auto);
437
438 game.setGroup("pieces");
439 QString label;
440 LoadSave save=move->saveGame();
441 for(int a=0;a<28;a++)
442 {
443 label.setNum(a);
444 game.writeEntry(label,save.pop[a].total);
445 }
446 QMessageBox::information(this,"Backgammon","Game saved","OK");
447}
448
449void BackGammon::deletegame()
450{
451 FileDialog* file=new FileDialog(this,"Delete Game",".game");
452 if(!file->exec())
453 return;
454
455 game_name=file->filename();
456 QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game";
457
458 if(!QMessageBox::warning(this,"Backgammon","deleted game\n"+game_name+" ?","OK","Cancel"))
459 {
460 QFile(game_file).remove();
461 }
462}
463
464
465void BackGammon::newtheme()
466{
467 ThemeDialog* theme=new ThemeDialog(this);
468
469 ImageNames names;
470 names.theme=theme_name;
471 names.board=board_name;
472 names.pieces1=piecesA_name;
473 names.pieces2=piecesB_name;
474 names.dice1=diceA_name;
475 names.dice2=diceB_name;
476 names.odds=odds_name;
477 names.table=table_name;
478
479 theme->setCurrent(names);
480 if(!theme->exec())
481 return;
482
483 names=theme->getNames();
484 theme_name=names.theme;
485 board_name=names.board;
486 piecesA_name=names.pieces1;
487 piecesB_name=names.pieces2;
488 diceA_name=names.dice1;
489 diceB_name=names.dice2;
490 odds_name=names.odds;
491 table_name=names.table;
492
493 applytheme();
494}
495
496void BackGammon::loadtheme()
497{
498 FileDialog* file=new FileDialog(this,"Load Theme",".theme");
499 if(!file->exec())
500 return;
501
502 theme_name=file->filename();
503 QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme";
504
505 Config theme(theme_file,Config::File);
506 theme.setGroup("theme");
507 board_name=theme.readEntry("board","board_1");
508 piecesA_name=theme.readEntry("pieces1","pieces_1");
509 piecesB_name=theme.readEntry("pieces2","pieces_2");
510 diceA_name=theme.readEntry("dice1","dice_1");
511 diceB_name=theme.readEntry("dice2","dice_2");
512 table_name=theme.readEntry("table","table_1");
513 odds_name=theme.readEntry("odds","odds_1");
514
515 applytheme();
516
517}
518
519void BackGammon::savetheme()
520{
521 if(theme_name=="default")
522 {
523 QMessageBox::information(this,"Backgammon","Sorry\nCannot overwrite default.theme","OK");
524 return;
525 }
526 QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme";
527 if(QMessageBox::information(this,"Backgammon","Save Theme\n"+theme_name,"Yes","No"))
528 return;
529
530 Config theme(theme_file,Config::File);
531 theme.setGroup("theme");
532 theme.writeEntry("board",board_name);
533 theme.writeEntry("pieces1",piecesA_name);
534 theme.writeEntry("pieces2",piecesB_name);
535 theme.writeEntry("dice1",diceA_name);
536 theme.writeEntry("dice2",diceB_name);
537 theme.writeEntry("table",table_name);
538 theme.writeEntry("odds",odds_name);
539
540}
541
542void BackGammon::themedefault()
543{
544 if(QMessageBox::information(this,"Backgammon","Make Theme\n"+theme_name+"\nthe default theme","Yes","No"))
545 return;
546
547 Config conf("backgammon");
548 conf.setGroup("general");
549 conf.writeEntry("theme",theme_name);
550}
551
552void BackGammon::deletetheme()
553{
554 FileDialog* file=new FileDialog(this,"Delete Theme",".theme");
555 if(!file->exec())
556 return;
557
558 theme_name=file->filename();
559 QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme";
560
561 if(!QMessageBox::warning(this,"Backgammon","deleted theme "+theme_name+" ?","OK","Cancel"))
562 {
563 QFile(theme_file).remove();
564 }
565}
566
567void BackGammon::modify_AI()
568{
569 AI_Dialog* ai_mod=new AI_Dialog(this,"Load Theme",".theme");
570 ai_mod->setAISettings(move->getAISettings());
571 if(!ai_mod->exec())
572 return;
573
574 //get the AI settings
575 AISettings ai=ai_mod->getAISettings();
576 move->setAISettings(ai);
577 //write new settings to conf file
578 Config conf("backgammon");
579 conf.setGroup("ai");
580 conf.writeEntry("rescue",ai.rescue);
581 conf.writeEntry("eliminate",ai.eliminate);
582 conf.writeEntry("expose",ai.expose);
583 conf.writeEntry("protect",ai.protect);
584 conf.writeEntry("safe",ai.safe);
585 conf.writeEntry("empty",ai.empty);
586}
587
588void BackGammon::setrules()
589{
590 RulesDialog* rulesdialog=new RulesDialog(this,"Load Theme",".theme");
591 rulesdialog->setRules(rules);
592 if(!rulesdialog->exec())
593 return;
594 rules=rulesdialog->getRules();
595 Config conf("backgammon");
596 conf.setGroup("rules");
597 conf.writeEntry("move_with_pieces_out",rules.move_with_pieces_out);
598 conf.writeEntry("nice_dice",rules.generous_dice);
599 move->setRules(rules);
600}
601
602void BackGammon::displaySettings()
603{
604 DisplayDialog* displaydialog=new DisplayDialog(this);
605 displaydialog->setDisplaySettings(display);
606 if(!displaydialog->exec())
607 return;
608 display=displaydialog->getDisplaySettings();
609 Config conf("backgammon");
610 conf.setGroup("display");
611 conf.writeEntry("small",display.small);
612 conf.writeEntry("warning",display.warning);
613 QMessageBox::warning(this,"Backgammon","changed display settings will\nonly take place after game has\nbeen restarted","OK");
614}
615
616void BackGammon::draw()
617{
618 Pieces pieces;
619 move->position(pieces,non_qte);
620 for(int a=0;a<15;a++)
621 {
622 if(!pieces.player1[a].side)
623 {
624 p1[a]->setX(pieces.player1[a].x);
625 p1[a]->setY(pieces.player1[a].y);
626 p1[a]->setZ(pieces.player1[a].z);
627 p1[a]->show();
628 p1_side[a]->hide();
629 }
630 else
631 {
632 p1_side[a]->setX(pieces.player1[a].x);
633 p1_side[a]->setY(pieces.player1[a].y);
634 p1_side[a]->setZ(pieces.player1[a].z);
635 p1_side[a]->show();
636 p1[a]->hide();
637 }
638
639 if(!pieces.player2[a].side)
640 {
641 p2[a]->setX(pieces.player2[a].x);
642 p2[a]->setY(pieces.player2[a].y);
643 p2[a]->setZ(pieces.player2[a].z);
644 p2[a]->show();
645 p2_side[a]->hide();
646 }
647 else
648 {
649 p2_side[a]->setX(pieces.player2[a].x);
650 p2_side[a]->setY(pieces.player2[a].y);
651 p2_side[a]->setZ(pieces.player2[a].z);
652 p2_side[a]->show();
653 p2[a]->hide();
654 }
655 }
656}
657
658void BackGammon::mouse(int x,int y)
659{
660 if(gameFinished)
661 {
662 newgame();
663 return;
664 }
665 if(y<=200) //move pieces
666 {
667 if((player==1 && player1_auto) || (player==2 && player2_auto))
668 return;
669
670 Marker marker;
671
672 move->boardpressed(x,y,marker,non_qte);
673 if(marker.visible_current)
674 {
675 marker_current->setX(marker.x_current-offset);
676 marker_current->setY(marker.y_current);
677 marker_current->show();
678 }
679 else
680 {
681 marker_current->hide();
682 }
683
684 for(int a=0;a<4;a++)
685 {
686 if(marker.visible_next[a])
687 {
688 marker_next[a]->setX(marker.x_next[a]-offset);
689 marker_next[a]->setY(marker.y_next[a]);
690 marker_next[a]->show();
691 }
692 else
693 {
694 marker_next[a]->hide();
695 }
696 }
697 area->update();
698 }
699 else //roll dice
700 {
701 if(x>=10 && x<=65 && player==1 && !dice_rolled)
702 {
703 dice1_played=false;
704 dice2_played=false;
705 dice3_played=false;
706 dice4_played=false;
707 dice_rolled=true;
708 srand(QTime::currentTime().msec());
709 diceA1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0));
710 diceA2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0));
711 if(diceA1_value==diceA2_value)
712 {
713 diceA3_value=diceA1_value;
714 diceA4_value=diceA1_value;
715 }
716 else
717 {
718 diceA3_value=7;
719 dice3_played=true;
720 diceA4_value=7;
721 dice4_played=true;
722 }
723 showdice();
724 area->update();
725 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto);
726
727 }
728 else if(x>=160 && x<=225 && player==2 && !dice_rolled)
729 {
730 dice1_played=false;
731 dice2_played=false;
732 dice3_played=false;
733 dice4_played=false;
734 dice_rolled=true;
735 srand(QTime::currentTime().msec());
736 diceB1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0));
737 diceB2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0));
738 if(diceB1_value==diceB2_value)
739 {
740 diceB3_value=diceB1_value;
741 diceB4_value=diceB1_value;
742 }
743 else
744 {
745 diceB3_value=7;
746 dice3_played=true;
747 diceB4_value=7;
748 dice4_played=true;
749 }
750 showdice();
751 area->update();
752 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto);
753 }
754 }
755}
756
757void BackGammon::done_dice1()
758{
759 dice1_played=true;
760 if(player==1)
761 diceA1_value=7;
762 else
763 diceB1_value=7;
764 setplayer();
765 showdice();
766 draw();
767 area->update();
768 if(!dice2_played || !dice3_played || !dice4_played)
769 {
770 if(player==1)
771 {
772 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto);
773 }
774 else
775 {
776 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto);
777 }
778 }
779}
780
781void BackGammon::done_dice2()
782{
783 dice2_played=true;
784 if(player==1)
785 diceA2_value=7;
786 else
787 diceB2_value=7;
788 setplayer();
789 showdice();
790 draw();
791 area->update();
792 if(!dice1_played || !dice3_played || !dice4_played)
793 {
794 if(player==1)
795 {
796 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto);
797 }
798 else
799 {
800 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto);
801 }
802 }
803}
804
805
806void BackGammon::done_dice3()
807{
808 dice3_played=true;
809 if(player==1)
810 diceA3_value=7;
811 else
812 diceB3_value=7;
813 setplayer();
814 showdice();
815 draw();
816 area->update();
817 if(!dice1_played || !dice2_played || !dice4_played)
818 {
819 if(player==1)
820 {
821 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto);
822 }
823 else
824 {
825 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto);
826 }
827 }
828}
829
830
831void BackGammon::done_dice4()
832{
833 dice4_played=true;
834 if(player==1)
835 diceA4_value=7;
836 else
837 diceB4_value=7;
838 setplayer();
839 showdice();
840 draw();
841 area->update();
842 if(!dice1_played || !dice2_played || !dice3_played)
843 {
844 if(player==1)
845 {
846 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto);
847 }
848 else
849 {
850 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto);
851 }
852 }
853}
854
855
856void BackGammon::nomove()
857{
858 if(player==1)
859 nomove_marker->setX(0);
860 else
861 nomove_marker->setX(170);
862 nomove_marker->show();
863 message->setText("<b>no move</b>");
864 dice1_played=true;
865 dice2_played=true;
866 dice3_played=true;
867 dice4_played=true;
868 if(player==1)
869 {
870 diceA1_value=7;
871 diceA2_value=7;
872 diceA3_value=7;
873 diceA4_value=7;
874 }
875 else
876 {
877 diceB1_value=7;
878 diceB2_value=7;
879 diceB3_value=7;
880 diceB4_value=7;
881 }
882 area->update();
883 QTimer::singleShot(2000,this,SLOT(nomove2()));
884}
885
886void BackGammon::nomove2()
887{
888 nomove_marker->hide();
889 setplayer();
890 showdice();
891 draw();
892 area->update();
893}
894
895void BackGammon::finished(int theplayer)
896{
897 nomove_marker->hide();
898 if(theplayer==1)
899 message->setText("<b>Player 1 wins. Click on board for new game.</b>");
900 else
901 message->setText("<b>Player 2 wins. Click on board for new game.</b>");
902 diceA1_value=7;
903 diceA2_value=7;
904 diceB1_value=7;
905 diceB2_value=7;
906 player=0;
907 showdice();
908 draw();
909 area->update();
910 gameFinished=true;
911}
912
913void BackGammon::showdice()
914{
915 int value_diceA1=diceA1_value-1;
916 if(diceA1_value==7 && diceA3_value!=7)
917 value_diceA1=diceA3_value-1;
918
919 int value_diceA2=diceA2_value-1;
920 if(diceA2_value==7 && diceA4_value!=7)
921 value_diceA2=diceA4_value-1;
922
923 int value_diceB1=diceB1_value-1;
924 if(diceB1_value==7 && diceB3_value!=7)
925 value_diceB1=diceB3_value-1;
926
927 int value_diceB2=diceB2_value-1;
928 if(diceB2_value==7 && diceB4_value!=7)
929 value_diceB2=diceB4_value-1;
930
931 for(int index=0;index<7;index++)
932 {
933 if(value_diceA1==index)
934 diceA1[index]->show();
935 else
936 diceA1[index]->hide();
937
938 if(value_diceA2==index)
939 diceA2[index]->show();
940 else
941 diceA2[index]->hide();
942
943 if(value_diceB1==index)
944 diceB1[index]->show();
945 else
946 diceB1[index]->hide();
947
948 if(value_diceB2==index)
949 diceB2[index]->show();
950 else
951 diceB2[index]->hide();
952 }
953}
954
955void BackGammon::setplayer()
956{
957 if(dice1_played && dice2_played && dice3_played && dice4_played && player==1)
958 {
959 message->setText("<b>P2 turn</b>");
960 dice_rolled=false;
961 player=2;
962 if(player2_auto)
963 QTimer::singleShot(2000,this,SLOT(autoroll_dice2()));
964 }
965 else if(dice1_played && dice2_played && dice3_played && dice4_played && player==2)
966 {
967 message->setText("<b>P1 turn</b>");
968 dice_rolled=false;
969 player=1;
970 if(player1_auto)
971 QTimer::singleShot(2000,this,SLOT(autoroll_dice1()));
972 }
973}
974
975void BackGammon::autoroll_dice1()
976{
977 mouse(20,210);
978}
979
980void BackGammon::autoroll_dice2()
981{
982 mouse(170,210);
983}
984
985void BackGammon::applytheme()
986{
987 QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name));
988 if(non_qte)
989 {
990 boardbg=boardbg.copy(offset,offset,235-2*offset,200-2*offset);
991 }
992 board->setImage(boardbg);
993
994 QImage tablebg(Resource::loadImage("backgammon/table/"+table_name));
995 if(non_qte)
996 {
997 tablebg=tablebg.copy(offset,0,235-offset,200);
998 }
999 table->setImage(tablebg);
1000
1001 QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name));
1002 QImage piece_1_front=piece_1_all.copy(0,0,15,15);
1003 QImage piece_1_side=piece_1_all.copy(0,15,15,5);
1004
1005 QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name));
1006 QImage piece_2_front=piece_2_all.copy(0,0,15,15);
1007 QImage piece_2_side=piece_2_all.copy(0,15,15,5);
1008
1009 int a=0;
1010 for(a=0;a<15;a++)
1011 {
1012 p1[a]->setImage(piece_1_front);
1013 p1_side[a]->setImage(piece_1_side);
1014
1015 p2[a]->setImage(piece_2_front);
1016 p2_side[a]->setImage(piece_2_side);
1017 }
1018 draw();
1019
1020 QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name));
1021 QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name));
1022 QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name));
1023
1024 for(a=0;a<7;a++)
1025 {
1026 QImage dicebgA=dicebgA_all.copy(a*25,0,25,25);
1027 diceA1[a]->setImage(dicebgA);
1028 diceA2[a]->setImage(dicebgA);
1029
1030 QImage dicebgB=dicebgB_all.copy(a*25,0,25,25);
1031 diceB1[a]->setImage(dicebgB);
1032 diceB2[a]->setImage(dicebgB);
1033 /*
1034 if(a<6)
1035 {
1036 QImage oddsbg=oddsbg_all.copy(a*15,0,15,15);
1037 oddsDice[a]->setImage(oddsbg);
1038 }
1039 */
1040 }
1041}
1042
1043
diff --git a/noncore/games/backgammon/backgammon.h b/noncore/games/backgammon/backgammon.h
new file mode 100644
index 0000000..40dbaba
--- a/dev/null
+++ b/noncore/games/backgammon/backgammon.h
@@ -0,0 +1,134 @@
1#ifndef BACKGAMMON_H
2#define BACKGAMMON_H
3
4#include "canvasimageitem.h"
5#include "definition.h"
6//#include "rulesdialog.h"
7#include "moveengine.h"
8
9#include <qcanvas.h>
10#include <qlabel.h>
11#include <qlineedit.h>
12#include <qwidget.h>
13
14
15class BackGammonView : public QCanvasView
16{
17 Q_OBJECT
18public:
19 BackGammonView(QCanvas* canvas,QWidget* parent);
20 ~BackGammonView();
21signals:
22 void mouse(int,int);
23private:
24 void contentsMousePressEvent(QMouseEvent* e);
25};
26
27class BackGammon : public QWidget
28{
29 Q_OBJECT
30private:
31 //GUI
32 //is the style not qte ?
33 bool non_qte;
34 int offset;
35 //the "status" bar
36 QLineEdit* inputfield;
37 //the main drawing area
38 QCanvas* area;
39 BackGammonView* boardview;
40 CanvasImageItem* board;
41 CanvasImageItem* table;
42 CanvasImageItem** p1;
43 CanvasImageItem** p2;
44 CanvasImageItem** p1_side;
45 CanvasImageItem** p2_side;
46
47 CanvasImageItem** diceA1;
48 CanvasImageItem** diceA2;
49 CanvasImageItem** diceB1;
50 CanvasImageItem** diceB2;
51 //CanvasImageItem** oddsDice;
52 CanvasImageItem* nomove_marker;
53
54 QCanvasRectangle* marker_current;
55 QCanvasRectangle* marker_next[4];
56 QLabel* message;
57 //ENGINE
58 MoveEngine* move;
59 //the dice values
60 int diceA1_value;
61 int diceA2_value;
62 int diceA3_value;
63 int diceA4_value;
64 int diceB1_value;
65 int diceB2_value;
66 int diceB3_value;
67 int diceB4_value;
68
69 int player;
70 bool dice1_played;
71 bool dice2_played;
72 bool dice3_played;
73 bool dice4_played;
74 bool dice_rolled;
75 //computer opponent
76 bool player1_auto;
77 bool player2_auto;
78
79 //the images;
80 QString theme_name;
81 QString board_name;
82 QString piecesA_name;
83 QString piecesB_name;
84 QString diceA_name;
85 QString diceB_name;
86 QString odds_name;
87 QString table_name;
88
89 //save game
90 QString game_name;
91
92 //the rules
93 Rules rules;
94
95 //display settings
96 Display display;
97 //is the game finished ?
98 bool gameFinished;
99
100public:
101 BackGammon( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
102 ~BackGammon();
103private slots:
104 void newgame();
105 void playerselect();
106 void loadgame();
107 void savegame();
108 void deletegame();
109 void newtheme();
110 void loadtheme();
111 void savetheme();
112 void themedefault();
113 void deletetheme();
114 void modify_AI();
115 void setrules();
116 void displaySettings();
117 void mouse(int x,int y);
118 void done_dice1();
119 void done_dice2();
120 void done_dice3();
121 void done_dice4();
122 void nomove();
123 void nomove2();
124 void finished(int theplayer);
125 void autoroll_dice1();
126 void autoroll_dice2();
127private:
128 void draw();
129 void showdice();
130 void setplayer();
131 void applytheme();
132};
133
134#endif //BACKGAMMON_H
diff --git a/noncore/games/backgammon/backgammon.pro b/noncore/games/backgammon/backgammon.pro
new file mode 100644
index 0000000..6f77a14
--- a/dev/null
+++ b/noncore/games/backgammon/backgammon.pro
@@ -0,0 +1,34 @@
1 TEMPLATE = app
2 CONFIG = qt warn_on release
3
4HEADERS = backgammon.h \
5 canvasimageitem.h \
6 themedialog.h \
7 moveengine.h \
8 filedialog.h \
9 playerdialog.h \
10 aidialog.h \
11 rulesdialog.h \
12 displaydialog.h \
13 definition.h
14
15SOURCES = main.cpp \
16 backgammon.cpp \
17 canvasimageitem.cpp \
18 themedialog.cpp \
19 moveengine.cpp \
20 filedialog.cpp \
21 playerdialog.cpp \
22 aidialog.cpp \
23 rulesdialog.cpp \
24 displaydialog.cpp \
25 definition.cpp
26
27 TARGET = backgammon
28 INCLUDEPATH+= $(OPIEDIR)/include
29 DEPENDPATH+= $(OPIEDIR)/include
30 LIBS += -lqpe -lstdc++
31 DESTDIR = $(OPIEDIR)/bin
32
33
34include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/games/backgammon/backgammonview.cpp b/noncore/games/backgammon/backgammonview.cpp
new file mode 100644
index 0000000..ecbc12b
--- a/dev/null
+++ b/noncore/games/backgammon/backgammonview.cpp
@@ -0,0 +1,17 @@
1#include "backgammonview.h"
2
3BackGammonView::BackGammonView(QCanvas* canvas,QWidget* parent)
4 :QCanvasView(canvas,parent)
5{
6}
7
8BackGammonView::~BackGammonView()
9{
10}
11
12void BackGammonView::contentsMousePressEvent(QMouseEvent* e)
13{
14 int x=e->x();
15 int y=e->y();
16 //emit mousepressed(x,y);
17} \ No newline at end of file
diff --git a/noncore/games/backgammon/backgammonview.h b/noncore/games/backgammon/backgammonview.h
new file mode 100644
index 0000000..e50f2b0
--- a/dev/null
+++ b/noncore/games/backgammon/backgammonview.h
@@ -0,0 +1,18 @@
1#ifndef BACKGAMMONVIEW_H
2#define BACKGAMMONVIEW_H
3
4#include <qcanvas.h>
5
6class BackGammonView : public QCanvasView
7{
8 Q_OBJECT
9public:
10 BackGammonView(QCanvas* canvas,QWidget* parent);
11 ~BackGammonView();
12signals:
13 //void mousepressed(int,int);
14private:
15 void contentsMousePressEvent(QMouseEvent* e);
16};
17
18#endif //BACKGAMMONVIEW_H \ No newline at end of file
diff --git a/noncore/games/backgammon/canvasimageitem.cpp b/noncore/games/backgammon/canvasimageitem.cpp
new file mode 100644
index 0000000..8d0297c
--- a/dev/null
+++ b/noncore/games/backgammon/canvasimageitem.cpp
@@ -0,0 +1,23 @@
1#include "canvasimageitem.h"
2
3CanvasImageItem::CanvasImageItem( QImage img, QCanvas *canvas )
4 : QCanvasRectangle( canvas )
5{
6 image=img;
7 setSize( image.width(), image.height() );
8}
9
10CanvasImageItem::~CanvasImageItem()
11{}
12
13
14
15void CanvasImageItem::drawShape( QPainter &p )
16{
17 p.drawImage( int(x()), int(y()), image, 0, 0, -1, -1, OrderedAlphaDither );
18}
19
20void CanvasImageItem::setImage(QImage newImage)
21{
22 image=newImage;
23}
diff --git a/noncore/games/backgammon/canvasimageitem.h b/noncore/games/backgammon/canvasimageitem.h
new file mode 100644
index 0000000..60d5498
--- a/dev/null
+++ b/noncore/games/backgammon/canvasimageitem.h
@@ -0,0 +1,21 @@
1#ifndef CNAVASIMAGEITEM_H
2#define CNAVASIMAGEITEM_H
3
4#include <qcanvas.h>
5#include <qimage.h>
6
7
8class CanvasImageItem: public QCanvasRectangle
9{
10private:
11 QImage image;
12public:
13 CanvasImageItem( QImage img, QCanvas *canvas );
14 ~CanvasImageItem();
15protected:
16 void drawShape( QPainter & );
17public:
18 void setImage(QImage newImage);
19};
20
21#endif //CNAVASIMAGEITEM_H
diff --git a/noncore/games/backgammon/config.in b/noncore/games/backgammon/config.in
new file mode 100644
index 0000000..c725fcc
--- a/dev/null
+++ b/noncore/games/backgammon/config.in
@@ -0,0 +1,4 @@
1 config BACKGAMMON
2 boolean "backgammon"
3 default "y"
4 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE
diff --git a/noncore/games/backgammon/definition.cpp b/noncore/games/backgammon/definition.cpp
new file mode 100644
index 0000000..9e0029d
--- a/dev/null
+++ b/noncore/games/backgammon/definition.cpp
@@ -0,0 +1,3 @@
1#include "definition.h"
2
3static bool debug=false;
diff --git a/noncore/games/backgammon/definition.h b/noncore/games/backgammon/definition.h
new file mode 100644
index 0000000..6a23801
--- a/dev/null
+++ b/noncore/games/backgammon/definition.h
@@ -0,0 +1,74 @@
1#ifndef DEFINITION_H
2#define DEFINITION_H
3
4
5struct Coord
6{
7 int x;
8 int y;
9 int z;
10 bool side;
11};
12
13struct Pieces
14{
15 Coord player1[15];
16 Coord player2[15];
17};
18
19struct Population
20{
21 //positive = player 1
22 //negative = player 2
23 //zero = no pieces
24 int total;
25};
26
27struct Marker
28{
29 int x_current;
30 int y_current;
31 bool visible_current;
32
33 int x_next[4];
34 int y_next[4];
35 bool visible_next[4];
36};
37
38struct LoadSave
39{
40 Population pop[28];
41};
42
43struct Possiblilites
44{
45 int weight[4];
46 int to[4];
47};
48
49struct AISettings
50{
51 int rescue;
52 int eliminate;
53 int expose;
54 int protect;
55 int safe;
56 int empty;
57};
58
59struct Rules
60{
61 bool move_with_pieces_out;
62 bool generous_dice;
63};
64
65
66struct Display
67{
68 bool small;
69 bool warning;
70};
71
72
73
74#endif //DEFINITION_H
diff --git a/noncore/games/backgammon/displaydialog.cpp b/noncore/games/backgammon/displaydialog.cpp
new file mode 100644
index 0000000..8b97545
--- a/dev/null
+++ b/noncore/games/backgammon/displaydialog.cpp
@@ -0,0 +1,89 @@
1#include "displaydialog.h"
2
3#include <qgroupbox.h>
4#include <qlabel.h>
5
6DisplayDialog::DisplayDialog(QWidget* parent,const char* name,bool modal,WFlags f)
7 : QDialog(parent,name,modal,f)
8{
9 setCaption("Display Configuration");
10 QLabel* header=new QLabel("<b>Change the display settings</b>",this);
11 header->setGeometry(10,10,200,20);
12
13 //
14 QGroupBox* settings_frame=new QGroupBox("Settings",this);
15 settings_frame->setGeometry(10,10,220,120);
16
17 small_box=new QRadioButton("Big display, e.g. for QPE Style",settings_frame);
18 small_box->setGeometry(10,20,200,20);
19 connect(small_box,SIGNAL(clicked()),this,SLOT(small_clicked()));
20
21 big_box=new QRadioButton("Small display, e.g. for Windows Style",settings_frame);
22 big_box->setGeometry(10,50,200,20);
23 connect(big_box,SIGNAL(clicked()),this,SLOT(big_clicked()));
24
25 //
26 QGroupBox* warning_frame=new QGroupBox("Warning",this);
27 warning_frame->setGeometry(10,140,220,120);
28
29 warning_box=new QCheckBox("show style warning",warning_frame);
30 warning_box->setGeometry(10,20,200,20);
31 connect(warning_box,SIGNAL(clicked()),this,SLOT(warning_clicked()));
32
33 QLabel* warning_help=new QLabel("show style warning at statup if the system style is not QPE\nif not set to small you may have\nscrollbars on the palying area",warning_frame);
34 warning_help->setGeometry(10,50,200,60);
35
36 showMaximized();
37}
38
39
40DisplayDialog::~DisplayDialog()
41{
42}
43
44void DisplayDialog::big_clicked()
45{
46 big_box->setChecked(true);
47 small_box->setChecked(false);
48}
49
50void DisplayDialog::small_clicked()
51{
52 big_box->setChecked(false);
53 small_box->setChecked(true);
54}
55
56void DisplayDialog::warning_clicked()
57{
58}
59
60void DisplayDialog::setDisplaySettings(const Display& display)
61{
62 if(!display.small)
63 {
64 big_box->setChecked(false);
65 small_box->setChecked(true);
66 }
67 else
68 {
69 big_box->setChecked(true);
70 small_box->setChecked(false);
71 }
72 if(display.warning)
73 warning_box->setChecked(true);
74 else
75 warning_box->setChecked(false);
76
77}
78
79Display DisplayDialog::getDisplaySettings()
80{
81 Display display;
82 display.small=!small_box->isChecked();
83 display.warning=warning_box->isChecked();
84 return display;
85}
86
87
88
89
diff --git a/noncore/games/backgammon/displaydialog.h b/noncore/games/backgammon/displaydialog.h
new file mode 100644
index 0000000..26b77f0
--- a/dev/null
+++ b/noncore/games/backgammon/displaydialog.h
@@ -0,0 +1,30 @@
1#ifndef DISPLAYDLAOG_H
2#define DISPLAYDLAOG_H
3
4#include <qcheckbox.h>
5#include <qdialog.h>
6#include <qradiobutton.h>
7
8#include "definition.h"
9
10
11class DisplayDialog : public QDialog
12{
13 Q_OBJECT
14private:
15 QRadioButton* small_box;
16 QRadioButton* big_box;
17 QCheckBox* warning_box;
18public:
19 DisplayDialog(QWidget* parent=0,const char* name=0,bool modal=TRUE,WFlags f=0);
20 ~DisplayDialog();
21private slots:
22 void big_clicked();
23 void small_clicked();
24 void warning_clicked();
25public:
26 void setDisplaySettings(const Display& display);
27 Display getDisplaySettings();
28};
29
30#endif //DISPLAYDLAOG_H
diff --git a/noncore/games/backgammon/filedialog.cpp b/noncore/games/backgammon/filedialog.cpp
new file mode 100644
index 0000000..6c858a2
--- a/dev/null
+++ b/noncore/games/backgammon/filedialog.cpp
@@ -0,0 +1,64 @@
1#include "filedialog.h"
2
3#include <qdir.h>
4#include <qfileinfo.h>
5#include <qmessagebox.h>
6#include <qpixmap.h>
7#include <qpushbutton.h>
8#include <qpe/qpeapplication.h>
9
10FileDialog::FileDialog(QWidget* parent,QString header,QString extension,const char* name,bool modal,WFlags f)
11 :QDialog(parent,name,modal,f)
12{
13 setCaption(header);
14 ext=extension;
15 dirselector=new QListView(this);
16 dirselector->setGeometry(1,10,235,200);
17 dirselector->addColumn("Files");
18 connect(dirselector,SIGNAL(clicked(QListViewItem*)),this,SLOT(selectorclicked(QListViewItem*)));
19
20 getCurrentDir();
21
22 file_name="user";
23 fileinput=new QLineEdit(file_name,this);
24 fileinput->setGeometry(1,220,235,20);
25 showMaximized();
26}
27
28FileDialog::~FileDialog()
29{}
30
31
32void FileDialog::selectorclicked(QListViewItem* entry)
33{
34 if(entry==NULL)
35 return;
36 file_name=entry->text(0);
37 fileinput->setText(file_name);
38}
39
40void FileDialog::getCurrentDir()
41{
42 dirselector->clear();
43 QDir dir(QPEApplication::qpeDir()+"/backgammon");
44 dir.setFilter(QDir::Files);
45 QFileInfoListIterator it(*(dir.entryInfoList()));
46 QFileInfo* fi;
47
48 int ext_length=ext.length();
49 while((fi=it.current())) // go through all file and subdirs
50 {
51 QString file=fi->fileName();
52 if(file.right(ext_length)==ext && file)
53 {
54 file=file.left(file.length()-ext_length);
55 new QListViewItem(dirselector,file);
56 }
57 ++it;
58 }
59}
60
61QString FileDialog::filename()
62{
63 return file_name;
64}
diff --git a/noncore/games/backgammon/filedialog.h b/noncore/games/backgammon/filedialog.h
new file mode 100644
index 0000000..2dfa557
--- a/dev/null
+++ b/noncore/games/backgammon/filedialog.h
@@ -0,0 +1,30 @@
1#ifndef FILEWIDGET_H
2#define FILEWIDGET_H
3
4#include <qdialog.h>
5#include <qlineedit.h>
6#include <qlistview.h>
7#include <qstring.h>
8
9
10class FileDialog : public QDialog
11{
12 Q_OBJECT
13private:
14 QListView* dirselector;
15 QLineEdit* fileinput;
16 QString ext;
17 QString file_name;
18
19public:
20 FileDialog(QWidget* parent,QString header,QString extension,const char* name=0,bool modal=TRUE,WFlags f=0);
21 ~FileDialog();
22private slots:
23 void selectorclicked(QListViewItem* entry);
24private:
25 void getCurrentDir();
26public:
27 QString filename();
28};
29
30#endif //FILEWIDGET_H
diff --git a/noncore/games/backgammon/main.cpp b/noncore/games/backgammon/main.cpp
new file mode 100644
index 0000000..86b452d
--- a/dev/null
+++ b/noncore/games/backgammon/main.cpp
@@ -0,0 +1,14 @@
1#include <qpe/qpeapplication.h>
2#include "backgammon.h"
3
4
5int main( int argc, char** argv )
6{
7 QPEApplication app( argc, argv );
8
9 BackGammon* view= new BackGammon();
10 app.showMainWidget(view);
11
12 return app.exec();
13}
14
diff --git a/noncore/games/backgammon/moveengine.cpp b/noncore/games/backgammon/moveengine.cpp
new file mode 100644
index 0000000..009c449
--- a/dev/null
+++ b/noncore/games/backgammon/moveengine.cpp
@@ -0,0 +1,558 @@
1#include "moveengine.h"
2
3#include <qmessagebox.h>
4
5#include <qtimer.h>
6
7MoveEngine::MoveEngine()
8 : QObject()
9{
10 int offset=7;
11 int a=0; //counter variable
12 int xfill[]={210,185,170,155,140,125,110,85,70,55,40,25,10,10,25,40,55,70,85,110,125,140,155,170,185,210};
13 for(a=0;a<26;a++)
14 {
15 x_coord[a]=xfill[a];
16 }
17
18 int yfill[]={10,25,40,55,70,10+offset,25+offset,40+offset,55+offset,25,40,55, 25+offset,40+offset,40};
19 int zfill[]={1,1,1,1,1,2,2,2,2,3,3,3,4,4,5};
20 for(a=0;a<15;a++)
21 {
22 yup_coord[a]=yfill[a];
23 ylow_coord[a]=185-(yfill[a]);
24 z_coord[a]=zfill[a];
25 }
26 for(a=0;a<5;a++)
27 {
28 if(a<3)
29 {
30 x_fin1[a]=65+a*15;
31 x_fin2[a]=155-a*15;
32 }
33 y_fin[a]=225-a*5;
34 }
35 z_fin=1;
36
37 reset();
38}
39
40MoveEngine::~MoveEngine()
41{}
42
43void MoveEngine::position(Pieces& pieces,bool non_qte)
44{
45 int player1_counter=0;
46 int player2_counter=0;
47
48 //non qte styles are smaller !!
49 int offset=(non_qte) ? 5 : 0;
50
51 for(int a=0;a<28;a++)
52 {
53 for(int b=0;b<abs(population[a].total);b++)
54 {
55 if(population[a].total>0) //player 1 pieces
56 {
57 pieces.player1[player1_counter].x=x_coord[a]-offset;
58 if(a>=0 && a<13)
59 {
60 pieces.player1[player1_counter].y=yup_coord[b]-offset;
61 pieces.player1[player1_counter].z=z_coord[b];
62 pieces.player1[player1_counter].side=false;
63 player1_counter++;
64 }
65 else if(a>12 && a<26)
66 {
67 pieces.player1[player1_counter].y=ylow_coord[b]-offset;
68 pieces.player1[player1_counter].z=z_coord[b];
69 pieces.player1[player1_counter].side=false;
70 player1_counter++;
71 }
72 else if(a==26)
73 {
74 if(b<5)
75 {
76 pieces.player1[player1_counter].x=x_fin1[0]-offset;
77 pieces.player1[player1_counter].y=y_fin[b]-offset;
78 pieces.player1[player1_counter].z=z_fin;
79 }
80 else if(b>=5 && b<10)
81 {
82 pieces.player1[player1_counter].x=x_fin1[1]-offset;
83 pieces.player1[player1_counter].y=y_fin[b-5]-offset;
84 pieces.player1[player1_counter].z=z_fin;
85 }
86 else
87 {
88 pieces.player1[player1_counter].x=x_fin1[2]-offset;
89 pieces.player1[player1_counter].y=y_fin[b-10]-offset;
90 pieces.player1[player1_counter].z=z_fin;
91 }
92 pieces.player1[player1_counter].side=true;
93 player1_counter++;
94
95 }
96 }
97
98 else if(population[a].total<0) //player 2 pieces
99 {
100 pieces.player2[player2_counter].x=x_coord[a]-offset;
101 if(a>=0 && a<13)
102 {
103 pieces.player2[player2_counter].y=yup_coord[b]-offset;
104 pieces.player2[player2_counter].z=z_coord[b];
105 pieces.player2[player2_counter].side=false;
106 player2_counter++;
107 }
108 else if(a>12 && a<26)
109 {
110 pieces.player2[player2_counter].y=ylow_coord[b]-offset;
111 pieces.player2[player2_counter].z=z_coord[b];
112 pieces.player2[player2_counter].side=false;
113 player2_counter++;
114 }
115 else if(a==27)
116 {
117 if(b<5)
118 {
119 pieces.player2[player2_counter].x=x_fin2[0]-offset;
120 pieces.player2[player2_counter].y=y_fin[b]-offset;
121 pieces.player2[player2_counter].z=z_fin;
122 }
123 else if(b>=5 && b<10)
124 {
125 pieces.player2[player2_counter].x=x_fin2[1]-offset;
126 pieces.player2[player2_counter].y=y_fin[b-5]-offset;
127 pieces.player2[player2_counter].z=z_fin;
128 }
129 else
130 {
131 pieces.player2[player2_counter].x=x_fin2[2]-offset;
132 pieces.player2[player2_counter].y=y_fin[b-10]-offset;
133 pieces.player2[player2_counter].z=z_fin;
134 }
135 pieces.player2[player2_counter].side=true;
136 player2_counter++;
137
138 }
139 }
140 }
141 }
142}
143
144void MoveEngine::diceroll(const int& newplayer,const int& face1,const int& face2,const int& face3,const int& face4,bool computer)
145{
146 checkstate();
147 player=newplayer;
148 otherplayer=(player==1) ? 2 : 1;
149 dice[0]=face1;
150 dice[1]=face2;
151 dice[2]=face3;
152 dice[3]=face4;
153 marker_current=-1;
154 if(getPossibleMoves()==0)
155 {
156 emit nomove();
157 return; // player will be changed
158 }
159 if(!computer)
160 return; //human intervention required
161
162 QTimer::singleShot(2000,this,SLOT(automove()));
163}
164
165
166void MoveEngine::automove()
167{
168 //the maximimum possibility
169 int maxpos=0;
170 //the position in the moves array
171 int from=-1;
172 int to=-1;
173 //dice1 or dice 2 ??
174 int index_dice=0;
175 for(int counter=0;counter<26;counter++)
176 {
177 int a=(player==1) ? counter : 25-counter;
178 for(int b=0;b<4;b++)
179 {
180 if(moves[a].weight[b]>maxpos)
181 {
182 maxpos=moves[a].weight[b];
183 from=a;
184 to=moves[a].to[b];
185 index_dice=b+1;
186 }
187 }
188 }
189 move(from,to,index_dice);
190}
191
192
193void MoveEngine::boardpressed(const int& x,const int& y,Marker& marker,bool non_qte)
194{
195 //get the position of the mouse click
196 bool upper=true;
197 bool found=false;
198
199 int offset=(non_qte) ? 5 : 0;
200
201 if(y<=85) // board slots 0 to 12
202 marker.y_current=0;
203 else if(y>=105) //board slots 13 to 25
204 {
205 marker.y_current=195-2*offset;
206 upper=false;
207 }
208
209 int index=13; // the clicked board slot
210
211 while(index<25 && !found)
212 {
213 if(x>=x_coord[index] && x<x_coord[index+1])
214 {
215 marker.x_current=x_coord[index];
216 found=true;
217 ;
218 }
219 else
220 {
221 index++;
222 }
223 }
224 if(!found)
225 {
226 marker.x_current=x_coord[25];
227 index=25;
228 }
229 if(upper)
230 {
231 index=25-index;
232 }
233
234 int a=0;
235 int usedice=-1;
236 int dice_value=7;
237 for(a=0;a<4;a++)
238 {
239 if(index==marker_next[a] && marker_next[a]!=-1 && dice_value>dice[a])
240 {
241 usedice=a;
242 dice_value=dice[0];
243 }
244 }
245 if(usedice!=-1)
246 {
247 move(marker_current,marker_next[usedice],usedice+1);
248 nomarker(marker);
249 return;
250
251 }
252
253
254 if(dice[0]==7 && dice[1]==7 && dice[2]==7 && dice[3]==7) //no dice rolled
255 {
256 nomarker(marker);
257 return;
258 }
259 else if(fieldColor(index)==player)
260 {
261 marker.visible_current=true;
262 marker_current=index;
263 }
264 else
265 {
266 nomarker(marker);
267 return;
268 }
269
270 for(a=0;a<4;a++)
271 {
272 if(moves[index].weight[a]>0)
273 {
274 int nextfield=moves[index].to[a];
275 marker.x_next[a]=x_coord[nextfield];
276 marker_next[a]=nextfield;
277 if(nextfield<13) //upper half
278 marker.y_next[a]=0;
279 else //lower half
280 marker.y_next[a]=195-2*offset;
281 marker.visible_next[a]=true;
282 }
283 else
284 {
285 marker.x_next[a]=0;
286 marker.y_next[a]=0;
287 marker_next[a]=-1;
288 marker.visible_next[a]=false;
289 }
290 }
291 return;
292}
293
294void MoveEngine::reset()
295{
296 int a=0;
297 for(a=0;a<28;a++)
298 {
299 population[a].total=0;
300 }
301
302 int p1_index[]={1,1,12,12,12,12,12,17,17,17,19,19,19,19,19};
303 int p2_index[]={24,24,13,13,13,13,13,8,8,8,6,6,6,6,6};
304 //int p1_index[]={19,20,21,22,22,23,23,18,18,23,24,24,24,24,24};
305 //int p2_index[]={6,5,4,3,3,2,2,2,2,2,1,7,7,1,1};
306 for(a=0;a<15;a++)
307 {
308 population[p1_index[a]].total++;
309 population[p2_index[a]].total--;
310 }
311
312 player=0;
313 dice[0]=7;
314 dice[1]=7;
315 dice[2]=7;
316 dice[3]=7;
317
318 marker_current=-1;
319 marker_next[0]=-1;
320 marker_next[1]=-1;
321 marker_next[2]=-1;
322 marker_next[3]=-1;
323 //allclear[0]==false;
324 allclear[1]=false;
325 allclear[2]=false;
326 last_piece[1]=0;
327 last_piece[2]=25;
328}
329
330void MoveEngine::loadGame(const LoadSave& load)
331{
332 for(int a=0;a<28;a++)
333 {
334 population[a].total=load.pop[a].total;
335 }
336 checkstate();
337}
338
339LoadSave MoveEngine::saveGame()
340{
341 LoadSave save;
342 for(int a=0;a<28;a++)
343 {
344 save.pop[a].total=population[a].total;
345 }
346 return save;
347}
348
349AISettings MoveEngine::getAISettings()
350{
351 return ai;
352}
353
354void MoveEngine::setAISettings(const AISettings& new_ai)
355{
356 ai=new_ai;
357}
358
359void MoveEngine::setRules(Rules rules)
360{
361 move_with_pieces_out=rules.move_with_pieces_out;
362 nice_dice=rules.generous_dice;
363}
364
365
366int MoveEngine::getPossibleMoves()
367{
368 int homezone[]={0,25,0};
369 int lastToHomeZone=abs(last_piece[player]-homezone[player]);
370 for(int field=0;field<26;field++)
371 {
372
373 for(int b=0;b<4;b++)
374 {
375 int dice_tmp=dice[b];
376 if(dice[b]!=7 && dice[b]> lastToHomeZone)
377 dice_tmp=lastToHomeZone;
378
379 int nextfield=(player==1) ? field+dice_tmp : field-dice_tmp;
380
381 if(nice_dice)
382 {
383 if(player==1 && nextfield>homezone[1])
384 nextfield=homezone[1];
385 else if(player==2 && nextfield<homezone[2])
386 nextfield=homezone[2];
387 }
388
389 moves[field].weight[b]=0;
390 moves[field].to[b]=nextfield;
391
392 int out_of_board[]={-1,0,25};
393 if(!move_with_pieces_out && field!=out_of_board[player] && pieces_out[player])
394 {
395 continue;
396 }
397
398
399
400 if(dice[b]!=7 && fieldColor(field)==player ) //player can only move his own pieces
401 {
402 if((player==1 && nextfield > homezone[1]) || (player==2 && nextfield < homezone[2]))
403 {
404 moves[field].weight[b]=0; //movement would be far out of board
405 }
406 else if(nextfield==homezone[player] && !allclear[player])
407 {
408 moves[field].weight[b]=0; //can not rescue pieces until all are in the endzone
409 }
410 else if(nextfield==homezone[player] && allclear[player])
411 {
412 moves[field].weight[b]=ai.rescue; //rescue your pieces : nuff said ;-)
413 }
414 else if(fieldColor(nextfield)==otherplayer)
415 {
416 if(abs(population[nextfield].total)>1) //can not move to this field
417 moves[field].weight[b]=0;
418 else if(abs(population[nextfield].total)==1) //eliminate opponent : very nice
419 moves[field].weight[b]=ai.eliminate;
420 }
421 else if(fieldColor(nextfield)==player) //nextfield already occupied by player
422 {
423 if(abs(population[field].total)==2) //expose own piece : not diserable
424 moves[field].weight[b]=ai.expose;
425 else if(abs(population[nextfield].total)>1) //own pices already there : safe
426 moves[field].weight[b]=ai.safe;
427 else if(abs(population[nextfield].total)==1) //protect own piece : most importatnt
428 moves[field].weight[b]=ai.protect;
429 }
430 else if(population[nextfield].total==0) //nextfield empty
431 {
432 if(abs(population[field].total)==2) //expose own piece : not diserable
433 moves[field].weight[b]=ai.expose;
434 else
435 moves[field].weight[b]=ai.empty;
436 }
437 else
438 moves[field].weight[b]=0; //default.
439 }
440
441
442
443 else
444 moves[field].weight[b]=0; //dice already used or field not used by player
445 }
446
447
448
449 }
450
451 int total=0;
452 for(int field=0;field<26;field++)
453 {
454 total+=moves[field].weight[0]+moves[field].weight[1]+moves[field].weight[2]+moves[field].weight[3];
455 }
456 return total;
457}
458
459void MoveEngine::move(const int& from, int to, const int& dice)
460{
461 //qDebug("%d moves from %d to %d (%d) with dice %d",player,from,to,to-from,dice);
462
463 if(player==1 && to==25)
464 to=26;
465 if(player==2 && to==0)
466 to=27;
467
468 //if space is occupied by enemy move pieces to startzone
469 if(fieldColor(to)==otherplayer)
470 {
471 population[to].total=0;
472 if(otherplayer==1)
473 population[0].total++;
474 else
475 population[25].total--;
476 }
477
478 if(player==1)
479 {
480 population[from].total--;
481 population[to].total++;
482 }
483 else //player=2
484 {
485 population[from].total++;
486 population[to].total--;
487 }
488
489 if(dice==1)
490 emit done_dice1();
491 else if(dice==2)
492 emit done_dice2();
493 else if(dice==3)
494 emit done_dice3();
495 else
496 emit done_dice4();
497
498 if(abs(population[26].total)==15)
499 emit player_finished(1);
500 if(abs(population[27].total)==15)
501 emit player_finished(2);
502}
503
504void MoveEngine::checkstate()
505{
506 //check if pieces are out
507 pieces_out[1]=(population[0].total>0) ? true : false;
508 pieces_out[2]=(population[25].total<0) ? true : false;
509
510 //check if all pieces are in the endzones
511 allclear[1]=true;
512 allclear[2]=true;
513
514 last_piece[1]=25;
515 bool found_last_piece1=false;
516 last_piece[2]=0;
517
518 for(int a=0;a<26;a++)
519 {
520 if(a<19 && population[a].total>0)
521 allclear[1]=false;
522 if(a>6 && population[a].total<0)
523 allclear[2]=false;
524
525 if(population[a].total>0 && !found_last_piece1)
526 {
527 last_piece[1]=a;
528 found_last_piece1=true;
529 }
530 if(population[a].total<0)
531 last_piece[2]=a;
532 }
533}
534
535void MoveEngine::nomarker(Marker& marker)
536{
537 marker.visible_current=false;
538 marker_current=-1;
539 for(int a=0;a<4;a++)
540 {
541 marker.x_next[a]=0;
542 marker.y_next[a]=0;
543 marker_next[a]=-1;
544 marker.visible_next[a]=false;
545 }
546}
547
548int MoveEngine::fieldColor(const int& index) const
549{
550 if(population[index].total>0)
551 return 1;
552 else if(population[index].total<0)
553 return 2;
554 else
555 return 0;
556}
557
558
diff --git a/noncore/games/backgammon/moveengine.h b/noncore/games/backgammon/moveengine.h
new file mode 100644
index 0000000..a2d4a52
--- a/dev/null
+++ b/noncore/games/backgammon/moveengine.h
@@ -0,0 +1,76 @@
1#ifndef MOVEENGINE_H
2#define MOVEENGINE_H
3
4#include <qobject.h>
5#include "definition.h"
6
7class MoveEngine : public QObject
8{
9 Q_OBJECT
10private:
11 //normal pieses
12 int x_coord[26]; //26 posssible x-positions or piece is not on the board
13 int yup_coord[15]; // the 15 posssible y-positions on the upper half of the board
14 int ylow_coord[15]; // the 15 posssible y-positions on the lower half of the board
15 int z_coord[15]; //the 15 possible z-positionson the board
16 //finshed pieces
17 int x_fin1[3];
18 int x_fin2[3];
19 int y_fin[5];
20 int z_fin;
21 //the board population
22 // |12|11|10|09|08|07|06|05|04|03|02|01|00|
23 // =======================================
24 // |13|14|15|16|17|18|19|20|21|22|23|24|25|
25 // endzones 26 player1, 27 player 2
26 Population population[28];
27 AISettings ai;
28 //move information
29 int player;
30 int otherplayer;
31 int dice[4];
32 //index of the markers
33 int marker_current;
34 int marker_next[4];
35 //player pieces are all in the end zone
36 bool allclear[3];
37 //player must bring pieces back into game
38 bool pieces_out[3];
39 bool move_with_pieces_out;
40 //player can rescue pieces with dice bigger than move, even if there are poeces "behind" it
41 bool nice_dice;
42 int last_piece[3];
43 //possible moves
44 Possiblilites moves[26];
45public:
46public:
47 MoveEngine();
48 ~MoveEngine();
49signals:
50 void done_dice1();
51 void done_dice2();
52 void done_dice3();
53 void done_dice4();
54 void nomove();
55 void player_finished(int);
56private slots:
57 void automove();
58public:
59 void position(Pieces& pieces,bool non_qte=false);
60 void diceroll(const int& player,const int& face1,const int& face2,const int& face3,const int& face4,bool computer);
61 void boardpressed(const int& x,const int& y,Marker& marker,bool non_qte=false);
62 void reset();
63 void loadGame(const LoadSave& load);
64 LoadSave saveGame();
65 AISettings getAISettings();
66 void setAISettings(const AISettings& new_ai);
67 void setRules(Rules rules);
68private:
69 int getPossibleMoves();
70 void move(const int& from, int to, const int& dice);
71 void checkstate();
72 void nomarker(Marker& marker);
73 int fieldColor(const int& index) const;
74};
75
76#endif //MOVEENGINE_H
diff --git a/noncore/games/backgammon/playerdialog.cpp b/noncore/games/backgammon/playerdialog.cpp
new file mode 100644
index 0000000..c16f202
--- a/dev/null
+++ b/noncore/games/backgammon/playerdialog.cpp
@@ -0,0 +1,114 @@
1#include "playerdialog.h"
2
3#include <qgroupbox.h>
4
5PlayerDialog::PlayerDialog(QWidget* parent,const char* name,bool modal,WFlags f)
6 :QDialog(parent,name,modal,f)
7{
8 auto2=false;
9 auto2=true;
10 setCaption("Player Settings");
11
12 QGroupBox* player1_box=new QGroupBox("Player 1",this);
13 player1_box->setGeometry(10,30,220,60);
14
15 manual_button1=new QRadioButton("Human",player1_box);
16 connect(manual_button1,SIGNAL(clicked()),this,SLOT(button_manual1()));
17 manual_button1->setGeometry(10,20,100,20);
18 auto_button1=new QRadioButton("Computer",player1_box);
19 connect(auto_button1,SIGNAL(clicked()),this,SLOT(button_auto1()));
20 auto_button1->setGeometry(110,20,100,20);
21 button1_state(auto1);
22
23 QGroupBox* player2_box=new QGroupBox("Player 2",this);
24 player2_box->setGeometry(10,150,220,60);
25
26 manual_button2=new QRadioButton("Human",player2_box);
27 connect(manual_button2,SIGNAL(clicked()),this,SLOT(button_manual2()));
28 manual_button2->setGeometry(10,20,100,20);
29 auto_button2=new QRadioButton("Computer",player2_box);
30 connect(auto_button2,SIGNAL(clicked()),this,SLOT(button_auto2()));
31 auto_button2->setGeometry(110,20,100,20);
32 button2_state(auto2);
33
34 showMaximized();
35}
36
37PlayerDialog::~PlayerDialog()
38{}
39
40
41void PlayerDialog::button_manual1()
42{
43 auto1=false;
44 button1_state(auto1);
45}
46
47void PlayerDialog::button_auto1()
48{
49 auto1=true;
50 button1_state(auto1);
51}
52
53void PlayerDialog::button_manual2()
54{
55 auto2=false;
56 button2_state(auto2);
57}
58
59void PlayerDialog::button_auto2()
60{
61 auto2=true;
62 button2_state(auto2);
63}
64
65void PlayerDialog::button1_state(bool computer)
66{
67 if(computer)
68 {
69 manual_button1->setChecked(false);
70 auto_button1->setChecked(true);
71 }
72 else
73 {
74 manual_button1->setChecked(true);
75 auto_button1->setChecked(false);
76 }
77}
78
79void PlayerDialog::button2_state(bool computer)
80{
81 if(computer)
82 {
83 manual_button2->setChecked(false);
84 auto_button2->setChecked(true);
85 }
86 else
87 {
88 manual_button2->setChecked(true);
89 auto_button2->setChecked(false);
90 }
91}
92
93
94void PlayerDialog::setAuto1(bool newstate)
95{
96 auto1=newstate;
97 button1_state(auto1);
98}
99
100bool PlayerDialog::getAuto1()
101{
102 return auto1;
103}
104
105void PlayerDialog::setAuto2(bool newstate)
106{
107 auto2=newstate;
108 button2_state(auto2);
109}
110
111bool PlayerDialog::getAuto2()
112{
113 return auto2;
114}
diff --git a/noncore/games/backgammon/playerdialog.h b/noncore/games/backgammon/playerdialog.h
new file mode 100644
index 0000000..8fccaa7
--- a/dev/null
+++ b/noncore/games/backgammon/playerdialog.h
@@ -0,0 +1,35 @@
1#ifndef PLAYERDIALOG_H
2#define PLAYERDIALOG_H
3
4#include <qradiobutton.h>
5#include <qdialog.h>
6
7class PlayerDialog : public QDialog
8{
9 Q_OBJECT
10private:
11 bool auto1;
12 bool auto2;
13 QRadioButton* manual_button1;
14 QRadioButton* auto_button1;
15 QRadioButton* manual_button2;
16 QRadioButton* auto_button2;
17public:
18 PlayerDialog(QWidget* parent=0,const char* name=0,bool modal=TRUE,WFlags f=0);
19 ~PlayerDialog();
20private slots:
21 void button_manual1();
22 void button_auto1();
23 void button_manual2();
24 void button_auto2();
25private:
26 void button1_state(bool computer);
27 void button2_state(bool computer);
28public:
29 void setAuto1(bool newstate);
30 bool getAuto1();
31 void setAuto2(bool newstate);
32 bool getAuto2();
33};
34
35#endif //PLAYERDIALOG_H
diff --git a/noncore/games/backgammon/rulesdialog.cpp b/noncore/games/backgammon/rulesdialog.cpp
new file mode 100644
index 0000000..85c3db3
--- a/dev/null
+++ b/noncore/games/backgammon/rulesdialog.cpp
@@ -0,0 +1,77 @@
1#include "rulesdialog.h"
2
3#include <qgroupbox.h>
4#include <qlabel.h>
5
6RulesDialog::RulesDialog(QWidget* parent,const char* name,bool modal,WFlags f)
7 : QDialog(parent,name,modal,f)
8{
9 setCaption("Rules Configuration");
10 QLabel* header=new QLabel("<b>Change the game rules here</b>",this);
11 header->setGeometry(10,10,200,20);
12
13 //
14 QGroupBox* pieces_out_box=new QGroupBox("Movement",this);
15 pieces_out_box->setGeometry(10,10,220,120);
16
17 pieces_out=new QCheckBox("Don't care about others",pieces_out_box);
18 pieces_out->setGeometry(10,20,200,20);
19 connect(pieces_out,SIGNAL(clicked()),this,SLOT(pieces_out_clicked()));
20
21 QLabel* pieces_out_help=new QLabel("allow movement of the pieses\neven if there are pieces knocked\nout by the opponent",pieces_out_box);
22 pieces_out_help->setGeometry(10,40,200,60);
23
24 //
25 QGroupBox* nice_dice_box=new QGroupBox("Dice",this);
26 nice_dice_box->setGeometry(10,140,220,120);
27
28 nice_dice=new QCheckBox("Big dice for small numbers",nice_dice_box);
29 nice_dice->setGeometry(10,20,200,20);
30 connect(nice_dice,SIGNAL(clicked()),this,SLOT(nice_dice_clicked()));
31
32 QLabel* nice_dice_help=new QLabel("allow to rescue pieces with dice\nvalues graeter than the distance\nto the players endzone.",nice_dice_box);
33 nice_dice_help->setGeometry(10,40,200,60);
34
35 showMaximized();
36}
37
38
39RulesDialog::~RulesDialog()
40{
41}
42
43void RulesDialog::pieces_out_clicked()
44{
45 if(pieces_out->isChecked())
46 rules.move_with_pieces_out=true;
47 else
48 rules.move_with_pieces_out=false;
49}
50
51void RulesDialog::nice_dice_clicked()
52{
53 if(nice_dice->isChecked())
54 rules.generous_dice=true;
55 else
56 rules.generous_dice=false;
57}
58
59void RulesDialog::setRules(const Rules& new_rules)
60{
61 rules=new_rules;
62 if(rules.move_with_pieces_out)
63 pieces_out->setChecked(true);
64 else
65 pieces_out->setChecked(false);
66
67 if(rules.generous_dice)
68 nice_dice->setChecked(true);
69 else
70 nice_dice->setChecked(false);
71}
72
73Rules RulesDialog::getRules()
74{
75 return rules;
76}
77
diff --git a/noncore/games/backgammon/rulesdialog.h b/noncore/games/backgammon/rulesdialog.h
new file mode 100644
index 0000000..9269a0e
--- a/dev/null
+++ b/noncore/games/backgammon/rulesdialog.h
@@ -0,0 +1,27 @@
1#ifndef RULESDIALOG_H_
2#define RULESDIALOG_H_
3
4#include <qcheckbox.h>
5#include <qdialog.h>
6#include "definition.h"
7
8
9class RulesDialog : public QDialog
10{
11 Q_OBJECT
12private:
13 QCheckBox* pieces_out;
14 QCheckBox* nice_dice;
15 Rules rules;
16public:
17 RulesDialog(QWidget* parent=0,const char* name=0,bool modal=TRUE,WFlags f=0);
18 ~RulesDialog();
19private slots:
20 void pieces_out_clicked();
21 void nice_dice_clicked();
22public:
23 void setRules(const Rules& new_rules);
24 Rules getRules();
25};
26
27#endif //RULESDIALOG_H
diff --git a/noncore/games/backgammon/themedialog.cpp b/noncore/games/backgammon/themedialog.cpp
new file mode 100644
index 0000000..dcb957c
--- a/dev/null
+++ b/noncore/games/backgammon/themedialog.cpp
@@ -0,0 +1,163 @@
1#include "themedialog.h"
2
3#include <qdir.h>
4#include <qfileinfo.h>
5#include <qlabel.h>
6#include <qpushbutton.h>
7#include <qpe/qpeapplication.h>
8
9
10ThemeDialog::ThemeDialog(QWidget* parent,const char* name,bool modal,WFlags f)
11 :QDialog(parent,name,modal,f)
12{
13 setCaption("Theme Dialog");
14 QLabel* labelname=new QLabel("name",this);
15 labelname->setGeometry(0,5,40,20);
16 lineName=new QLineEdit("user",this);
17 lineName->setGeometry(40,5,195,20);
18
19 QLabel* labelboard=new QLabel("board",this);
20 labelboard->setGeometry(0,30,40,20);
21 boxboard=new QComboBox(this,"");
22 boxboard->setGeometry(40,30,195,20);
23 fillBox("boards",boxboard);
24
25 QLabel* labelpiecesA=new QLabel("pieces1",this);
26 labelpiecesA->setGeometry(0,70,40,20);
27 boxpiecesA=new QComboBox(this);
28 boxpiecesA->setGeometry(40,70,195,20);
29 fillBox("pieces",boxpiecesA);
30
31 QLabel* labelpiecesB=new QLabel("pieces2",this);
32 labelpiecesB->setGeometry(0,95,40,20);
33 boxpiecesB=new QComboBox(this);
34 boxpiecesB->setGeometry(40,95,195,20);
35 fillBox("pieces",boxpiecesB);
36
37 QLabel* labeldiceA=new QLabel("dice1",this);
38 labeldiceA->setGeometry(0,135,40,20);
39 boxdiceA=new QComboBox(this);
40 boxdiceA->setGeometry(40,135,195,20);
41 fillBox("dice",boxdiceA);
42
43 QLabel* labeldiceB=new QLabel("dice2",this);
44 labeldiceB->setGeometry(0,160,40,20);
45 boxdiceB=new QComboBox(this);
46 boxdiceB->setGeometry(40,160,195,20);
47 fillBox("dice",boxdiceB);
48
49 QLabel* labelodds=new QLabel("odds",this);
50 labelodds->setGeometry(0,200,40,20);
51 boxodds=new QComboBox(this);
52 boxodds->setGeometry(40,200,195,20);
53 fillBox("odds",boxodds);
54 boxodds->setEnabled(false);
55
56 QLabel* labeltable=new QLabel("table",this);
57 labeltable->setGeometry(0,225,40,20);
58 boxtable=new QComboBox(this);
59 boxtable->setGeometry(40,225,195,20);
60 fillBox("table",boxtable);
61
62 showMaximized();
63}
64
65ThemeDialog::~ThemeDialog()
66{}
67
68
69ImageNames ThemeDialog::getNames()
70{
71 ImageNames names;
72 names.theme=lineName->text();
73 names.board=boxboard->currentText();
74 names.pieces1=boxpiecesA->currentText();
75 names.pieces2=boxpiecesB->currentText();
76 names.dice1=boxdiceA->currentText();
77 names.dice2=boxdiceB->currentText();
78 names.odds=boxodds->currentText();
79 names.table=boxtable->currentText();
80 return names;
81}
82
83void ThemeDialog::setCurrent(const ImageNames& current)
84{
85 int a=0;
86 lineName->setText(current.theme);
87 for(a=0;a<boxboard->count();a++)
88 {
89 if(boxboard->text(a)==current.board)
90 {
91 boxboard->setCurrentItem(a);
92 break;
93 }
94 }
95 for(a=0;a<boxpiecesA->count();a++)
96 {
97 if(boxpiecesA->text(a)==current.pieces1)
98 {
99 boxpiecesA->setCurrentItem(a);
100 break;
101 }
102 }
103 for(a=0;a<boxpiecesB->count();a++)
104 {
105 if(boxpiecesB->text(a)==current.pieces2)
106 {
107 boxpiecesB->setCurrentItem(a);
108 break;
109 }
110 }
111 for(a=0;a<boxdiceA->count();a++)
112 {
113 if(boxdiceA->text(a)==current.dice1)
114 {
115 boxdiceA->setCurrentItem(a);
116 break;
117 }
118 }
119 for(a=0;a<boxdiceB->count();a++)
120 {
121 if(boxdiceB->text(a)==current.dice2)
122 {
123 boxdiceB->setCurrentItem(a);
124 break;
125 }
126 }
127 for(a=0;a<boxodds->count();a++)
128 {
129 if(boxodds->text(a)==current.odds)
130 {
131 boxodds->setCurrentItem(a);
132 break;
133 }
134 }
135 for(a=0;a<boxtable->count();a++)
136 {
137 if(boxtable->text(a)==current.table)
138 {
139 boxtable->setCurrentItem(a);
140 break;
141 }
142 }
143}
144
145void ThemeDialog::fillBox(QString dirname,QComboBox* thebox)
146{
147 thebox->clear();
148 QDir dir(QPEApplication::qpeDir()+"/pics/backgammon/"+dirname);
149 dir.setFilter(QDir::Dirs | QDir::Files);
150 QFileInfoListIterator it(*(dir.entryInfoList()));
151 QFileInfo* fi;
152
153 while((fi=it.current())) // go through all file and subdirs
154 {
155 QString file=fi->fileName();
156 if(file.right(4)==".png")
157 {
158 thebox->insertItem(file.left(file.find(".png")));
159 }
160 ++it;
161 }
162 delete fi;
163}
diff --git a/noncore/games/backgammon/themedialog.h b/noncore/games/backgammon/themedialog.h
new file mode 100644
index 0000000..45a61f2
--- a/dev/null
+++ b/noncore/games/backgammon/themedialog.h
@@ -0,0 +1,42 @@
1#ifndef THEMEDIALOG_H
2#define THEMEDIALOG_H
3
4#include <qcombobox.h>
5#include <qdialog.h>
6#include <qlineedit.h>
7
8struct ImageNames
9{
10 QString theme;
11 QString board;
12 QString pieces1;
13 QString pieces2;
14 QString dice1;
15 QString dice2;
16 QString odds;
17 QString table;
18};
19
20class ThemeDialog : public QDialog
21{
22 Q_OBJECT
23private:
24 QLineEdit* lineName;
25 QComboBox* boxboard;
26 QComboBox* boxpiecesA;
27 QComboBox* boxpiecesB;
28 QComboBox* boxdiceA;
29 QComboBox* boxdiceB;
30 QComboBox* boxodds;
31 QComboBox* boxtable;
32public:
33 ThemeDialog(QWidget* parent=0,const char* name=0,bool modal=TRUE,WFlags f=0);
34 ~ThemeDialog();
35public:
36 ImageNames getNames();
37 void setCurrent(const ImageNames& current);
38private:
39 void fillBox(QString dirname,QComboBox* thebox);
40};
41
42#endif //THEMEDIALOG_H
diff --git a/pics/backgammon/backgammon.png b/pics/backgammon/backgammon.png
new file mode 100644
index 0000000..762994e
--- a/dev/null
+++ b/pics/backgammon/backgammon.png
Binary files differ
diff --git a/pics/backgammon/boards/casino_board_1.png b/pics/backgammon/boards/casino_board_1.png
new file mode 100644
index 0000000..2e5bbaf
--- a/dev/null
+++ b/pics/backgammon/boards/casino_board_1.png
Binary files differ
diff --git a/pics/backgammon/dice/casino_dice.png b/pics/backgammon/dice/casino_dice.png
new file mode 100755
index 0000000..4dfc9c9
--- a/dev/null
+++ b/pics/backgammon/dice/casino_dice.png
Binary files differ
diff --git a/pics/backgammon/no_move.png b/pics/backgammon/no_move.png
new file mode 100755
index 0000000..5dcf479
--- a/dev/null
+++ b/pics/backgammon/no_move.png
Binary files differ
diff --git a/pics/backgammon/odds/casino_odds.png b/pics/backgammon/odds/casino_odds.png
new file mode 100644
index 0000000..92cf4b7
--- a/dev/null
+++ b/pics/backgammon/odds/casino_odds.png
Binary files differ
diff --git a/pics/backgammon/pieces/casino_pieces_blue.png b/pics/backgammon/pieces/casino_pieces_blue.png
new file mode 100755
index 0000000..cf70960
--- a/dev/null
+++ b/pics/backgammon/pieces/casino_pieces_blue.png
Binary files differ
diff --git a/pics/backgammon/pieces/casino_pieces_white.png b/pics/backgammon/pieces/casino_pieces_white.png
new file mode 100755
index 0000000..c23b6e6
--- a/dev/null
+++ b/pics/backgammon/pieces/casino_pieces_white.png
Binary files differ
diff --git a/pics/backgammon/table/casino_table_green.png b/pics/backgammon/table/casino_table_green.png
new file mode 100644
index 0000000..003e0d4
--- a/dev/null
+++ b/pics/backgammon/table/casino_table_green.png
Binary files differ