author | waspe <waspe> | 2003-05-16 16:34:55 (UTC) |
---|---|---|
committer | waspe <waspe> | 2003-05-16 16:34:55 (UTC) |
commit | 11b6ce5ac500dce757ccdd0a5f5b5ecd7fb866c8 (patch) (side-by-side diff) | |
tree | 3013dbafcb4e1f919e104204d1288f0309da5641 /noncore/games/backgammon/backgammon.cpp | |
parent | 75f1e9815410e75a6f9ae76d8db716c0c315ea45 (diff) | |
download | opie-11b6ce5ac500dce757ccdd0a5f5b5ecd7fb866c8.zip opie-11b6ce5ac500dce757ccdd0a5f5b5ecd7fb866c8.tar.gz opie-11b6ce5ac500dce757ccdd0a5f5b5ecd7fb866c8.tar.bz2 |
*** empty log message ***
Diffstat (limited to 'noncore/games/backgammon/backgammon.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/games/backgammon/backgammon.cpp | 131 |
1 files changed, 31 insertions, 100 deletions
diff --git a/noncore/games/backgammon/backgammon.cpp b/noncore/games/backgammon/backgammon.cpp index 38ccb49..c40f462 100644 --- a/noncore/games/backgammon/backgammon.cpp +++ b/noncore/games/backgammon/backgammon.cpp @@ -1,57 +1,37 @@ #include "backgammon.h" #include "aidialog.h" -#include "displaydialog.h" #include "filedialog.h" #include "playerdialog.h" #include "rulesdialog.h" #include "themedialog.h" #include <qdatetime.h> #include <qfile.h> +#include <qlayout.h> #include <qmessagebox.h> #include <qstring.h> #include <qtimer.h> +#include <qmainwindow.h> #include <qpe/qpeapplication.h> #include <qpe/config.h> #include <qpe/qpemenubar.h> #include <qpe/resource.h> #include <stdlib.h> -BackGammonView::BackGammonView(QCanvas* canvas,QWidget* parent) - :QCanvasView(canvas,parent) -{ - //do nothing -} - - - -BackGammonView::~BackGammonView() -{ - //do nothing -} - - - -void BackGammonView::contentsMousePressEvent(QMouseEvent* e) -{ - int x=e->x(); - int y=e->y(); - emit mouse(x,y); -} BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl) - : QWidget(parent, name, fl) + : QMainWindow(parent, name, fl) { if (!name) setName("BackGammon"); setCaption("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()) @@ -87,39 +67,24 @@ BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl) //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); - //non qte styles are smaller - conf.setGroup("display"); - display.small=conf.readBoolEntry("small",false); - display.warning=conf.readBoolEntry("warning",true); - non_qte=display.small; - if(display.warning) - { - Config test("qpe"); - test.setGroup("Appearance"); - if(test.readEntry("Style")!="QPE") - { - displaySettings(); - } - } - offset=(non_qte) ? 5 : 0; //get the theme component names Config theme(theme_file,Config::File); if(!theme.isValid()) { qDebug("theme file does not exist"); 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"); @@ -154,44 +119,39 @@ BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl) thememenu->insertItem("Load",this,SLOT(loadtheme())); thememenu->insertItem("Save",this,SLOT(savetheme())); thememenu->insertSeparator(); thememenu->insertItem("Default",this,SLOT(themedefault())); thememenu->insertItem("Delete",this,SLOT(deletetheme())); menuBar->insertItem("Theme",thememenu); QPopupMenu* optionmenu=new QPopupMenu(this); optionmenu->insertItem("Player",this,SLOT(playerselect())); optionmenu->insertSeparator(); optionmenu->insertItem("AI",this,SLOT(modify_AI())); optionmenu->insertItem("Rules",this,SLOT(setrules())); - optionmenu->insertItem("Display",this,SLOT(displaySettings())); menuBar->insertItem("Options",optionmenu); - //status bar - message=new QLabel("<b>Backgammon</b>",this); - message->setGeometry(0,260,237,20); - message->setAlignment(AlignHCenter); - + QWidget* mainarea=new QWidget(this); + setCentralWidget(mainarea); //the main area - area=new QCanvas(235-2*offset,235-2*offset); - boardview=new BackGammonView(area,this); + 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))); - if(non_qte) - { - boardview->setGeometry(5,20,229,229); - } - else - { - boardview->setGeometry(1,20,237,237); - } + //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); @@ -239,85 +199,77 @@ BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl) diceA2=new CanvasImageItem*[7]; QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name)); diceB1=new CanvasImageItem*[7]; diceB2=new CanvasImageItem*[7]; QImage oddsbg_all=(Resource::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-offset); - diceA1[a]->setY(205-2*offset); + 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-offset); - diceA2[a]->setY(205-2*offset); + 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-offset); - diceB1[a]->setY(205-2*offset); + 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-offset); - diceB2[a]->setY(205-2*offset); + 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-offset); - oddsDice[a]->setY(210-2*offset); + 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)); - if(non_qte) - { - boardbg=boardbg.copy(offset,offset,235-2*offset,200-2*offset); - } board=new CanvasImageItem(boardbg,area); board->setX(0); board->setY(0); board->setZ(0); - board->setSize(235-2*offset,200-2*offset); + board->setSize(235-2,200-2); board->show(); //the table QImage tablebg(Resource::loadImage("backgammon/table/"+table_name)); - if(non_qte) - { - tablebg=tablebg.copy(offset,0,235-offset,200); - } table=new CanvasImageItem(tablebg,area); table->setX(0); - table->setY(200-2*offset); + table->setY(200-2); table->setZ(0); - table->setSize(235-2*offset,20); + 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; @@ -590,42 +542,29 @@ void BackGammon::setrules() RulesDialog* rulesdialog=new RulesDialog(this,"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::displaySettings() -{ - DisplayDialog* displaydialog=new DisplayDialog(this); - displaydialog->setDisplaySettings(display); - if(!displaydialog->exec()) - return; - display=displaydialog->getDisplaySettings(); - Config conf("backgammon"); - conf.setGroup("display"); - conf.writeEntry("small",display.small); - conf.writeEntry("warning",display.warning); - QMessageBox::warning(this,"Backgammon","changed display settings will\nonly take place after game has\nbeen restarted","OK"); -} void BackGammon::draw() { Pieces pieces; - move->position(pieces,non_qte); + 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 { @@ -660,41 +599,41 @@ 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; Marker marker; - move->boardpressed(x,y,marker,non_qte); + move->boardpressed(x,y,marker); if(marker.visible_current) { - marker_current->setX(marker.x_current-offset); + marker_current->setX(marker.x_current); marker_current->setY(marker.y_current); marker_current->show(); } else { marker_current->hide(); } for(int a=0;a<4;a++) { if(marker.visible_next[a]) { - marker_next[a]->setX(marker.x_next[a]-offset); + marker_next[a]->setX(marker.x_next[a]); marker_next[a]->setY(marker.y_next[a]); marker_next[a]->show(); } else { marker_next[a]->hide(); } } area->update(); } else //roll dice { @@ -976,35 +915,27 @@ 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)); - if(non_qte) - { - boardbg=boardbg.copy(offset,offset,235-2*offset,200-2*offset); - } board->setImage(boardbg); QImage tablebg(Resource::loadImage("backgammon/table/"+table_name)); - if(non_qte) - { - tablebg=tablebg.copy(offset,0,235-offset,200); - } table->setImage(tablebg); QImage piece_1_all(Resource::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_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++) |