summaryrefslogtreecommitdiff
path: root/noncore/games/buzzword/buzzword.cpp
authoralwin <alwin>2004-03-02 12:21:11 (UTC)
committer alwin <alwin>2004-03-02 12:21:11 (UTC)
commitb6b1c97559c0ed9f2e33632272426bf98f289232 (patch) (unidiff)
treed3a9987704770cdf5eb14e1136f6e3ecb2f36a04 /noncore/games/buzzword/buzzword.cpp
parent0d59c780513da78033f4d9040475dee9db0256d4 (diff)
downloadopie-b6b1c97559c0ed9f2e33632272426bf98f289232.zip
opie-b6b1c97559c0ed9f2e33632272426bf98f289232.tar.gz
opie-b6b1c97559c0ed9f2e33632272426bf98f289232.tar.bz2
applied the patch generated by the optimize_connect script from
TT.
Diffstat (limited to 'noncore/games/buzzword/buzzword.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/buzzword/buzzword.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/games/buzzword/buzzword.cpp b/noncore/games/buzzword/buzzword.cpp
index 13eb481..b7f2573 100644
--- a/noncore/games/buzzword/buzzword.cpp
+++ b/noncore/games/buzzword/buzzword.cpp
@@ -18,164 +18,164 @@
18 18
19#include <qlayout.h> 19#include <qlayout.h>
20#include <qmainwindow.h> 20#include <qmainwindow.h>
21#include <qlabel.h> 21#include <qlabel.h>
22#include <qgrid.h> 22#include <qgrid.h>
23#include <qcolor.h> 23#include <qcolor.h>
24#include <qbutton.h> 24#include <qbutton.h>
25#include <qfile.h> 25#include <qfile.h>
26#include <qtextstream.h> 26#include <qtextstream.h>
27#include <qstringlist.h> 27#include <qstringlist.h>
28#include <qmessagebox.h> 28#include <qmessagebox.h>
29#include <qdir.h> 29#include <qdir.h>
30 30
31#include <math.h> 31#include <math.h>
32#include <stdlib.h> 32#include <stdlib.h>
33 33
34#include <qpe/qpeapplication.h> 34#include <qpe/qpeapplication.h>
35 35
36#include "buzzword.h" 36#include "buzzword.h"
37 37
38BuzzLabel::BuzzLabel( QWidget *parent, const char *name ) 38BuzzLabel::BuzzLabel( QWidget *parent, const char *name )
39: QLabel( parent, name ) 39: QLabel( parent, name )
40{ 40{
41} 41}
42 42
43void BuzzLabel::mousePressEvent(QMouseEvent *e) 43void BuzzLabel::mousePressEvent(QMouseEvent *e)
44{ 44{
45 if(e->button() == LeftButton) 45 if(e->button() == LeftButton)
46 { 46 {
47 emit clicked(); 47 emit clicked();
48 } 48 }
49} 49}
50 50
51BuzzItem::BuzzItem( int row, int column, QString text, QWidget *parent, const char *name ) 51BuzzItem::BuzzItem( int row, int column, QString text, QWidget *parent, const char *name )
52: QVBox( parent, name ), _row(row), _column(column) 52: QVBox( parent, name ), _row(row), _column(column)
53{ 53{
54 setFrameStyle( QFrame::Panel | QFrame::Raised ); 54 setFrameStyle( QFrame::Panel | QFrame::Raised );
55 setLineWidth( 1 ); 55 setLineWidth( 1 );
56 label = new BuzzLabel(this, "label"); 56 label = new BuzzLabel(this, "label");
57 label->setText(text); 57 label->setText(text);
58 label->setAlignment( int( QLabel::AlignCenter ) ); 58 label->setAlignment( int( QLabel::AlignCenter ) );
59 59
60 connect( label, SIGNAL(clicked()), this, SLOT(flip()) ); 60 connect( label, SIGNAL(clicked()), this, SLOT(flip()) );
61} 61}
62 62
63void BuzzItem::flip() 63void BuzzItem::flip()
64{ 64{
65 setLineWidth( 1 ); 65 setLineWidth( 1 );
66 label->setBackgroundColor(label->colorGroup().highlight()); 66 label->setBackgroundColor(label->colorGroup().highlight());
67 emit clicked(_row, _column); 67 emit clicked(_row, _column);
68} 68}
69 69
70BuzzWord::BuzzWord(QWidget* parent, const char* name, WFlags fl ) : QMainWindow( parent, name, fl ) 70BuzzWord::BuzzWord(QWidget* parent, const char* name, WFlags fl ) : QMainWindow( parent, name, fl )
71{ 71{
72 setCaption(tr("buZzword")); 72 setCaption(tr("buZzword"));
73 73
74 menu = menuBar(); 74 menu = menuBar();
75 game = new QPopupMenu; 75 game = new QPopupMenu;
76 game->insertItem(tr("&New game"), this, SLOT(newGame()), Key_N ); 76 game->insertItem(tr("&New game"), this, SLOT(newGame()), Key_N );
77 menu->insertItem( tr("&Game"), game ); 77 menu->insertItem( tr("&Game"), game );
78 78
79 gridVal = 4; 79 gridVal = 4;
80 grid = NULL; 80 grid = NULL;
81 gameOver = false; 81 gameOver = false;
82 newGame(); 82 newGame();
83} 83}
84 84
85void BuzzWord::drawGrid() 85void BuzzWord::drawGrid()
86{ 86{
87 QStringList l; 87 QStringList l;
88 88
89 QString path = QPEApplication::qpeDir()+"share/buzzword/"; 89 QString path = QPEApplication::qpeDir()+"share/buzzword/";
90 QFile f( path + "buzzwords" ); 90 QFile f( path + "buzzwords" );
91 if ( !f.open( IO_ReadOnly ) ) 91 if ( !f.open( IO_ReadOnly ) )
92 return; 92 return;
93 93
94 QTextStream t( &f ); 94 QTextStream t( &f );
95 95
96 while (!t.atEnd()) 96 while (!t.atEnd())
97 { 97 {
98 l << t.readLine(); 98 l << t.readLine();
99 } 99 }
100 100
101 f.close(); 101 f.close();
102 102
103 grid = new QGrid(gridVal, this); 103 grid = new QGrid(gridVal, this);
104 //grid->setFixedSize( 480, 480 ); 104 //grid->setFixedSize( 480, 480 );
105 105
106 for( int c = 0 ; c < gridVal ; c++ ) 106 for( int c = 0 ; c < gridVal ; c++ )
107 { 107 {
108 for( int r = 0 ; r < gridVal ; r++ ) 108 for( int r = 0 ; r < gridVal ; r++ )
109 { 109 {
110 uint pos = rand() % l. count(); 110 uint pos = rand() % l. count();
111 111
112 QString word = QStringList::split(" ", l[pos]).join("\n"); 112 QString word = QStringList::split(" ", l[pos]).join("\n");
113 BuzzItem* bi = new BuzzItem( c, r, word, grid ); 113 BuzzItem* bi = new BuzzItem( c, r, word, grid );
114 connect( bi, SIGNAL(clicked(int, int)), this, SLOT(clicked(int,int)) ); 114 connect( bi, SIGNAL(clicked(int,int)), this, SLOT(clicked(int,int)) );
115 map[c][r] = 0; 115 map[c][r] = 0;
116 116
117 l.remove( l.at( pos )); 117 l.remove( l.at( pos ));
118 } 118 }
119 } 119 }
120} 120}
121 121
122void BuzzWord::clicked(int row, int column) 122void BuzzWord::clicked(int row, int column)
123{ 123{
124 if ( ! gameOver ) 124 if ( ! gameOver )
125 { 125 {
126 int rowTotal = 0; 126 int rowTotal = 0;
127 int columnTotal = 0; 127 int columnTotal = 0;
128 128
129 map[column][row] = 1; 129 map[column][row] = 1;
130 130
131 for( int c = 0 ; c < gridVal ; c++ ) 131 for( int c = 0 ; c < gridVal ; c++ )
132 { 132 {
133 for( int r = 0 ; r < gridVal ; r++ ) 133 for( int r = 0 ; r < gridVal ; r++ )
134 { 134 {
135 if ( map[c][r] == 1 ) 135 if ( map[c][r] == 1 )
136 rowTotal++; 136 rowTotal++;
137 137
138 if ( rowTotal == 4 ) 138 if ( rowTotal == 4 )
139 { 139 {
140 bingo(); 140 bingo();
141 } 141 }
142 } 142 }
143 rowTotal = 0; 143 rowTotal = 0;
144 } 144 }
145 145
146 for( int r = 0 ; r < gridVal ; r++ ) 146 for( int r = 0 ; r < gridVal ; r++ )
147 { 147 {
148 for( int c = 0 ; c < gridVal ; c++ ) 148 for( int c = 0 ; c < gridVal ; c++ )
149 { 149 {
150 if ( map[c][r] == 1 ) 150 if ( map[c][r] == 1 )
151 columnTotal++; 151 columnTotal++;
152 152
153 if ( columnTotal == 4 ) 153 if ( columnTotal == 4 )
154 { 154 {
155 bingo(); 155 bingo();
156 } 156 }
157 } 157 }
158 columnTotal = 0; 158 columnTotal = 0;
159 } 159 }
160 160
161 if ( map[0][0] && map[1][1] && map[2][2] && map[3][3] ) 161 if ( map[0][0] && map[1][1] && map[2][2] && map[3][3] )
162 bingo(); 162 bingo();
163 163
164 if ( map[0][3] && map[1][2] && map[2][1] && map[3][0] ) 164 if ( map[0][3] && map[1][2] && map[2][1] && map[3][0] )
165 bingo(); 165 bingo();
166 } 166 }
167} 167}
168 168
169void BuzzWord::bingo() 169void BuzzWord::bingo()
170{ 170{
171 gameOver = true; 171 gameOver = true;
172 QMessageBox::information( this, "BUZZWORD", tr("<h1><b>BINGO !</b></h1>")); 172 QMessageBox::information( this, "BUZZWORD", tr("<h1><b>BINGO !</b></h1>"));
173} 173}
174 174
175void BuzzWord::newGame() 175void BuzzWord::newGame()
176{ 176{
177 gameOver = false; 177 gameOver = false;
178 delete grid; 178 delete grid;
179 drawGrid(); 179 drawGrid();
180 setCentralWidget(grid); 180 setCentralWidget(grid);
181} 181}