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: v13i071: ishido - Unix/X11 solitare game, Part02/02
- Message-ID: <2644@master.CNA.TEK.COM>
- Date: 23 Mar 92 21:18:40 GMT
- Sender: news@master.CNA.TEK.COM
- Lines: 1034
- Approved: billr@saab.CNA.TEK.COM
-
- Submitted-by: jjs40@cd.amdahl.COM (John Sullivan)
- Posting-number: Volume 13, Issue 71
- Archive-name: ishido/Part02
- Environment: Unix, X11
-
-
- #! /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 2 (of 2)."
- # Contents: ./ishido.c
- # Wrapped by jjs40@anubis on Fri Feb 21 16:26:44 1992
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f './ishido.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'./ishido.c'\"
- else
- echo shar: Extracting \"'./ishido.c'\" \(23630 characters\)
- sed "s/^X//" >'./ishido.c' <<'END_OF_FILE'
- X/*
- X * ishido.c - Ancient stone matching game.
- X *
- X * Authors: John Sullivan, Amdahl Corporation (jjs40@cd.amdahl.com)
- X * Sean Cummins, Amdahl Corporation (spc10@cd.amdahl.com)
- X *
- X * "No matter how great your achievements or how stunning your defeats, over a
- X * billion Chinese couldn't care less."
- X *
- X */
- X
- X/****************************************************************************/
- X
- X#include <stdio.h>
- X#include <pwd.h>
- X#include "gl.h"
- X
- X/****************************************************************************/
- X
- X#include "bitmap/hwood.bm"
- X#include "bitmap/vwood.bm"
- X#include "bitmap/atom.bm"
- X#include "bitmap/dollar.bm"
- X#include "bitmap/hammer.bm"
- X#include "bitmap/maple.bm"
- X#include "bitmap/smile.bm"
- X#include "bitmap/star.bm"
- X
- X/****************************************************************************/
- X
- X#define TILE_WIDTH 50
- X#define TILE_HEIGHT 50
- X#define BOARD_WIDTH 12
- X#define BOARD_HEIGHT 8
- X#define MARGIN_X 10
- X#define MARGIN_Y 10
- X
- X/****************************************************************************/
- X
- X#define BOARD_X MARGIN_X
- X#define BOARD_Y MARGIN_Y
- X#define BOARD_W (TILE_WIDTH*BOARD_WIDTH)
- X#define BOARD_H (TILE_HEIGHT*BOARD_HEIGHT)
- X#define TILE_X(x) (BOARD_X+TILE_WIDTH*(x))
- X#define TILE_Y(y) (BOARD_Y+TILE_HEIGHT*(y))
- X#define SCORE_X MARGIN_X*2+BOARD_W
- X#define SCORE_Y BOARD_Y
- X#define SCORE_W 20*GL_FONT_WIDTH
- X#define SCREEN_W MARGIN_X*3+BOARD_W+SCORE_W
- X#define SCREEN_H MARGIN_Y*2+BOARD_H
- X#define QUITB_H 25
- X#define QUITB_W SCORE_W
- X#define QUITB_X SCORE_X
- X#define QUITB_Y SCREEN_H-MARGIN_Y-QUITB_H-1
- X
- X#define RULEB_H 25
- X#define RULEB_W SCORE_W
- X#define RULEB_X SCORE_X
- X#define RULEB_Y QUITB_Y-MARGIN_Y-GAMEB_H
- X
- X#define GAMEB_H 25
- X#define GAMEB_W SCORE_W
- X#define GAMEB_X SCORE_X
- X#define GAMEB_Y RULEB_Y-MARGIN_Y-GAMEB_H
- X#define SCORE_H GAMEB_Y-MARGIN_Y-SCORE_Y
- X
- X/****************************************************************************/
- X
- X#define IS_INTERIOR(x,y) ((x > 0) && (x < BOARD_WIDTH-1) && \
- X (y > 0) && (y < BOARD_HEIGHT-1))
- X
- X/****************************************************************************/
- X
- X#define TILE_SHAPES 6
- X#define DECK_SIZE TILE_SHAPES*TILE_SHAPES*2
- X
- X#define TILE_EMPTY -1
- Xtypedef int TILE;
- X
- X#define TILE_COLOR(x) ((x)%TILE_SHAPES)
- X#define TILE_SHAPE(x) ((x)/TILE_SHAPES)
- X
- X/****************************************************************************/
- X
- X#ifndef HIGH_SCORE_FILE
- X#define HIGH_SCORE_FILE "ishido_scores"
- X#endif
- X
- X#define NUM_HIGH_SCORES 20
- X
- Xtypedef struct HIGH_SCORE_STRUCT {
- X char name[12];
- X int score;
- X int fourways;
- X int tiles;
- X} HIGH_SCORE;
- X
- X/****************************************************************************/
- X
- Xextern void quit_button();
- Xextern void new_game_button();
- Xextern void end_game_button();
- Xextern void rule_button();
- X
- X/****************************************************************************/
- X
- X#define streq(a,b) (strcmp(a,b)==0)
- X
- X/****************************************************************************/
- X
- XGL_PIXEL pix_bg;
- XGL_PIXEL pix_border;
- XGL_PIXEL pix_text;
- XGL_PIXEL pix_wood_fg[2];
- XGL_PIXEL pix_wood_bg[2];
- XGL_PIXEL pix_tile_bg[TILE_SHAPES];
- XGL_PIXEL pix_tile_fg;
- XGL_PIXEL pix_highlight;
- X
- XGL_BITMAP bitmap_wood[2];
- XGL_BITMAP bitmap_tile[TILE_SHAPES];
- X
- XGB_BUTTON button[3];
- X
- X/****************************************************************************/
- X
- XHIGH_SCORE high_score[NUM_HIGH_SCORES];
- X
- Xint game_over;
- Xint rule_screen;
- X
- XTILE board[BOARD_WIDTH][BOARD_HEIGHT];
- X
- Xint num_deck_tiles;
- XTILE deck[DECK_SIZE];
- X
- Xint score;
- Xint fourways;
- Xint bonehead;
- Xint silent;
- X
- Xint num_possible;
- Xint possible_x[BOARD_WIDTH*BOARD_HEIGHT];
- Xint possible_y[BOARD_WIDTH*BOARD_HEIGHT];
- X
- X/****************************************************************************/
- X
- Xint
- Xint_rand(m)
- X int m;
- X{
- X int v;
- X
- X v = (lrand48() % m);
- X return (v);
- X};
- X
- X/****************************************************************************/
- X
- Xvoid
- Xseed_rand()
- X{
- X srand48(time(NULL));
- X};
- X
- X/****************************************************************************/
- X
- Xchar *
- Xget_user_name()
- X{
- X int uid;
- X struct passwd *passwd;
- X
- X uid = geteuid();
- X passwd = getpwuid(uid);
- X return (passwd->pw_name);
- X};
- X
- X/****************************************************************************/
- X
- Xvoid
- Xdeck_init()
- X{
- X int i, j, n, c;
- X TILE tile;
- X
- X num_deck_tiles = DECK_SIZE;
- X for (i = 0; i < DECK_SIZE; i++) {
- X deck[i] = i / 2;
- X };
- X for (i = 0; i < DECK_SIZE - 1; i++) {
- X n = int_rand(DECK_SIZE - i - 1);
- X tile = deck[i + n + 1];
- X deck[i + n + 1] = deck[i];
- X deck[i] = tile;
- X };
- X i = 0;
- X c = 0;
- X while (c < TILE_SHAPES) {
- X n = 0;
- X for (j = 0; j < c; j++) {
- X if (TILE_COLOR(deck[i]) == TILE_COLOR(deck[j])) {
- X n++;
- X };
- X if (TILE_SHAPE(deck[i]) == TILE_SHAPE(deck[j])) {
- X n++;
- X };
- X };
- X if (n == 0) {
- X tile = deck[c];
- X deck[c] = deck[i];
- X deck[i] = tile;
- X c++;
- X };
- X i++;
- X };
- X};
- X
- X/****************************************************************************/
- X
- Xvoid
- Xdeck_print()
- X{
- X int i, c;
- X
- X printf("num_deck_tiles = %d:\n", num_deck_tiles);
- X
- X c = 0;
- X for (i = 0; i < num_deck_tiles; i++) {
- X printf("%4d ", deck[i]);
- X c++;
- X if (c == 14) {
- X printf("\n");
- X c = 0;
- X };
- X };
- X printf("\n");
- X};
- X
- X/****************************************************************************/
- X
- XTILE
- Xdeck_take_tile()
- X{
- X int i;
- X TILE tile;
- X
- X tile = deck[0];
- X
- X for (i = 0; i < num_deck_tiles - 1; i++) {
- X deck[i] = deck[i + 1];
- X };
- X num_deck_tiles = num_deck_tiles - 1;
- X return (tile);
- X};
- X
- X/****************************************************************************/
- X
- Xvoid
- Xboard_init()
- X{
- X int i, j;
- X
- X for (j = 0; j < BOARD_HEIGHT; j++) {
- X for (i = 0; i < BOARD_WIDTH; i++) {
- X board[i][j] = TILE_EMPTY;
- X };
- X };
- X board[0][0] = deck_take_tile();
- X board[0][7] = deck_take_tile();
- X board[11][0] = deck_take_tile();
- X board[11][7] = deck_take_tile();
- X board[5][3] = deck_take_tile();
- X board[6][4] = deck_take_tile();
- X};
- X
- X/****************************************************************************/
- X
- XTILE
- Xboard_get_tile(x, y)
- X int x, y;
- X{
- X if ((x < 0) || (x >= BOARD_WIDTH)) {
- X return (TILE_EMPTY);
- X };
- X if ((y < 0) || (y >= BOARD_HEIGHT)) {
- X return (TILE_EMPTY);
- X };
- X return (board[x][y]);
- X};
- X
- X/****************************************************************************/
- X
- Xint
- Xboard_adjacent_tiles(tile, x, y, c, s)
- X TILE tile;
- X int x, y;
- X int *c;
- X int *s;
- X{
- X int i;
- X int num;
- X TILE adjtile[4];
- X
- X adjtile[0] = board_get_tile(x - 1, y);
- X adjtile[1] = board_get_tile(x + 1, y);
- X adjtile[2] = board_get_tile(x, y - 1);
- X adjtile[3] = board_get_tile(x, y + 1);
- X num = 0;
- X for (i = 0; i < 4; i++) {
- X if (adjtile[i] != TILE_EMPTY) {
- X c[num] = (TILE_COLOR(tile) == TILE_COLOR(adjtile[i]));
- X s[num] = (TILE_SHAPE(tile) == TILE_SHAPE(adjtile[i]));
- X num++;
- X };
- X };
- X return (num);
- X};
- X
- X/****************************************************************************/
- X
- Xint
- Xboard_can_place_tile(x, y)
- X int x, y;
- X{
- X int num;
- X TILE tile;
- X int c[4], s[4];
- X
- X if (board[x][y] != TILE_EMPTY) {
- X return (0);
- X };
- X tile = deck[0];
- X num = board_adjacent_tiles(tile, x, y, c, s);
- X if (num == 1) {
- X if (s[0] || c[0])
- X return (num);
- X };
- X if (num == 2) {
- X if (s[0] && c[1])
- X return (num);
- X if (s[1] && c[0])
- X return (num);
- X };
- X if (num == 3) {
- X if (s[0] && c[1] && c[2])
- X return (num);
- X if (s[1] && c[2] && c[0])
- X return (num);
- X if (s[2] && c[0] && c[1])
- X return (num);
- X if (c[0] && s[1] && s[2])
- X return (num);
- X if (c[1] && s[2] && s[0])
- X return (num);
- X if (c[2] && s[0] && s[1])
- X return (num);
- X };
- X if (num == 4) {
- X if (s[0] && s[1] && c[2] && c[3])
- X return (num);
- X if (s[0] && s[2] && c[1] && c[3])
- X return (num);
- X if (s[0] && s[3] && c[1] && c[2])
- X return (num);
- X if (s[1] && s[2] && c[0] && c[3])
- X return (num);
- X if (s[1] && s[3] && c[0] && c[2])
- X return (num);
- X if (s[2] && s[3] && c[0] && c[1])
- X return (num);
- X };
- X return (0);
- X};
- X
- X/****************************************************************************/
- X
- Xvoid board_update_possible_moves()
- X{
- X int i,j;
- X int c;
- X
- X num_possible = 0;
- X if (num_deck_tiles == 0) {
- X return;
- X };
- X for (j = 0; j < BOARD_HEIGHT; j++) {
- X for (i = 0; i < BOARD_WIDTH; i++) {
- X if (board_can_place_tile(i,j)) {
- X possible_x[num_possible] = i;
- X possible_y[num_possible] = j;
- X num_possible++;
- X };
- X };
- X };
- X};
- X
- X/****************************************************************************/
- X
- Xint four_way_bonus[] = {
- X 25, 50, 100, 200, 400, 600, 800, 1000, 5000, 10000, 25000, 50000
- X};
- X
- X/****************************************************************************/
- X
- Xint
- Xboard_place_tile(x, y)
- X int x, y;
- X{
- X int num;
- X
- X if (num_deck_tiles == 0) {
- X return (0);
- X };
- X num = board_can_place_tile(x, y);
- X if (num == 0) {
- X return (0);
- X };
- X board[x][y] = deck_take_tile();
- X if (IS_INTERIOR(x, y)) {
- X if (num == 1)
- X score = score + 1;
- X if (num == 2)
- X score = score + 2;
- X if (num == 3)
- X score = score + 4;
- X if (num == 4) {
- X score = score + 8;
- X if (fourways < 12) {
- X score = score + four_way_bonus[fourways];
- X } else {
- X score = score + four_way_bonus[11];
- X };
- X fourways++;
- X };
- X };
- X return (1);
- X};
- X
- X/****************************************************************************/
- X
- Xvoid
- Xhigh_score_load()
- X{
- X FILE *f;
- X int i;
- X
- X f = fopen(HIGH_SCORE_FILE, "r");
- X if (f != NULL) {
- X fread(high_score, sizeof(HIGH_SCORE), NUM_HIGH_SCORES, f);
- X } else {
- X for (i = 0; i < NUM_HIGH_SCORES; i++) {
- X strcpy(high_score[i].name, "nobody");
- X high_score[i].score = 0;
- X high_score[i].fourways = 0;
- X high_score[i].tiles = 66;
- X };
- X };
- X fclose(f);
- X};
- X
- X/****************************************************************************/
- X
- Xvoid
- Xhigh_score_save()
- X{
- X FILE *f;
- X
- X f = fopen(HIGH_SCORE_FILE, "w");
- X if (f != NULL) {
- X fwrite(high_score, sizeof(HIGH_SCORE), NUM_HIGH_SCORES, f);
- X };
- X fclose(f);
- X};
- X
- X/****************************************************************************/
- X
- Xvoid
- Xhigh_score_add(name, sc, fw, ti)
- X char *name;
- X int sc;
- X int fw;
- X int ti;
- X{
- X int i;
- X int pos;
- X
- X high_score_load();
- X pos = NUM_HIGH_SCORES;
- X for (i = NUM_HIGH_SCORES - 1; i >= 0; i--) {
- X if (sc >= high_score[i].score) {
- X pos = i;
- X };
- X };
- X if (pos < NUM_HIGH_SCORES) {
- X for (i = NUM_HIGH_SCORES - 1; i > pos; i--) {
- X strcpy(high_score[i].name, high_score[i - 1].name);
- X high_score[i].score = high_score[i - 1].score;
- X high_score[i].fourways = high_score[i - 1].fourways;
- X high_score[i].tiles = high_score[i - 1].tiles;
- X };
- X strcpy(high_score[pos].name, name);
- X high_score[pos].score = sc;
- X high_score[pos].fourways = fw;
- X high_score[pos].tiles = ti;
- X high_score_save();
- X };
- X};
- X
- X/****************************************************************************/
- X
- Xvoid
- Xinit_game_play()
- X{
- X strcpy(button[0].label, "End Game");
- X button[0].event_fn = end_game_button;
- X
- X game_over = 0;
- X rule_screen = 0;
- X
- X seed_rand();
- X deck_init();
- X board_init();
- X board_update_possible_moves();
- X
- X score = 0;
- X fourways = 0;
- X};
- X
- X/****************************************************************************/
- X
- Xvoid
- Xinit_game_over()
- X{
- X strcpy(button[0].label, "New Game");
- X button[0].event_fn = new_game_button;
- X
- X high_score_load();
- X
- X game_over = 1;
- X rule_screen = 0;
- X};
- X
- X/****************************************************************************/
- X
- Xvoid
- Xinit_game_end()
- X{
- X char *name;
- X
- X if (num_deck_tiles == 0)
- X score = score + 1000;
- X if (num_deck_tiles == 1)
- X score = score + 500;
- X if (num_deck_tiles == 2)
- X score = score + 100;
- X name = get_user_name();
- X high_score_add(name, score, fourways, num_deck_tiles);
- X};
- X
- X/****************************************************************************/
- X
- Xvoid
- Xinit_game(argc, argv)
- X int argc;
- X char **argv;
- X{
- X int i;
- X int help;
- X
- X pix_bg = gl_alloc_color("black");
- X pix_border = gl_alloc_color("red");
- X pix_text = gl_alloc_color("white");
- X pix_wood_fg[0] = gl_alloc_color("tan4");
- X pix_wood_fg[1] = gl_alloc_color("tan3");
- X pix_wood_bg[0] = gl_alloc_color("sienna4");
- X pix_wood_bg[1] = gl_alloc_color("sienna3");
- X pix_tile_fg = gl_alloc_color("black");
- X pix_tile_bg[0] = gl_alloc_color("red");
- X pix_tile_bg[1] = gl_alloc_color("green");
- X pix_tile_bg[2] = gl_alloc_color("skyblue1");
- X pix_tile_bg[3] = gl_alloc_color("yellow");
- X pix_tile_bg[4] = gl_alloc_color("mediumpurple1");
- X pix_tile_bg[5] = gl_alloc_color("pink");
- X pix_highlight = gl_alloc_color("magenta");
- X
- X bitmap_wood[0] = gl_load_bitmap(hwood_bits, hwood_width, hwood_height);
- X bitmap_wood[1] = gl_load_bitmap(vwood_bits, vwood_width, vwood_height);
- X
- X bitmap_tile[0] = gl_load_bitmap(atom_bits, atom_width, atom_height);
- X bitmap_tile[1] = gl_load_bitmap(dollar_bits, dollar_width, dollar_height);
- X bitmap_tile[2] = gl_load_bitmap(hammer_bits, hammer_width, hammer_height);
- X bitmap_tile[3] = gl_load_bitmap(maple_bits, maple_width, maple_height);
- X bitmap_tile[4] = gl_load_bitmap(smile_bits, smile_width, smile_height);
- X bitmap_tile[5] = gl_load_bitmap(star_bits, star_width, star_height);
- X
- X button[0].x = GAMEB_X;
- X button[0].y = GAMEB_Y;
- X button[0].w = GAMEB_W;
- X button[0].h = GAMEB_H;
- X button[0].border = pix_border;
- X button[0].background = pix_bg;
- X button[0].text = pix_text;
- X
- X button[1].x = RULEB_X;
- X button[1].y = RULEB_Y;
- X button[1].w = RULEB_W;
- X button[1].h = RULEB_H;
- X button[1].border = pix_border;
- X button[1].background = pix_bg;
- X button[1].text = pix_text;
- X strcpy(button[1].label, "Rules");
- X button[1].event_fn = rule_button;
- X
- X button[2].x = QUITB_X;
- X button[2].y = QUITB_Y;
- X button[2].w = QUITB_W;
- X button[2].h = QUITB_H;
- X button[2].border = pix_border;
- X button[2].background = pix_bg;
- X button[2].text = pix_text;
- X strcpy(button[2].label, "Quit");
- X button[2].event_fn = quit_button;
- X
- X num_possible = 0;
- X
- X bonehead = 0;
- X silent = 0;
- X help = 0;
- X
- X for (i = 1; i < argc; i++) {
- X if (streq(argv[i],"-bonehead")) {
- X bonehead = 1;
- X } else if (streq(argv[i],"-silent")) {
- X silent = 1;
- X } else if (streq(argv[i],"-h")) {
- X help = 1;
- X } else {
- X help = 1;
- X };
- X };
- X
- X if (help) {
- X printf("usage: ishido [-bonehead] [-silent]\n");
- X printf(" -bonehead Shows possible moves.\n");
- X printf(" -silent Turns off bell.\n");
- X printf(" -h This message.\n");
- X gl_exit();
- X };
- X
- X init_game_play();
- X init_game_over();
- X};
- X
- X/****************************************************************************/
- X
- Xvoid
- Xdraw_tile(x, y, tile)
- X int x, y;
- X TILE tile;
- X{
- X
- X gl_set_fg(pix_tile_fg);
- X gl_set_bg(pix_tile_bg[TILE_COLOR(tile)]);
- X gl_draw_bitmap(bitmap_tile[TILE_SHAPE(tile)], x, y,
- X TILE_WIDTH, TILE_HEIGHT);
- X};
- X
- X/****************************************************************************/
- X
- Xvoid
- Xdraw_board_tile(x, y)
- X int x, y;
- X{
- X TILE tile;
- X
- X tile = board[x][y];
- X if (tile == TILE_EMPTY) {
- X gl_set_fg_bg(pix_wood_fg[IS_INTERIOR(x, y)],
- X pix_wood_bg[IS_INTERIOR(x, y)]);
- X gl_draw_bitmap(bitmap_wood[(x + y) % 2],
- X TILE_X(x), TILE_Y(y),
- X TILE_WIDTH, TILE_HEIGHT);
- X } else {
- X draw_tile(TILE_X(x), TILE_Y(y), tile);
- X };
- X};
- X
- X/****************************************************************************/
- X
- Xvoid
- Xdraw_board_highlight_tile(x, y)
- X int x, y;
- X{
- X gl_set_fg_bg(pix_highlight,
- X pix_wood_bg[IS_INTERIOR(x, y)]);
- X gl_draw_bitmap(bitmap_wood[(x + y) % 2],
- X TILE_X(x), TILE_Y(y),
- X TILE_WIDTH, TILE_HEIGHT);
- X};
- X
- X/****************************************************************************/
- X
- Xvoid draw_board_show_possible_moves()
- X{
- X int i;
- X
- X for (i = 0; i < num_possible; i++) {
- X draw_board_highlight_tile(possible_x[i],possible_y[i]);
- X };
- X};
- X
- X
- X/****************************************************************************/
- X
- Xvoid
- Xdraw_board_hide_possible_moves()
- X{
- X int i;
- X
- X for (i = 0; i < num_possible; i++) {
- X draw_board_tile(possible_x[i], possible_y[i]);
- X };
- X};
- X
- X/****************************************************************************/
- X
- Xvoid
- Xdraw_board()
- X{
- X int i, j;
- X
- X for (j = 0; j < BOARD_HEIGHT; j++) {
- X for (i = 0; i < BOARD_WIDTH; i++) {
- X draw_board_tile(i, j);
- X };
- X };
- X if (bonehead) {
- X draw_board_show_possible_moves();
- X };
- X};
- X
- X/****************************************************************************/
- X
- Xvoid
- Xdraw_score()
- X{
- X char buf[128];
- X
- X gl_set_fg_bg(pix_text, pix_bg);
- X gu_draw_centered_text(SCORE_X + SCORE_W / 2,
- X SCORE_Y + GL_FONT_HEIGHT * 1, "Ishido v1.0");
- X gu_draw_centered_text(SCORE_X + SCORE_W / 2,
- X SCORE_Y + GL_FONT_HEIGHT * 3, "Score");
- X sprintf(buf, "%06d", score);
- X gu_draw_centered_text(SCORE_X + SCORE_W / 2,
- X SCORE_Y + GL_FONT_HEIGHT * 4, buf);
- X gu_draw_centered_text(SCORE_X + SCORE_W / 2,
- X SCORE_Y + GL_FONT_HEIGHT * 5, "4-Way Matches");
- X sprintf(buf, "%d", fourways);
- X gu_draw_centered_text(SCORE_X + SCORE_W / 2,
- X SCORE_Y + GL_FONT_HEIGHT * 6, buf);
- X gu_draw_centered_text(SCORE_X + SCORE_W / 2,
- X SCORE_Y + GL_FONT_HEIGHT * 7, "Tiles Remaining");
- X sprintf(buf, "%02d", num_deck_tiles);
- X gu_draw_centered_text(SCORE_X + SCORE_W / 2,
- X SCORE_Y + GL_FONT_HEIGHT * 8, buf);
- X if ((game_over) || (num_deck_tiles == 0)) {
- X gu_draw_centered_text(SCORE_X + SCORE_W / 2,
- X SCORE_Y + GL_FONT_HEIGHT * 10, " ");
- X gu_draw_centered_text(SCORE_X + SCORE_W / 2,
- X SCORE_Y + GL_FONT_HEIGHT * 11, " ");
- X gu_draw_centered_text(SCORE_X + SCORE_W / 2,
- X SCORE_Y + GL_FONT_HEIGHT * 12, " ");
- X gl_set_fg_bg(pix_bg, pix_bg);
- X gl_fill_rect(SCORE_X + SCORE_W / 2 - TILE_WIDTH / 2,
- X SCORE_Y + GL_FONT_HEIGHT * 13, TILE_WIDTH, TILE_HEIGHT);
- X } else {
- X gu_draw_centered_text(SCORE_X + SCORE_W / 2,
- X SCORE_Y + GL_FONT_HEIGHT * 10, "Possible Moves");
- X if (bonehead) {
- X sprintf(buf, "%02d", num_possible);
- X } else {
- X if (num_possible > 0) {
- X sprintf(buf,"Yes");
- X } else {
- X sprintf(buf,"None ");
- X };
- X };
- X gu_draw_centered_text(SCORE_X + SCORE_W / 2,
- X SCORE_Y + GL_FONT_HEIGHT * 11, buf);
- X gu_draw_centered_text(SCORE_X + SCORE_W / 2,
- X SCORE_Y + GL_FONT_HEIGHT * 12, "Next Tile");
- X draw_tile(SCORE_X + SCORE_W / 2 - TILE_WIDTH / 2,
- X SCORE_Y + GL_FONT_HEIGHT * 13, deck[0]);
- X };
- X};
- X
- X/****************************************************************************/
- X
- Xint rule_lines = 21;
- Xchar *rule_text[] = {
- X "There are 72 tiles, two of each combination of six colors and six shapes.",
- X "At the start of the game, there are six tiles on the board representing",
- X "each shape and color. To place an additional tile on the board, you",
- X "must match at least one adjacent tile according to the following rules:",
- X " - To match a single tile, you must match either the color or shape.",
- X " - To match two tiles, you must match one shape and one color.",
- X " - To match three tiles, you must match two colors and one shape OR two",
- X " shapes and one color.",
- X " - To match four tiles, you must match two colors and two shapes.",
- X "",
- X "Tiles placed on the interior (lighter) squares score points when placed,",
- X "according to the number of adjacent tiles that they match.",
- X " - Matching one tile: 1 point. - Matching three tiles: 4 points.",
- X " - Matching two tiles: 2 points. - Matching four tiles: 8 points.",
- X "",
- X "In addition to the regular score there is an increasing bonus for each",
- X "four-way match starting with 25 points for the first and continuing with",
- X "50, 100, 200, 400, 600, 800, 1000, 5000, 10000, and 50000 points.",
- X "",
- X "A bonus of 1000 points is awarded at the end of the game placing for all",
- X "72 tiles. 500 and 100 points are awarded for one and two tiles remaining."
- X};
- X
- X/****************************************************************************/
- X
- Xvoid
- Xdraw_rule_screen()
- X{
- X int i;
- X
- X gl_set_fg(pix_bg);
- X gl_fill_rect(BOARD_X, BOARD_Y, BOARD_W, BOARD_H);
- X gl_set_fg_bg(pix_text, pix_bg);
- X gu_draw_centered_text(BOARD_X + BOARD_W / 2, BOARD_Y + GL_FONT_HEIGHT,
- X "Rules");
- X for (i = 0; i < rule_lines; i++) {
- X gl_draw_text(BOARD_X + GL_FONT_WIDTH,
- X BOARD_Y + GL_FONT_HEIGHT * (i + 2),
- X rule_text[i]);
- X };
- X};
- X
- X/****************************************************************************/
- X
- Xvoid
- Xdraw_high_scores()
- X{
- X int i;
- X char buf[200];
- X
- X gl_set_fg(pix_bg);
- X gl_fill_rect(BOARD_X, BOARD_Y, BOARD_W, BOARD_H);
- X gl_set_fg_bg(pix_text, pix_bg);
- X gu_draw_centered_text(BOARD_X + BOARD_W / 2, BOARD_Y + GL_FONT_HEIGHT * 1,
- X "-- Game Over --");
- X gu_draw_centered_text(BOARD_X + BOARD_W / 2, BOARD_Y + GL_FONT_HEIGHT * 2,
- X "## Name Score 4-Ways Tiles");
- X gu_draw_centered_text(BOARD_X + BOARD_W / 2, BOARD_Y + GL_FONT_HEIGHT * 3,
- X "--------------------------------------");
- X for (i = 0; i < NUM_HIGH_SCORES; i++) {
- X sprintf(buf, "%2d %-12s %5d %2d %2d ", i + 1,
- X high_score[i].name, high_score[i].score,
- X high_score[i].fourways, high_score[i].tiles);
- X gu_draw_centered_text(BOARD_X + BOARD_W / 2,
- X BOARD_Y + GL_FONT_HEIGHT * (i + 4), buf);
- X };
- X};
- X
- X/****************************************************************************/
- X
- Xvoid
- Xredraw()
- X{
- X gl_set_fg_bg(pix_border, pix_bg);
- X gu_draw_border(BOARD_X, BOARD_Y, BOARD_W, BOARD_H, 2);
- X gu_draw_border(SCORE_X, SCORE_Y, SCORE_W, SCORE_H, 2);
- X
- X gl_set_fg(pix_bg);
- X gl_fill_rect(SCORE_X, SCORE_Y, SCORE_W, SCORE_H);
- X draw_score();
- X
- X gb_draw_buttons(3, button);
- X
- X if (rule_screen) {
- X draw_rule_screen();
- X } else if (game_over) {
- X draw_high_scores();
- X } else {
- X draw_board();
- X };
- X};
- X
- X/****************************************************************************/
- X
- Xvoid
- Xquit_button()
- X{
- X if (!game_over) {
- X init_game_end();
- X };
- X gl_exit_main();
- X};
- X
- X/****************************************************************************/
- X
- Xvoid
- Xnew_game_button()
- X{
- X init_game_play();
- X redraw();
- X};
- X
- X/****************************************************************************/
- X
- Xvoid
- Xend_game_button()
- X{
- X init_game_end();
- X init_game_over();
- X redraw();
- X};
- X
- X/****************************************************************************/
- X
- Xvoid
- Xrule_button()
- X{
- X rule_screen = 1 - rule_screen;
- X redraw();
- X};
- X
- X/****************************************************************************/
- X
- Xvoid
- Xboard_button(event)
- X GL_EVENT *event;
- X{
- X int x, y;
- X
- X x = (event->x - BOARD_X) / TILE_WIDTH;
- X y = (event->y - BOARD_Y) / TILE_WIDTH;
- X if (board_place_tile(x, y)) {
- X if (bonehead) {
- X draw_board_hide_possible_moves();
- X };
- X board_update_possible_moves();
- X draw_board_tile(x, y);
- X if (bonehead) {
- X draw_board_show_possible_moves();
- X };
- X draw_score();
- X } else if (silent == 0) {
- X gl_ring_bell();
- X };
- X};
- X
- X/****************************************************************************/
- X
- Xvoid
- Xevent(event)
- X GL_EVENT *event;
- X{
- X if ((gb_button_event(event, 3, button) == GL_FALSE) && (!game_over)) {
- X if (gu_event_in_rect(event, BOARD_X, BOARD_Y, BOARD_W, BOARD_H)) {
- X board_button(event);
- X }
- X };
- X};
- X
- X/****************************************************************************/
- X
- Xmain(argc, argv)
- X int argc;
- X char **argv;
- X{
- X
- X
- X gl_init(argc, argv, SCREEN_W, SCREEN_H);
- X
- X gl_redraw_func(redraw);
- X gl_event_func(event);
- X
- X init_game(argc, argv);
- X
- X gl_start();
- X gl_main_loop();
- X gl_exit();
- X};
- END_OF_FILE
- if test 23630 -ne `wc -c <'./ishido.c'`; then
- echo shar: \"'./ishido.c'\" unpacked with wrong size!
- fi
- # end of './ishido.c'
- fi
- echo shar: End of archive 2 \(of 2\).
- cp /dev/null ark2isdone
- 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
-