home *** CD-ROM | disk | FTP | other *** search
- Path: uunet!zephyr.ens.tek.com!master!saab!billr
- From: billr@saab.CNA.TEK.COM (Bill Randle)
- Newsgroups: comp.sources.games
- Subject: v13i072: ishido - Unix/X11 solitare game, Part01/02 (REPOST)
- Message-ID: <2655@master.CNA.TEK.COM>
- Date: 24 Mar 92 20:36:29 GMT
- Sender: news@master.CNA.TEK.COM
- Lines: 723
- Approved: billr@saab.CNA.TEK.COM
-
- Submitted-by: jjs40@cd.amdahl.COM (John Sullivan)
- Posting-number: Volume 13, Issue 70
- Archive-name: ishido/Part01
- Environment: Unix, X11
-
- [This repost appears not to have gone out so it is reposted again.]
-
- [The first posting of Part01 unpacked with wrong counts due to line
- wrapping on the original files. This version is fixed. -br]
-
- Here is a Unix/X11 port of an entertaining solitare game.
-
- #! /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 2)."
- # Contents: README Makefile bitmap gl.c gl.h
- # Wrapped by billr@saab on Mon Mar 23 13:27:40 1992
- 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'\" \(1961 characters\)
- sed "s/^X//" >'README' <<'END_OF_FILE'
- XIshido is a (questionably) ancient solitare game of matching stone tiles.
- XThere is a on-line rule screen in the game. It is known to compile and
- Xwork on Suns running SunOS 4.1 and 386/486 systems running ISC SysV.
- X
- XThis archive contains the following files:
- X bitmaps - directory of X11 bitmaps used for the tiles.
- X gl.c - An X11-based graphics library for an extra level of
- X simplicity/portability/flexibility. Not comprehensive.
- X gl.h - Include file for gl.c.
- X ishido.c - The actual source code of the game.
- X
- XTo install ishido:
- X 1. Edit the Makefile. Set LIBS for the system you are on, and
- X set the high score file and game directory at the top of
- X the file.
- X 2. Type "make install".
- X
- XTo run ishido:
- X Type 'ishido -h' for a list of options.
- X
- XI wrote this game because it's fairly simple and interesting. It also
- Xgave me an opportunity to do some hacking around with X11 while avoiding
- Xthe time-consuming trap of dealing with Xt. Implementation took most of
- Xa weekend, so there is no great depth to the code. However, everything
- Xseems to work well and correctly, so I am not inclined to do much more
- Xwork on it. Finally, it is always great fun to unlease a new game upon one's
- Xco-workers just to bring productivity to a crashing halt.
- X
- XA note on strategy: The best way to get high scores is to work on setting up
- Xfour-way matches and ignore all else. The first two to concentrate on are
- Xthe ones you can build around the middle pieces. Use the corner pieces
- Xfor the next four four-way matches. My office mate can regularly get 4-6
- Xfour-way matches, and has gotten as many as eight.
- X
- XFinally, a disclaimer: This code was developed entirely on my system at
- Xhome, and I didn't even think about working this program while at work.
- XAmdahl has no responsibility for the existence of this program and
- Xshares none of my political views.
- X
- X- John Sullivan, Amdahl Corporation
- X jjs40@cd.amdahl.com
- END_OF_FILE
- if test 1961 -ne `wc -c <'README'`; then
- echo shar: \"'README'\" unpacked with wrong size!
- fi
- # end of 'README'
- fi
- if test -f 'Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Makefile'\"
- else
- echo shar: Extracting \"'Makefile'\" \(904 characters\)
- sed "s/^X//" >'Makefile' <<'END_OF_FILE'
- X################################################################################
- X# Makefile for Ishido
- X#
- X################################################################################
- X
- XHIGH_SCORE_FILE=/home/cd1/evu2/jjs40/tmp/ishido_scores
- XGAME_DIR=/home/cd1/evu2/jjs40/bin
- X
- X################################################################################
- X
- X# Libs for SunOS 4.1
- XLIBS= -lX11
- X
- X# Libs for ISC Unix Sys V
- X# LIBS= -lX11 -linet -lpt
- X
- XCFLAGS=-DHIGH_SCORE_FILE='"$(HIGH_SCORE_FILE)"'
- X
- X################################################################################
- X
- XOBJS= gl.o ishido.o
- X
- X################################################################################
- X
- Xall: ishido
- X
- Xishido: $(OBJS)
- X cc -o ishido $(OBJS) $(LIBS)
- X
- Xinstall: all
- X cp ishido $(GAME_DIR)
- X
- Xclean:
- X -rm *.o
- X -rm Part*
- X -rm ishido
- X
- Xshar: clean
- X find . -print | makekit
- END_OF_FILE
- if test 904 -ne `wc -c <'Makefile'`; then
- echo shar: \"'Makefile'\" unpacked with wrong size!
- fi
- # end of 'Makefile'
- fi
- if test ! -d 'bitmap' ; then
- echo shar: Creating directory \"'bitmap'\"
- mkdir 'bitmap'
- fi
- if test -f 'gl.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'gl.c'\"
- else
- echo shar: Extracting \"'gl.c'\" \(9528 characters\)
- sed "s/^X//" >'gl.c' <<'END_OF_FILE'
- X/*
- X * gl.c - Simple graphics library, based on X11.
- X *
- X * Author: John Sullivan, Amdahl Corporation (jjs40@cd.amdahl.com)
- X *
- X */
- X
- X/*****************************************************************************/
- X
- X#include "gl.h"
- X
- X#include <X11/Xlib.h>
- X#include <X11/Xutil.h>
- X#include <X11/Xos.h>
- X
- X#include <stdlib.h>
- X#include <stdio.h>
- X
- X/*****************************************************************************/
- X
- XDisplay *gl_display;
- Xint gl_screen;
- XWindow gl_window;
- XGC gl_gc;
- XGL_REDRAW_FUNC gl_redraw_fn;
- XGL_EVENT_FUNC gl_event_fn;
- Xint gl_main;
- Xint gl_screen_width;
- Xint gl_screen_height;
- Xint gl_fg;
- Xint gl_bg;
- X
- X/*****************************************************************************/
- X
- Xvoid
- Xgl_bomb(s)
- X char *s;
- X{
- X printf("gl_bomb(): %s\n");
- X exit(1);
- X};
- X
- X/*****************************************************************************/
- X
- XGL_PIXEL
- Xgl_alloc_color(name)
- X char *name;
- X{
- X XColor c1, c2;
- X int res;
- X
- X res = XAllocNamedColor(gl_display,
- X DefaultColormap(gl_display, gl_screen),
- X name, &c1, &c2);
- X if (!res) {
- X gl_bomb("Unable to allocate color.");
- X };
- X return (c1.pixel);
- X};
- X
- X/*****************************************************************************/
- X
- Xvoid
- Xgl_redraw_func(func)
- X GL_REDRAW_FUNC func;
- X{
- X gl_redraw_fn = func;
- X};
- X
- X/*****************************************************************************/
- X
- Xvoid
- Xgl_event_func(func)
- X GL_EVENT_FUNC func;
- X{
- X gl_event_fn = func;
- X};
- X
- X/*****************************************************************************/
- X
- Xchar gl_event_str_buf[GL_BUFSIZE];
- X
- Xchar *
- Xgl_event_str(gl_ev)
- X GL_EVENT *gl_ev;
- X{
- X switch (gl_ev->type) {
- X case GL_EVENT_KEY:
- X sprintf(gl_event_str_buf,
- X "gl_event: key '%c' at (%d,%d)",
- X gl_ev->key, gl_ev->x, gl_ev->y);
- X break;
- X case GL_EVENT_BUTTON:
- X sprintf(gl_event_str_buf,
- X "gl_event: button %d at (%d,%d)",
- X gl_ev->button, gl_ev->x, gl_ev->y);
- X };
- X return (gl_event_str_buf);
- X};
- X
- X/*****************************************************************************/
- X
- Xvoid
- Xgl_main_loop()
- X{
- X XEvent xev;
- X XButtonEvent *xbev;
- X XKeyEvent *xkev;
- X GL_EVENT gl_ev;
- X char buf[GL_BUFSIZE];
- X
- X gl_main = 1;
- X while (gl_main) {
- X XNextEvent(gl_display, &xev);
- X switch (xev.type) {
- X case Expose:
- X if (gl_redraw_fn != NULL) {
- X (*gl_redraw_fn) ();
- X };
- X break;
- X case KeyPress:
- X gl_ev.type = GL_EVENT_KEY;
- X xkev = (XKeyEvent *) & xev;
- X XLookupString(xkev, buf, GL_BUFSIZE, NULL, NULL);
- X gl_ev.key = buf[0];
- X gl_ev.x = xkev->x;
- X gl_ev.y = xkev->y;
- X if (gl_event_fn != NULL) {
- X (*gl_event_fn) (&gl_ev);
- X };
- X break;
- X case ButtonPress:
- X gl_ev.type = GL_EVENT_BUTTON;
- X xbev = (XButtonEvent *) & xev;
- X gl_ev.button = xbev->button;
- X gl_ev.x = xbev->x;
- X gl_ev.y = xbev->y;
- X if (gl_event_fn != NULL) {
- X (*gl_event_fn) (&gl_ev);
- X };
- X break;
- X };
- X };
- X};
- X
- X/*****************************************************************************/
- X
- Xvoid
- Xgl_exit_main()
- X{
- X gl_main = 0;
- X};
- X
- X/*****************************************************************************/
- X
- Xvoid
- Xgl_set_fg(c)
- X GL_PIXEL c;
- X{
- X XGCValues gcv;
- X
- X gl_fg = c;
- X gcv.foreground = gl_fg;
- X XChangeGC(gl_display, gl_gc, GCForeground, &gcv);
- X};
- X
- X/*****************************************************************************/
- X
- Xvoid
- Xgl_set_bg(c)
- X GL_PIXEL c;
- X{
- X XGCValues gcv;
- X
- X gl_bg = c;
- X gcv.background = gl_bg;
- X XChangeGC(gl_display, gl_gc, GCBackground, &gcv);
- X};
- X
- X/*****************************************************************************/
- X
- Xvoid
- Xgl_set_fg_bg(c1, c2)
- X GL_PIXEL c1, c2;
- X{
- X gl_set_fg(c1);
- X gl_set_bg(c2);
- X};
- X
- X/*****************************************************************************/
- X
- Xvoid
- Xgl_draw_point(x, y)
- X int x, y;
- X{
- X XDrawPoint(gl_display, gl_window, gl_gc, x, y);
- X};
- X
- X/*****************************************************************************/
- X
- Xvoid
- Xgl_draw_line(x1, y1, x2, y2)
- X int x1, y1;
- X int x2, y2;
- X{
- X XDrawLine(gl_display, gl_window, gl_gc, x1, y1, x2, y2);
- X};
- X
- X/*****************************************************************************/
- X
- Xvoid
- Xgl_draw_rect(x1, y1, w, h)
- X int x1, y1;
- X int w, h;
- X{
- X XDrawRectangle(gl_display, gl_window, gl_gc, x1, y1, w - 1, h - 1);
- X};
- X
- X/*****************************************************************************/
- X
- Xvoid
- Xgl_fill_rect(x1, y1, w, h)
- X int x1, y1;
- X int w, h;
- X{
- X XFillRectangle(gl_display, gl_window, gl_gc, x1, y1, w, h);
- X};
- X
- X/*****************************************************************************/
- X
- Xvoid
- Xgl_draw_text(x, y, s)
- X int x, y;
- X char *s;
- X{
- X int len;
- X
- X len = strlen(s);
- X y = y + GL_FONT_DESCENT;
- X XDrawImageString(gl_display, gl_window, gl_gc, x, y, s, len);
- X};
- X
- X/*****************************************************************************/
- X
- Xvoid
- Xgl_ring_bell()
- X{
- X XBell(gl_display, 75);
- X};
- X
- X/*****************************************************************************/
- X
- XGL_BITMAP
- Xgl_load_bitmap(data, w, h)
- X char *data;
- X int w, h;
- X{
- X return (XCreateBitmapFromData(gl_display, gl_window, data, w, h));
- X};
- X
- X/*****************************************************************************/
- X
- Xvoid
- Xgl_draw_bitmap(bitmap, x, y, w, h)
- X GL_BITMAP bitmap;
- X int x, y;
- X int w, h;
- X{
- X XCopyPlane(gl_display, bitmap, gl_window, gl_gc, 0, 0, w, h, x, y,
- X1);
- X};
- X
- X/*****************************************************************************/
- X
- Xvoid
- Xgl_init(argc, argv, w, h)
- X int argc;
- X char **argv;
- X int w, h;
- X{
- X XSizeHints hints;
- X XGCValues gcv;
- X unsigned long gcvm;
- X
- X gl_display = XOpenDisplay(NULL);
- X if (!gl_display) {
- X gl_bomb("Unable to connect to display.");
- X };
- X
- X gl_redraw_fn = NULL;
- X gl_event_fn = NULL;
- X
- X gl_screen_width = w;
- X gl_screen_height = h;
- X hints.width = gl_screen_width;
- X hints.height = gl_screen_height;
- X hints.flags = PSize;
- X
- X gl_fg = gl_alloc_color(GL_FOREGROUND);
- X gl_bg = gl_alloc_color(GL_BACKGROUND);
- X gcv.foreground = gl_fg;
- X gcv.background = gl_bg;
- X gcv.font = XLoadFont(gl_display, GL_FONT);
- X gcvm = GCForeground | GCBackground | GCFont;
- X
- X gl_screen = DefaultScreen(gl_display);
- X gl_window = XCreateSimpleWindow(gl_display,
- X RootWindow(gl_display, gl_screen), 0, 0, hints.width,
- X hints.height, 2, gcv.foreground, gcv.background);
- X
- X XSetStandardProperties(gl_display, gl_window, "GL", "GL",
- X None, argv, argc, &hints);
- X XSelectInput(gl_display, gl_window,
- X ExposureMask | KeyPressMask | ButtonPressMask);
- X
- X gl_gc = XCreateGC(gl_display, gl_window, gcvm, &gcv);
- X};
- X
- X/*****************************************************************************/
- X
- Xvoid
- Xgl_start()
- X{
- X XMapWindow(gl_display, gl_window);
- X XSync(gl_display);
- X};
- X
- X/*****************************************************************************/
- X
- Xvoid
- Xgl_exit()
- X{
- X XCloseDisplay(gl_display);
- X exit(0);
- X};
- X
- X/*****************************************************************************/
- X
- Xvoid
- Xgu_draw_border(x, y, w, h, z)
- X int x, y;
- X int w, h;
- X int z;
- X{
- X int i;
- X
- X for (i = 1; i <= z; i++) {
- X gl_draw_rect(x - i, y - i, w + i * 2, h + i * 2);
- X };
- X};
- X
- X/*****************************************************************************/
- X
- Xvoid
- Xgu_draw_centered_text(x, y, s)
- X int x, y;
- X char *s;
- X{
- X int sx, sy;
- X
- X sx = x - (strlen(s) * GL_FONT_WIDTH) / 2;
- X sy = y - GL_FONT_HEIGHT / 2;
- X gl_draw_text(sx, sy, s);
- X};
- X
- X/*****************************************************************************/
- X
- XGL_BOOL
- Xgu_event_in_rect(event, x, y, w, h)
- X GL_EVENT *event;
- X int x, y;
- X int w, h;
- X{
- X x = event->x - x;
- X y = event->y - y;
- X return ((x >= 0) && (x < w) && (y >= 0) && (y < h));
- X};
- X
- X/*****************************************************************************/
- X
- Xvoid
- Xgb_draw_button(btn)
- X GB_BUTTON *btn;
- X{
- X gl_set_fg(btn->border);
- X gu_draw_border(btn->x, btn->y, btn->w, btn->h, 2);
- X gl_set_fg(btn->background);
- X gl_fill_rect(btn->x, btn->y, btn->w, btn->h);
- X gl_set_fg_bg(btn->text, btn->background);
- X gu_draw_centered_text(btn->x + btn->w / 2, btn->y + btn->h / 2,
- Xbtn->label);
- X};
- X
- X/*****************************************************************************/
- X
- Xvoid
- Xgb_draw_buttons(n, btn)
- X int n;
- X GB_BUTTON *btn;
- X{
- X int i;
- X
- X for (i = 0; i < n; i++) {
- X gb_draw_button(&(btn[i]));
- X };
- X};
- X
- X/*****************************************************************************/
- X
- XGL_BOOL
- Xgb_event_in_button(event, btn)
- X GL_EVENT *event;
- X GB_BUTTON *btn;
- X{
- X return (gu_event_in_rect(event, btn->x, btn->y, btn->w, btn->h));
- X};
- X
- X/*****************************************************************************/
- X
- Xvoid
- Xgb_button_press(event, btn)
- X GL_EVENT *event;
- X GB_BUTTON *btn;
- X{
- X if (btn->event_fn != NULL) {
- X (*(btn->event_fn)) (event);
- X };
- X};
- X
- X/*****************************************************************************/
- X
- XGL_BOOL
- Xgb_button_event(event, n, btn)
- X GL_EVENT *event;
- X int n;
- X GB_BUTTON *btn;
- X{
- X int i;
- X
- X for (i = 0; i < n; i++) {
- X if (gb_event_in_button(event, &(btn[i]))) {
- X gb_button_press(event, &(btn[i]));
- X return (GL_TRUE);
- X };
- X };
- X return (GL_FALSE);
- X};
- X
- X/*****************************************************************************/
- END_OF_FILE
- if test 9528 -ne `wc -c <'gl.c'`; then
- echo shar: \"'gl.c'\" unpacked with wrong size!
- fi
- # end of 'gl.c'
- fi
- if test -f 'gl.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'gl.h'\"
- else
- echo shar: Extracting \"'gl.h'\" \(3085 characters\)
- sed "s/^X//" >'gl.h' <<'END_OF_FILE'
- X/*
- X * gl.h - Header file for gl.c graphics functions.
- X *
- X * Note: This file can be included without including any X11 header files.
- X *
- X * Author: John Sullivan, Amdahl Corporation (jjs40@cd.amdahl.com)
- X *
- X */
- X
- X/*****************************************************************************/
- X/* Some defines.
- X*/
- X/*****************************************************************************/
- X
- X#define GL_SCREEN_DEPTH 8
- X#define GL_FOREGROUND "white"
- X#define GL_BACKGROUND "black"
- X#define GL_FONT "8x13"
- X#define GL_FONT_WIDTH 8
- X#define GL_FONT_HEIGHT 16
- X#define GL_FONT_DESCENT 13
- X#define GL_BUFSIZE 128
- X
- X/*****************************************************************************/
- X/* Some GL types
- X*/
- X/*****************************************************************************/
- X
- X#define GL_FALSE 0
- X#define GL_TRUE 1
- Xtypedef int GL_BOOL;
- X
- X#define GL_EVENT_KEY 0
- X#define GL_EVENT_BUTTON 1
- Xtypedef unsigned long GL_EVENT_TYPE;
- X
- Xtypedef struct GL_EVENT_S {
- X GL_EVENT_TYPE type;
- X int x, y;
- X int button;
- X char key;
- X} GL_EVENT;
- X
- Xtypedef unsigned long GL_PIXEL;
- Xtypedef unsigned long GL_BITMAP;
- X
- Xtypedef void (*GL_REDRAW_FUNC) ();
- Xtypedef void (*GL_EVENT_FUNC) ();
- X
- X/*****************************************************************************/
- X/* Function externs.
- X*/
- X/*****************************************************************************/
- X
- Xextern void gl_bomb();
- Xextern GL_PIXEL gl_alloc_color();
- Xextern void gl_redraw_func();
- Xextern void gl_event_func();
- Xextern char *gl_event_str();
- Xextern void gl_main_loop();
- Xextern void gl_exit_main();
- Xextern void gl_set_fg();
- Xextern void gl_set_bg();
- Xextern void gl_set_fg_bg();
- Xextern void gl_draw_point();
- Xextern void gl_draw_line();
- Xextern void gl_draw_rect();
- Xextern void gl_fill_rect();
- Xextern void gl_draw_text();
- Xextern void gl_ring_bell();
- Xextern GL_BITMAP gl_load_bitmap();
- Xextern void gl_draw_bitmap();
- Xextern void gl_init();
- Xextern void gl_start();
- Xextern void gl_exit();
- X
- X/**********************************************************************
- X*******/
- X
- Xextern void gu_draw_border();
- Xextern void gu_draw_centered_text();
- Xextern GL_BOOL gu_event_in_rect();
- X
- X/**********************************************************************
- X*******/
- X
- X#define GB_BUTTON_LABEL_LEN 16
- X
- Xtypedef struct GB_BUTTON_S {
- X int x, y;
- X int w, h;
- X GL_PIXEL border;
- X GL_PIXEL background;
- X GL_PIXEL flash;
- X GL_PIXEL text;
- X char label[GB_BUTTON_LABEL_LEN];
- X GL_EVENT_FUNC event_fn;
- X} GB_BUTTON;
- X
- X/**********************************************************************
- X*******/
- X
- Xextern void gb_draw_button();
- Xextern void gb_draw_buttons();
- Xextern GL_BOOL gb_event_in_button();
- Xextern void gb_button_press();
- Xextern GL_BOOL gb_button_event();
- END_OF_FILE
- if test 3085 -ne `wc -c <'gl.h'`; then
- echo shar: \"'gl.h'\" unpacked with wrong size!
- fi
- # end of 'gl.h'
- fi
- echo shar: End of archive 1 \(of 2\).
- cp /dev/null ark1isdone
- MISSING=""
- for I in 1 2 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked both 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
-