home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
games
/
volume15
/
xstratego
/
part02
/
callback.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-01-27
|
3KB
|
131 lines
/*
* Callback.c
*/
#include "stratego.h"
/*
* BoardPosition Callback Routine.
*/
XtCallbackProc ActivateBoardPosition (widget, board_pos)
Widget widget;
BOARD_POS *board_pos;
{
if (players[0].confirm)
ConfirmMove ();
if (players[0].status == PL_SETUP)
setup_tile (board_pos);
else if (players[0].status == PL_ENDGAME)
message ("The game has ended!");
else if (players[0].status >= PL_PLAYING)
play_tile (board_pos);
else
message ("It is not your turn %s.", players[0].name);
}
void AssignBoardPosition (board_pos, tile, owner)
BOARD_POS *board_pos;
TILE *tile;
int owner;
{
Pixmap pixmap;
Arg args[1];
if (owner == O_ENEMY && tile->value >= FLAG && tile->value <= BOMB)
pixmap = tiles[ENEMY].pixmap;
else
pixmap = tile->pixmap;
board_pos->owner = owner;
board_pos->value = tile->value;
XtSetArg (args[0], XtNbitmap, pixmap);
XtSetValues (board_pos->widget, args, 1);
}
void MarkBoardPosition (board_pos, reveal)
BOARD_POS *board_pos;
Boolean reveal;
{
Pixmap pixmap;
Arg args[1];
if (reveal == True)
pixmap = tiles[board_pos->value].stippled_pixmap;
else if (board_pos->owner == O_ENEMY)
pixmap = tiles[ENEMY].pixmap;
else
pixmap = tiles[board_pos->value].pixmap;
XtSetArg (args[0], XtNbitmap, pixmap);
XtSetValues (board_pos->widget, args, 1);
}
void UpdateTileCount (tile, delta)
TILE *tile;
int delta;
{
Arg args[2];
char num_buf[5];
tile->count += delta;
if (tile->count == 0) {
strcpy (num_buf, " - ");
XtSetArg (args[0], XtNhighlightThickness, 0);
XtSetArg (args[1], XtNbitmap, tile->stippled_pixmap);
XtSetValues (tile->bitmap_widget, args, 2);
}
else {
sprintf (num_buf, " %d ", tile->count);
if (tile->count == delta) {
if (players[0].status == PL_SETUP)
XtSetArg (args[0], XtNhighlightThickness, 1);
else
XtSetArg (args[0], XtNhighlightThickness, 0);
XtSetArg (args[1], XtNbitmap, tile->pixmap);
XtSetValues (tile->bitmap_widget, args, 2);
}
}
XtSetArg (args[0], XtNlabel, num_buf);
XtSetValues (tile->count_widget, args, 1);
}
XtActionHookProc ButtonPressHook (widget, data, action_name, event, params, cnt)
Widget widget;
XtPointer data;
String action_name;
XEvent *event;
String *params;
Cardinal *cnt;
{
if (event->type == ButtonPress) {
message ("");
if (players[0].confirm)
ConfirmMove ();
}
}
#include <varargs.h>
/*VARARGS0*/
void message (va_alist)
va_dcl
{
static char msg_buf[BUFSIZ];
va_list arglist;
char *fmt;
Arg args[1];
va_start (arglist);
fmt = va_arg (arglist, char *);
vsprintf (msg_buf, fmt, arglist);
va_end (arglist);
XtSetArg (args[0], XtNlabel, msg_buf);
XtSetValues (Message, args, 1);
}