/* * CS 453 - Final project : An OpenGL version of the pegboard game IQ * Due : June 5, 1997 * Author : Kiri Wagstaff * * File : game.c * Description : All the routines to actually play the game. * */ #include "gliq.h" int playdone=0; void playgame(void); void drawquit(float x, float y, float r1, float r2); int legalmove(void); int canmove(int peg); int movesexist(void); void playgame(void) { int height = glutGet(GLUT_WINDOW_HEIGHT); int width = glutGet(GLUT_WINDOW_WIDTH); /* Draw the quit button */ drawquit(7.0, 9.0, 0.4, 1.0); /* Quit */ #if 0 // glColor3f(1.0, 1.0, 1.0); /* white */ // text(0.78*width, 0.88*height, 0.1*height, "Quit"); #endif /* Draw the current scores */ /* Draw the total # of pegs */ glPushMatrix(); glColor3f(1.0, 1.0, 0.0); /* yellow */ glTranslatef(-7.8, 8.8, 0.0); drawpeg(); text(0.1*width, 0.9*height, 0.07*height, ": %02d", pegs); glPopMatrix(); if (playdone) text(0.2*glutGet(GLUT_WINDOW_WIDTH), 0.75*glutGet(GLUT_WINDOW_HEIGHT), 0.08*glutGet(GLUT_WINDOW_HEIGHT), "No moves left."); /* do the trackball rotation. */ glPushMatrix(); glRotatef(45.0, 1.0, 0.0, 0.0); tbMatrix(); drawboard(); drawpegs(); glPopMatrix(); } int canmove(int peg) { int i, j; if (peg == 0) return 0; i = (peg-1)/BOARDSIZE; j = (peg-1)%BOARDSIZE; if ((i-2>0) && (filled[i-1][j]==FULL) && (filled[i-2][j]==EMPTY)) return 1; else if ((i+20) && (filled[i][j-1]==FULL) && (filled[i][j-2]==EMPTY)) return 1; else if ((j+2