-rw-r--r-- | noncore/games/backgammon/backgammon.cpp | 131 | ||||
-rw-r--r-- | noncore/games/backgammon/backgammon.h | 32 | ||||
-rw-r--r-- | noncore/games/backgammon/backgammonview.cpp | 14 | ||||
-rw-r--r-- | noncore/games/backgammon/backgammonview.h | 10 | ||||
-rw-r--r-- | noncore/games/backgammon/definition.cpp | 1 | ||||
-rw-r--r-- | noncore/games/backgammon/displaydialog.cpp | 89 | ||||
-rw-r--r-- | noncore/games/backgammon/displaydialog.h | 30 | ||||
-rw-r--r-- | noncore/games/backgammon/moveengine.cpp | 2 | ||||
-rw-r--r-- | noncore/games/backgammon/moveengine.h | 2 | ||||
-rw-r--r-- | noncore/games/backgammon/rulesdialog.h | 1 |
10 files changed, 56 insertions, 256 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,407 +1,359 @@ #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()) { qDebug("config file does not exist"); 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); - //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"); 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 QPEMenuBar* menuBar = new QPEMenuBar(this); QPopupMenu* gamemenu= new QPopupMenu(this); gamemenu->insertItem("New",this,SLOT(newgame())); gamemenu->insertSeparator(); gamemenu->insertItem("Load",this,SLOT(loadgame())); gamemenu->insertItem("Save",this,SLOT(savegame())); gamemenu->insertSeparator(); gamemenu->insertItem("Delete",this,SLOT(deletegame())); menuBar->insertItem("Game",gamemenu); QPopupMenu* thememenu= new QPopupMenu(this); thememenu->insertItem("New",this,SLOT(newtheme())); thememenu->insertSeparator(); 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); 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_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_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)); diceA1=new CanvasImageItem*[7]; 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; 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"; 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); } @@ -506,279 +458,266 @@ void BackGammon::loadtheme() 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"; 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"; if(!QMessageBox::warning(this,"Backgammon","deleted theme "+theme_name+" ?","OK","Cancel")) { QFile(theme_file).remove(); } } void BackGammon::modify_AI() { AI_Dialog* ai_mod=new AI_Dialog(this,"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,"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 { 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; 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 { if(x>=10 && x<=65 && player==1 && !dice_rolled) { dice1_played=false; dice2_played=false; dice3_played=false; dice4_played=false; dice_rolled=true; srand(QTime::currentTime().msec()); diceA1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); diceA2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); if(diceA1_value==diceA2_value) { diceA3_value=diceA1_value; diceA4_value=diceA1_value; } else { diceA3_value=7; dice3_played=true; diceA4_value=7; dice4_played=true; } showdice(); area->update(); move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); } else if(x>=160 && x<=225 && player==2 && !dice_rolled) { dice1_played=false; dice2_played=false; dice3_played=false; dice4_played=false; dice_rolled=true; srand(QTime::currentTime().msec()); diceB1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); diceB2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); if(diceB1_value==diceB2_value) { diceB3_value=diceB1_value; diceB4_value=diceB1_value; } else { diceB3_value=7; dice3_played=true; diceB4_value=7; dice4_played=true; } showdice(); area->update(); move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); } } } void BackGammon::done_dice1() { dice1_played=true; if(player==1) diceA1_value=7; else diceB1_value=7; setplayer(); showdice(); draw(); area->update(); if(!dice2_played || !dice3_played || !dice4_played) { if(player==1) { move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); } else { move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); } } } void BackGammon::done_dice2() { dice2_played=true; if(player==1) @@ -892,152 +831,144 @@ void BackGammon::nomove2() area->update(); } void BackGammon::finished(int theplayer) { nomove_marker->hide(); if(theplayer==1) message->setText("<b>Player 1 wins. Click on board for new game.</b>"); else message->setText("<b>Player 2 wins. Click on board for new game.</b>"); diceA1_value=7; diceA2_value=7; diceB1_value=7; diceB2_value=7; player=0; showdice(); draw(); area->update(); gameFinished=true; } void BackGammon::showdice() { int value_diceA1=diceA1_value-1; if(diceA1_value==7 && diceA3_value!=7) value_diceA1=diceA3_value-1; int value_diceA2=diceA2_value-1; if(diceA2_value==7 && diceA4_value!=7) value_diceA2=diceA4_value-1; int value_diceB1=diceB1_value-1; if(diceB1_value==7 && diceB3_value!=7) value_diceB1=diceB3_value-1; int value_diceB2=diceB2_value-1; if(diceB2_value==7 && diceB4_value!=7) value_diceB2=diceB4_value-1; for(int index=0;index<7;index++) { if(value_diceA1==index) diceA1[index]->show(); else diceA1[index]->hide(); if(value_diceA2==index) 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("<b>P2 turn</b>"); 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("<b>P1 turn</b>"); 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)); - 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++) { 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)); 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); } */ } } diff --git a/noncore/games/backgammon/backgammon.h b/noncore/games/backgammon/backgammon.h index 40dbaba..e3276f1 100644 --- a/noncore/games/backgammon/backgammon.h +++ b/noncore/games/backgammon/backgammon.h @@ -1,134 +1,120 @@ #ifndef BACKGAMMON_H #define BACKGAMMON_H +#include "backgammonview.h" #include "canvasimageitem.h" -#include "definition.h" //#include "rulesdialog.h" #include "moveengine.h" -#include <qcanvas.h> + #include <qlabel.h> -#include <qlineedit.h> -#include <qwidget.h> +#include <qmainwindow.h> +//#include <qwidget.h> -class BackGammonView : public QCanvasView -{ - Q_OBJECT -public: - BackGammonView(QCanvas* canvas,QWidget* parent); - ~BackGammonView(); -signals: - void mouse(int,int); -private: - void contentsMousePressEvent(QMouseEvent* e); -}; -class BackGammon : public QWidget + +class BackGammon : public QMainWindow { Q_OBJECT private: //GUI - //is the style not qte ? - bool non_qte; - int offset; //the "status" bar - QLineEdit* inputfield; + QLabel* message; //the main drawing area QCanvas* area; BackGammonView* boardview; CanvasImageItem* board; CanvasImageItem* table; CanvasImageItem** p1; CanvasImageItem** p2; CanvasImageItem** p1_side; CanvasImageItem** p2_side; CanvasImageItem** diceA1; CanvasImageItem** diceA2; CanvasImageItem** diceB1; CanvasImageItem** diceB2; //CanvasImageItem** oddsDice; CanvasImageItem* nomove_marker; - + QCanvasRectangle* marker_current; QCanvasRectangle* marker_next[4]; - QLabel* message; + //ENGINE MoveEngine* move; //the dice values int diceA1_value; int diceA2_value; int diceA3_value; int diceA4_value; int diceB1_value; int diceB2_value; int diceB3_value; int diceB4_value; int player; bool dice1_played; bool dice2_played; bool dice3_played; bool dice4_played; bool dice_rolled; //computer opponent bool player1_auto; bool player2_auto; //the images; QString theme_name; QString board_name; QString piecesA_name; QString piecesB_name; QString diceA_name; QString diceB_name; QString odds_name; QString table_name; //save game QString game_name; //the rules Rules rules; //display settings Display display; //is the game finished ? bool gameFinished; public: BackGammon( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); ~BackGammon(); private slots: void newgame(); void playerselect(); void loadgame(); void savegame(); void deletegame(); void newtheme(); void loadtheme(); void savetheme(); void themedefault(); void deletetheme(); void modify_AI(); void setrules(); - void displaySettings(); void mouse(int x,int y); void done_dice1(); void done_dice2(); void done_dice3(); void done_dice4(); void nomove(); void nomove2(); void finished(int theplayer); void autoroll_dice1(); void autoroll_dice2(); private: void draw(); void showdice(); void setplayer(); void applytheme(); }; #endif //BACKGAMMON_H diff --git a/noncore/games/backgammon/backgammonview.cpp b/noncore/games/backgammon/backgammonview.cpp index ecbc12b..6ee8f10 100644 --- a/noncore/games/backgammon/backgammonview.cpp +++ b/noncore/games/backgammon/backgammonview.cpp @@ -1,17 +1,23 @@ #include "backgammonview.h" BackGammonView::BackGammonView(QCanvas* canvas,QWidget* parent) - :QCanvasView(canvas,parent) + :QCanvasView(canvas,parent) { + //do nothing } + + BackGammonView::~BackGammonView() { + //do nothing } + + void BackGammonView::contentsMousePressEvent(QMouseEvent* e) { int x=e->x(); - int y=e->y(); - //emit mousepressed(x,y); -}
\ No newline at end of file + int y=e->y(); + emit mouse(x,y); +} diff --git a/noncore/games/backgammon/backgammonview.h b/noncore/games/backgammon/backgammonview.h index e50f2b0..52508e2 100644 --- a/noncore/games/backgammon/backgammonview.h +++ b/noncore/games/backgammon/backgammonview.h @@ -1,18 +1,18 @@ -#ifndef BACKGAMMONVIEW_H -#define BACKGAMMONVIEW_H +#ifndef BACKGAMMON_VIEW_H +#define BACKGAMMON_VIEW_H #include <qcanvas.h> class BackGammonView : public QCanvasView { Q_OBJECT public: BackGammonView(QCanvas* canvas,QWidget* parent); - ~BackGammonView(); + ~BackGammonView(); signals: - //void mousepressed(int,int); + void mouse(int,int); private: void contentsMousePressEvent(QMouseEvent* e); }; -#endif //BACKGAMMONVIEW_H
\ No newline at end of file +#endif //BACKGAMMON_VIEW_H
\ No newline at end of file diff --git a/noncore/games/backgammon/definition.cpp b/noncore/games/backgammon/definition.cpp index 9e0029d..c036319 100644 --- a/noncore/games/backgammon/definition.cpp +++ b/noncore/games/backgammon/definition.cpp @@ -1,3 +1,2 @@ #include "definition.h" -static bool debug=false; diff --git a/noncore/games/backgammon/displaydialog.cpp b/noncore/games/backgammon/displaydialog.cpp deleted file mode 100644 index 8b97545..0000000 --- a/noncore/games/backgammon/displaydialog.cpp +++ b/dev/null @@ -1,89 +0,0 @@ -#include "displaydialog.h" - -#include <qgroupbox.h> -#include <qlabel.h> - -DisplayDialog::DisplayDialog(QWidget* parent,const char* name,bool modal,WFlags f) - : QDialog(parent,name,modal,f) -{ - setCaption("Display Configuration"); - QLabel* header=new QLabel("<b>Change the display settings</b>",this); - header->setGeometry(10,10,200,20); - - // - QGroupBox* settings_frame=new QGroupBox("Settings",this); - settings_frame->setGeometry(10,10,220,120); - - small_box=new QRadioButton("Big display, e.g. for QPE Style",settings_frame); - small_box->setGeometry(10,20,200,20); - connect(small_box,SIGNAL(clicked()),this,SLOT(small_clicked())); - - big_box=new QRadioButton("Small display, e.g. for Windows Style",settings_frame); - big_box->setGeometry(10,50,200,20); - connect(big_box,SIGNAL(clicked()),this,SLOT(big_clicked())); - - // - QGroupBox* warning_frame=new QGroupBox("Warning",this); - warning_frame->setGeometry(10,140,220,120); - - warning_box=new QCheckBox("show style warning",warning_frame); - warning_box->setGeometry(10,20,200,20); - connect(warning_box,SIGNAL(clicked()),this,SLOT(warning_clicked())); - - QLabel* warning_help=new QLabel("show style warning at statup if the system style is not QPE\nif not set to small you may have\nscrollbars on the palying area",warning_frame); - warning_help->setGeometry(10,50,200,60); - - showMaximized(); -} - - -DisplayDialog::~DisplayDialog() -{ -} - -void DisplayDialog::big_clicked() -{ - big_box->setChecked(true); - small_box->setChecked(false); -} - -void DisplayDialog::small_clicked() -{ - big_box->setChecked(false); - small_box->setChecked(true); -} - -void DisplayDialog::warning_clicked() -{ -} - -void DisplayDialog::setDisplaySettings(const Display& display) -{ - if(!display.small) - { - big_box->setChecked(false); - small_box->setChecked(true); - } - else - { - big_box->setChecked(true); - small_box->setChecked(false); - } - if(display.warning) - warning_box->setChecked(true); - else - warning_box->setChecked(false); - -} - -Display DisplayDialog::getDisplaySettings() -{ - Display display; - display.small=!small_box->isChecked(); - display.warning=warning_box->isChecked(); - return display; -} - - - - diff --git a/noncore/games/backgammon/displaydialog.h b/noncore/games/backgammon/displaydialog.h deleted file mode 100644 index 26b77f0..0000000 --- a/noncore/games/backgammon/displaydialog.h +++ b/dev/null @@ -1,30 +0,0 @@ -#ifndef DISPLAYDLAOG_H -#define DISPLAYDLAOG_H - -#include <qcheckbox.h> -#include <qdialog.h> -#include <qradiobutton.h> - -#include "definition.h" - - -class DisplayDialog : public QDialog -{ - Q_OBJECT -private: - QRadioButton* small_box; - QRadioButton* big_box; - QCheckBox* warning_box; -public: - DisplayDialog(QWidget* parent=0,const char* name=0,bool modal=TRUE,WFlags f=0); - ~DisplayDialog(); -private slots: - void big_clicked(); - void small_clicked(); - void warning_clicked(); -public: - void setDisplaySettings(const Display& display); - Display getDisplaySettings(); -}; - -#endif //DISPLAYDLAOG_H diff --git a/noncore/games/backgammon/moveengine.cpp b/noncore/games/backgammon/moveengine.cpp index 8106b3f..009c449 100644 --- a/noncore/games/backgammon/moveengine.cpp +++ b/noncore/games/backgammon/moveengine.cpp @@ -1,104 +1,102 @@ #include "moveengine.h" #include <qmessagebox.h> #include <qtimer.h> -#include <stdlib.h> - MoveEngine::MoveEngine() : QObject() { int offset=7; int a=0; //counter variable int xfill[]={210,185,170,155,140,125,110,85,70,55,40,25,10,10,25,40,55,70,85,110,125,140,155,170,185,210}; for(a=0;a<26;a++) { x_coord[a]=xfill[a]; } int yfill[]={10,25,40,55,70,10+offset,25+offset,40+offset,55+offset,25,40,55, 25+offset,40+offset,40}; int zfill[]={1,1,1,1,1,2,2,2,2,3,3,3,4,4,5}; for(a=0;a<15;a++) { yup_coord[a]=yfill[a]; ylow_coord[a]=185-(yfill[a]); z_coord[a]=zfill[a]; } for(a=0;a<5;a++) { if(a<3) { x_fin1[a]=65+a*15; x_fin2[a]=155-a*15; } y_fin[a]=225-a*5; } z_fin=1; reset(); } MoveEngine::~MoveEngine() {} void MoveEngine::position(Pieces& pieces,bool non_qte) { int player1_counter=0; int player2_counter=0; //non qte styles are smaller !! int offset=(non_qte) ? 5 : 0; for(int a=0;a<28;a++) { for(int b=0;b<abs(population[a].total);b++) { if(population[a].total>0) //player 1 pieces { pieces.player1[player1_counter].x=x_coord[a]-offset; if(a>=0 && a<13) { pieces.player1[player1_counter].y=yup_coord[b]-offset; pieces.player1[player1_counter].z=z_coord[b]; pieces.player1[player1_counter].side=false; player1_counter++; } else if(a>12 && a<26) { pieces.player1[player1_counter].y=ylow_coord[b]-offset; pieces.player1[player1_counter].z=z_coord[b]; pieces.player1[player1_counter].side=false; player1_counter++; } else if(a==26) { if(b<5) { pieces.player1[player1_counter].x=x_fin1[0]-offset; pieces.player1[player1_counter].y=y_fin[b]-offset; pieces.player1[player1_counter].z=z_fin; } else if(b>=5 && b<10) { pieces.player1[player1_counter].x=x_fin1[1]-offset; pieces.player1[player1_counter].y=y_fin[b-5]-offset; pieces.player1[player1_counter].z=z_fin; } else { pieces.player1[player1_counter].x=x_fin1[2]-offset; pieces.player1[player1_counter].y=y_fin[b-10]-offset; pieces.player1[player1_counter].z=z_fin; } pieces.player1[player1_counter].side=true; player1_counter++; } } else if(population[a].total<0) //player 2 pieces { pieces.player2[player2_counter].x=x_coord[a]-offset; if(a>=0 && a<13) { diff --git a/noncore/games/backgammon/moveengine.h b/noncore/games/backgammon/moveengine.h index a2d4a52..4c39a04 100644 --- a/noncore/games/backgammon/moveengine.h +++ b/noncore/games/backgammon/moveengine.h @@ -1,76 +1,76 @@ #ifndef MOVEENGINE_H #define MOVEENGINE_H -#include <qobject.h> #include "definition.h" +#include <qobject.h> class MoveEngine : public QObject { Q_OBJECT private: //normal pieses int x_coord[26]; //26 posssible x-positions or piece is not on the board int yup_coord[15]; // the 15 posssible y-positions on the upper half of the board int ylow_coord[15]; // the 15 posssible y-positions on the lower half of the board int z_coord[15]; //the 15 possible z-positionson the board //finshed pieces int x_fin1[3]; int x_fin2[3]; int y_fin[5]; int z_fin; //the board population // |12|11|10|09|08|07|06|05|04|03|02|01|00| // ======================================= // |13|14|15|16|17|18|19|20|21|22|23|24|25| // endzones 26 player1, 27 player 2 Population population[28]; AISettings ai; //move information int player; int otherplayer; int dice[4]; //index of the markers int marker_current; int marker_next[4]; //player pieces are all in the end zone bool allclear[3]; //player must bring pieces back into game bool pieces_out[3]; bool move_with_pieces_out; //player can rescue pieces with dice bigger than move, even if there are poeces "behind" it bool nice_dice; int last_piece[3]; //possible moves Possiblilites moves[26]; public: public: MoveEngine(); ~MoveEngine(); signals: void done_dice1(); void done_dice2(); void done_dice3(); void done_dice4(); void nomove(); void player_finished(int); private slots: void automove(); public: void position(Pieces& pieces,bool non_qte=false); void diceroll(const int& player,const int& face1,const int& face2,const int& face3,const int& face4,bool computer); void boardpressed(const int& x,const int& y,Marker& marker,bool non_qte=false); void reset(); void loadGame(const LoadSave& load); LoadSave saveGame(); AISettings getAISettings(); void setAISettings(const AISettings& new_ai); void setRules(Rules rules); private: int getPossibleMoves(); void move(const int& from, int to, const int& dice); void checkstate(); void nomarker(Marker& marker); int fieldColor(const int& index) const; }; #endif //MOVEENGINE_H diff --git a/noncore/games/backgammon/rulesdialog.h b/noncore/games/backgammon/rulesdialog.h index 9269a0e..f11a28c 100644 --- a/noncore/games/backgammon/rulesdialog.h +++ b/noncore/games/backgammon/rulesdialog.h @@ -1,27 +1,26 @@ #ifndef RULESDIALOG_H_ #define RULESDIALOG_H_ #include <qcheckbox.h> #include <qdialog.h> #include "definition.h" - class RulesDialog : public QDialog { Q_OBJECT private: QCheckBox* pieces_out; QCheckBox* nice_dice; Rules rules; public: RulesDialog(QWidget* parent=0,const char* name=0,bool modal=TRUE,WFlags f=0); ~RulesDialog(); private slots: void pieces_out_clicked(); void nice_dice_clicked(); public: void setRules(const Rules& new_rules); Rules getRules(); }; #endif //RULESDIALOG_H |