00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <opie2/oapplicationfactory.h>
00023 #include <opie2/oresource.h>
00024
00025 #include <qtoolbar.h>
00026 #include <qmenubar.h>
00027 #include <qapplication.h>
00028 #include <qaction.h>
00029 #include <qmessagebox.h>
00030
00031 #include <kapplication.h>
00032
00033 #include "ZSameWidget.h"
00034
00035 static int default_colors=3;
00036
00037 #define i18n tr
00038
00039
00040 using namespace Opie::Core;
00041 OPIE_EXPORT_APP( OApplicationFactory<ZSameWidget> )
00042
00043
00044
00045 ZSameWidget::ZSameWidget( QWidget* parent, const char* name, WFlags fl )
00046 : QMainWindow( parent, name, fl )
00047 {
00048 setCaption(tr("ZSame"));
00049
00050 setToolBarsMovable( false );
00051 QToolBar* con = new QToolBar( this );
00052 con->setHorizontalStretchable( true );
00053 QMenuBar* mb = new QMenuBar( con );
00054 QToolBar* tb = new QToolBar( this );
00055
00056 QPopupMenu* fileMenu = new QPopupMenu( this );
00057
00058 QAction* a = new QAction(tr("New Game"), Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ),
00059 QString::null, 0, this, "new_icon");
00060 a->addTo( fileMenu );
00061 a->addTo( tb );
00062 connect(a, SIGNAL(activated()), this, SLOT(m_new()));
00063
00064 a = new QAction(tr("Restart This Board"), Opie::Core::OResource::loadPixmap( "redo", Opie::Core::OResource::SmallIcon ),
00065 QString::null, 0, this, "restart_board" );
00066 a->addTo( fileMenu );
00067 connect( a, SIGNAL(activated()), this, SLOT(m_restart()));
00068 restart = a;
00069
00070 a = new QAction( tr("Undo"), Opie::Core::OResource::loadPixmap( "undo", Opie::Core::OResource::SmallIcon ),
00071 QString::null, 0, this, "undo_action" );
00072 a->addTo( fileMenu );
00073 a->addTo( tb );
00074 connect( a, SIGNAL(activated()), this, SLOT(m_undo()));
00075
00076 a = new QAction(tr("Quit"), Opie::Core::OResource::loadPixmap( "quit_icon", Opie::Core::OResource::SmallIcon ),
00077 QString::null, 0, this, "quit_action");
00078 a->addTo( fileMenu );
00079 a->addTo( tb );
00080 connect(a, SIGNAL(activated()), this, SLOT(m_quit()));
00081
00082 mb->insertItem(tr("Game" ), fileMenu );
00083
00084 int foo[2];
00085 desktop_widget(foo);
00086 stone = new StoneWidget(this,foo[0],foo[1]);
00087
00088 connect( stone, SIGNAL(s_gameover()), this, SLOT(gameover()));
00089
00090 connect( stone, SIGNAL(s_colors(int)), this, SLOT(setColors(int)));
00091 connect( stone, SIGNAL(s_board(int)), this, SLOT(setBoard(int)));
00092 connect( stone, SIGNAL(s_marked(int)), this, SLOT(setMarked(int)));
00093 connect( stone, SIGNAL(s_score(int)), this, SLOT(setScore(int)));
00094 connect( stone, SIGNAL(s_remove(int,int)), this, SLOT(stonesRemoved(int,int)));
00095
00096 connect(stone, SIGNAL(s_sizechanged()), this, SLOT(sizeChanged()));
00097
00098 sizeChanged();
00099 setCentralWidget(stone);
00100
00101
00102 setScore(0);
00103 }
00104
00105 ZSameWidget::~ZSameWidget() {
00106
00107 }
00108
00109 void ZSameWidget::readProperties(Config *) {
00110
00111
00112
00113
00114 }
00115
00116 void ZSameWidget::saveProperties(Config *) {
00117
00118
00119
00120
00121
00122 }
00123
00124 void ZSameWidget::sizeChanged() {
00125
00126 }
00127
00128 void ZSameWidget::newGame(unsigned int board,int colors) {
00129 while (board>=1000000) board-=1000000;
00130
00131 stone->newGame(board,colors);
00132 setScore(0);
00133 }
00134
00135 bool ZSameWidget::confirmAbort() {
00136 return stone->isGameover() ||
00137 stone->isOriginalBoard() ||
00138 (QMessageBox::warning(this, i18n("Resign"), i18n("<qt>Do you want to resign?</qt>"),
00139 QMessageBox::Yes,
00140 QMessageBox::No|QMessageBox::Default|QMessageBox::Escape, 0) == QMessageBox::Yes );
00141 }
00142
00143 void ZSameWidget::m_new() {
00144 if (confirmAbort())
00145 newGame(_random(),default_colors);
00146
00147 }
00148
00149 void ZSameWidget::m_restart() {
00150 if (confirmAbort())
00151 newGame(stone->board(),default_colors);
00152 }
00153
00154 void ZSameWidget::m_load() {
00155
00156 }
00157
00158 void ZSameWidget::m_save() {
00159
00160 }
00161
00162 void ZSameWidget::m_undo() {
00163
00164 stone->undo();
00165 }
00166
00167
00168 void ZSameWidget::m_showhs() {
00169
00170
00171
00172
00173
00174
00175 }
00176
00177 void ZSameWidget::m_quit() {
00178
00179 stone->unmark();
00180 qApp->quit();
00181
00182 }
00183
00184 void ZSameWidget::m_tglboard() {
00185
00186 }
00187
00188
00189 void ZSameWidget::setColors(int ) {
00190
00191 }
00192
00193 void ZSameWidget::setBoard(int ) {
00194
00195 }
00196
00197 void ZSameWidget::setMarked(int ) {
00198
00199 }
00200
00201 void ZSameWidget::stonesRemoved(int,int) {
00202
00203
00204 }
00205
00206 void ZSameWidget::setScore(int ) {
00207
00208
00209
00210 }
00211
00212 void ZSameWidget::gameover() {
00213
00214 if (stone->hasBonus()) {
00215 QMessageBox::information(this,i18n("Game won"),
00216 i18n("<qt>You even removed the last stone, great job! "
00217 "This gave you a score of %1 in total.</qt>").arg(stone->score()));
00218 stone->clearBonus();
00219 } else {
00220 QMessageBox::information(this,i18n("Game over"),
00221 i18n("<qt>There are no more removeable stones. "
00222 "You got a score of %1 in total.</qt>").arg(stone->score()));
00223 }
00224 stone->unmark();
00225 }
00226
00227 void ZSameWidget::desktop_widget(int *f)const{
00228
00229 QWidget* wid = QApplication::desktop();
00230
00231 if ( wid->width() > wid->height() ) {
00232 f[0]=15;
00233 f[1]=9;
00234 }
00235
00236 else{
00237 f[0]=12;
00238 f[1]=13;
00239 }
00240 }
00241
00242