[comp.sources.games] v06i036: pc-mahjongg - solitaire mahjongg for IBM PC family

games@tekred.CNA.TEK.COM (03/23/89)

Submitted-by: Joerg Hattenhauer <uunet!unido!jah>
Posting-number: Volume 6, Issue 36
Archive-name: pc-mahjongg/Part01

	[This is a port of mahjongg2 and mahjongg-pc to the IBM PC
	 family with Turbo-C and Hercules graphics adapter.  An MS-DOS
	 binary has already been posted to comp.binaries.ibm.pc  -br]

#! /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 4)."
# Contents:  README MANIFEST event.c mahjongg.6 mahjongg.c mahjongg.h
#   mahjongg.man screen.c tiles tiles.c tiles/s_autumn.img
#   tiles/s_spring.img tiles/s_winter.img
# Wrapped by billr@saab on Wed Mar 22 15:53:16 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(1274 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
XThis is a version of the Mahjongg game ported to the PC-Family.
XIt came from the version by Mark Holm for the Sun, and the Version
Xby Tom Tkacik for the UNIXPC.
X
XThe manual is in mahjongg.6 and mahjongg.man.
X
XIf you have any problems with this version do not complain to Mark or Tom.
XPlease address all questions to me (...!uunet!unido!jah).
X
XAll of the code, except for screen.c and mouse.c, retains the copyrights
Xof Mark Holm.
X
XTo make a running copy of mahjongg you need to:
X
X- create a directory named mahjongg
X- put all files (except the *.img and *.but) in a directory
X- within this directory create a subdirectory named tiles
X- put all *.img and *.but files in this subdir
X- use the 'bgiobj' programm that was delivered with your copy of
X  Turbo-C 1.5/2.0 to create the files 'hercf.obj' and 'tripf.obj'.
X  to create the two objectfiles type the commands:
X        bgiobj /F herc
X        bgiobj /F trip
X- put these objectfiles in your mahjongg-dir or change the path
X  in the project-file according to your environment
X- then 'cd' to your mahjongg-dir and type 'tc' from the dos prompt
X- within Turbo-C change the name of your project-file to mahjongg.prj
X- change the compilers memory-model to MEDIUM
X- type 'F9'
X
XHave fun
X                        Joerg Hattenhauer
X
END_OF_FILE
if test 1274 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'MANIFEST'\"
else
echo shar: Extracting \"'MANIFEST'\" \(2005 characters\)
sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
X   File Name		Archive #	Description
X-----------------------------------------------------------
X MANIFEST                   1	This shipping list
X README                     1	
X event.c                    1	
X mahjongg.6                 1	
X mahjongg.c                 1	
X mahjongg.h                 1	
X mahjongg.man               1	
X mahjongg.prj               2	
X mouse.c                    2	
X screen.c                   1	
X tiles                      1	
X tiles.c                    1	
X tiles/bam1.img             3	
X tiles/bam2.img             4	
X tiles/bam3.img             3	
X tiles/bam4.img             3	
X tiles/bam5.img             3	
X tiles/bam6.img             3	
X tiles/bam7.img             3	
X tiles/bam8.img             3	
X tiles/bam9.img             3	
X tiles/blank.img            2	
X tiles/c_east.img           2	
X tiles/c_north.img          2	
X tiles/c_south.img          2	
X tiles/c_west.img           2	
X tiles/char1.img            2	
X tiles/char2.img            2	
X tiles/char3.img            2	
X tiles/char4.img            2	
X tiles/char5.img            2	
X tiles/char6.img            3	
X tiles/char7.img            2	
X tiles/char8.img            2	
X tiles/char9.img            3	
X tiles/circ1.img            3	
X tiles/circ2.img            3	
X tiles/circ3.img            3	
X tiles/circ4.img            3	
X tiles/circ5.img            3	
X tiles/circ6.img            3	
X tiles/circ7.img            3	
X tiles/circ8.img            3	
X tiles/circ9.img            2	
X tiles/d_green.img          2	
X tiles/d_red.img            2	
X tiles/d_white.img          2	
X tiles/f_bam.img            3	
X tiles/f_mum.img            3	
X tiles/f_orch.img           2	
X tiles/f_plum.img           2	
X tiles/help.but             4	
X tiles/new.but              4	
X tiles/quit.but             4	
X tiles/removed.img          4	
X tiles/replay.but           4	
X tiles/s_autumn.img         1	
X tiles/s_spring.img         1	
X tiles/s_summer.img         2	
X tiles/s_winter.img         1	
X tiles/undo.but             4	
END_OF_FILE
if test 2005 -ne `wc -c <'MANIFEST'`; then
    echo shar: \"'MANIFEST'\" unpacked with wrong size!
fi
# end of 'MANIFEST'
fi
if test -f 'event.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'event.c'\"
else
echo shar: Extracting \"'event.c'\" \(8144 characters\)
sed "s/^X//" >'event.c' <<'END_OF_FILE'
X
X/*
X *	This program contains much of the code from the original
X *	 Sun version of mahjongg, written by Mark Holm, and the
X *	 port/rewrite for the UNIXPC, written by Tom Tkacik. Both
X *	 were inspired by the PC version.
X *
X *	This version of Mahjongg was modified/re-written/ported
X *	 for/to the PC-Family    by Joerg Hattenhauer
X *
X */
X
X/*
X *	Copyright 1988, Mark Holm
X *			Exceptions
X *
X *	Permission is given to copy and distribute for non-profit purposes.
X *
X */
X
X
X/*      This file has the event handlers for the background and
X *       tiles in the play panel
X */
X
X#include <dos.h>
X#include <stdio.h>
X#include <stdlib.h>
X#include "mahjongg.h"
X
Xint	undo_tiles[NUMTILES][2];
Xint	undo_count = 0;
Xint	help_mode = FALSE;
Xint	query_mode = FALSE;
Xint	tile_count;
Xint	selected[2];
X
X
X/*******************************************/
X
X/*
X * help the user -- show matching tiles
X */
X
Xhelp_proc()
X{
X	int         i;
X	static int  parse[2] = { 0, 0 };
X    static boolean     match_found;
X
X	if(selected[0] == -1) { /* find all pairs of matching tiles */
X
X	     /* if not in help mode, initialize search */
X		if(!(help_mode)) {
X			help_mode = TRUE;
X            match_found = FALSE;
X			parse[0] = 143;
X			parse[1] = 142;
X		}
X
X	     /* look for a free tile */
X		for(; parse[0] >= 0; parse[0]--) {
X			if(!((tiles[parse[0]].top_free && 
X		 	     (tiles[parse[0]].left_free ||
X			      tiles[parse[0]].right_free) &&
X			   (!(tiles[parse[0]].removed))))) {
X
X				continue; /* not available -- try another */
X			}
X
X		     /* found a free tile */
X		     /* check for a matching second tile */
X			for(; parse[1] >= 0; parse[1]--) {
X				if((tiles[parse[0]].value ==
X						tiles[parse[1]].value) &&
X				   (parse[0] != parse[1]) &&
X			    	   (tiles[parse[1]].top_free &&
X			           (tiles[parse[1]].left_free ||
X						tiles[parse[1]].right_free) &&
X			    	 (!(tiles[parse[1]].removed)))) {
X
X			    	     /* Found a match -- show them */
X                        match_found = TRUE;
X			    		selected[0] = parse[0];
X			    		selected[1] = parse[1];
X			    		preview_tile(selected[0]);
X			    		preview_tile(selected[1]);
X
X                        /* prepare for next help */
X			    		parse[1]--;
X			    		return;
X				}
X			}
X
X		     /* no matching tile was found */
X		     /* look for the next free tile */
X
X		     /* going around again */
X			parse[1] = parse[0] - 2;
X
X		}
X
X	     /* we found all matching tiles -- beep and leave help mode */
X		help_mode = FALSE;
X		window_bell();
X        if (!match_found)
X            wcmd ("No more moves!");
X
X	} else {  /* user selected one tile -- look for a match */
X
X         /* deselect previous choice if there was one */
X         /* and cancel preview of it */
X		if (selected[1] != -1) {
X			preview_tile(selected[1]);
X			selected[1] = -1;
X		}
X
X
X	     /* if not in query mode then start the search */
X	     /* otherwise, continue from last tile */
X		if (!query_mode) {
X			query_mode = TRUE;
X			parse[0] = 143;
X		}
X
X
X		for(i = parse[0]; i >= 0; i--) {
X
X		     /* is this a match */
X			if ((tiles[i].value == tiles[selected[0]].value) &&
X			    (i != selected[0]) &&
X			    (tiles[i].top_free &&
X			    (tiles[i].left_free || tiles[i].right_free) &&
X                (!(tiles[i].removed)))) {
X
X			     /* yes, we found one */
X			     /* show it */
X				selected[1] = i;
X				preview_tile(selected[1]);
X
X			     /* return to sender */
X				parse[0] = i - 1;
X				return;
X		    	}
X		}
X
X         /* oops! could not find a match -- stop search */
X        query_mode = FALSE;
X        preview_tile(selected[0]);
X        selected[0]= -1;
X        window_bell();
X
X    }
X}
X
X/*
X * remove (or restore) selected tiles
X */
X
Xremove_tiles(REMOVE)
Xboolean	REMOVE;
X{
X	int	data[2];
X	int	i;
X
X	if (REMOVE) {   /* get tiles to be removed */
X
X		data[0] = selected[0];
X		data[1] = selected[1];
X
X	} else { 	/* or those to be replaced */
X
X		data[0] = undo_tiles[undo_count][0];
X		data[1] = undo_tiles[undo_count][1];
X
X	}
X
X     /* adjust adjacent tiles */
X	for(i = 0; i < 2 && tiles[data[0]].left_next[i] != -1; i++)
X		tiles[tiles[data[0]].left_next[i]].right_free = REMOVE;
X
X	for(i = 0; i < 2 && tiles[data[1]].left_next[i] != -1; i++)
X		tiles[tiles[data[1]].left_next[i]].right_free = REMOVE;
X
X	for(i = 0; i < 2 && tiles[data[0]].right_next[i] != -1; i++)
X		tiles[tiles[data[0]].right_next[i]].left_free = REMOVE;
X
X	for(i = 0; i < 2 && tiles[data[1]].right_next[i] != -1; i++)
X		tiles[tiles[data[1]].right_next[i]].left_free = REMOVE;
X
X     /* adjust covered tiles */
X	for(i = 0; i < 4 && tiles[data[0]].covered[i] != -1; i++)
X		tiles[tiles[data[0]].covered[i]].top_free = REMOVE;
X
X	for(i = 0; i < 4 && tiles[data[1]].covered[i] != -1; i++)
X		tiles[tiles[data[1]].covered[i]].top_free = REMOVE;
X
X     /* set removed flags */
X	tiles[data[0]].removed = REMOVE;
X	tiles[data[1]].removed = REMOVE;
X
X	if (REMOVE) {
X
X	     /* turn off preview */
X        /*
X        preview_tile(selected[0]);
X		preview_tile(selected[1]);
X        */
X
X         /* remove tiles before redisplay */
X        erase_tile (data[0]);
X        erase_tile (data[1]);
X
X	} else {
X
X	     /* turn off preview of any selected tiles */
X
X		if(selected[0] != -1) {
X			preview_tile(selected[0]);
X		}
X
X		if(selected[1] != -1) {
X			preview_tile(selected[1]);
X		}
X	}
X
X     /* fix tile counter */
X	tile_count += (REMOVE) ? -2 : 2;
X
X	if (REMOVE) {
X
X	     /* update undo_count */
X		undo_count++;
X
X	     /* update removed array */
X		undo_tiles[undo_count][0] = selected[0];
X		undo_tiles[undo_count][1] = selected[1];
X
X	     /* check for clean board and congrat them */
X		if(tile_count == 0)
X            wcmd("Congratulations!! You did it!");
X
X	} else { /* decrement undo_count */
X		undo_tiles[undo_count][0] = -1;
X		undo_tiles[undo_count][1] = -1;
X		undo_count--;
X	}
X
X     /* deselect tiles */
X     /* we will redisplay the playing field so no need to unpreview */
X	selected[0] = -1;
X	selected[1] = -1;
X
X     /* show the corrected playing field */
X	draw_tiles();
X}
X
X/*
X * perform secondary mouse actions 
X */
X
Xplay_back_proc(button)
Xint		button;
X{
X
X	if ((button == MBUTM) && (selected[0] != -1) && !help_mode) {
X
X	     /* he wants to be shown a matching tile */
X		help_proc();
X
X	} else {
X
X		query_mode = FALSE;
X
X        if ((selected[1] != -1) && (button == MBUTL)) {
X
X            /* confirmed selection. remove them */
X           remove_tiles(TRUE);
X
X            /* leave help_mode */
X           help_mode = FALSE;
X	}
X
X    }
X}
X
X/*
X * perform mouse action
X */
X
Xplay_event_proc(i, button)
Xint	i;
Xint	button;
X{
X     /* check to see if in help_mode */
X	if (help_mode || query_mode) {
X		play_back_proc(button);
X		return;
X	}
X
X     /* check to see if just confirming */
X    if (selected[1] != -1) {
X		play_back_proc(button);
X		return;
X	}
X
X	switch(button) {
X
X	case MBUTL: 
X
X	     /* Left button down begin selection */
X
X         /* if no tile is selected then just ignore it */
X		if (i == -1)
X			return;
X
X		if (selected[0] == -1) {
X
X		     /* select first tile of pair */
X			selected[0] = i;
X			preview_tile(selected[0]);
X
X		} else if (selected[0] == i) {
X
X		     /* deselect first tile */
X			preview_tile(selected[0]);
X			selected[0] = -1;
X
X		} else if(tiles[selected[0]].value == tiles[i].value) {
X
X		     /* select second tile */
X			selected[1] = i;
X			preview_tile(selected[1]);
X
X		} else {
X
X		     /* illegal move -- beep at them */
X			window_bell();
X		}
X
X		break;
X
X	case MBUTM:
X		if (selected[0] != -1) {
X
X		     /* request for help */
X			help_proc();
X		}
X
X		break;
X
X		/* and all else shall pass */
X	}
X}
X
X/*
X * undo the last move -- may be called repeatedly
X */
X
Xundo_proc()
X{
X    /* if some tiles are selected, unselect them */
X    if (selected[0] != -1) {
X        /* if in help_mode, leave help */
X       help_mode = FALSE;
X
X        /* if in query_mode, leave query */
X       query_mode = FALSE;
X
X        /* deselect first tile */
X       preview_tile(selected[0]);
X       selected[0] = -1;
X       if (selected[1] != -1) {
X           /* deselect second tile */
X          preview_tile(selected[1]);
X          selected[1] = -1;
X        }
X    } else
X        /* no tiles are selected so try undoing last move */
X        if (undo_count < 0)
X           window_bell();
X        else
X           remove_tiles(FALSE);
X}
X
END_OF_FILE
if test 8144 -ne `wc -c <'event.c'`; then
    echo shar: \"'event.c'\" unpacked with wrong size!
fi
# end of 'event.c'
fi
if test -f 'mahjongg.6' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'mahjongg.6'\"
else
echo shar: Extracting \"'mahjongg.6'\" \(3597 characters\)
sed "s/^X//" >'mahjongg.6' <<'END_OF_FILE'
X.\"	Copyright 1988 Mark A. Holm
X.\"
X.\"	Permission is given to copy and distribute for non-profit purposes.
X.\"
X.TH MAHJONGG 6 "1 August 1988"
X.SH NAME
Xmahjongg \- Solitaire game using mahjongg tiles
X.SH SYNOPSIS
X.B /usr/games/mahjongg
X[ \fI###\fR ]
X.SH DESCRIPTION
XMah jongg
Xis an ancient chinese game whose origins are supposed to date back around
X3000 years. It is typically a four player game with similarities to most
Xpopular card games. This version is a solitaire game using the mahjongg
Xtiles.
XIt has been ported to the PC-Family from the UNIXPC version of the SUN version, which was
Xinspired by a version originally seen on a PC with EGA-Adaptor. 
X.SH THEORY OF PLAY
XThe object of the game is to remove all the tiles from the board in matching
Xpairs. Tiles match only if they are identical. Exceptions are the flower
Xand season tiles. Any season tile will match any other season tile and any
Xflower tile will match any other flower tile. Tiles may be removed from the
Xboard only if they have either a left or a right edge open and they do not have
Xa tile covering them.
X.PP
XThe display is divided into two areas:  the play area, which shows the
Xtiles, the control area, which shows the
Xnumber of tiles remaining and the game control buttons.  As tiles are removed
Xthe "Tiles Remaining" count will be updated and play related messages and
Xmouse button defintions will 
Xbe shown just above the tilecount.
X.PP
XTiles are selected by placing the mouse icon on a tile and pressing the left
Xbutton. To deselect a tile simply repress the left button while on the tile.
XAfter selecting a pair of tiles, simply press the left mouse button again
Xto confirm your choice or the the right mouse button to cancel.
X.SH HELP FEATURES
XTwo help features are currently implemented. By selecting the "help" button
Xor pressing the middle mouse button
Xwhen no tiles are selected, you will be shown all available
Xtile combinations. To see each combination press the left mouse button while
Xthe mouse cursor is on the "help" button or press the middle mouse button
Xuntil no more moves are shown. To cancel "help" press the
Xright mouse button. If you have selected a tile, pressing the middle mouse
Xbutton, or selecting the "help" button, will find the 
Xfirst matching tile (if any) starting at the top of the pile and working down.
XIf a match is found, press the left mouse button while the mouse cursor
Xis not on a button and the pair will be removed from the board.
XIf an alternate match is available pressing the middle mouse button
Xwill show it.
X.SH UNDO
XSince some people tend to be a little faster on the mouse then they should be,
Xthe undo feature was implemented. The "undo" button replaces the previous
Xpair that was removed from board. You can continue to press undo until you
Xget back to a new board.
X.SH NEW and SAME
XSelecting the "new" button restarts the game with a new
Xboard. Selecting the "replay" button restarts the game using the same board.
XEither button may be used at any time during the game.
X.SH OPTIONS
X.IP \fI###\fR
XStart with board number ###. Boards through 32768 are available.
X.SH DIAGNOSTICS
X.SH FILES
X/usr/games/mahjongg			executable
X.SH AUTHOR
XCopyright 1988 Mark A. Holm
X.br
X<tektronix!tessi!exc!markh>
X.sp
XPorted to the UNIXPC by Thomas Tkacik
X.br
X<rphroy!tetnix!tet>
X.sp
XPorted to the PC-Family by Joerg Hattenhauer
X.br
X<...!uunet!unido!jah>
X.SH BUGS
XBoard number is not checked very close. If you put something wierd in, you 
Xdeserve everthing you get.
X.PP
XNo score file. It is up to you to keep track of who did how well on what board.
X.PP
XNot as pretty as the SUN version.
END_OF_FILE
if test 3597 -ne `wc -c <'mahjongg.6'`; then
    echo shar: \"'mahjongg.6'\" unpacked with wrong size!
fi
# end of 'mahjongg.6'
fi
if test -f 'mahjongg.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'mahjongg.c'\"
else
echo shar: Extracting \"'mahjongg.c'\" \(10824 characters\)
sed "s/^X//" >'mahjongg.c' <<'END_OF_FILE'
X
X/*
X *	This program contains much of the code from the original
X *	 Sun version of mahjongg, written by Mark Holm, and the
X *	 port/rewrite for the UNIXPC, written by Tom Tkacik. Both
X *	 were inspired by the PC version.
X *
X *	This version of Mahjongg was modified/re-written/ported
X *	 for/to the PC-Family    by Joerg Hattenhauer
X *
X */
X
X/*
X *	Copyright 1988, Mark Holm
X *			Exceptions
X *
X *	Permission is given to copy and distribute for non-profit purposes.
X *
X */
X
X
X#include <dos.h>
X#include <stdio.h>
X#include <stdlib.h>
X#include "mahjongg.h"
X
Xint graphdriver,
X    graphmode;
X
X/* page to plot on */
Xint screen_page;
X
X/* number used to generate the current board */
Xint board;
X
X/* user specified a board */
Xboolean special_board;
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X     /* parse arguments --  boardnumber is the only allowed argument */
X    if (argc > 2)
X        leave ("Usage: mahjongg [boardnumber]", 1);
X
X    if (argc == 2) {
X       board = atoi (argv[1]);
X       special_board = TRUE;
X    } else {
X       randomize();
X       board = random (RAND_MAX);
X    }
X
X    if ((board < 0) || (board > RAND_MAX))
X        leave ("illegal boardnumber", 2);
X
X    initscreen();
X
X    initmouse(screen_page);
X
X    start_game();
X
X    dispatch();
X
X}
X
X/*
X * read input and call appropriate routines
X */
X
Xdispatch()
X{
X    int button, xpos, ypos, action;
X
X    showcur();
X    for (;;) {
X        get_button(&button, &xpos, &ypos);
X        action = what_action(button, xpos, ypos);
X        wcmd ("");
X        hidecur();
X        switch(action) {
X            case QUIT:
X                leave ("Ported to the PC-Family by\n\t\t\t\tJoerg Hattenhauer", 0);
X            case HELP:
X				help();
X				break;
X            case REPLAY:
X				start_game();
X				break;
X            case NEW:
X				new();
X				break;
X            case UNDO:
X				undo_proc();
X				break;
X            case TILE:
X                domouse(button,xpos,ypos);
X				break;
X			default:
X			     /* ignore all other input */
X				break;
X		}
X        showcur();
X	}
X}
X
X/*
X * which (screen)button was pressed?
X */
X
Xint what_action( Button, CurX, CurY)
Xint     Button,
X        CurX,
X        CurY;
X{
X    /*
X     * decides which screenbutton was pressed
X     * (HELP NEW REPLAY UNDO QUIT)
X     * tries do return a tile if no screenbutton was found
X     */
X    if (Button == MBUTM)
X        return HELP;
X    if (Button == MBUTR)
X        return UNDO;
X    if ( (CurX >= HelpButXPos) && (CurX <= HelpButXPos+ButtonXSize) &&
X         (CurY >= HelpButYPos) && (CurY <= HelpButYPos+ButtonYSize) )
X         return HELP;
X    if ( (CurX >= NewButXPos) && (CurX <= NewButXPos+ButtonXSize) &&
X         (CurY >= NewButYPos) && (CurY <= NewButYPos+ButtonYSize) )
X         return NEW;
X    if ( (CurX >= ReplayButXPos) && (CurX <= ReplayButXPos+ButtonXSize) &&
X         (CurY >= ReplayButYPos) && (CurY <= ReplayButYPos+ButtonYSize) )
X         return REPLAY;
X    if ( (CurX >= UndoButXPos) && (CurX <= UndoButXPos+ButtonXSize) &&
X         (CurY >= UndoButYPos) && (CurY <= UndoButYPos+ButtonYSize) )
X         return UNDO;
X    if ( (CurX >= QuitButXPos) && (CurX <= QuitButXPos+ButtonXSize) &&
X         (CurY >= QuitButYPos) && (CurY <= QuitButYPos+ButtonYSize) )
X         return QUIT;
X    return TILE;
X}
X
X
X/*
X * start a new game
X */
X
Xnew()
X{
X     /*
X      * if the user specified a board, randomize to get different
X      * boards after the same specified number
X      */
X    if (special_board) {
X        randomize();
X        special_board = FALSE;
X    }
X    board = random(RAND_MAX);
X	start_game();
X}
X
X/*
X * play the game with the current board number
X */
X
Xstart_game()
X{
X    srand(board);
X	tile_count = 144;
X    clear_window();
X
X     /* set the tiles up for randomizing */
X	initmahjongg();
X
X    draw_buttons();
X    show_board_nr (board);
X	draw_tiles();
X}
X
X/*
X * when the help button is pushed
X */
X
Xhelp()
X{
X	if((selected[0] != -1) && !help_mode) {
X
X	     /* in query mode */
X		help_proc();
X	} else {
X
X	     /* not in query mode */
X		query_mode = FALSE;
X
X	     /* cancel preview of selected tiles */
X		preview_tile(selected[0]);
X		preview_tile(selected[1]);
X
X	     /* Clean up selected's variables */
X		selected[0] = -1;
X		selected[1] = -1;
X
X	     /* do next help */
X		help_proc();
X	}
X}
X
X/*
X * when one of the mouse buttons is pushed
X */
X
Xdomouse(button,x,y)
Xint x, y, button;
X{
X	int i;
X
X     /* see if the mouse is in a free tile */
X	for(i = NUMTILES-1; i >= 0; i--) {
X	    	if((x >= tiles[i].x_pos) &&
X		   (x <  tiles[i].x_pos + TILE_X) &&
X		   (y >= tiles[i].y_pos) &&
X		   (y <  tiles[i].y_pos + TILE_Y) &&
X		   (tiles[i].removed == FALSE) &&
X		   (tiles[i].top_free == TRUE) &&
X		   ((tiles[i].left_free == TRUE) ||
X		    (tiles[i].right_free == TRUE))) {
X			break;
X		}
X	}
X
X    /* i will equal -1 if not on a legal tile */
X    play_event_proc(i, button);
X}
X
X/*
X * initialize the mahjongg tiles
X */
X
Xinitmahjongg()
X{
X	int i, j;
X
X	selected[0] = -1;
X	selected[1] = -1;
X	undo_count  = -1;
X
X     /* set up tiles for shuffling */
X	for(i = 0, j = 0; i < 34; i+=1, j+=4) {
X		tiles[j].value = i;
X		tiles[j].image = images[i];
X		tiles[j+1].value = i;
X		tiles[j+1].image = images[i];
X		tiles[j+2].value = i;
X		tiles[j+2].image = images[i];
X		tiles[j+3].value = i;
X		tiles[j+3].image = images[i];
X	}
X
X     /* now the one of a kind tiles */
X	for(i = 34, j = 136; i < 36; i+=1, j+=4) {
X		tiles[j].value = i;
X		tiles[j].image = images[j-136+34];
X		tiles[j+1].value = i;
X		tiles[j+1].image = images[j-136+34 + 1];
X		tiles[j+2].value = i;
X		tiles[j+2].image = images[j-136+34 + 2];
X		tiles[j+3].value = i;
X		tiles[j+3].image = images[j-136+34 + 3];
X	}
X
X     /* shuffle tiles */
X	for(i = NUMTILES-1; i > 0 ; i--) {
X		Tile temp;
X
X	     /* a random integer between 0 and i */
X        j = random(i+1);
X
X	     /* swap tiles */
X		temp = tiles[i];
X		tiles[i] = tiles[j];
X		tiles[j] = temp;
X	}
X
X	position_tiles();
X}
X
X/*
X * give each tile a position on the playing board 
X */
X
Xposition_tiles()
X{
X	int i, j;
X	int x_pos, y_pos;
X
X     /* give each tile a position on the board */
X
X     /* ROW 1 */
X	x_pos = X_OFF2;
X	y_pos = Y_OFF1;
X	for(i = 0; i < 12; i++) {
X		init_tile(i, x_pos, y_pos);
X		x_pos += TILE_X;
X	}
X	tiles[0].left_free = TRUE;
X	tiles[0].left_next[0] = -1;
X	tiles[11].right_free = TRUE;
X	tiles[11].right_next[0] = -1;
X
X     /* ROW 2 */
X	x_pos = X_OFF4;
X	y_pos = Y_OFF2;
X	for(i = 12; i < 20; i++) {
X		init_tile(i, x_pos, y_pos);
X		x_pos += TILE_X;
X	}
X	tiles[12].left_free = TRUE;
X	tiles[12].left_next[0] = -1;
X	tiles[19].right_free = TRUE;
X	tiles[19].right_next[0] = -1;
X
X     /* ROW 3 */
X	x_pos = X_OFF3;
X	y_pos = Y_OFF3;
X	for(i = 20; i < 30; i++) {
X		init_tile(i, x_pos, y_pos);
X		x_pos += TILE_X;
X	}
X	tiles[20].left_free = TRUE;
X	tiles[20].left_next[0] = -1;
X	tiles[29].right_free = TRUE;
X	tiles[29].right_next[0] = -1;
X
X     /* ROW 4 1/2  Left side */
X	x_pos = X_OFF1;
X	y_pos = Y_OFF45;
X	init_tile(30, x_pos, y_pos);
X	tiles[30].left_free = TRUE;
X	tiles[30].left_next[0] = -1;
X	tiles[30].right_next[1] = 43;
X
X     /* ROW 4 */
X	x_pos = X_OFF2;
X	y_pos = Y_OFF4;
X	for(i = 31; i < 43; i++) {
X		init_tile(i, x_pos, y_pos);
X		x_pos += TILE_X;
X	}
X	tiles[42].right_next[0] = 55;
X
X     /* ROW 5 */
X	x_pos = X_OFF2;
X	y_pos = Y_OFF5;
X	for(i = 43; i < 55; i++) {
X		init_tile(i, x_pos, y_pos);
X		x_pos += TILE_X;
X	}
X	tiles[43].left_next[0] = 30;
X
X     /* ROW 4 1/2  Right side */
X	x_pos = X_OFF14;
X	y_pos = Y_OFF45;
X	for(i = 55; i < 57; i++) {
X		init_tile(i, x_pos, y_pos);
X		x_pos += TILE_X;
X	}
X	tiles[55].left_next[1] = 42;
X	tiles[56].right_free = TRUE;
X	tiles[56].right_next[0] = -1;
X
X     /* ROW 6 */
X	x_pos = X_OFF3;
X	y_pos = Y_OFF6;
X	for(i = 57; i < 67; i++) {
X		init_tile(i, x_pos, y_pos);
X		x_pos += TILE_X;
X	}
X	tiles[57].left_free = TRUE;
X	tiles[57].left_next[0] = -1;
X	tiles[66].right_free = TRUE;
X	tiles[66].right_next[0] = -1;
X
X     /* ROW 7 */
X	x_pos = X_OFF4;
X	y_pos = Y_OFF7;
X	for(i = 67; i < 75; i++) {
X		init_tile(i, x_pos, y_pos);
X		x_pos += TILE_X;
X	}
X	tiles[67].left_free = TRUE;
X	tiles[67].left_next[0] = -1;
X	tiles[74].right_free = TRUE;
X	tiles[74].right_next[0] = -1;
X
X     /* ROW 8 */
X	x_pos = X_OFF2;
X	y_pos = Y_OFF8;
X	for(i = 75; i < 87; i++) {
X		init_tile(i, x_pos, y_pos);
X		x_pos += TILE_X;
X	}
X	tiles[75].left_free = TRUE;
X	tiles[75].left_next[0] = -1;
X	tiles[86].right_free = TRUE;
X	tiles[86].right_next[0] = -1;
X
X     /* LEVEL 2 */
X	x_pos = X_OFF5 + X_OFFL2;
X	y_pos = Y_OFF2 + Y_OFFL2;
X	for(i = 87; i < 123; i+=6) {
X		for(j = 0; j < 6; j++) {
X			init_tile(i+j, x_pos, y_pos);
X			x_pos += TILE_X;
X		}
X		x_pos = X_OFF5 + X_OFFL2;
X		y_pos += TILE_Y;
X		tiles[i].left_free = TRUE;
X		tiles[i].left_next[0] = -1;
X		tiles[i+5].right_free = TRUE;
X		tiles[i+5].right_next[0] = -1;
X	}
X
X     /* LEVEL 3 */
X	x_pos = X_OFF6 + X_OFFL3;
X	y_pos = Y_OFF3 + Y_OFFL3;
X	for(i = 123; i < 139; i+=4) {
X		for(j = 0; j < 4; j++) {
X			init_tile(i+j, x_pos, y_pos);
X			x_pos += TILE_X;
X		}
X		x_pos = X_OFF6 + X_OFFL3;
X		y_pos += TILE_Y;
X		tiles[i].left_free = TRUE;
X		tiles[i].left_next[0] = -1;
X		tiles[i+3].right_free = TRUE;
X		tiles[i+3].right_next[0] = -1;
X	}
X
X     /* LEVEL 4 */
X	x_pos = X_OFF7 + X_OFFL4;
X	y_pos = Y_OFF4 + Y_OFFL4;
X	for(i = 139; i < 143; i+=2) {
X		for(j = 0; j < 2; j++) {
X			init_tile(i+j, x_pos, y_pos);
X			x_pos += TILE_X;
X		}
X		x_pos = X_OFF7 + X_OFFL4;
X		y_pos += TILE_Y;
X		tiles[i].left_free = TRUE;
X		tiles[i].left_next[0] = -1;
X		tiles[i+1].right_free = TRUE;
X		tiles[i+1].right_next[0] = -1;
X	}
X	tiles[139].top_free = FALSE;
X	tiles[140].top_free = FALSE;
X	tiles[141].top_free = FALSE;
X	tiles[142].top_free = FALSE;
X
X     /* LEVEL 5 */
X	x_pos = X_OFF75 + X_OFFL5;
X	y_pos = Y_OFF45 + Y_OFFL5;
X	init_tile(143, x_pos, y_pos);
X	tiles[143].left_free = TRUE;
X	tiles[143].left_next[0] = -1;
X	tiles[143].right_free = TRUE;
X	tiles[143].right_next[0] = -1;
X	tiles[143].covered[0] = 139;
X	tiles[143].covered[1] = 140;
X	tiles[143].covered[2] = 141;
X	tiles[143].covered[3] = 142;
X
X     /* this code copied verbatim from Mark Holm's Mahjongg */
X     /* set top_free flags  and covered pointers */
X	for(i = 87, j = 13; i < 143; i++, j++) {
X		tiles[i].covered[0] = j;
X		tiles[j].top_free = FALSE;
X		switch(j) {
X			case 97:
X			case 103:
X			case 109:
X			case 129:
X				 j += 2;
X				 break;
X			case 18:
X			case 64:
X				 j += 3;
X				 break;
X			case 27:
X			case 39:
X				 j += 6;
X				 break;
X			case 51:
X				 j += 7;
X				 break;
X			case 73:
X				 j += 20;
X				 break;
X			case 115:
X				 j += 12;
X				 break;
X		}
X	}
X}
X
X/*
X * give tile i its default initial values
X */
X
Xinit_tile(i, x_pos, y_pos)
Xint i;
Xint x_pos, y_pos;
X{
X	tiles[i].x_pos = x_pos;
X	tiles[i].y_pos = y_pos;
X	tiles[i].left_free = FALSE;
X	tiles[i].right_free = FALSE;
X	tiles[i].top_free = TRUE;
X	tiles[i].left_next[0] = i - 1;
X	tiles[i].left_next[1] = -1;
X	tiles[i].right_next[0] = i + 1;
X	tiles[i].right_next[1] = -1;
X	tiles[i].covered[0] = -1;
X	tiles[i].covered[1] = -1;
X	tiles[i].covered[2] = -1;
X	tiles[i].covered[3] = -1;
X	tiles[i].removed = FALSE;
X}
X
END_OF_FILE
if test 10824 -ne `wc -c <'mahjongg.c'`; then
    echo shar: \"'mahjongg.c'\" unpacked with wrong size!
fi
# end of 'mahjongg.c'
fi
if test -f 'mahjongg.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'mahjongg.h'\"
else
echo shar: Extracting \"'mahjongg.h'\" \(3934 characters\)
sed "s/^X//" >'mahjongg.h' <<'END_OF_FILE'
X
X/*
X *	This program contains much of the code from the original
X *	 Sun version of mahjongg, written by Mark Holm, and the
X *	 port/rewrite for the UNIXPC, written by Tom Tkacik. Both
X *	 were inspired by the PC version.
X *
X *	This version of Mahjongg was modified/re-written/ported
X *	 for/to the PC-Family    by Joerg Hattenhauer
X *
X */
X
X/*
X *	Copyright 1988, Mark Holm
X *			Exceptions
X *
X *	Permission is given to copy and distribute for non-profit purposes.
X *
X */
X
X
X/* TILE size and offsets */
X#define  TILE_W  52
X#define  TILE_H  47
X#define  TILE_X  46
X#define  TILE_Y  42
X
X/* TILE offset on playing board */
X#define  X_OFF1  10
X#define  X_OFF2  (X_OFF1 + TILE_X)
X#define  X_OFF3  (X_OFF2 + TILE_X)
X#define  X_OFF4  (X_OFF3 + TILE_X)
X#define  X_OFF5  (X_OFF4 + TILE_X)
X#define  X_OFF6  (X_OFF5 + TILE_X)
X#define  X_OFF7  (X_OFF6 + TILE_X)
X#define  X_OFF75 (X_OFF7 + (TILE_X/2))
X#define  X_OFF8  (X_OFF7 + TILE_X)
X#define  X_OFF9  (X_OFF8 + TILE_X)
X#define  X_OFF10  (X_OFF9 + TILE_X)
X#define  X_OFF11  (X_OFF10 + TILE_X)
X#define  X_OFF12  (X_OFF11 + TILE_X)
X#define  X_OFF13  (X_OFF12 + TILE_X)
X#define  X_OFF14  (X_OFF13 + TILE_X)
X#define  X_OFF15  (X_OFF14 + TILE_X)
X
X#define  Y_OFF1  5
X#define  Y_OFF2  (Y_OFF1 + TILE_Y)
X#define  Y_OFF3  (Y_OFF2 + TILE_Y)
X#define  Y_OFF4  (Y_OFF3 + TILE_Y)
X#define  Y_OFF45 (Y_OFF4 + (TILE_Y/2))
X#define  Y_OFF5  (Y_OFF4 + TILE_Y)
X#define  Y_OFF6  (Y_OFF5 + TILE_Y)
X#define  Y_OFF7  (Y_OFF6 + TILE_Y)
X#define  Y_OFF8  (Y_OFF7 + TILE_Y)
X
X/* offsets due to being on a different level */
X#define  X_OFFL2  (TILE_X - TILE_W)
X#define  X_OFFL3  ((TILE_X - TILE_W) * 2)
X#define  X_OFFL4  ((TILE_X - TILE_W) * 3)
X#define  X_OFFL5  ((TILE_X - TILE_W) * 4)
X
X#define  Y_OFFL2  (TILE_Y - TILE_H)
X#define  Y_OFFL3  ((TILE_Y - TILE_H) * 2)
X#define  Y_OFFL4  ((TILE_Y - TILE_H) * 3)
X#define  Y_OFFL5  ((TILE_Y - TILE_H) * 4)
X
X/* more TILE data */
X#define  IMAGESIZE 333
X#define  NUMIMAGES 42
X#define  NUMTILES  144
X
X/* mouse buttons */
X#define MBUTL   0
X#define MBUTR   1
X#define MBUTM   2
X
X/* possible Actions */
X#define HELP    0
X#define REPLAY  1
X#define NEW     2
X#define UNDO    3
X#define QUIT    4
X#define TILE    5
X
X/* Screenposition of Buttons */
X#define QuitButXPos     650
X#define QuitButYPos     320
X#define NewButXPos      QuitButXPos
X#define NewButYPos      QuitButYPos - 25
X#define ReplayButXPos   QuitButXPos
X#define ReplayButYPos   NewButYPos - 25
X#define UndoButXPos     QuitButXPos
X#define UndoButYPos     ReplayButYPos - 25
X#define HelpButXPos     QuitButXPos
X#define HelpButYPos     UndoButYPos - 25
X#define ButtonXSize     63
X#define ButtonYSize     15
X
X/* size of buttonimage */
X#define BUTTONSIZE      140
X
X/* position to display tilecount */
X#define TileCountX  655
X#define TileCountY  90
X
X/* position to display boardnumber */
X#define BoardNrX  650
X#define BoardNrY  0
X
X#define TRUE  1
X#define FALSE 0
X
X#define MOUSEINTR   51
X
Xtypedef char boolean;
X
X/* define a tile */
Xtypedef struct {
X    char *image;
X	int value;
X	int x_pos;
X	int y_pos;
X	boolean left_free;
X	boolean right_free;
X	boolean top_free;
X	int left_next[2];
X	int right_next[2];
X	int covered[4];
X	boolean removed;
X} Tile;
X
X/* window discriptor */
X/* extern int wn; */
X
X/* tile image definitions */
Xextern char images[42][IMAGESIZE];
X
X/* blank tile definition */
Xextern char blank[IMAGESIZE];
X
X/* removed tile definition */
Xextern char removed[IMAGESIZE];
X
X/* buttonimage definitions */
Xextern char new_but[BUTTONSIZE];
Xextern char undo_but[BUTTONSIZE];
Xextern char replay_but[BUTTONSIZE];
Xextern char help_but[BUTTONSIZE];
Xextern char quit_but[BUTTONSIZE];
X
X/* the 144 playing tiles */
Xextern Tile tiles[NUMTILES];
X
X/* built-in pattern used for wrastop() */
Xextern unsigned short patwhite[];
Xextern unsigned short patblack[];
X
Xextern int	tile_count;
Xextern int	selected[2];
Xextern int	undo_tiles[144][2];
Xextern int	undo_count;
Xextern int	help_mode;
Xextern int	query_mode;
X
Xextern int graphdriver;
Xextern int graphmode;
X
END_OF_FILE
if test 3934 -ne `wc -c <'mahjongg.h'`; then
    echo shar: \"'mahjongg.h'\" unpacked with wrong size!
fi
# end of 'mahjongg.h'
fi
if test -f 'mahjongg.man' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'mahjongg.man'\"
else
echo shar: Extracting \"'mahjongg.man'\" \(3995 characters\)
sed "s/^X//" >'mahjongg.man' <<'END_OF_FILE'
X
X
X
XMAHJONGG(6)              GAMES AND DEMOS              MAHJONGG(6)
X
X
X
XNAME
X     mahjongg - Solitaire game using mahjongg tiles
X
XSYNOPSIS
X     /usr/games/mahjongg [ ### ]
X
XDESCRIPTION
X     Mah jongg is an ancient chinese game whose origins are  sup-
X     posed to date back around 3000 years. It is typically a four
X     player game with similarities to most  popular  card  games.
X     This  version  is a solitaire game using the mahjongg tiles.
X     It has been ported to the PC-Family from the UNIXPC  version
X     of  the  SUN version, which was inspired by a version origi-
X     nally seen on a PC with EGA-Adaptor.
X
XTHEORY OF PLAY
X     The object of the game is to remove all the tiles  from  the
X     board in matching pairs. Tiles match only if they are ident-
X     ical. Exceptions are the flower and season tiles. Any season
X     tile  will  match  any other season tile and any flower tile
X     will match any other flower tile. Tiles may be removed  from
X     the  board  only  if they have either a left or a right edge
X     open and they do not have a tile covering them.
X
X     The display is divided into two areas:  the play area, which
X     shows the tiles, the control area, which shows the number of
X     tiles remaining and the game control buttons.  As tiles  are
X     removed the "Tiles Remaining" count will be updated and play
X     related messages and mouse button defintions will  be  shown
X     just above the tilecount.
X
X     Tiles are selected by placing the mouse icon on a  tile  and
X     pressing  the left button. To deselect a tile simply repress
X     the left button while on the tile.  After selecting  a  pair
X     of  tiles,  simply press the left mouse button again to con-
X     firm your choice or the the right mouse button to cancel.
X
XHELP FEATURES
X     Two help features are currently  implemented.  By  selecting
X     the  "help"  button or pressing the middle mouse button when
X     no tiles are selected, you will be shown all available  tile
X     combinations.  To  see each combination press the left mouse
X     button while the mouse cursor is on  the  "help"  button  or
X     press the middle mouse button until no more moves are shown.
X     To cancel "help" press the right mouse button. If  you  have
X     selected  a  tile,  pressing  the  middle  mouse  button, or
X     selecting the "help" button, will find  the  first  matching
X     tile  (if  any)  starting at the top of the pile and working
X     down.  If a match is found,  press  the  left  mouse  button
X     while  the mouse cursor is not on a button and the pair will
X     be removed from the board.  If an alternate match is  avail-
X     able pressing the middle mouse button will show it.
X
XUNDO
X     Since some people tend to be a little faster  on  the  mouse
X     then  they  should be, the undo feature was implemented. The
X     "undo" button replaces the previous pair  that  was  removed
X     from  board.  You  can  continue to press undo until you get
X
X
X
X								1
X
X
X
X
X
X
XMAHJONGG(6)              GAMES AND DEMOS              MAHJONGG(6)
X
X
X
X     back to a new board.
X
XNEW and SAME
X     Selecting the "new" button restarts  the  game  with  a  new
X     board. Selecting the "replay" button restarts the game using
X     the same board.  Either button may be used at any time  dur-
X     ing the game.
X
XOPTIONS
X     ###  Start with board number ###. Boards through  32768  are
X          available.
X
XDIAGNOSTICS
XFILES
X     /usr/games/mahjongg           executable
X
XAUTHOR
X     Copyright 1988 Mark A. Holm
X     <tektronix!tessi!exc!markh>
X
X     Ported to the UNIXPC by Thomas Tkacik
X     <rphroy!tetnix!tet>
X
X     Ported to the PC-Family by Joerg Hattenhauer
X     <...!uunet!unido!jah>
X
XBUGS
X     Board number is not checked very close. If you put something
X     wierd in, you deserve everthing you get.
X
X     No score file. It is up to you to keep track of who did  how
X     well on what board.
X
X     Not as pretty as the SUN version.
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X								2
X
X
X
END_OF_FILE
if test 3995 -ne `wc -c <'mahjongg.man'`; then
    echo shar: \"'mahjongg.man'\" unpacked with wrong size!
fi
# end of 'mahjongg.man'
fi
if test -f 'screen.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'screen.c'\"
else
echo shar: Extracting \"'screen.c'\" \(4534 characters\)
sed "s/^X//" >'screen.c' <<'END_OF_FILE'
X/*
X *  This code was written by Joerg Hattenhauer and contains
X *	 absolutely no code from Mark Holm's Mahjongg program.
X *
X */
X
X#include <dos.h>
X#include <stdio.h>
X#include <stdlib.h>
X#include <graphics.h>
X#include "mahjongg.h"
X
X
X/*  screen routines */
X
X/*
X * initialize screen
X */
X
Xinitscreen()
X{
X    int     errflg;
X
X    errflg = registerfarbgidriver(Herc_driver_far);
X    if (errflg < 0)
X        leave("Herculesdriver not loaded !!", errflg);
X
X    errflg = registerfarbgifont(triplex_font_far);
X    if (errflg < 0)
X        leave("Triplex-Font not loaded !!", errflg);
X
X    /* initialize Herculescard */
X    graphdriver = DETECT;
X    initgraph(&graphdriver, &graphmode, "");
X    clear_window();
X}
X
X
Xclear_window()
X{
X    clearviewport();
X}
X
X
Xleave(text, errnr)
Xchar    *text;
Xint     errnr;
X{
X    hidecur();
X    restorecrtmode();
X    if (errnr)
X        fprintf (stderr, "Mah-Jongg:  error %d: %s\n\n", errnr, text);
X    else
X        fprintf (stderr, "%s\n\n", text);
X    exit (errnr);
X}
X
X
Xwcmd (text)
Xchar    *text;
X{
X    int        i, textXbeg;
X    static int winXbeg, winYbeg, winXend, winYend;
X    static char *win = NULL;
X
X    settextstyle (DEFAULT_FONT, HORIZ_DIR, 1);
X    hidecur();
X
X     /* allocate storage just once */
X    if (win == NULL) {
X        winXbeg = X_OFF13 + TILE_W / 2;
X        winYbeg = Y_OFF2 + TILE_H / 3;
X        winXend = getmaxx();
X        winYend = winYbeg + textheight (text);
X        win = (char *) malloc (imagesize ( winXbeg, winYbeg, winXend, winYend));
X        getimage ( winXbeg, winYbeg, winXend, winYend, win);
X    }
X
X    textXbeg = max (winXend - textwidth (text), winXbeg);
X    putimage (winXbeg, winYbeg, win, COPY_PUT);
X    outtextxy (textXbeg, winYbeg, text);
X
X    showcur();
X}
X
X
X/*
X * draw the buttons on the playing field
X */
X
Xdraw_buttons()
X{
X    putimage (QuitButXPos, QuitButYPos, quit_but, COPY_PUT);
X    putimage (NewButXPos, NewButYPos, new_but, COPY_PUT);
X    putimage (ReplayButXPos, ReplayButYPos, replay_but, COPY_PUT);
X    putimage (UndoButXPos, UndoButYPos, undo_but, COPY_PUT);
X    putimage (HelpButXPos, HelpButYPos, help_but, COPY_PUT);
X}
X
X/*
X * show the current boardnumber
X */
X
Xshow_board_nr (board_nr)
Xint	board_nr;
X{
X    char    board_str[16];
X
X    itoa( board_nr, board_str, 10);
X    settextstyle(DEFAULT_FONT, HORIZ_DIR, 1);
X    outtextxy( BoardNrX, BoardNrY, "Board");
X    settextstyle(TRIPLEX_FONT, HORIZ_DIR, 3);
X    outtextxy( BoardNrX, BoardNrY+10, board_str);
X}
X
X
X/*
X * show the current tilecount
X */
X
Xshow_tile_count()
X{
X    static int     text_x, text_y;
X    char           count[4];
X    static char    *scr = NULL;
X
X
X    itoa( tile_count, count, 10);
X
X     /* allocate storage just once */
X    if (scr == NULL) {
X       settextstyle (TRIPLEX_FONT, HORIZ_DIR, 3);
X       text_x = TileCountX + textwidth (count);
X       text_y = TileCountY + textheight (count);
X       scr = (char *) malloc (imagesize( TileCountX, TileCountY, text_x, text_y));
X       settextstyle (DEFAULT_FONT, HORIZ_DIR, 1);
X       outtextxy (TileCountX-15, TileCountY+30, "Tiles left");
X    }
X
X    /* remove old tilecount */
X    getimage (TileCountX, TileCountY, text_x, text_y, scr);
X    putimage (TileCountX, TileCountY, scr, XOR_PUT);
X
X    /* show new tilecount */
X    settextstyle (TRIPLEX_FONT, HORIZ_DIR, 3);
X    outtextxy (TileCountX, TileCountY, count);
X}
X
X
X/*
X * draw the tiles on the playing field
X */
X
Xdraw_tiles()
X{
X	int i = 0;
X
X    show_tile_count();
X
X    /* place tiles */
X	for(i = 0; i < NUMTILES; i++) {
X
X        if (tiles[i].removed)
X			continue;
X		
X        if ((i >= 139) || (tiles[i].top_free)) {
X
X		     /* show the tile */
X            putimage(tiles[i].x_pos,tiles[i].y_pos,tiles[i].image,COPY_PUT);
X
X        } else {
X
X		     /* draw a blank tile -- do not show hidden tiles */
X            putimage(tiles[i].x_pos,tiles[i].y_pos,blank,COPY_PUT);
X
X        }
X	}
X}
X
X/*
X * highlight a tile -- if already highlighted, turn it off
X */
X
Xpreview_tile(i)
Xint i;
X{
X    int            X, Y;
X    static char    *akt_tile = NULL;
X
X    X = tiles[i].x_pos+1;
X    Y = tiles[i].y_pos+1;
X
X     /* allocate storage just once */
X    if (akt_tile == NULL) {
X       akt_tile = (char *) malloc (imagesize( X, Y, X+TILE_X-2, Y+TILE_Y-2));
X    }
X
X    getimage( X, Y, X+TILE_X-2, Y+TILE_Y-2, akt_tile);
X    putimage( X, Y, akt_tile, NOT_PUT);
X}
X
X
X/*
X * erase a tile from screen
X */
X
Xerase_tile ( tile_nr)
Xint tile_nr;
X{
X    putimage(tiles[tile_nr].x_pos,tiles[tile_nr].y_pos,removed,COPY_PUT);
X}
X
X
X/*
X * beep at the user
X */
X
Xwindow_bell()
X{
X    sound( 880);
X    delay( 120);
X    nosound();
X}
X
END_OF_FILE
if test 4534 -ne `wc -c <'screen.c'`; then
    echo shar: \"'screen.c'\" unpacked with wrong size!
fi
# end of 'screen.c'
fi
if test ! -d 'tiles' ; then
    echo shar: Creating directory \"'tiles'\"
    mkdir 'tiles'
fi
if test -f 'tiles.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'tiles.c'\"
else
echo shar: Extracting \"'tiles.c'\" \(2469 characters\)
sed "s/^X//" >'tiles.c' <<'END_OF_FILE'
X
X/*
X *	This program contains much of the code from the original
X *	 Sun version of mahjongg, written by Mark Holm, and the
X *	 port/rewrite for the UNIXPC, written by Tom Tkacik. Both
X *	 were inspired by the PC version.
X *
X *	This version of Mahjongg was modified/re-written/ported
X *	 for/to the PC-Family    by Joerg Hattenhauer
X *
X *	The tiles in this version were rebuild from scratch
X *			by Joerg Hattenhauer.
X *
X *
X */
X
X/*
X *	Copyright 1988, Mark Holm
X *			Exceptions
X *
X *	Permission is given to copy and distribute for non-profit purposes.
X *
X */
X
X
X#include "mahjongg.h"
X
Xchar new_but[BUTTONSIZE] = {
X#include "tiles\new.but"
X};
X
Xchar undo_but[BUTTONSIZE] = {
X#include "tiles\undo.but"
X};
X
Xchar replay_but[BUTTONSIZE] = {
X#include "tiles\replay.but"
X};
X
Xchar help_but[BUTTONSIZE] = {
X#include "tiles\help.but"
X};
X
Xchar quit_but[BUTTONSIZE] = {
X#include "tiles\quit.but"
X};
X
X
X/* the 144 tiles */
XTile tiles[NUMTILES];
X
Xchar blank[IMAGESIZE] = {
X#include "tiles\blank.img"
X};
X
Xchar removed[IMAGESIZE] = {
X#include "tiles\removed.img"
X};
X
X/* the 42 rastor images */
Xchar images[42][IMAGESIZE] = {
X	  {
X#include "tiles\bam1.img"
X	},{
X#include "tiles\bam2.img"
X	},{
X#include "tiles\bam3.img"
X	},{
X#include "tiles\bam4.img"
X	},{
X#include "tiles\bam5.img"
X	},{
X#include "tiles\bam6.img"
X	},{
X#include "tiles\bam7.img"
X	},{
X#include "tiles\bam8.img"
X	},{
X#include "tiles\bam9.img"
X	},{
X#include "tiles\char1.img"
X	},{
X#include "tiles\char2.img"
X	},{
X#include "tiles\char3.img"
X	},{
X#include "tiles\char4.img"
X	},{
X#include "tiles\char5.img"
X	},{
X#include "tiles\char6.img"
X	},{
X#include "tiles\char7.img"
X	},{
X#include "tiles\char8.img"
X	},{
X#include "tiles\char9.img"
X	},{
X#include "tiles\circ1.img"
X	},{
X#include "tiles\circ2.img"
X	},{
X#include "tiles\circ3.img"
X	},{
X#include "tiles\circ4.img"
X	},{
X#include "tiles\circ5.img"
X	},{
X#include "tiles\circ6.img"
X	},{
X#include "tiles\circ7.img"
X	},{
X#include "tiles\circ8.img"
X	},{
X#include "tiles\circ9.img"
X	},{
X#include "tiles\d_white.img"
X	},{
X#include "tiles\d_red.img"
X	},{
X#include "tiles\d_green.img"
X	},{
X#include "tiles\c_north.img"
X	},{
X#include "tiles\c_east.img"
X	},{
X#include "tiles\c_south.img"
X	},{
X#include "tiles\c_west.img"
X	},{
X#include "tiles\f_plum.img"
X	},{
X#include "tiles\f_orch.img"
X	},{
X#include "tiles\f_bam.img"
X	},{
X#include "tiles\f_mum.img"
X	},{
X#include "tiles\s_autumn.img"
X	},{
X#include "tiles\s_summer.img"
X	},{
X#include "tiles\s_spring.img"
X	},{
X#include "tiles\s_winter.img"
X	}
X};
END_OF_FILE
if test 2469 -ne `wc -c <'tiles.c'`; then
    echo shar: \"'tiles.c'\" unpacked with wrong size!
fi
# end of 'tiles.c'
fi
if test -f 'tiles/s_autumn.img' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'tiles/s_autumn.img'\"
else
echo shar: Extracting \"'tiles/s_autumn.img'\" \(2410 characters\)
sed "s/^X//" >'tiles/s_autumn.img' <<'END_OF_FILE'
X/* Width=52, Height=47, Depth=1
X*  Copyright 1989, Joerg Hattenhauer
X*          Exceptions
X*
X*  Permission is given to copy and distribute for non-profit purposes.
X*
X*/
X    0x33, 0x00,
X    0x2e, 0x00,
X
X    0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 
X    0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 
X    0x80, 0x00, 0x00, 0x00, 0x00, 0x02, 0xc0, 
X    0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0x60, 
X    0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xd0, 
X    0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xb0, 
X    0x80, 0x00, 0x00, 0x00, 0x00, 0x02, 0xe0, 
X    0x83, 0x80, 0x78, 0x00, 0x00, 0x03, 0x70, 
X    0x80, 0xf0, 0xc8, 0x00, 0x00, 0x03, 0xd0, 
X    0x80, 0x0d, 0x0c, 0xf8, 0x00, 0x03, 0xb0, 
X    0x80, 0x07, 0x83, 0x30, 0x00, 0x02, 0xe0, 
X    0x80, 0x04, 0x70, 0x0f, 0x80, 0x03, 0x70, 
X    0x80, 0x04, 0x08, 0x00, 0x60, 0x03, 0xd0, 
X    0x80, 0x08, 0x04, 0x00, 0xc0, 0x03, 0xb0, 
X    0x80, 0x08, 0x01, 0x01, 0x00, 0x02, 0xe0, 
X    0x80, 0x10, 0x00, 0x43, 0x00, 0x03, 0x70, 
X    0x80, 0x30, 0x20, 0x10, 0xf0, 0x03, 0xd0, 
X    0x80, 0x20, 0x60, 0x08, 0x0c, 0x03, 0xb0, 
X    0x80, 0x30, 0x90, 0x44, 0x30, 0x02, 0xe0, 
X    0x80, 0x3c, 0x90, 0x72, 0xc0, 0x03, 0x70, 
X    0x80, 0x25, 0x18, 0x51, 0x40, 0x03, 0xd0, 
X    0x80, 0x03, 0x08, 0xa0, 0xb0, 0x03, 0xb0, 
X    0x80, 0x01, 0x0f, 0x60, 0x4c, 0x02, 0xe0, 
X    0x80, 0x01, 0x08, 0x7e, 0x28, 0x03, 0x70, 
X    0x80, 0x00, 0x00, 0x03, 0xf8, 0x03, 0xd0, 
X    0x80, 0x00, 0x00, 0x00, 0x38, 0x03, 0xb0, 
X    0x80, 0x00, 0x00, 0x00, 0x1c, 0x02, 0xe0, 
X    0x80, 0x00, 0x00, 0x00, 0x04, 0x03, 0x70, 
X    0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xd0, 
X    0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xb0, 
X    0x80, 0x00, 0x00, 0x00, 0x00, 0x02, 0xe0, 
X    0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0x70, 
X    0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xd0, 
X    0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xb0, 
X    0x83, 0x10, 0xbe, 0x85, 0x0a, 0x12, 0xe0, 
X    0x84, 0x90, 0x88, 0x85, 0x9b, 0x13, 0x70, 
X    0x88, 0x50, 0x88, 0x85, 0x6a, 0x93, 0xd0, 
X    0x8f, 0xd0, 0x88, 0x85, 0x6a, 0x53, 0xb0, 
X    0x88, 0x50, 0x88, 0x85, 0x0a, 0x32, 0xe0, 
X    0x88, 0x50, 0x88, 0x85, 0x0a, 0x13, 0x70, 
X    0x88, 0x4f, 0x08, 0x79, 0x0a, 0x13, 0xd0, 
X    0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xb0, 
X    0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xe0, 
X    0x48, 0x88, 0x88, 0x88, 0x88, 0x89, 0x90, 
X    0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0xf0, 
X    0x14, 0x44, 0x44, 0x44, 0x44, 0x44, 0x70, 
X    0x09, 0x11, 0x11, 0x11, 0x11, 0x11, 0x10
X
END_OF_FILE
if test 2410 -ne `wc -c <'tiles/s_autumn.img'`; then
    echo shar: \"'tiles/s_autumn.img'\" unpacked with wrong size!
fi
# end of 'tiles/s_autumn.img'
fi
if test -f 'tiles/s_spring.img' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'tiles/s_spring.img'\"
else
echo shar: Extracting \"'tiles/s_spring.img'\" \(2410 characters\)
sed "s/^X//" >'tiles/s_spring.img' <<'END_OF_FILE'
X/* Width=52, Height=47, Depth=1
X*  Copyright 1989, Joerg Hattenhauer
X*          Exceptions
X*
X*  Permission is given to copy and distribute for non-profit purposes.
X*
X*/
X    0x33, 0x00,
X    0x2e, 0x00,
X
X    0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 
X    0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 
X    0x80, 0x00, 0x00, 0x00, 0x00, 0x02, 0xc0, 
X    0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0x60, 
X    0x80, 0x00, 0x01, 0xc8, 0x00, 0x03, 0xd0, 
X    0x80, 0x00, 0x03, 0x50, 0x03, 0xa3, 0xb0, 
X    0x80, 0x00, 0x02, 0x60, 0x06, 0xc2, 0xe0, 
X    0x80, 0x00, 0x02, 0xc0, 0x04, 0x83, 0x70, 
X    0x80, 0x00, 0x03, 0x80, 0x05, 0x03, 0xd0, 
X    0x80, 0x00, 0x03, 0x00, 0x06, 0x03, 0xb0, 
X    0x80, 0x00, 0x02, 0x00, 0x08, 0x02, 0xe0, 
X    0x80, 0x00, 0xe4, 0x00, 0x10, 0x03, 0x70, 
X    0x80, 0x01, 0xa8, 0x03, 0xe3, 0x93, 0xd0, 
X    0x80, 0x01, 0x30, 0x06, 0xc6, 0xa3, 0xb0, 
X    0x80, 0x01, 0x60, 0x04, 0x84, 0xc2, 0xe0, 
X    0x80, 0x01, 0xc0, 0x05, 0x05, 0x83, 0x70, 
X    0x80, 0x01, 0x80, 0x06, 0x07, 0x03, 0xd0, 
X    0x80, 0x01, 0x00, 0x04, 0x06, 0x03, 0xb0, 
X    0x80, 0x01, 0x00, 0x08, 0x04, 0x02, 0xe0, 
X    0x80, 0x02, 0x00, 0x10, 0x08, 0x03, 0x70, 
X    0x80, 0x04, 0x00, 0x20, 0x10, 0x03, 0xd0, 
X    0x80, 0xec, 0x1c, 0x47, 0x20, 0x03, 0xb0, 
X    0x81, 0xb8, 0x34, 0x8d, 0x40, 0x02, 0xe0, 
X    0x81, 0x30, 0x27, 0x09, 0x80, 0x03, 0x70, 
X    0x81, 0x60, 0x2e, 0x0b, 0x00, 0x03, 0xd0, 
X    0x81, 0xe0, 0x38, 0x0e, 0x00, 0x03, 0xb0, 
X    0x80, 0xc0, 0x30, 0x0c, 0x00, 0x02, 0xe0, 
X    0x80, 0x80, 0x20, 0x08, 0x00, 0x03, 0x70, 
X    0x81, 0x00, 0x40, 0x10, 0x00, 0x03, 0xd0, 
X    0x82, 0x00, 0x80, 0x20, 0x00, 0x03, 0xb0, 
X    0x82, 0x01, 0x00, 0x40, 0x00, 0x02, 0xe0, 
X    0x80, 0x02, 0x00, 0x80, 0x00, 0x03, 0x70, 
X    0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xd0, 
X    0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xb0, 
X    0x83, 0xcf, 0x9f, 0x28, 0x4f, 0x02, 0xe0, 
X    0x84, 0x28, 0x50, 0xac, 0x50, 0x83, 0x70, 
X    0x84, 0x08, 0x50, 0xaa, 0x50, 0x03, 0xd0, 
X    0x83, 0xcf, 0x9f, 0x29, 0x53, 0x83, 0xb0, 
X    0x80, 0x28, 0x12, 0x28, 0xd0, 0x82, 0xe0, 
X    0x84, 0x28, 0x11, 0x28, 0x50, 0x83, 0x70, 
X    0x83, 0xc8, 0x10, 0xa8, 0x4f, 0x03, 0xd0, 
X    0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xb0, 
X    0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xe0, 
X    0x48, 0x88, 0x88, 0x88, 0x88, 0x89, 0x90, 
X    0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0xf0, 
X    0x14, 0x44, 0x44, 0x44, 0x44, 0x44, 0x70, 
X    0x09, 0x11, 0x11, 0x11, 0x11, 0x11, 0x10
X
END_OF_FILE
if test 2410 -ne `wc -c <'tiles/s_spring.img'`; then
    echo shar: \"'tiles/s_spring.img'\" unpacked with wrong size!
fi
# end of 'tiles/s_spring.img'
fi
if test -f 'tiles/s_winter.img' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'tiles/s_winter.img'\"
else
echo shar: Extracting \"'tiles/s_winter.img'\" \(2410 characters\)
sed "s/^X//" >'tiles/s_winter.img' <<'END_OF_FILE'
X/* Width=52, Height=47, Depth=1
X*  Copyright 1989, Joerg Hattenhauer
X*          Exceptions
X*
X*  Permission is given to copy and distribute for non-profit purposes.
X*
X*/
X    0x33, 0x00,
X    0x2e, 0x00,
X
X    0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 
X    0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 
X    0x80, 0x00, 0x00, 0x00, 0x00, 0x02, 0xc0, 
X    0x80, 0x00, 0x01, 0xc0, 0x00, 0x03, 0x60, 
X    0x80, 0x00, 0x01, 0xc0, 0x00, 0x03, 0xd0, 
X    0x80, 0x00, 0x00, 0x80, 0x00, 0x03, 0xb0, 
X    0x80, 0x38, 0x00, 0x80, 0x1c, 0x02, 0xe0, 
X    0x80, 0x38, 0x30, 0x8c, 0x1c, 0x03, 0x70, 
X    0x80, 0x0c, 0x30, 0x8c, 0x30, 0x03, 0xd0, 
X    0x80, 0x02, 0x08, 0x90, 0x40, 0x03, 0xb0, 
X    0x80, 0x01, 0x07, 0xe0, 0x80, 0x02, 0xe0, 
X    0x80, 0x00, 0x98, 0x19, 0x00, 0x03, 0x70, 
X    0x80, 0x38, 0x63, 0xc6, 0x1c, 0x03, 0xd0, 
X    0x80, 0x3c, 0x6d, 0xb6, 0x3c, 0x03, 0xb0, 
X    0x80, 0x03, 0x94, 0x29, 0xc0, 0x02, 0xe0, 
X    0x80, 0x00, 0xaa, 0x55, 0x00, 0x03, 0x70, 
X    0x83, 0x01, 0x4b, 0xd2, 0x80, 0x03, 0xd0, 
X    0x87, 0xff, 0x57, 0xea, 0x80, 0xc3, 0xb0, 
X    0x83, 0x01, 0x57, 0xea, 0xff, 0xe2, 0xe0, 
X    0x80, 0x01, 0x4b, 0xd2, 0x80, 0xc3, 0x70, 
X    0x80, 0x00, 0xaa, 0x55, 0x00, 0x03, 0xd0, 
X    0x80, 0x03, 0x94, 0x29, 0xc0, 0x03, 0xb0, 
X    0x80, 0x3c, 0x6d, 0xb6, 0x3c, 0x02, 0xe0, 
X    0x80, 0x38, 0x63, 0xc6, 0x1c, 0x03, 0x70, 
X    0x80, 0x00, 0x98, 0x19, 0x00, 0x03, 0xd0, 
X    0x80, 0x01, 0x07, 0xe0, 0x80, 0x03, 0xb0, 
X    0x80, 0x02, 0x09, 0x10, 0x40, 0x02, 0xe0, 
X    0x80, 0x0c, 0x31, 0x0c, 0x30, 0x03, 0x70, 
X    0x80, 0x38, 0x31, 0x0c, 0x1c, 0x03, 0xd0, 
X    0x80, 0x38, 0x01, 0x00, 0x1c, 0x03, 0xb0, 
X    0x80, 0x00, 0x01, 0x00, 0x00, 0x02, 0xe0, 
X    0x80, 0x00, 0x03, 0x80, 0x00, 0x03, 0x70, 
X    0x80, 0x00, 0x03, 0x80, 0x00, 0x03, 0xd0, 
X    0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xb0, 
X    0x82, 0x15, 0x0b, 0xef, 0xdf, 0x02, 0xe0, 
X    0x82, 0x15, 0x88, 0x88, 0x10, 0x83, 0x70, 
X    0x82, 0x15, 0x48, 0x88, 0x10, 0x83, 0xd0, 
X    0x82, 0xd5, 0x28, 0x8f, 0x1f, 0x03, 0xb0, 
X    0x82, 0xd5, 0x18, 0x88, 0x12, 0x02, 0xe0, 
X    0x83, 0x35, 0x08, 0x88, 0x11, 0x03, 0x70, 
X    0x82, 0x15, 0x08, 0x8f, 0xd0, 0x83, 0xd0, 
X    0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xb0, 
X    0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xe0, 
X    0x48, 0x88, 0x88, 0x88, 0x88, 0x89, 0x90, 
X    0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0xf0, 
X    0x14, 0x44, 0x44, 0x44, 0x44, 0x44, 0x70, 
X    0x09, 0x11, 0x11, 0x11, 0x11, 0x11, 0x10
X
END_OF_FILE
if test 2410 -ne `wc -c <'tiles/s_winter.img'`; then
    echo shar: \"'tiles/s_winter.img'\" unpacked with wrong size!
fi
# end of 'tiles/s_winter.img'
fi
echo shar: End of archive 1 \(of 4\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 2 3 4 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 4 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