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) (show 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
@@ -22,12 +22,15 @@
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,
@@ -161,9 +164,13 @@ QTetrix::QTetrix( QWidget *parent, const char *name, WFlags f )
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();
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
@@ -17,8 +17,6 @@
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
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
@@ -4,12 +4,14 @@ 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