summaryrefslogtreecommitdiff
authorimm <imm>2002-08-30 17:33:51 (UTC)
committer imm <imm>2002-08-30 17:33:51 (UTC)
commitd5d60019e96ae6d7c4ac6f11034627a01d8fb36c (patch) (unidiff)
tree26c1ab5d916325d42f0dab72102e08ef4f65ac3f
parent2e1362616524463697dfe2693178a698ccc713ec (diff)
downloadopie-d5d60019e96ae6d7c4ac6f11034627a01d8fb36c.zip
opie-d5d60019e96ae6d7c4ac6f11034627a01d8fb36c.tar.gz
opie-d5d60019e96ae6d7c4ac6f11034627a01d8fb36c.tar.bz2
import
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/buzzword/buzzword.cpp199
-rw-r--r--noncore/games/buzzword/buzzword.h89
-rw-r--r--noncore/games/buzzword/buzzword.pro9
-rw-r--r--noncore/games/buzzword/main.cpp35
-rw-r--r--noncore/games/buzzword/opie-buzzword.control10
5 files changed, 342 insertions, 0 deletions
diff --git a/noncore/games/buzzword/buzzword.cpp b/noncore/games/buzzword/buzzword.cpp
new file mode 100644
index 0000000..37032df
--- a/dev/null
+++ b/noncore/games/buzzword/buzzword.cpp
@@ -0,0 +1,199 @@
1/*
2 * Copyright (C) 2002 Martin Imobersteg <imm@gmx.ch>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License,Life or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
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
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19#include <qlayout.h>
20#include <qmessagebox.h>
21#include <qmainwindow.h>
22#include <qlabel.h>
23#include <qgrid.h>
24#include <qcolor.h>
25#include <qbutton.h>
26#include <qfile.h>
27#include <qtextstream.h>
28#include <qstringlist.h>
29#include <qmessagebox.h>
30#include <qdir.h>
31
32#include <math.h>
33#include <stdlib.h>
34
35#include <list>
36#include <string>
37
38#include <qpe/qpeapplication.h>
39
40#include "buzzword.h"
41
42// sponsered by rikkus :)
43bool random_compare(const QString &, const QString &)
44{
45 return (rand() % 2) > 0.5;
46}
47
48BuzzLabel::BuzzLabel( QWidget *parent, const char *name )
49: QLabel( parent, name )
50{
51}
52
53void BuzzLabel::mousePressEvent(QMouseEvent *e)
54{
55 if(e->button() == LeftButton)
56 {
57 emit clicked();
58 }
59}
60
61BuzzItem::BuzzItem( int row, int column, QString text, QWidget *parent, const char *name )
62: QVBox( parent, name ), _row(row), _column(column)
63{
64 setFrameStyle( QFrame::Panel | QFrame::Raised );
65 setLineWidth( 1 );
66 label = new BuzzLabel(this, "label");
67 label->setText(text);
68 label->setAlignment( int( QLabel::AlignCenter ) );
69
70 connect( label, SIGNAL(clicked()), this, SLOT(flip()) );
71}
72
73void BuzzItem::flip()
74{
75 setLineWidth( 1 );
76 label->setBackgroundColor(label->colorGroup().highlight());
77 emit clicked(_row, _column);
78}
79
80BuzzWord::BuzzWord() : QMainWindow(0)
81{
82 setCaption(tr("buZzword"));
83
84 menu = menuBar();
85 game = new QPopupMenu;
86 game->insertItem(tr("&New game"), this, SLOT(newGame()), Key_N );
87 game->insertSeparator();
88 game->insertItem(tr("&About"), this, SLOT(about()));
89 game->insertItem(tr("&Quit"), qApp, SLOT(quit()), Key_Q );
90 menu->insertItem( tr("&Game"), game );
91
92 gridVal = 4;
93 grid = NULL;
94 gameOver = false;
95 newGame();
96}
97
98void BuzzWord::drawGrid()
99{
100 std::list<QString> l;
101
102 QString path = QPEApplication::qpeDir()+"share/buzzword/";
103 QFile f( path + "buzzwords" );
104 if ( !f.open( IO_ReadOnly ) )
105 return;
106
107 QTextStream t( &f );
108
109 while (!t.atEnd())
110 {
111 l.push_back(t.readLine());
112 }
113
114 f.close();
115
116 l.sort(random_compare);
117
118 grid = new QGrid(gridVal, this);
119 grid->setFixedSize(240,240);
120
121 for( int c = 0 ; c < gridVal ; c++ )
122 {
123 for( int r = 0 ; r < gridVal ; r++ )
124 {
125 QString word = QStringList::split(" ", l.front()).join("\n");
126 BuzzItem* bi = new BuzzItem( c, r, word, grid );
127 connect( bi, SIGNAL(clicked(int, int)), this, SLOT(clicked(int,int)) );
128 map[c][r] = 0;
129
130 l.pop_front();
131 }
132 }
133}
134
135void BuzzWord::clicked(int row, int column)
136{
137 if ( ! gameOver )
138 {
139 int rowTotal = 0;
140 int columnTotal = 0;
141
142 map[column][row] = 1;
143
144 for( int c = 0 ; c < gridVal ; c++ )
145 {
146 for( int r = 0 ; r < gridVal ; r++ )
147 {
148 if ( map[c][r] == 1 )
149 rowTotal++;
150
151 if ( rowTotal == 4 )
152 {
153 bingo();
154 }
155 }
156 rowTotal = 0;
157 }
158
159 for( int r = 0 ; r < gridVal ; r++ )
160 {
161 for( int c = 0 ; c < gridVal ; c++ )
162 {
163 if ( map[c][r] == 1 )
164 columnTotal++;
165
166 if ( columnTotal == 4 )
167 {
168 bingo();
169 }
170 }
171 columnTotal = 0;
172 }
173
174 if ( map[0][0] && map[1][1] && map[2][2] && map[3][3] )
175 bingo();
176
177 if ( map[0][3] && map[1][2] && map[2][1] && map[3][0] )
178 bingo();
179 }
180}
181
182void BuzzWord::bingo()
183{
184 gameOver = true;
185 QMessageBox::information( this, "BUZZWORD", tr("<h1><b>BINGO !</b></h1>"));
186}
187
188void BuzzWord::about()
189{
190 QMessageBox::information( this, "About", "buZzword 1.0\n(c) 2002 Martin Imobersteg\n\nThis program is distributed\nunder the terms of the GPL v2." );
191}
192
193void BuzzWord::newGame()
194{
195 gameOver = false;
196 delete grid;
197 drawGrid();
198 setCentralWidget(grid);
199}
diff --git a/noncore/games/buzzword/buzzword.h b/noncore/games/buzzword/buzzword.h
new file mode 100644
index 0000000..f72be9a
--- a/dev/null
+++ b/noncore/games/buzzword/buzzword.h
@@ -0,0 +1,89 @@
1/*
2 * Copyright (C) 2002 Martin Imobersteg <imm@gmx.ch>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License,Life or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
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
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19#ifndef BUZZWORD_H
20#define BUZZWORD_H
21
22#include <qmainwindow.h>
23#include <qmenubar.h>
24#include <qlabel.h>
25#include <qvbox.h>
26
27class QGrid;
28
29class BuzzLabel : public QLabel
30{
31 Q_OBJECT
32
33public:
34 BuzzLabel( QWidget *parent=0, const char *name=0 );
35
36protected:
37 virtual void mousePressEvent(QMouseEvent *e);
38
39signals:
40 void clicked();
41};
42
43class BuzzItem : public QVBox
44{
45 Q_OBJECT
46
47public:
48 BuzzItem( int row, int column, QString text, QWidget *parent=0, const char *name=0 );
49
50private:
51 QLabel* label;
52 int _row;
53 int _column;
54
55public slots:
56 void flip();
57
58signals:
59 void clicked(int row,int column);
60};
61
62class BuzzWord : public QMainWindow
63{
64 Q_OBJECT
65
66public:
67 BuzzWord();
68
69private:
70 void drawGrid();
71 void bingo();
72 QString getWord();
73
74 QMenuBar *menu;
75 QPopupMenu *game;
76 QGrid *grid;
77
78 int gridVal;
79 int map[4][4];
80 bool gameOver;
81
82public slots:
83 void about();
84 void newGame();
85 void clicked(int row, int column);
86
87};
88
89#endif
diff --git a/noncore/games/buzzword/buzzword.pro b/noncore/games/buzzword/buzzword.pro
new file mode 100644
index 0000000..7fe9bab
--- a/dev/null
+++ b/noncore/games/buzzword/buzzword.pro
@@ -0,0 +1,9 @@
1 TEMPLATE= app
2 CONFIG = qt warn_on release
3 HEADERS = buzzword.h
4 SOURCES = buzzword.cpp main.cpp
5 INCLUDEPATH+= $(QPEDIR)/include
6 DEPENDPATH+= $(QPEDIR)/include
7DESTDIR = $(OPIEDIR)/bin
8LIBS += -lqpe
9 TARGET = buzzword
diff --git a/noncore/games/buzzword/main.cpp b/noncore/games/buzzword/main.cpp
new file mode 100644
index 0000000..1fa011b
--- a/dev/null
+++ b/noncore/games/buzzword/main.cpp
@@ -0,0 +1,35 @@
1/*
2 * Copyright (C) 2002 Martin Imobersteg <imm@gmx.ch>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License,Life or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
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
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19#include <qpe/qpeapplication.h>
20
21#include <stdlib.h>
22#include <time.h>
23
24#include "buzzword.h"
25
26int main(int argc, char **argv)
27{
28 srand(time(0));
29
30 QPEApplication a( argc, argv );
31 BuzzWord *top = new BuzzWord;
32 a.showMainWidget(top);
33
34 return a.exec();
35}
diff --git a/noncore/games/buzzword/opie-buzzword.control b/noncore/games/buzzword/opie-buzzword.control
new file mode 100644
index 0000000..f047d59
--- a/dev/null
+++ b/noncore/games/buzzword/opie-buzzword.control
@@ -0,0 +1,10 @@
1Files: bin/buzzword apps/Games/buzzword.desktop pics/buzzword/buzzword.png share/buzzword/buzzwords
2Version: 1.1
3Depends: opie-base ($QPE_VERSION)
4Priority: optional
5Section: opie/games
6Maintainer: Martin Imobersteg <imm@gmx.ch>
7Architecture: arm
8License: GPL
9Description: BuzzWord
10 A BuzzWord Bingo for Qtopia.