summaryrefslogtreecommitdiff
path: root/noncore/games
Side-by-side diff
Diffstat (limited to 'noncore/games') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/backgammon/backgammon.cpp14
-rw-r--r--noncore/games/backgammon/filedialog.cpp2
-rw-r--r--noncore/games/backgammon/themedialog.cpp2
3 files changed, 9 insertions, 9 deletions
diff --git a/noncore/games/backgammon/backgammon.cpp b/noncore/games/backgammon/backgammon.cpp
index bdb1c78..c286a36 100644
--- a/noncore/games/backgammon/backgammon.cpp
+++ b/noncore/games/backgammon/backgammon.cpp
@@ -1,156 +1,156 @@
#include "backgammon.h"
#include "aidialog.h"
#include "filedialog.h"
#include "playerdialog.h"
#include "rulesdialog.h"
#include "themedialog.h"
/* OPIE */
#include <opie2/odebug.h>
#include <qpe/qpeapplication.h>
#include <qpe/config.h>
#include <qpe/resource.h>
using namespace Opie::Core;
/* QT */
#include <qfile.h>
#include <qlayout.h>
#include <qmessagebox.h>
#include <qtimer.h>
#include <qmenubar.h>
#include <stdlib.h>
BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl)
: QMainWindow(parent, name, fl)
{
if (!name) setName("BackGammon");
setCaption(tr( "Backgammon") );
setIcon( Resource::loadPixmap( "backgammon" ) );
//general counter varaible
int a=0;
//the game engine
move=new MoveEngine();
//load the default theme
Config conf("backgammon");
if(!conf.isValid())
{
odebug << "config file does not exist" << oendl;
conf.setGroup("general");
conf.writeEntry("theme","default");
conf.setGroup("rules");
conf.writeEntry("move_with_pieces_out",false);
conf.writeEntry("nice_dice",false);
conf.setGroup("display");
conf.writeEntry("small",false);
conf.writeEntry("warning",true);
conf.setGroup("ai");
conf.writeEntry("rescue",6);
conf.writeEntry("eliminate",4);
conf.writeEntry("expose",1);
conf.writeEntry("protect",5);
conf.writeEntry("safe",3);
conf.writeEntry("empty",2);
}
conf.setGroup("general");
theme_name=conf.readEntry("theme","default");
- QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme";
+ QString theme_file=QPEApplication::qpeDir()+"backgammon/"+theme_name+".theme";
//the rules
conf.setGroup("rules");
rules.move_with_pieces_out=conf.readBoolEntry("move_with_pieces_out",false);
rules.generous_dice=conf.readBoolEntry("nice_dice",false);
move->setRules(rules);
//get the AI settings
AISettings ai;
conf.setGroup("ai");
ai.rescue=conf.readNumEntry("rescue",6);
ai.eliminate=conf.readNumEntry("eliminate",4);
ai.expose=conf.readNumEntry("expose",1);
ai.protect=conf.readNumEntry("protect",5);
ai.safe=conf.readNumEntry("safe",3);
ai.empty=conf.readNumEntry("empty",2);
move->setAISettings(ai);
//get the theme component names
Config theme(theme_file,Config::File);
if(!theme.isValid())
{
odebug << "theme file does not exist" << oendl;
theme.setGroup("theme");
theme.writeEntry("board","casino_board_1");
theme.writeEntry("pieces1","casino_pieces_blue");
theme.writeEntry("pieces2","casino_pieces_white");
theme.writeEntry("dice1","casino_dice");
theme.writeEntry("dice2","casino_dice");
theme.writeEntry("table","casino_table_green");
theme.writeEntry("odds","casino_odds");
}
theme.setGroup("theme");
board_name=theme.readEntry("board","casino_board_1");
piecesA_name=theme.readEntry("pieces1","casino_pieces_blue");
piecesB_name=theme.readEntry("pieces2","casino_pieces_white");
diceA_name=theme.readEntry("dice1","casino_dice");
diceB_name=theme.readEntry("dice2","casino_dice");
table_name=theme.readEntry("table","casino_table_green");
odds_name=theme.readEntry("odds","casino_odds");
//the menu
QMenuBar* menuBar = new QMenuBar(this);
QPopupMenu* gamemenu= new QPopupMenu(this);
gamemenu->insertItem(tr( "New" ),this,SLOT(newgame()));
gamemenu->insertSeparator();
gamemenu->insertItem(tr( "Load" ),this,SLOT(loadgame()));
gamemenu->insertItem(tr( "Save" ),this,SLOT(savegame()));
gamemenu->insertSeparator();
gamemenu->insertItem(tr( "Delete" ),this,SLOT(deletegame()));
menuBar->insertItem(tr( "Game" ),gamemenu);
QPopupMenu* thememenu= new QPopupMenu(this);
thememenu->insertItem(tr( "New" ),this,SLOT(newtheme()));
thememenu->insertSeparator();
thememenu->insertItem(tr( "Load"),this,SLOT(loadtheme()));
thememenu->insertItem(tr( "Save" ),this,SLOT(savetheme()));
thememenu->insertSeparator();
thememenu->insertItem(tr( "Default"),this,SLOT(themedefault()));
thememenu->insertItem(tr( "Delete" ),this,SLOT(deletetheme()));
menuBar->insertItem(tr( "Theme" ),thememenu);
QPopupMenu* optionmenu=new QPopupMenu(this);
optionmenu->insertItem(tr( "Player" ),this,SLOT(playerselect()));
optionmenu->insertSeparator();
optionmenu->insertItem(tr( "AI" ),this,SLOT(modify_AI()));
optionmenu->insertItem(tr( "Rules" ),this,SLOT(setrules()));
menuBar->insertItem(tr( "Options"),optionmenu);
QWidget* mainarea=new QWidget(this);
setCentralWidget(mainarea);
//the main area
QBoxLayout* layout=new QBoxLayout(mainarea,QBoxLayout::TopToBottom);
area=new QCanvas(235,235);
boardview=new BackGammonView(area,mainarea);
boardview->setMaximumHeight(240);
layout->addWidget(boardview);
connect(boardview,SIGNAL(mouse(int,int)),this,SLOT(mouse(int,int)));
//status bar
message=new QLabel("<b>Backgammon</b>",mainarea);
message->setAlignment(AlignHCenter);
layout->addWidget(message);
//the marker
marker_current=new QCanvasRectangle(area);
marker_current->setBrush(QColor(0,0,255));
marker_current->setSize(15,5);
marker_current->setZ(1);
for(a=0;a<4;a++)
{
marker_next[a]=new QCanvasRectangle(area);
@@ -235,374 +235,374 @@ BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl)
if(a<6)
{
QImage oddsbg=oddsbg_all.copy(a*15,0,15,15);
oddsDice[a]=new CanvasImageItem(oddsbg,area);
oddsDice[a]->setX(110);
oddsDice[a]->setY(210-2);
oddsDice[a]->setZ(1);
oddsDice[a]->setSize(15,15);
oddsDice[a]->hide();
}
*/
}
//oddsDice[0]->show();
//set the board
QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name));
board=new CanvasImageItem(boardbg,area);
board->setX(0);
board->setY(0);
board->setZ(0);
board->setSize(235-2,200-2);
board->show();
//the table
QImage tablebg(Resource::loadImage("backgammon/table/"+table_name));
table=new CanvasImageItem(tablebg,area);
table->setX(0);
table->setY(200-2);
table->setZ(0);
table->setSize(235-2,20);
table->show();
//the no move marker
QImage nomovebg(Resource::loadImage("backgammon/no_move"));
nomove_marker=new CanvasImageItem(nomovebg,area);
nomove_marker->setX(0);
nomove_marker->setY(200);
nomove_marker->setZ(2);
nomove_marker->hide();
//default human against computer
player1_auto=false;
player2_auto=true;
//start new game
newgame();
}
BackGammon::~BackGammon()
{
//DESTRUCTOR
}
void BackGammon::newgame()
{
gameFinished=false;
QDateTime now=QDateTime::currentDateTime();
game_name=now.date().toString()+"_"+now.time().toString();
move->reset();
draw();
diceA1_value=7;
diceA2_value=7;
diceA3_value=7;
diceA4_value=7;
diceB1_value=7;
diceB2_value=7;
diceB3_value=7;
diceB4_value=7;
showdice();
player=2;
dice1_played=true;
dice2_played=true;
dice3_played=true;
dice4_played=true;
dice_rolled=false;
setplayer();
area->update();
}
void BackGammon::playerselect()
{
PlayerDialog* playerdialog=new PlayerDialog(this);
playerdialog->setAuto1(player1_auto);
playerdialog->setAuto2(player2_auto);
if(!playerdialog->exec())
return;
player1_auto=playerdialog->getAuto1();
player2_auto=playerdialog->getAuto2();
}
void BackGammon::loadgame()
{
FileDialog* file=new FileDialog(this,"Load Game",".game");
if(!file->exec())
return;
game_name=file->filename();
- QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game";
+ QString game_file=QPEApplication::qpeDir()+"backgammon/"+game_name+".game";
Config game(game_file,Config::File);
game.setGroup("dice");
diceA1_value=game.readNumEntry("diceA1_value");
diceA2_value=game.readNumEntry("diceA2_value");
diceA3_value=game.readNumEntry("diceA3_value");
diceA4_value=game.readNumEntry("diceA4_value");
diceB1_value=game.readNumEntry("diceB1_value");
diceB2_value=game.readNumEntry("diceB2_value");
diceB3_value=game.readNumEntry("diceB3_value");
diceB4_value=game.readNumEntry("diceB4_value");
player=game.readNumEntry("player");
dice1_played=game.readBoolEntry("dice1_played");
dice2_played=game.readBoolEntry("dice2_played");
dice3_played=game.readBoolEntry("dice3_played");
dice4_played=game.readBoolEntry("dice4_played");
dice_rolled=game.readBoolEntry("dice_rolled");
player1_auto=game.readBoolEntry("player1_auto");
player2_auto=game.readBoolEntry("player2_auto");
game.setGroup("pieces");
QString label;
LoadSave load;
for(int a=0;a<28;a++)
{
label.setNum(a);
load.pop[a].total = game.readNumEntry(label,0);
}
move->loadGame(load);
setplayer();
showdice();
draw();
area->update();
}
void BackGammon::savegame()
{
- QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game";
+ QString game_file=QPEApplication::qpeDir()+"backgammon/"+game_name+".game";
Config game(game_file,Config::File);
game.setGroup("dice");
game.writeEntry("diceA1_value",diceA1_value);
game.writeEntry("diceA2_value",diceA2_value);
game.writeEntry("diceA3_value",diceA3_value);
game.writeEntry("diceA4_value",diceA4_value);
game.writeEntry("diceB1_value",diceB1_value);
game.writeEntry("diceB2_value",diceB3_value);
game.writeEntry("diceB3_value",diceB4_value);
game.writeEntry("diceB4_value",diceB4_value);
game.writeEntry("player",player);
game.writeEntry("dice1_played",dice1_played);
game.writeEntry("dice2_played",dice2_played);
game.writeEntry("dice3_played",dice3_played);
game.writeEntry("dice4_played",dice4_played);
game.writeEntry("dice_rolled",dice_rolled);
game.writeEntry("player1_auto",player1_auto);
game.writeEntry("player2_auto",player2_auto);
game.setGroup("pieces");
QString label;
LoadSave save=move->saveGame();
for(int a=0;a<28;a++)
{
label.setNum(a);
game.writeEntry(label,save.pop[a].total);
}
QMessageBox::information(this,"Backgammon","Game saved","OK");
}
void BackGammon::deletegame()
{
FileDialog* file=new FileDialog(this,"Delete Game",".game");
if(!file->exec())
return;
game_name=file->filename();
- QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game";
+ QString game_file=QPEApplication::qpeDir()+"backgammon/"+game_name+".game";
if(!QMessageBox::warning(this,"Backgammon","deleted game\n"+game_name+" ?","OK","Cancel"))
{
QFile(game_file).remove();
}
}
void BackGammon::newtheme()
{
ThemeDialog* theme=new ThemeDialog(this);
ImageNames names;
names.theme=theme_name;
names.board=board_name;
names.pieces1=piecesA_name;
names.pieces2=piecesB_name;
names.dice1=diceA_name;
names.dice2=diceB_name;
names.odds=odds_name;
names.table=table_name;
theme->setCurrent(names);
if(!theme->exec())
return;
names=theme->getNames();
theme_name=names.theme;
board_name=names.board;
piecesA_name=names.pieces1;
piecesB_name=names.pieces2;
diceA_name=names.dice1;
diceB_name=names.dice2;
odds_name=names.odds;
table_name=names.table;
applytheme();
}
void BackGammon::loadtheme()
{
FileDialog* file=new FileDialog(this,"Load Theme",".theme");
if(!file->exec())
return;
theme_name=file->filename();
- QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme";
+ QString theme_file=QPEApplication::qpeDir()+"backgammon/"+theme_name+".theme";
Config theme(theme_file,Config::File);
theme.setGroup("theme");
board_name=theme.readEntry("board","board_1");
piecesA_name=theme.readEntry("pieces1","pieces_1");
piecesB_name=theme.readEntry("pieces2","pieces_2");
diceA_name=theme.readEntry("dice1","dice_1");
diceB_name=theme.readEntry("dice2","dice_2");
table_name=theme.readEntry("table","table_1");
odds_name=theme.readEntry("odds","odds_1");
applytheme();
}
void BackGammon::savetheme()
{
if(theme_name=="default")
{
QMessageBox::information(this,"Backgammon","Sorry\nCannot overwrite default.theme","OK");
return;
}
- QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme";
+ QString theme_file=QPEApplication::qpeDir()+"backgammon/"+theme_name+".theme";
if(QMessageBox::information(this,"Backgammon","Save Theme\n"+theme_name,"Yes","No"))
return;
Config theme(theme_file,Config::File);
theme.setGroup("theme");
theme.writeEntry("board",board_name);
theme.writeEntry("pieces1",piecesA_name);
theme.writeEntry("pieces2",piecesB_name);
theme.writeEntry("dice1",diceA_name);
theme.writeEntry("dice2",diceB_name);
theme.writeEntry("table",table_name);
theme.writeEntry("odds",odds_name);
}
void BackGammon::themedefault()
{
if(QMessageBox::information(this,"Backgammon","Make Theme\n"+theme_name+"\nthe default theme","Yes","No"))
return;
Config conf("backgammon");
conf.setGroup("general");
conf.writeEntry("theme",theme_name);
}
void BackGammon::deletetheme()
{
FileDialog* file=new FileDialog(this,"Delete Theme",".theme");
if(!file->exec())
return;
theme_name=file->filename();
- QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme";
+ QString theme_file=QPEApplication::qpeDir()+"backgammon/"+theme_name+".theme";
if(!QMessageBox::warning(this,tr( "Backgammon" ),tr( "deleted theme %1?").arg(theme_name),tr( "OK" ),tr( "Cancel" )))
{
QFile(theme_file).remove();
}
}
void BackGammon::modify_AI()
{
AI_Dialog* ai_mod=new AI_Dialog(this,tr( "Load Theme" ),".theme");
ai_mod->setAISettings(move->getAISettings());
if(!ai_mod->exec())
return;
//get the AI settings
AISettings ai=ai_mod->getAISettings();
move->setAISettings(ai);
//write new settings to conf file
Config conf("backgammon");
conf.setGroup("ai");
conf.writeEntry("rescue",ai.rescue);
conf.writeEntry("eliminate",ai.eliminate);
conf.writeEntry("expose",ai.expose);
conf.writeEntry("protect",ai.protect);
conf.writeEntry("safe",ai.safe);
conf.writeEntry("empty",ai.empty);
}
void BackGammon::setrules()
{
RulesDialog* rulesdialog=new RulesDialog(this,tr( "Load Theme" ),".theme");
rulesdialog->setRules(rules);
if(!rulesdialog->exec())
return;
rules=rulesdialog->getRules();
Config conf("backgammon");
conf.setGroup("rules");
conf.writeEntry("move_with_pieces_out",rules.move_with_pieces_out);
conf.writeEntry("nice_dice",rules.generous_dice);
move->setRules(rules);
}
void BackGammon::draw()
{
Pieces pieces;
move->position(pieces);
for(int a=0;a<15;a++)
{
if(!pieces.player1[a].side)
{
p1[a]->setX(pieces.player1[a].x);
p1[a]->setY(pieces.player1[a].y);
p1[a]->setZ(pieces.player1[a].z);
p1[a]->show();
p1_side[a]->hide();
}
else
{
p1_side[a]->setX(pieces.player1[a].x);
p1_side[a]->setY(pieces.player1[a].y);
p1_side[a]->setZ(pieces.player1[a].z);
p1_side[a]->show();
p1[a]->hide();
}
if(!pieces.player2[a].side)
{
p2[a]->setX(pieces.player2[a].x);
p2[a]->setY(pieces.player2[a].y);
p2[a]->setZ(pieces.player2[a].z);
p2[a]->show();
p2_side[a]->hide();
}
else
{
p2_side[a]->setX(pieces.player2[a].x);
p2_side[a]->setY(pieces.player2[a].y);
p2_side[a]->setZ(pieces.player2[a].z);
p2_side[a]->show();
p2[a]->hide();
}
}
}
void BackGammon::mouse(int x,int y)
{
if(gameFinished)
{
newgame();
return;
}
if(y<=200) //move pieces
{
if((player==1 && player1_auto) || (player==2 && player2_auto))
return;
diff --git a/noncore/games/backgammon/filedialog.cpp b/noncore/games/backgammon/filedialog.cpp
index e0a2914..f185188 100644
--- a/noncore/games/backgammon/filedialog.cpp
+++ b/noncore/games/backgammon/filedialog.cpp
@@ -1,61 +1,61 @@
#include "filedialog.h"
#include <qdir.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);
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");
+ 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/themedialog.cpp b/noncore/games/backgammon/themedialog.cpp
index afd6a1b..9bdb6a9 100644
--- a/noncore/games/backgammon/themedialog.cpp
+++ b/noncore/games/backgammon/themedialog.cpp
@@ -50,112 +50,112 @@ ThemeDialog::ThemeDialog(QWidget* parent,const char* name,bool modal,WFlags f)
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);
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);
+ 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;
}