summaryrefslogtreecommitdiff
authorcniehaus <cniehaus>2003-03-15 20:50:41 (UTC)
committer cniehaus <cniehaus>2003-03-15 20:50:41 (UTC)
commit917fb7d2dca76f5c2c5c86553be0fcc2832c3435 (patch) (unidiff)
tree972e7e2e17496cb4ab618f4a07035d2c2b6f20c8
parentdfe0e1302aa2a366cfa2a8b53102a38b7143ba4b (diff)
downloadopie-917fb7d2dca76f5c2c5c86553be0fcc2832c3435.zip
opie-917fb7d2dca76f5c2c5c86553be0fcc2832c3435.tar.gz
opie-917fb7d2dca76f5c2c5c86553be0fcc2832c3435.tar.bz2
merging with the branch.
Comments?
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/tetrix/ohighscoredlg.cpp199
-rw-r--r--noncore/games/tetrix/ohighscoredlg.h97
-rw-r--r--noncore/games/tetrix/qtetrix.cpp9
-rw-r--r--noncore/games/tetrix/qtetrix.h2
-rw-r--r--noncore/games/tetrix/tetrix.pro6
5 files changed, 308 insertions, 5 deletions
diff --git a/noncore/games/tetrix/ohighscoredlg.cpp b/noncore/games/tetrix/ohighscoredlg.cpp
new file mode 100644
index 0000000..cf0dcf7
--- a/dev/null
+++ b/noncore/games/tetrix/ohighscoredlg.cpp
@@ -0,0 +1,199 @@
1/***************************************************************************
2 begin : January 2003
3 copyright : ( C ) 2003 by Carsten Niehaus
4 email : cniehaus@handhelds.org
5 **************************************************************************/
6
7/***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * ( at your option ) any later version. *
13 * *
14 **************************************************************************/
15
16#include <qdialog.h>
17#include <qpe/config.h>
18#include <qlayout.h>
19#include <qpe/config.h>
20
21#include <qstring.h>
22#include <qhbox.h>
23#include <qvbox.h>
24#include <qlabel.h>
25#include <qlistview.h>
26#include <qlineedit.h>
27
28#include "ohighscoredlg.h"
29
30OHighscore::OHighscore( int score , int playerLevel )
31{
32 pLevel = playerLevel;
33 getList();
34 checkIfItIsANewhighscore( score );
35}
36
37OHighscore::~OHighscore()
38{
39 std::list<t_playerData*>::iterator deleteIterator = playerData.begin();
40 for ( ; deleteIterator != playerData.end() ; deleteIterator++ )
41 {
42 delete ( *deleteIterator );
43 }
44}
45
46void OHighscore::getList()
47{
48 Config cfg ( "tetrix" );
49 cfg.setGroup( QString::number( 1 ) );
50 lowest = cfg.readNumEntry( "Points" );
51 playerData.clear();
52
53 int rest = 1;//for the filling up later
54
55 for ( int i = 1 ; i < 11 ; i++ )
56 {
57 if ( cfg.hasGroup( QString::number( i ) ) )
58 {
59 cfg.setGroup( QString::number( i ) );
60 int temp = cfg.readNumEntry( "Points" );
61
62 t_playerData *pPlayerData = new t_playerData;
63 pPlayerData->sName = cfg.readEntry( "Name" );
64 pPlayerData->points = temp;
65 pPlayerData->level = cfg.readNumEntry( "Level" );
66
67 playerData.push_back( pPlayerData );
68
69 if ( (temp < lowest) ) lowest = temp;
70 rest++;
71 }
72 }
73
74 //now I fill up the rest of the list
75 if ( rest < 11 ) //only go in this loop if there are less than
76 //10 highscoreentries
77 {
78 lowest = 0;
79 for ( ; rest < 11 ; rest++ )
80 {
81 t_playerData *pPlayerData = new t_playerData;
82 pPlayerData->sName = tr( "empty");
83 pPlayerData->points = 0;
84 pPlayerData->level = 0;
85
86 playerData.push_back( pPlayerData );
87 }
88 }
89
90}
91
92void OHighscore::checkIfItIsANewhighscore( int points)
93{
94 if ( points > lowest )
95 isNewhighscore = true;
96 else
97 isNewhighscore = false;
98}
99
100void OHighscore::insertData( QString name , int punkte , int playerLevel )
101{
102 Config cfg ( "tetrix" );
103 int entryNumber = 1;
104 std::list<t_playerData*>::iterator insertIterator = playerData.begin();
105 while ( insertIterator != playerData.end() )
106 {
107 if ( punkte > ( *insertIterator )->points )
108 {
109 t_playerData* temp = new t_playerData;
110 temp->sName = name;
111 temp->points = punkte;
112 temp->level = playerLevel;
113 playerData.insert( insertIterator , temp );
114
115 //now we have to delete the last entry
116 insertIterator = playerData.end();
117 insertIterator--;
118 //X delete *insertIterator; //memleak?
119 playerData.erase( insertIterator );
120
121 /////////////////////////////////////////
122 //this block just rewrites the highscore
123 insertIterator = playerData.begin();
124 while ( insertIterator != playerData.end() )
125 {
126 cfg.setGroup( QString::number( entryNumber ) );
127 cfg.writeEntry( "Name" , ( *insertIterator )->sName );
128 cfg.writeEntry( "Points" , ( *insertIterator )->points );
129 cfg.writeEntry( "Level" , ( *insertIterator )->level );
130 entryNumber++;
131 insertIterator++;
132 }
133 ////////////////////////////////////////
134
135 return;
136 }
137 insertIterator++;
138 }
139}
140
141QString OHighscore::getName()
142{
143 QString name;
144 QDialog *d = new QDialog ( this, 0, true );
145 d->setCaption( tr( "Enter your name!" ));
146 QLineEdit *ed = new QLineEdit ( d );
147 ( new QVBoxLayout ( d, 3, 3 ))->addWidget ( ed );
148 ed->setFocus ( );
149
150 if ( d->exec() == QDialog::Accepted ) {
151 name = ed->text();
152 }
153 //delete d;
154 return name;
155}
156
157OHighscoreDialog::OHighscoreDialog(OHighscore *highscore, QWidget *parent, const char *name, bool modal) : QDialog(parent, name, modal)
158{
159 hs_ = highscore;
160 setCaption( tr( "Highscores" ) );
161 vbox_layout = new QVBoxLayout( this, 4 , 4 );
162 list = new QListView( this );
163 list->setSorting( -1 );
164 list->addColumn( tr( "#" ));
165 list->addColumn( tr( "Name" ));
166 list->addColumn( tr( "Points" ));
167 list->addColumn( tr( "Level" ));
168
169 createHighscoreListView();
170
171 vbox_layout->addWidget( list );
172 showMaximized();
173}
174
175void OHighscoreDialog::createHighscoreListView()
176{
177 int pos = 10;
178 int points_ = 0;
179 int level_ = 0;
180
181 std::list<t_playerData*>::reverse_iterator iListe = hs_->playerData.rbegin();
182
183 for ( ; iListe != hs_->playerData.rend() ; ++iListe )
184 {
185 QListViewItem *item = new QListViewItem( list );
186 item->setText( 0 , QString::number( pos ) ); //number
187 item->setText( 1 , ( *iListe )->sName ); //name
188 if ( ( *iListe )->points == -1 )
189 points_ = 0;
190 else points_ = ( *iListe )->points;
191 if ( ( *iListe )->level == -1 )
192 level_ = 0;
193 else level_ = ( *iListe )->level;
194 item->setText( 2 , QString::number( points_ ) ); //points
195 item->setText( 3 , QString::number( level_ ) ); //level
196 pos--;
197 }
198}
199
diff --git a/noncore/games/tetrix/ohighscoredlg.h b/noncore/games/tetrix/ohighscoredlg.h
new file mode 100644
index 0000000..fdbe623
--- a/dev/null
+++ b/noncore/games/tetrix/ohighscoredlg.h
@@ -0,0 +1,97 @@
1/***************************************************************************
2 * *
3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or *
6 * ( at your option ) any later version. *
7 * *
8 **************************************************************************/
9
10class QWidget;
11class QVBoxLayout;
12class QListView;
13
14#include <qdialog.h>
15#include <list>
16
17using namespace std;
18
19struct t_playerData
20{
21 QString sName;
22 int points;
23 int level;
24};
25
26class OHighscore : public QWidget
27{
28 Q_OBJECT
29
30 public:
31 /*
32 *An OHighscore-Object contains all Points, level and playernames sorted in a stl::vector
33 */
34 OHighscore( int , int );
35
36 ~OHighscore();
37
38 /*
39 * is true if the player did a new highscore
40 */
41 bool isNewhighscore;
42
43 /*
44 * this inserts the new entry at the correct position
45 */
46 void insertData( QString , int , int );
47
48 list<t_playerData*> playerData;
49
50 /*
51 * As Qt/e does not support QInputDialog I did that code myself
52 */
53 QString getName();
54 private:
55
56 list<t_playerData*>::iterator iPlayerData;
57
58 /*
59 * the lowest score in the highscorelist
60 */
61 int lowest;
62
63 /*
64 * the level of the highscore
65 */
66 int pLevel;
67
68 /*
69 * get all scores in a vector and give "lowest" a value
70 */
71 void getList();
72
73 /*
74 * sets the bool if the current score is in the top10
75 */
76 void checkIfItIsANewhighscore( int );
77};
78
79class OHighscoreDialog : public QDialog
80{
81 Q_OBJECT
82
83 public:
84 OHighscoreDialog(OHighscore *highscore, QWidget *parent, const char *name = 0, bool modal = true );
85
86 private:
87 OHighscore *hs_;
88
89 QVBoxLayout *vbox_layout;
90
91 /*
92 * this method creates the QListView with all data
93 */
94 void createHighscoreListView();
95
96 QListView *list;
97};
diff --git a/noncore/games/tetrix/qtetrix.cpp b/noncore/games/tetrix/qtetrix.cpp
index f649894..6d29c3f 100644
--- a/noncore/games/tetrix/qtetrix.cpp
+++ b/noncore/games/tetrix/qtetrix.cpp
@@ -1,54 +1,57 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21 21
22#include "qtetrix.h" 22#include "qtetrix.h"
23 23
24#include <qpe/resource.h> 24#include <qpe/resource.h>
25#include <qpe/config.h>
25 26
26#include <qapplication.h> 27#include <qapplication.h>
27#include <qlabel.h> 28#include <qlabel.h>
28#include <qdatetime.h> 29#include <qdatetime.h>
29#include <qlayout.h> 30#include <qlayout.h>
31#include <qstring.h>
30 32
33#include "ohighscoredlg.h"
31 34
32 35
33void drawTetrixButton( QPainter *p, int x, int y, int w, int h, 36void drawTetrixButton( QPainter *p, int x, int y, int w, int h,
34 const QColor *color ) 37 const QColor *color )
35{ 38{
36 QColor fc; 39 QColor fc;
37 if ( color ) { 40 if ( color ) {
38 QPointArray a; 41 QPointArray a;
39 a.setPoints( 3, x,y+h-1, x,y, x+w-1,y ); 42 a.setPoints( 3, x,y+h-1, x,y, x+w-1,y );
40 p->setPen( color->light() ); 43 p->setPen( color->light() );
41 p->drawPolyline( a ); 44 p->drawPolyline( a );
42 a.setPoints( 3, x+1,y+h-1, x+w-1,y+h-1, x+w-1,y+1 ); 45 a.setPoints( 3, x+1,y+h-1, x+w-1,y+h-1, x+w-1,y+1 );
43 p->setPen( color->dark() ); 46 p->setPen( color->dark() );
44 p->drawPolyline( a ); 47 p->drawPolyline( a );
45 x++; 48 x++;
46 y++; 49 y++;
47 w -= 2; 50 w -= 2;
48 h -= 2; 51 h -= 2;
49 fc = *color; 52 fc = *color;
50 } 53 }
51 else 54 else
52 fc = p->backgroundColor(); 55 fc = p->backgroundColor();
53 p->fillRect( x, y, w, h, fc ); 56 p->fillRect( x, y, w, h, fc );
54} 57}
@@ -140,31 +143,35 @@ QTetrix::QTetrix( QWidget *parent, const char *name, WFlags f )
140 pb->setFocusPolicy( NoFocus ); 143 pb->setFocusPolicy( NoFocus );
141 connect( pb, SIGNAL( clicked() ), board, SLOT( start() ) ); 144 connect( pb, SIGNAL( clicked() ), board, SLOT( start() ) );
142 gl->addMultiCellWidget( pb, 4, 4, 0, 1 ); 145 gl->addMultiCellWidget( pb, 4, 4, 0, 1 );
143 146
144 connect( board, SIGNAL(gameOverSignal()), SLOT(gameOver()) ); 147 connect( board, SIGNAL(gameOverSignal()), SLOT(gameOver()) );
145 connect( board, SIGNAL(drawNextSquareSignal(int,int,QColor*)), showNext, 148 connect( board, SIGNAL(drawNextSquareSignal(int,int,QColor*)), showNext,
146 SLOT(drawNextSquare(int,int,QColor*)) ); 149 SLOT(drawNextSquare(int,int,QColor*)) );
147 connect( showNext, SIGNAL(update()), board, SLOT(updateNext()) ); 150 connect( showNext, SIGNAL(update()), board, SLOT(updateNext()) );
148 connect( board, SIGNAL(updateScoreSignal(int)), showScore, 151 connect( board, SIGNAL(updateScoreSignal(int)), showScore,
149 SLOT(setNum(int)) ); 152 SLOT(setNum(int)) );
150 connect( board, SIGNAL(updateLevelSignal(int)), showLevel, 153 connect( board, SIGNAL(updateLevelSignal(int)), showLevel,
151 SLOT(setNum(int))); 154 SLOT(setNum(int)));
152 connect( board, SIGNAL(updateRemovedSignal(int)), showLines, 155 connect( board, SIGNAL(updateRemovedSignal(int)), showLines,
153 SLOT(setNum(int))); 156 SLOT(setNum(int)));
154 157
155 showScore->setNum( 0 ); 158 showScore->setNum( 0 );
156 showLevel->setNum( 0 ); 159 showLevel->setNum( 0 );
157 showLines->setNum( 0 ); 160 showLines->setNum( 0 );
158 board->revealNextPiece(TRUE); 161 board->revealNextPiece(TRUE);
159 board->setFocusPolicy( StrongFocus ); 162 board->setFocusPolicy( StrongFocus );
160} 163}
161 164
162void QTetrix::gameOver() 165void QTetrix::gameOver()
163{ 166{
167 OHighscore *hs = new OHighscore( showScore->text().toInt() , showLevel->text().toInt() );
168 if ( hs->isNewhighscore )
169 hs->insertData( hs->getName(), showScore->text().toInt() , showLevel->text().toInt() );
170 OHighscoreDialog hscdlg( hs, this, "OHighscoreDialog", true );
171 hscdlg.exec();
164} 172}
165 173
166
167void QTetrix::quit() 174void QTetrix::quit()
168{ 175{
169 close(); 176 close();
170} 177}
diff --git a/noncore/games/tetrix/qtetrix.h b/noncore/games/tetrix/qtetrix.h
index b6e058a..cb33941 100644
--- a/noncore/games/tetrix/qtetrix.h
+++ b/noncore/games/tetrix/qtetrix.h
@@ -1,45 +1,43 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20
21
22#ifndef QTETRIX_H 20#ifndef QTETRIX_H
23#define QTETRIX_H 21#define QTETRIX_H
24 22
25#include "qtetrixb.h" 23#include "qtetrixb.h"
26#include <qframe.h> 24#include <qframe.h>
27#include <qlcdnumber.h> 25#include <qlcdnumber.h>
28#include <qpushbutton.h> 26#include <qpushbutton.h>
29#include <qpainter.h> 27#include <qpainter.h>
30#include <qmainwindow.h> 28#include <qmainwindow.h>
31 29
32class QLabel; 30class QLabel;
33 31
34class ShowNextPiece : public QFrame 32class ShowNextPiece : public QFrame
35{ 33{
36 Q_OBJECT 34 Q_OBJECT
37 friend class QTetrix; 35 friend class QTetrix;
38public: 36public:
39 ShowNextPiece( QWidget *parent=0, const char *name=0 ); 37 ShowNextPiece( QWidget *parent=0, const char *name=0 );
40public slots: 38public slots:
41 void drawNextSquare( int x, int y,QColor *color ); 39 void drawNextSquare( int x, int y,QColor *color );
42signals: 40signals:
43 void update(); 41 void update();
44private: 42private:
45 void paintEvent( QPaintEvent * ); 43 void paintEvent( QPaintEvent * );
diff --git a/noncore/games/tetrix/tetrix.pro b/noncore/games/tetrix/tetrix.pro
index 061b4f3..f316dc2 100644
--- a/noncore/games/tetrix/tetrix.pro
+++ b/noncore/games/tetrix/tetrix.pro
@@ -1,36 +1,38 @@
1 TEMPLATE= app 1 TEMPLATE= app
2 CONFIG = qt warn_on release 2 CONFIG = qt warn_on release
3 DESTDIR = $(OPIEDIR)/bin 3 DESTDIR = $(OPIEDIR)/bin
4 HEADERS = gtetrix.h \ 4 HEADERS = gtetrix.h \
5 qtetrix.h \ 5 qtetrix.h \
6 qtetrixb.h \ 6 qtetrixb.h \
7 tpiece.h 7 tpiece.h \
8 ohighscoredlg.h
8 SOURCES = main.cpp \ 9 SOURCES = main.cpp \
9 gtetrix.cpp \ 10 gtetrix.cpp \
10 qtetrix.cpp \ 11 qtetrix.cpp \
11 qtetrixb.cpp \ 12 qtetrixb.cpp \
12 tpiece.cpp 13 tpiece.cpp \
14 ohighscoredlg.cpp
13INCLUDEPATH += $(OPIEDIR)/include 15INCLUDEPATH += $(OPIEDIR)/include
14 DEPENDPATH+= $(OPIEDIR)/include 16 DEPENDPATH+= $(OPIEDIR)/include
15LIBS += -lqpe 17LIBS += -lqpe
16 INTERFACES= 18 INTERFACES=
17 TARGET = tetrix 19 TARGET = tetrix
18 20
19TRANSLATIONS = ../../../i18n/de/tetrix.ts \ 21TRANSLATIONS = ../../../i18n/de/tetrix.ts \
20 ../../../i18n/da/tetrix.ts \ 22 ../../../i18n/da/tetrix.ts \
21 ../../../i18n/xx/tetrix.ts \ 23 ../../../i18n/xx/tetrix.ts \
22 ../../../i18n/en/tetrix.ts \ 24 ../../../i18n/en/tetrix.ts \
23 ../../../i18n/es/tetrix.ts \ 25 ../../../i18n/es/tetrix.ts \
24 ../../../i18n/fr/tetrix.ts \ 26 ../../../i18n/fr/tetrix.ts \
25 ../../../i18n/hu/tetrix.ts \ 27 ../../../i18n/hu/tetrix.ts \
26 ../../../i18n/ja/tetrix.ts \ 28 ../../../i18n/ja/tetrix.ts \
27 ../../../i18n/ko/tetrix.ts \ 29 ../../../i18n/ko/tetrix.ts \
28 ../../../i18n/no/tetrix.ts \ 30 ../../../i18n/no/tetrix.ts \
29 ../../../i18n/pl/tetrix.ts \ 31 ../../../i18n/pl/tetrix.ts \
30 ../../../i18n/pt/tetrix.ts \ 32 ../../../i18n/pt/tetrix.ts \
31 ../../../i18n/pt_BR/tetrix.ts \ 33 ../../../i18n/pt_BR/tetrix.ts \
32 ../../../i18n/sl/tetrix.ts \ 34 ../../../i18n/sl/tetrix.ts \
33 ../../../i18n/zh_CN/tetrix.ts \ 35 ../../../i18n/zh_CN/tetrix.ts \
34 ../../../i18n/it/tetrix.ts \ 36 ../../../i18n/it/tetrix.ts \
35 ../../../i18n/zh_TW/tetrix.ts 37 ../../../i18n/zh_TW/tetrix.ts
36 38