markh@cvedc.UUCP (Mark Holm) (07/09/88)
The following is the first official patch to the code for mahjongg2. This patch includes a new event.h and a patch file. To apply, first remove (or save) the existing event.c and unpack the archive. Then run mahjongg2.patch1 through patch. The patch file updates the man page to reflect the code changes and acknowledges contributors to mahjongg's progress. It also updates the shuffling and message facility. The new event.c makes tile selection on down buttons and extends the short help to find multiple matches. Many Thanks to Gilbert Harrus for the new shuffling algorithm and to Jim Flar(?) for the new selection and messaging facility. =========================================================================== Mark Holm ..tektronix!ogcvax!cvedc!exc!markh Exceptions ..sun!cvbnet!cvedc!exc!markh 126 NE Grant Phone (503)648-8307 Hillsboro, Oregon 97124 Messages only until after 6:00 PM =-=-=cut-=-=-cut=-=-=cut-=-=-cut=-=-=cut-=-=-cut=-=-=cut-=-=-cut=-=-= #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of archive 1 (of 1)." # Contents: mahjongg2.patch1 event.c # Wrapped by markh@cvedc on Fri Jul 8 16:45:43 1988 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f mahjongg2.patch1 -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"mahjongg2.patch1\" else echo shar: Extracting \"mahjongg2.patch1\" \(8052 characters\) sed "s/^X//" >mahjongg2.patch1 <<'END_OF_mahjongg2.patch1' X*** mahjongg.6 Fri Jul 8 16:33:09 1988 X--- mahjongg.6.new Fri Jul 8 16:31:30 1988 X*************** X*** 44,55 **** X Two help features are currently implemented. By selecting the "help" button in X the control window when no tiles are selected, you will be shown all available X tile combinations. To see each combination press the left mouse button until X! the message "No more moves [DONE] [] []" is shown. To cancel "help" press the X right mouse button. If you have selected a tile, pressing the middle mouse X button or selecting the "help" button in the control window, will find the X first matching tile (if any) starting at the top of the pile and working down. X If a match is found, you will be asked to confirm and the pair will be X! removed from the board. X .SH UNDO X Since some people tend to be a little faster on the mouse then they should be, X the undo feature was implemented. The "undo" button replaces the previous X--- 44,56 ---- X Two help features are currently implemented. By selecting the "help" button in X the control window when no tiles are selected, you will be shown all available X tile combinations. To see each combination press the left mouse button until X! no more moves are shown. To cancel "help" press the X right mouse button. If you have selected a tile, pressing the middle mouse X button or selecting the "help" button in the control window, will find the X first matching tile (if any) starting at the top of the pile and working down. X If a match is found, you will be asked to confirm and the pair will be X! removed from the board. If an alternate match is available pressing the middle X! button labeled "NEXT" will show it. X .SH UNDO X Since some people tend to be a little faster on the mouse then they should be, X the undo feature was implemented. The "undo" button replaces the previous X*************** X*** 73,86 **** X Copyright 1988 Mark A. Holm X .br X <tektronix!tessi!exc!markh> X .SH BUGS X If a tile is selected when the game goes iconic it is not drawn as selected X! when the game is re-opened. the board returns to normal after the next X icon pair is removed or by pressing undo (backs up one move). X .PP X Sunview option "-WI iconfile" only works in black and white. X .PP X! Board number is not checked very close. If you put something wierd in, you X deserve everthing you get. X .PP X No score file. It is up to you to keep track of who did how well on what board. X--- 74,96 ---- X Copyright 1988 Mark A. Holm X .br X <tektronix!tessi!exc!markh> X+ .SH ACKNOWLEGED CONTRIBUTORS X+ .nf X+ .na X+ Dorothy Robinson (Prime-CV Beaverton) Tiles X+ Jim Batch (Prime-CV Beaverton) Theory and code help X+ Gilbert Harrus (Gip-Altair/INRIA) Shuffling algorithm X+ Jim Flar (??) (Sun) New selection and help X+ .fi X+ .ad X .SH BUGS X If a tile is selected when the game goes iconic it is not drawn as selected X! when the game is re-opened, the board returns to normal after the next X icon pair is removed or by pressing undo (backs up one move). X .PP X Sunview option "-WI iconfile" only works in black and white. X .PP X! Board number is not checked very close. If you put something weird in, you X deserve everthing you get. X .PP X No score file. It is up to you to keep track of who did how well on what board. X*** mahjongg.c Fri Jul 8 16:32:54 1988 X--- mahjongg.c.new Fri Jul 8 13:25:49 1988 X*************** X*** 17,22 **** X--- 17,25 ---- X * 1.1 removed non-working reverse video cursor code X * added 386 support. X * added blank tiles for hidden tiles to stop cheating. X+ * X+ * 1.2 incorporated sun fix for panel messages and added new X+ * shuffling algorithm. X */ X X #ifndef lint X*************** X*** 62,67 **** X--- 65,71 ---- X extern void board_num_proc(); X extern void play_back_proc(); X extern void play_event_proc(); X+ extern void panel_msg(); X X extern short stick_image[]; X extern int undo_count; X*************** X*** 779,797 **** X X /* clear stand_by message and release input mask */ X X! panel_set(message, PANEL_SHOW_ITEM, X! FALSE, X! 0); X X- window_set(message_panel, WIN_CONSUME_PICK_EVENTS, X- WIN_MOUSE_BUTTONS, 0, X- 0); X- window_set(message_panel, WIN_CONSUME_KBD_EVENT, X- WIN_ASCII_EVENTS, 0, 0); X- X- cursor_set(play_cursor, CURSOR_IMAGE, &stick, 0); X- window_set(play_panel, WIN_CURSOR, play_cursor, 0); X- X } X X void build_image(oldimage) X--- 783,790 ---- X X /* clear stand_by message and release input mask */ X X! panel_msg((char *)0, &stick); X X } X X void build_image(oldimage) X*************** X*** 800,809 **** X { X int i; X int j; X- int pool[42]; X boolean ok; X boolean dir; X char seed_text[80]; X X /* initialize selected structures */ X X--- 793,804 ---- X { X int i; X int j; X boolean ok; X boolean dir; X char seed_text[80]; X+ int tmp_pool[144]; X+ int tmp_tiles_left; X+ int pos; X X /* initialize selected structures */ X X*************** X*** 836,853 **** X X /* show stand_by message while building image and grab all input */ X X! panel_set(message, PANEL_LABEL_STRING, X! "Building board. Please wait.", X! PANEL_SHOW_ITEM, X! TRUE, 0); X X- window_set(message_panel, WIN_IGNORE_PICK_EVENTS, X- WIN_MOUSE_BUTTONS, 0, 0); X- window_set(message_panel, WIN_IGNORE_KBD_EVENT, X- WIN_ASCII_EVENTS, 0, 0); X- cursor_set(play_cursor, CURSOR_IMAGE, &wait, 0); X- window_set(play_panel, WIN_CURSOR, play_cursor, 0); X- X /* initialize random number counter */ X X (void) srandom(seed); X--- 831,838 ---- X X /* show stand_by message while building image and grab all input */ X X! panel_msg( "Building board. Please wait.", &wait); X X /* initialize random number counter */ X X (void) srandom(seed); X*************** X*** 854,863 **** X X tile_count = 144; X X! /* initialize tile pool */ X! for(i = 0; i < 34; i++) pool[i] = 4; X! for(; i < 42; i++) pool[i] = 1; X X /* assign values to each location. Board is built from upper left * X * to lower right, bottom to top. Exception are left tile for row * X * 4pt5 is before rows 4 and 5, and right tiles for row 4.5 are * X--- 839,853 ---- X X tile_count = 144; X X! /* initialize tmp_pool */ X! for(j = 0; j < 136; j++) tmp_pool[j] = j/4; /* tiles * 4 */ X! for(j=136; j<144; j++) tmp_pool[j] = j- 102; /* flowers & seasons */ X! /* 136 --> 34 */ X! /* 143 --> 41 */ X! tmp_tiles_left = 144; X X+ X+ X /* assign values to each location. Board is built from upper left * X * to lower right, bottom to top. Exception are left tile for row * X * 4pt5 is before rows 4 and 5, and right tiles for row 4.5 are * X*************** X*** 869,896 **** X X if (!oldimage) { /* not repeating last board */ X X! /* Randomly seed index into pool. Randomly * X! * run up or down list until unused tile * X! * is found or end of list. If end of * X! * list reseed and run in opposite * X! * direction in list until unused tile is * X! * found. If beginning of list found, * X! * start over. */ X X! ok = FALSE; X! while (ok == FALSE) { X! i = RANDOM(41); X! /* Up, up, up! */ X! dir = random()&01; X! while ((i < 42 || i >=0) && pool[i] == 0) (dir) ? i++ : i--; X! if (i == 42 || i < 0) { /* Thud! Reverse march! */ X! i = RANDOM(41); X! while ((i < 42 || i >= 0) && pool[i] == 0) (dir) ? i-- : i++; X! } X! if (i == 42 || i < 0) continue; /* Missed! try again */ X! pool[i]--; X! ok = TRUE; X! } X X /* all flowers and all seasons */ X X--- 859,870 ---- X X if (!oldimage) { /* not repeating last board */ X X! /* Shuffle/pick tile */ X X! pos = RANDOM(tmp_tiles_left); X! i= tmp_pool[pos]; X! for(;pos<tmp_tiles_left; pos++) tmp_pool[pos] = tmp_pool[pos+1]; X! tmp_tiles_left--; X X /* all flowers and all seasons */ X END_OF_mahjongg2.patch1 if test 8052 -ne `wc -c <mahjongg2.patch1`; then echo shar: \"mahjongg2.patch1\" unpacked with wrong size! fi # end of overwriting check fi if test -f event.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"event.c\" else echo shar: Extracting \"event.c\" \(16933 characters\) sed "s/^X//" >event.c <<'END_OF_event.c' X/* X * Copyright 1988, Mark Holm X * Exceptions X * X * Acknowledgments to Dorothy Robinson for her artistic X * abilities in drawing the icons and to Jim Batch for X * technical support and graphical concepts (which I abandoned in favor X * of the easy way out). X * X * Permission is given to copy and distribute for non-profit purposes. X * X */ X#ifndef lint Xstatic char *rcs = "$header$ Copyright 1988 Mark A. Holm"; X#endif !lint X X/* This file has the event handlers for the background and X * tiles in the play panel X */ X X#include <stdio.h> X#include <sys/types.h> X#include <suntool/sunview.h> X#include <suntool/panel.h> X#include <sunwindow/notify.h> X#include <pixrect/pixrect.h> X X#include "mahjongg.h" X X/* external definitions */ X Xextern Frame main_frame; Xextern Panel play_panel, message_panel; Xextern Panel_item TL_hundred; Xextern Panel_item TL_ten; Xextern Panel_item TL_one; Xextern Panel_item message; Xextern Panel_item tile[144]; Xextern Panel_item tiles_left[3]; Xextern Panel_item board_num; Xextern Cursor play_cursor; X Xextern boolean BandW; Xextern Tiles *board[144]; Xextern int tile_count; Xextern int seed; Xextern Selected selected[2]; X X/* local globals */ X XSelected undo_tiles[144][2]; Xint undo_count; Xboolean help_mode = FALSE; Xboolean query_mode = FALSE; X X/*******************************************/ X Xvoid panel_msg(string, cursor_image) Xchar *string; XPixrect *cursor_image; X X{ X static char *old_string = (char *)0; X X if (string) { X X if (old_string) X panel_set(message,PANEL_SHOW_ITEM, FALSE, 0); X X panel_set(message, PANEL_LABEL_STRING, X string, PANEL_SHOW_ITEM, TRUE, 0); X X window_set(message_panel, WIN_IGNORE_PICK_EVENTS, X WIN_MOUSE_BUTTONS, 0, 0); X window_set(message_panel, WIN_IGNORE_KBD_EVENT, X WIN_ASCII_EVENTS, 0, 0); X cursor_set(play_cursor, CURSOR_IMAGE, cursor_image, 0); X window_set(play_panel, WIN_CURSOR, play_cursor, 0); X X } else { X X panel_set(message,PANEL_SHOW_ITEM, FALSE, 0); X window_set(message_panel, WIN_CONSUME_PICK_EVENTS, X WIN_MOUSE_BUTTONS, 0, 0); X window_set(message_panel, WIN_CONSUME_KBD_EVENT, X WIN_ASCII_EVENTS, 0, 0); X cursor_set(play_cursor, CURSOR_IMAGE, cursor_image, 0); X window_set(play_panel, WIN_CURSOR, play_cursor, 0); X X } X X old_string = string; X X} X Xvoid help_proc(item, event) XPanel_item item; XEvent *event; X X{ X int i; X Tiles *data[2]; X static int parse[2] = { 0, 0 }; X X if(!(selected[0].filled)) X { X if(!(help_mode)) { /* Just starting. init and recall */ X X help_mode = TRUE; X parse[0] = 143; X parse[1] = 142; X X } X X for(; parse[0] >= 0; parse[0]--) X { X if (!((board[parse[0]]->top_free && /* uncovered */ X (board[parse[0]]->left_free || board[parse[0]]->right_free) && /* open */ X (!(board[parse[0]]->removed))))) { /* not already used */ X X continue; /* not available go to next */ X X } X X for(; parse[1] >= 0; parse[1]--) { /* check for second tile */ X X if ((board[parse[0]]->value == board[parse[1]]->value) && /* right value */ X (parse[0] != parse[1]) && /* different item */ X (board[parse[1]]->top_free && /* uncovered */ X (board[parse[1]]->left_free || board[parse[1]]->right_free) && /* open */ X (!(board[parse[1]]->removed)))) { /* not already used */ X X /* Found a match, show it */ X X /* flag found items */ X selected[0].filled = TRUE; X selected[1].filled = TRUE; X X /* fake in some data */ X selected[0].item = tile[parse[0]]; X selected[0].event.ie_locx = ((int) panel_get(tile[parse[0]], PANEL_ITEM_X) + 10); X selected[0].event.ie_locy = ((int) panel_get(tile[parse[0]], PANEL_ITEM_Y) + 10); X selected[0].event.ie_time.tv_sec = event->ie_time.tv_sec; X selected[0].event.ie_time.tv_usec = event->ie_time.tv_usec; X X selected[1].item = tile[parse[1]]; X selected[1].event.ie_locx = ((int) panel_get(tile[parse[1]], PANEL_ITEM_X) + 10); X selected[1].event.ie_locy = ((int) panel_get(tile[parse[1]], PANEL_ITEM_Y) + 10); X selected[1].event.ie_time.tv_sec = event->ie_time.tv_sec; X selected[1].event.ie_time.tv_usec = event->ie_time.tv_usec; X X /* Muppet news flash */ X panel_begin_preview(selected[0].item, selected[0].event); X panel_begin_preview(selected[1].item, selected[1].event); X X panel_msg("Show next move? [Y] [] [N]", &confirm); X X parse[1]--; /* do loop step */ X return; /* all done this rotation */ X X } X X } /* else go to next */ X X parse[1] = parse[0] - 2; /* going around again */ X X } X X /* no more moves beep and show message */ X X help_mode = FALSE; X window_bell(main_frame); X panel_msg((char *)0, &stick); X X } else { /* search for available match */ X X if (selected[1].filled) { /* deselect last choice */ X X /* cancel preview of selected tiles */ X panel_cancel_preview(selected[1].item, selected[1].event); X /* Clean up selected's variables */ X selected[1].filled = FALSE; X X } X X if (!query_mode) { X X query_mode = TRUE; X parse[0] = 143; X X } X X data[0] = (Tiles *) panel_get(selected[0].item, PANEL_CLIENT_DATA); X X for(i = parse[0]; i >= 0; i--) { X X if ((board[i]->value == data[0]->value) && /* right value */ X (tile[i] != selected[0].item) && /* different item */ X (board[i]->top_free && /* uncovered */ X (board[i]->left_free || board[i]->right_free) && /* open */ X (!(board[i]->removed)))) { /* not already used */ X X /* found one */ X X /* fake in some selected data */ X X selected[1].item = tile[i]; X selected[1].event.ie_locx = ((int) panel_get(tile[i], PANEL_ITEM_X) + 10); X selected[1].event.ie_locy = ((int) panel_get(tile[i], PANEL_ITEM_Y) + 10); X selected[1].event.ie_time.tv_sec = 10; /*sounds good */ X selected[1].event.ie_time.tv_usec = 10; /*sounds good */ X X selected[1].filled = TRUE; X X /* turn on preview */ X X panel_begin_preview(selected[1].item, selected[1].event); X X /* set confirm message */ X X panel_msg("Please confirm. [Y] [NEXT] [N]", &confirm); X X /* return to sender */ X X parse[0] = i - 1; X return; X X } X } X X query_mode = FALSE; X selected[0].filled = FALSE; X panel_cancel_preview(selected[0].item, selected[0].event); X panel_msg((char *)0, &stick); X window_bell(main_frame); X X } X} X Xvoid remove_tiles(REMOVE) Xboolean REMOVE; X X{ XTiles *data[2]; Xint i; Xint tiles_left_hun; Xint tiles_left_ten; Xint tiles_left_one; XPixwin *pw; XRect *r; X X if (REMOVE) { X /* get data from items to be removed */ X data[0] = (Tiles *) panel_get(selected[0].item, PANEL_CLIENT_DATA); X data[1] = (Tiles *) panel_get(selected[1].item, PANEL_CLIENT_DATA); X X } else { X /* get data from items to be replaced */ X data[0] = (Tiles *) panel_get(undo_tiles[undo_count][0].item, PANEL_CLIENT_DATA); X data[1] = (Tiles *) panel_get(undo_tiles[undo_count][1].item, PANEL_CLIENT_DATA); X } X X /* adjust adjacent tiles */ X for(i = 0; i < 2 && data[0]->left_next[i] != 999; board[data[0]->left_next[i]]->right_free = REMOVE, i++); X for(i = 0; i < 2 && data[1]->left_next[i] != 999; board[data[1]->left_next[i]]->right_free = REMOVE, i++); X for(i = 0; i < 2 && data[0]->right_next[i] != 999; board[data[0]->right_next[i]]->left_free = REMOVE, i++); X for(i = 0; i < 2 && data[1]->right_next[i] != 999; board[data[1]->right_next[i]]->left_free = REMOVE, i++); X X /* adjust covered tiles and images */ X for(i = 0; i < 4 && data[0]->covered[i] != 999; board[data[0]->covered[i]]->top_free = REMOVE, i++) X panel_set(tile[data[0]->covered[i]], PANEL_LABEL_IMAGE, (REMOVE || data[0]->covered[i] >= 139) ? board[data[0]->covered[i]]->image : (BandW) ? &BLANK : &cBLANK, 0); X for(i = 0; i < 4 && data[1]->covered[i] != 999; board[data[1]->covered[i]]->top_free = REMOVE, i++) X panel_set(tile[data[1]->covered[i]], PANEL_LABEL_IMAGE, (REMOVE || data[1]->covered[i] >= 139) ? board[data[1]->covered[i]]->image : (BandW) ? &BLANK : &cBLANK, 0); X X /* set removed flags */ X data[0]->removed = REMOVE; X data[1]->removed = REMOVE; X X if (REMOVE) { X /* turn off preview */ X panel_cancel_preview(selected[0].item, selected[0].event); X panel_cancel_preview(selected[1].item, selected[1].event); X } else /* check to see if previewing an item and un-preview and select */ X if (selected[0].filled) { X panel_cancel_preview(selected[0].item, selected[0].event); X selected[0].filled = FALSE; X } X X /* fix playing field */ X panel_paint(play_panel, PANEL_NONE); X panel_set((REMOVE) ? selected[0].item : undo_tiles[undo_count][0].item, PANEL_SHOW_ITEM, !REMOVE, 0); X panel_set((REMOVE) ? selected[1].item : undo_tiles[undo_count][1].item, PANEL_SHOW_ITEM, !REMOVE, 0); X panel_paint(play_panel, PANEL_NO_CLEAR); X X /* deselect tiles */ X selected[0].filled = FALSE; X selected[1].filled = FALSE; X X /* fix tile counter */ X tile_count += (REMOVE) ? -2 : 2; X X tiles_left_hun = tile_count / 100; X tiles_left_ten = (tile_count - (tiles_left_hun * 100)) / 10; X tiles_left_one = tile_count - (tiles_left_hun * 100) - (tiles_left_ten * 10); X X /* display hundreds tile by own status */ X panel_set(TL_hundred, PANEL_SHOW_ITEM, tiles_left_hun, 0); X X /* display tens tile by own status ored with hundreds status */ X panel_set(TL_ten, PANEL_SHOW_ITEM, tiles_left_hun || tiles_left_ten, 0); X X switch(tiles_left_ten) { X case 0: X panel_set(TL_ten, PANEL_LABEL_IMAGE, (BandW) ? &NUM0 : &cNUM0, 0); X break; X case 1: X panel_set(TL_ten, PANEL_LABEL_IMAGE, (BandW) ? &NUM1 : &cNUM1, 0); X break; X case 2: X panel_set(TL_ten, PANEL_LABEL_IMAGE, (BandW) ? &NUM2 : &cNUM2, 0); X break; X case 3: X panel_set(TL_ten, PANEL_LABEL_IMAGE, (BandW) ? &NUM3 : &cNUM3, 0); X break; X case 4: X panel_set(TL_ten, PANEL_LABEL_IMAGE, (BandW) ? &NUM4 : &cNUM4, 0); X break; X case 5: X panel_set(TL_ten, PANEL_LABEL_IMAGE, (BandW) ? &NUM5 : &cNUM5, 0); X break; X case 6: X panel_set(TL_ten, PANEL_LABEL_IMAGE, (BandW) ? &NUM6 : &cNUM6, 0); X break; X case 7: X panel_set(TL_ten, PANEL_LABEL_IMAGE, (BandW) ? &NUM7 : &cNUM7, 0); X break; X case 8: X panel_set(TL_ten, PANEL_LABEL_IMAGE, (BandW) ? &NUM8 : &cNUM8, 0); X break; X case 9: X panel_set(TL_ten, PANEL_LABEL_IMAGE, (BandW) ? &NUM9 : &cNUM9, 0); X break; X } X X switch(tiles_left_one) { /* only need even tiles */ X case 0: X panel_set(TL_one, PANEL_LABEL_IMAGE, (BandW) ? &NUM0 : &cNUM0, 0); X break; X case 2: X panel_set(TL_one, PANEL_LABEL_IMAGE, (BandW) ? &NUM2 : &cNUM2, 0); X break; X case 4: X panel_set(TL_one, PANEL_LABEL_IMAGE, (BandW) ? &NUM4 : &cNUM4, 0); X break; X case 6: X panel_set(TL_one, PANEL_LABEL_IMAGE, (BandW) ? &NUM6 : &cNUM6, 0); X break; X case 8: X panel_set(TL_one, PANEL_LABEL_IMAGE, (BandW) ? &NUM8 : &cNUM8, 0); X break; X } X X if (REMOVE) { X X /* update undo_count */ X undo_count++; X X /* update removed array */ X undo_tiles[undo_count][0].item = selected[0].item; X undo_tiles[undo_count][0].event.ie_locx = selected[0].event.ie_locx; X undo_tiles[undo_count][0].event.ie_locy = selected[0].event.ie_locy; X undo_tiles[undo_count][0].event.ie_time.tv_sec = selected[0].event.ie_time.tv_sec; X undo_tiles[undo_count][0].event.ie_time.tv_usec = selected[0].event.ie_time.tv_usec; X undo_tiles[undo_count][0].filled = TRUE; X X undo_tiles[undo_count][1].item = selected[1].item; X undo_tiles[undo_count][1].event.ie_locx = selected[1].event.ie_locx; X undo_tiles[undo_count][1].event.ie_locy = selected[1].event.ie_locy; X undo_tiles[undo_count][1].event.ie_time.tv_sec = selected[1].event.ie_time.tv_sec; X undo_tiles[undo_count][1].event.ie_time.tv_usec = selected[1].event.ie_time.tv_usec; X undo_tiles[undo_count][1].filled = TRUE; X X /* remove confirm message */ X X panel_msg((char *)0, &stick); X X /* check for clean board and congrat them */ X X if ( tiles_left_hun == 0 && tiles_left_ten == 0 && tiles_left_one == 0) X panel_set(message, PANEL_LABEL_STRING, X "Congratulations!! Press 'AGAIN' or 'NEW'", X PANEL_SHOW_ITEM, X TRUE, 0); X X } else { /* decrement undo_count */ X undo_tiles[undo_count][0].filled = FALSE; X undo_tiles[undo_count][1].filled = FALSE; X undo_count--; X } X} X Xvoid play_back_proc(where, event) XPanel where; XEvent *event; X{ X if (!event_is_down(event)) X return; X X if ((event_id(event) == MS_MIDDLE) && selected[0].filled && !help_mode) { X X help_proc(); X X } else { X X query_mode = FALSE; X X if (selected[1].filled) { /* doing confirm or next help */ X X switch (event_id(event)) { X X case MS_LEFT: X /* confirmed selection */ X if (help_mode) { /* do next help */ X X /* cancel preview of selected tiles */ X panel_cancel_preview(selected[0].item, selected[0].event); X panel_cancel_preview(selected[1].item, selected[1].event); X /* Clean up selected's variables */ X selected[0].filled = FALSE; X selected[1].filled = FALSE; X X /* do next help */ X help_proc(selected[0].item, event); X X } else { /* confirmed selection. remove them */ X X remove_tiles(TRUE); X X } X break; X X case MS_RIGHT: X /* refused selection */ X X /* cancel preview of selected tiles */ X panel_cancel_preview(selected[0].item, selected[0].event); X panel_cancel_preview(selected[1].item, selected[1].event); X /* Clean up selected's variables */ X selected[0].filled = FALSE; X selected[1].filled = FALSE; X X /* remove confirm message */ X X panel_msg((char *)0, &stick); X X /* if in help mode toggle out */ X if (help_mode) X help_mode = FALSE; X X break; X X } X } X } X} X Xvoid play_event_proc(item, event) XPanel_item item; XEvent *event; X X{ X Tiles *data; X int value; X int i; X int x; X int y; X X if (!event_is_down(event)) X return; X X /* check to see if in help_mode */ X X if (help_mode || query_mode) { X play_back_proc(play_panel, event); X return; X } X X /* check to see if just confirming */ X X if (selected[1].filled) { X play_back_proc(play_panel, event); X return; X } X X /* translate item to top level available */ X X if ((event_id(event) == MS_LEFT) && X ((ROW2 - B_TILE_SHADOW) <= event->ie_locy) && X (event->ie_locy <= (ROW2 - B_TILE_SHADOW + (6 * W_BASE_TILE))) && X ((COL5 - S_TILE_SHADOW) <= event->ie_locx) && X (event->ie_locx <= (COL5 - S_TILE_SHADOW + (6 * H_BASE_TILE))) ) { /* in overlap area, check for stacks */ X X for(i = 143; i > 86 ; i--) { /* check from top to bottom */ X X x = (int) panel_get(tile[i], PANEL_ITEM_X); X y = (int) panel_get(tile[i], PANEL_ITEM_Y); X X if ((x <= event->ie_locx) && X (event->ie_locx <= x + W_BASE_TILE) && X (y <= event->ie_locy) && X (event->ie_locy <= y + H_BASE_TILE)) { /* right spot */ X X if ( !(board[i]->removed) ) { X X item = tile[i]; /* got it */ X break; X X } else if (i != 143) { /* look on next layer down */ X /* take first covered tile and add 1 for loop */ X i = board[i]->covered[0] + 1; X } X X } /* wrong location. try again */ X X } /* next loop */ X X } X X /* get data from item selected */ X X data = (Tiles *) panel_get(item, PANEL_CLIENT_DATA); X value = data->value; X X switch(event_id(event)) { X X case MS_LEFT: X /* Left button down begin selection */ X if ( data->top_free && (data->left_free || data->right_free)) { X X if (!(selected[0].filled)) { X X /* fill first selection if empty */ X selected[0].item = item; X selected[0].event.ie_locx = event->ie_locx; X selected[0].event.ie_locy = event->ie_locy; X selected[0].event.ie_time.tv_sec = event->ie_time.tv_sec; X selected[0].event.ie_time.tv_usec = event->ie_time.tv_usec; X X selected[0].filled = TRUE; X panel_begin_preview(selected[0].item, selected[0].event); X X } else { X X if (item == selected[0].item) { /* deselect item */ X X selected[0].filled = FALSE; X panel_cancel_preview(selected[0].item, selected[0].event); X X } else { X data = (Tiles *) panel_get(selected[0].item, PANEL_CLIENT_DATA); X if ( value == data->value) { X /* fill second and show confirm message */ X X selected[1].item = item; X selected[1].event.ie_locx = event->ie_locx; X selected[1].event.ie_locy = event->ie_locy; X selected[1].event.ie_time.tv_sec = event->ie_time.tv_sec; X selected[1].event.ie_time.tv_usec = event->ie_time.tv_usec; X X selected[1].filled = TRUE; X panel_begin_preview(selected[1].item, selected[1].event); X X panel_msg("Please confirm. [Y] [] [N]", &confirm); X X } else { /* beep at them */ X X window_bell(main_frame); X X } X } X } X X } else { /* beep at them */ X X window_bell(main_frame); X X } X break; X X case MS_MIDDLE: X if (selected[0].filled) { /* request for help */ X X help_proc(); X X } X break; X X /* and all else shall pass */ X } X} X Xvoid quit_proc() X{ X window_destroy(main_frame); X} X Xvoid new_proc() X{ X X seed = random() % 20011; X build_image(FALSE); X place_tiles(FALSE); X} X Xvoid again_proc() X{ X build_image(TRUE); X place_tiles(FALSE); X} X Xvoid undo_proc() X X{ X if(undo_count < 0) X window_bell(main_frame); X else X remove_tiles(FALSE); X} X Xvoid board_num_proc() X{ X sscanf((char *) panel_get(board_num, PANEL_VALUE), "%d", &seed); X build_image(FALSE); X place_tiles(FALSE); X} END_OF_event.c if test 16933 -ne `wc -c <event.c`; then echo shar: \"event.c\" unpacked with wrong size! fi # end of overwriting check fi echo shar: End of archive 1 \(of 1\). cp /dev/null ark1isdone MISSING="" for I in 1 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 1 archives. rm -f ark[1-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0