summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/zsame/StoneWidget.cpp12
-rw-r--r--noncore/games/zsame/ZSameWidget.cpp13
2 files changed, 8 insertions, 17 deletions
diff --git a/noncore/games/zsame/StoneWidget.cpp b/noncore/games/zsame/StoneWidget.cpp
index 5dd0252..f370714 100644
--- a/noncore/games/zsame/StoneWidget.cpp
+++ b/noncore/games/zsame/StoneWidget.cpp
@@ -1,238 +1,232 @@
/*
* ksame 0.4 - simple Game
* Copyright (C) 1997,1998 Marcus Kreutzberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
-#include <stdio.h>
-#include <stdlib.h>
+#include <opie2/oresource.h>
-
-
-#include <qpe/resource.h>
+#include <qbitmap.h>
#include <time.h>
#include <assert.h>
#include "StoneWidget.h"
struct StoneSlice {
QPixmap stone;
};
StoneWidget::StoneWidget( QWidget *parent, int x, int y )
: QWidget(parent,"StoneWidget"), stonefield(x,y)
{
-// setBackgroundPixmap(QPixmap(locate("wallpaper", "Time-For-Lunch-2.jpg")));
-// QPixmap stonemap(locate("appdata", "stones.png"));
-
- QPixmap stonemap = Resource::loadPixmap("zsame/stones" );
+ QPixmap stonemap = Opie::Core::OResource::loadPixmap( "zsame/stones" );
assert(!stonemap.isNull());
slice=0;
maxslices=30;
maxcolors=4;
sizex=x;
sizey=y;
stone_width=stonemap.width()/(maxslices+1);
stone_height=stonemap.height()/maxcolors;
map = new StoneSlice*[maxcolors];
QBitmap mask;
for (int c = 0; c < maxcolors; c++) {
map[c] = new StoneSlice[maxslices];
for (int s = 0; s < maxslices; s++) {
map[c][s].stone.resize(stone_width, stone_height);
assert(!map[c][s].stone.isNull());
bitBlt(&map[c][s].stone, 0, 0,
&stonemap, stone_width * s,
c*stone_height,
stone_width,stone_height,CopyROP,false);
QImage im = map[c][s].stone.convertToImage();
mask = im.createHeuristicMask();
map[c][s].stone.setMask(mask);
}
}
field_height=stone_height*sizey;
field_width=stone_width*sizex;
setMouseTracking(true);
// QColor c(115,115,115);
// setBackgroundColor(c);
// emit s_sizechanged();
startTimer( 100 );
history.setAutoDelete(true);
}
StoneWidget::~StoneWidget() {
for (int c = 0; c < maxcolors; c++) {
delete [] map[c];
}
delete [] map;
setMouseTracking(false);
killTimers();
}
unsigned int
StoneWidget::board() {
return stonefield.getBoard();
}
int
StoneWidget::score() {
return stonefield.getScore();
}
int
StoneWidget::marked() {
return stonefield.getMarked();
}
QSize
StoneWidget::size() {
return QSize(sizex,sizey);
}
int
StoneWidget::colors() {
return stonefield.getColors();
}
QSize
StoneWidget::sizeHint () const {
return QSize(field_width,field_height);
}
void
StoneWidget::newGame(unsigned int board,int colors) {
stonefield.newGame(board,colors);
history.clear();
modified= false;
emit s_newgame();
emit s_colors(stonefield.getColors());
emit s_board(stonefield.getBoard());
}
void
StoneWidget::reset() {
stonefield.reset();
history.clear();
emit s_newgame();
}
void
StoneWidget::unmark() {
stonefield.unmark();
emit s_marked(0);
}
bool StoneWidget::undoPossible() const {
if (stonefield.isGameover()) return false;
return stonefield.undoPossible();
}
int
StoneWidget::undo(int count) {
if (stonefield.isGameover()) return 0;
int ret_val=stonefield.undo(count);
QPoint p=mapFromGlobal(cursor().pos());
int x=p.x();
int y=p.y();
if (x<0||y<0||x>=field_width||y>=field_height) {
emit s_score(stonefield.getMarked());
return ret_val;
}
int marked=stonefield.mark(x/stone_width,y/stone_height);
emit s_marked(marked);
slice=0;
emit s_score(stonefield.getScore());
modified= (stonefield.getScore()>0);
return ret_val;
}
bool StoneWidget::isGameover() {
return stonefield.isGameover();
}
bool StoneWidget::hasBonus() {
return stonefield.gotBonus(); // don't ask me why the names differ... ;-| [hlm]
}
void StoneWidget::clearBonus() {
stonefield.clearBonus();
}
bool StoneWidget::isOriginalBoard() {
return !modified;
}
void StoneWidget::readProperties(Config *) {
/* Q_ASSERT(conf);
history.clear();
if (!conf->hasKey("Board")||
!conf->hasKey("Colors")||
!conf->hasKey("Stones")) {
return;
}
newGame(conf->readNumEntry("Board"),conf->readNumEntry("Colors"));
QStrList list;
conf->readListEntry("Stones",list);
for (const char *item=list.first();item;item=list.next()) {
int x=-1,y=-1;
if (sscanf(item,"%02X%02X",&x,&y)!=2) break;
history.append(new QPoint(x,y));
stonefield.remove(x,y);
}
*/
}
void
StoneWidget::saveProperties(Config *) {
/*
Q_ASSERT(conf);
QStrList list(true);
QString tmp;
for (QPoint *item=history.first();item;item=history.next()) {
tmp.sprintf("%02X%02X",item->x(),item->y());
list.append(tmp.ascii());
}
conf->writeEntry("Stones",list);
conf->writeEntry("Board",stonefield.getBoard());
conf->writeEntry("Colors",stonefield.getColors());
*/
}
diff --git a/noncore/games/zsame/ZSameWidget.cpp b/noncore/games/zsame/ZSameWidget.cpp
index dee4a1c..7bcbee1 100644
--- a/noncore/games/zsame/ZSameWidget.cpp
+++ b/noncore/games/zsame/ZSameWidget.cpp
@@ -1,245 +1,242 @@
/* Yo Emacs, this is -*- C++ -*- */
/*
* ksame 0.4 - simple Game
* Copyright (C) 1997,1998 Marcus Kreutzberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
-#include <stdio.h>
-
#include <opie2/oapplicationfactory.h>
-
-#include <qpe/resource.h>
+#include <opie2/oresource.h>
#include <qtoolbar.h>
#include <qmenubar.h>
#include <qapplication.h>
#include <qaction.h>
#include <qmessagebox.h>
#include <kapplication.h>
#include "ZSameWidget.h"
static int default_colors=3;
#define i18n tr
using namespace Opie::Core;
OPIE_EXPORT_APP( OApplicationFactory<ZSameWidget> )
ZSameWidget::ZSameWidget( QWidget* parent, const char* name, WFlags fl )
: QMainWindow( parent, name, fl )
{
setCaption(tr("ZSame"));
setToolBarsMovable( false );
QToolBar* con = new QToolBar( this );
con->setHorizontalStretchable( true );
QMenuBar* mb = new QMenuBar( con );
QToolBar* tb = new QToolBar( this );
QPopupMenu* fileMenu = new QPopupMenu( this );
- QAction* a = new QAction(tr("New Game"), Resource::loadIconSet("new") ,
+ QAction* a = new QAction(tr("New Game"), Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ),
QString::null, 0, this, "new_icon");
a->addTo( fileMenu );
a->addTo( tb );
connect(a, SIGNAL(activated()), this, SLOT(m_new()));
- a = new QAction(tr("Restart This Board"), Resource::loadIconSet("redo"),
+ a = new QAction(tr("Restart This Board"), Opie::Core::OResource::loadPixmap( "redo", Opie::Core::OResource::SmallIcon ),
QString::null, 0, this, "restart_board" );
a->addTo( fileMenu );
connect( a, SIGNAL(activated()), this, SLOT(m_restart()));
restart = a;
- a = new QAction( tr("Undo"), Resource::loadIconSet("undo"),
+ a = new QAction( tr("Undo"), Opie::Core::OResource::loadPixmap( "undo", Opie::Core::OResource::SmallIcon ),
QString::null, 0, this, "undo_action" );
a->addTo( fileMenu );
a->addTo( tb );
connect( a, SIGNAL(activated()), this, SLOT(m_undo()));
- a = new QAction(tr("Quit"), Resource::loadIconSet("quit_icon"),
+ a = new QAction(tr("Quit"), Opie::Core::OResource::loadPixmap( "quit_icon", Opie::Core::OResource::SmallIcon ),
QString::null, 0, this, "quit_action");
a->addTo( fileMenu );
a->addTo( tb );
connect(a, SIGNAL(activated()), this, SLOT(m_quit()));
mb->insertItem(tr("Game" ), fileMenu );
int foo[2];
desktop_widget(foo);
stone = new StoneWidget(this,foo[0],foo[1]);
connect( stone, SIGNAL(s_gameover()), this, SLOT(gameover()));
connect( stone, SIGNAL(s_colors(int)), this, SLOT(setColors(int)));
connect( stone, SIGNAL(s_board(int)), this, SLOT(setBoard(int)));
connect( stone, SIGNAL(s_marked(int)), this, SLOT(setMarked(int)));
connect( stone, SIGNAL(s_score(int)), this, SLOT(setScore(int)));
connect( stone, SIGNAL(s_remove(int,int)), this, SLOT(stonesRemoved(int,int)));
connect(stone, SIGNAL(s_sizechanged()), this, SLOT(sizeChanged()));
sizeChanged();
setCentralWidget(stone);
setScore(0);
}
ZSameWidget::~ZSameWidget() {
}
void ZSameWidget::readProperties(Config *) {
/*
Q_ASSERT(conf);
stone->readProperties(conf);
*/
}
void ZSameWidget::saveProperties(Config *) {
/*
Q_ASSERT(conf);
stone->saveProperties(conf);
conf->sync();
*/
}
void ZSameWidget::sizeChanged() {
// stone->setFixedSize(stone->sizeHint());
}
void ZSameWidget::newGame(unsigned int board,int colors) {
while (board>=1000000) board-=1000000;
// kdDebug() << "newgame board " << board << " colors " << colors << endl;
stone->newGame(board,colors);
setScore(0);
}
bool ZSameWidget::confirmAbort() {
return stone->isGameover() ||
stone->isOriginalBoard() ||
(QMessageBox::warning(this, i18n("Resign"), i18n("<qt>Do you want to resign?</qt>"),
QMessageBox::Yes,
QMessageBox::No|QMessageBox::Default|QMessageBox::Escape, 0) == QMessageBox::Yes );
}
void ZSameWidget::m_new() {
if (confirmAbort())
newGame(_random(),default_colors);
}
void ZSameWidget::m_restart() {
if (confirmAbort())
newGame(stone->board(),default_colors);
}
void ZSameWidget::m_load() {
// kdDebug() << "menu load not supported" << endl;
}
void ZSameWidget::m_save() {
// kdDebug() << "menu save not supported" << endl;
}
void ZSameWidget::m_undo() {
// Q_ASSERT(stone);
stone->undo();
}
void ZSameWidget::m_showhs() {
/* Q_ASSERT(stone);
stone->unmark();
KScoreDialog d(KScoreDialog::Name | KScoreDialog::Score, this);
d.addField(Board, i18n("Board"), "Board");
d.exec();
*/
}
void ZSameWidget::m_quit() {
// Q_ASSERT(stone);
stone->unmark();
qApp->quit();
// delete this;
}
void ZSameWidget::m_tglboard() {
// kdDebug() << "toggled" << endl;
}
void ZSameWidget::setColors(int ) {
// status->changeItem(i18n("%1 Colors").arg(colors),1);
}
void ZSameWidget::setBoard(int ) {
// status->changeItem(i18n("Board: %1").arg(board, 6), 2);
}
void ZSameWidget::setMarked(int ) {
// status->changeItem(i18n("Marked: %1").arg(m, 6),3);
}
void ZSameWidget::stonesRemoved(int,int) {
// KNotifyClient::event("stones removed",
// i18n("%1 stones removed.").arg(stone->marked()));
}
void ZSameWidget::setScore(int ) {
// status->changeItem(i18n("Score: %1").arg(score, 6),4);
// undo->setEnabled(stone->undoPossible());
// restart->setEnabled(!stone->isOriginalBoard());
}
void ZSameWidget::gameover() {
// kdDebug() << "GameOver" << endl;
if (stone->hasBonus()) {
QMessageBox::information(this,i18n("Game won"),
i18n("<qt>You even removed the last stone, great job! "
"This gave you a score of %1 in total.</qt>").arg(stone->score()));
stone->clearBonus();
} else {
QMessageBox::information(this,i18n("Game over"),
i18n("<qt>There are no more removeable stones. "
"You got a score of %1 in total.</qt>").arg(stone->score()));
}
stone->unmark();
}
void ZSameWidget::desktop_widget(int *f)const{
QWidget* wid = QApplication::desktop();
/* width > height landscape mode */
if ( wid->width() > wid->height() ) {
f[0]=15;
f[1]=9;
}
/* normal */
else{
f[0]=12;
f[1]=13;
}
}