summaryrefslogtreecommitdiff
authorimm <imm>2002-08-30 17:50:52 (UTC)
committer imm <imm>2002-08-30 17:50:52 (UTC)
commitf6125710c0ca99fc62ffce69973a168b6604f29d (patch) (unidiff)
tree5bb82f49b81db7cb990ea2f72d9ff20222f4db15
parent91e02e91751e9e477ac8a7b4666d58d739dd9283 (diff)
downloadopie-f6125710c0ca99fc62ffce69973a168b6604f29d.zip
opie-f6125710c0ca99fc62ffce69973a168b6604f29d.tar.gz
opie-f6125710c0ca99fc62ffce69973a168b6604f29d.tar.bz2
license update
removed quit from menubar
Diffstat (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,185 +1,184 @@
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 )
138 { 137 {
139 int rowTotal = 0; 138 int rowTotal = 0;
140 int columnTotal = 0; 139 int columnTotal = 0;
141 140
142 map[column][row] = 1; 141 map[column][row] = 1;
143 142
144 for( int c = 0 ; c < gridVal ; c++ ) 143 for( int c = 0 ; c < gridVal ; c++ )
145 { 144 {
146 for( int r = 0 ; r < gridVal ; r++ ) 145 for( int r = 0 ; r < gridVal ; r++ )
147 { 146 {
148 if ( map[c][r] == 1 ) 147 if ( map[c][r] == 1 )
149 rowTotal++; 148 rowTotal++;
150 149
151 if ( rowTotal == 4 ) 150 if ( rowTotal == 4 )
152 { 151 {
153 bingo(); 152 bingo();
154 } 153 }
155 } 154 }
156 rowTotal = 0; 155 rowTotal = 0;
157 } 156 }
158 157
159 for( int r = 0 ; r < gridVal ; r++ ) 158 for( int r = 0 ; r < gridVal ; r++ )
160 { 159 {
161 for( int c = 0 ; c < gridVal ; c++ ) 160 for( int c = 0 ; c < gridVal ; c++ )
162 { 161 {
163 if ( map[c][r] == 1 ) 162 if ( map[c][r] == 1 )
164 columnTotal++; 163 columnTotal++;
165 164
166 if ( columnTotal == 4 ) 165 if ( columnTotal == 4 )
167 { 166 {
168 bingo(); 167 bingo();
169 } 168 }
170 } 169 }
171 columnTotal = 0; 170 columnTotal = 0;
172 } 171 }
173 172
174 if ( map[0][0] && map[1][1] && map[2][2] && map[3][3] ) 173 if ( map[0][0] && map[1][1] && map[2][2] && map[3][3] )
175 bingo(); 174 bingo();
176 175
177 if ( map[0][3] && map[1][2] && map[2][1] && map[3][0] ) 176 if ( map[0][3] && map[1][2] && map[2][1] && map[3][0] )
178 bingo(); 177 bingo();
179 } 178 }
180} 179}
181 180
182void BuzzWord::bingo() 181void BuzzWord::bingo()
183{ 182{
184 gameOver = true; 183 gameOver = true;
185 QMessageBox::information( this, "BUZZWORD", tr("<h1><b>BINGO !</b></h1>")); 184 QMessageBox::information( this, "BUZZWORD", tr("<h1><b>BINGO !</b></h1>"));
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,89 +1,89 @@
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;
54 54
55public slots: 55public slots:
56 void flip(); 56 void flip();
57 57
58signals: 58signals:
59 void clicked(int row,int column); 59 void clicked(int row,int column);
60}; 60};
61 61
62class BuzzWord : public QMainWindow 62class BuzzWord : public QMainWindow
63{ 63{
64 Q_OBJECT 64 Q_OBJECT
65 65
66public: 66public:
67 BuzzWord(); 67 BuzzWord();
68 68
69private: 69private:
70 void drawGrid(); 70 void drawGrid();
71 void bingo(); 71 void bingo();
72 QString getWord(); 72 QString getWord();
73 73
74 QMenuBar *menu; 74 QMenuBar *menu;
75 QPopupMenu *game; 75 QPopupMenu *game;
76 QGrid *grid; 76 QGrid *grid;
77 77
78 int gridVal; 78 int gridVal;
79 int map[4][4]; 79 int map[4][4];
80 bool gameOver; 80 bool gameOver;
81 81
82public slots: 82public slots:
83 void about(); 83 void about();
84 void newGame(); 84 void newGame();
85 void clicked(int row, int column); 85 void clicked(int row, int column);
86 86
87}; 87};
88 88
89#endif 89#endif
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}