summaryrefslogtreecommitdiff
path: root/noncore
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 /noncore
parentdfe0e1302aa2a366cfa2a8b53102a38b7143ba4b (diff)
downloadopie-917fb7d2dca76f5c2c5c86553be0fcc2832c3435.zip
opie-917fb7d2dca76f5c2c5c86553be0fcc2832c3435.tar.gz
opie-917fb7d2dca76f5c2c5c86553be0fcc2832c3435.tar.bz2
merging with the branch.
Comments?
Diffstat (limited to 'noncore') (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
@@ -1,78 +1,81 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** 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.
**
**********************************************************************/
#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 );
p->setPen( color->dark() );
p->drawPolyline( a );
x++;
y++;
w -= 2;
h -= 2;
fc = *color;
}
else
fc = p->backgroundColor();
p->fillRect( x, y, w, h, fc );
}
ShowNextPiece::ShowNextPiece( QWidget *parent, const char *name )
: QFrame( parent, name )
{
setFrameStyle( QFrame::Panel | QFrame::Sunken );
xOffset = -1; // -1 until first resizeEvent.
}
void ShowNextPiece::resizeEvent( QResizeEvent *e )
{
QSize sz = e->size();
blockWidth = (sz.width() - 3)/5;
blockHeight = (sz.height() - 3)/6;
xOffset = (sz.width() - 3)/5;
yOffset = (sz.height() - 3)/6;
}
void ShowNextPiece::paintEvent( QPaintEvent * )
{
QPainter p( this );
drawFrame( &p );
p.end(); // explicit end() so any slots can paint too
@@ -116,55 +119,59 @@ QTetrix::QTetrix( QWidget *parent, const char *name, WFlags f )
gl->addWidget( showNext, 0, 1 );
l = new QLabel( tr("Score"), gameArea );
gl->addWidget( l, 1, 0 );
showScore = new QLabel(gameArea);
gl->addWidget( showScore, 1, 1 );
l = new QLabel( tr("Level"), gameArea );
gl->addWidget( l, 2, 0 );
showLevel = new QLabel(gameArea);
gl->addWidget( showLevel, 2, 1 );
l = new QLabel( tr("Removed"), gameArea );
gl->addWidget( l, 3, 0 );
showLines = new QLabel(gameArea);
gl->addWidget( showLines, 3, 1 );
board = new QTetrixBoard(gameArea);
board->setBackgroundColor(QColor(0,0,0));
board->setFixedWidth( 124 );
gl->addMultiCellWidget( board, 0, 4, 2, 2 );
gl->addColSpacing( 2, 100 );
gl->addColSpacing( 1, 35 );
gl->addRowSpacing( 0, 35 );
QPushButton *pb = new QPushButton( tr("Start"), gameArea );
pb->setFocusPolicy( NoFocus );
connect( pb, SIGNAL( clicked() ), board, SLOT( start() ) );
gl->addMultiCellWidget( pb, 4, 4, 0, 1 );
connect( board, SIGNAL(gameOverSignal()), SLOT(gameOver()) );
connect( board, SIGNAL(drawNextSquareSignal(int,int,QColor*)), showNext,
SLOT(drawNextSquare(int,int,QColor*)) );
connect( showNext, SIGNAL(update()), board, SLOT(updateNext()) );
connect( board, SIGNAL(updateScoreSignal(int)), showScore,
SLOT(setNum(int)) );
connect( board, SIGNAL(updateLevelSignal(int)), showLevel,
SLOT(setNum(int)));
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
@@ -1,69 +1,67 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** 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;
class ShowNextPiece : public QFrame
{
Q_OBJECT
friend class QTetrix;
public:
ShowNextPiece( QWidget *parent=0, const char *name=0 );
public slots:
void drawNextSquare( int x, int y,QColor *color );
signals:
void update();
private:
void paintEvent( QPaintEvent * );
void resizeEvent( QResizeEvent * );
int blockWidth,blockHeight;
int xOffset,yOffset;
};
class QTetrix : public QMainWindow
{
Q_OBJECT
public:
QTetrix( QWidget *parent=0, const char *name=0, WFlags f=0 );
void startGame() { board->startGame(); }
public slots:
void gameOver();
void quit();
private:
void keyPressEvent( QKeyEvent *e ) { board->keyPressEvent(e); }
QTetrixBoard *board;
ShowNextPiece *showNext;
QLabel *showScore;
QLabel *showLevel;
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,39 +1,41 @@
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 \
../../../i18n/hu/tetrix.ts \
../../../i18n/ja/tetrix.ts \
../../../i18n/ko/tetrix.ts \
../../../i18n/no/tetrix.ts \
../../../i18n/pl/tetrix.ts \
../../../i18n/pt/tetrix.ts \
../../../i18n/pt_BR/tetrix.ts \
../../../i18n/sl/tetrix.ts \
../../../i18n/zh_CN/tetrix.ts \
../../../i18n/it/tetrix.ts \
../../../i18n/zh_TW/tetrix.ts
include ( $(OPIEDIR)/include.pro )