-rw-r--r-- | noncore/games/backgammon/aidialog.cpp | 3 | ||||
-rw-r--r-- | noncore/games/backgammon/filedialog.cpp | 3 | ||||
-rw-r--r-- | noncore/games/backgammon/playerdialog.cpp | 4 | ||||
-rw-r--r-- | noncore/games/backgammon/rulesdialog.cpp | 4 | ||||
-rw-r--r-- | noncore/games/backgammon/themedialog.cpp | 2 | ||||
-rw-r--r-- | noncore/games/sfcave/helpwindow.cpp | 4 | ||||
-rw-r--r-- | noncore/games/tetrix/ohighscoredlg.cpp | 3 | ||||
-rw-r--r-- | noncore/games/tictac/tictac.cpp | 4 |
8 files changed, 18 insertions, 9 deletions
diff --git a/noncore/games/backgammon/aidialog.cpp b/noncore/games/backgammon/aidialog.cpp index 7dfe403..32e9b52 100644 --- a/noncore/games/backgammon/aidialog.cpp +++ b/noncore/games/backgammon/aidialog.cpp @@ -1,211 +1,212 @@ #include "aidialog.h" #include <qgroupbox.h> +#include <qpe/qpeapplication.h> AI_Dialog::AI_Dialog(QWidget* parent,const char* name,bool modal,WFlags f) : QDialog(parent,name,modal,f) { setCaption("AI Configuration"); QGroupBox* settings=new QGroupBox(tr( "Settings" ),this); settings->setGeometry(10,5,220,170); QLabel* rescue_label=new QLabel(tr( "<b>Rescue</b>" ),settings); rescue_label->setGeometry(50,20,50,20); rescue=new QSpinBox(0,6,1,settings); rescue->setGeometry(100,20,40,20); QPushButton* rescuehelp=new QPushButton(tr( "?" ),settings); rescuehelp->setGeometry(140,20,20,20); connect(rescuehelp,SIGNAL(pressed()),this,SLOT(rescuehelp_pressed())); connect(rescuehelp,SIGNAL(released()),this,SLOT(rescuehelp_released())); QLabel* eliminate_label=new QLabel(tr( "<b>Eliminate</b>" ),settings); eliminate_label->setGeometry(50,40,50,20); eliminate=new QSpinBox(0,6,1,settings); eliminate->setGeometry(100,40,40,20); QPushButton* eliminatehelp=new QPushButton(tr( "?" ),settings); eliminatehelp->setGeometry(140,40,20,20); connect(eliminatehelp,SIGNAL(pressed()),this,SLOT(eliminatehelp_pressed())); connect(eliminatehelp,SIGNAL(released()),this,SLOT(eliminatehelp_released())); QLabel* expose_label=new QLabel(tr( "<b>Expose</b>" ),settings); expose_label->setGeometry(50,60,50,20); expose=new QSpinBox(0,6,1,settings); expose->setGeometry(100,60,40,20); QPushButton* exposeehelp=new QPushButton(tr( "?" ),settings); exposeehelp->setGeometry(140,60,20,20); connect(exposeehelp,SIGNAL(pressed()),this,SLOT(exposehelp_pressed())); connect(exposeehelp,SIGNAL(released()),this,SLOT(exposehelp_released())); QLabel* protect_label=new QLabel(tr( "<b>Protect</b>" ),settings); protect_label->setGeometry(50,80,50,20); protect=new QSpinBox(0,6,1,settings); protect->setGeometry(100,80,40,20); QPushButton* protecthelp=new QPushButton(tr( "?" ),settings); protecthelp->setGeometry(140,80,20,20); connect(protecthelp,SIGNAL(pressed()),this,SLOT(protecthelp_pressed())); connect(protecthelp,SIGNAL(released()),this,SLOT(protecthelp_released())); QLabel* safe_label=new QLabel(tr( "<b>Safe</b>" ),settings); safe_label->setGeometry(50,100,50,20); safe=new QSpinBox(0,6,1,settings); safe->setGeometry(100,100,40,20); QPushButton* safeehelp=new QPushButton(tr( "?" ),settings); safeehelp->setGeometry(140,100,20,20); connect(safeehelp,SIGNAL(pressed()),this,SLOT(safehelp_pressed())); connect(safeehelp,SIGNAL(released()),this,SLOT(safehelp_released())); QLabel* empty_label=new QLabel(tr( "<b>Empty</b>" ),settings); empty_label->setGeometry(50,120,50,20); empty=new QSpinBox(0,6,1,settings); empty->setGeometry(100,120,40,20); QPushButton* emptyhelp=new QPushButton(tr( "?" ),settings); emptyhelp->setGeometry(140,120,20,20); connect(emptyhelp,SIGNAL(pressed()),this,SLOT(emptyhelp_pressed())); connect(emptyhelp,SIGNAL(released()),this,SLOT(emptyhelp_released())); defaultvalues=new QPushButton(tr( "Default Values" ),settings); defaultvalues->setGeometry(60,140,90,20); connect(defaultvalues,SIGNAL(clicked()),this,SLOT(setDefaultValues())); QGroupBox* helpbox=new QGroupBox(tr( "Help" ),this); helpbox->setGeometry(10,185,220,90); help=new QLabel(helpbox); help->setGeometry(10,15,200,65); setHelpText(); - showMaximized(); + QPEApplication::showDialog( this ); } AI_Dialog::~AI_Dialog() { } void AI_Dialog::rescuehelp_pressed() { setHelpText("rescue"); } void AI_Dialog::rescuehelp_released() { setHelpText(); } void AI_Dialog::eliminatehelp_pressed() { setHelpText("eliminate"); } void AI_Dialog::eliminatehelp_released() { setHelpText(); } void AI_Dialog::exposehelp_pressed() { setHelpText("expose"); } void AI_Dialog::exposehelp_released() { setHelpText(); } void AI_Dialog::protecthelp_pressed() { setHelpText("protect"); } void AI_Dialog::protecthelp_released() { setHelpText(); } void AI_Dialog::safehelp_pressed() { setHelpText("safe"); } void AI_Dialog::safehelp_released() { setHelpText(); } void AI_Dialog::emptyhelp_pressed() { setHelpText("empty"); } void AI_Dialog::emptyhelp_released() { setHelpText(); } void AI_Dialog::setDefaultValues() { rescue->setValue(6); eliminate->setValue(4); expose->setValue(1); protect->setValue(5); safe->setValue(3); empty->setValue(2); } void AI_Dialog::setAISettings(const AISettings& values) { rescue->setValue(values.rescue); eliminate->setValue(values.eliminate); expose->setValue(values.expose); protect->setValue(values.protect); safe->setValue(values.safe); empty->setValue(values.empty); } AISettings AI_Dialog::getAISettings() { AISettings ai; ai.rescue=rescue->value(); ai.eliminate=eliminate->value(); ai.expose=expose->value(); ai.protect=protect->value(); ai.safe= safe->value(); ai.empty=empty->value(); return ai; } void AI_Dialog::setHelpText(const QString& type) { if(type=="rescue") { help->setText(tr( "Bring the pieces out of the endzone" )); } else if(type=="eliminate") { help->setText(tr( "Eliminate an opponents piece" )); } else if(type=="expose") { help->setText(tr( "Expose you own pieces.\nAfter such a move only one piece will remain in the slot") ); } else if(type=="protect") { help->setText(tr( "Protect a single piece by\nputting another one in this slot" )); } else if(type=="safe") { help->setText(tr( "Move piece to a slot already\noccupied by the player" )); } else if(type=="empty") { help->setText(tr( "Move piece to an empty slot") ); } else { help->setText(tr( "Press and hold the ? buttton\nnext to a field for help") ); } } diff --git a/noncore/games/backgammon/filedialog.cpp b/noncore/games/backgammon/filedialog.cpp index 6c858a2..a5e71c9 100644 --- a/noncore/games/backgammon/filedialog.cpp +++ b/noncore/games/backgammon/filedialog.cpp @@ -1,64 +1,65 @@ #include "filedialog.h" #include <qdir.h> #include <qfileinfo.h> #include <qmessagebox.h> #include <qpixmap.h> #include <qpushbutton.h> #include <qpe/qpeapplication.h> FileDialog::FileDialog(QWidget* parent,QString header,QString extension,const char* name,bool modal,WFlags f) :QDialog(parent,name,modal,f) { setCaption(header); ext=extension; dirselector=new QListView(this); dirselector->setGeometry(1,10,235,200); dirselector->addColumn("Files"); connect(dirselector,SIGNAL(clicked(QListViewItem*)),this,SLOT(selectorclicked(QListViewItem*))); getCurrentDir(); file_name="user"; fileinput=new QLineEdit(file_name,this); fileinput->setGeometry(1,220,235,20); - showMaximized(); +
+ QPEApplication::showDialog( this );
} FileDialog::~FileDialog() {} void FileDialog::selectorclicked(QListViewItem* entry) { if(entry==NULL) return; file_name=entry->text(0); fileinput->setText(file_name); } void FileDialog::getCurrentDir() { dirselector->clear(); QDir dir(QPEApplication::qpeDir()+"/backgammon"); dir.setFilter(QDir::Files); QFileInfoListIterator it(*(dir.entryInfoList())); QFileInfo* fi; int ext_length=ext.length(); while((fi=it.current())) // go through all file and subdirs { QString file=fi->fileName(); if(file.right(ext_length)==ext && file) { file=file.left(file.length()-ext_length); new QListViewItem(dirselector,file); } ++it; } } QString FileDialog::filename() { return file_name; } diff --git a/noncore/games/backgammon/playerdialog.cpp b/noncore/games/backgammon/playerdialog.cpp index c16f202..0faf7e2 100644 --- a/noncore/games/backgammon/playerdialog.cpp +++ b/noncore/games/backgammon/playerdialog.cpp @@ -1,114 +1,116 @@ #include "playerdialog.h" #include <qgroupbox.h> +#include <qpe/qpeapplication.h> + PlayerDialog::PlayerDialog(QWidget* parent,const char* name,bool modal,WFlags f) :QDialog(parent,name,modal,f) { auto2=false; auto2=true; setCaption("Player Settings"); QGroupBox* player1_box=new QGroupBox("Player 1",this); player1_box->setGeometry(10,30,220,60); manual_button1=new QRadioButton("Human",player1_box); connect(manual_button1,SIGNAL(clicked()),this,SLOT(button_manual1())); manual_button1->setGeometry(10,20,100,20); auto_button1=new QRadioButton("Computer",player1_box); connect(auto_button1,SIGNAL(clicked()),this,SLOT(button_auto1())); auto_button1->setGeometry(110,20,100,20); button1_state(auto1); QGroupBox* player2_box=new QGroupBox("Player 2",this); player2_box->setGeometry(10,150,220,60); manual_button2=new QRadioButton("Human",player2_box); connect(manual_button2,SIGNAL(clicked()),this,SLOT(button_manual2())); manual_button2->setGeometry(10,20,100,20); auto_button2=new QRadioButton("Computer",player2_box); connect(auto_button2,SIGNAL(clicked()),this,SLOT(button_auto2())); auto_button2->setGeometry(110,20,100,20); button2_state(auto2); - showMaximized(); + QPEApplication::showDialog( this ); } PlayerDialog::~PlayerDialog() {} void PlayerDialog::button_manual1() { auto1=false; button1_state(auto1); } void PlayerDialog::button_auto1() { auto1=true; button1_state(auto1); } void PlayerDialog::button_manual2() { auto2=false; button2_state(auto2); } void PlayerDialog::button_auto2() { auto2=true; button2_state(auto2); } void PlayerDialog::button1_state(bool computer) { if(computer) { manual_button1->setChecked(false); auto_button1->setChecked(true); } else { manual_button1->setChecked(true); auto_button1->setChecked(false); } } void PlayerDialog::button2_state(bool computer) { if(computer) { manual_button2->setChecked(false); auto_button2->setChecked(true); } else { manual_button2->setChecked(true); auto_button2->setChecked(false); } } void PlayerDialog::setAuto1(bool newstate) { auto1=newstate; button1_state(auto1); } bool PlayerDialog::getAuto1() { return auto1; } void PlayerDialog::setAuto2(bool newstate) { auto2=newstate; button2_state(auto2); } bool PlayerDialog::getAuto2() { return auto2; } diff --git a/noncore/games/backgammon/rulesdialog.cpp b/noncore/games/backgammon/rulesdialog.cpp index 85c3db3..5e17eeb 100644 --- a/noncore/games/backgammon/rulesdialog.cpp +++ b/noncore/games/backgammon/rulesdialog.cpp @@ -1,77 +1,79 @@ #include "rulesdialog.h" #include <qgroupbox.h> #include <qlabel.h> +#include <qpe/qpeapplication.h> + RulesDialog::RulesDialog(QWidget* parent,const char* name,bool modal,WFlags f) : QDialog(parent,name,modal,f) { setCaption("Rules Configuration"); QLabel* header=new QLabel("<b>Change the game rules here</b>",this); header->setGeometry(10,10,200,20); // QGroupBox* pieces_out_box=new QGroupBox("Movement",this); pieces_out_box->setGeometry(10,10,220,120); pieces_out=new QCheckBox("Don't care about others",pieces_out_box); pieces_out->setGeometry(10,20,200,20); connect(pieces_out,SIGNAL(clicked()),this,SLOT(pieces_out_clicked())); QLabel* pieces_out_help=new QLabel("allow movement of the pieses\neven if there are pieces knocked\nout by the opponent",pieces_out_box); pieces_out_help->setGeometry(10,40,200,60); // QGroupBox* nice_dice_box=new QGroupBox("Dice",this); nice_dice_box->setGeometry(10,140,220,120); nice_dice=new QCheckBox("Big dice for small numbers",nice_dice_box); nice_dice->setGeometry(10,20,200,20); connect(nice_dice,SIGNAL(clicked()),this,SLOT(nice_dice_clicked())); QLabel* nice_dice_help=new QLabel("allow to rescue pieces with dice\nvalues graeter than the distance\nto the players endzone.",nice_dice_box); nice_dice_help->setGeometry(10,40,200,60); - showMaximized(); + QPEApplication::showDialog( this ); } RulesDialog::~RulesDialog() { } void RulesDialog::pieces_out_clicked() { if(pieces_out->isChecked()) rules.move_with_pieces_out=true; else rules.move_with_pieces_out=false; } void RulesDialog::nice_dice_clicked() { if(nice_dice->isChecked()) rules.generous_dice=true; else rules.generous_dice=false; } void RulesDialog::setRules(const Rules& new_rules) { rules=new_rules; if(rules.move_with_pieces_out) pieces_out->setChecked(true); else pieces_out->setChecked(false); if(rules.generous_dice) nice_dice->setChecked(true); else nice_dice->setChecked(false); } Rules RulesDialog::getRules() { return rules; } diff --git a/noncore/games/backgammon/themedialog.cpp b/noncore/games/backgammon/themedialog.cpp index dcb957c..f342381 100644 --- a/noncore/games/backgammon/themedialog.cpp +++ b/noncore/games/backgammon/themedialog.cpp @@ -1,163 +1,163 @@ #include "themedialog.h" #include <qdir.h> #include <qfileinfo.h> #include <qlabel.h> #include <qpushbutton.h> #include <qpe/qpeapplication.h> ThemeDialog::ThemeDialog(QWidget* parent,const char* name,bool modal,WFlags f) :QDialog(parent,name,modal,f) { setCaption("Theme Dialog"); QLabel* labelname=new QLabel("name",this); labelname->setGeometry(0,5,40,20); lineName=new QLineEdit("user",this); lineName->setGeometry(40,5,195,20); QLabel* labelboard=new QLabel("board",this); labelboard->setGeometry(0,30,40,20); boxboard=new QComboBox(this,""); boxboard->setGeometry(40,30,195,20); fillBox("boards",boxboard); QLabel* labelpiecesA=new QLabel("pieces1",this); labelpiecesA->setGeometry(0,70,40,20); boxpiecesA=new QComboBox(this); boxpiecesA->setGeometry(40,70,195,20); fillBox("pieces",boxpiecesA); QLabel* labelpiecesB=new QLabel("pieces2",this); labelpiecesB->setGeometry(0,95,40,20); boxpiecesB=new QComboBox(this); boxpiecesB->setGeometry(40,95,195,20); fillBox("pieces",boxpiecesB); QLabel* labeldiceA=new QLabel("dice1",this); labeldiceA->setGeometry(0,135,40,20); boxdiceA=new QComboBox(this); boxdiceA->setGeometry(40,135,195,20); fillBox("dice",boxdiceA); QLabel* labeldiceB=new QLabel("dice2",this); labeldiceB->setGeometry(0,160,40,20); boxdiceB=new QComboBox(this); boxdiceB->setGeometry(40,160,195,20); fillBox("dice",boxdiceB); QLabel* labelodds=new QLabel("odds",this); labelodds->setGeometry(0,200,40,20); boxodds=new QComboBox(this); boxodds->setGeometry(40,200,195,20); fillBox("odds",boxodds); boxodds->setEnabled(false); QLabel* labeltable=new QLabel("table",this); labeltable->setGeometry(0,225,40,20); boxtable=new QComboBox(this); boxtable->setGeometry(40,225,195,20); fillBox("table",boxtable); - showMaximized(); + QPEApplication::showDialog( this ); } ThemeDialog::~ThemeDialog() {} ImageNames ThemeDialog::getNames() { ImageNames names; names.theme=lineName->text(); names.board=boxboard->currentText(); names.pieces1=boxpiecesA->currentText(); names.pieces2=boxpiecesB->currentText(); names.dice1=boxdiceA->currentText(); names.dice2=boxdiceB->currentText(); names.odds=boxodds->currentText(); names.table=boxtable->currentText(); return names; } void ThemeDialog::setCurrent(const ImageNames& current) { int a=0; lineName->setText(current.theme); for(a=0;a<boxboard->count();a++) { if(boxboard->text(a)==current.board) { boxboard->setCurrentItem(a); break; } } for(a=0;a<boxpiecesA->count();a++) { if(boxpiecesA->text(a)==current.pieces1) { boxpiecesA->setCurrentItem(a); break; } } for(a=0;a<boxpiecesB->count();a++) { if(boxpiecesB->text(a)==current.pieces2) { boxpiecesB->setCurrentItem(a); break; } } for(a=0;a<boxdiceA->count();a++) { if(boxdiceA->text(a)==current.dice1) { boxdiceA->setCurrentItem(a); break; } } for(a=0;a<boxdiceB->count();a++) { if(boxdiceB->text(a)==current.dice2) { boxdiceB->setCurrentItem(a); break; } } for(a=0;a<boxodds->count();a++) { if(boxodds->text(a)==current.odds) { boxodds->setCurrentItem(a); break; } } for(a=0;a<boxtable->count();a++) { if(boxtable->text(a)==current.table) { boxtable->setCurrentItem(a); break; } } } void ThemeDialog::fillBox(QString dirname,QComboBox* thebox) { thebox->clear(); QDir dir(QPEApplication::qpeDir()+"/pics/backgammon/"+dirname); dir.setFilter(QDir::Dirs | QDir::Files); QFileInfoListIterator it(*(dir.entryInfoList())); QFileInfo* fi; while((fi=it.current())) // go through all file and subdirs { QString file=fi->fileName(); if(file.right(4)==".png") { thebox->insertItem(file.left(file.find(".png"))); } ++it; } delete fi; } diff --git a/noncore/games/sfcave/helpwindow.cpp b/noncore/games/sfcave/helpwindow.cpp index c920312..544e237 100644 --- a/noncore/games/sfcave/helpwindow.cpp +++ b/noncore/games/sfcave/helpwindow.cpp @@ -1,79 +1,81 @@ /*************************************************************************** helpwindow.cpp - description ------------------- begin : Sun Sep 8 2002 copyright : (C) 2002 by Andy Qua email : andy.qua@blueyonder.co.uk ***************************************************************************/ /*************************************************************************** * * * 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 <qwidget.h> #include <qlayout.h> #include <qstring.h> #include <qtextview.h> +#include <qpe/qpeapplication.h> + #include "helpwindow.h" #define HELP_TEXT \ "<qt><h1>SFCave Help</h1><p> " \ "SFCave is a flying game for the Zaurus.<br><br> " \ "The aim is to stay alive for as long as possible and get the highest score " \ "you can.<br><br>" \ "There are three game types currently - SFCave, Gates, and Fly.<br>" \ "<b>SFCave</b> is a remake of the classic SFCave game - fly through the " \ "cavern avoiding all the blocks that just happen to be hanging in " \ "midair<br><br>" \ "<b>Gates</b> is similar to SFCave but instead you must fly through the " \ "without crashing.<br><br>" \ "<b>Fly</b> is somewhat different to SFCave and above. Instead, you have " \ "are flying in the open air above a scrolling landscape, and the aim is to " \ "hug the ground - the closer to the land you fly the more points " \ "scored.<br><br><br>" \ "Basic instruction - Press <b>Up</B> or <b>Down</b> on the circle pad to " \ "start a new game, press the middle of the pad to apply thrust (makes you " \ "go up), and release the pad to remove thrust and drop down.<br><br>" \ "Also, if playing the Fly game, you can press z to toggle the display " \ "of the scoring zones. This will display 4 red lines at varying heights " \ "above the landscape - if your ship falls into this zone, point are scored. " \ "The closer to the landscape you get the more points you get.<br><br>" \ "In addition, SFCave has replays - save and load too so you can show off to all " \ "your friends (or vice versa). Currently, this is in its infancy but will improve.<br>" \ "To use, once you have crashed, press 'r' to replay the last game.<br>" \ "To save the replay press 's'.<br>" \ "To load a saved replay press 'l' (after you've crashed at least once).<br><br>" \ "Replays are currently saved to your home directory in a file called sfcave.replay." \ "This file can be copied and given to others as long as it it put in their home directory.<br><br>" \ "Have lots of fun.<br>" \ "Andy" \ "</p></qt>" HelpWindow::HelpWindow( QWidget *parent, const char *name, bool modal, WFlags flags ) : QDialog( parent, name, modal, flags ) { // resize( 230, 280 ); setCaption( "Help for SFCave" ); QVBoxLayout *layout = new QVBoxLayout( this ); QString text = HELP_TEXT;; QTextView *view = new QTextView( text, 0, this, "view" ); layout->insertSpacing( -1, 5 ); layout->insertWidget( -1, view ); layout->insertSpacing( -1, 5 ); - showMaximized(); + QPEApplication::showDialog( this ); } HelpWindow::~HelpWindow() { } diff --git a/noncore/games/tetrix/ohighscoredlg.cpp b/noncore/games/tetrix/ohighscoredlg.cpp index cf0dcf7..7581f51 100644 --- a/noncore/games/tetrix/ohighscoredlg.cpp +++ b/noncore/games/tetrix/ohighscoredlg.cpp @@ -1,199 +1,200 @@ /*************************************************************************** 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 <qpe/qpeapplication.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(); + QPEApplication::showDialog( this ); } 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/tictac/tictac.cpp b/noncore/games/tictac/tictac.cpp index 4954ba4..9de3b58 100644 --- a/noncore/games/tictac/tictac.cpp +++ b/noncore/games/tictac/tictac.cpp @@ -1,382 +1,382 @@ /**************************************************************************** ** tictac.cpp,v 1.3.8.1 2003/08/29 06:50:40 harlekin Exp ** ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. ** ** This file is part of an example program for Qt. This example ** program may be used, distributed and modified without limitation. ** *****************************************************************************/ #include "tictac.h" #include <qpe/qpeapplication.h> #include <qpainter.h> #include <qdrawutil.h> #include <qcombobox.h> #include <qcheckbox.h> #include <qlabel.h> #include <qlayout.h> #include <stdlib.h> // rand() function #include <qdatetime.h> // seed for rand() #include <qstringlist.h> //needed for proper internationalization //*************************************************************************** //* TicTacButton member functions //*************************************************************************** // -------------------------------------------------------------------------- // Creates a TicTacButton // TicTacButton::TicTacButton( QWidget *parent ) : QPushButton( parent ) { t = Blank; // initial type } // -------------------------------------------------------------------------- // Paints TicTacButton // void TicTacButton::drawButtonLabel( QPainter *p ) { QRect r = rect(); p->setPen( QPen( white,2 ) ); // set fat pen if ( t == Circle ) { p->drawEllipse( r.left()+4, r.top()+4, r.width()-8, r.height()-8 ); } else if ( t == Cross ) { // draw cross p->drawLine( r.topLeft() +QPoint(4,4), r.bottomRight()-QPoint(4,4)); p->drawLine( r.bottomLeft()+QPoint(4,-4),r.topRight() -QPoint(4,-4)); } } //*************************************************************************** //* TicTacGameBoard member functions //*************************************************************************** // -------------------------------------------------------------------------- // Creates a game board with N x N buttons and connects the "clicked()" // signal of all buttons to the "buttonClicked()" slot. // TicTacGameBoard::TicTacGameBoard( int n, QWidget *parent, const char *name ) : QWidget( parent, name ) { - showMaximized(); + QPEApplication::showWidget( this ); st = Init; // initial state nBoard = n; n *= n; // make square comp_starts = FALSE; // human starts buttons = new TicTacButtons(n); // create real buttons btArray = new TicTacArray(n); // create button model QGridLayout * grid = new QGridLayout( this, 3, 3, 4 ); QPalette p( blue ); for ( int i=0; i<n; i++ ) { // create and connect buttons TicTacButton *ttb = new TicTacButton( this ); ttb->setPalette( p ); ttb->setEnabled( FALSE ); connect( ttb, SIGNAL(clicked()), SLOT(buttonClicked()) ); grid->addWidget( ttb, i%3, i/3 ); buttons->insert( i, ttb ); btArray->at(i) = TicTacButton::Blank; // initial button type } QTime t = QTime::currentTime(); // set random seed srand( t.hour()*12+t.minute()*60+t.second()*60 ); } TicTacGameBoard::~TicTacGameBoard() { delete buttons; delete btArray; } // -------------------------------------------------------------------------- // TicTacGameBoard::computerStarts( bool v ) // // Computer starts if v=TRUE. The human starts by default. // void TicTacGameBoard::computerStarts( bool v ) { comp_starts = v; } // -------------------------------------------------------------------------- // TicTacGameBoard::newGame() // // Clears the game board and prepares for a new game // void TicTacGameBoard::newGame() { st = HumansTurn; for ( int i=0; i<nBoard*nBoard; i++ ) btArray->at(i) = TicTacButton::Blank; if ( comp_starts ) computerMove(); else updateButtons(); } // -------------------------------------------------------------------------- // TicTacGameBoard::buttonClicked() - SLOT // // This slot is activated when a TicTacButton emits the signal "clicked()", // i.e. the user has clicked on a TicTacButton. // void TicTacGameBoard::buttonClicked() { if ( st != HumansTurn ) // not ready return; int i = buttons->findRef( (TicTacButton*)sender() ); TicTacButton *b = buttons->at(i); // get piece that was pressed if ( b->type() == TicTacButton::Blank ) { // empty piece? btArray->at(i) = TicTacButton::Circle; updateButtons(); if ( checkBoard( btArray ) == 0 ) // not a winning move? computerMove(); int s = checkBoard( btArray ); if ( s ) { // any winners yet? st = s == TicTacButton::Circle ? HumanWon : ComputerWon; emit finished(); } } } // -------------------------------------------------------------------------- // TicTacGameBoard::updateButtons() // // Updates all buttons that have changed state // void TicTacGameBoard::updateButtons() { for ( int i=0; i<nBoard*nBoard; i++ ) { if ( buttons->at(i)->type() != btArray->at(i) ) buttons->at(i)->setType( (TicTacButton::Type)btArray->at(i) ); buttons->at(i)->setEnabled( buttons->at(i)->type() == TicTacButton::Blank ); } } // -------------------------------------------------------------------------- // TicTacGameBoard::checkBoard() // // Checks if one of the players won the game, works for any board size. // // Returns: // - TicTacButton::Cross if the player with X buttons won // - TicTacButton::Circle if the player with O buttons won // - Zero (0) if there is no winner yet // int TicTacGameBoard::checkBoard( TicTacArray *a ) { int t = 0; int row, col; bool won = FALSE; for ( row=0; row<nBoard && !won; row++ ) { // check horizontal t = a->at(row*nBoard); if ( t == TicTacButton::Blank ) continue; col = 1; while ( col<nBoard && a->at(row*nBoard+col) == t ) col++; if ( col == nBoard ) won = TRUE; } for ( col=0; col<nBoard && !won; col++ ) { // check vertical t = a->at(col); if ( t == TicTacButton::Blank ) continue; row = 1; while ( row<nBoard && a->at(row*nBoard+col) == t ) row++; if ( row == nBoard ) won = TRUE; } if ( !won ) { // check diagonal top left t = a->at(0); // to bottom right if ( t != TicTacButton::Blank ) { int i = 1; while ( i<nBoard && a->at(i*nBoard+i) == t ) i++; if ( i == nBoard ) won = TRUE; } } if ( !won ) { // check diagonal bottom left int j = nBoard-1; // to top right int i = 0; t = a->at(i+j*nBoard); if ( t != TicTacButton::Blank ) { i++; j--; while ( i<nBoard && a->at(i+j*nBoard) == t ) { i++; j--; } if ( i == nBoard ) won = TRUE; } } if ( !won ) // no winner t = 0; return t; } // -------------------------------------------------------------------------- // TicTacGameBoard::computerMove() // // Puts a piece on the game board. Very, very simple. // void TicTacGameBoard::computerMove() { int numButtons = nBoard*nBoard; int *altv = new int[numButtons]; // buttons alternatives int altc = 0; int stopHuman = -1; TicTacArray a = btArray->copy(); int i; for ( i=0; i<numButtons; i++ ) { // try all positions if ( a[i] != TicTacButton::Blank ) // already a piece there continue; a[i] = TicTacButton::Cross; // test if computer wins if ( checkBoard(&a) == a[i] ) { // computer will win st = ComputerWon; stopHuman = -1; break; } a[i] = TicTacButton::Circle; // test if human wins if ( checkBoard(&a) == a[i] ) { // oops... stopHuman = i; // remember position a[i] = TicTacButton::Blank; // restore button continue; // computer still might win } a[i] = TicTacButton::Blank; // restore button altv[altc++] = i; // remember alternative } if ( stopHuman >= 0 ) // must stop human from winning a[stopHuman] = TicTacButton::Cross; else if ( i == numButtons ) { // tried all alternatives if ( altc > 0 ) // set random piece a[altv[rand()%(altc--)]] = TicTacButton::Cross; if ( altc == 0 ) { // no more blanks st = NobodyWon; emit finished(); } } *btArray = a; // update model updateButtons(); // update buttons delete[] altv; } //*************************************************************************** //* TicTacToe member functions //*************************************************************************** // -------------------------------------------------------------------------- // Creates a game widget with a game board and two push buttons, and connects // signals of child widgets to slots. // TicTacToe::TicTacToe( QWidget *parent, const char *name, WFlags fl ) : QWidget( parent, name, fl ) { QVBoxLayout * l = new QVBoxLayout( this, 6 ); // Create a message label boardSize = 3; message = new QLabel( this ); message->setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); message->setAlignment( AlignCenter ); l->addWidget( message ); // Create the game board and connect the signal finished() to this // gameOver() slot board = new TicTacGameBoard( boardSize, this ); connect( board, SIGNAL(finished()), SLOT(gameOver()) ); l->addWidget( board ); // Create a horizontal frame line QFrame *line = new QFrame( this ); line->setFrameStyle( QFrame::HLine | QFrame::Sunken ); l->addWidget( line ); // Create the combo box for deciding who should start, and // connect its clicked() signals to the buttonClicked() slot whoStarts = new QComboBox( this ); whoStarts->insertItem( tr( "Computer starts" ) ); whoStarts->insertItem( tr( "Human starts" ) ); l->addWidget( whoStarts ); // Create the push buttons and connect their clicked() signals // to this right slots. newGame = new QPushButton( tr( "Play!" ), this ); connect( newGame, SIGNAL(clicked()), SLOT(newGameClicked()) ); quit = new QPushButton( tr( "Quit" ), this ); connect( quit, SIGNAL(clicked()), qApp, SLOT(quit()) ); QHBoxLayout * b = new QHBoxLayout; l->addLayout( b ); b->addWidget( newGame ); b->addWidget( quit ); - showMaximized(); + QPEApplication::showWidget( this ); newState(); } // -------------------------------------------------------------------------- // TicTacToe::newGameClicked() - SLOT // // This slot is activated when the new game button is clicked. // void TicTacToe::newGameClicked() { board->computerStarts( whoStarts->currentItem() == 0 ); board->newGame(); newState(); } // -------------------------------------------------------------------------- // TicTacToe::gameOver() - SLOT // // This slot is activated when the TicTacGameBoard emits the signal // "finished()", i.e. when a player has won or when it is a draw. // void TicTacToe::gameOver() { newState(); // update text box } // -------------------------------------------------------------------------- // Updates the message to reflect a new state. // void TicTacToe::newState() { QStringList msg; msg << tr( "Click Play to start") << tr("Make your move") << tr("You won!") << tr("Computer won!") << tr("It's a draw"); message->setText( msg[board->state()] ); return; } |