summaryrefslogtreecommitdiff
path: root/noncore/games/backgammon/backgammon.cpp
Side-by-side diff
Diffstat (limited to 'noncore/games/backgammon/backgammon.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/backgammon/backgammon.cpp34
1 files changed, 17 insertions, 17 deletions
diff --git a/noncore/games/backgammon/backgammon.cpp b/noncore/games/backgammon/backgammon.cpp
index c286a36..31835f8 100644
--- a/noncore/games/backgammon/backgammon.cpp
+++ b/noncore/games/backgammon/backgammon.cpp
@@ -1,78 +1,78 @@
#include "backgammon.h"
#include "aidialog.h"
#include "filedialog.h"
#include "playerdialog.h"
#include "rulesdialog.h"
#include "themedialog.h"
/* OPIE */
#include <opie2/odebug.h>
+#include <opie2/oresource.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" ) );
+ setIcon( Opie::Core::OResource::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";
//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);
@@ -124,193 +124,193 @@ BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl)
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);
marker_next[a]->setBrush(QColor(0,255,0));
marker_next[a]->setSize(15,5);
marker_next[a]->setZ(1);
}
connect(move,SIGNAL(done_dice1()),this,SLOT(done_dice1()));
connect(move,SIGNAL(done_dice2()),this,SLOT(done_dice2()));
connect(move,SIGNAL(done_dice3()),this,SLOT(done_dice3()));
connect(move,SIGNAL(done_dice4()),this,SLOT(done_dice4()));
connect(move,SIGNAL(nomove()),this,SLOT(nomove()));
connect(move,SIGNAL(player_finished(int)),this,SLOT(finished(int)));
//the pieces
p1=new CanvasImageItem*[15];
p1_side=new CanvasImageItem*[15];
- QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name));
+ QImage piece_1_all(Opie::Core::OResource::loadImage("backgammon/pieces/"+piecesA_name));
QImage piece_1_front=piece_1_all.copy(0,0,15,15);
QImage piece_1_side=piece_1_all.copy(0,15,15,5);
p2=new CanvasImageItem*[15];
p2_side=new CanvasImageItem*[15];
- QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name));
+ QImage piece_2_all(Opie::Core::OResource::loadImage("backgammon/pieces/"+piecesB_name));
QImage piece_2_front=piece_2_all.copy(0,0,15,15);
QImage piece_2_side=piece_2_all.copy(0,15,15,5);
for(a=0;a<15;a++)
{
p1[a]=new CanvasImageItem(piece_1_front,area);
p1[a]->setSize(15,15);
p1_side[a]=new CanvasImageItem(piece_1_side,area);
p1_side[a]->setSize(15,5);
p2[a]=new CanvasImageItem(piece_2_front,area);
p2[a]->setSize(15,15);
p2_side[a]=new CanvasImageItem(piece_2_side,area);
p2_side[a]->setSize(15,5);
}
draw();
//the dice
- QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name));
+ QImage dicebgA_all(Opie::Core::OResource::loadImage("backgammon/dice/"+diceA_name));
diceA1=new CanvasImageItem*[7];
diceA2=new CanvasImageItem*[7];
- QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name));
+ QImage dicebgB_all(Opie::Core::OResource::loadImage("backgammon/dice/"+diceB_name));
diceB1=new CanvasImageItem*[7];
diceB2=new CanvasImageItem*[7];
- QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name));
+ QImage oddsbg_all=(Opie::Core::OResource::loadImage("backgammon/odds/"+odds_name));
//oddsDice=new CanvasImageItem*[6];
for(a=0;a<7;a++)
{
QImage dicebgA=dicebgA_all.copy(a*25,0,25,25);
diceA1[a]=new CanvasImageItem(dicebgA,area);
diceA1[a]->setX(5);
diceA1[a]->setY(205-2);
diceA1[a]->setZ(1);
diceA1[a]->setSize(25,25);
diceA2[a]=new CanvasImageItem(dicebgA,area);
diceA2[a]->setX(35);
diceA2[a]->setY(205-2);
diceA2[a]->setZ(1);
diceA2[a]->setSize(25,25);
QImage dicebgB=dicebgB_all.copy(a*25,0,25,25);
diceB1[a]=new CanvasImageItem(dicebgB,area);
diceB1[a]->setX(175);
diceB1[a]->setY(205-2);
diceB1[a]->setZ(1);
diceB1[a]->setSize(25,25);
diceB2[a]=new CanvasImageItem(dicebgB,area);
diceB2[a]->setX(205);
diceB2[a]->setY(205-2);
diceB2[a]->setZ(1);
diceB2[a]->setSize(25,25);
/*
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));
+ QImage boardbg(Opie::Core::OResource::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));
+ QImage tablebg(Opie::Core::OResource::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"));
+ QImage nomovebg(Opie::Core::OResource::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);
@@ -879,97 +879,97 @@ void BackGammon::showdice()
diceA2[index]->show();
else
diceA2[index]->hide();
if(value_diceB1==index)
diceB1[index]->show();
else
diceB1[index]->hide();
if(value_diceB2==index)
diceB2[index]->show();
else
diceB2[index]->hide();
}
}
void BackGammon::setplayer()
{
if(dice1_played && dice2_played && dice3_played && dice4_played && player==1)
{
message->setText(tr( "<b>P2 turn</b>", "P means player" ));
dice_rolled=false;
player=2;
if(player2_auto)
QTimer::singleShot(2000,this,SLOT(autoroll_dice2()));
}
else if(dice1_played && dice2_played && dice3_played && dice4_played && player==2)
{
message->setText(tr( "<b>P1 turn</b>", "P means player" ));
dice_rolled=false;
player=1;
if(player1_auto)
QTimer::singleShot(2000,this,SLOT(autoroll_dice1()));
}
}
void BackGammon::autoroll_dice1()
{
mouse(20,210);
}
void BackGammon::autoroll_dice2()
{
mouse(170,210);
}
void BackGammon::applytheme()
{
- QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name));
+ QImage boardbg(Opie::Core::OResource::loadImage("backgammon/boards/"+board_name));
board->setImage(boardbg);
- QImage tablebg(Resource::loadImage("backgammon/table/"+table_name));
+ QImage tablebg(Opie::Core::OResource::loadImage("backgammon/table/"+table_name));
table->setImage(tablebg);
- QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name));
+ QImage piece_1_all(Opie::Core::OResource::loadImage("backgammon/pieces/"+piecesA_name));
QImage piece_1_front=piece_1_all.copy(0,0,15,15);
QImage piece_1_side=piece_1_all.copy(0,15,15,5);
- QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name));
+ QImage piece_2_all(Opie::Core::OResource::loadImage("backgammon/pieces/"+piecesB_name));
QImage piece_2_front=piece_2_all.copy(0,0,15,15);
QImage piece_2_side=piece_2_all.copy(0,15,15,5);
int a=0;
for(a=0;a<15;a++)
{
p1[a]->setImage(piece_1_front);
p1_side[a]->setImage(piece_1_side);
p2[a]->setImage(piece_2_front);
p2_side[a]->setImage(piece_2_side);
}
draw();
- QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name));
- QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name));
- QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name));
+ QImage dicebgA_all(Opie::Core::OResource::loadImage("backgammon/dice/"+diceA_name));
+ QImage dicebgB_all(Opie::Core::OResource::loadImage("backgammon/dice/"+diceB_name));
+ QImage oddsbg_all=(Opie::Core::OResource::loadImage("backgammon/odds/"+odds_name));
for(a=0;a<7;a++)
{
QImage dicebgA=dicebgA_all.copy(a*25,0,25,25);
diceA1[a]->setImage(dicebgA);
diceA2[a]->setImage(dicebgA);
QImage dicebgB=dicebgB_all.copy(a*25,0,25,25);
diceB1[a]->setImage(dicebgB);
diceB2[a]->setImage(dicebgB);
/*
if(a<6)
{
QImage oddsbg=oddsbg_all.copy(a*15,0,15,15);
oddsDice[a]->setImage(oddsbg);
}
*/
}
}