summaryrefslogtreecommitdiff
path: root/noncore/games/buzzword
authorkergoth <kergoth>2003-08-09 16:24:58 (UTC)
committer kergoth <kergoth>2003-08-09 16:24:58 (UTC)
commite16d333ec2e8509fc665921ca106c25325bae9e0 (patch) (unidiff)
tree9e9068190a15bc9b2a52ab33b40881128f732c0e /noncore/games/buzzword
parent1c58d1407f9584fedcdae390a04e2b37e5853361 (diff)
downloadopie-e16d333ec2e8509fc665921ca106c25325bae9e0.zip
opie-e16d333ec2e8509fc665921ca106c25325bae9e0.tar.gz
opie-e16d333ec2e8509fc665921ca106c25325bae9e0.tar.bz2
Merge from BRANCH_1_0
Diffstat (limited to 'noncore/games/buzzword') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/buzzword/buzzword.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/noncore/games/buzzword/buzzword.cpp b/noncore/games/buzzword/buzzword.cpp
index b870a59..97a17a1 100644
--- a/noncore/games/buzzword/buzzword.cpp
+++ b/noncore/games/buzzword/buzzword.cpp
@@ -1,50 +1,50 @@
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 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 <qpe/qpeapplication.h> 35#include <qpe/qpeapplication.h>
36 36
37#include "buzzword.h" 37#include "buzzword.h"
38 38
39BuzzLabel::BuzzLabel( QWidget *parent, const char *name ) 39BuzzLabel::BuzzLabel( QWidget *parent, const char *name )
40: QLabel( parent, name ) 40: QLabel( parent, name )
41{ 41{
42} 42}
43 43
44void BuzzLabel::mousePressEvent(QMouseEvent *e) 44void 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}
@@ -57,123 +57,123 @@ BuzzItem::BuzzItem( int row, int column, QString text, QWidget *parent, const ch
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
64void BuzzItem::flip() 64void 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
71BuzzWord::BuzzWord() : QMainWindow(0) 71BuzzWord::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 menu->insertItem( tr("&Game"), game ); 78 menu->insertItem( tr("&Game"), game );
79 79
80 gridVal = 4; 80 gridVal = 4;
81 grid = NULL; 81 grid = NULL;
82 gameOver = false; 82 gameOver = false;
83 newGame(); 83 newGame();
84} 84}
85 85
86void BuzzWord::drawGrid() 86void BuzzWord::drawGrid()
87{ 87{
88 QStringList l; 88 QStringList l;
89 89
90 QString path = QPEApplication::qpeDir()+"share/buzzword/"; 90 QString path = QPEApplication::qpeDir()+"share/buzzword/";
91 QFile f( path + "buzzwords" ); 91 QFile f( path + "buzzwords" );
92 if ( !f.open( IO_ReadOnly ) ) 92 if ( !f.open( IO_ReadOnly ) )
93 return; 93 return;
94 94
95 QTextStream t( &f ); 95 QTextStream t( &f );
96 96
97 while (!t.atEnd()) 97 while (!t.atEnd())
98 { 98 {
99 l << t.readLine(); 99 l << t.readLine();
100 } 100 }
101 101
102 f.close(); 102 f.close();
103 103
104 grid = new QGrid(gridVal, this); 104 grid = new QGrid(gridVal, this);
105 grid->setFixedSize(240,240); 105 //grid->setFixedSize( 480, 480 );
106 106
107 for( int c = 0 ; c < gridVal ; c++ ) 107 for( int c = 0 ; c < gridVal ; c++ )
108 { 108 {
109 for( int r = 0 ; r < gridVal ; r++ ) 109 for( int r = 0 ; r < gridVal ; r++ )
110 { 110 {
111 uint pos = rand() % l. count(); 111 uint pos = rand() % l. count();
112 112
113 QString word = QStringList::split(" ", l[pos]).join("\n"); 113 QString word = QStringList::split(" ", l[pos]).join("\n");
114 BuzzItem* bi = new BuzzItem( c, r, word, grid ); 114 BuzzItem* bi = new BuzzItem( c, r, word, grid );
115 connect( bi, SIGNAL(clicked(int, int)), this, SLOT(clicked(int,int)) ); 115 connect( bi, SIGNAL(clicked(int, int)), this, SLOT(clicked(int,int)) );
116 map[c][r] = 0; 116 map[c][r] = 0;
117 117
118 l.remove( l.at( pos )); 118 l.remove( l.at( pos ));
119 } 119 }
120 } 120 }
121} 121}
122 122
123void BuzzWord::clicked(int row, int column) 123void BuzzWord::clicked(int row, int column)
124{ 124{
125 if ( ! gameOver ) 125 if ( ! gameOver )
126 { 126 {
127 int rowTotal = 0; 127 int rowTotal = 0;
128 int columnTotal = 0; 128 int columnTotal = 0;
129 129
130 map[column][row] = 1; 130 map[column][row] = 1;
131 131
132 for( int c = 0 ; c < gridVal ; c++ ) 132 for( int c = 0 ; c < gridVal ; c++ )
133 { 133 {
134 for( int r = 0 ; r < gridVal ; r++ ) 134 for( int r = 0 ; r < gridVal ; r++ )
135 { 135 {
136 if ( map[c][r] == 1 ) 136 if ( map[c][r] == 1 )
137 rowTotal++; 137 rowTotal++;
138 138
139 if ( rowTotal == 4 ) 139 if ( rowTotal == 4 )
140 { 140 {
141 bingo(); 141 bingo();
142 } 142 }
143 } 143 }
144 rowTotal = 0; 144 rowTotal = 0;
145 } 145 }
146 146
147 for( int r = 0 ; r < gridVal ; r++ ) 147 for( int r = 0 ; r < gridVal ; r++ )
148 { 148 {
149 for( int c = 0 ; c < gridVal ; c++ ) 149 for( int c = 0 ; c < gridVal ; c++ )
150 { 150 {
151 if ( map[c][r] == 1 ) 151 if ( map[c][r] == 1 )
152 columnTotal++; 152 columnTotal++;
153 153
154 if ( columnTotal == 4 ) 154 if ( columnTotal == 4 )
155 { 155 {
156 bingo(); 156 bingo();
157 } 157 }
158 } 158 }
159 columnTotal = 0; 159 columnTotal = 0;
160 } 160 }
161 161
162 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] )
163 bingo(); 163 bingo();
164 164
165 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] )
166 bingo(); 166 bingo();
167 } 167 }
168} 168}
169 169
170void BuzzWord::bingo() 170void BuzzWord::bingo()
171{ 171{
172 gameOver = true; 172 gameOver = true;
173 QMessageBox::information( this, "BUZZWORD", tr("<h1><b>BINGO !</b></h1>")); 173 QMessageBox::information( this, "BUZZWORD", tr("<h1><b>BINGO !</b></h1>"));
174} 174}
175 175
176void BuzzWord::newGame() 176void BuzzWord::newGame()
177{ 177{
178 gameOver = false; 178 gameOver = false;
179 delete grid; 179 delete grid;