author | mickeyl <mickeyl> | 2003-05-17 13:52:25 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-05-17 13:52:25 (UTC) |
commit | 1aa5c1fc6ef4b7b4e520e6265e6b53c18f025b83 (patch) (unidiff) | |
tree | 6e98d8318cb9d99c9daa986e273ba6c4ed8d6dfc | |
parent | bc581ecfb47325fc6b8c8558b596f643002401b6 (diff) | |
download | opie-1aa5c1fc6ef4b7b4e520e6265e6b53c18f025b83.zip opie-1aa5c1fc6ef4b7b4e520e6265e6b53c18f025b83.tar.gz opie-1aa5c1fc6ef4b7b4e520e6265e6b53c18f025b83.tar.bz2 |
backgammon compiles again
-rw-r--r-- | noncore/games/backgammon/backgammon.pro | 38 | ||||
-rw-r--r-- | noncore/games/backgammon/backgammonview.h | 3 | ||||
-rw-r--r-- | noncore/games/backgammon/moveengine.cpp | 2 |
3 files changed, 22 insertions, 21 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 @@ | |||
1 | TEMPLATE = app | 1 | TEMPLATE = app |
2 | CONFIG = qt warn_on release | 2 | CONFIG = qt warn_on release |
3 | 3 | ||
4 | HEADERS = backgammon.h \ | 4 | HEADERS = backgammon.h \ |
5 | canvasimageitem.h \ | 5 | backgammonview.h \ |
6 | themedialog.h \ | 6 | canvasimageitem.h \ |
7 | moveengine.h \ | 7 | themedialog.h \ |
8 | filedialog.h \ | 8 | moveengine.h \ |
9 | playerdialog.h \ | 9 | filedialog.h \ |
10 | aidialog.h \ | 10 | playerdialog.h \ |
11 | rulesdialog.h \ | 11 | aidialog.h \ |
12 | displaydialog.h \ | 12 | rulesdialog.h \ |
13 | definition.h | 13 | definition.h |
14 | 14 | ||
15 | SOURCES = main.cpp \ | 15 | SOURCES = main.cpp \ |
16 | backgammon.cpp \ | 16 | backgammon.cpp \ |
17 | canvasimageitem.cpp \ | 17 | backgammonview.cpp \ |
18 | themedialog.cpp \ | 18 | canvasimageitem.cpp \ |
19 | moveengine.cpp \ | 19 | themedialog.cpp \ |
20 | filedialog.cpp \ | 20 | moveengine.cpp \ |
21 | playerdialog.cpp \ | 21 | filedialog.cpp \ |
22 | aidialog.cpp \ | 22 | playerdialog.cpp \ |
23 | rulesdialog.cpp \ | 23 | aidialog.cpp \ |
24 | displaydialog.cpp \ | 24 | rulesdialog.cpp \ |
25 | definition.cpp | 25 | definition.cpp |
26 | 26 | ||
27 | TARGET = backgammon | 27 | TARGET = backgammon |
28 | INCLUDEPATH+= $(OPIEDIR)/include | 28 | INCLUDEPATH+= $(OPIEDIR)/include |
29 | DEPENDPATH+= $(OPIEDIR)/include | 29 | DEPENDPATH+= $(OPIEDIR)/include |
30 | LIBS += -lqpe -lstdc++ | 30 | LIBS += -lqpe -lstdc++ |
31 | DESTDIR = $(OPIEDIR)/bin | 31 | DESTDIR = $(OPIEDIR)/bin |
32 | 32 | ||
33 | 33 | ||
34 | include ( $(OPIEDIR)/include.pro ) | 34 | 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 @@ | |||
1 | #ifndef BACKGAMMON_VIEW_H | 1 | #ifndef BACKGAMMON_VIEW_H |
2 | #define BACKGAMMON_VIEW_H | 2 | #define BACKGAMMON_VIEW_H |
3 | 3 | ||
4 | #include <qcanvas.h> | 4 | #include <qcanvas.h> |
5 | 5 | ||
6 | class BackGammonView : public QCanvasView | 6 | class BackGammonView : public QCanvasView |
7 | { | 7 | { |
8 | Q_OBJECT | 8 | Q_OBJECT |
9 | public: | 9 | public: |
10 | BackGammonView(QCanvas* canvas,QWidget* parent); | 10 | BackGammonView(QCanvas* canvas,QWidget* parent); |
11 | ~BackGammonView(); | 11 | ~BackGammonView(); |
12 | signals: | 12 | signals: |
13 | void mouse(int,int); | 13 | void mouse(int,int); |
14 | private: | 14 | private: |
15 | void contentsMousePressEvent(QMouseEvent* e); | 15 | void contentsMousePressEvent(QMouseEvent* e); |
16 | }; | 16 | }; |
17 | 17 | ||
18 | #endif //BACKGAMMON_VIEW_H \ No newline at end of file | 18 | #endif //BACKGAMMON_VIEW_H |
19 | |||
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,197 +1,197 @@ | |||
1 | #include "moveengine.h" | 1 | #include "moveengine.h" |
2 | 2 | ||
3 | #include <qmessagebox.h> | 3 | #include <qmessagebox.h> |
4 | |||
5 | #include <qtimer.h> | 4 | #include <qtimer.h> |
5 | #include <stdlib.h> | ||
6 | 6 | ||
7 | MoveEngine::MoveEngine() | 7 | MoveEngine::MoveEngine() |
8 | : QObject() | 8 | : QObject() |
9 | { | 9 | { |
10 | int offset=7; | 10 | int offset=7; |
11 | int a=0; //counter variable | 11 | int a=0; //counter variable |
12 | 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}; | 12 | 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}; |
13 | for(a=0;a<26;a++) | 13 | for(a=0;a<26;a++) |
14 | { | 14 | { |
15 | x_coord[a]=xfill[a]; | 15 | x_coord[a]=xfill[a]; |
16 | } | 16 | } |
17 | 17 | ||
18 | int yfill[]={10,25,40,55,70,10+offset,25+offset,40+offset,55+offset,25,40,55, 25+offset,40+offset,40}; | 18 | int yfill[]={10,25,40,55,70,10+offset,25+offset,40+offset,55+offset,25,40,55, 25+offset,40+offset,40}; |
19 | int zfill[]={1,1,1,1,1,2,2,2,2,3,3,3,4,4,5}; | 19 | int zfill[]={1,1,1,1,1,2,2,2,2,3,3,3,4,4,5}; |
20 | for(a=0;a<15;a++) | 20 | for(a=0;a<15;a++) |
21 | { | 21 | { |
22 | yup_coord[a]=yfill[a]; | 22 | yup_coord[a]=yfill[a]; |
23 | ylow_coord[a]=185-(yfill[a]); | 23 | ylow_coord[a]=185-(yfill[a]); |
24 | z_coord[a]=zfill[a]; | 24 | z_coord[a]=zfill[a]; |
25 | } | 25 | } |
26 | for(a=0;a<5;a++) | 26 | for(a=0;a<5;a++) |
27 | { | 27 | { |
28 | if(a<3) | 28 | if(a<3) |
29 | { | 29 | { |
30 | x_fin1[a]=65+a*15; | 30 | x_fin1[a]=65+a*15; |
31 | x_fin2[a]=155-a*15; | 31 | x_fin2[a]=155-a*15; |
32 | } | 32 | } |
33 | y_fin[a]=225-a*5; | 33 | y_fin[a]=225-a*5; |
34 | } | 34 | } |
35 | z_fin=1; | 35 | z_fin=1; |
36 | 36 | ||
37 | reset(); | 37 | reset(); |
38 | } | 38 | } |
39 | 39 | ||
40 | MoveEngine::~MoveEngine() | 40 | MoveEngine::~MoveEngine() |
41 | {} | 41 | {} |
42 | 42 | ||
43 | void MoveEngine::position(Pieces& pieces,bool non_qte) | 43 | void MoveEngine::position(Pieces& pieces,bool non_qte) |
44 | { | 44 | { |
45 | int player1_counter=0; | 45 | int player1_counter=0; |
46 | int player2_counter=0; | 46 | int player2_counter=0; |
47 | 47 | ||
48 | //non qte styles are smaller !! | 48 | //non qte styles are smaller !! |
49 | int offset=(non_qte) ? 5 : 0; | 49 | int offset=(non_qte) ? 5 : 0; |
50 | 50 | ||
51 | for(int a=0;a<28;a++) | 51 | for(int a=0;a<28;a++) |
52 | { | 52 | { |
53 | for(int b=0;b<abs(population[a].total);b++) | 53 | for(int b=0;b<abs(population[a].total);b++) |
54 | { | 54 | { |
55 | if(population[a].total>0) //player 1 pieces | 55 | if(population[a].total>0) //player 1 pieces |
56 | { | 56 | { |
57 | pieces.player1[player1_counter].x=x_coord[a]-offset; | 57 | pieces.player1[player1_counter].x=x_coord[a]-offset; |
58 | if(a>=0 && a<13) | 58 | if(a>=0 && a<13) |
59 | { | 59 | { |
60 | pieces.player1[player1_counter].y=yup_coord[b]-offset; | 60 | pieces.player1[player1_counter].y=yup_coord[b]-offset; |
61 | pieces.player1[player1_counter].z=z_coord[b]; | 61 | pieces.player1[player1_counter].z=z_coord[b]; |
62 | pieces.player1[player1_counter].side=false; | 62 | pieces.player1[player1_counter].side=false; |
63 | player1_counter++; | 63 | player1_counter++; |
64 | } | 64 | } |
65 | else if(a>12 && a<26) | 65 | else if(a>12 && a<26) |
66 | { | 66 | { |
67 | pieces.player1[player1_counter].y=ylow_coord[b]-offset; | 67 | pieces.player1[player1_counter].y=ylow_coord[b]-offset; |
68 | pieces.player1[player1_counter].z=z_coord[b]; | 68 | pieces.player1[player1_counter].z=z_coord[b]; |
69 | pieces.player1[player1_counter].side=false; | 69 | pieces.player1[player1_counter].side=false; |
70 | player1_counter++; | 70 | player1_counter++; |
71 | } | 71 | } |
72 | else if(a==26) | 72 | else if(a==26) |
73 | { | 73 | { |
74 | if(b<5) | 74 | if(b<5) |
75 | { | 75 | { |
76 | pieces.player1[player1_counter].x=x_fin1[0]-offset; | 76 | pieces.player1[player1_counter].x=x_fin1[0]-offset; |
77 | pieces.player1[player1_counter].y=y_fin[b]-offset; | 77 | pieces.player1[player1_counter].y=y_fin[b]-offset; |
78 | pieces.player1[player1_counter].z=z_fin; | 78 | pieces.player1[player1_counter].z=z_fin; |
79 | } | 79 | } |
80 | else if(b>=5 && b<10) | 80 | else if(b>=5 && b<10) |
81 | { | 81 | { |
82 | pieces.player1[player1_counter].x=x_fin1[1]-offset; | 82 | pieces.player1[player1_counter].x=x_fin1[1]-offset; |
83 | pieces.player1[player1_counter].y=y_fin[b-5]-offset; | 83 | pieces.player1[player1_counter].y=y_fin[b-5]-offset; |
84 | pieces.player1[player1_counter].z=z_fin; | 84 | pieces.player1[player1_counter].z=z_fin; |
85 | } | 85 | } |
86 | else | 86 | else |
87 | { | 87 | { |
88 | pieces.player1[player1_counter].x=x_fin1[2]-offset; | 88 | pieces.player1[player1_counter].x=x_fin1[2]-offset; |
89 | pieces.player1[player1_counter].y=y_fin[b-10]-offset; | 89 | pieces.player1[player1_counter].y=y_fin[b-10]-offset; |
90 | pieces.player1[player1_counter].z=z_fin; | 90 | pieces.player1[player1_counter].z=z_fin; |
91 | } | 91 | } |
92 | pieces.player1[player1_counter].side=true; | 92 | pieces.player1[player1_counter].side=true; |
93 | player1_counter++; | 93 | player1_counter++; |
94 | 94 | ||
95 | } | 95 | } |
96 | } | 96 | } |
97 | 97 | ||
98 | else if(population[a].total<0) //player 2 pieces | 98 | else if(population[a].total<0) //player 2 pieces |
99 | { | 99 | { |
100 | pieces.player2[player2_counter].x=x_coord[a]-offset; | 100 | pieces.player2[player2_counter].x=x_coord[a]-offset; |
101 | if(a>=0 && a<13) | 101 | if(a>=0 && a<13) |
102 | { | 102 | { |
103 | pieces.player2[player2_counter].y=yup_coord[b]-offset; | 103 | pieces.player2[player2_counter].y=yup_coord[b]-offset; |
104 | pieces.player2[player2_counter].z=z_coord[b]; | 104 | pieces.player2[player2_counter].z=z_coord[b]; |
105 | pieces.player2[player2_counter].side=false; | 105 | pieces.player2[player2_counter].side=false; |
106 | player2_counter++; | 106 | player2_counter++; |
107 | } | 107 | } |
108 | else if(a>12 && a<26) | 108 | else if(a>12 && a<26) |
109 | { | 109 | { |
110 | pieces.player2[player2_counter].y=ylow_coord[b]-offset; | 110 | pieces.player2[player2_counter].y=ylow_coord[b]-offset; |
111 | pieces.player2[player2_counter].z=z_coord[b]; | 111 | pieces.player2[player2_counter].z=z_coord[b]; |
112 | pieces.player2[player2_counter].side=false; | 112 | pieces.player2[player2_counter].side=false; |
113 | player2_counter++; | 113 | player2_counter++; |
114 | } | 114 | } |
115 | else if(a==27) | 115 | else if(a==27) |
116 | { | 116 | { |
117 | if(b<5) | 117 | if(b<5) |
118 | { | 118 | { |
119 | pieces.player2[player2_counter].x=x_fin2[0]-offset; | 119 | pieces.player2[player2_counter].x=x_fin2[0]-offset; |
120 | pieces.player2[player2_counter].y=y_fin[b]-offset; | 120 | pieces.player2[player2_counter].y=y_fin[b]-offset; |
121 | pieces.player2[player2_counter].z=z_fin; | 121 | pieces.player2[player2_counter].z=z_fin; |
122 | } | 122 | } |
123 | else if(b>=5 && b<10) | 123 | else if(b>=5 && b<10) |
124 | { | 124 | { |
125 | pieces.player2[player2_counter].x=x_fin2[1]-offset; | 125 | pieces.player2[player2_counter].x=x_fin2[1]-offset; |
126 | pieces.player2[player2_counter].y=y_fin[b-5]-offset; | 126 | pieces.player2[player2_counter].y=y_fin[b-5]-offset; |
127 | pieces.player2[player2_counter].z=z_fin; | 127 | pieces.player2[player2_counter].z=z_fin; |
128 | } | 128 | } |
129 | else | 129 | else |
130 | { | 130 | { |
131 | pieces.player2[player2_counter].x=x_fin2[2]-offset; | 131 | pieces.player2[player2_counter].x=x_fin2[2]-offset; |
132 | pieces.player2[player2_counter].y=y_fin[b-10]-offset; | 132 | pieces.player2[player2_counter].y=y_fin[b-10]-offset; |
133 | pieces.player2[player2_counter].z=z_fin; | 133 | pieces.player2[player2_counter].z=z_fin; |
134 | } | 134 | } |
135 | pieces.player2[player2_counter].side=true; | 135 | pieces.player2[player2_counter].side=true; |
136 | player2_counter++; | 136 | player2_counter++; |
137 | 137 | ||
138 | } | 138 | } |
139 | } | 139 | } |
140 | } | 140 | } |
141 | } | 141 | } |
142 | } | 142 | } |
143 | 143 | ||
144 | void MoveEngine::diceroll(const int& newplayer,const int& face1,const int& face2,const int& face3,const int& face4,bool computer) | 144 | void MoveEngine::diceroll(const int& newplayer,const int& face1,const int& face2,const int& face3,const int& face4,bool computer) |
145 | { | 145 | { |
146 | checkstate(); | 146 | checkstate(); |
147 | player=newplayer; | 147 | player=newplayer; |
148 | otherplayer=(player==1) ? 2 : 1; | 148 | otherplayer=(player==1) ? 2 : 1; |
149 | dice[0]=face1; | 149 | dice[0]=face1; |
150 | dice[1]=face2; | 150 | dice[1]=face2; |
151 | dice[2]=face3; | 151 | dice[2]=face3; |
152 | dice[3]=face4; | 152 | dice[3]=face4; |
153 | marker_current=-1; | 153 | marker_current=-1; |
154 | if(getPossibleMoves()==0) | 154 | if(getPossibleMoves()==0) |
155 | { | 155 | { |
156 | emit nomove(); | 156 | emit nomove(); |
157 | return; // player will be changed | 157 | return; // player will be changed |
158 | } | 158 | } |
159 | if(!computer) | 159 | if(!computer) |
160 | return; //human intervention required | 160 | return; //human intervention required |
161 | 161 | ||
162 | QTimer::singleShot(2000,this,SLOT(automove())); | 162 | QTimer::singleShot(2000,this,SLOT(automove())); |
163 | } | 163 | } |
164 | 164 | ||
165 | 165 | ||
166 | void MoveEngine::automove() | 166 | void MoveEngine::automove() |
167 | { | 167 | { |
168 | //the maximimum possibility | 168 | //the maximimum possibility |
169 | int maxpos=0; | 169 | int maxpos=0; |
170 | //the position in the moves array | 170 | //the position in the moves array |
171 | int from=-1; | 171 | int from=-1; |
172 | int to=-1; | 172 | int to=-1; |
173 | //dice1 or dice 2 ?? | 173 | //dice1 or dice 2 ?? |
174 | int index_dice=0; | 174 | int index_dice=0; |
175 | for(int counter=0;counter<26;counter++) | 175 | for(int counter=0;counter<26;counter++) |
176 | { | 176 | { |
177 | int a=(player==1) ? counter : 25-counter; | 177 | int a=(player==1) ? counter : 25-counter; |
178 | for(int b=0;b<4;b++) | 178 | for(int b=0;b<4;b++) |
179 | { | 179 | { |
180 | if(moves[a].weight[b]>maxpos) | 180 | if(moves[a].weight[b]>maxpos) |
181 | { | 181 | { |
182 | maxpos=moves[a].weight[b]; | 182 | maxpos=moves[a].weight[b]; |
183 | from=a; | 183 | from=a; |
184 | to=moves[a].to[b]; | 184 | to=moves[a].to[b]; |
185 | index_dice=b+1; | 185 | index_dice=b+1; |
186 | } | 186 | } |
187 | } | 187 | } |
188 | } | 188 | } |
189 | move(from,to,index_dice); | 189 | move(from,to,index_dice); |
190 | } | 190 | } |
191 | 191 | ||
192 | 192 | ||
193 | void MoveEngine::boardpressed(const int& x,const int& y,Marker& marker,bool non_qte) | 193 | void MoveEngine::boardpressed(const int& x,const int& y,Marker& marker,bool non_qte) |
194 | { | 194 | { |
195 | //get the position of the mouse click | 195 | //get the position of the mouse click |
196 | bool upper=true; | 196 | bool upper=true; |
197 | bool found=false; | 197 | bool found=false; |