summaryrefslogtreecommitdiff
authorcniehaus <cniehaus>2003-03-15 20:50:41 (UTC)
committer cniehaus <cniehaus>2003-03-15 20:50:41 (UTC)
commit917fb7d2dca76f5c2c5c86553be0fcc2832c3435 (patch) (side-by-side diff)
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 @@
+/***************************************************************************
+ begin : January 2003
+ copyright : ( C ) 2003 by Carsten Niehaus
+ email : cniehaus@handhelds.org
+ **************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * ( at your option ) any later version. *
+ * *
+ **************************************************************************/
+
+#include <qdialog.h>
+#include <qpe/config.h>
+#include <qlayout.h>
+#include <qpe/config.h>
+
+#include <qstring.h>
+#include <qhbox.h>
+#include <qvbox.h>
+#include <qlabel.h>
+#include <qlistview.h>
+#include <qlineedit.h>
+
+#include "ohighscoredlg.h"
+
+OHighscore::OHighscore( int score , int playerLevel )
+{
+ pLevel = playerLevel;
+ getList();
+ checkIfItIsANewhighscore( score );
+}
+
+OHighscore::~OHighscore()
+{
+ std::list<t_playerData*>::iterator deleteIterator = playerData.begin();
+ for ( ; deleteIterator != playerData.end() ; deleteIterator++ )
+ {
+ delete ( *deleteIterator );
+ }
+}
+
+void OHighscore::getList()
+{
+ Config cfg ( "tetrix" );
+ cfg.setGroup( QString::number( 1 ) );
+ lowest = cfg.readNumEntry( "Points" );
+ playerData.clear();
+
+ int rest = 1; //for the filling up later
+
+ for ( int i = 1 ; i < 11 ; i++ )
+ {
+ if ( cfg.hasGroup( QString::number( i ) ) )
+ {
+ cfg.setGroup( QString::number( i ) );
+ int temp = cfg.readNumEntry( "Points" );
+
+ t_playerData *pPlayerData = new t_playerData;
+ pPlayerData->sName = cfg.readEntry( "Name" );
+ pPlayerData->points = temp;
+ pPlayerData->level = cfg.readNumEntry( "Level" );
+
+ playerData.push_back( pPlayerData );
+
+ if ( (temp < lowest) ) lowest = temp;
+ rest++;
+ }
+ }
+
+ //now I fill up the rest of the list
+ if ( rest < 11 ) //only go in this loop if there are less than
+ //10 highscoreentries
+ {
+ lowest = 0;
+ for ( ; rest < 11 ; rest++ )
+ {
+ t_playerData *pPlayerData = new t_playerData;
+ pPlayerData->sName = tr( "empty");
+ pPlayerData->points = 0;
+ pPlayerData->level = 0;
+
+ playerData.push_back( pPlayerData );
+ }
+ }
+
+}
+
+void OHighscore::checkIfItIsANewhighscore( int points)
+{
+ if ( points > lowest )
+ isNewhighscore = true;
+ else
+ isNewhighscore = false;
+}
+
+void OHighscore::insertData( QString name , int punkte , int playerLevel )
+{
+ Config cfg ( "tetrix" );
+ int entryNumber = 1;
+ std::list<t_playerData*>::iterator insertIterator = playerData.begin();
+ while ( insertIterator != playerData.end() )
+ {
+ if ( punkte > ( *insertIterator )->points )
+ {
+ t_playerData* temp = new t_playerData;
+ temp->sName = name;
+ temp->points = punkte;
+ temp->level = playerLevel;
+ playerData.insert( insertIterator , temp );
+
+ //now we have to delete the last entry
+ insertIterator = playerData.end();
+ insertIterator--;
+//X delete *insertIterator; //memleak?
+ playerData.erase( insertIterator );
+
+ /////////////////////////////////////////
+ //this block just rewrites the highscore
+ insertIterator = playerData.begin();
+ while ( insertIterator != playerData.end() )
+ {
+ cfg.setGroup( QString::number( entryNumber ) );
+ cfg.writeEntry( "Name" , ( *insertIterator )->sName );
+ cfg.writeEntry( "Points" , ( *insertIterator )->points );
+ cfg.writeEntry( "Level" , ( *insertIterator )->level );
+ entryNumber++;
+ insertIterator++;
+ }
+ ////////////////////////////////////////
+
+ return;
+ }
+ insertIterator++;
+ }
+}
+
+QString OHighscore::getName()
+{
+ QString name;
+ QDialog *d = new QDialog ( this, 0, true );
+ d->setCaption( tr( "Enter your name!" ));
+ QLineEdit *ed = new QLineEdit ( d );
+ ( new QVBoxLayout ( d, 3, 3 ))->addWidget ( ed );
+ ed->setFocus ( );
+
+ if ( d->exec() == QDialog::Accepted ) {
+ name = ed->text();
+ }
+ //delete d;
+ return name;
+}
+
+OHighscoreDialog::OHighscoreDialog(OHighscore *highscore, QWidget *parent, const char *name, bool modal) : QDialog(parent, name, modal)
+{
+ hs_ = highscore;
+ setCaption( tr( "Highscores" ) );
+ vbox_layout = new QVBoxLayout( this, 4 , 4 );
+ list = new QListView( this );
+ list->setSorting( -1 );
+ list->addColumn( tr( "#" ));
+ list->addColumn( tr( "Name" ));
+ list->addColumn( tr( "Points" ));
+ list->addColumn( tr( "Level" ));
+
+ createHighscoreListView();
+
+ vbox_layout->addWidget( list );
+ showMaximized();
+}
+
+void OHighscoreDialog::createHighscoreListView()
+{
+ int pos = 10;
+ int points_ = 0;
+ int level_ = 0;
+
+ std::list<t_playerData*>::reverse_iterator iListe = hs_->playerData.rbegin();
+
+ for ( ; iListe != hs_->playerData.rend() ; ++iListe )
+ {
+ QListViewItem *item = new QListViewItem( list );
+ item->setText( 0 , QString::number( pos ) ); //number
+ item->setText( 1 , ( *iListe )->sName ); //name
+ if ( ( *iListe )->points == -1 )
+ points_ = 0;
+ else points_ = ( *iListe )->points;
+ if ( ( *iListe )->level == -1 )
+ level_ = 0;
+ else level_ = ( *iListe )->level;
+ item->setText( 2 , QString::number( points_ ) ); //points
+ item->setText( 3 , QString::number( level_ ) ); //level
+ pos--;
+ }
+}
+
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 @@
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * ( at your option ) any later version. *
+ * *
+ **************************************************************************/
+
+class QWidget;
+class QVBoxLayout;
+class QListView;
+
+#include <qdialog.h>
+#include <list>
+
+using namespace std;
+
+struct t_playerData
+{
+ QString sName;
+ int points;
+ int level;
+};
+
+class OHighscore : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ /*
+ *An OHighscore-Object contains all Points, level and playernames sorted in a stl::vector
+ */
+ OHighscore( int , int );
+
+ ~OHighscore();
+
+ /*
+ * is true if the player did a new highscore
+ */
+ bool isNewhighscore;
+
+ /*
+ * this inserts the new entry at the correct position
+ */
+ void insertData( QString , int , int );
+
+ list<t_playerData*> playerData;
+
+ /*
+ * As Qt/e does not support QInputDialog I did that code myself
+ */
+ QString getName();
+ private:
+
+ list<t_playerData*>::iterator iPlayerData;
+
+ /*
+ * the lowest score in the highscorelist
+ */
+ int lowest;
+
+ /*
+ * the level of the highscore
+ */
+ int pLevel;
+
+ /*
+ * get all scores in a vector and give "lowest" a value
+ */
+ void getList();
+
+ /*
+ * sets the bool if the current score is in the top10
+ */
+ void checkIfItIsANewhighscore( int );
+};
+
+class OHighscoreDialog : public QDialog
+{
+ Q_OBJECT
+
+ public:
+ OHighscoreDialog(OHighscore *highscore, QWidget *parent, const char *name = 0, bool modal = true );
+
+ private:
+ OHighscore *hs_;
+
+ QVBoxLayout *vbox_layout;
+
+ /*
+ * this method creates the QListView with all data
+ */
+ void createHighscoreListView();
+
+ QListView *list;
+};
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
@@ -13,30 +13,33 @@
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "qtetrix.h"
#include <qpe/resource.h>
+#include <qpe/config.h>
#include <qapplication.h>
#include <qlabel.h>
#include <qdatetime.h>
#include <qlayout.h>
+#include <qstring.h>
+#include "ohighscoredlg.h"
void drawTetrixButton( QPainter *p, int x, int y, int w, int h,
const QColor *color )
{
QColor fc;
if ( color ) {
QPointArray a;
a.setPoints( 3, x,y+h-1, x,y, x+w-1,y );
p->setPen( color->light() );
p->drawPolyline( a );
a.setPoints( 3, x+1,y+h-1, x+w-1,y+h-1, x+w-1,y+1 );
@@ -152,19 +155,23 @@ QTetrix::QTetrix( QWidget *parent, const char *name, WFlags f )
connect( board, SIGNAL(updateRemovedSignal(int)), showLines,
SLOT(setNum(int)));
showScore->setNum( 0 );
showLevel->setNum( 0 );
showLines->setNum( 0 );
board->revealNextPiece(TRUE);
board->setFocusPolicy( StrongFocus );
}
void QTetrix::gameOver()
{
+ OHighscore *hs = new OHighscore( showScore->text().toInt() , showLevel->text().toInt() );
+ if ( hs->isNewhighscore )
+ hs->insertData( hs->getName(), showScore->text().toInt() , showLevel->text().toInt() );
+ OHighscoreDialog hscdlg( hs, this, "OHighscoreDialog", true );
+ hscdlg.exec();
}
-
void QTetrix::quit()
{
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
@@ -8,26 +8,24 @@
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
-
-
#ifndef QTETRIX_H
#define QTETRIX_H
#include "qtetrixb.h"
#include <qframe.h>
#include <qlcdnumber.h>
#include <qpushbutton.h>
#include <qpainter.h>
#include <qmainwindow.h>
class QLabel;
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,24 +1,26 @@
TEMPLATE = app
CONFIG = qt warn_on release
DESTDIR = $(OPIEDIR)/bin
HEADERS = gtetrix.h \
qtetrix.h \
qtetrixb.h \
- tpiece.h
+ tpiece.h \
+ ohighscoredlg.h
SOURCES = main.cpp \
gtetrix.cpp \
qtetrix.cpp \
qtetrixb.cpp \
- tpiece.cpp
+ tpiece.cpp \
+ ohighscoredlg.cpp
INCLUDEPATH += $(OPIEDIR)/include
DEPENDPATH += $(OPIEDIR)/include
LIBS += -lqpe
INTERFACES =
TARGET = tetrix
TRANSLATIONS = ../../../i18n/de/tetrix.ts \
../../../i18n/da/tetrix.ts \
../../../i18n/xx/tetrix.ts \
../../../i18n/en/tetrix.ts \
../../../i18n/es/tetrix.ts \
../../../i18n/fr/tetrix.ts \