-rw-r--r-- | noncore/games/buzzword/buzzword.cpp | 7 | ||||
-rw-r--r-- | noncore/games/buzzword/buzzword.h | 1 |
2 files changed, 0 insertions, 8 deletions
diff --git a/noncore/games/buzzword/buzzword.cpp b/noncore/games/buzzword/buzzword.cpp index 324b5bd..b870a59 100644 --- a/noncore/games/buzzword/buzzword.cpp +++ b/noncore/games/buzzword/buzzword.cpp | |||
@@ -14,176 +14,169 @@ | |||
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 <qpe/qpeapplication.h> | 35 | #include <qpe/qpeapplication.h> |
36 | 36 | ||
37 | #include "buzzword.h" | 37 | #include "buzzword.h" |
38 | 38 | ||
39 | BuzzLabel::BuzzLabel( QWidget *parent, const char *name ) | 39 | BuzzLabel::BuzzLabel( QWidget *parent, const char *name ) |
40 | : QLabel( parent, name ) | 40 | : QLabel( parent, name ) |
41 | { | 41 | { |
42 | } | 42 | } |
43 | 43 | ||
44 | void BuzzLabel::mousePressEvent(QMouseEvent *e) | 44 | void BuzzLabel::mousePressEvent(QMouseEvent *e) |
45 | { | 45 | { |
46 | if(e->button() == LeftButton) | 46 | if(e->button() == LeftButton) |
47 | { | 47 | { |
48 | emit clicked(); | 48 | emit clicked(); |
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||
52 | BuzzItem::BuzzItem( int row, int column, QString text, QWidget *parent, const char *name ) | 52 | BuzzItem::BuzzItem( int row, int column, QString text, QWidget *parent, const char *name ) |
53 | : QVBox( parent, name ), _row(row), _column(column) | 53 | : QVBox( parent, name ), _row(row), _column(column) |
54 | { | 54 | { |
55 | setFrameStyle( QFrame::Panel | QFrame::Raised ); | 55 | setFrameStyle( QFrame::Panel | QFrame::Raised ); |
56 | setLineWidth( 1 ); | 56 | setLineWidth( 1 ); |
57 | label = new BuzzLabel(this, "label"); | 57 | label = new BuzzLabel(this, "label"); |
58 | label->setText(text); | 58 | label->setText(text); |
59 | label->setAlignment( int( QLabel::AlignCenter ) ); | 59 | label->setAlignment( int( QLabel::AlignCenter ) ); |
60 | 60 | ||
61 | connect( label, SIGNAL(clicked()), this, SLOT(flip()) ); | 61 | connect( label, SIGNAL(clicked()), this, SLOT(flip()) ); |
62 | } | 62 | } |
63 | 63 | ||
64 | void BuzzItem::flip() | 64 | void BuzzItem::flip() |
65 | { | 65 | { |
66 | setLineWidth( 1 ); | 66 | setLineWidth( 1 ); |
67 | label->setBackgroundColor(label->colorGroup().highlight()); | 67 | label->setBackgroundColor(label->colorGroup().highlight()); |
68 | emit clicked(_row, _column); | 68 | emit clicked(_row, _column); |
69 | } | 69 | } |
70 | 70 | ||
71 | BuzzWord::BuzzWord() : QMainWindow(0) | 71 | BuzzWord::BuzzWord() : QMainWindow(0) |
72 | { | 72 | { |
73 | setCaption(tr("buZzword")); | 73 | setCaption(tr("buZzword")); |
74 | 74 | ||
75 | menu = menuBar(); | 75 | menu = menuBar(); |
76 | game = new QPopupMenu; | 76 | game = new QPopupMenu; |
77 | game->insertItem(tr("&New game"), this, SLOT(newGame()), Key_N ); | 77 | game->insertItem(tr("&New game"), this, SLOT(newGame()), Key_N ); |
78 | game->insertSeparator(); | ||
79 | game->insertItem(tr("&About"), this, SLOT(about())); | ||
80 | menu->insertItem( tr("&Game"), game ); | 78 | menu->insertItem( tr("&Game"), game ); |
81 | 79 | ||
82 | gridVal = 4; | 80 | gridVal = 4; |
83 | grid = NULL; | 81 | grid = NULL; |
84 | gameOver = false; | 82 | gameOver = false; |
85 | newGame(); | 83 | newGame(); |
86 | } | 84 | } |
87 | 85 | ||
88 | void BuzzWord::drawGrid() | 86 | void BuzzWord::drawGrid() |
89 | { | 87 | { |
90 | QStringList l; | 88 | QStringList l; |
91 | 89 | ||
92 | QString path = QPEApplication::qpeDir()+"share/buzzword/"; | 90 | QString path = QPEApplication::qpeDir()+"share/buzzword/"; |
93 | QFile f( path + "buzzwords" ); | 91 | QFile f( path + "buzzwords" ); |
94 | if ( !f.open( IO_ReadOnly ) ) | 92 | if ( !f.open( IO_ReadOnly ) ) |
95 | return; | 93 | return; |
96 | 94 | ||
97 | QTextStream t( &f ); | 95 | QTextStream t( &f ); |
98 | 96 | ||
99 | while (!t.atEnd()) | 97 | while (!t.atEnd()) |
100 | { | 98 | { |
101 | l << t.readLine(); | 99 | l << t.readLine(); |
102 | } | 100 | } |
103 | 101 | ||
104 | f.close(); | 102 | f.close(); |
105 | 103 | ||
106 | grid = new QGrid(gridVal, this); | 104 | grid = new QGrid(gridVal, this); |
107 | grid->setFixedSize(240,240); | 105 | grid->setFixedSize(240,240); |
108 | 106 | ||
109 | for( int c = 0 ; c < gridVal ; c++ ) | 107 | for( int c = 0 ; c < gridVal ; c++ ) |
110 | { | 108 | { |
111 | for( int r = 0 ; r < gridVal ; r++ ) | 109 | for( int r = 0 ; r < gridVal ; r++ ) |
112 | { | 110 | { |
113 | uint pos = rand() % l. count(); | 111 | uint pos = rand() % l. count(); |
114 | 112 | ||
115 | QString word = QStringList::split(" ", l[pos]).join("\n"); | 113 | QString word = QStringList::split(" ", l[pos]).join("\n"); |
116 | BuzzItem* bi = new BuzzItem( c, r, word, grid ); | 114 | BuzzItem* bi = new BuzzItem( c, r, word, grid ); |
117 | connect( bi, SIGNAL(clicked(int, int)), this, SLOT(clicked(int,int)) ); | 115 | connect( bi, SIGNAL(clicked(int, int)), this, SLOT(clicked(int,int)) ); |
118 | map[c][r] = 0; | 116 | map[c][r] = 0; |
119 | 117 | ||
120 | l.remove( l.at( pos )); | 118 | l.remove( l.at( pos )); |
121 | } | 119 | } |
122 | } | 120 | } |
123 | } | 121 | } |
124 | 122 | ||
125 | void BuzzWord::clicked(int row, int column) | 123 | void BuzzWord::clicked(int row, int column) |
126 | { | 124 | { |
127 | if ( ! gameOver ) | 125 | if ( ! gameOver ) |
128 | { | 126 | { |
129 | int rowTotal = 0; | 127 | int rowTotal = 0; |
130 | int columnTotal = 0; | 128 | int columnTotal = 0; |
131 | 129 | ||
132 | map[column][row] = 1; | 130 | map[column][row] = 1; |
133 | 131 | ||
134 | for( int c = 0 ; c < gridVal ; c++ ) | 132 | for( int c = 0 ; c < gridVal ; c++ ) |
135 | { | 133 | { |
136 | for( int r = 0 ; r < gridVal ; r++ ) | 134 | for( int r = 0 ; r < gridVal ; r++ ) |
137 | { | 135 | { |
138 | if ( map[c][r] == 1 ) | 136 | if ( map[c][r] == 1 ) |
139 | rowTotal++; | 137 | rowTotal++; |
140 | 138 | ||
141 | if ( rowTotal == 4 ) | 139 | if ( rowTotal == 4 ) |
142 | { | 140 | { |
143 | bingo(); | 141 | bingo(); |
144 | } | 142 | } |
145 | } | 143 | } |
146 | rowTotal = 0; | 144 | rowTotal = 0; |
147 | } | 145 | } |
148 | 146 | ||
149 | for( int r = 0 ; r < gridVal ; r++ ) | 147 | for( int r = 0 ; r < gridVal ; r++ ) |
150 | { | 148 | { |
151 | for( int c = 0 ; c < gridVal ; c++ ) | 149 | for( int c = 0 ; c < gridVal ; c++ ) |
152 | { | 150 | { |
153 | if ( map[c][r] == 1 ) | 151 | if ( map[c][r] == 1 ) |
154 | columnTotal++; | 152 | columnTotal++; |
155 | 153 | ||
156 | if ( columnTotal == 4 ) | 154 | if ( columnTotal == 4 ) |
157 | { | 155 | { |
158 | bingo(); | 156 | bingo(); |
159 | } | 157 | } |
160 | } | 158 | } |
161 | columnTotal = 0; | 159 | columnTotal = 0; |
162 | } | 160 | } |
163 | 161 | ||
164 | if ( map[0][0] && map[1][1] && map[2][2] && map[3][3] ) | 162 | if ( map[0][0] && map[1][1] && map[2][2] && map[3][3] ) |
165 | bingo(); | 163 | bingo(); |
166 | 164 | ||
167 | if ( map[0][3] && map[1][2] && map[2][1] && map[3][0] ) | 165 | if ( map[0][3] && map[1][2] && map[2][1] && map[3][0] ) |
168 | bingo(); | 166 | bingo(); |
169 | } | 167 | } |
170 | } | 168 | } |
171 | 169 | ||
172 | void BuzzWord::bingo() | 170 | void BuzzWord::bingo() |
173 | { | 171 | { |
174 | gameOver = true; | 172 | gameOver = true; |
175 | QMessageBox::information( this, "BUZZWORD", tr("<h1><b>BINGO !</b></h1>")); | 173 | QMessageBox::information( this, "BUZZWORD", tr("<h1><b>BINGO !</b></h1>")); |
176 | } | 174 | } |
177 | 175 | ||
178 | void BuzzWord::about() | ||
179 | { | ||
180 | QMessageBox::information( this, "About", "buZzword 1.0\n(c) 2002 Martin Imobersteg\n\nThis program is distributed\nunder the terms of the GPL v2." ); | ||
181 | } | ||
182 | |||
183 | void BuzzWord::newGame() | 176 | void BuzzWord::newGame() |
184 | { | 177 | { |
185 | gameOver = false; | 178 | gameOver = false; |
186 | delete grid; | 179 | delete grid; |
187 | drawGrid(); | 180 | drawGrid(); |
188 | setCentralWidget(grid); | 181 | setCentralWidget(grid); |
189 | } | 182 | } |
diff --git a/noncore/games/buzzword/buzzword.h b/noncore/games/buzzword/buzzword.h index 2e00563..37dd5b4 100644 --- a/noncore/games/buzzword/buzzword.h +++ b/noncore/games/buzzword/buzzword.h | |||
@@ -19,71 +19,70 @@ | |||
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 | ||
27 | class QGrid; | 27 | class QGrid; |
28 | 28 | ||
29 | class BuzzLabel : public QLabel | 29 | class BuzzLabel : public QLabel |
30 | { | 30 | { |
31 | Q_OBJECT | 31 | Q_OBJECT |
32 | 32 | ||
33 | public: | 33 | public: |
34 | BuzzLabel( QWidget *parent=0, const char *name=0 ); | 34 | BuzzLabel( QWidget *parent=0, const char *name=0 ); |
35 | 35 | ||
36 | protected: | 36 | protected: |
37 | virtual void mousePressEvent(QMouseEvent *e); | 37 | virtual void mousePressEvent(QMouseEvent *e); |
38 | 38 | ||
39 | signals: | 39 | signals: |
40 | void clicked(); | 40 | void clicked(); |
41 | }; | 41 | }; |
42 | 42 | ||
43 | class BuzzItem : public QVBox | 43 | class BuzzItem : public QVBox |
44 | { | 44 | { |
45 | Q_OBJECT | 45 | Q_OBJECT |
46 | 46 | ||
47 | public: | 47 | public: |
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 | ||
50 | private: | 50 | private: |
51 | QLabel* label; | 51 | QLabel* label; |
52 | int _row; | 52 | int _row; |
53 | int _column; | 53 | int _column; |
54 | 54 | ||
55 | public slots: | 55 | public slots: |
56 | void flip(); | 56 | void flip(); |
57 | 57 | ||
58 | signals: | 58 | signals: |
59 | void clicked(int row,int column); | 59 | void clicked(int row,int column); |
60 | }; | 60 | }; |
61 | 61 | ||
62 | class BuzzWord : public QMainWindow | 62 | class BuzzWord : public QMainWindow |
63 | { | 63 | { |
64 | Q_OBJECT | 64 | Q_OBJECT |
65 | 65 | ||
66 | public: | 66 | public: |
67 | BuzzWord(); | 67 | BuzzWord(); |
68 | 68 | ||
69 | private: | 69 | private: |
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 | ||
82 | public slots: | 82 | public slots: |
83 | void about(); | ||
84 | void newGame(); | 83 | void newGame(); |
85 | void clicked(int row, int column); | 84 | void clicked(int row, int column); |
86 | 85 | ||
87 | }; | 86 | }; |
88 | 87 | ||
89 | #endif | 88 | #endif |