summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/backgammon/aidialog.cpp15
-rw-r--r--noncore/games/backgammon/filedialog.cpp129
-rw-r--r--noncore/games/backgammon/playerdialog.cpp4
-rw-r--r--noncore/games/backgammon/rulesdialog.cpp4
-rw-r--r--noncore/games/backgammon/themedialog.cpp2
-rw-r--r--noncore/games/sfcave/helpwindow.cpp4
-rw-r--r--noncore/games/tetrix/ohighscoredlg.cpp3
-rw-r--r--noncore/games/tictac/tictac.cpp4
8 files changed, 87 insertions, 78 deletions
diff --git a/noncore/games/backgammon/aidialog.cpp b/noncore/games/backgammon/aidialog.cpp
index 7dfe403..32e9b52 100644
--- a/noncore/games/backgammon/aidialog.cpp
+++ b/noncore/games/backgammon/aidialog.cpp
@@ -1,211 +1,212 @@
1#include "aidialog.h" 1#include "aidialog.h"
2 2
3#include <qgroupbox.h> 3#include <qgroupbox.h>
4 4
5#include <qpe/qpeapplication.h>
5 6
6AI_Dialog::AI_Dialog(QWidget* parent,const char* name,bool modal,WFlags f) 7AI_Dialog::AI_Dialog(QWidget* parent,const char* name,bool modal,WFlags f)
7 : QDialog(parent,name,modal,f) 8 : QDialog(parent,name,modal,f)
8{ 9{
9 setCaption("AI Configuration"); 10 setCaption("AI Configuration");
10 11
11 QGroupBox* settings=new QGroupBox(tr( "Settings" ),this); 12 QGroupBox* settings=new QGroupBox(tr( "Settings" ),this);
12 settings->setGeometry(10,5,220,170); 13 settings->setGeometry(10,5,220,170);
13 14
14 QLabel* rescue_label=new QLabel(tr( "<b>Rescue</b>" ),settings); 15 QLabel* rescue_label=new QLabel(tr( "<b>Rescue</b>" ),settings);
15 rescue_label->setGeometry(50,20,50,20); 16 rescue_label->setGeometry(50,20,50,20);
16 rescue=new QSpinBox(0,6,1,settings); 17 rescue=new QSpinBox(0,6,1,settings);
17 rescue->setGeometry(100,20,40,20); 18 rescue->setGeometry(100,20,40,20);
18 QPushButton* rescuehelp=new QPushButton(tr( "?" ),settings); 19 QPushButton* rescuehelp=new QPushButton(tr( "?" ),settings);
19 rescuehelp->setGeometry(140,20,20,20); 20 rescuehelp->setGeometry(140,20,20,20);
20 connect(rescuehelp,SIGNAL(pressed()),this,SLOT(rescuehelp_pressed())); 21 connect(rescuehelp,SIGNAL(pressed()),this,SLOT(rescuehelp_pressed()));
21 connect(rescuehelp,SIGNAL(released()),this,SLOT(rescuehelp_released())); 22 connect(rescuehelp,SIGNAL(released()),this,SLOT(rescuehelp_released()));
22 23
23 QLabel* eliminate_label=new QLabel(tr( "<b>Eliminate</b>" ),settings); 24 QLabel* eliminate_label=new QLabel(tr( "<b>Eliminate</b>" ),settings);
24 eliminate_label->setGeometry(50,40,50,20); 25 eliminate_label->setGeometry(50,40,50,20);
25 eliminate=new QSpinBox(0,6,1,settings); 26 eliminate=new QSpinBox(0,6,1,settings);
26 eliminate->setGeometry(100,40,40,20); 27 eliminate->setGeometry(100,40,40,20);
27 QPushButton* eliminatehelp=new QPushButton(tr( "?" ),settings); 28 QPushButton* eliminatehelp=new QPushButton(tr( "?" ),settings);
28 eliminatehelp->setGeometry(140,40,20,20); 29 eliminatehelp->setGeometry(140,40,20,20);
29 connect(eliminatehelp,SIGNAL(pressed()),this,SLOT(eliminatehelp_pressed())); 30 connect(eliminatehelp,SIGNAL(pressed()),this,SLOT(eliminatehelp_pressed()));
30 connect(eliminatehelp,SIGNAL(released()),this,SLOT(eliminatehelp_released())); 31 connect(eliminatehelp,SIGNAL(released()),this,SLOT(eliminatehelp_released()));
31 32
32 QLabel* expose_label=new QLabel(tr( "<b>Expose</b>" ),settings); 33 QLabel* expose_label=new QLabel(tr( "<b>Expose</b>" ),settings);
33 expose_label->setGeometry(50,60,50,20); 34 expose_label->setGeometry(50,60,50,20);
34 expose=new QSpinBox(0,6,1,settings); 35 expose=new QSpinBox(0,6,1,settings);
35 expose->setGeometry(100,60,40,20); 36 expose->setGeometry(100,60,40,20);
36 QPushButton* exposeehelp=new QPushButton(tr( "?" ),settings); 37 QPushButton* exposeehelp=new QPushButton(tr( "?" ),settings);
37 exposeehelp->setGeometry(140,60,20,20); 38 exposeehelp->setGeometry(140,60,20,20);
38 connect(exposeehelp,SIGNAL(pressed()),this,SLOT(exposehelp_pressed())); 39 connect(exposeehelp,SIGNAL(pressed()),this,SLOT(exposehelp_pressed()));
39 connect(exposeehelp,SIGNAL(released()),this,SLOT(exposehelp_released())); 40 connect(exposeehelp,SIGNAL(released()),this,SLOT(exposehelp_released()));
40 41
41 QLabel* protect_label=new QLabel(tr( "<b>Protect</b>" ),settings); 42 QLabel* protect_label=new QLabel(tr( "<b>Protect</b>" ),settings);
42 protect_label->setGeometry(50,80,50,20); 43 protect_label->setGeometry(50,80,50,20);
43 protect=new QSpinBox(0,6,1,settings); 44 protect=new QSpinBox(0,6,1,settings);
44 protect->setGeometry(100,80,40,20); 45 protect->setGeometry(100,80,40,20);
45 QPushButton* protecthelp=new QPushButton(tr( "?" ),settings); 46 QPushButton* protecthelp=new QPushButton(tr( "?" ),settings);
46 protecthelp->setGeometry(140,80,20,20); 47 protecthelp->setGeometry(140,80,20,20);
47 connect(protecthelp,SIGNAL(pressed()),this,SLOT(protecthelp_pressed())); 48 connect(protecthelp,SIGNAL(pressed()),this,SLOT(protecthelp_pressed()));
48 connect(protecthelp,SIGNAL(released()),this,SLOT(protecthelp_released())); 49 connect(protecthelp,SIGNAL(released()),this,SLOT(protecthelp_released()));
49 50
50 QLabel* safe_label=new QLabel(tr( "<b>Safe</b>" ),settings); 51 QLabel* safe_label=new QLabel(tr( "<b>Safe</b>" ),settings);
51 safe_label->setGeometry(50,100,50,20); 52 safe_label->setGeometry(50,100,50,20);
52 safe=new QSpinBox(0,6,1,settings); 53 safe=new QSpinBox(0,6,1,settings);
53 safe->setGeometry(100,100,40,20); 54 safe->setGeometry(100,100,40,20);
54 QPushButton* safeehelp=new QPushButton(tr( "?" ),settings); 55 QPushButton* safeehelp=new QPushButton(tr( "?" ),settings);
55 safeehelp->setGeometry(140,100,20,20); 56 safeehelp->setGeometry(140,100,20,20);
56 connect(safeehelp,SIGNAL(pressed()),this,SLOT(safehelp_pressed())); 57 connect(safeehelp,SIGNAL(pressed()),this,SLOT(safehelp_pressed()));
57 connect(safeehelp,SIGNAL(released()),this,SLOT(safehelp_released())); 58 connect(safeehelp,SIGNAL(released()),this,SLOT(safehelp_released()));
58 59
59 QLabel* empty_label=new QLabel(tr( "<b>Empty</b>" ),settings); 60 QLabel* empty_label=new QLabel(tr( "<b>Empty</b>" ),settings);
60 empty_label->setGeometry(50,120,50,20); 61 empty_label->setGeometry(50,120,50,20);
61 empty=new QSpinBox(0,6,1,settings); 62 empty=new QSpinBox(0,6,1,settings);
62 empty->setGeometry(100,120,40,20); 63 empty->setGeometry(100,120,40,20);
63 QPushButton* emptyhelp=new QPushButton(tr( "?" ),settings); 64 QPushButton* emptyhelp=new QPushButton(tr( "?" ),settings);
64 emptyhelp->setGeometry(140,120,20,20); 65 emptyhelp->setGeometry(140,120,20,20);
65 connect(emptyhelp,SIGNAL(pressed()),this,SLOT(emptyhelp_pressed())); 66 connect(emptyhelp,SIGNAL(pressed()),this,SLOT(emptyhelp_pressed()));
66 connect(emptyhelp,SIGNAL(released()),this,SLOT(emptyhelp_released())); 67 connect(emptyhelp,SIGNAL(released()),this,SLOT(emptyhelp_released()));
67 68
68 defaultvalues=new QPushButton(tr( "Default Values" ),settings); 69 defaultvalues=new QPushButton(tr( "Default Values" ),settings);
69 defaultvalues->setGeometry(60,140,90,20); 70 defaultvalues->setGeometry(60,140,90,20);
70 connect(defaultvalues,SIGNAL(clicked()),this,SLOT(setDefaultValues())); 71 connect(defaultvalues,SIGNAL(clicked()),this,SLOT(setDefaultValues()));
71 72
72 QGroupBox* helpbox=new QGroupBox(tr( "Help" ),this); 73 QGroupBox* helpbox=new QGroupBox(tr( "Help" ),this);
73 helpbox->setGeometry(10,185,220,90); 74 helpbox->setGeometry(10,185,220,90);
74 75
75 help=new QLabel(helpbox); 76 help=new QLabel(helpbox);
76 help->setGeometry(10,15,200,65); 77 help->setGeometry(10,15,200,65);
77 78
78 setHelpText(); 79 setHelpText();
79 showMaximized(); 80 QPEApplication::showDialog( this );
80} 81}
81 82
82 83
83AI_Dialog::~AI_Dialog() 84AI_Dialog::~AI_Dialog()
84{ 85{
85} 86}
86 87
87void AI_Dialog::rescuehelp_pressed() 88void AI_Dialog::rescuehelp_pressed()
88{ 89{
89 setHelpText("rescue"); 90 setHelpText("rescue");
90} 91}
91 92
92void AI_Dialog::rescuehelp_released() 93void AI_Dialog::rescuehelp_released()
93{ 94{
94 setHelpText(); 95 setHelpText();
95} 96}
96 97
97void AI_Dialog::eliminatehelp_pressed() 98void AI_Dialog::eliminatehelp_pressed()
98{ 99{
99 setHelpText("eliminate"); 100 setHelpText("eliminate");
100} 101}
101 102
102void AI_Dialog::eliminatehelp_released() 103void AI_Dialog::eliminatehelp_released()
103{ 104{
104 setHelpText(); 105 setHelpText();
105} 106}
106 107
107void AI_Dialog::exposehelp_pressed() 108void AI_Dialog::exposehelp_pressed()
108{ 109{
109 setHelpText("expose"); 110 setHelpText("expose");
110} 111}
111 112
112void AI_Dialog::exposehelp_released() 113void AI_Dialog::exposehelp_released()
113{ 114{
114 setHelpText(); 115 setHelpText();
115} 116}
116 117
117void AI_Dialog::protecthelp_pressed() 118void AI_Dialog::protecthelp_pressed()
118{ 119{
119 setHelpText("protect"); 120 setHelpText("protect");
120} 121}
121 122
122void AI_Dialog::protecthelp_released() 123void AI_Dialog::protecthelp_released()
123{ 124{
124 setHelpText(); 125 setHelpText();
125} 126}
126 127
127void AI_Dialog::safehelp_pressed() 128void AI_Dialog::safehelp_pressed()
128{ 129{
129 setHelpText("safe"); 130 setHelpText("safe");
130} 131}
131 132
132void AI_Dialog::safehelp_released() 133void AI_Dialog::safehelp_released()
133{ 134{
134 setHelpText(); 135 setHelpText();
135} 136}
136 137
137void AI_Dialog::emptyhelp_pressed() 138void AI_Dialog::emptyhelp_pressed()
138{ 139{
139 setHelpText("empty"); 140 setHelpText("empty");
140} 141}
141 142
142void AI_Dialog::emptyhelp_released() 143void AI_Dialog::emptyhelp_released()
143{ 144{
144 setHelpText(); 145 setHelpText();
145} 146}
146 147
147 148
148 149
149void AI_Dialog::setDefaultValues() 150void AI_Dialog::setDefaultValues()
150{ 151{
151 rescue->setValue(6); 152 rescue->setValue(6);
152 eliminate->setValue(4); 153 eliminate->setValue(4);
153 expose->setValue(1); 154 expose->setValue(1);
154 protect->setValue(5); 155 protect->setValue(5);
155 safe->setValue(3); 156 safe->setValue(3);
156 empty->setValue(2); 157 empty->setValue(2);
157} 158}
158 159
159void AI_Dialog::setAISettings(const AISettings& values) 160void AI_Dialog::setAISettings(const AISettings& values)
160{ 161{
161 rescue->setValue(values.rescue); 162 rescue->setValue(values.rescue);
162 eliminate->setValue(values.eliminate); 163 eliminate->setValue(values.eliminate);
163 expose->setValue(values.expose); 164 expose->setValue(values.expose);
164 protect->setValue(values.protect); 165 protect->setValue(values.protect);
165 safe->setValue(values.safe); 166 safe->setValue(values.safe);
166 empty->setValue(values.empty); 167 empty->setValue(values.empty);
167} 168}
168 169
169AISettings AI_Dialog::getAISettings() 170AISettings AI_Dialog::getAISettings()
170{ 171{
171 AISettings ai; 172 AISettings ai;
172 ai.rescue=rescue->value(); 173 ai.rescue=rescue->value();
173 ai.eliminate=eliminate->value(); 174 ai.eliminate=eliminate->value();
174 ai.expose=expose->value(); 175 ai.expose=expose->value();
175 ai.protect=protect->value(); 176 ai.protect=protect->value();
176 ai.safe= safe->value(); 177 ai.safe= safe->value();
177 ai.empty=empty->value(); 178 ai.empty=empty->value();
178 return ai; 179 return ai;
179} 180}
180 181
181void AI_Dialog::setHelpText(const QString& type) 182void AI_Dialog::setHelpText(const QString& type)
182{ 183{
183 if(type=="rescue") 184 if(type=="rescue")
184 { 185 {
185 help->setText(tr( "Bring the pieces out of the endzone" )); 186 help->setText(tr( "Bring the pieces out of the endzone" ));
186 } 187 }
187 else if(type=="eliminate") 188 else if(type=="eliminate")
188 { 189 {
189 help->setText(tr( "Eliminate an opponents piece" )); 190 help->setText(tr( "Eliminate an opponents piece" ));
190 } 191 }
191 else if(type=="expose") 192 else if(type=="expose")
192 { 193 {
193 help->setText(tr( "Expose you own pieces.\nAfter such a move only one piece will remain in the slot") ); 194 help->setText(tr( "Expose you own pieces.\nAfter such a move only one piece will remain in the slot") );
194 } 195 }
195 else if(type=="protect") 196 else if(type=="protect")
196 { 197 {
197 help->setText(tr( "Protect a single piece by\nputting another one in this slot" )); 198 help->setText(tr( "Protect a single piece by\nputting another one in this slot" ));
198 } 199 }
199 else if(type=="safe") 200 else if(type=="safe")
200 { 201 {
201 help->setText(tr( "Move piece to a slot already\noccupied by the player" )); 202 help->setText(tr( "Move piece to a slot already\noccupied by the player" ));
202 } 203 }
203 else if(type=="empty") 204 else if(type=="empty")
204 { 205 {
205 help->setText(tr( "Move piece to an empty slot") ); 206 help->setText(tr( "Move piece to an empty slot") );
206 } 207 }
207 else 208 else
208 { 209 {
209 help->setText(tr( "Press and hold the ? buttton\nnext to a field for help") ); 210 help->setText(tr( "Press and hold the ? buttton\nnext to a field for help") );
210 } 211 }
211} 212}
diff --git a/noncore/games/backgammon/filedialog.cpp b/noncore/games/backgammon/filedialog.cpp
index 6c858a2..a5e71c9 100644
--- a/noncore/games/backgammon/filedialog.cpp
+++ b/noncore/games/backgammon/filedialog.cpp
@@ -1,64 +1,65 @@
1#include "filedialog.h" 1#include "filedialog.h"
2 2
3#include <qdir.h> 3#include <qdir.h>
4#include <qfileinfo.h> 4#include <qfileinfo.h>
5#include <qmessagebox.h> 5#include <qmessagebox.h>
6#include <qpixmap.h> 6#include <qpixmap.h>
7#include <qpushbutton.h> 7#include <qpushbutton.h>
8#include <qpe/qpeapplication.h> 8#include <qpe/qpeapplication.h>
9 9
10FileDialog::FileDialog(QWidget* parent,QString header,QString extension,const char* name,bool modal,WFlags f) 10FileDialog::FileDialog(QWidget* parent,QString header,QString extension,const char* name,bool modal,WFlags f)
11 :QDialog(parent,name,modal,f) 11 :QDialog(parent,name,modal,f)
12{ 12{
13 setCaption(header); 13 setCaption(header);
14 ext=extension; 14 ext=extension;
15 dirselector=new QListView(this); 15 dirselector=new QListView(this);
16 dirselector->setGeometry(1,10,235,200); 16 dirselector->setGeometry(1,10,235,200);
17 dirselector->addColumn("Files"); 17 dirselector->addColumn("Files");
18 connect(dirselector,SIGNAL(clicked(QListViewItem*)),this,SLOT(selectorclicked(QListViewItem*))); 18 connect(dirselector,SIGNAL(clicked(QListViewItem*)),this,SLOT(selectorclicked(QListViewItem*)));
19 19
20 getCurrentDir(); 20 getCurrentDir();
21 21
22 file_name="user"; 22 file_name="user";
23 fileinput=new QLineEdit(file_name,this); 23 fileinput=new QLineEdit(file_name,this);
24 fileinput->setGeometry(1,220,235,20); 24 fileinput->setGeometry(1,220,235,20);
25 showMaximized(); 25
26} 26 QPEApplication::showDialog( this );
27 27}
28FileDialog::~FileDialog() 28
29{} 29FileDialog::~FileDialog()
30 30{}
31 31
32void FileDialog::selectorclicked(QListViewItem* entry) 32
33{ 33void FileDialog::selectorclicked(QListViewItem* entry)
34 if(entry==NULL) 34{
35 return; 35 if(entry==NULL)
36 file_name=entry->text(0); 36 return;
37 fileinput->setText(file_name); 37 file_name=entry->text(0);
38} 38 fileinput->setText(file_name);
39 39}
40void FileDialog::getCurrentDir() 40
41{ 41void FileDialog::getCurrentDir()
42 dirselector->clear(); 42{
43 QDir dir(QPEApplication::qpeDir()+"/backgammon"); 43 dirselector->clear();
44 dir.setFilter(QDir::Files); 44 QDir dir(QPEApplication::qpeDir()+"/backgammon");
45 QFileInfoListIterator it(*(dir.entryInfoList())); 45 dir.setFilter(QDir::Files);
46 QFileInfo* fi; 46 QFileInfoListIterator it(*(dir.entryInfoList()));
47 47 QFileInfo* fi;
48 int ext_length=ext.length(); 48
49 while((fi=it.current())) // go through all file and subdirs 49 int ext_length=ext.length();
50 { 50 while((fi=it.current())) // go through all file and subdirs
51 QString file=fi->fileName(); 51 {
52 if(file.right(ext_length)==ext && file) 52 QString file=fi->fileName();
53 { 53 if(file.right(ext_length)==ext && file)
54 file=file.left(file.length()-ext_length); 54 {
55 new QListViewItem(dirselector,file); 55 file=file.left(file.length()-ext_length);
56 } 56 new QListViewItem(dirselector,file);
57 ++it; 57 }
58 } 58 ++it;
59} 59 }
60 60}
61QString FileDialog::filename() 61
62{ 62QString FileDialog::filename()
63 return file_name; 63{
64} 64 return file_name;
65}
diff --git a/noncore/games/backgammon/playerdialog.cpp b/noncore/games/backgammon/playerdialog.cpp
index c16f202..0faf7e2 100644
--- a/noncore/games/backgammon/playerdialog.cpp
+++ b/noncore/games/backgammon/playerdialog.cpp
@@ -1,114 +1,116 @@
1#include "playerdialog.h" 1#include "playerdialog.h"
2 2
3#include <qgroupbox.h> 3#include <qgroupbox.h>
4 4
5#include <qpe/qpeapplication.h>
6
5PlayerDialog::PlayerDialog(QWidget* parent,const char* name,bool modal,WFlags f) 7PlayerDialog::PlayerDialog(QWidget* parent,const char* name,bool modal,WFlags f)
6 :QDialog(parent,name,modal,f) 8 :QDialog(parent,name,modal,f)
7{ 9{
8 auto2=false; 10 auto2=false;
9 auto2=true; 11 auto2=true;
10 setCaption("Player Settings"); 12 setCaption("Player Settings");
11 13
12 QGroupBox* player1_box=new QGroupBox("Player 1",this); 14 QGroupBox* player1_box=new QGroupBox("Player 1",this);
13 player1_box->setGeometry(10,30,220,60); 15 player1_box->setGeometry(10,30,220,60);
14 16
15 manual_button1=new QRadioButton("Human",player1_box); 17 manual_button1=new QRadioButton("Human",player1_box);
16 connect(manual_button1,SIGNAL(clicked()),this,SLOT(button_manual1())); 18 connect(manual_button1,SIGNAL(clicked()),this,SLOT(button_manual1()));
17 manual_button1->setGeometry(10,20,100,20); 19 manual_button1->setGeometry(10,20,100,20);
18 auto_button1=new QRadioButton("Computer",player1_box); 20 auto_button1=new QRadioButton("Computer",player1_box);
19 connect(auto_button1,SIGNAL(clicked()),this,SLOT(button_auto1())); 21 connect(auto_button1,SIGNAL(clicked()),this,SLOT(button_auto1()));
20 auto_button1->setGeometry(110,20,100,20); 22 auto_button1->setGeometry(110,20,100,20);
21 button1_state(auto1); 23 button1_state(auto1);
22 24
23 QGroupBox* player2_box=new QGroupBox("Player 2",this); 25 QGroupBox* player2_box=new QGroupBox("Player 2",this);
24 player2_box->setGeometry(10,150,220,60); 26 player2_box->setGeometry(10,150,220,60);
25 27
26 manual_button2=new QRadioButton("Human",player2_box); 28 manual_button2=new QRadioButton("Human",player2_box);
27 connect(manual_button2,SIGNAL(clicked()),this,SLOT(button_manual2())); 29 connect(manual_button2,SIGNAL(clicked()),this,SLOT(button_manual2()));
28 manual_button2->setGeometry(10,20,100,20); 30 manual_button2->setGeometry(10,20,100,20);
29 auto_button2=new QRadioButton("Computer",player2_box); 31 auto_button2=new QRadioButton("Computer",player2_box);
30 connect(auto_button2,SIGNAL(clicked()),this,SLOT(button_auto2())); 32 connect(auto_button2,SIGNAL(clicked()),this,SLOT(button_auto2()));
31 auto_button2->setGeometry(110,20,100,20); 33 auto_button2->setGeometry(110,20,100,20);
32 button2_state(auto2); 34 button2_state(auto2);
33 35
34 showMaximized(); 36 QPEApplication::showDialog( this );
35} 37}
36 38
37PlayerDialog::~PlayerDialog() 39PlayerDialog::~PlayerDialog()
38{} 40{}
39 41
40 42
41void PlayerDialog::button_manual1() 43void PlayerDialog::button_manual1()
42{ 44{
43 auto1=false; 45 auto1=false;
44 button1_state(auto1); 46 button1_state(auto1);
45} 47}
46 48
47void PlayerDialog::button_auto1() 49void PlayerDialog::button_auto1()
48{ 50{
49 auto1=true; 51 auto1=true;
50 button1_state(auto1); 52 button1_state(auto1);
51} 53}
52 54
53void PlayerDialog::button_manual2() 55void PlayerDialog::button_manual2()
54{ 56{
55 auto2=false; 57 auto2=false;
56 button2_state(auto2); 58 button2_state(auto2);
57} 59}
58 60
59void PlayerDialog::button_auto2() 61void PlayerDialog::button_auto2()
60{ 62{
61 auto2=true; 63 auto2=true;
62 button2_state(auto2); 64 button2_state(auto2);
63} 65}
64 66
65void PlayerDialog::button1_state(bool computer) 67void PlayerDialog::button1_state(bool computer)
66{ 68{
67 if(computer) 69 if(computer)
68 { 70 {
69 manual_button1->setChecked(false); 71 manual_button1->setChecked(false);
70 auto_button1->setChecked(true); 72 auto_button1->setChecked(true);
71 } 73 }
72 else 74 else
73 { 75 {
74 manual_button1->setChecked(true); 76 manual_button1->setChecked(true);
75 auto_button1->setChecked(false); 77 auto_button1->setChecked(false);
76 } 78 }
77} 79}
78 80
79void PlayerDialog::button2_state(bool computer) 81void PlayerDialog::button2_state(bool computer)
80{ 82{
81 if(computer) 83 if(computer)
82 { 84 {
83 manual_button2->setChecked(false); 85 manual_button2->setChecked(false);
84 auto_button2->setChecked(true); 86 auto_button2->setChecked(true);
85 } 87 }
86 else 88 else
87 { 89 {
88 manual_button2->setChecked(true); 90 manual_button2->setChecked(true);
89 auto_button2->setChecked(false); 91 auto_button2->setChecked(false);
90 } 92 }
91} 93}
92 94
93 95
94void PlayerDialog::setAuto1(bool newstate) 96void PlayerDialog::setAuto1(bool newstate)
95{ 97{
96 auto1=newstate; 98 auto1=newstate;
97 button1_state(auto1); 99 button1_state(auto1);
98} 100}
99 101
100bool PlayerDialog::getAuto1() 102bool PlayerDialog::getAuto1()
101{ 103{
102 return auto1; 104 return auto1;
103} 105}
104 106
105void PlayerDialog::setAuto2(bool newstate) 107void PlayerDialog::setAuto2(bool newstate)
106{ 108{
107 auto2=newstate; 109 auto2=newstate;
108 button2_state(auto2); 110 button2_state(auto2);
109} 111}
110 112
111bool PlayerDialog::getAuto2() 113bool PlayerDialog::getAuto2()
112{ 114{
113 return auto2; 115 return auto2;
114} 116}
diff --git a/noncore/games/backgammon/rulesdialog.cpp b/noncore/games/backgammon/rulesdialog.cpp
index 85c3db3..5e17eeb 100644
--- a/noncore/games/backgammon/rulesdialog.cpp
+++ b/noncore/games/backgammon/rulesdialog.cpp
@@ -1,77 +1,79 @@
1#include "rulesdialog.h" 1#include "rulesdialog.h"
2 2
3#include <qgroupbox.h> 3#include <qgroupbox.h>
4#include <qlabel.h> 4#include <qlabel.h>
5 5
6#include <qpe/qpeapplication.h>
7
6RulesDialog::RulesDialog(QWidget* parent,const char* name,bool modal,WFlags f) 8RulesDialog::RulesDialog(QWidget* parent,const char* name,bool modal,WFlags f)
7 : QDialog(parent,name,modal,f) 9 : QDialog(parent,name,modal,f)
8{ 10{
9 setCaption("Rules Configuration"); 11 setCaption("Rules Configuration");
10 QLabel* header=new QLabel("<b>Change the game rules here</b>",this); 12 QLabel* header=new QLabel("<b>Change the game rules here</b>",this);
11 header->setGeometry(10,10,200,20); 13 header->setGeometry(10,10,200,20);
12 14
13 // 15 //
14 QGroupBox* pieces_out_box=new QGroupBox("Movement",this); 16 QGroupBox* pieces_out_box=new QGroupBox("Movement",this);
15 pieces_out_box->setGeometry(10,10,220,120); 17 pieces_out_box->setGeometry(10,10,220,120);
16 18
17 pieces_out=new QCheckBox("Don't care about others",pieces_out_box); 19 pieces_out=new QCheckBox("Don't care about others",pieces_out_box);
18 pieces_out->setGeometry(10,20,200,20); 20 pieces_out->setGeometry(10,20,200,20);
19 connect(pieces_out,SIGNAL(clicked()),this,SLOT(pieces_out_clicked())); 21 connect(pieces_out,SIGNAL(clicked()),this,SLOT(pieces_out_clicked()));
20 22
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); 23 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); 24 pieces_out_help->setGeometry(10,40,200,60);
23 25
24 // 26 //
25 QGroupBox* nice_dice_box=new QGroupBox("Dice",this); 27 QGroupBox* nice_dice_box=new QGroupBox("Dice",this);
26 nice_dice_box->setGeometry(10,140,220,120); 28 nice_dice_box->setGeometry(10,140,220,120);
27 29
28 nice_dice=new QCheckBox("Big dice for small numbers",nice_dice_box); 30 nice_dice=new QCheckBox("Big dice for small numbers",nice_dice_box);
29 nice_dice->setGeometry(10,20,200,20); 31 nice_dice->setGeometry(10,20,200,20);
30 connect(nice_dice,SIGNAL(clicked()),this,SLOT(nice_dice_clicked())); 32 connect(nice_dice,SIGNAL(clicked()),this,SLOT(nice_dice_clicked()));
31 33
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); 34 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); 35 nice_dice_help->setGeometry(10,40,200,60);
34 36
35 showMaximized(); 37 QPEApplication::showDialog( this );
36} 38}
37 39
38 40
39RulesDialog::~RulesDialog() 41RulesDialog::~RulesDialog()
40{ 42{
41} 43}
42 44
43void RulesDialog::pieces_out_clicked() 45void RulesDialog::pieces_out_clicked()
44{ 46{
45 if(pieces_out->isChecked()) 47 if(pieces_out->isChecked())
46 rules.move_with_pieces_out=true; 48 rules.move_with_pieces_out=true;
47 else 49 else
48 rules.move_with_pieces_out=false; 50 rules.move_with_pieces_out=false;
49} 51}
50 52
51void RulesDialog::nice_dice_clicked() 53void RulesDialog::nice_dice_clicked()
52{ 54{
53 if(nice_dice->isChecked()) 55 if(nice_dice->isChecked())
54 rules.generous_dice=true; 56 rules.generous_dice=true;
55 else 57 else
56 rules.generous_dice=false; 58 rules.generous_dice=false;
57} 59}
58 60
59void RulesDialog::setRules(const Rules& new_rules) 61void RulesDialog::setRules(const Rules& new_rules)
60{ 62{
61 rules=new_rules; 63 rules=new_rules;
62 if(rules.move_with_pieces_out) 64 if(rules.move_with_pieces_out)
63 pieces_out->setChecked(true); 65 pieces_out->setChecked(true);
64 else 66 else
65 pieces_out->setChecked(false); 67 pieces_out->setChecked(false);
66 68
67 if(rules.generous_dice) 69 if(rules.generous_dice)
68 nice_dice->setChecked(true); 70 nice_dice->setChecked(true);
69 else 71 else
70 nice_dice->setChecked(false); 72 nice_dice->setChecked(false);
71} 73}
72 74
73Rules RulesDialog::getRules() 75Rules RulesDialog::getRules()
74{ 76{
75 return rules; 77 return rules;
76} 78}
77 79
diff --git a/noncore/games/backgammon/themedialog.cpp b/noncore/games/backgammon/themedialog.cpp
index dcb957c..f342381 100644
--- a/noncore/games/backgammon/themedialog.cpp
+++ b/noncore/games/backgammon/themedialog.cpp
@@ -1,163 +1,163 @@
1#include "themedialog.h" 1#include "themedialog.h"
2 2
3#include <qdir.h> 3#include <qdir.h>
4#include <qfileinfo.h> 4#include <qfileinfo.h>
5#include <qlabel.h> 5#include <qlabel.h>
6#include <qpushbutton.h> 6#include <qpushbutton.h>
7#include <qpe/qpeapplication.h> 7#include <qpe/qpeapplication.h>
8 8
9 9
10ThemeDialog::ThemeDialog(QWidget* parent,const char* name,bool modal,WFlags f) 10ThemeDialog::ThemeDialog(QWidget* parent,const char* name,bool modal,WFlags f)
11 :QDialog(parent,name,modal,f) 11 :QDialog(parent,name,modal,f)
12{ 12{
13 setCaption("Theme Dialog"); 13 setCaption("Theme Dialog");
14 QLabel* labelname=new QLabel("name",this); 14 QLabel* labelname=new QLabel("name",this);
15 labelname->setGeometry(0,5,40,20); 15 labelname->setGeometry(0,5,40,20);
16 lineName=new QLineEdit("user",this); 16 lineName=new QLineEdit("user",this);
17 lineName->setGeometry(40,5,195,20); 17 lineName->setGeometry(40,5,195,20);
18 18
19 QLabel* labelboard=new QLabel("board",this); 19 QLabel* labelboard=new QLabel("board",this);
20 labelboard->setGeometry(0,30,40,20); 20 labelboard->setGeometry(0,30,40,20);
21 boxboard=new QComboBox(this,""); 21 boxboard=new QComboBox(this,"");
22 boxboard->setGeometry(40,30,195,20); 22 boxboard->setGeometry(40,30,195,20);
23 fillBox("boards",boxboard); 23 fillBox("boards",boxboard);
24 24
25 QLabel* labelpiecesA=new QLabel("pieces1",this); 25 QLabel* labelpiecesA=new QLabel("pieces1",this);
26 labelpiecesA->setGeometry(0,70,40,20); 26 labelpiecesA->setGeometry(0,70,40,20);
27 boxpiecesA=new QComboBox(this); 27 boxpiecesA=new QComboBox(this);
28 boxpiecesA->setGeometry(40,70,195,20); 28 boxpiecesA->setGeometry(40,70,195,20);
29 fillBox("pieces",boxpiecesA); 29 fillBox("pieces",boxpiecesA);
30 30
31 QLabel* labelpiecesB=new QLabel("pieces2",this); 31 QLabel* labelpiecesB=new QLabel("pieces2",this);
32 labelpiecesB->setGeometry(0,95,40,20); 32 labelpiecesB->setGeometry(0,95,40,20);
33 boxpiecesB=new QComboBox(this); 33 boxpiecesB=new QComboBox(this);
34 boxpiecesB->setGeometry(40,95,195,20); 34 boxpiecesB->setGeometry(40,95,195,20);
35 fillBox("pieces",boxpiecesB); 35 fillBox("pieces",boxpiecesB);
36 36
37 QLabel* labeldiceA=new QLabel("dice1",this); 37 QLabel* labeldiceA=new QLabel("dice1",this);
38 labeldiceA->setGeometry(0,135,40,20); 38 labeldiceA->setGeometry(0,135,40,20);
39 boxdiceA=new QComboBox(this); 39 boxdiceA=new QComboBox(this);
40 boxdiceA->setGeometry(40,135,195,20); 40 boxdiceA->setGeometry(40,135,195,20);
41 fillBox("dice",boxdiceA); 41 fillBox("dice",boxdiceA);
42 42
43 QLabel* labeldiceB=new QLabel("dice2",this); 43 QLabel* labeldiceB=new QLabel("dice2",this);
44 labeldiceB->setGeometry(0,160,40,20); 44 labeldiceB->setGeometry(0,160,40,20);
45 boxdiceB=new QComboBox(this); 45 boxdiceB=new QComboBox(this);
46 boxdiceB->setGeometry(40,160,195,20); 46 boxdiceB->setGeometry(40,160,195,20);
47 fillBox("dice",boxdiceB); 47 fillBox("dice",boxdiceB);
48 48
49 QLabel* labelodds=new QLabel("odds",this); 49 QLabel* labelodds=new QLabel("odds",this);
50 labelodds->setGeometry(0,200,40,20); 50 labelodds->setGeometry(0,200,40,20);
51 boxodds=new QComboBox(this); 51 boxodds=new QComboBox(this);
52 boxodds->setGeometry(40,200,195,20); 52 boxodds->setGeometry(40,200,195,20);
53 fillBox("odds",boxodds); 53 fillBox("odds",boxodds);
54 boxodds->setEnabled(false); 54 boxodds->setEnabled(false);
55 55
56 QLabel* labeltable=new QLabel("table",this); 56 QLabel* labeltable=new QLabel("table",this);
57 labeltable->setGeometry(0,225,40,20); 57 labeltable->setGeometry(0,225,40,20);
58 boxtable=new QComboBox(this); 58 boxtable=new QComboBox(this);
59 boxtable->setGeometry(40,225,195,20); 59 boxtable->setGeometry(40,225,195,20);
60 fillBox("table",boxtable); 60 fillBox("table",boxtable);
61 61
62 showMaximized(); 62 QPEApplication::showDialog( this );
63} 63}
64 64
65ThemeDialog::~ThemeDialog() 65ThemeDialog::~ThemeDialog()
66{} 66{}
67 67
68 68
69ImageNames ThemeDialog::getNames() 69ImageNames ThemeDialog::getNames()
70{ 70{
71 ImageNames names; 71 ImageNames names;
72 names.theme=lineName->text(); 72 names.theme=lineName->text();
73 names.board=boxboard->currentText(); 73 names.board=boxboard->currentText();
74 names.pieces1=boxpiecesA->currentText(); 74 names.pieces1=boxpiecesA->currentText();
75 names.pieces2=boxpiecesB->currentText(); 75 names.pieces2=boxpiecesB->currentText();
76 names.dice1=boxdiceA->currentText(); 76 names.dice1=boxdiceA->currentText();
77 names.dice2=boxdiceB->currentText(); 77 names.dice2=boxdiceB->currentText();
78 names.odds=boxodds->currentText(); 78 names.odds=boxodds->currentText();
79 names.table=boxtable->currentText(); 79 names.table=boxtable->currentText();
80 return names; 80 return names;
81} 81}
82 82
83void ThemeDialog::setCurrent(const ImageNames& current) 83void ThemeDialog::setCurrent(const ImageNames& current)
84{ 84{
85 int a=0; 85 int a=0;
86 lineName->setText(current.theme); 86 lineName->setText(current.theme);
87 for(a=0;a<boxboard->count();a++) 87 for(a=0;a<boxboard->count();a++)
88 { 88 {
89 if(boxboard->text(a)==current.board) 89 if(boxboard->text(a)==current.board)
90 { 90 {
91 boxboard->setCurrentItem(a); 91 boxboard->setCurrentItem(a);
92 break; 92 break;
93 } 93 }
94 } 94 }
95 for(a=0;a<boxpiecesA->count();a++) 95 for(a=0;a<boxpiecesA->count();a++)
96 { 96 {
97 if(boxpiecesA->text(a)==current.pieces1) 97 if(boxpiecesA->text(a)==current.pieces1)
98 { 98 {
99 boxpiecesA->setCurrentItem(a); 99 boxpiecesA->setCurrentItem(a);
100 break; 100 break;
101 } 101 }
102 } 102 }
103 for(a=0;a<boxpiecesB->count();a++) 103 for(a=0;a<boxpiecesB->count();a++)
104 { 104 {
105 if(boxpiecesB->text(a)==current.pieces2) 105 if(boxpiecesB->text(a)==current.pieces2)
106 { 106 {
107 boxpiecesB->setCurrentItem(a); 107 boxpiecesB->setCurrentItem(a);
108 break; 108 break;
109 } 109 }
110 } 110 }
111 for(a=0;a<boxdiceA->count();a++) 111 for(a=0;a<boxdiceA->count();a++)
112 { 112 {
113 if(boxdiceA->text(a)==current.dice1) 113 if(boxdiceA->text(a)==current.dice1)
114 { 114 {
115 boxdiceA->setCurrentItem(a); 115 boxdiceA->setCurrentItem(a);
116 break; 116 break;
117 } 117 }
118 } 118 }
119 for(a=0;a<boxdiceB->count();a++) 119 for(a=0;a<boxdiceB->count();a++)
120 { 120 {
121 if(boxdiceB->text(a)==current.dice2) 121 if(boxdiceB->text(a)==current.dice2)
122 { 122 {
123 boxdiceB->setCurrentItem(a); 123 boxdiceB->setCurrentItem(a);
124 break; 124 break;
125 } 125 }
126 } 126 }
127 for(a=0;a<boxodds->count();a++) 127 for(a=0;a<boxodds->count();a++)
128 { 128 {
129 if(boxodds->text(a)==current.odds) 129 if(boxodds->text(a)==current.odds)
130 { 130 {
131 boxodds->setCurrentItem(a); 131 boxodds->setCurrentItem(a);
132 break; 132 break;
133 } 133 }
134 } 134 }
135 for(a=0;a<boxtable->count();a++) 135 for(a=0;a<boxtable->count();a++)
136 { 136 {
137 if(boxtable->text(a)==current.table) 137 if(boxtable->text(a)==current.table)
138 { 138 {
139 boxtable->setCurrentItem(a); 139 boxtable->setCurrentItem(a);
140 break; 140 break;
141 } 141 }
142 } 142 }
143} 143}
144 144
145void ThemeDialog::fillBox(QString dirname,QComboBox* thebox) 145void ThemeDialog::fillBox(QString dirname,QComboBox* thebox)
146{ 146{
147 thebox->clear(); 147 thebox->clear();
148 QDir dir(QPEApplication::qpeDir()+"/pics/backgammon/"+dirname); 148 QDir dir(QPEApplication::qpeDir()+"/pics/backgammon/"+dirname);
149 dir.setFilter(QDir::Dirs | QDir::Files); 149 dir.setFilter(QDir::Dirs | QDir::Files);
150 QFileInfoListIterator it(*(dir.entryInfoList())); 150 QFileInfoListIterator it(*(dir.entryInfoList()));
151 QFileInfo* fi; 151 QFileInfo* fi;
152 152
153 while((fi=it.current())) // go through all file and subdirs 153 while((fi=it.current())) // go through all file and subdirs
154 { 154 {
155 QString file=fi->fileName(); 155 QString file=fi->fileName();
156 if(file.right(4)==".png") 156 if(file.right(4)==".png")
157 { 157 {
158 thebox->insertItem(file.left(file.find(".png"))); 158 thebox->insertItem(file.left(file.find(".png")));
159 } 159 }
160 ++it; 160 ++it;
161 } 161 }
162 delete fi; 162 delete fi;
163} 163}
diff --git a/noncore/games/sfcave/helpwindow.cpp b/noncore/games/sfcave/helpwindow.cpp
index c920312..544e237 100644
--- a/noncore/games/sfcave/helpwindow.cpp
+++ b/noncore/games/sfcave/helpwindow.cpp
@@ -1,79 +1,81 @@
1/*************************************************************************** 1/***************************************************************************
2 helpwindow.cpp - description 2 helpwindow.cpp - description
3 ------------------- 3 -------------------
4 begin : Sun Sep 8 2002 4 begin : Sun Sep 8 2002
5 copyright : (C) 2002 by Andy Qua 5 copyright : (C) 2002 by Andy Qua
6 email : andy.qua@blueyonder.co.uk 6 email : andy.qua@blueyonder.co.uk
7 ***************************************************************************/ 7 ***************************************************************************/
8 8
9/*************************************************************************** 9/***************************************************************************
10 * * 10 * *
11 * This program is free software; you can redistribute it and/or modify * 11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by * 12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or * 13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. * 14 * (at your option) any later version. *
15 * * 15 * *
16 ***************************************************************************/ 16 ***************************************************************************/
17 17
18#include <qwidget.h> 18#include <qwidget.h>
19#include <qlayout.h> 19#include <qlayout.h>
20#include <qstring.h> 20#include <qstring.h>
21#include <qtextview.h> 21#include <qtextview.h>
22 22
23#include <qpe/qpeapplication.h>
24
23#include "helpwindow.h" 25#include "helpwindow.h"
24 26
25 27
26#define HELP_TEXT \ 28#define HELP_TEXT \
27"<qt><h1>SFCave Help</h1><p> " \ 29"<qt><h1>SFCave Help</h1><p> " \
28"SFCave is a flying game for the Zaurus.<br><br> " \ 30"SFCave is a flying game for the Zaurus.<br><br> " \
29"The aim is to stay alive for as long as possible and get the highest score " \ 31"The aim is to stay alive for as long as possible and get the highest score " \
30"you can.<br><br>" \ 32"you can.<br><br>" \
31"There are three game types currently - SFCave, Gates, and Fly.<br>" \ 33"There are three game types currently - SFCave, Gates, and Fly.<br>" \
32"<b>SFCave</b> is a remake of the classic SFCave game - fly through the " \ 34"<b>SFCave</b> is a remake of the classic SFCave game - fly through the " \
33"cavern avoiding all the blocks that just happen to be hanging in " \ 35"cavern avoiding all the blocks that just happen to be hanging in " \
34"midair<br><br>" \ 36"midair<br><br>" \
35"<b>Gates</b> is similar to SFCave but instead you must fly through the " \ 37"<b>Gates</b> is similar to SFCave but instead you must fly through the " \
36"without crashing.<br><br>" \ 38"without crashing.<br><br>" \
37"<b>Fly</b> is somewhat different to SFCave and above. Instead, you have " \ 39"<b>Fly</b> is somewhat different to SFCave and above. Instead, you have " \
38"are flying in the open air above a scrolling landscape, and the aim is to " \ 40"are flying in the open air above a scrolling landscape, and the aim is to " \
39"hug the ground - the closer to the land you fly the more points " \ 41"hug the ground - the closer to the land you fly the more points " \
40"scored.<br><br><br>" \ 42"scored.<br><br><br>" \
41"Basic instruction - Press <b>Up</B> or <b>Down</b> on the circle pad to " \ 43"Basic instruction - Press <b>Up</B> or <b>Down</b> on the circle pad to " \
42"start a new game, press the middle of the pad to apply thrust (makes you " \ 44"start a new game, press the middle of the pad to apply thrust (makes you " \
43"go up), and release the pad to remove thrust and drop down.<br><br>" \ 45"go up), and release the pad to remove thrust and drop down.<br><br>" \
44"Also, if playing the Fly game, you can press z to toggle the display " \ 46"Also, if playing the Fly game, you can press z to toggle the display " \
45"of the scoring zones. This will display 4 red lines at varying heights " \ 47"of the scoring zones. This will display 4 red lines at varying heights " \
46"above the landscape - if your ship falls into this zone, point are scored. " \ 48"above the landscape - if your ship falls into this zone, point are scored. " \
47"The closer to the landscape you get the more points you get.<br><br>" \ 49"The closer to the landscape you get the more points you get.<br><br>" \
48"In addition, SFCave has replays - save and load too so you can show off to all " \ 50"In addition, SFCave has replays - save and load too so you can show off to all " \
49"your friends (or vice versa). Currently, this is in its infancy but will improve.<br>" \ 51"your friends (or vice versa). Currently, this is in its infancy but will improve.<br>" \
50"To use, once you have crashed, press 'r' to replay the last game.<br>" \ 52"To use, once you have crashed, press 'r' to replay the last game.<br>" \
51"To save the replay press 's'.<br>" \ 53"To save the replay press 's'.<br>" \
52"To load a saved replay press 'l' (after you've crashed at least once).<br><br>" \ 54"To load a saved replay press 'l' (after you've crashed at least once).<br><br>" \
53"Replays are currently saved to your home directory in a file called sfcave.replay." \ 55"Replays are currently saved to your home directory in a file called sfcave.replay." \
54"This file can be copied and given to others as long as it it put in their home directory.<br><br>" \ 56"This file can be copied and given to others as long as it it put in their home directory.<br><br>" \
55"Have lots of fun.<br>" \ 57"Have lots of fun.<br>" \
56"Andy" \ 58"Andy" \
57"</p></qt>" 59"</p></qt>"
58 60
59 61
60HelpWindow::HelpWindow( QWidget *parent, const char *name, bool modal, WFlags flags ) 62HelpWindow::HelpWindow( QWidget *parent, const char *name, bool modal, WFlags flags )
61 : QDialog( parent, name, modal, flags ) 63 : QDialog( parent, name, modal, flags )
62{ 64{
63// resize( 230, 280 ); 65// resize( 230, 280 );
64 66
65 setCaption( "Help for SFCave" ); 67 setCaption( "Help for SFCave" );
66 68
67 QVBoxLayout *layout = new QVBoxLayout( this ); 69 QVBoxLayout *layout = new QVBoxLayout( this );
68 QString text = HELP_TEXT;; 70 QString text = HELP_TEXT;;
69 QTextView *view = new QTextView( text, 0, this, "view" ); 71 QTextView *view = new QTextView( text, 0, this, "view" );
70 layout->insertSpacing( -1, 5 ); 72 layout->insertSpacing( -1, 5 );
71 layout->insertWidget( -1, view ); 73 layout->insertWidget( -1, view );
72 layout->insertSpacing( -1, 5 ); 74 layout->insertSpacing( -1, 5 );
73 75
74 showMaximized(); 76 QPEApplication::showDialog( this );
75} 77}
76 78
77HelpWindow::~HelpWindow() 79HelpWindow::~HelpWindow()
78{ 80{
79} 81}
diff --git a/noncore/games/tetrix/ohighscoredlg.cpp b/noncore/games/tetrix/ohighscoredlg.cpp
index cf0dcf7..7581f51 100644
--- a/noncore/games/tetrix/ohighscoredlg.cpp
+++ b/noncore/games/tetrix/ohighscoredlg.cpp
@@ -1,199 +1,200 @@
1/*************************************************************************** 1/***************************************************************************
2 begin : January 2003 2 begin : January 2003
3 copyright : ( C ) 2003 by Carsten Niehaus 3 copyright : ( C ) 2003 by Carsten Niehaus
4 email : cniehaus@handhelds.org 4 email : cniehaus@handhelds.org
5 **************************************************************************/ 5 **************************************************************************/
6 6
7/*************************************************************************** 7/***************************************************************************
8 * * 8 * *
9 * This program is free software; you can redistribute it and/or modify * 9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by * 10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or * 11 * the Free Software Foundation; either version 2 of the License, or *
12 * ( at your option ) any later version. * 12 * ( at your option ) any later version. *
13 * * 13 * *
14 **************************************************************************/ 14 **************************************************************************/
15 15
16#include <qdialog.h> 16#include <qdialog.h>
17#include <qpe/config.h> 17#include <qpe/config.h>
18#include <qlayout.h> 18#include <qlayout.h>
19#include <qpe/config.h> 19#include <qpe/config.h>
20#include <qpe/qpeapplication.h>
20 21
21#include <qstring.h> 22#include <qstring.h>
22#include <qhbox.h> 23#include <qhbox.h>
23#include <qvbox.h> 24#include <qvbox.h>
24#include <qlabel.h> 25#include <qlabel.h>
25#include <qlistview.h> 26#include <qlistview.h>
26#include <qlineedit.h> 27#include <qlineedit.h>
27 28
28#include "ohighscoredlg.h" 29#include "ohighscoredlg.h"
29 30
30OHighscore::OHighscore( int score , int playerLevel ) 31OHighscore::OHighscore( int score , int playerLevel )
31{ 32{
32 pLevel = playerLevel; 33 pLevel = playerLevel;
33 getList(); 34 getList();
34 checkIfItIsANewhighscore( score ); 35 checkIfItIsANewhighscore( score );
35} 36}
36 37
37OHighscore::~OHighscore() 38OHighscore::~OHighscore()
38{ 39{
39 std::list<t_playerData*>::iterator deleteIterator = playerData.begin(); 40 std::list<t_playerData*>::iterator deleteIterator = playerData.begin();
40 for ( ; deleteIterator != playerData.end() ; deleteIterator++ ) 41 for ( ; deleteIterator != playerData.end() ; deleteIterator++ )
41 { 42 {
42 delete ( *deleteIterator ); 43 delete ( *deleteIterator );
43 } 44 }
44} 45}
45 46
46void OHighscore::getList() 47void OHighscore::getList()
47{ 48{
48 Config cfg ( "tetrix" ); 49 Config cfg ( "tetrix" );
49 cfg.setGroup( QString::number( 1 ) ); 50 cfg.setGroup( QString::number( 1 ) );
50 lowest = cfg.readNumEntry( "Points" ); 51 lowest = cfg.readNumEntry( "Points" );
51 playerData.clear(); 52 playerData.clear();
52 53
53 int rest = 1;//for the filling up later 54 int rest = 1;//for the filling up later
54 55
55 for ( int i = 1 ; i < 11 ; i++ ) 56 for ( int i = 1 ; i < 11 ; i++ )
56 { 57 {
57 if ( cfg.hasGroup( QString::number( i ) ) ) 58 if ( cfg.hasGroup( QString::number( i ) ) )
58 { 59 {
59 cfg.setGroup( QString::number( i ) ); 60 cfg.setGroup( QString::number( i ) );
60 int temp = cfg.readNumEntry( "Points" ); 61 int temp = cfg.readNumEntry( "Points" );
61 62
62 t_playerData *pPlayerData = new t_playerData; 63 t_playerData *pPlayerData = new t_playerData;
63 pPlayerData->sName = cfg.readEntry( "Name" ); 64 pPlayerData->sName = cfg.readEntry( "Name" );
64 pPlayerData->points = temp; 65 pPlayerData->points = temp;
65 pPlayerData->level = cfg.readNumEntry( "Level" ); 66 pPlayerData->level = cfg.readNumEntry( "Level" );
66 67
67 playerData.push_back( pPlayerData ); 68 playerData.push_back( pPlayerData );
68 69
69 if ( (temp < lowest) ) lowest = temp; 70 if ( (temp < lowest) ) lowest = temp;
70 rest++; 71 rest++;
71 } 72 }
72 } 73 }
73 74
74 //now I fill up the rest of the list 75 //now I fill up the rest of the list
75 if ( rest < 11 ) //only go in this loop if there are less than 76 if ( rest < 11 ) //only go in this loop if there are less than
76 //10 highscoreentries 77 //10 highscoreentries
77 { 78 {
78 lowest = 0; 79 lowest = 0;
79 for ( ; rest < 11 ; rest++ ) 80 for ( ; rest < 11 ; rest++ )
80 { 81 {
81 t_playerData *pPlayerData = new t_playerData; 82 t_playerData *pPlayerData = new t_playerData;
82 pPlayerData->sName = tr( "empty"); 83 pPlayerData->sName = tr( "empty");
83 pPlayerData->points = 0; 84 pPlayerData->points = 0;
84 pPlayerData->level = 0; 85 pPlayerData->level = 0;
85 86
86 playerData.push_back( pPlayerData ); 87 playerData.push_back( pPlayerData );
87 } 88 }
88 } 89 }
89 90
90} 91}
91 92
92void OHighscore::checkIfItIsANewhighscore( int points) 93void OHighscore::checkIfItIsANewhighscore( int points)
93{ 94{
94 if ( points > lowest ) 95 if ( points > lowest )
95 isNewhighscore = true; 96 isNewhighscore = true;
96 else 97 else
97 isNewhighscore = false; 98 isNewhighscore = false;
98} 99}
99 100
100void OHighscore::insertData( QString name , int punkte , int playerLevel ) 101void OHighscore::insertData( QString name , int punkte , int playerLevel )
101{ 102{
102 Config cfg ( "tetrix" ); 103 Config cfg ( "tetrix" );
103 int entryNumber = 1; 104 int entryNumber = 1;
104 std::list<t_playerData*>::iterator insertIterator = playerData.begin(); 105 std::list<t_playerData*>::iterator insertIterator = playerData.begin();
105 while ( insertIterator != playerData.end() ) 106 while ( insertIterator != playerData.end() )
106 { 107 {
107 if ( punkte > ( *insertIterator )->points ) 108 if ( punkte > ( *insertIterator )->points )
108 { 109 {
109 t_playerData* temp = new t_playerData; 110 t_playerData* temp = new t_playerData;
110 temp->sName = name; 111 temp->sName = name;
111 temp->points = punkte; 112 temp->points = punkte;
112 temp->level = playerLevel; 113 temp->level = playerLevel;
113 playerData.insert( insertIterator , temp ); 114 playerData.insert( insertIterator , temp );
114 115
115 //now we have to delete the last entry 116 //now we have to delete the last entry
116 insertIterator = playerData.end(); 117 insertIterator = playerData.end();
117 insertIterator--; 118 insertIterator--;
118 //X delete *insertIterator; //memleak? 119 //X delete *insertIterator; //memleak?
119 playerData.erase( insertIterator ); 120 playerData.erase( insertIterator );
120 121
121 ///////////////////////////////////////// 122 /////////////////////////////////////////
122 //this block just rewrites the highscore 123 //this block just rewrites the highscore
123 insertIterator = playerData.begin(); 124 insertIterator = playerData.begin();
124 while ( insertIterator != playerData.end() ) 125 while ( insertIterator != playerData.end() )
125 { 126 {
126 cfg.setGroup( QString::number( entryNumber ) ); 127 cfg.setGroup( QString::number( entryNumber ) );
127 cfg.writeEntry( "Name" , ( *insertIterator )->sName ); 128 cfg.writeEntry( "Name" , ( *insertIterator )->sName );
128 cfg.writeEntry( "Points" , ( *insertIterator )->points ); 129 cfg.writeEntry( "Points" , ( *insertIterator )->points );
129 cfg.writeEntry( "Level" , ( *insertIterator )->level ); 130 cfg.writeEntry( "Level" , ( *insertIterator )->level );
130 entryNumber++; 131 entryNumber++;
131 insertIterator++; 132 insertIterator++;
132 } 133 }
133 //////////////////////////////////////// 134 ////////////////////////////////////////
134 135
135 return; 136 return;
136 } 137 }
137 insertIterator++; 138 insertIterator++;
138 } 139 }
139} 140}
140 141
141QString OHighscore::getName() 142QString OHighscore::getName()
142{ 143{
143 QString name; 144 QString name;
144 QDialog *d = new QDialog ( this, 0, true ); 145 QDialog *d = new QDialog ( this, 0, true );
145 d->setCaption( tr( "Enter your name!" )); 146 d->setCaption( tr( "Enter your name!" ));
146 QLineEdit *ed = new QLineEdit ( d ); 147 QLineEdit *ed = new QLineEdit ( d );
147 ( new QVBoxLayout ( d, 3, 3 ))->addWidget ( ed ); 148 ( new QVBoxLayout ( d, 3, 3 ))->addWidget ( ed );
148 ed->setFocus ( ); 149 ed->setFocus ( );
149 150
150 if ( d->exec() == QDialog::Accepted ) { 151 if ( d->exec() == QDialog::Accepted ) {
151 name = ed->text(); 152 name = ed->text();
152 } 153 }
153 //delete d; 154 //delete d;
154 return name; 155 return name;
155} 156}
156 157
157OHighscoreDialog::OHighscoreDialog(OHighscore *highscore, QWidget *parent, const char *name, bool modal) : QDialog(parent, name, modal) 158OHighscoreDialog::OHighscoreDialog(OHighscore *highscore, QWidget *parent, const char *name, bool modal) : QDialog(parent, name, modal)
158{ 159{
159 hs_ = highscore; 160 hs_ = highscore;
160 setCaption( tr( "Highscores" ) ); 161 setCaption( tr( "Highscores" ) );
161 vbox_layout = new QVBoxLayout( this, 4 , 4 ); 162 vbox_layout = new QVBoxLayout( this, 4 , 4 );
162 list = new QListView( this ); 163 list = new QListView( this );
163 list->setSorting( -1 ); 164 list->setSorting( -1 );
164 list->addColumn( tr( "#" )); 165 list->addColumn( tr( "#" ));
165 list->addColumn( tr( "Name" )); 166 list->addColumn( tr( "Name" ));
166 list->addColumn( tr( "Points" )); 167 list->addColumn( tr( "Points" ));
167 list->addColumn( tr( "Level" )); 168 list->addColumn( tr( "Level" ));
168 169
169 createHighscoreListView(); 170 createHighscoreListView();
170 171
171 vbox_layout->addWidget( list ); 172 vbox_layout->addWidget( list );
172 showMaximized(); 173 QPEApplication::showDialog( this );
173} 174}
174 175
175void OHighscoreDialog::createHighscoreListView() 176void OHighscoreDialog::createHighscoreListView()
176{ 177{
177 int pos = 10; 178 int pos = 10;
178 int points_ = 0; 179 int points_ = 0;
179 int level_ = 0; 180 int level_ = 0;
180 181
181 std::list<t_playerData*>::reverse_iterator iListe = hs_->playerData.rbegin(); 182 std::list<t_playerData*>::reverse_iterator iListe = hs_->playerData.rbegin();
182 183
183 for ( ; iListe != hs_->playerData.rend() ; ++iListe ) 184 for ( ; iListe != hs_->playerData.rend() ; ++iListe )
184 { 185 {
185 QListViewItem *item = new QListViewItem( list ); 186 QListViewItem *item = new QListViewItem( list );
186 item->setText( 0 , QString::number( pos ) ); //number 187 item->setText( 0 , QString::number( pos ) ); //number
187 item->setText( 1 , ( *iListe )->sName ); //name 188 item->setText( 1 , ( *iListe )->sName ); //name
188 if ( ( *iListe )->points == -1 ) 189 if ( ( *iListe )->points == -1 )
189 points_ = 0; 190 points_ = 0;
190 else points_ = ( *iListe )->points; 191 else points_ = ( *iListe )->points;
191 if ( ( *iListe )->level == -1 ) 192 if ( ( *iListe )->level == -1 )
192 level_ = 0; 193 level_ = 0;
193 else level_ = ( *iListe )->level; 194 else level_ = ( *iListe )->level;
194 item->setText( 2 , QString::number( points_ ) ); //points 195 item->setText( 2 , QString::number( points_ ) ); //points
195 item->setText( 3 , QString::number( level_ ) ); //level 196 item->setText( 3 , QString::number( level_ ) ); //level
196 pos--; 197 pos--;
197 } 198 }
198} 199}
199 200
diff --git a/noncore/games/tictac/tictac.cpp b/noncore/games/tictac/tictac.cpp
index 4954ba4..9de3b58 100644
--- a/noncore/games/tictac/tictac.cpp
+++ b/noncore/games/tictac/tictac.cpp
@@ -1,382 +1,382 @@
1/**************************************************************************** 1/****************************************************************************
2 ** tictac.cpp,v 1.3.8.1 2003/08/29 06:50:40 harlekin Exp 2 ** tictac.cpp,v 1.3.8.1 2003/08/29 06:50:40 harlekin Exp
3 ** 3 **
4 ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. 4 ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
5 ** 5 **
6 ** This file is part of an example program for Qt. This example 6 ** This file is part of an example program for Qt. This example
7 ** program may be used, distributed and modified without limitation. 7 ** program may be used, distributed and modified without limitation.
8 ** 8 **
9 *****************************************************************************/ 9 *****************************************************************************/
10 10
11#include "tictac.h" 11#include "tictac.h"
12#include <qpe/qpeapplication.h> 12#include <qpe/qpeapplication.h>
13#include <qpainter.h> 13#include <qpainter.h>
14#include <qdrawutil.h> 14#include <qdrawutil.h>
15#include <qcombobox.h> 15#include <qcombobox.h>
16#include <qcheckbox.h> 16#include <qcheckbox.h>
17#include <qlabel.h> 17#include <qlabel.h>
18#include <qlayout.h> 18#include <qlayout.h>
19#include <stdlib.h> // rand() function 19#include <stdlib.h> // rand() function
20#include <qdatetime.h> // seed for rand() 20#include <qdatetime.h> // seed for rand()
21#include <qstringlist.h> //needed for proper internationalization 21#include <qstringlist.h> //needed for proper internationalization
22 22
23 23
24//*************************************************************************** 24//***************************************************************************
25//* TicTacButton member functions 25//* TicTacButton member functions
26//*************************************************************************** 26//***************************************************************************
27 27
28// -------------------------------------------------------------------------- 28// --------------------------------------------------------------------------
29// Creates a TicTacButton 29// Creates a TicTacButton
30// 30//
31 31
32TicTacButton::TicTacButton( QWidget *parent ) : QPushButton( parent ) 32TicTacButton::TicTacButton( QWidget *parent ) : QPushButton( parent )
33{ 33{
34 t = Blank; // initial type 34 t = Blank; // initial type
35} 35}
36 36
37// -------------------------------------------------------------------------- 37// --------------------------------------------------------------------------
38// Paints TicTacButton 38// Paints TicTacButton
39// 39//
40 40
41void TicTacButton::drawButtonLabel( QPainter *p ) 41void TicTacButton::drawButtonLabel( QPainter *p )
42{ 42{
43 QRect r = rect(); 43 QRect r = rect();
44 p->setPen( QPen( white,2 ) ); // set fat pen 44 p->setPen( QPen( white,2 ) ); // set fat pen
45 if ( t == Circle ) { 45 if ( t == Circle ) {
46 p->drawEllipse( r.left()+4, r.top()+4, r.width()-8, r.height()-8 ); 46 p->drawEllipse( r.left()+4, r.top()+4, r.width()-8, r.height()-8 );
47 } else if ( t == Cross ) { // draw cross 47 } else if ( t == Cross ) { // draw cross
48 p->drawLine( r.topLeft() +QPoint(4,4), r.bottomRight()-QPoint(4,4)); 48 p->drawLine( r.topLeft() +QPoint(4,4), r.bottomRight()-QPoint(4,4));
49 p->drawLine( r.bottomLeft()+QPoint(4,-4),r.topRight() -QPoint(4,-4)); 49 p->drawLine( r.bottomLeft()+QPoint(4,-4),r.topRight() -QPoint(4,-4));
50 } 50 }
51} 51}
52 52
53 53
54//*************************************************************************** 54//***************************************************************************
55//* TicTacGameBoard member functions 55//* TicTacGameBoard member functions
56//*************************************************************************** 56//***************************************************************************
57 57
58// -------------------------------------------------------------------------- 58// --------------------------------------------------------------------------
59// Creates a game board with N x N buttons and connects the "clicked()" 59// Creates a game board with N x N buttons and connects the "clicked()"
60// signal of all buttons to the "buttonClicked()" slot. 60// signal of all buttons to the "buttonClicked()" slot.
61// 61//
62 62
63TicTacGameBoard::TicTacGameBoard( int n, QWidget *parent, const char *name ) 63TicTacGameBoard::TicTacGameBoard( int n, QWidget *parent, const char *name )
64 : QWidget( parent, name ) 64 : QWidget( parent, name )
65{ 65{
66 showMaximized(); 66 QPEApplication::showWidget( this );
67 st = Init; // initial state 67 st = Init; // initial state
68 nBoard = n; 68 nBoard = n;
69 n *= n; // make square 69 n *= n; // make square
70 comp_starts = FALSE; // human starts 70 comp_starts = FALSE; // human starts
71 buttons = new TicTacButtons(n); // create real buttons 71 buttons = new TicTacButtons(n); // create real buttons
72 btArray = new TicTacArray(n); // create button model 72 btArray = new TicTacArray(n); // create button model
73 QGridLayout * grid = new QGridLayout( this, 3, 3, 4 ); 73 QGridLayout * grid = new QGridLayout( this, 3, 3, 4 );
74 QPalette p( blue ); 74 QPalette p( blue );
75 for ( int i=0; i<n; i++ ) { // create and connect buttons 75 for ( int i=0; i<n; i++ ) { // create and connect buttons
76 TicTacButton *ttb = new TicTacButton( this ); 76 TicTacButton *ttb = new TicTacButton( this );
77 ttb->setPalette( p ); 77 ttb->setPalette( p );
78 ttb->setEnabled( FALSE ); 78 ttb->setEnabled( FALSE );
79 connect( ttb, SIGNAL(clicked()), SLOT(buttonClicked()) ); 79 connect( ttb, SIGNAL(clicked()), SLOT(buttonClicked()) );
80 grid->addWidget( ttb, i%3, i/3 ); 80 grid->addWidget( ttb, i%3, i/3 );
81 buttons->insert( i, ttb ); 81 buttons->insert( i, ttb );
82 btArray->at(i) = TicTacButton::Blank; // initial button type 82 btArray->at(i) = TicTacButton::Blank; // initial button type
83 } 83 }
84 QTime t = QTime::currentTime(); // set random seed 84 QTime t = QTime::currentTime(); // set random seed
85 srand( t.hour()*12+t.minute()*60+t.second()*60 ); 85 srand( t.hour()*12+t.minute()*60+t.second()*60 );
86} 86}
87 87
88TicTacGameBoard::~TicTacGameBoard() 88TicTacGameBoard::~TicTacGameBoard()
89{ 89{
90 delete buttons; 90 delete buttons;
91 delete btArray; 91 delete btArray;
92} 92}
93 93
94 94
95// -------------------------------------------------------------------------- 95// --------------------------------------------------------------------------
96// TicTacGameBoard::computerStarts( bool v ) 96// TicTacGameBoard::computerStarts( bool v )
97// 97//
98// Computer starts if v=TRUE. The human starts by default. 98// Computer starts if v=TRUE. The human starts by default.
99// 99//
100 100
101void TicTacGameBoard::computerStarts( bool v ) 101void TicTacGameBoard::computerStarts( bool v )
102{ 102{
103 comp_starts = v; 103 comp_starts = v;
104} 104}
105 105
106 106
107// -------------------------------------------------------------------------- 107// --------------------------------------------------------------------------
108// TicTacGameBoard::newGame() 108// TicTacGameBoard::newGame()
109// 109//
110// Clears the game board and prepares for a new game 110// Clears the game board and prepares for a new game
111// 111//
112 112
113void TicTacGameBoard::newGame() 113void TicTacGameBoard::newGame()
114{ 114{
115 st = HumansTurn; 115 st = HumansTurn;
116 for ( int i=0; i<nBoard*nBoard; i++ ) 116 for ( int i=0; i<nBoard*nBoard; i++ )
117 btArray->at(i) = TicTacButton::Blank; 117 btArray->at(i) = TicTacButton::Blank;
118 if ( comp_starts ) 118 if ( comp_starts )
119 computerMove(); 119 computerMove();
120 else 120 else
121 updateButtons(); 121 updateButtons();
122} 122}
123 123
124 124
125// -------------------------------------------------------------------------- 125// --------------------------------------------------------------------------
126// TicTacGameBoard::buttonClicked() - SLOT 126// TicTacGameBoard::buttonClicked() - SLOT
127// 127//
128// This slot is activated when a TicTacButton emits the signal "clicked()", 128// This slot is activated when a TicTacButton emits the signal "clicked()",
129// i.e. the user has clicked on a TicTacButton. 129// i.e. the user has clicked on a TicTacButton.
130// 130//
131 131
132void TicTacGameBoard::buttonClicked() 132void TicTacGameBoard::buttonClicked()
133{ 133{
134 if ( st != HumansTurn ) // not ready 134 if ( st != HumansTurn ) // not ready
135 return; 135 return;
136 int i = buttons->findRef( (TicTacButton*)sender() ); 136 int i = buttons->findRef( (TicTacButton*)sender() );
137 TicTacButton *b = buttons->at(i); // get piece that was pressed 137 TicTacButton *b = buttons->at(i); // get piece that was pressed
138 if ( b->type() == TicTacButton::Blank ) { // empty piece? 138 if ( b->type() == TicTacButton::Blank ) { // empty piece?
139 btArray->at(i) = TicTacButton::Circle; 139 btArray->at(i) = TicTacButton::Circle;
140 updateButtons(); 140 updateButtons();
141 if ( checkBoard( btArray ) == 0 ) // not a winning move? 141 if ( checkBoard( btArray ) == 0 ) // not a winning move?
142 computerMove(); 142 computerMove();
143 int s = checkBoard( btArray ); 143 int s = checkBoard( btArray );
144 if ( s ) { // any winners yet? 144 if ( s ) { // any winners yet?
145 st = s == TicTacButton::Circle ? HumanWon : ComputerWon; 145 st = s == TicTacButton::Circle ? HumanWon : ComputerWon;
146 emit finished(); 146 emit finished();
147 } 147 }
148 } 148 }
149} 149}
150 150
151 151
152// -------------------------------------------------------------------------- 152// --------------------------------------------------------------------------
153// TicTacGameBoard::updateButtons() 153// TicTacGameBoard::updateButtons()
154// 154//
155// Updates all buttons that have changed state 155// Updates all buttons that have changed state
156// 156//
157 157
158void TicTacGameBoard::updateButtons() 158void TicTacGameBoard::updateButtons()
159{ 159{
160 for ( int i=0; i<nBoard*nBoard; i++ ) { 160 for ( int i=0; i<nBoard*nBoard; i++ ) {
161 if ( buttons->at(i)->type() != btArray->at(i) ) 161 if ( buttons->at(i)->type() != btArray->at(i) )
162 buttons->at(i)->setType( (TicTacButton::Type)btArray->at(i) ); 162 buttons->at(i)->setType( (TicTacButton::Type)btArray->at(i) );
163 buttons->at(i)->setEnabled( buttons->at(i)->type() == 163 buttons->at(i)->setEnabled( buttons->at(i)->type() ==
164 TicTacButton::Blank ); 164 TicTacButton::Blank );
165 } 165 }
166} 166}
167 167
168 168
169// -------------------------------------------------------------------------- 169// --------------------------------------------------------------------------
170// TicTacGameBoard::checkBoard() 170// TicTacGameBoard::checkBoard()
171// 171//
172// Checks if one of the players won the game, works for any board size. 172// Checks if one of the players won the game, works for any board size.
173// 173//
174// Returns: 174// Returns:
175// - TicTacButton::Cross if the player with X buttons won 175// - TicTacButton::Cross if the player with X buttons won
176// - TicTacButton::Circle if the player with O buttons won 176// - TicTacButton::Circle if the player with O buttons won
177// - Zero (0) if there is no winner yet 177// - Zero (0) if there is no winner yet
178// 178//
179 179
180int TicTacGameBoard::checkBoard( TicTacArray *a ) 180int TicTacGameBoard::checkBoard( TicTacArray *a )
181{ 181{
182 int t = 0; 182 int t = 0;
183 int row, col; 183 int row, col;
184 bool won = FALSE; 184 bool won = FALSE;
185 for ( row=0; row<nBoard && !won; row++ ) { // check horizontal 185 for ( row=0; row<nBoard && !won; row++ ) { // check horizontal
186 t = a->at(row*nBoard); 186 t = a->at(row*nBoard);
187 if ( t == TicTacButton::Blank ) 187 if ( t == TicTacButton::Blank )
188 continue; 188 continue;
189 col = 1; 189 col = 1;
190 while ( col<nBoard && a->at(row*nBoard+col) == t ) 190 while ( col<nBoard && a->at(row*nBoard+col) == t )
191 col++; 191 col++;
192 if ( col == nBoard ) 192 if ( col == nBoard )
193 won = TRUE; 193 won = TRUE;
194 } 194 }
195 for ( col=0; col<nBoard && !won; col++ ) { // check vertical 195 for ( col=0; col<nBoard && !won; col++ ) { // check vertical
196 t = a->at(col); 196 t = a->at(col);
197 if ( t == TicTacButton::Blank ) 197 if ( t == TicTacButton::Blank )
198 continue; 198 continue;
199 row = 1; 199 row = 1;
200 while ( row<nBoard && a->at(row*nBoard+col) == t ) 200 while ( row<nBoard && a->at(row*nBoard+col) == t )
201 row++; 201 row++;
202 if ( row == nBoard ) 202 if ( row == nBoard )
203 won = TRUE; 203 won = TRUE;
204 } 204 }
205 if ( !won ) { // check diagonal top left 205 if ( !won ) { // check diagonal top left
206 t = a->at(0); // to bottom right 206 t = a->at(0); // to bottom right
207 if ( t != TicTacButton::Blank ) { 207 if ( t != TicTacButton::Blank ) {
208 int i = 1; 208 int i = 1;
209 while ( i<nBoard && a->at(i*nBoard+i) == t ) 209 while ( i<nBoard && a->at(i*nBoard+i) == t )
210 i++; 210 i++;
211 if ( i == nBoard ) 211 if ( i == nBoard )
212 won = TRUE; 212 won = TRUE;
213 } 213 }
214 } 214 }
215 if ( !won ) { // check diagonal bottom left 215 if ( !won ) { // check diagonal bottom left
216 int j = nBoard-1; // to top right 216 int j = nBoard-1; // to top right
217 int i = 0; 217 int i = 0;
218 t = a->at(i+j*nBoard); 218 t = a->at(i+j*nBoard);
219 if ( t != TicTacButton::Blank ) { 219 if ( t != TicTacButton::Blank ) {
220 i++; j--; 220 i++; j--;
221 while ( i<nBoard && a->at(i+j*nBoard) == t ) { 221 while ( i<nBoard && a->at(i+j*nBoard) == t ) {
222 i++; j--; 222 i++; j--;
223 } 223 }
224 if ( i == nBoard ) 224 if ( i == nBoard )
225 won = TRUE; 225 won = TRUE;
226 } 226 }
227 } 227 }
228 if ( !won ) // no winner 228 if ( !won ) // no winner
229 t = 0; 229 t = 0;
230 return t; 230 return t;
231} 231}
232 232
233 233
234// -------------------------------------------------------------------------- 234// --------------------------------------------------------------------------
235// TicTacGameBoard::computerMove() 235// TicTacGameBoard::computerMove()
236// 236//
237// Puts a piece on the game board. Very, very simple. 237// Puts a piece on the game board. Very, very simple.
238// 238//
239 239
240void TicTacGameBoard::computerMove() 240void TicTacGameBoard::computerMove()
241{ 241{
242 int numButtons = nBoard*nBoard; 242 int numButtons = nBoard*nBoard;
243 int *altv = new int[numButtons]; // buttons alternatives 243 int *altv = new int[numButtons]; // buttons alternatives
244 int altc = 0; 244 int altc = 0;
245 int stopHuman = -1; 245 int stopHuman = -1;
246 TicTacArray a = btArray->copy(); 246 TicTacArray a = btArray->copy();
247 int i; 247 int i;
248 for ( i=0; i<numButtons; i++ ) { // try all positions 248 for ( i=0; i<numButtons; i++ ) { // try all positions
249 if ( a[i] != TicTacButton::Blank ) // already a piece there 249 if ( a[i] != TicTacButton::Blank ) // already a piece there
250 continue; 250 continue;
251 a[i] = TicTacButton::Cross; // test if computer wins 251 a[i] = TicTacButton::Cross; // test if computer wins
252 if ( checkBoard(&a) == a[i] ) { // computer will win 252 if ( checkBoard(&a) == a[i] ) { // computer will win
253 st = ComputerWon; 253 st = ComputerWon;
254 stopHuman = -1; 254 stopHuman = -1;
255 break; 255 break;
256 } 256 }
257 a[i] = TicTacButton::Circle; // test if human wins 257 a[i] = TicTacButton::Circle; // test if human wins
258 if ( checkBoard(&a) == a[i] ) { // oops... 258 if ( checkBoard(&a) == a[i] ) { // oops...
259 stopHuman = i; // remember position 259 stopHuman = i; // remember position
260 a[i] = TicTacButton::Blank; // restore button 260 a[i] = TicTacButton::Blank; // restore button
261 continue; // computer still might win 261 continue; // computer still might win
262 } 262 }
263 a[i] = TicTacButton::Blank; // restore button 263 a[i] = TicTacButton::Blank; // restore button
264 altv[altc++] = i; // remember alternative 264 altv[altc++] = i; // remember alternative
265 } 265 }
266 if ( stopHuman >= 0 ) // must stop human from winning 266 if ( stopHuman >= 0 ) // must stop human from winning
267 a[stopHuman] = TicTacButton::Cross; 267 a[stopHuman] = TicTacButton::Cross;
268 else if ( i == numButtons ) { // tried all alternatives 268 else if ( i == numButtons ) { // tried all alternatives
269 if ( altc > 0 ) // set random piece 269 if ( altc > 0 ) // set random piece
270 a[altv[rand()%(altc--)]] = TicTacButton::Cross; 270 a[altv[rand()%(altc--)]] = TicTacButton::Cross;
271 if ( altc == 0 ) { // no more blanks 271 if ( altc == 0 ) { // no more blanks
272 st = NobodyWon; 272 st = NobodyWon;
273 emit finished(); 273 emit finished();
274 } 274 }
275 } 275 }
276 *btArray = a; // update model 276 *btArray = a; // update model
277 updateButtons(); // update buttons 277 updateButtons(); // update buttons
278 delete[] altv; 278 delete[] altv;
279} 279}
280 280
281 281
282//*************************************************************************** 282//***************************************************************************
283//* TicTacToe member functions 283//* TicTacToe member functions
284//*************************************************************************** 284//***************************************************************************
285 285
286// -------------------------------------------------------------------------- 286// --------------------------------------------------------------------------
287// Creates a game widget with a game board and two push buttons, and connects 287// Creates a game widget with a game board and two push buttons, and connects
288// signals of child widgets to slots. 288// signals of child widgets to slots.
289// 289//
290 290
291TicTacToe::TicTacToe( QWidget *parent, const char *name, WFlags fl ) 291TicTacToe::TicTacToe( QWidget *parent, const char *name, WFlags fl )
292 : QWidget( parent, name, fl ) 292 : QWidget( parent, name, fl )
293{ 293{
294 QVBoxLayout * l = new QVBoxLayout( this, 6 ); 294 QVBoxLayout * l = new QVBoxLayout( this, 6 );
295 295
296 // Create a message label 296 // Create a message label
297 boardSize = 3; 297 boardSize = 3;
298 298
299 message = new QLabel( this ); 299 message = new QLabel( this );
300 message->setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); 300 message->setFrameStyle( QFrame::WinPanel | QFrame::Sunken );
301 message->setAlignment( AlignCenter ); 301 message->setAlignment( AlignCenter );
302 l->addWidget( message ); 302 l->addWidget( message );
303 303
304 // Create the game board and connect the signal finished() to this 304 // Create the game board and connect the signal finished() to this
305 // gameOver() slot 305 // gameOver() slot
306 306
307 board = new TicTacGameBoard( boardSize, this ); 307 board = new TicTacGameBoard( boardSize, this );
308 connect( board, SIGNAL(finished()), SLOT(gameOver()) ); 308 connect( board, SIGNAL(finished()), SLOT(gameOver()) );
309 l->addWidget( board ); 309 l->addWidget( board );
310 310
311 // Create a horizontal frame line 311 // Create a horizontal frame line
312 312
313 QFrame *line = new QFrame( this ); 313 QFrame *line = new QFrame( this );
314 line->setFrameStyle( QFrame::HLine | QFrame::Sunken ); 314 line->setFrameStyle( QFrame::HLine | QFrame::Sunken );
315 l->addWidget( line ); 315 l->addWidget( line );
316 316
317 // Create the combo box for deciding who should start, and 317 // Create the combo box for deciding who should start, and
318 // connect its clicked() signals to the buttonClicked() slot 318 // connect its clicked() signals to the buttonClicked() slot
319 319
320 whoStarts = new QComboBox( this ); 320 whoStarts = new QComboBox( this );
321 whoStarts->insertItem( tr( "Computer starts" ) ); 321 whoStarts->insertItem( tr( "Computer starts" ) );
322 whoStarts->insertItem( tr( "Human starts" ) ); 322 whoStarts->insertItem( tr( "Human starts" ) );
323 l->addWidget( whoStarts ); 323 l->addWidget( whoStarts );
324 324
325 // Create the push buttons and connect their clicked() signals 325 // Create the push buttons and connect their clicked() signals
326 // to this right slots. 326 // to this right slots.
327 327
328 newGame = new QPushButton( tr( "Play!" ), this ); 328 newGame = new QPushButton( tr( "Play!" ), this );
329 connect( newGame, SIGNAL(clicked()), SLOT(newGameClicked()) ); 329 connect( newGame, SIGNAL(clicked()), SLOT(newGameClicked()) );
330 quit = new QPushButton( tr( "Quit" ), this ); 330 quit = new QPushButton( tr( "Quit" ), this );
331 connect( quit, SIGNAL(clicked()), qApp, SLOT(quit()) ); 331 connect( quit, SIGNAL(clicked()), qApp, SLOT(quit()) );
332 QHBoxLayout * b = new QHBoxLayout; 332 QHBoxLayout * b = new QHBoxLayout;
333 l->addLayout( b ); 333 l->addLayout( b );
334 b->addWidget( newGame ); 334 b->addWidget( newGame );
335 b->addWidget( quit ); 335 b->addWidget( quit );
336 showMaximized(); 336 QPEApplication::showWidget( this );
337 newState(); 337 newState();
338} 338}
339 339
340 340
341// -------------------------------------------------------------------------- 341// --------------------------------------------------------------------------
342// TicTacToe::newGameClicked() - SLOT 342// TicTacToe::newGameClicked() - SLOT
343// 343//
344// This slot is activated when the new game button is clicked. 344// This slot is activated when the new game button is clicked.
345// 345//
346 346
347void TicTacToe::newGameClicked() 347void TicTacToe::newGameClicked()
348{ 348{
349 board->computerStarts( whoStarts->currentItem() == 0 ); 349 board->computerStarts( whoStarts->currentItem() == 0 );
350 board->newGame(); 350 board->newGame();
351 newState(); 351 newState();
352} 352}
353 353
354 354
355// -------------------------------------------------------------------------- 355// --------------------------------------------------------------------------
356// TicTacToe::gameOver() - SLOT 356// TicTacToe::gameOver() - SLOT
357// 357//
358// This slot is activated when the TicTacGameBoard emits the signal 358// This slot is activated when the TicTacGameBoard emits the signal
359// "finished()", i.e. when a player has won or when it is a draw. 359// "finished()", i.e. when a player has won or when it is a draw.
360// 360//
361 361
362void TicTacToe::gameOver() 362void TicTacToe::gameOver()
363{ 363{
364 newState(); // update text box 364 newState(); // update text box
365} 365}
366 366
367 367
368// -------------------------------------------------------------------------- 368// --------------------------------------------------------------------------
369// Updates the message to reflect a new state. 369// Updates the message to reflect a new state.
370// 370//
371 371
372void TicTacToe::newState() 372void TicTacToe::newState()
373{ 373{
374 QStringList msg; 374 QStringList msg;
375 msg << tr( "Click Play to start") 375 msg << tr( "Click Play to start")
376 << tr("Make your move") 376 << tr("Make your move")
377 << tr("You won!") 377 << tr("You won!")
378 << tr("Computer won!") 378 << tr("Computer won!")
379 << tr("It's a draw"); 379 << tr("It's a draw");
380 message->setText( msg[board->state()] ); 380 message->setText( msg[board->state()] );
381 return; 381 return;
382} 382}