1 /*
2 * XScrabble - X version of the popular board game, for 1 to 4 players.
3 *
4 * This software comes with NO warranty whatsoever. I therefore take no
5 * responsibility for any damages, losses or problems caused through use
6 * or misuse of this program.
7 *
8 * I hereby grant permission for this program to be freely copied and
9 * distributed by any means, provided no charge is made for it.
10 *
11 * Matthew Chapman, csuoq@csv.warwick.ac.uk
12 * Oct 1994.
13 */
14
15 /* display.c - output functions for X interface */
16
17 #include "scrab.h"
18 #include "globals.h"
19
ShowTiles()20 void ShowTiles()
21 {
22 char lname[2];
23 int ac,dn;
24
25 for (dn=0; dn<BOARDSIZE; dn++)
26 for (ac=0; ac<BOARDSIZE; ac++)
27 if (cboard[ac][dn] != ' ')
28 {
29 sprintf(lname,"%c",cboard[ac][dn]);
30 XtVaSetValues(sq[curr_player][ac][dn],XtNlabel,lname,
31 SETBG(app_data.tilecolor),NULL);
32 is_perm[ac][dn]=True;
33 }
34 else
35 {
36 XtVaSetValues(sq[curr_player][ac][dn],XtNlabel," ",
37 SETBG((char *)colours[sq_col[ac][dn]]),NULL);
38 is_perm[ac][dn]=False;
39 }
40 }
41
ShowBoard(Boolean leavecolours)42 void ShowBoard(Boolean leavecolours)
43 {
44 /* display board for everyone */
45 int ac,dn,i;
46 char lname[2];
47
48 for (i=0; i<num_players; i++)
49 for (dn=0; dn<BOARDSIZE; dn++)
50 for (ac=0; ac<BOARDSIZE; ac++)
51 if (board[ac][dn] != ' ')
52 {
53 sprintf(lname,"%c",board[ac][dn]);
54 XtVaSetValues(sq[i][ac][dn],XtNlabel,lname,NULL);
55 if (leavecolours && (!is_perm[ac][dn]))
56 XtVaSetValues(sq[i][ac][dn],SETBG(app_data.brightcolor),NULL);
57 else
58 XtVaSetValues(sq[i][ac][dn],SETBG(app_data.tilecolor),NULL);
59 }
60 }
61
ShowBar(int ply)62 void ShowBar(int ply)
63 {
64 /* display letters in bar for player number ply */
65 int i;
66 char ch,lett[3];
67
68 for (i=0; i<LONGBAR; i++)
69 {
70 if ((i>2) && (i<10))
71 {
72 /* in central part of bar */
73 ch=player[ply].bar[i-3];
74 bar[ply][i]=ch;
75 sprintf(lett,"%c",ch);
76 if (ch==' ')
77 XtVaSetValues(br[ply][i],SETBG(app_data.barcolor),XtNlabel,lett,NULL);
78 else
79 XtVaSetValues(br[ply][i],SETBG(app_data.tilecolor),XtNlabel,lett,NULL);
80 }
81 else
82 {
83 XtVaSetValues(br[ply][i],SETBG(app_data.barcolor),XtNlabel," ",NULL);
84 bar[ply][i]=' ';
85 }
86 }
87 }
88
ShowScores()89 void ShowScores()
90 {
91 int i,rep;
92 char scoretext[256]="",scstring[8];
93
94 for (i=0; i<num_players; i++)
95 {
96 if (i==curr_player)
97 strcat(scoretext,">");
98 else
99 strcat(scoretext," ");
100 strcat(scoretext,player[i].name);
101 sprintf(scstring,"%d",player[i].score);
102 for (rep=0; rep<(int)(16-strlen(player[i].name)-strlen(scstring)); rep++)
103 strcat(scoretext,".");
104 strcat(scoretext,scstring);
105 if (i<num_players-1)
106 strcat(scoretext,"\n");
107 }
108
109 for (i=0; i<num_players; i++)
110 XtVaSetValues(scorebox[i],XtNlabel,scoretext,NULL);
111 }
112
TilesLeft()113 void TilesLeft()
114 {
115 char tileltext[256];
116 int i;
117
118 sprintf(tileltext,"%s%d",PROMPT[TILES_LEFT],bagptr+1);
119
120 for (i=0; i<num_players; i++)
121 XtVaSetValues(tilesleft[i],XtNlabel,tileltext,NULL);
122 }
123
124 /* for the timer */
Click()125 void Click()
126 {
127 if (!finished_go)
128 {
129 if (pauseflag==1) comp+=10;
130 if (comp==10000-10*50)
131 XBell(dpy[curr_player],2*bell_level-100);
132 if (comp==10000-10*25)
133 XBell(dpy[curr_player],(3*bell_level)/2-100);
134 if (comp==10000/2)
135 XBell(dpy[curr_player],bell_level-100);
136 if (comp>10000)
137 {
138 char mess[256];
139
140 XtVaSetValues(pauseButton[curr_player],
141 XtNmappedWhenManaged,False,NULL);
142
143 XBell(dpy[curr_player],2*bell_level-100);
144 sprintf(mess,PROMPT[OUT_TIME_ALL],player[curr_player].name);
145 Message(curr_player,PROMPT[OUT_TIME],mess);
146 Deselect(curr_player);
147
148 RemoveFromBoard();
149 ShowTiles();
150 ShowBar(curr_player);
151 num_passed=0;
152 if (waiting_for_change)
153 {
154 XtPopdown(changeshell);
155 XtDestroyWidget(changeshell);
156 waiting_for_change=False;
157 }
158 if (waiting_for_blank)
159 {
160 XtPopdown(blankshell);
161 XtDestroyWidget(blankshell);
162 waiting_for_blank=False;
163 }
164 GotoNextPlayer();
165 }
166 else
167 {
168 XtVaSetValues(timeleft[curr_player],XtNpercentageCompleted,
169 comp,NULL);
170 XtAppAddTimeOut(app_context,55*time_limit,Click,
171 timeleft[curr_player]);
172 }
173 }
174 }
175
176
MessageAll(char * mess)177 void MessageAll(char *mess)
178 {
179 /* send same message to everyone */
180 int i;
181
182 for (i=0; i<num_players; i++)
183 XtVaSetValues(message[i],XtNlabel,mess,NULL);
184 }
185
Message(int ply,char * mess1,char * mess2)186 void Message(int ply,char *mess1, char *mess2)
187 {
188 /* send mess1 to ply, and mess2 to everyone else */
189 int i;
190
191 for (i=0; i<num_players; i++)
192 if (i==ply)
193 XtVaSetValues(message[i],XtNlabel,mess1,NULL);
194 else
195 XtVaSetValues(message[i],XtNlabel,mess2,NULL);
196 }
197
MessageOne(int ply,char * mess)198 void MessageOne(int ply,char *mess)
199 {
200 /* send mess only to ply */
201 XtVaSetValues(message[ply],XtNlabel,mess,NULL);
202 }
203
EndDelay()204 void EndDelay()
205 {
206 waiting=False;
207 }
208
Wait(int delay)209 void Wait(int delay)
210 {
211 /* wait for specified time, processing X events */
212 waiting=True;
213 XtAppAddTimeOut(XtWidgetToApplicationContext(message[0]),delay,
214 EndDelay,message[0]);
215 while (waiting==True)
216 ProcessEvent();
217 }
218
ProcessEvent()219 void ProcessEvent()
220 {
221 /* processes any pending events */
222 XtInputMask msk=XtIMAll;
223 if (XtAppPending(app_context)!=0)
224 XtAppProcessEvent(app_context,msk);
225 }
226
UpdateComp(int perc)227 void UpdateComp(int perc)
228 {
229 /* on computer's move, update Xc widget with % completed */
230 /* printf("Update value = %i\n",perc);*/
231 XcBGUpdateValue(compw[curr_player],&perc);
232 }
233