summaryrefslogtreecommitdiff
path: root/noncore/games/zsame/ZSameWidget.cpp
Unidiff
Diffstat (limited to 'noncore/games/zsame/ZSameWidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/zsame/ZSameWidget.cpp250
1 files changed, 250 insertions, 0 deletions
diff --git a/noncore/games/zsame/ZSameWidget.cpp b/noncore/games/zsame/ZSameWidget.cpp
new file mode 100644
index 0000000..5001b55
--- a/dev/null
+++ b/noncore/games/zsame/ZSameWidget.cpp
@@ -0,0 +1,250 @@
1/* Yo Emacs, this is -*- C++ -*- */
2/*
3 * ksame 0.4 - simple Game
4 * Copyright (C) 1997,1998 Marcus Kreutzberger
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 *
20 */
21
22#include <stdio.h>
23
24#include <qwidget.h>
25#include <qpushbutton.h>
26#include <qpixmap.h>
27#include <qvbox.h>
28#include <qpopupmenu.h>
29#include <qtoolbar.h>
30#include <qmenubar.h>
31
32#include <qapplication.h>
33#include <qaction.h>
34#include <qmessagebox.h>
35
36#include <qpe/resource.h>
37#include <opie/oapplicationfactory.h>
38#include <kapplication.h>
39
40
41#include "ZSameWidget.h"
42#include "StoneWidget.h"
43#include "version.h"
44
45static int default_colors=3;
46
47#define i18n tr
48
49
50OPIE_EXPORT_APP( OApplicationFactory<ZSameWidget> )
51
52
53
54ZSameWidget::ZSameWidget( QWidget* parent, const char* name, WFlags fl )
55 : QMainWindow( parent, name, fl )
56{
57 setCaption(tr("ZSame"));
58
59 setToolBarsMovable( false );
60 QToolBar* con = new QToolBar( this );
61 con->setHorizontalStretchable( true );
62 QMenuBar* mb = new QMenuBar( con );
63 QToolBar* tb = new QToolBar( this );
64
65 QPopupMenu* fileMenu = new QPopupMenu( this );
66
67 QAction* a = new QAction(tr("New Game"), Resource::loadIconSet("new") ,
68 QString::null, 0, this, "new_icon");
69 a->addTo( fileMenu );
70 a->addTo( tb );
71 connect(a, SIGNAL(activated()), this, SLOT(m_new()));
72
73 a = new QAction(tr("Restart This Board"), Resource::loadIconSet("redo"),
74 QString::null, 0, this, "restart_board" );
75 a->addTo( fileMenu );
76 connect( a, SIGNAL(activated()), this, SLOT(m_restart()));
77 restart = a;
78
79 a = new QAction( tr("Undo"), Resource::loadIconSet("undo"),
80 QString::null, 0, this, "undo_action" );
81 a->addTo( fileMenu );
82 a->addTo( tb );
83 connect( a, SIGNAL(activated()), this, SLOT(m_undo()));
84
85 a = new QAction(tr("Quit"), Resource::loadIconSet("quit_icon"),
86 QString::null, 0, this, "quit_action");
87 a->addTo( fileMenu );
88 a->addTo( tb );
89 connect(a, SIGNAL(activated()), this, SLOT(m_quit()));
90
91 mb->insertItem(tr("Game" ), fileMenu );
92
93 int foo[2];
94 desktop_widget(foo);
95 stone = new StoneWidget(this,foo[0],foo[1]);
96
97 connect( stone, SIGNAL(s_gameover()), this, SLOT(gameover()));
98
99 connect( stone, SIGNAL(s_colors(int)), this, SLOT(setColors(int)));
100 connect( stone, SIGNAL(s_board(int)), this, SLOT(setBoard(int)));
101 connect( stone, SIGNAL(s_marked(int)), this, SLOT(setMarked(int)));
102 connect( stone, SIGNAL(s_score(int)), this, SLOT(setScore(int)));
103 connect( stone, SIGNAL(s_remove(int,int)), this, SLOT(stonesRemoved(int,int)));
104
105 connect(stone, SIGNAL(s_sizechanged()), this, SLOT(sizeChanged()));
106
107 sizeChanged();
108 setCentralWidget(stone);
109
110
111 setScore(0);
112}
113
114ZSameWidget::~ZSameWidget() {
115
116}
117
118void ZSameWidget::readProperties(Config *conf) {
119/*
120 Q_ASSERT(conf);
121 stone->readProperties(conf);
122*/
123}
124
125void ZSameWidget::saveProperties(Config *conf) {
126/*
127 Q_ASSERT(conf);
128 stone->saveProperties(conf);
129 conf->sync();
130*/
131}
132
133void ZSameWidget::sizeChanged() {
134 //stone->setFixedSize(stone->sizeHint());
135}
136
137void ZSameWidget::newGame(unsigned int board,int colors) {
138 while (board>=1000000) board-=1000000;
139 // kdDebug() << "newgame board " << board << " colors " << colors << endl;
140 stone->newGame(board,colors);
141 setScore(0);
142}
143
144bool ZSameWidget::confirmAbort() {
145 return stone->isGameover() ||
146 stone->isOriginalBoard() ||
147 (QMessageBox::warning(this, i18n("Resign"), i18n("<qt>Do you want to resign?</qt>"),
148 QMessageBox::Yes,
149 QMessageBox::No|QMessageBox::Default|QMessageBox::Escape, 0) == QMessageBox::Yes );
150}
151
152void ZSameWidget::m_new() {
153 if (confirmAbort())
154 newGame(_random(),default_colors);
155
156}
157
158void ZSameWidget::m_restart() {
159 if (confirmAbort())
160 newGame(stone->board(),default_colors);
161}
162
163void ZSameWidget::m_load() {
164// kdDebug() << "menu load not supported" << endl;
165}
166
167void ZSameWidget::m_save() {
168// kdDebug() << "menu save not supported" << endl;
169}
170
171void ZSameWidget::m_undo() {
172 //Q_ASSERT(stone);
173 stone->undo();
174}
175
176
177void ZSameWidget::m_showhs() {
178/* Q_ASSERT(stone);
179 stone->unmark();
180 KScoreDialog d(KScoreDialog::Name | KScoreDialog::Score, this);
181 d.addField(Board, i18n("Board"), "Board");
182 d.exec();
183*/
184}
185
186void ZSameWidget::m_quit() {
187// Q_ASSERT(stone);
188 stone->unmark();
189 qApp->quit();
190// delete this;
191}
192
193void ZSameWidget::m_tglboard() {
194 //kdDebug() << "toggled" << endl;
195}
196
197
198void ZSameWidget::setColors(int colors) {
199 //status->changeItem(i18n("%1 Colors").arg(colors),1);
200}
201
202void ZSameWidget::setBoard(int board) {
203 //status->changeItem(i18n("Board: %1").arg(board, 6), 2);
204}
205
206void ZSameWidget::setMarked(int m) {
207// status->changeItem(i18n("Marked: %1").arg(m, 6),3);
208}
209
210void ZSameWidget::stonesRemoved(int,int) {
211 //KNotifyClient::event("stones removed",
212 // i18n("%1 stones removed.").arg(stone->marked()));
213}
214
215void ZSameWidget::setScore(int score) {
216// status->changeItem(i18n("Score: %1").arg(score, 6),4);
217// undo->setEnabled(stone->undoPossible());
218// restart->setEnabled(!stone->isOriginalBoard());
219}
220
221void ZSameWidget::gameover() {
222// kdDebug() << "GameOver" << endl;
223 if (stone->hasBonus()) {
224 QMessageBox::information(this,i18n("Game won"),
225 i18n("<qt>You even removed the last stone, great job! "
226 "This gave you a score of %1 in total.</qt>").arg(stone->score()));
227 } else {
228 QMessageBox::information(this,i18n("Game over"),
229 i18n("<qt>There are no more removeable stones. "
230 "You got a score of %1 in total.</qt>").arg(stone->score()));
231 }
232 stone->unmark();
233}
234
235void ZSameWidget::desktop_widget(int *f)const{
236
237 QWidget* wid = QApplication::desktop();
238 /* width > height landscape mode */
239 if ( wid->width() > wid->height() ) {
240 f[0]=15;
241 f[1]=9;
242 }
243 /* normal */
244 else{
245 f[0]=12;
246 f[1]=13;
247 }
248}
249
250