-rw-r--r-- | noncore/games/backgammon/backgammon.pro | 4 | ||||
-rw-r--r-- | noncore/games/backgammon/backgammonview.h | 1 | ||||
-rw-r--r-- | noncore/games/backgammon/moveengine.cpp | 2 |
3 files changed, 4 insertions, 3 deletions
diff --git a/noncore/games/backgammon/backgammon.pro b/noncore/games/backgammon/backgammon.pro index 6f77a14..4be9491 100644 --- a/noncore/games/backgammon/backgammon.pro +++ b/noncore/games/backgammon/backgammon.pro @@ -1,34 +1,34 @@ TEMPLATE = app CONFIG = qt warn_on release HEADERS = backgammon.h \ + backgammonview.h \ canvasimageitem.h \ themedialog.h \ moveengine.h \ filedialog.h \ playerdialog.h \ aidialog.h \ rulesdialog.h \ - displaydialog.h \ definition.h SOURCES = main.cpp \ backgammon.cpp \ + backgammonview.cpp \ canvasimageitem.cpp \ themedialog.cpp \ moveengine.cpp \ filedialog.cpp \ playerdialog.cpp \ aidialog.cpp \ rulesdialog.cpp \ - displaydialog.cpp \ definition.cpp TARGET = backgammon INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include LIBS += -lqpe -lstdc++ DESTDIR = $(OPIEDIR)/bin include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/games/backgammon/backgammonview.h b/noncore/games/backgammon/backgammonview.h index 52508e2..81f1973 100644 --- a/noncore/games/backgammon/backgammonview.h +++ b/noncore/games/backgammon/backgammonview.h @@ -1,18 +1,19 @@ #ifndef BACKGAMMON_VIEW_H #define BACKGAMMON_VIEW_H #include <qcanvas.h> class BackGammonView : public QCanvasView { Q_OBJECT public: BackGammonView(QCanvas* canvas,QWidget* parent); ~BackGammonView(); signals: void mouse(int,int); private: void contentsMousePressEvent(QMouseEvent* e); }; #endif //BACKGAMMON_VIEW_H
\ No newline at end of file + diff --git a/noncore/games/backgammon/moveengine.cpp b/noncore/games/backgammon/moveengine.cpp index 009c449..37b73a6 100644 --- a/noncore/games/backgammon/moveengine.cpp +++ b/noncore/games/backgammon/moveengine.cpp @@ -1,261 +1,261 @@ #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) { pieces.player2[player2_counter].y=yup_coord[b]-offset; pieces.player2[player2_counter].z=z_coord[b]; pieces.player2[player2_counter].side=false; player2_counter++; } else if(a>12 && a<26) { pieces.player2[player2_counter].y=ylow_coord[b]-offset; pieces.player2[player2_counter].z=z_coord[b]; pieces.player2[player2_counter].side=false; player2_counter++; } else if(a==27) { if(b<5) { pieces.player2[player2_counter].x=x_fin2[0]-offset; pieces.player2[player2_counter].y=y_fin[b]-offset; pieces.player2[player2_counter].z=z_fin; } else if(b>=5 && b<10) { pieces.player2[player2_counter].x=x_fin2[1]-offset; pieces.player2[player2_counter].y=y_fin[b-5]-offset; pieces.player2[player2_counter].z=z_fin; } else { pieces.player2[player2_counter].x=x_fin2[2]-offset; pieces.player2[player2_counter].y=y_fin[b-10]-offset; pieces.player2[player2_counter].z=z_fin; } pieces.player2[player2_counter].side=true; player2_counter++; } } } } } void MoveEngine::diceroll(const int& newplayer,const int& face1,const int& face2,const int& face3,const int& face4,bool computer) { checkstate(); player=newplayer; otherplayer=(player==1) ? 2 : 1; dice[0]=face1; dice[1]=face2; dice[2]=face3; dice[3]=face4; marker_current=-1; if(getPossibleMoves()==0) { emit nomove(); return; // player will be changed } if(!computer) return; //human intervention required QTimer::singleShot(2000,this,SLOT(automove())); } void MoveEngine::automove() { //the maximimum possibility int maxpos=0; //the position in the moves array int from=-1; int to=-1; //dice1 or dice 2 ?? int index_dice=0; for(int counter=0;counter<26;counter++) { int a=(player==1) ? counter : 25-counter; for(int b=0;b<4;b++) { if(moves[a].weight[b]>maxpos) { maxpos=moves[a].weight[b]; from=a; to=moves[a].to[b]; index_dice=b+1; } } } move(from,to,index_dice); } void MoveEngine::boardpressed(const int& x,const int& y,Marker& marker,bool non_qte) { //get the position of the mouse click bool upper=true; bool found=false; int offset=(non_qte) ? 5 : 0; if(y<=85) // board slots 0 to 12 marker.y_current=0; else if(y>=105) //board slots 13 to 25 { marker.y_current=195-2*offset; upper=false; } int index=13; // the clicked board slot while(index<25 && !found) { if(x>=x_coord[index] && x<x_coord[index+1]) { marker.x_current=x_coord[index]; found=true; ; } else { index++; } } if(!found) { marker.x_current=x_coord[25]; index=25; } if(upper) { index=25-index; } int a=0; int usedice=-1; int dice_value=7; for(a=0;a<4;a++) { if(index==marker_next[a] && marker_next[a]!=-1 && dice_value>dice[a]) { usedice=a; dice_value=dice[0]; } } if(usedice!=-1) { move(marker_current,marker_next[usedice],usedice+1); nomarker(marker); return; } if(dice[0]==7 && dice[1]==7 && dice[2]==7 && dice[3]==7) //no dice rolled { nomarker(marker); return; } else if(fieldColor(index)==player) { marker.visible_current=true; |