v09i028: xmines, Part02/03
Jim McBeath
uunet!globes!jimmc at uunet.UU.NET
Wed Sep 12 18:26:00 AEST 1990
Submitted-by: uunet!globes!jimmc at uunet.UU.NET (Jim McBeath)
Posting-number: Volume 9, Issue 28
Archive-name: xmines/part02
#! /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". If this archive is complete, you will
## see the following message at the end:
# "End of archive 2 (of 3)."
# Contents: mines.h patchlevel.h actions.c board.c buttons.c draw.c
# info.c main.c makeform.c msg.c
# Wrapped by jimmc at ss on Mon Sep 10 09:43:10 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f mines.h -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"mines.h\"
else
echo shar: Extracting \"mines.h\" \(2111 characters\)
sed "s/^X//" >mines.h <<'END_OF_mines.h'
X/*
X * Copyright (c) 1987 Tom Anderson; 20831 Frank Waters Road;
X * Stanwood, WA 98282.
X *
X * Permission to use, copy, modify, distribute, and sell this software and its
X * documentation for any purpose is hereby granted without fee, provided that
X * the above copyright notice appear in all copies and that both that
X * copyright notice and this permission notice appear in supporting
X * documentation, and that the name of Tom Anderson not be used
X * in advertising or publicity pertaining to distribution of the software
X * without specific, written prior permission. Tom Anderson makes
X * no representations about the suitability of this software for any purpose.
X * It is provided "as is" without express or implied warranty.
X *
X * TOM ANDERSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
X * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
X * EVENT SHALL TOM ANDERSON BE LIABLE FOR ANY SPECIAL, INDIRECT OR
X * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
X * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
X * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
X * OF THIS SOFTWARE.
X *
X */
X
X/* #define TINY_GAME /* for debugging */
X
X/*
X * mines header
X *
X */
X
X#define BOOL int
X#ifndef TRUE
X#define TRUE 1
X#endif
X#ifndef FALSE
X#define FALSE 0
X#endif
X
X/*
X * number of board squares per side
X */
X#define MAX_BOARD_ROWS 100
X#define MAX_BOARD_COLS 100
X#define DEFAULT_BOARD_ROWS 12
X#define DEFAULT_BOARD_COLS 12
X
X/*
X * board coordinates
X */
Xtypedef struct {
X int x;
X int y;
X} BoardCoordinate;
X
X/*
X * square state
X */
Xtypedef struct {
X BOOL traversed; /* has the poor soul stepped here? */
X BOOL mined; /* is this square mined? */
X BOOL occupied; /* is this square occupied? */
X BOOL unsafe; /* has the player determined a mine here?*/
X BOOL safe; /* has the player determined no mines here?*/
X BOOL visited; /* has connected test looked here yet? */
X int nearby; /* number of mines nearby. */
X short row,col;
X Widget w;
X} Square;
X
X/* end */
END_OF_mines.h
if test 2111 -ne `wc -c <mines.h`; then
echo shar: \"mines.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f patchlevel.h -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"patchlevel.h\"
else
echo shar: Extracting \"patchlevel.h\" \(1453 characters\)
sed "s/^X//" >patchlevel.h <<'END_OF_patchlevel.h'
X/*
X * Copyright 1990 Globetrotter Software, Inc.
X *
X * Permission to use, copy, modify, distribute, and sell this software and its
X * documentation for any purpose is hereby granted without fee, provided that
X * the above copyright notice appear in all copies and that both that
X * copyright notice and this permission notice appear in supporting
X * documentation, and that the name of Globetrotter Software not be used
X * in advertising or publicity pertaining to distribution of the software
X * without specific, written prior permission. Globetrotter Software makes
X * no representations about the suitability of this software for any purpose.
X * It is provided "as is" without express or implied warranty.
X *
X * GLOBETROTTER SOFTWARE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
X * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
X * EVENT SHALL GLOBETROTTER SOFTWARE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
X * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
X * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
X * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
X * OF THIS SOFTWARE.
X *
X * Author: Jim McBeath, Globetrotter Software
X * globes!jimmc at oliveb.olivetti.com
X * (408)741-0489
X */
X
X/* patchlevel.h for xmines
X */
X
Xchar *MinesVersion = "XMines v1.1";
X
X/*
X * Current patchlevel is 0 - this is the original!
X */
X
X/* end */
END_OF_patchlevel.h
if test 1453 -ne `wc -c <patchlevel.h`; then
echo shar: \"patchlevel.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f actions.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"actions.c\"
else
echo shar: Extracting \"actions.c\" \(2816 characters\)
sed "s/^X//" >actions.c <<'END_OF_actions.c'
X/*
X * Copyright 1990 Globetrotter Software, Inc.
X *
X * Permission to use, copy, modify, distribute, and sell this software and its
X * documentation for any purpose is hereby granted without fee, provided that
X * the above copyright notice appear in all copies and that both that
X * copyright notice and this permission notice appear in supporting
X * documentation, and that the name of Globetrotter Software not be used
X * in advertising or publicity pertaining to distribution of the software
X * without specific, written prior permission. Globetrotter Software makes
X * no representations about the suitability of this software for any purpose.
X * It is provided "as is" without express or implied warranty.
X *
X * GLOBETROTTER SOFTWARE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
X * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
X * EVENT SHALL GLOBETROTTER SOFTWARE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
X * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
X * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
X * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
X * OF THIS SOFTWARE.
X *
X * Author: Jim McBeath, Globetrotter Software
X * globes!jimmc at oliveb.olivetti.com
X * (408)741-0489
X */
X
X/* actions.c - action functions
X */
X
X#include <X11/Intrinsic.h>
X#include "mines.h"
X
Xextern int BoardRows, BoardCols;
X
Xextern Square *GetSquare();
X
Xvoid
XDrawCell(w,ev,params,num_params)
XWidget w;
XXEvent *ev;
XString *params;
XCardinal *num_params;
X{
X int row, col;
X Square *sqp, *GetWidgetSquare();
X
X if (*num_params == 0) {
X sqp = GetWidgetSquare(w);
X DrawSquare(sqp);
X return;
X }
X if (*num_params != 2)
X return;
X row = atoi(params[0]);
X col = atoi(params[1]);
X if (row<0 || row>=BoardRows)
X return;
X if (col<0 || col>=BoardCols)
X return;
X sqp = GetSquare(row,col);
X DrawSquare(sqp);
X}
X
Xvoid
XMovePlayer(w,ev,params,num_params)
XWidget w;
XXEvent *ev;
XString *params;
XCardinal *num_params;
X{
X Square *sqp;
X
X if (*num_params != 0)
X return;
X sqp = GetWidgetSquare(w);
X if (!sqp)
X return;
X DoMove(sqp);
X}
X
Xvoid
XMarkMined(w,ev,params,num_params)
XWidget w;
XXEvent *ev;
XString *params;
XCardinal *num_params;
X{
X Square *sqp;
X
X if (*num_params != 0)
X return;
X sqp = GetWidgetSquare(w);
X if (!sqp)
X return;
X MarkSquare(sqp,FALSE);
X}
X
Xvoid
XMarkSafe(w,ev,params,num_params)
XWidget w;
XXEvent *ev;
XString *params;
XCardinal *num_params;
X{
X Square *sqp;
X
X if (*num_params != 0)
X return;
X sqp = GetWidgetSquare(w);
X if (!sqp)
X return;
X MarkSquare(sqp,TRUE);
X}
X
XXtActionsRec actions[] = {
X { "DrawCell", DrawCell},
X { "MovePlayer", MovePlayer},
X { "MarkMined", MarkMined},
X { "MarkSafe", MarkSafe},
X};
X
XInitActions(appctx)
XXtAppContext appctx;
X{
X XtAppAddActions(appctx,actions,XtNumber(actions));
X}
X
X/* end */
END_OF_actions.c
if test 2816 -ne `wc -c <actions.c`; then
echo shar: \"actions.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f board.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"board.c\"
else
echo shar: Extracting \"board.c\" \(8437 characters\)
sed "s/^X//" >board.c <<'END_OF_board.c'
X/*
X * Copyright (c) 1987 Tom Anderson; 20831 Frank Waters Road;
X * Stanwood, WA 98282.
X *
X * Permission to use, copy, modify, distribute, and sell this software and its
X * documentation for any purpose is hereby granted without fee, provided that
X * the above copyright notice appear in all copies and that both that
X * copyright notice and this permission notice appear in supporting
X * documentation, and that the name of Tom Anderson not be used
X * in advertising or publicity pertaining to distribution of the software
X * without specific, written prior permission. Tom Anderson makes
X * no representations about the suitability of this software for any purpose.
X * It is provided "as is" without express or implied warranty.
X *
X * TOM ANDERSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
X * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
X * EVENT SHALL TOM ANDERSON BE LIABLE FOR ANY SPECIAL, INDIRECT OR
X * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
X * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
X * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
X * OF THIS SOFTWARE.
X *
X */
X
X/*
X * manage the board state
X *
X */
Xstatic char copyright[] = "Copyright 1987 Tom Anderson";
X
X#include <stdio.h>
X#include <strings.h>
X#include <sys/types.h>
X
X#include <X11/Intrinsic.h>
X#include "mines.h"
X
Xextern char *malloc();
X
XSquare **MainBoard;
Xint BoardRows;
Xint BoardCols;
XSquare *PlayerSquare;
XBOOL GameOver;
XBOOL Impossible;
X
Xstatic int lastlevel;
X
Xstatic char *
Xs_malloc(size)
Xint size;
X{
X char *p;
X
X p = malloc(size);
X if (!p) {
X fprintf(stderr,"Can't allocate memory for playing board\n");
X exit(1);
X }
X return p;
X}
X
Xvoid
XAllocBoard(numrows,numcols,deflevel)
Xint numrows,numcols;
Xint deflevel; /* default number of mines to put in */
X{
X int i;
X
X BoardRows = numrows;
X BoardCols = numcols;
X
X if (BoardRows < 3)
X BoardRows = 3;
X if (BoardCols < 3)
X BoardCols = 3;
X if (BoardRows > MAX_BOARD_ROWS)
X BoardRows = MAX_BOARD_ROWS;
X if (BoardCols > MAX_BOARD_COLS)
X BoardCols = MAX_BOARD_COLS;
X
X MainBoard = (Square **)s_malloc(BoardRows * sizeof(Square *));
X for (i=0; i<BoardRows; i++) {
X MainBoard[i] = (Square *)s_malloc(BoardCols * sizeof(Square));
X }
X if (deflevel>0) /* set default mine quantity */
X lastlevel = deflevel;
X else
X lastlevel = (BoardRows + BoardCols) / 2;
X}
X
X/*
X * set up the playing surface at the beginning of the game
X */
Xvoid
XInitBoard(level)
Xint level; /* number of mines */
X{
X register int i, j, minesPlaced, cutoff;
X register Square * sqp;
X int pass = 0;
X void MazeConnected();
X char *MineWarningMessage();
X
X if (level<=0) level=lastlevel;
X if (level > (BoardRows*BoardCols-5))
X level = BoardRows*BoardCols-5; /* avoid infinite loop below */
X lastlevel = level;
X SetMineCountDisplay(level);
X
X /* zero the board */
X for (i = 0 ; i < BoardRows ; i++) {
X for (j = 0 ; j < BoardCols ; j++) {
X sqp = &MainBoard[i][j];
X sqp->traversed = sqp->mined = sqp->occupied
X = sqp->unsafe = sqp->safe = FALSE;
X sqp->nearby = 0;
X sqp->visited = FALSE;
X sqp->row = i;
X sqp->col = j;
X }
X }
X
X /* make several passes over the board, placing mines at
X * a probability calculated to require about 3 passes on the average
X */
X cutoff = level / 3 + 1;
X for (minesPlaced = 0 ; minesPlaced < level ; ) {
X for (i = 0 ; i < BoardRows ; i++) {
X for (j = 0 ; j < BoardCols ; j++) {
X if ((random() % (BoardRows * BoardCols)) <cutoff
X && ! MainBoard[i][j].mined
X && minesPlaced < level
X && ! (i <= 1 && j <= 1)
X && ! (i==BoardRows-1 && j==BoardCols-1)) {
X MainBoard[i][j].mined = TRUE;
X minesPlaced++;
X }
X }
X }
X }
X PlayerSquare = &MainBoard[0][0];
X MainBoard[0][0].occupied = MainBoard[0][0].traversed = TRUE;
X GameOver = FALSE;
X
X MazeConnected();
X
X Message(MineWarningMessage());
X
X#ifndef NOSCORE
X SetHints(0);
X SetNumberMoves(0);
X SetMinesMarked(0);
X SetSafesMarked(0);
X#endif
X}
X
XBOOL
XTraverse(x, y)
Xint x;
Xint y;
X{
X int i;
X int j;
X
X if (y == BoardRows-1 && x == BoardCols-1) return TRUE;
X
X MainBoard[y][x].visited = TRUE;
X
X for (i=y-1; i <= y+1; i++) {
X if (i < 0 || i == BoardRows) continue;
X for (j=x-1; j <= x+1; j++) {
X if (j < 0 || j == BoardCols) continue;
X if (i == y && j == x) continue;
X if (MainBoard[i][j].visited) continue;
X if (MainBoard[i][j].mined) continue;
X
X if (Traverse(j, i)) return TRUE;
X }
X }
X
X return FALSE;
X}
X
Xvoid
XMazeConnected()
X{
X Impossible = !Traverse(0, 0);
X}
X
XSetCellWidget(row,col,w)
Xint row,col;
XWidget w;
X{
X MainBoard[row][col].w = w;
X}
X
X/* translate (row,col) to Square pointer */
XSquare *
XGetSquare(row,col)
Xint row,col;
X{
X return (&MainBoard[row][col]);
X}
X
X/* translate Widget to Square pointer; NULL pointer if didn't get it */
XSquare *
XGetWidgetSquare(w)
XWidget w;
X{
X int x,y;
X Square *sqp;
X
X for (y=0; y<BoardRows; y++) {
X for (x=0; x<BoardCols; x++) {
X sqp = &MainBoard[y][x];
X if (sqp->w == w) {
X return sqp;
X }
X }
X }
X return NULL;
X}
X
X/* toggle a square's marking as being probably safe or unsafe */
Xvoid
XMarkSquare(sqp,safe)
XSquare *sqp;
XBOOL safe;
X{
X if (sqp->traversed)
X return;
X
X if (safe) {
X#ifndef NOSCORE
X IncrSafesMarked(sqp->safe ? -1 : 1);
X IncrMinesMarked(sqp->unsafe ? -1 : 0);
X#endif
X sqp->safe = ! sqp->safe;
X sqp->unsafe = FALSE;
X } else {
X#ifndef NOSCORE
X IncrSafesMarked(sqp->safe ? -1 : 0);
X IncrMinesMarked(sqp->unsafe ? -1 : 1);
X#endif
X sqp->unsafe = ! sqp->unsafe;
X sqp->safe = FALSE;
X }
X DrawSquare(sqp);
X}
X
X
X/* try to move to a certain board coordinate */
Xvoid
XDoMove(sqp)
XSquare *sqp;
X{
X int row,col;
X register int y = PlayerSquare->row;
X register int x = PlayerSquare->col;
X
X row = sqp->row;
X col = sqp->col;
X if ((col == x) && (row == y)) return;
X if (MainBoard[row][col].unsafe) return;
X
X if ((abs(col - x) > 1) || (abs(row - y) > 1)) {
X int xx, yy;
X
X /* allow moving to any square which is or is adjacent to
X * a traversed square */
X for (xx = col - 1 ; xx <= col + 1 ; xx++) {
X for (yy = row - 1 ; yy <= row + 1 ; yy++) {
X if (xx >= 0 && xx < BoardCols &&
X yy >= 0 && yy < BoardRows &&
X MainBoard[yy][xx].traversed) goto ok;
X }
X }
X return;
X }
X
Xok:
X
X#ifndef NOSCORE
X IncrNumberMoves(1);
X#endif
X
X /* step off our current square */
X MainBoard[y][x].occupied = FALSE;
X DrawSquare(PlayerSquare);
X sqp = &MainBoard[row][col];
X
X /* if we stepped on a mine, blow him up */
X if (sqp->mined) {
X GameOver = TRUE;
X Message("You just exploded. ");
X DrawBoard(0);
X }
X
X /* else if this is home, render congratulations */
X else if (col == BoardCols-1 && row == BoardRows-1) {
X PlayerSquare = sqp;
X sqp->traversed = sqp->occupied = TRUE;
X GameOver = TRUE;
X Message("You honestly made it!");
X DrawBoard(0);
X }
X
X /* else move onto the new square */
X else {
X /* if player marked that square as safe, unmark */
X if (sqp->safe) {
X#ifndef NOSCORE
X IncrSafesMarked(-1);
X#endif
X sqp->safe = FALSE;
X }
X PlayerSquare = sqp;
X Message(MineWarningMessage());
X sqp->traversed = sqp->occupied = TRUE;
X DrawSquare(sqp);
X }
X}
X
XSquare *
XGetHintSquare() /* returns pointer to a square suitable for a hint; or NULL */
X{
X int i;
X int j;
X int x = PlayerSquare->col;
X int y = PlayerSquare->row;
X
X for (j = y-1; j <= y+1; j++) {
X if (j < 0 || j == BoardRows) continue;
X for (i = x-1; i <= x+1; i++) {
X if (i < 0 || i == BoardCols) continue;
X if (j == y && i == x) continue;
X
X if (MainBoard[j][i].traversed) continue;
X
X if (!MainBoard[j][i].mined) {
X
X#ifndef NOSCORE
X IncrHints(1);
X#endif
X MainBoard[j][i].safe = TRUE;
X MainBoard[j][i].unsafe = FALSE;
X
X return (GetSquare(j,i));
X }
X }
X }
X return NULL;
X}
X
X/*
X * return a pointer to the warning message
X */
Xchar *
XMineWarningMessage()
X{
X static char warning[128];
X register int x, y;
X int minesFound = 0;
X
X if (!PlayerSquare->traversed) {
X for (x = PlayerSquare->col - 1 ;
X x <= PlayerSquare->col + 1 ;
X x++) {
X for (y = PlayerSquare->row - 1 ;
X y <= PlayerSquare->row + 1 ;
X y++) {
X if (x >= 0 && x < BoardCols &&
X y >= 0 && y < BoardRows &&
X MainBoard[y][x].mined)
X minesFound++;
X }
X }
X PlayerSquare->nearby = minesFound;
X } else {
X minesFound = PlayerSquare->nearby;
X }
X
X if (minesFound == 0) {
X sprintf(warning, "No mines nearby.");
X } else if (minesFound == 1) {
X sprintf(warning, "1 mine nearby.");
X } else {
X sprintf(warning, "%d mines nearby.", minesFound);
X }
X
X return(warning);
X}
X
X/* end */
END_OF_board.c
if test 8437 -ne `wc -c <board.c`; then
echo shar: \"board.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f buttons.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"buttons.c\"
else
echo shar: Extracting \"buttons.c\" \(3958 characters\)
sed "s/^X//" >buttons.c <<'END_OF_buttons.c'
X/*
X * Copyright 1990 Globetrotter Software, Inc.
X *
X * Permission to use, copy, modify, distribute, and sell this software and its
X * documentation for any purpose is hereby granted without fee, provided that
X * the above copyright notice appear in all copies and that both that
X * copyright notice and this permission notice appear in supporting
X * documentation, and that the name of Globetrotter Software not be used
X * in advertising or publicity pertaining to distribution of the software
X * without specific, written prior permission. Globetrotter Software makes
X * no representations about the suitability of this software for any purpose.
X * It is provided "as is" without express or implied warranty.
X *
X * GLOBETROTTER SOFTWARE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
X * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
X * EVENT SHALL GLOBETROTTER SOFTWARE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
X * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
X * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
X * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
X * OF THIS SOFTWARE.
X *
X * Author: Jim McBeath, Globetrotter Software
X * globes!jimmc at oliveb.olivetti.com
X * (408)741-0489
X */
X
X/* buttons.c - command button processing
X */
X
X#include <X11/Intrinsic.h>
X#include <X11/StringDefs.h>
X#include <X11/Xaw/Form.h>
X#include <X11/Xaw/Command.h>
X#include <X11/Xaw/AsciiText.h>
X#include "mines.h"
X
X#define MBUFSIZE 6
Xchar MineCountBuf[MBUFSIZE];
XWidget TotalMineCountWidget;
X
Xvoid
XSetMineCountDisplay(n)
Xint n;
X{
X char mbuf[MBUFSIZE];
X Arg arg;
X
X bzero(mbuf,sizeof(mbuf));
X sprintf(mbuf,"%d",n);
X XtSetArg(arg,"string",mbuf);
X XtSetValues(TotalMineCountWidget,&arg,1);
X}
X
Xstatic void
XRestartGameCB(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data, call_data; /* ignored */
X{
X int n;
X Arg arg;
X char *ss;
X
X XtSetArg(arg,"string",&ss);
X XtGetValues(TotalMineCountWidget,&arg,1);
X n = atoi(ss);
X InitBoard(n);
X DrawBoard(1); /* redraw the board */
X}
X
Xstatic void
XQuitCB(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data, call_data; /* ignored */
X{
X exit(0); /* TBD - any saving options or anything? */
X}
X
Xstatic void
XGiveHintCB(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data, call_data; /* ignored */
X{
X Square *sqp, *GetHintSquare();
X
X sqp = GetHintSquare();
X if (!sqp)
X return;
X DrawSquare(sqp);
X}
X
XWidget
XInitButtons(parent,above)
XWidget parent;
XWidget above;
X{
X int i;
X Arg args[10];
X Widget lasthwidget, minecountw;
X
X i = 0;
X XtSetArg(args[i],XtNfromVert,above);
X i++;
X lasthwidget = XtCreateManagedWidget("countlabel",
X labelWidgetClass, parent, args, i);
X
X i = 0;
X XtSetArg(args[i],XtNfromVert,above);
X i++;
X XtSetArg(args[i],XtNfromHoriz,lasthwidget);
X i++;
X XtSetArg(args[i],XtNeditType,XawtextEdit);
X i++;
X XtSetArg(args[i],XtNstring,MineCountBuf);
X i++;
X XtSetArg(args[i],XtNlength,sizeof(MineCountBuf)-1);
X i++;
X lasthwidget = TotalMineCountWidget = XtCreateManagedWidget(
X "mineinputcount",asciiTextWidgetClass, parent, args, i);
X minecountw = lasthwidget;
X
X i = 0;
X XtSetArg(args[i],XtNfromVert,above);
X i++;
X XtSetArg(args[i],XtNfromHoriz,lasthwidget);
X i++;
X lasthwidget = XtCreateManagedWidget("restart",
X commandWidgetClass, parent, args, i);
X XtAddCallback(lasthwidget,XtNcallback,RestartGameCB,(caddr_t)0);
X XtInstallAccelerators(minecountw,lasthwidget);
X
X i = 0;
X XtSetArg(args[i],XtNfromVert,above);
X i++;
X XtSetArg(args[i],XtNfromHoriz,lasthwidget);
X i++;
X lasthwidget = XtCreateManagedWidget("hint",
X commandWidgetClass, parent, args, i);
X XtAddCallback(lasthwidget,XtNcallback,GiveHintCB,(caddr_t)0);
X
X i = 0;
X XtSetArg(args[i],XtNfromVert,above);
X i++;
X XtSetArg(args[i],XtNfromHoriz,lasthwidget);
X i++;
X lasthwidget = XtCreateManagedWidget("quit",
X commandWidgetClass, parent, args, i);
X XtAddCallback(lasthwidget,XtNcallback,QuitCB,(caddr_t)0);
X
X return lasthwidget;
X}
X
X/* end */
END_OF_buttons.c
if test 3958 -ne `wc -c <buttons.c`; then
echo shar: \"buttons.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f draw.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"draw.c\"
else
echo shar: Extracting \"draw.c\" \(7508 characters\)
sed "s/^X//" >draw.c <<'END_OF_draw.c'
X/*
X * Copyright 1990 Globetrotter Software, Inc.
X *
X * Permission to use, copy, modify, distribute, and sell this software and its
X * documentation for any purpose is hereby granted without fee, provided that
X * the above copyright notice appear in all copies and that both that
X * copyright notice and this permission notice appear in supporting
X * documentation, and that the name of Globetrotter Software not be used
X * in advertising or publicity pertaining to distribution of the software
X * without specific, written prior permission. Globetrotter Software makes
X * no representations about the suitability of this software for any purpose.
X * It is provided "as is" without express or implied warranty.
X *
X * GLOBETROTTER SOFTWARE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
X * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
X * EVENT SHALL GLOBETROTTER SOFTWARE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
X * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
X * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
X * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
X * OF THIS SOFTWARE.
X *
X * Author: Jim McBeath, Globetrotter Software
X * globes!jimmc at oliveb.olivetti.com
X * (408)741-0489
X */
X
X/* draw.c - functions to draw stuff on the screen
X */
X
X#include <X11/Intrinsic.h>
X#include <X11/StringDefs.h>
X#include "mines.h"
X
X/* include all of the bitmaps */
X#include "bMine.xbm" /* bad mine */
X#include "bMineSm.xbm" /* bad mine, small version */
X#include "bSafe.xbm" /* bad safee */
X#include "bSafeSm.xbm"
X#include "hMine.xbm" /* hidden mine */
X#include "hMineSm.xbm"
X#include "mine.xbm"
X#include "mineSm.xbm"
X#include "safe.xbm"
X#include "safeSm.xbm"
X
X#include "e0.xbm" /* empty traversed square with 0 mines around */
X#include "e0Sm.xbm" /* small version of 0-mine empty */
X#include "e1.xbm" /* one mine in neighboring cells */
X#include "e1Sm.xbm"
X#include "e2.xbm"
X#include "e2Sm.xbm"
X#include "e3.xbm"
X#include "e3Sm.xbm"
X#include "e4.xbm"
X#include "e4Sm.xbm"
X#include "e5.xbm"
X#include "e5Sm.xbm"
X#include "e6.xbm"
X#include "e6Sm.xbm"
X#include "e7.xbm"
X#include "e7Sm.xbm"
X#include "e8.xbm"
X#include "e8Sm.xbm"
X
X#include "pl0.xbm" /* player square with 0 mine around it */
X#include "pl0Sm.xbm" /* small version of 0-mine player square */
X#include "pl1.xbm"
X#include "pl1Sm.xbm"
X#include "pl2.xbm"
X#include "pl2Sm.xbm"
X#include "pl3.xbm"
X#include "pl3Sm.xbm"
X#include "pl4.xbm"
X#include "pl4Sm.xbm"
X#include "pl5.xbm"
X#include "pl5Sm.xbm"
X#include "pl6.xbm"
X#include "pl6Sm.xbm"
X#include "pl7.xbm"
X#include "pl7Sm.xbm"
X#include "pl8.xbm"
X#include "pl8Sm.xbm"
X
Xextern int BoardRows, BoardCols;
Xextern BOOL GameOver;
X
Xextern Square *GetSquare();
X
X/* bitmaps and small bitmaps */
XPixmap MineSquareBM, BadMineSquareBM, HiddenMineSquareBM;
XPixmap MineSquareSBM, BadMineSquareSBM, HiddenMineSquareSBM;
XPixmap SafeSquareBM, BadSafeSquareBM;
XPixmap SafeSquareSBM, BadSafeSquareSBM;
X
XPixmap player_squaresBM[9];
XPixmap player_squaresSBM[9];
XPixmap numbered_squaresBM[9];
XPixmap numbered_squaresSBM[9];
X
XInitBitmaps(dpy,win)
XDisplay *dpy;
XWindow win;
X{
X#define BB(var,file) \
X var = XCreateBitmapFromData(dpy,win,\
X file/**/_bits,file/**/_width,file/**/_height);
X BB(MineSquareBM,mine);
X BB(MineSquareSBM,mineSmall);
X BB(BadMineSquareBM,badmine);
X BB(BadMineSquareSBM,badmineSmall);
X BB(HiddenMineSquareBM,hiddenmine);
X BB(HiddenMineSquareSBM,hiddenmineSmall);
X BB(SafeSquareBM,safe);
X BB(SafeSquareSBM,safeSmall);
X BB(BadSafeSquareBM,badsafe);
X BB(BadSafeSquareSBM,badsafeSmall);
X BB(player_squaresBM[0],plZero);
X BB(player_squaresSBM[0],plZeroSmall);
X BB(player_squaresBM[1],plOne);
X BB(player_squaresSBM[1],plOneSmall);
X BB(player_squaresBM[2],plTwo);
X BB(player_squaresSBM[2],plTwoSmall);
X BB(player_squaresBM[3],plThree);
X BB(player_squaresSBM[3],plThreeSmall);
X BB(player_squaresBM[4],plFour);
X BB(player_squaresSBM[4],plFourSmall);
X BB(player_squaresBM[5],plFive);
X BB(player_squaresSBM[5],plFiveSmall);
X BB(player_squaresBM[6],plSix);
X BB(player_squaresSBM[6],plSixSmall);
X BB(player_squaresBM[7],plSeven);
X BB(player_squaresSBM[7],plSevenSmall);
X BB(player_squaresBM[8],plEight);
X BB(player_squaresSBM[8],plEightSmall);
X BB(numbered_squaresBM[0],zero);
X BB(numbered_squaresSBM[0],zeroSmall);
X BB(numbered_squaresBM[1],one);
X BB(numbered_squaresSBM[1],oneSmall);
X BB(numbered_squaresBM[2],two);
X BB(numbered_squaresSBM[2],twoSmall);
X BB(numbered_squaresBM[3],three);
X BB(numbered_squaresSBM[3],threeSmall);
X BB(numbered_squaresBM[4],four);
X BB(numbered_squaresSBM[4],fourSmall);
X BB(numbered_squaresBM[5],five);
X BB(numbered_squaresSBM[5],fiveSmall);
X BB(numbered_squaresBM[6],six);
X BB(numbered_squaresSBM[6],sixSmall);
X BB(numbered_squaresBM[7],seven);
X BB(numbered_squaresSBM[7],sevenSmall);
X BB(numbered_squaresBM[8],eight);
X BB(numbered_squaresSBM[8],eightSmall);
X}
X
X/*
X * draw a square
X */
Xvoid
XDrawSquare(sqp)
XSquare *sqp;
X{
X Pixmap bm,sbm;
X String bmname;
X char nbuf[30];
X Widget w;
X Window win;
X Display *dpy;
X GC gc;
X int width,height,bmsize;
X int dx,dy;
X int i;
X Arg args[10];
X static int lastwidth, lastheight;
X
X if (!sqp)
X return;
X /* determine which bitmap to paint the square with */
X if (sqp->occupied) {
X bm = player_squaresBM[sqp->nearby];
X sbm = player_squaresSBM[sqp->nearby];
X sprintf(nbuf,"pl%d",sqp->nearby);
X bmname = nbuf;
X } else if (sqp->traversed) {
X bm = numbered_squaresBM[sqp->nearby];
X sbm = numbered_squaresSBM[sqp->nearby];
X sprintf(nbuf,"%d",sqp->nearby);
X bmname = nbuf;
X } else if (GameOver) {
X if (sqp->mined) {
X if (sqp->safe) {
X bm = BadSafeSquareBM;
X sbm = BadSafeSquareSBM;
X bmname = "badsafe";
X } else if (sqp->unsafe) {
X bm = MineSquareBM;
X sbm = MineSquareSBM;
X bmname = "mine";
X } else {
X bm = HiddenMineSquareBM;
X sbm = HiddenMineSquareSBM;
X bmname = "hiddenmine";
X }
X } else {
X if (sqp->unsafe) {
X bm = BadMineSquareBM;
X sbm = BadMineSquareSBM;
X bmname = "badmine";
X } else if (sqp->safe) {
X bm = SafeSquareBM;
X sbm = SafeSquareSBM;
X bmname = "safe";
X } else {
X bm = sbm = NULL;
X bmname = "white";
X }
X }
X } else if (sqp->unsafe) {
X bm = MineSquareBM;
X sbm = MineSquareSBM;
X bmname = "mine";
X } else if (sqp->safe) {
X bm = SafeSquareBM;
X sbm = SafeSquareSBM;
X bmname = "safe";
X } else {
X bm = sbm = NULL;
X bmname = "white";
X }
X
X /* paint the square */
X w = sqp->w;
X win = XtWindow(w);
X dpy = XtDisplay(w);
X gc = XDefaultGC(dpy,XDefaultScreen(dpy));
X XClearWindow(dpy,win);
X#if 0 /* doesn't work */
X i=0;
X XtSetArg(args[i],XtNwidth,&width);
X i++;
X XtSetArg(args[i],XtNheight,&height);
X i++;
X XtGetValues(w,args,i);
X#else
X/* a hack to avoid getting the size for every cell */
X if (sqp->row==0 && sqp->col==0) {
X Window root;
X int x,y,bwidth,depth;
X XGetGeometry(dpy,win,&root,&x,&y,&width,&height,&bwidth,&depth);
X lastwidth = width;
X lastheight = height;
X } else {
X width = lastwidth;
X height = lastheight;
X }
X#endif
X if (width<32 || height<32) {
X bm = sbm; /* use small bitmap */
X bmsize = 16;
X } else {
X bmsize = 32;
X }
X dx = (width-bmsize)/2;
X dy = (height-bmsize)/2;
X if (bm) {
X XCopyPlane(dpy,bm,win,gc,0,0,bmsize,bmsize,dx,dy,1);
X }
X#if 0
X XDrawImageString(dpy,win,gc,0,12,bmname,strlen(bmname));
X#endif
X}
X
Xvoid
XDrawBoard(clearflag)
Xint clearflag; /* ignored for now */
X{
X int x,y;
X Square *sqp;
X
X for (y=0; y<BoardRows; y++) {
X for (x=0; x<BoardCols; x++) {
X sqp = GetSquare(y,x);
X DrawSquare(sqp);
X }
X }
X}
X
X/* end */
END_OF_draw.c
if test 7508 -ne `wc -c <draw.c`; then
echo shar: \"draw.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f info.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"info.c\"
else
echo shar: Extracting \"info.c\" \(3308 characters\)
sed "s/^X//" >info.c <<'END_OF_info.c'
X/*
X * Copyright 1990 Globetrotter Software, Inc.
X *
X * Permission to use, copy, modify, distribute, and sell this software and its
X * documentation for any purpose is hereby granted without fee, provided that
X * the above copyright notice appear in all copies and that both that
X * copyright notice and this permission notice appear in supporting
X * documentation, and that the name of Globetrotter Software not be used
X * in advertising or publicity pertaining to distribution of the software
X * without specific, written prior permission. Globetrotter Software makes
X * no representations about the suitability of this software for any purpose.
X * It is provided "as is" without express or implied warranty.
X *
X * GLOBETROTTER SOFTWARE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
X * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
X * EVENT SHALL GLOBETROTTER SOFTWARE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
X * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
X * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
X * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
X * OF THIS SOFTWARE.
X *
X * Author: Jim McBeath, Globetrotter Software
X * globes!jimmc at oliveb.olivetti.com
X * (408)741-0489
X */
X
X/* info.c - add an info button to a form; it will pop up an info panel
X *
X * 19.Jul.90 jimmc Initial definition
X */
X
X#include <X11/Intrinsic.h>
X#include <X11/StringDefs.h>
X#include <X11/Shell.h>
X#include <X11/Xaw/Form.h>
X#include <X11/Xaw/Command.h>
X#include "mines.h"
X
Xextern char *MinesVersion;
X
Xstatic char infotext[] = "\
XCopyright 1990 Globetrotter Software, Inc.\n\
XPortions Copyright 1987 Tom Anderson.\n\
XThis software is freely redistributable\n\
X(with some restrictions).\n\
X\n\
XOriginal version written by Tom Anderson;\n\
Xmodified by Brian Dalio;\n\
Xmodified and ported to X11 by Jim McBeath.";
X
Xstatic void
XInfoCB(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data, call_data; /* ignored */
X{
X Widget shell = (Widget)client_data;
X
X XtPopup(shell,XtGrabNone);
X}
X
Xstatic void
XInfoDownCB(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data, call_data; /* ignored */
X{
X Widget shell = (Widget)client_data;
X
X XtPopdown(shell);
X}
X
Xvoid
XInitInfoButton(topw,parent,fromhoriz)
XWidget topw;
XWidget parent;
XWidget fromhoriz;
X{
X int i;
X Arg args[10];
X Widget infoshell, infoform, w;
X
X/* first, make the popup with the info in it */
X i = 0;
X infoshell = XtCreatePopupShell("xmines_info",
X applicationShellWidgetClass,
X topw,args,i);
X
X i = 0;
X infoform = XtCreateManagedWidget("info",formWidgetClass,
X infoshell,args,i);
X
X i = 0;
X XtSetArg(args[i],XtNlabel,MinesVersion);
X i++;
X w = XtCreateManagedWidget("version",labelWidgetClass,infoform,args,i);
X
X i = 0;
X XtSetArg(args[i],XtNlabel,infotext);
X i++;
X XtSetArg(args[i],XtNfromVert,w);
X i++;
X w = XtCreateManagedWidget("text",commandWidgetClass,infoform,args,i);
X /* put in the text */
X XtAddCallback(w,XtNcallback,InfoDownCB,(caddr_t)infoshell);
X
X/* now add a button to the parent form which will bring up the info popup */
X i = 0;
X XtSetArg(args[i],XtNfromHoriz,fromhoriz);
X i++;
X w = XtCreateManagedWidget("info",
X commandWidgetClass, parent, args, i);
X XtAddCallback(w,XtNcallback,InfoCB,(caddr_t)infoshell);
X}
X
X/* end */
END_OF_info.c
if test 3308 -ne `wc -c <info.c`; then
echo shar: \"info.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f main.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"main.c\"
else
echo shar: Extracting \"main.c\" \(5104 characters\)
sed "s/^X//" >main.c <<'END_OF_main.c'
X/*
X * Copyright 1990 Globetrotter Software, Inc.
X *
X * Permission to use, copy, modify, distribute, and sell this software and its
X * documentation for any purpose is hereby granted without fee, provided that
X * the above copyright notice appear in all copies and that both that
X * copyright notice and this permission notice appear in supporting
X * documentation, and that the name of Globetrotter Software not be used
X * in advertising or publicity pertaining to distribution of the software
X * without specific, written prior permission. Globetrotter Software makes
X * no representations about the suitability of this software for any purpose.
X * It is provided "as is" without express or implied warranty.
X *
X * GLOBETROTTER SOFTWARE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
X * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
X * EVENT SHALL GLOBETROTTER SOFTWARE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
X * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
X * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
X * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
X * OF THIS SOFTWARE.
X *
X * Author: Jim McBeath, Globetrotter Software
X * globes!jimmc at oliveb.olivetti.com
X * (408)741-0489
X */
X
X/* xmines - the minestool game for X11
X */
X
X#include <X11/Intrinsic.h>
X#include <X11/Xatom.h>
X#include <X11/StringDefs.h>
X#include <X11/Shell.h>
X#include <stdio.h>
X#include <ctype.h>
X#include "mines.h"
X#include "patchlevel.h" /* pick up the version string */
X
Xchar *Progname;
XXtAppContext appctx;
X
X/* we use the AppResources structure to collect info from the calls to
X * XtGetApplicationResources.
X */
Xtypedef struct {
X int cellsize; /* width and height of each cell in the array */
X int numrows, numcols;
X int minecount;
X} AppResources, *AppResourcesPtr;
X
X/* a place to put data into from the call to XtGetApplicationResources. */
Xstatic AppResources Adata = { 32, DEFAULT_BOARD_ROWS, DEFAULT_BOARD_COLS};
X
X/* fallback resources in case we can't find the app-defaults file */
Xstatic String fallback_resources[] = {
X "*Cell.height: 32",
X "*Cell.width: 32",
X "*ArraySize: 12",
X "*Mines: 26",
X "*cell.*.translations: #override \n\
X <Btn1Down> : MovePlayer() \n\
X <Btn2Down> : MarkMined() \n\
X <Btn3Down> : MarkSafe()",
X "*mineinputcount.accelerators: #override \n\
X <Key>R : set() notify() unset() \n\
X <Key>Return : set() notify() unset()",
X "*restart.accelerators: #override \n\
X <Key>R : set() notify() unset() \n\
X <Key>Return : set() notify() unset()",
X NULL
X};
X
X/* command line options */
Xstatic XrmOptionDescRec options[] = {
X {"-cellsize", "cellSize", XrmoptionSepArg, NULL },
X {"-rows", "rows", XrmoptionSepArg, NULL },
X {"-columns", "columns", XrmoptionSepArg, NULL },
X {"-mines", "mines", XrmoptionSepArg, NULL },
X};
X
X/* resource items that can be specified in the users resources database
X * (e.g. xmines*cellsize)
X */
Xstatic XtResource resources[] = {
X {"cellSize", "CellSize", XtRInt, sizeof(int),
X XtOffset(AppResourcesPtr,cellsize), XtRInt, (char *)0},
X {"rows", "ArraySize", XtRInt, sizeof(int),
X XtOffset(AppResourcesPtr,numrows), XtRInt, (char *)0},
X {"columns", "ArraySize", XtRInt, sizeof(int),
X XtOffset(AppResourcesPtr,numcols), XtRInt, (char *)0},
X {"mines", "Mines", XtRInt, sizeof(int),
X XtOffset(AppResourcesPtr,minecount), XtRInt, (char *)0},
X};
X
X
Xvoid usage()
X{
Xfprintf(stderr,"usage: %s\n",Progname);
Xfprintf(stderr,
X " [-cellsize]");
Xexit(1);
X}
X
Xvoid main(argc, argv)
Xint argc;
Xchar *argv[];
X{
X char host[256];
X Widget top;
X Arg arg;
X int i,n;
X Display *dpy;
X XrmDatabase rmdb;
X
X Progname = rindex(argv[0],'/');
X if (Progname) Progname++;
X else Progname=argv[0];
X
X#if 0
X/* If I call these functions instead of XtInitialize, I get error messages
X * about not having a type converter registered for String to Orientation.
X */
X XtToolkitInitialize();
X appctx = XtCreateApplicationContext();
X XtAppSetFallbackResources(appctx,fallback_resources);
X dpy = XtOpenDisplay(appctx,NULL,Progname,"XMines",
X options,XtNumber(options),&argc,argv);
X top = XtAppCreateShell(Progname,"XMines",
X applicationShellWidgetClass,dpy,NULL,0);
X if (argc != 1) usage();
X#else
X#if 0
X top = XtInitialize(Progname,"XMines",options,XtNumber(options),
X &argc,argv);
X appctx = XtWidgetToApplicationContext(top);
X XtAppSetFallbackResources(appctx,fallback_resources);
X dpy = XtDisplay(top);
X#else
X top = XtAppInitialize(&appctx,"XMines",options,XtNumber(options),
X &argc,argv,fallback_resources,NULL,0);
X dpy = XtDisplay(top);
X#endif
X#endif
X InitActions(appctx);
X
X XtGetApplicationResources(top,&Adata,resources,XtNumber(resources),
X NULL,0);
X if (Adata.cellsize==0)
X Adata.cellsize = 32;
X
X if (Adata.numrows==0)
X Adata.numrows = DEFAULT_BOARD_ROWS;
X if (Adata.numcols==0)
X Adata.numcols = DEFAULT_BOARD_COLS;
X
X AllocBoard(Adata.numrows,Adata.numcols,Adata.minecount);
X
X makeform(top,Adata.numrows,Adata.numcols,Adata.cellsize);
X XtRealizeWidget(top);
X InitBitmaps(dpy,XtWindow(top));
X InitBoard(0);
X XtAppMainLoop(appctx);
X /* NOTREACHED */
X}
X
X/* end */
END_OF_main.c
if test 5104 -ne `wc -c <main.c`; then
echo shar: \"main.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f makeform.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"makeform.c\"
else
echo shar: Extracting \"makeform.c\" \(3274 characters\)
sed "s/^X//" >makeform.c <<'END_OF_makeform.c'
X/*
X * Copyright 1990 Globetrotter Software, Inc.
X *
X * Permission to use, copy, modify, distribute, and sell this software and its
X * documentation for any purpose is hereby granted without fee, provided that
X * the above copyright notice appear in all copies and that both that
X * copyright notice and this permission notice appear in supporting
X * documentation, and that the name of Globetrotter Software not be used
X * in advertising or publicity pertaining to distribution of the software
X * without specific, written prior permission. Globetrotter Software makes
X * no representations about the suitability of this software for any purpose.
X * It is provided "as is" without express or implied warranty.
X *
X * GLOBETROTTER SOFTWARE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
X * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
X * EVENT SHALL GLOBETROTTER SOFTWARE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
X * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
X * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
X * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
X * OF THIS SOFTWARE.
X *
X * Author: Jim McBeath, Globetrotter Software
X * globes!jimmc at oliveb.olivetti.com
X * (408)741-0489
X */
X
X/* makeform.c - builds the form which displays everything
X */
X
X#include <X11/Intrinsic.h>
X#include <X11/Xatom.h>
X#include <X11/StringDefs.h>
X#include <X11/Core.h>
X#include <X11/Shell.h>
X#include <X11/Xaw/Form.h>
X#include <X11/Xaw/Label.h>
X#include <X11/Xaw/Command.h>
X#include <stdio.h>
X#include <ctype.h>
X#include "mines.h"
X
Xextern char *MinesVersion;
X
Xvoid
Xmakeform(topw,numrows,numcols,cellsize)
XWidget topw;
Xint numrows, numcols;
Xint cellsize; /* size of each cell in pixels */
X{
X Widget form, cells;
X Widget top, bottom, bar;
X Widget lasthwidget, lastvwidget, w;
X Widget InitButtons(), InitMsg();
X Arg args[10];
X int i, b;
X int x,y;
X char buf[100],buf2[100],tbuf[100];
X XtTranslations tr;
X
X i = 0;
X form = XtCreateManagedWidget("form", formWidgetClass, topw, args, i);
X
X i = 0;
X XtSetArg(args[i],XtNlabel,MinesVersion);
X i++;
X lastvwidget = XtCreateManagedWidget("title",
X labelWidgetClass, form, args, i);
X
X InitInfoButton(topw,form,lastvwidget);
X
X lastvwidget = InitButtons(form,lastvwidget);
X /* init command buttons */
X
X lastvwidget = InitMsg(form,lastvwidget);
X /* init the message area */
X
X i = 0;
X XtSetArg(args[i],XtNfromVert,lastvwidget);
X i++;
X cells = XtCreateManagedWidget("cell",formWidgetClass,form,args,i);
X lastvwidget = 0;
X
X for (y=0; y<numrows; y++) {
X lasthwidget = (Widget)0;
X for (x=0; x<numcols; x++) {
X sprintf(buf,"R%dC%d",y,x);
X i = 0;
X XtSetArg(args[i],XtNfromVert,lastvwidget);
X i++;
X XtSetArg(args[i],XtNfromHoriz,lasthwidget);
X i++;
X XtSetArg(args[i],XtNwidth,cellsize);
X i++;
X XtSetArg(args[i],XtNheight,cellsize);
X i++;
X XtSetArg(args[i],XtNinput,TRUE);
X i++;
X w = XtCreateManagedWidget(buf,widgetClass,cells,args,i);
X /* just use a core widget */
X sprintf(tbuf,"<Expose> : DrawCell(%d %d)",
X y,x);
X tr = XtParseTranslationTable(tbuf);
X XtOverrideTranslations(w,tr); /* add the expose tr */
X lasthwidget = w;
X SetCellWidget(y,x,w);
X }
X lastvwidget = w;
X }
X}
X
X/* end */
END_OF_makeform.c
if test 3274 -ne `wc -c <makeform.c`; then
echo shar: \"makeform.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f msg.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"msg.c\"
else
echo shar: Extracting \"msg.c\" \(4388 characters\)
sed "s/^X//" >msg.c <<'END_OF_msg.c'
X/*
X * Copyright 1990 Globetrotter Software, Inc.
X *
X * Permission to use, copy, modify, distribute, and sell this software and its
X * documentation for any purpose is hereby granted without fee, provided that
X * the above copyright notice appear in all copies and that both that
X * copyright notice and this permission notice appear in supporting
X * documentation, and that the name of Globetrotter Software not be used
X * in advertising or publicity pertaining to distribution of the software
X * without specific, written prior permission. Globetrotter Software makes
X * no representations about the suitability of this software for any purpose.
X * It is provided "as is" without express or implied warranty.
X *
X * GLOBETROTTER SOFTWARE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
X * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
X * EVENT SHALL GLOBETROTTER SOFTWARE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
X * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
X * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
X * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
X * OF THIS SOFTWARE.
X *
X * Author: Jim McBeath, Globetrotter Software
X * globes!jimmc at oliveb.olivetti.com
X * (408)741-0489
X */
X
X/* msg.c - deals with the message window
X */
X
X#include <X11/Intrinsic.h>
X#include <X11/StringDefs.h>
X#include <X11/Xaw/Form.h>
X#include <X11/Xaw/Label.h>
X#include "mines.h"
X
Xextern BOOL Impossible;
Xextern int Hints;
X
Xint NumberMoves;
Xint SafesMarked;
Xint MinesMarked;
Xint Hints;
X
Xstatic char *lastmessage;
Xstatic char *firstmessage="Welcome to XMines";
X
XWidget MsgWidget;
XWidget MoveCountWidget, HintCountWidget;
XWidget SafeCountWidget, MineCountWidget;
X
Xstatic Widget
XMakeCountWidget(name,parent,above,left)
Xchar *name;
XWidget parent;
XWidget above, left;
X{
X int i;
X Arg args[10];
X char namebuf[50];
X Widget lasthwidget;
X
X i = 0;
X XtSetArg(args[i],XtNfromVert,above);
X i++;
X if (left) {
X XtSetArg(args[i],XtNfromHoriz,left);
X i++;
X }
X sprintf(namebuf,"%slabel",name);
X lasthwidget = XtCreateManagedWidget(namebuf,
X labelWidgetClass, parent, args, i);
X
X i = 0;
X XtSetArg(args[i],XtNfromVert,above);
X i++;
X XtSetArg(args[i],XtNfromHoriz,lasthwidget);
X i++;
X sprintf(namebuf,"%scount",name);
X lasthwidget = XtCreateManagedWidget(namebuf,
X labelWidgetClass, parent, args, i);
X return lasthwidget;
X}
X
XWidget
XInitMsg(parent,above)
XWidget parent;
XWidget above;
X{
X int i;
X Arg args[10];
X Widget lasthwidget;
X
X lasthwidget = (Widget)0;
X
X#ifndef NOSCORE
X MoveCountWidget = lasthwidget =
X MakeCountWidget("move",parent,above,lasthwidget);
X HintCountWidget = lasthwidget =
X MakeCountWidget("hint",parent,above,lasthwidget);
X SafeCountWidget = lasthwidget =
X MakeCountWidget("safe",parent,above,lasthwidget);
X MineCountWidget = lasthwidget =
X MakeCountWidget("mine",parent,above,lasthwidget);
X above = lasthwidget;
X#endif
X
X i = 0;
X XtSetArg(args[i],XtNstring,firstmessage);
X i++;
X XtSetArg(args[i],XtNfromVert,above);
X i++;
X MsgWidget = XtCreateManagedWidget("message", labelWidgetClass,
X parent, args, i);
X if (lastmessage) {
X i=0;
X XtSetArg(args[0],XtNlabel,lastmessage);
X i++;
X XtSetValues(MsgWidget,args,1);
X }
X return MsgWidget;
X};
X
Xstatic void
XSetCountWidget(w,n)
XWidget w;
Xint n;
X{
X Arg arg;
X char buf[10];
X
X if (!w)
X return;
X sprintf(buf,"%d ",n);
X XtSetArg(arg,XtNlabel,buf);
X XtSetValues(w,&arg,1);
X}
X
X#ifndef NOSCORE
XSetNumberMoves(n)
Xint n;
X{
X NumberMoves = n;
X SetCountWidget(MoveCountWidget,n);
X}
X
XSetMinesMarked(n)
Xint n;
X{
X MinesMarked = n;
X SetCountWidget(MineCountWidget,n);
X}
X
XSetSafesMarked(n)
Xint n;
X{
X SafesMarked = n;
X SetCountWidget(SafeCountWidget,n);
X}
X
XSetHints(n)
Xint n;
X{
X Hints = n;
X SetCountWidget(HintCountWidget,n);
X}
X
XIncrNumberMoves(n)
Xint n;
X{
X if (n==0) return;
X SetNumberMoves(NumberMoves+n);
X}
X
XIncrMinesMarked(n)
Xint n;
X{
X if (n==0) return;
X SetMinesMarked(MinesMarked+n);
X}
X
XIncrSafesMarked(n)
Xint n;
X{
X if (n==0) return;
X SetSafesMarked(SafesMarked+n);
X}
X
XIncrHints(n)
Xint n;
X{
X if (n==0) return;
X SetHints(Hints+n);
X}
X#endif NOSCORE
X
Xvoid
XMessage(cp)
Xchar * cp;
X{
X Arg arg;
X static char full_message[100];
X
X sprintf(full_message, "%s %s",
X cp,
X Impossible ? "(impossible)" : "");
X
X lastmessage = full_message;
X if (MsgWidget) {
X XtSetArg(arg,XtNlabel,full_message);
X XtSetValues(MsgWidget,&arg,1);
X }
X}
X
X/* end */
END_OF_msg.c
if test 4388 -ne `wc -c <msg.c`; then
echo shar: \"msg.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 2 \(of 3\).
cp /dev/null ark2isdone
MISSING=""
for I in 1 2 3 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 3 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
dan
----------------------------------------------------
O'Reilly && Associates argv at sun.com / argv at ora.com
Opinions expressed reflect those of the author only.
More information about the Comp.sources.x
mailing list