8
COLOURTYPE Colour::MYFOREGROUND=0; //initializers
9
COLOURTYPE Colour::MYBACKGROUND=0;
10
COLOURTYPE Colour::WALLCOLOUR=0;
11
COLOURTYPE Colour::PACMANCOLOUR=0;
12
COLOURTYPE Colour::GHOSTCOLOUR1=0;
13
COLOURTYPE Colour::GHOSTCOLOUR2=0;
14
COLOURTYPE Colour::GHOSTCOLOUR3=0;
15
COLOURTYPE Colour::GHOSTCOLOUR4=0;
16
COLOURTYPE Colour::RUNGHOSTCOLOUR=0;
17
COLOURTYPE Colour::FOODCOLOUR=0;
18
COLOURTYPE Colour::SUPERFOODCOLOUR=0;
19
COLOURTYPE Colour::BONUSPOINTCOLOUR=0;
20
COLOURTYPE Colour::BONUSLIFECOLOUR=0;
23
static COLOURNAME black,white,cyan,lightblue,yellow,red,violetred,violet,orangered,deepskyblue,gold,lightyellow,grey,lightgrey,dimgrey,slategrey,darkslategrey,lightslategrey;
25
Colour::Colour(UserInterface* u) { //constructor
26
static int starts=0; //to make sure only one construction
28
#ifdef XWIN //X-Win only
29
Window window; //our window
30
int screen; //our screen
33
if (starts) { //make sure it is initialized just once
34
pacwarning("Colour is just initialized once\n");
37
starts=1; //to make sure only one construction
40
display=u->getdisplay(); //get pointer to display connection
41
screen=u->getscreen(); //get the screen
43
Visual *vis=DefaultVisual(display,screen); //get the visual type class
45
int colour=0; //colour?
47
//if it is not grayish then it is colour (only maybe)
48
if (Argument::argc==1 && vis->c_class!=GrayScale && vis->c_class!=StaticGray) colour=1;
50
//the following picks the first argument matching grey or colour
51
//in none given, no colour is assumed
52
if (Argument::argc>1) { //if there are arguments
53
char** temp=Argument::args; //initial pointer to strings
54
char* s; //argument string
55
while(s=*temp) { //while there is still an argument left
56
if (!strcmp(s,"grey")) //if argument is grey then no colours
58
if (!strcmp(s,"colour")) //if argument is colour then colours
60
temp++; //increment to next string
64
if (colour) { //if colour chosen
66
cmap=DefaultColormap(display,DefaultScreen(display)); //get colourmap
68
//the colour initializing is almost straightforward, you set the RGB
69
//mark flags according to what attribute members were set
70
//then you allocate the colour, which you get with ?????.pixel
74
cyan.flags=DoRed|DoGreen|DoBlue;
75
if(XAllocColor(display,cmap,&cyan)==0) pacexit("Colour initialization error");
80
black.flags=DoRed|DoGreen|DoBlue;
81
if(XAllocColor(display,cmap,&black)==0) pacexit("Colour initialization error");
86
white.flags=DoRed|DoGreen|DoBlue;
87
if(XAllocColor(display,cmap,&white)==0) pacexit("Colour initialization error");
89
lightblue.red=173*256;
90
lightblue.green=216*256;
91
lightblue.blue=230*256;
92
lightblue.flags=DoRed|DoGreen|DoBlue;
93
if(XAllocColor(display,cmap,&lightblue)==0) pacexit("Colour initialization error");
98
yellow.flags=DoRed|DoGreen|DoBlue;
99
if(XAllocColor(display,cmap,&yellow)==0) pacexit("Colour initialization error");
104
red.flags=DoRed|DoGreen|DoBlue;
105
if(XAllocColor(display,cmap,&red)==0) pacexit("Colour initialization error");
108
orangered.green=69*256;
110
orangered.flags=DoRed|DoGreen|DoBlue;
111
if(XAllocColor(display,cmap,&orangered)==0) pacexit("Colour initialization error");
113
violetred.red=208*256;
114
violetred.green=32*256;
115
violetred.blue=144*256;
116
violetred.flags=DoRed|DoGreen|DoBlue;
117
if(XAllocColor(display,cmap,&violetred)==0) pacexit("Colour initialization error");
120
violet.green=130*256;
122
violet.flags=DoRed|DoGreen|DoBlue;
123
if(XAllocColor(display,cmap,&violet)==0) pacexit("Colour initialization error");
126
deepskyblue.green=192*256-1;
127
deepskyblue.blue=65535;
128
deepskyblue.flags=DoRed|DoGreen|DoBlue;
129
if(XAllocColor(display,cmap,&deepskyblue)==0) pacexit("Colour initialization error");
132
gold.green=216*256-1;
134
gold.flags=DoRed|DoGreen|DoBlue;
135
if(XAllocColor(display,cmap,&gold)==0) pacexit("Colour initialization error");
137
lightyellow.red=65535;
138
lightyellow.green=65535;
140
lightyellow.flags=DoRed|DoGreen|DoBlue;
141
if(XAllocColor(display,cmap,&lightyellow)==0) pacexit("Colour initialization error");
143
MYFOREGROUND =cyan.pixel;
144
MYBACKGROUND =black.pixel;
145
WALLCOLOUR =deepskyblue.pixel;
146
PACMANCOLOUR =yellow.pixel;
147
GHOSTCOLOUR1 =red.pixel;
148
GHOSTCOLOUR2 =violetred.pixel;
149
GHOSTCOLOUR3 =violet.pixel;
150
GHOSTCOLOUR4 =orangered.pixel;
151
RUNGHOSTCOLOUR =lightblue.pixel;
152
FOODCOLOUR =lightyellow.pixel;
153
SUPERFOODCOLOUR =gold.pixel;
154
BONUSPOINTCOLOUR =gold.pixel;
155
BONUSLIFECOLOUR =gold.pixel;
157
#define MYFOREGROUND cyan.pixel
158
#define MYBACKGROUND black.pixel
159
#define WALLCOLOUR deepskyblue.pixel
160
#define PACMANCOLOUR yellow.pixel
161
#define GHOSTCOLOUR1 red.pixel
162
#define GHOSTCOLOUR2 violetred.pixel
163
#define GHOSTCOLOUR3 violet.pixel
164
#define GHOSTCOLOUR4 orangered.pixel
165
#define RUNGHOSTCOLOUR lightblue.pixel
166
#define FOODCOLOUR lightyellow.pixel
167
#define SUPERFOODCOLOUR gold.pixel
168
#define BONUSPOINTCOLOUR gold.pixel
169
#define BONUSLIFECOLOUR gold.pixel
171
} else { //if no colours chosen
172
cmap=DefaultColormap(display,DefaultScreen(display));
177
grey.flags=DoRed|DoGreen|DoBlue;
178
if(XAllocColor(display,cmap,&grey)==0) pacexit("Colour initialization error");
181
dimgrey.green=105*256;
182
dimgrey.blue=105*256;
183
dimgrey.flags=DoRed|DoGreen|DoBlue;
184
if(XAllocColor(display,cmap,&dimgrey)==0) pacexit("Colour initialization error");
186
lightgrey.red=211*256;
187
lightgrey.green=211*256;
188
lightgrey.blue=211*256;
189
lightgrey.flags=DoRed|DoGreen|DoBlue;
190
if(XAllocColor(display,cmap,&lightgrey)==0) pacexit("Colour initialization error");
192
lightslategrey.red=119*256;
193
lightslategrey.green=136*256;
194
lightslategrey.blue=153*256;
195
lightslategrey.flags=DoRed|DoGreen|DoBlue;
196
if(XAllocColor(display,cmap,&lightslategrey)==0) pacexit("Colour initialization error");
198
slategrey.red=112*256;
199
slategrey.green=128*256;
200
slategrey.blue=144*256;
201
slategrey.flags=DoRed|DoGreen|DoBlue;
202
if(XAllocColor(display,cmap,&slategrey)==0) pacexit("Colour initialization error");
204
darkslategrey.red=47*256;
205
darkslategrey.green=79*256;
206
darkslategrey.blue=79*256;
207
darkslategrey.flags=DoRed|DoGreen|DoBlue;
208
if(XAllocColor(display,cmap,&darkslategrey)==0) pacexit("Colour initialization error");
210
MYFOREGROUND =WhitePixel(display,screen);
211
MYBACKGROUND =BlackPixel(display,screen);
212
WALLCOLOUR =darkslategrey.pixel;
213
PACMANCOLOUR =WhitePixel(display,screen);
214
GHOSTCOLOUR1 =slategrey.pixel;
215
GHOSTCOLOUR2 =slategrey.pixel;
216
GHOSTCOLOUR3 =slategrey.pixel;
217
GHOSTCOLOUR4 =slategrey.pixel;
218
RUNGHOSTCOLOUR =lightgrey.pixel;
219
FOODCOLOUR =lightgrey.pixel;
220
SUPERFOODCOLOUR =grey.pixel;
221
BONUSPOINTCOLOUR =dimgrey.pixel;
222
BONUSLIFECOLOUR =WhitePixel(display,screen);
224
#define MYFOREGROUND WhitePixel(display,screen)
225
#define MYBACKGROUND BlackPixel(display,screen)
226
#define WALLCOLOUR darkslategrey.pixel
227
#define PACMANCOLOUR WhitePixel(display,screen)
228
#define GHOSTCOLOUR1 slategrey.pixel
229
#define GHOSTCOLOUR2 slategrey.pixel
230
#define GHOSTCOLOUR3 slategrey.pixel
231
#define GHOSTCOLOUR4 slategrey.pixel
232
#define RUNGHOSTCOLOUR =lightgrey.pixel
233
#define FOODCOLOUR lightgrey.pixel
234
#define SUPERFOODCOLOUR grey.pixel
235
#define BONUSPOINTCOLOUR dimgrey.pixel
236
#define BONUSLIFECOLOUR WhitePixel(display,screen)
243
.flags=DoRed|DoGreen|DoBlue;
244
if(XAllocColor(display,cmap,&)==0) pacexit("Colour initialization error");
247
#elif defined MSWIN //MS-Win only
249
cyan=(RGB(0,255,255));
251
white=(RGB(255,255,255));
252
lightblue=(RGB(173,216,230));
253
yellow=(RGB(255,255,0));
255
orangered=(RGB(255,69,0));
256
violetred=(RGB(208,32,144));
257
violet=(RGB(238,130,238));
258
deepskyblue=(RGB(0,191,255));
259
gold=(RGB(255,215,0));
260
lightyellow=(RGB(255,255,0));
264
WALLCOLOUR =deepskyblue;
265
PACMANCOLOUR =yellow;
267
GHOSTCOLOUR2 =violetred;
268
GHOSTCOLOUR3 =violet;
269
GHOSTCOLOUR4 =orangered;
270
RUNGHOSTCOLOUR =lightblue;
271
FOODCOLOUR =lightyellow;
272
SUPERFOODCOLOUR =gold;
273
BONUSPOINTCOLOUR =gold;
274
BONUSLIFECOLOUR =gold;
277
#define MYFOREGROUND RGB(0,255,255)
278
#define MYBACKGROUND RGB(0,0,0)
279
#define WALLCOLOUR RGB(0,191,255)
280
#define PACMANCOLOUR RGB(255,255,0)
281
#define GHOSTCOLOUR1 RGB(255,0,0)
282
#define GHOSTCOLOUR2 RGB(208,32,144)
283
#define GHOSTCOLOUR3 RGB(238,130,238)
284
#define GHOSTCOLOUR4 RGB(255,69,0)
285
#define RUNGHOSTCOLOUR RGB(173,216,230)
286
#define FOODCOLOUR RGB(255,255,0)
287
#define SUPERFOODCOLOUR RGB(255,215,0)
288
#define BONUSPOINTCOLOUR RGB(255,215,0)
289
#define BONUSLIFECOLOUR RGB(255,215,0)
295
#ifdef XWIN //X-Win only
296
XFreeColormap(display,cmap); //free the colourmap
298
#elif defined MSWIN //MS-Win only
304
DeleteObject(lightblue);
305
DeleteObject(yellow);
306
DeleteObject(lightyellow);
308
DeleteObject(orangered);
309
DeleteObject(violetred);
310
DeleteObject(violet);
311
DeleteObject(deepskyblue);