summaryrefslogtreecommitdiff
path: root/noncore
Unidiff
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/buzzword/buzzword.cpp3
-rw-r--r--noncore/games/buzzword/buzzword.h2
-rw-r--r--noncore/games/buzzword/main.cpp2
3 files changed, 3 insertions, 4 deletions
diff --git a/noncore/games/buzzword/buzzword.cpp b/noncore/games/buzzword/buzzword.cpp
index 37032df..447396b 100644
--- a/noncore/games/buzzword/buzzword.cpp
+++ b/noncore/games/buzzword/buzzword.cpp
@@ -1,137 +1,136 @@
1/* 1/*
2 * Copyright (C) 2002 Martin Imobersteg <imm@gmx.ch> 2 * Copyright (C) 2002 Martin Imobersteg <imm@gmx.ch>
3 * 3 *
4 * This program is free software; you can redistribute it and/or 4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License,Life or (at your option) any later version. 7 * version 2 of the License,Life or (at your option) any later version.
8 * 8 *
9 * This program is distributed in the hope that it will be useful, 9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details. 12 * Library General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Library General Public 14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the Free 15 * License along with this program; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */ 17 */
18 18
19#include <qlayout.h> 19#include <qlayout.h>
20#include <qmessagebox.h> 20#include <qmessagebox.h>
21#include <qmainwindow.h> 21#include <qmainwindow.h>
22#include <qlabel.h> 22#include <qlabel.h>
23#include <qgrid.h> 23#include <qgrid.h>
24#include <qcolor.h> 24#include <qcolor.h>
25#include <qbutton.h> 25#include <qbutton.h>
26#include <qfile.h> 26#include <qfile.h>
27#include <qtextstream.h> 27#include <qtextstream.h>
28#include <qstringlist.h> 28#include <qstringlist.h>
29#include <qmessagebox.h> 29#include <qmessagebox.h>
30#include <qdir.h> 30#include <qdir.h>
31 31
32#include <math.h> 32#include <math.h>
33#include <stdlib.h> 33#include <stdlib.h>
34 34
35#include <list> 35#include <list>
36#include <string> 36#include <string>
37 37
38#include <qpe/qpeapplication.h> 38#include <qpe/qpeapplication.h>
39 39
40#include "buzzword.h" 40#include "buzzword.h"
41 41
42// sponsered by rikkus :) 42// sponsered by rikkus :)
43bool random_compare(const QString &, const QString &) 43bool random_compare(const QString &, const QString &)
44{ 44{
45 return (rand() % 2) > 0.5; 45 return (rand() % 2) > 0.5;
46} 46}
47 47
48BuzzLabel::BuzzLabel( QWidget *parent, const char *name ) 48BuzzLabel::BuzzLabel( QWidget *parent, const char *name )
49: QLabel( parent, name ) 49: QLabel( parent, name )
50{ 50{
51} 51}
52 52
53void BuzzLabel::mousePressEvent(QMouseEvent *e) 53void BuzzLabel::mousePressEvent(QMouseEvent *e)
54{ 54{
55 if(e->button() == LeftButton) 55 if(e->button() == LeftButton)
56 { 56 {
57 emit clicked(); 57 emit clicked();
58 } 58 }
59} 59}
60 60
61BuzzItem::BuzzItem( int row, int column, QString text, QWidget *parent, const char *name ) 61BuzzItem::BuzzItem( int row, int column, QString text, QWidget *parent, const char *name )
62: QVBox( parent, name ), _row(row), _column(column) 62: QVBox( parent, name ), _row(row), _column(column)
63{ 63{
64 setFrameStyle( QFrame::Panel | QFrame::Raised ); 64 setFrameStyle( QFrame::Panel | QFrame::Raised );
65 setLineWidth( 1 ); 65 setLineWidth( 1 );
66 label = new BuzzLabel(this, "label"); 66 label = new BuzzLabel(this, "label");
67 label->setText(text); 67 label->setText(text);
68 label->setAlignment( int( QLabel::AlignCenter ) ); 68 label->setAlignment( int( QLabel::AlignCenter ) );
69 69
70 connect( label, SIGNAL(clicked()), this, SLOT(flip()) ); 70 connect( label, SIGNAL(clicked()), this, SLOT(flip()) );
71} 71}
72 72
73void BuzzItem::flip() 73void BuzzItem::flip()
74{ 74{
75 setLineWidth( 1 ); 75 setLineWidth( 1 );
76 label->setBackgroundColor(label->colorGroup().highlight()); 76 label->setBackgroundColor(label->colorGroup().highlight());
77 emit clicked(_row, _column); 77 emit clicked(_row, _column);
78} 78}
79 79
80BuzzWord::BuzzWord() : QMainWindow(0) 80BuzzWord::BuzzWord() : QMainWindow(0)
81{ 81{
82 setCaption(tr("buZzword")); 82 setCaption(tr("buZzword"));
83 83
84 menu = menuBar(); 84 menu = menuBar();
85 game = new QPopupMenu; 85 game = new QPopupMenu;
86 game->insertItem(tr("&New game"), this, SLOT(newGame()), Key_N ); 86 game->insertItem(tr("&New game"), this, SLOT(newGame()), Key_N );
87 game->insertSeparator(); 87 game->insertSeparator();
88 game->insertItem(tr("&About"), this, SLOT(about())); 88 game->insertItem(tr("&About"), this, SLOT(about()));
89 game->insertItem(tr("&Quit"), qApp, SLOT(quit()), Key_Q );
90 menu->insertItem( tr("&Game"), game ); 89 menu->insertItem( tr("&Game"), game );
91 90
92 gridVal = 4; 91 gridVal = 4;
93 grid = NULL; 92 grid = NULL;
94 gameOver = false; 93 gameOver = false;
95 newGame(); 94 newGame();
96} 95}
97 96
98void BuzzWord::drawGrid() 97void BuzzWord::drawGrid()
99{ 98{
100 std::list<QString> l; 99 std::list<QString> l;
101 100
102 QString path = QPEApplication::qpeDir()+"share/buzzword/"; 101 QString path = QPEApplication::qpeDir()+"share/buzzword/";
103 QFile f( path + "buzzwords" ); 102 QFile f( path + "buzzwords" );
104 if ( !f.open( IO_ReadOnly ) ) 103 if ( !f.open( IO_ReadOnly ) )
105 return; 104 return;
106 105
107 QTextStream t( &f ); 106 QTextStream t( &f );
108 107
109 while (!t.atEnd()) 108 while (!t.atEnd())
110 { 109 {
111 l.push_back(t.readLine()); 110 l.push_back(t.readLine());
112 } 111 }
113 112
114 f.close(); 113 f.close();
115 114
116 l.sort(random_compare); 115 l.sort(random_compare);
117 116
118 grid = new QGrid(gridVal, this); 117 grid = new QGrid(gridVal, this);
119 grid->setFixedSize(240,240); 118 grid->setFixedSize(240,240);
120 119
121 for( int c = 0 ; c < gridVal ; c++ ) 120 for( int c = 0 ; c < gridVal ; c++ )
122 { 121 {
123 for( int r = 0 ; r < gridVal ; r++ ) 122 for( int r = 0 ; r < gridVal ; r++ )
124 { 123 {
125 QString word = QStringList::split(" ", l.front()).join("\n"); 124 QString word = QStringList::split(" ", l.front()).join("\n");
126 BuzzItem* bi = new BuzzItem( c, r, word, grid ); 125 BuzzItem* bi = new BuzzItem( c, r, word, grid );
127 connect( bi, SIGNAL(clicked(int, int)), this, SLOT(clicked(int,int)) ); 126 connect( bi, SIGNAL(clicked(int, int)), this, SLOT(clicked(int,int)) );
128 map[c][r] = 0; 127 map[c][r] = 0;
129 128
130 l.pop_front(); 129 l.pop_front();
131 } 130 }
132 } 131 }
133} 132}
134 133
135void BuzzWord::clicked(int row, int column) 134void BuzzWord::clicked(int row, int column)
136{ 135{
137 if ( ! gameOver ) 136 if ( ! gameOver )
diff --git a/noncore/games/buzzword/buzzword.h b/noncore/games/buzzword/buzzword.h
index f72be9a..2e00563 100644
--- a/noncore/games/buzzword/buzzword.h
+++ b/noncore/games/buzzword/buzzword.h
@@ -1,53 +1,53 @@
1/* 1/*
2 * Copyright (C) 2002 Martin Imobersteg <imm@gmx.ch> 2 * Copyright (C) 2002 Martin Imobersteg <imm@gmx.ch>
3 * 3 *
4 * This program is free software; you can redistribute it and/or 4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License,Life or (at your option) any later version. 7 * version 2 of the License,Life or (at your option) any later version.
8 * 8 *
9 * This program is distributed in the hope that it will be useful, 9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details. 12 * Library General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Library General Public 14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the Free 15 * License along with this program; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */ 17 */
18 18
19#ifndef BUZZWORD_H 19#ifndef BUZZWORD_H
20#define BUZZWORD_H 20#define BUZZWORD_H
21 21
22#include <qmainwindow.h> 22#include <qmainwindow.h>
23#include <qmenubar.h> 23#include <qmenubar.h>
24#include <qlabel.h> 24#include <qlabel.h>
25#include <qvbox.h> 25#include <qvbox.h>
26 26
27class QGrid; 27class QGrid;
28 28
29class BuzzLabel : public QLabel 29class BuzzLabel : public QLabel
30{ 30{
31 Q_OBJECT 31 Q_OBJECT
32 32
33public: 33public:
34 BuzzLabel( QWidget *parent=0, const char *name=0 ); 34 BuzzLabel( QWidget *parent=0, const char *name=0 );
35 35
36protected: 36protected:
37 virtual void mousePressEvent(QMouseEvent *e); 37 virtual void mousePressEvent(QMouseEvent *e);
38 38
39signals: 39signals:
40 void clicked(); 40 void clicked();
41}; 41};
42 42
43class BuzzItem : public QVBox 43class BuzzItem : public QVBox
44{ 44{
45 Q_OBJECT 45 Q_OBJECT
46 46
47public: 47public:
48 BuzzItem( int row, int column, QString text, QWidget *parent=0, const char *name=0 ); 48 BuzzItem( int row, int column, QString text, QWidget *parent=0, const char *name=0 );
49 49
50private: 50private:
51 QLabel* label; 51 QLabel* label;
52 int _row; 52 int _row;
53 int _column; 53 int _column;
diff --git a/noncore/games/buzzword/main.cpp b/noncore/games/buzzword/main.cpp
index 1fa011b..2d9ff81 100644
--- a/noncore/games/buzzword/main.cpp
+++ b/noncore/games/buzzword/main.cpp
@@ -1,35 +1,35 @@
1/* 1/*
2 * Copyright (C) 2002 Martin Imobersteg <imm@gmx.ch> 2 * Copyright (C) 2002 Martin Imobersteg <imm@gmx.ch>
3 * 3 *
4 * This program is free software; you can redistribute it and/or 4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License,Life or (at your option) any later version. 7 * version 2 of the License,Life or (at your option) any later version.
8 * 8 *
9 * This program is distributed in the hope that it will be useful, 9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details. 12 * Library General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Library General Public 14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the Free 15 * License along with this program; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */ 17 */
18 18
19#include <qpe/qpeapplication.h> 19#include <qpe/qpeapplication.h>
20 20
21#include <stdlib.h> 21#include <stdlib.h>
22#include <time.h> 22#include <time.h>
23 23
24#include "buzzword.h" 24#include "buzzword.h"
25 25
26int main(int argc, char **argv) 26int main(int argc, char **argv)
27{ 27{
28 srand(time(0)); 28 srand(time(0));
29 29
30 QPEApplication a( argc, argv ); 30 QPEApplication a( argc, argv );
31 BuzzWord *top = new BuzzWord; 31 BuzzWord *top = new BuzzWord;
32 a.showMainWidget(top); 32 a.showMainWidget(top);
33 33
34 return a.exec(); 34 return a.exec();
35} 35}