void WriteScoreString(RatIndexType rat) { char buf[64]; int leftEdge; sprintf(buf, "%d", (unsigned int) GetRatScore(rat).value()); XClearArea(dpy, mwWindow, SCORE_X_ORIGIN, SCORE_Y_ORIGIN + rat.value() * (scoreFontInfo->max_bounds.ascent + scoreFontInfo->max_bounds.descent), SCORE_X_DIM, (scoreFontInfo->max_bounds.ascent + scoreFontInfo->max_bounds.descent), FALSE); XDrawImageString(dpy, mwWindow, copyGC, SCORE_X_ORIGIN, SCORE_Y_ORIGIN + rat.value() * (scoreFontInfo->max_bounds.ascent + scoreFontInfo->max_bounds.descent) + scoreFontInfo->max_bounds.ascent, GetRatName(rat), strlen(GetRatName(rat))); leftEdge = SCORE_X_DIM - XTextWidth(scoreFontInfo, buf, strlen(buf)); XDrawImageString(dpy, mwWindow, copyGC, leftEdge+SCORE_X_ORIGIN, SCORE_Y_ORIGIN + rat.value() * (scoreFontInfo->max_bounds.ascent + scoreFontInfo->max_bounds.descent) + scoreFontInfo->max_bounds.ascent, buf, strlen(buf)); }
void NewScoreCard() { register RatIndexType ratIndex(0); for( ratIndex = 0; ratIndex < MAX_RATS; ratIndex = RatIndexType(ratIndex.value() +1)) UpdateScoreCard(ratIndex); }
/* ----------------------------------------------------------------------- */ void UpdateScoreCard(RatIndexType ratIndex) { ClearScoreLine(ratIndex); if (M->mazeRats_[ratIndex.value()].playing) WriteScoreString(ratIndex); if (Rats2Display[ratIndex.value()].visible == TRUE) InvertScoreLine(ratIndex); }
/* * draw him into the maze, with the right size for his distance away * and facing the right way. */ static void XORToken(RatIndexType hisRatIndex) { int size; int srcX, srcY; getRat(hisRatIndex, &srcX, &srcY, &size); DisplayRatBitmap(Rats2Display[hisRatIndex.value()].x.value() - size/2, Rats2Display[hisRatIndex.value()].y.value() - size/2, size, size, srcX, srcY); }
/* This is just for the sample version, rewrite your own */ Score GetRatScore(RatIndexType ratId) { if (ratId.value() == 0 ) { return(M->score()); } else { if(rat_array[(ratId.value())]==NULL) return 0; else return rat_array[ratId.value()]->score; } }
static short RandomEvent(void) { bool visible = FALSE; register RatIndexType ratIndex(0); int choice; choice = random() % 4; if ((choice == 0) || M->peeking()) { for (ratIndex = RatIndexType(0); ratIndex.value() < MAX_RATS; ratIndex = RatIndexType(ratIndex.value() + 1)) { if ((ratIndex != MY_RAT_INDEX) && (Rats2Display[ratIndex.value()].visible == TRUE)) { visible = TRUE; break; } } } if (TheNextEvent > 0) { TheNextEvent = -TheNextEvent; return (EVENT_D); } else if (TheNextEvent < 0) { M->dirIs(Direction(-TheNextEvent)); TheNextEvent = 0; return (EVENT_MIDDLE_D); } else if ((M->peeking()) && (visible == TRUE)) { /* Cheat */ TheNextEvent = M->dirPeek().value(); return (EVENT_LEFT_U); } else if ((M->peeking()) && (choice != 2)) { return (EVENT_LEFT_U); } else if (visible == TRUE) { return (EVENT_MIDDLE_D); } else if (emptyAhead() && choice != 2) { return (EVENT_D); } else if (emptyRight()) { return (EVENT_F); } else if (emptyLeft()) { return (EVENT_S); } else if ((choice != 2) && (emptyBehind())) { return (EVENT_A); } else { return (4 + (random() % 4)); } /* Never about face unless blocked */ }
/* * Clear out the score line for a player that's left the game. */ void ClearScoreLine(RatIndexType rat) { XClearArea(dpy, mwWindow, SCORE_X_ORIGIN, SCORE_Y_ORIGIN + rat.value() * (scoreFontInfo->max_bounds.ascent + scoreFontInfo->max_bounds.descent), SCORE_X_DIM, scoreFontInfo->max_bounds.ascent + scoreFontInfo->max_bounds.descent, False); }
/* * Pretty obvious, eh? Means the guy's in sight. */ void InvertScoreLine(RatIndexType rat) { XFillRectangle(dpy, mwWindow, xorGC, SCORE_X_ORIGIN, SCORE_Y_ORIGIN + rat.value() * (scoreFontInfo->max_bounds.ascent + scoreFontInfo->max_bounds.descent), SCORE_X_DIM, scoreFontInfo->max_bounds.ascent + scoreFontInfo->max_bounds.descent); }
/* * When someone moves off a position, clear it out. If there's someone * "under" him, display the second guy. */ void clearPosition(RatIndexType ratIndex, Loc xClear, Loc yClear) { Rat rp; register int i; clearSquare(xClear, yClear); for (i = 0; i < MAX_RATS; i++) { rp = M->rat(i); if ((i == ratIndex.value()) || !(rp.playing)) continue; if ((rp.x == xClear) && (rp.y == yClear)) if (i == MY_RAT_INDEX) showMe(rp.x, rp.y, rp.dir); } }
/* * sets Rats2Display[hisRatIndex] variables */ static void TokenVisible(RatIndexType hisRatIndex) { RatLook ratLook = &Rats2Display[hisRatIndex.value()]; Rat rat = M->rat(hisRatIndex); Loc tx(0), ty(0); Direction td(0); int ix, ix12; ratLook->visible = FALSE; if (!rat.playing) return; if (M->peeking()) { tx = M->xPeek(); ty = M->yPeek(); td = M->dirPeek(); } else { tx = MY_X_LOC; ty = MY_Y_LOC; td = MY_DIR; } ix = 0; while (!M->maze_[tx.value()][ty.value()]) { switch(td.value()) { case NORTH: tx = Loc(tx.value()+1); break; case SOUTH: tx = Loc(tx.value()-1); break; case EAST: ty = Loc(ty.value()+1); break; case WEST: ty = Loc(ty.value()-1); break; } ix++; if ((tx == rat.x) && (ty == rat.y)) { ratLook->visible = TRUE; ix12 = ix * 12; ratLook->x = (viewTable[ix12+3].p2.x + viewTable[ix12+10].p1.x)/2; ratLook->y = (viewTable[ix12+3].p1.y + viewTable[ix12+3].p2.y)/2; ratLook->tokenId = relativeTokens[td.value()][rat.dir.value()]; ratLook->distance = ix; break; } } }
/* This is just for the sample version, rewrite your own */ Score GetRatScore(RatIndexType ratId) { if (ratId.value() == M->myRatId().value()) { return(M->score()); } else { return (0); } }
/* * Dig the appropriate bitmap out of the master bitmap, which has all * possible views neatly packed into place. */ static void getRat(RatIndexType hisRatIndex, int *x, int *y, int *size) { int viewT = LEFT; int view = Rats2Display[hisRatIndex.value()].tokenId.value(); switch (Rats2Display[hisRatIndex.value()].distance) { case 1: *size = 64; *x = 0; *y = 0; for (viewT = 0; viewT != view; *x += 64) viewT++; return; case 2: *size = 32; for (*x = 4*64; *x != 64*5; *x += 32) for (*y = 0; *y != 64; *y += 32) if (viewT == view) return; else viewT++; case 3: *size = 24; for (*x = 5*64; *x != 64*5+48; *x += 24) for (*y = 0; *y != 48; *y += 24) if (viewT == view) return; else viewT++; case 4: case 5: *size = 16; *x = 64*5+48; for (*y = 0; *y != 64; *y += 16) if (viewT == view) return; else viewT++; case 6: case 7: case 8: *size = 9; *y = 48; for (*x = 64*5; *x != 64*5 + 4*9; *x += 9) if (viewT == view) return; else viewT++; case 9: case 10: case 11: case 12: *size = 6; *y = 48+9; for (*x = 64*5; *x != 64*5 + 4*6; *x += 6) if (viewT == view) return; else viewT++; case 13: case 14: case 15: case 16: case 17: case 18: *size = 4; *y = 48+9+3; for (*x = 64*5 + 4*6; *x != 64*5 +4*6 + 4*4; *x += 4) if (viewT == view) return; else viewT++; default: *size = 3; *y = 48+9; for (*x = 64*5 + 4*6; *x != 64*5 + 4*6 + 4*3; *x += 3) if (viewT == view) return; else viewT++; } }