Diffstat (limited to 'noncore/games/buzzword/buzzword.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/buzzword/buzzword.cpp | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/noncore/games/buzzword/buzzword.cpp b/noncore/games/buzzword/buzzword.cpp index 447396b..324b5bd 100644 --- a/noncore/games/buzzword/buzzword.cpp +++ b/noncore/games/buzzword/buzzword.cpp | |||
@@ -29,25 +29,16 @@ | |||
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> | ||
36 | #include <string> | ||
37 | |||
38 | #include <qpe/qpeapplication.h> | 35 | #include <qpe/qpeapplication.h> |
39 | 36 | ||
40 | #include "buzzword.h" | 37 | #include "buzzword.h" |
41 | 38 | ||
42 | // sponsered by rikkus :) | ||
43 | bool random_compare(const QString &, const QString &) | ||
44 | { | ||
45 | return (rand() % 2) > 0.5; | ||
46 | } | ||
47 | |||
48 | BuzzLabel::BuzzLabel( QWidget *parent, const char *name ) | 39 | BuzzLabel::BuzzLabel( QWidget *parent, const char *name ) |
49 | : QLabel( parent, name ) | 40 | : QLabel( parent, name ) |
50 | { | 41 | { |
51 | } | 42 | } |
52 | 43 | ||
53 | void BuzzLabel::mousePressEvent(QMouseEvent *e) | 44 | void BuzzLabel::mousePressEvent(QMouseEvent *e) |
@@ -93,43 +84,43 @@ BuzzWord::BuzzWord() : QMainWindow(0) | |||
93 | gameOver = false; | 84 | gameOver = false; |
94 | newGame(); | 85 | newGame(); |
95 | } | 86 | } |
96 | 87 | ||
97 | void BuzzWord::drawGrid() | 88 | void BuzzWord::drawGrid() |
98 | { | 89 | { |
99 | std::list<QString> l; | 90 | QStringList l; |
100 | 91 | ||
101 | QString path = QPEApplication::qpeDir()+"share/buzzword/"; | 92 | QString path = QPEApplication::qpeDir()+"share/buzzword/"; |
102 | QFile f( path + "buzzwords" ); | 93 | QFile f( path + "buzzwords" ); |
103 | if ( !f.open( IO_ReadOnly ) ) | 94 | if ( !f.open( IO_ReadOnly ) ) |
104 | return; | 95 | return; |
105 | 96 | ||
106 | QTextStream t( &f ); | 97 | QTextStream t( &f ); |
107 | 98 | ||
108 | while (!t.atEnd()) | 99 | while (!t.atEnd()) |
109 | { | 100 | { |
110 | l.push_back(t.readLine()); | 101 | l << t.readLine(); |
111 | } | 102 | } |
112 | 103 | ||
113 | f.close(); | 104 | f.close(); |
114 | 105 | ||
115 | l.sort(random_compare); | ||
116 | |||
117 | grid = new QGrid(gridVal, this); | 106 | grid = new QGrid(gridVal, this); |
118 | grid->setFixedSize(240,240); | 107 | grid->setFixedSize(240,240); |
119 | 108 | ||
120 | for( int c = 0 ; c < gridVal ; c++ ) | 109 | for( int c = 0 ; c < gridVal ; c++ ) |
121 | { | 110 | { |
122 | for( int r = 0 ; r < gridVal ; r++ ) | 111 | for( int r = 0 ; r < gridVal ; r++ ) |
123 | { | 112 | { |
124 | QString word = QStringList::split(" ", l.front()).join("\n"); | 113 | uint pos = rand() % l. count(); |
114 | |||
115 | QString word = QStringList::split(" ", l[pos]).join("\n"); | ||
125 | BuzzItem* bi = new BuzzItem( c, r, word, grid ); | 116 | BuzzItem* bi = new BuzzItem( c, r, word, grid ); |
126 | connect( bi, SIGNAL(clicked(int, int)), this, SLOT(clicked(int,int)) ); | 117 | connect( bi, SIGNAL(clicked(int, int)), this, SLOT(clicked(int,int)) ); |
127 | map[c][r] = 0; | 118 | map[c][r] = 0; |
128 | 119 | ||
129 | l.pop_front(); | 120 | l.remove( l.at( pos )); |
130 | } | 121 | } |
131 | } | 122 | } |
132 | } | 123 | } |
133 | 124 | ||
134 | void BuzzWord::clicked(int row, int column) | 125 | void BuzzWord::clicked(int row, int column) |
135 | { | 126 | { |