summaryrefslogtreecommitdiff
path: root/noncore/games/backgammon/backgammon.cpp
Unidiff
Diffstat (limited to 'noncore/games/backgammon/backgammon.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/backgammon/backgammon.cpp48
1 files changed, 24 insertions, 24 deletions
diff --git a/noncore/games/backgammon/backgammon.cpp b/noncore/games/backgammon/backgammon.cpp
index c40f462..06523f1 100644
--- a/noncore/games/backgammon/backgammon.cpp
+++ b/noncore/games/backgammon/backgammon.cpp
@@ -4,49 +4,49 @@
4#include "filedialog.h" 4#include "filedialog.h"
5#include "playerdialog.h" 5#include "playerdialog.h"
6#include "rulesdialog.h" 6#include "rulesdialog.h"
7#include "themedialog.h" 7#include "themedialog.h"
8 8
9#include <qdatetime.h> 9#include <qdatetime.h>
10#include <qfile.h> 10#include <qfile.h>
11#include <qlayout.h> 11#include <qlayout.h>
12#include <qmessagebox.h> 12#include <qmessagebox.h>
13#include <qstring.h> 13#include <qstring.h>
14#include <qtimer.h> 14#include <qtimer.h>
15#include <qmainwindow.h> 15#include <qmainwindow.h>
16#include <qpe/qpeapplication.h> 16#include <qpe/qpeapplication.h>
17#include <qpe/config.h> 17#include <qpe/config.h>
18#include <qpe/qpemenubar.h> 18#include <qpe/qpemenubar.h>
19#include <qpe/resource.h> 19#include <qpe/resource.h>
20 20
21#include <stdlib.h> 21#include <stdlib.h>
22 22
23 23
24BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl) 24BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl)
25 : QMainWindow(parent, name, fl) 25 : QMainWindow(parent, name, fl)
26{ 26{
27 if (!name) setName("BackGammon"); 27 if (!name) setName("BackGammon");
28 setCaption("Backgammon"); 28 setCaption(tr( "Backgammon") );
29 setIcon( Resource::loadPixmap( "backgammon" ) ); 29 setIcon( Resource::loadPixmap( "backgammon" ) );
30 //general counter varaible 30 //general counter varaible
31 int a=0; 31 int a=0;
32 //the game engine 32 //the game engine
33 move=new MoveEngine(); 33 move=new MoveEngine();
34 34
35 //load the default theme 35 //load the default theme
36 Config conf("backgammon"); 36 Config conf("backgammon");
37 if(!conf.isValid()) 37 if(!conf.isValid())
38 { 38 {
39 qDebug("config file does not exist"); 39 qDebug("config file does not exist");
40 conf.setGroup("general"); 40 conf.setGroup("general");
41 conf.writeEntry("theme","default"); 41 conf.writeEntry("theme","default");
42 conf.setGroup("rules"); 42 conf.setGroup("rules");
43 conf.writeEntry("move_with_pieces_out",false); 43 conf.writeEntry("move_with_pieces_out",false);
44 conf.writeEntry("nice_dice",false); 44 conf.writeEntry("nice_dice",false);
45 conf.setGroup("display"); 45 conf.setGroup("display");
46 conf.writeEntry("small",false); 46 conf.writeEntry("small",false);
47 conf.writeEntry("warning",true); 47 conf.writeEntry("warning",true);
48 conf.setGroup("ai"); 48 conf.setGroup("ai");
49 conf.writeEntry("rescue",6); 49 conf.writeEntry("rescue",6);
50 conf.writeEntry("eliminate",4); 50 conf.writeEntry("eliminate",4);
51 conf.writeEntry("expose",1); 51 conf.writeEntry("expose",1);
52 conf.writeEntry("protect",5); 52 conf.writeEntry("protect",5);
@@ -84,72 +84,72 @@ BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl)
84 qDebug("theme file does not exist"); 84 qDebug("theme file does not exist");
85 theme.setGroup("theme"); 85 theme.setGroup("theme");
86 theme.writeEntry("board","casino_board_1"); 86 theme.writeEntry("board","casino_board_1");
87 theme.writeEntry("pieces1","casino_pieces_blue"); 87 theme.writeEntry("pieces1","casino_pieces_blue");
88 theme.writeEntry("pieces2","casino_pieces_white"); 88 theme.writeEntry("pieces2","casino_pieces_white");
89 theme.writeEntry("dice1","casino_dice"); 89 theme.writeEntry("dice1","casino_dice");
90 theme.writeEntry("dice2","casino_dice"); 90 theme.writeEntry("dice2","casino_dice");
91 theme.writeEntry("table","casino_table_green"); 91 theme.writeEntry("table","casino_table_green");
92 theme.writeEntry("odds","casino_odds"); 92 theme.writeEntry("odds","casino_odds");
93 } 93 }
94 theme.setGroup("theme"); 94 theme.setGroup("theme");
95 board_name=theme.readEntry("board","casino_board_1"); 95 board_name=theme.readEntry("board","casino_board_1");
96 piecesA_name=theme.readEntry("pieces1","casino_pieces_blue"); 96 piecesA_name=theme.readEntry("pieces1","casino_pieces_blue");
97 piecesB_name=theme.readEntry("pieces2","casino_pieces_white"); 97 piecesB_name=theme.readEntry("pieces2","casino_pieces_white");
98 diceA_name=theme.readEntry("dice1","casino_dice"); 98 diceA_name=theme.readEntry("dice1","casino_dice");
99 diceB_name=theme.readEntry("dice2","casino_dice"); 99 diceB_name=theme.readEntry("dice2","casino_dice");
100 table_name=theme.readEntry("table","casino_table_green"); 100 table_name=theme.readEntry("table","casino_table_green");
101 odds_name=theme.readEntry("odds","casino_odds"); 101 odds_name=theme.readEntry("odds","casino_odds");
102 102
103 103
104 //the menu 104 //the menu
105 QPEMenuBar* menuBar = new QPEMenuBar(this); 105 QPEMenuBar* menuBar = new QPEMenuBar(this);
106 106
107 QPopupMenu* gamemenu= new QPopupMenu(this); 107 QPopupMenu* gamemenu= new QPopupMenu(this);
108 gamemenu->insertItem("New",this,SLOT(newgame())); 108 gamemenu->insertItem(tr( "New" ),this,SLOT(newgame()));
109 gamemenu->insertSeparator(); 109 gamemenu->insertSeparator();
110 gamemenu->insertItem("Load",this,SLOT(loadgame())); 110 gamemenu->insertItem(tr( "Load" ),this,SLOT(loadgame()));
111 gamemenu->insertItem("Save",this,SLOT(savegame())); 111 gamemenu->insertItem(tr( "Save" ),this,SLOT(savegame()));
112 gamemenu->insertSeparator(); 112 gamemenu->insertSeparator();
113 gamemenu->insertItem("Delete",this,SLOT(deletegame())); 113 gamemenu->insertItem(tr( "Delete" ),this,SLOT(deletegame()));
114 menuBar->insertItem("Game",gamemenu); 114 menuBar->insertItem(tr( "Game" ),gamemenu);
115 115
116 QPopupMenu* thememenu= new QPopupMenu(this); 116 QPopupMenu* thememenu= new QPopupMenu(this);
117 thememenu->insertItem("New",this,SLOT(newtheme())); 117 thememenu->insertItem(tr( "New" ),this,SLOT(newtheme()));
118 thememenu->insertSeparator(); 118 thememenu->insertSeparator();
119 thememenu->insertItem("Load",this,SLOT(loadtheme())); 119 thememenu->insertItem(tr( "Load"),this,SLOT(loadtheme()));
120 thememenu->insertItem("Save",this,SLOT(savetheme())); 120 thememenu->insertItem(tr( "Save" ),this,SLOT(savetheme()));
121 thememenu->insertSeparator(); 121 thememenu->insertSeparator();
122 thememenu->insertItem("Default",this,SLOT(themedefault())); 122 thememenu->insertItem(tr( "Default"),this,SLOT(themedefault()));
123 thememenu->insertItem("Delete",this,SLOT(deletetheme())); 123 thememenu->insertItem(tr( "Delete" ),this,SLOT(deletetheme()));
124 menuBar->insertItem("Theme",thememenu); 124 menuBar->insertItem(tr( "Theme" ),thememenu);
125 125
126 QPopupMenu* optionmenu=new QPopupMenu(this); 126 QPopupMenu* optionmenu=new QPopupMenu(this);
127 optionmenu->insertItem("Player",this,SLOT(playerselect())); 127 optionmenu->insertItem(tr( "Player" ),this,SLOT(playerselect()));
128 optionmenu->insertSeparator(); 128 optionmenu->insertSeparator();
129 optionmenu->insertItem("AI",this,SLOT(modify_AI())); 129 optionmenu->insertItem(tr( "AI" ),this,SLOT(modify_AI()));
130 optionmenu->insertItem("Rules",this,SLOT(setrules())); 130 optionmenu->insertItem(tr( "Rules" ),this,SLOT(setrules()));
131 menuBar->insertItem("Options",optionmenu); 131 menuBar->insertItem(tr( "Options"),optionmenu);
132 132
133 QWidget* mainarea=new QWidget(this); 133 QWidget* mainarea=new QWidget(this);
134 setCentralWidget(mainarea); 134 setCentralWidget(mainarea);
135 //the main area 135 //the main area
136 QBoxLayout* layout=new QBoxLayout(mainarea,QBoxLayout::TopToBottom); 136 QBoxLayout* layout=new QBoxLayout(mainarea,QBoxLayout::TopToBottom);
137 area=new QCanvas(235,235); 137 area=new QCanvas(235,235);
138 boardview=new BackGammonView(area,mainarea); 138 boardview=new BackGammonView(area,mainarea);
139 boardview->setMaximumHeight(240); 139 boardview->setMaximumHeight(240);
140 layout->addWidget(boardview); 140 layout->addWidget(boardview);
141 connect(boardview,SIGNAL(mouse(int,int)),this,SLOT(mouse(int,int))); 141 connect(boardview,SIGNAL(mouse(int,int)),this,SLOT(mouse(int,int)));
142 //status bar 142 //status bar
143 message=new QLabel("<b>Backgammon</b>",mainarea); 143 message=new QLabel("<b>Backgammon</b>",mainarea);
144 message->setAlignment(AlignHCenter); 144 message->setAlignment(AlignHCenter);
145 layout->addWidget(message); 145 layout->addWidget(message);
146 146
147 //the marker 147 //the marker
148 marker_current=new QCanvasRectangle(area); 148 marker_current=new QCanvasRectangle(area);
149 marker_current->setBrush(QColor(0,0,255)); 149 marker_current->setBrush(QColor(0,0,255));
150 marker_current->setSize(15,5); 150 marker_current->setSize(15,5);
151 marker_current->setZ(1); 151 marker_current->setZ(1);
152 152
153 for(a=0;a<4;a++) 153 for(a=0;a<4;a++)
154 { 154 {
155 marker_next[a]=new QCanvasRectangle(area); 155 marker_next[a]=new QCanvasRectangle(area);
@@ -489,78 +489,78 @@ void BackGammon::savetheme()
489 theme.writeEntry("table",table_name); 489 theme.writeEntry("table",table_name);
490 theme.writeEntry("odds",odds_name); 490 theme.writeEntry("odds",odds_name);
491 491
492} 492}
493 493
494void BackGammon::themedefault() 494void BackGammon::themedefault()
495{ 495{
496 if(QMessageBox::information(this,"Backgammon","Make Theme\n"+theme_name+"\nthe default theme","Yes","No")) 496 if(QMessageBox::information(this,"Backgammon","Make Theme\n"+theme_name+"\nthe default theme","Yes","No"))
497 return; 497 return;
498 498
499 Config conf("backgammon"); 499 Config conf("backgammon");
500 conf.setGroup("general"); 500 conf.setGroup("general");
501 conf.writeEntry("theme",theme_name); 501 conf.writeEntry("theme",theme_name);
502} 502}
503 503
504void BackGammon::deletetheme() 504void BackGammon::deletetheme()
505{ 505{
506 FileDialog* file=new FileDialog(this,"Delete Theme",".theme"); 506 FileDialog* file=new FileDialog(this,"Delete Theme",".theme");
507 if(!file->exec()) 507 if(!file->exec())
508 return; 508 return;
509 509
510 theme_name=file->filename(); 510 theme_name=file->filename();
511 QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; 511 QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme";
512 512
513 if(!QMessageBox::warning(this,"Backgammon","deleted theme "+theme_name+" ?","OK","Cancel")) 513 if(!QMessageBox::warning(this,tr( "Backgammon" ),tr( "deleted theme %1?").arg(theme_name),tr( "OK" ),tr( "Cancel" )))
514 { 514 {
515 QFile(theme_file).remove(); 515 QFile(theme_file).remove();
516 } 516 }
517} 517}
518 518
519void BackGammon::modify_AI() 519void BackGammon::modify_AI()
520{ 520{
521 AI_Dialog* ai_mod=new AI_Dialog(this,"Load Theme",".theme"); 521 AI_Dialog* ai_mod=new AI_Dialog(this,tr( "Load Theme" ),".theme");
522 ai_mod->setAISettings(move->getAISettings()); 522 ai_mod->setAISettings(move->getAISettings());
523 if(!ai_mod->exec()) 523 if(!ai_mod->exec())
524 return; 524 return;
525 525
526 //get the AI settings 526 //get the AI settings
527 AISettings ai=ai_mod->getAISettings(); 527 AISettings ai=ai_mod->getAISettings();
528 move->setAISettings(ai); 528 move->setAISettings(ai);
529 //write new settings to conf file 529 //write new settings to conf file
530 Config conf("backgammon"); 530 Config conf("backgammon");
531 conf.setGroup("ai"); 531 conf.setGroup("ai");
532 conf.writeEntry("rescue",ai.rescue); 532 conf.writeEntry("rescue",ai.rescue);
533 conf.writeEntry("eliminate",ai.eliminate); 533 conf.writeEntry("eliminate",ai.eliminate);
534 conf.writeEntry("expose",ai.expose); 534 conf.writeEntry("expose",ai.expose);
535 conf.writeEntry("protect",ai.protect); 535 conf.writeEntry("protect",ai.protect);
536 conf.writeEntry("safe",ai.safe); 536 conf.writeEntry("safe",ai.safe);
537 conf.writeEntry("empty",ai.empty); 537 conf.writeEntry("empty",ai.empty);
538} 538}
539 539
540void BackGammon::setrules() 540void BackGammon::setrules()
541{ 541{
542 RulesDialog* rulesdialog=new RulesDialog(this,"Load Theme",".theme"); 542 RulesDialog* rulesdialog=new RulesDialog(this,tr( "Load Theme" ),".theme");
543 rulesdialog->setRules(rules); 543 rulesdialog->setRules(rules);
544 if(!rulesdialog->exec()) 544 if(!rulesdialog->exec())
545 return; 545 return;
546 rules=rulesdialog->getRules(); 546 rules=rulesdialog->getRules();
547 Config conf("backgammon"); 547 Config conf("backgammon");
548 conf.setGroup("rules"); 548 conf.setGroup("rules");
549 conf.writeEntry("move_with_pieces_out",rules.move_with_pieces_out); 549 conf.writeEntry("move_with_pieces_out",rules.move_with_pieces_out);
550 conf.writeEntry("nice_dice",rules.generous_dice); 550 conf.writeEntry("nice_dice",rules.generous_dice);
551 move->setRules(rules); 551 move->setRules(rules);
552} 552}
553 553
554 554
555void BackGammon::draw() 555void BackGammon::draw()
556{ 556{
557 Pieces pieces; 557 Pieces pieces;
558 move->position(pieces); 558 move->position(pieces);
559 for(int a=0;a<15;a++) 559 for(int a=0;a<15;a++)
560 { 560 {
561 if(!pieces.player1[a].side) 561 if(!pieces.player1[a].side)
562 { 562 {
563 p1[a]->setX(pieces.player1[a].x); 563 p1[a]->setX(pieces.player1[a].x);
564 p1[a]->setY(pieces.player1[a].y); 564 p1[a]->setY(pieces.player1[a].y);
565 p1[a]->setZ(pieces.player1[a].z); 565 p1[a]->setZ(pieces.player1[a].z);
566 p1[a]->show(); 566 p1[a]->show();
@@ -778,87 +778,87 @@ void BackGammon::done_dice4()
778 showdice(); 778 showdice();
779 draw(); 779 draw();
780 area->update(); 780 area->update();
781 if(!dice1_played || !dice2_played || !dice3_played) 781 if(!dice1_played || !dice2_played || !dice3_played)
782 { 782 {
783 if(player==1) 783 if(player==1)
784 { 784 {
785 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); 785 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto);
786 } 786 }
787 else 787 else
788 { 788 {
789 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); 789 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto);
790 } 790 }
791 } 791 }
792} 792}
793 793
794 794
795void BackGammon::nomove() 795void BackGammon::nomove()
796{ 796{
797 if(player==1) 797 if(player==1)
798 nomove_marker->setX(0); 798 nomove_marker->setX(0);
799 else 799 else
800 nomove_marker->setX(170); 800 nomove_marker->setX(170);
801 nomove_marker->show(); 801 nomove_marker->show();
802 message->setText("<b>no move</b>"); 802 message->setText(tr( "<b>no move</b>" ));
803 dice1_played=true; 803 dice1_played=true;
804 dice2_played=true; 804 dice2_played=true;
805 dice3_played=true; 805 dice3_played=true;
806 dice4_played=true; 806 dice4_played=true;
807 if(player==1) 807 if(player==1)
808 { 808 {
809 diceA1_value=7; 809 diceA1_value=7;
810 diceA2_value=7; 810 diceA2_value=7;
811 diceA3_value=7; 811 diceA3_value=7;
812 diceA4_value=7; 812 diceA4_value=7;
813 } 813 }
814 else 814 else
815 { 815 {
816 diceB1_value=7; 816 diceB1_value=7;
817 diceB2_value=7; 817 diceB2_value=7;
818 diceB3_value=7; 818 diceB3_value=7;
819 diceB4_value=7; 819 diceB4_value=7;
820 } 820 }
821 area->update(); 821 area->update();
822 QTimer::singleShot(2000,this,SLOT(nomove2())); 822 QTimer::singleShot(2000,this,SLOT(nomove2()));
823} 823}
824 824
825void BackGammon::nomove2() 825void BackGammon::nomove2()
826{ 826{
827 nomove_marker->hide(); 827 nomove_marker->hide();
828 setplayer(); 828 setplayer();
829 showdice(); 829 showdice();
830 draw(); 830 draw();
831 area->update(); 831 area->update();
832} 832}
833 833
834void BackGammon::finished(int theplayer) 834void BackGammon::finished(int theplayer)
835{ 835{
836 nomove_marker->hide(); 836 nomove_marker->hide();
837 if(theplayer==1) 837 if(theplayer==1)
838 message->setText("<b>Player 1 wins. Click on board for new game.</b>"); 838 message->setText(tr( "<b>Player 1 wins. Click on board for new game.</b>" ));
839 else 839 else
840 message->setText("<b>Player 2 wins. Click on board for new game.</b>"); 840 message->setText(tr( "<b>Player 2 wins. Click on board for new game.</b>" ));
841 diceA1_value=7; 841 diceA1_value=7;
842 diceA2_value=7; 842 diceA2_value=7;
843 diceB1_value=7; 843 diceB1_value=7;
844 diceB2_value=7; 844 diceB2_value=7;
845 player=0; 845 player=0;
846 showdice(); 846 showdice();
847 draw(); 847 draw();
848 area->update(); 848 area->update();
849 gameFinished=true; 849 gameFinished=true;
850} 850}
851 851
852void BackGammon::showdice() 852void BackGammon::showdice()
853{ 853{
854 int value_diceA1=diceA1_value-1; 854 int value_diceA1=diceA1_value-1;
855 if(diceA1_value==7 && diceA3_value!=7) 855 if(diceA1_value==7 && diceA3_value!=7)
856 value_diceA1=diceA3_value-1; 856 value_diceA1=diceA3_value-1;
857 857
858 int value_diceA2=diceA2_value-1; 858 int value_diceA2=diceA2_value-1;
859 if(diceA2_value==7 && diceA4_value!=7) 859 if(diceA2_value==7 && diceA4_value!=7)
860 value_diceA2=diceA4_value-1; 860 value_diceA2=diceA4_value-1;
861 861
862 int value_diceB1=diceB1_value-1; 862 int value_diceB1=diceB1_value-1;
863 if(diceB1_value==7 && diceB3_value!=7) 863 if(diceB1_value==7 && diceB3_value!=7)
864 value_diceB1=diceB3_value-1; 864 value_diceB1=diceB3_value-1;
@@ -874,57 +874,57 @@ void BackGammon::showdice()
874 else 874 else
875 diceA1[index]->hide(); 875 diceA1[index]->hide();
876 876
877 if(value_diceA2==index) 877 if(value_diceA2==index)
878 diceA2[index]->show(); 878 diceA2[index]->show();
879 else 879 else
880 diceA2[index]->hide(); 880 diceA2[index]->hide();
881 881
882 if(value_diceB1==index) 882 if(value_diceB1==index)
883 diceB1[index]->show(); 883 diceB1[index]->show();
884 else 884 else
885 diceB1[index]->hide(); 885 diceB1[index]->hide();
886 886
887 if(value_diceB2==index) 887 if(value_diceB2==index)
888 diceB2[index]->show(); 888 diceB2[index]->show();
889 else 889 else
890 diceB2[index]->hide(); 890 diceB2[index]->hide();
891 } 891 }
892} 892}
893 893
894void BackGammon::setplayer() 894void BackGammon::setplayer()
895{ 895{
896 if(dice1_played && dice2_played && dice3_played && dice4_played && player==1) 896 if(dice1_played && dice2_played && dice3_played && dice4_played && player==1)
897 { 897 {
898 message->setText("<b>P2 turn</b>"); 898 message->setText(tr( "<b>P2 turn</b>", "P means player" ));
899 dice_rolled=false; 899 dice_rolled=false;
900 player=2; 900 player=2;
901 if(player2_auto) 901 if(player2_auto)
902 QTimer::singleShot(2000,this,SLOT(autoroll_dice2())); 902 QTimer::singleShot(2000,this,SLOT(autoroll_dice2()));
903 } 903 }
904 else if(dice1_played && dice2_played && dice3_played && dice4_played && player==2) 904 else if(dice1_played && dice2_played && dice3_played && dice4_played && player==2)
905 { 905 {
906 message->setText("<b>P1 turn</b>"); 906 message->setText(tr( "<b>P1 turn</b>", "P means player" ));
907 dice_rolled=false; 907 dice_rolled=false;
908 player=1; 908 player=1;
909 if(player1_auto) 909 if(player1_auto)
910 QTimer::singleShot(2000,this,SLOT(autoroll_dice1())); 910 QTimer::singleShot(2000,this,SLOT(autoroll_dice1()));
911 } 911 }
912} 912}
913 913
914void BackGammon::autoroll_dice1() 914void BackGammon::autoroll_dice1()
915{ 915{
916 mouse(20,210); 916 mouse(20,210);
917} 917}
918 918
919void BackGammon::autoroll_dice2() 919void BackGammon::autoroll_dice2()
920{ 920{
921 mouse(170,210); 921 mouse(170,210);
922} 922}
923 923
924void BackGammon::applytheme() 924void BackGammon::applytheme()
925{ 925{
926 QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name)); 926 QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name));
927 board->setImage(boardbg); 927 board->setImage(boardbg);
928 928
929 QImage tablebg(Resource::loadImage("backgammon/table/"+table_name)); 929 QImage tablebg(Resource::loadImage("backgammon/table/"+table_name));
930 table->setImage(tablebg); 930 table->setImage(tablebg);