-+-+-+-+-+-+-+-+ START OF PART 3 -+-+-+-+-+-+-+-+ X score_pad`5Bitems`5D.score = Score; X ++items; X qsort((char *)score_pad, items, sizeof(score_t), ScCmp); X if (items > HS_ENTRIES) X items = HS_ENTRIES; X if ((fp = fopen(HSFile, "r+")) == NULL) X `7B X ScDisplayErr(back_win, "Unable to write HS file."); X`09 fclose(fp); X return; X `7D X if (fwrite((char *)score_pad, sizeof(score_t), items, fp) == 0) X ScDisplayErr(back_win, "No HS entries written."); X fclose(fp); X `7D X`20 Xstatic int ScCmp(sc_rec1, sc_rec2) X`20 Xscore_t *sc_rec1, *sc_rec2; X`20 X `7B X if (sc_rec1->score < sc_rec2->score) X return 1; X if (sc_rec1->score > sc_rec2->score) X return -1; X return 0; X `7D X`20 Xvoid PressSpace(back_win, y, x, cur_win, sy, sx) X`20 XWINDOW *back_win, *cur_win; Xint y, x, sy, sx; X`20 X `7B X mvwaddstr(cur_win, sy, sx, "--press space--"); X wrefresh(cur_win); X while (wgetch(cur_win) != ' '); X delwin(cur_win); X wmove(back_win, y, x); X touchwin(back_win); X wrefresh(back_win); X `7D X`20 Xstatic void ScDisplayErr(back_win, str) X`20 XWINDOW *back_win; Xchar *str; X`20 X `7B X int old_y, old_x, win_len; X WINDOW *err_win; X`20 X getyx(back_win, old_y, old_x); X wmove(back_win, 0, 0); X wrefresh(back_win); X win_len = strlen(str) + 2; X err_win = newwin(3, win_len, LINES / 2 - 2, (COLS - win_len - 2) / 2) V; X box(err_win, 0, 0); X mvwaddstr(err_win, 1, 1, str); X wrefresh(err_win); X sleep(3); X delwin(err_win); X wmove(back_win, old_y, old_x); X touchwin(back_win); X wrefresh(back_win); X `7D X`20 Xvoid UpdateScore(screen) X`20 XWINDOW *screen; X`20 X `7B X int pad_i = 0, found = 0, fuel_bonus, diff_bonus; X char scr_buf`5B128`5D; X`20 X while (pad_i < SCR_X && ! found) X `7B X found = LastLegalX >= ScorePad`5Bpad_i`5D.start_x && X LastLegalX <= ScorePad`5Bpad_i`5D.end_x && X ScorePad`5Bpad_i`5D.y == LastLegalY; X ++pad_i; X `7D X --pad_i; X fuel_bonus = Fuel / 100.0 + 0.5; X sprintf(scr_buf, "Fuel bonus: %d", fuel_bonus); X mvwaddstr(screen, 3, 25, scr_buf); X wrefresh(screen); X diff_bonus = (Landings + 1) * 10; X sprintf(scr_buf, "Consecutive Landings Bonus: %d", diff_bonus); X mvwaddstr(screen, 4, 9, scr_buf); X wrefresh(screen); X Score += PadScore`5Bpad_i`5D + fuel_bonus + diff_bonus; X `7D X`20 Xvoid InitScore() X`20 X `7B X int i, j, pad_count = 0; X char *line; X`20 X for (i = 0; i < SCR_Y; ++i) X `7B X j = 0; X line = Template`5Bi`5D; X while (j < SCR_X) X `7B X if (line`5Bj`5D == PAD) X `7B X ScorePad`5Bpad_count`5D.y = i; X ScorePad`5Bpad_count`5D.start_x = j; X while (j < SCR_X && line`5Bj`5D == PAD) X ++j; X if (j >= SCR_X) X --j; X ScorePad`5Bpad_count`5D.end_x = j; X ++pad_count; X `7D X ++j; X `7D X `7D X TotalPads = pad_count; X `7D $ CALL UNPACK SCORE.C;1 2030107366 $ create 'f' X#include X#ifdef VMS X#include X#else X#include X#endif X#include X#include X#include "consts.h" X#include "funcs.h" X`20 X#define ALT_ADD(screen, y, x, ch) \ X wmove(screen, y, x); \ X waddch(screen, ch); X#define STAND_ADD(screen, y, x, ch) \ X wmove(screen, y, x); \ X wstandout(screen); \ X waddch(screen, ch); \ X wstandend(screen); X#define STAND_ALT_ADD(screen, y, x, ch) \ X wstandout(screen); \ X ALT_ADD(screen, y, x, ch); \ X wstandend(screen); X`20 Xchar *Template`5B`5D = `7B X" `20 V ", X". V /" V, X"< /v V+", X"< /++ V+", X"< /v+++ V+", X"< /====. >++++ V+", X"< `60v30v< /+++ V+++", X"< >++++. >+++++ V+", X"< >++++< /++++++ V+", X"< >++++< /+++++++ V+", X"+. >+++++. `60+++++ V+++", X"+< /++++++< `60++++ V+++", X"+< /+++++++< >+++++ V+", X"+< >+++++++< /v. >+++++ V+", X"+< >+++++++< /+++. >+++++ V+", X"+< >+++++++' >+++< >+++++ V+", X"++====. /====+++++++< >+++< >+++++ V+", X"++v30v< /vvv+v15v+++++++< /v. /v++++< >+++++ V+", X"+++++++v. /vv++++++++++++++++< /v+++====. >++++++==++++++ V+", X"+++++++++=======+++++++++++++++++++< /v+++++v20v+======+++++++50++++++ V+", X"+++++++++vv10vvv++++++++++++++++++++======++++++++++++vv15vv+++++++++++++++ V+", X"++++++++++++++++++++++++++++++++++++vv25vv+++++++++++++++++++++++++++++++++ V+"`7D; X`20 Xint PadScore`5BMAX_PADS`5D = `7B30, 30, 15, 20, 50, 10, 15, 25`7D; Xint LastLegalY, LastLegalX; X`20 X#ifdef BSD Xtypedef char chtype_port_t; X#else Xtypedef chtype chtype_port_t; X#endif X`20 Xstatic chtype_port_t LineMap`5B128`5D = `7B0`7D; Xstatic int Old_Y, Old_X; X`20 Xvoid Introduction(); Xvoid dumpcore(); Xvoid zap(); X`20 Xvoid InitialiseScreen(init_scr) X`20 XWINDOW **init_scr; X`20 X `7B X register WINDOW *screen; X`20 X signal(SIGINT, zap); X signal(SIGQUIT, dumpcore); X initscr(); X printf("\033`5B?25l"); X noecho(); X cbreak(); X *init_scr = stdscr; X screen = *init_scr; X#ifdef BSD X LineMap`5B'\''`5D = '+'; X LineMap`5B'.'`5D = '+'; X LineMap`5B'`7C'`5D = '`7C'; X LineMap`5B'-'`5D = '-'; X LineMap`5B'/'`5D = '+'; X LineMap`5B'`60'`5D = '+'; X LineMap`5B'+'`5D = '+'; X LineMap`5B'>'`5D = '+'; X LineMap`5B'<'`5D = '+'; X LineMap`5B'`5E'`5D = '+'; X LineMap`5B'v'`5D = '+'; X LineMap`5BPAD`5D = '='; X#else X LineMap`5B'\''`5D = ACS_LRCORNER; X LineMap`5B'.'`5D = ACS_URCORNER; X LineMap`5B'`7C'`5D = ACS_VLINE; X LineMap`5B'-'`5D = ACS_HLINE; X LineMap`5B'/'`5D = ACS_ULCORNER; X LineMap`5B'`60'`5D = ACS_LLCORNER; X LineMap`5B'+'`5D = ACS_PLUS; X LineMap`5B'>'`5D = ACS_LTEE; X LineMap`5B'<'`5D = ACS_RTEE; X LineMap`5B'`5E'`5D = ACS_BTEE; X LineMap`5B'v'`5D = ACS_TTEE; X LineMap`5BPAD`5D = ACS_HLINE; X#endif X Introduction(screen); X printf("\033`5B?25l"); X `7D X`20 Xvoid DrawScreen(screen) X`20 XWINDOW *screen; X`20 X `7B X register int i, j, scr_i; X chtype_port_t map; X char *line, ch; X`20 X werase(screen); X for (i = 0; i < SCR_Y; ++i) X `7B X line = Template`5Bi`5D; X scr_i = i + 1; X for (j = 0; j < SCR_X; ++j) X `7B X ch = *(line + j); X map = LineMap`5Bch`5D; X if (map) X if (ch == PAD) X `7B X STAND_ALT_ADD(screen, scr_i, j, map); X `7D X else X `7B X ALT_ADD(screen, scr_i, j, map); X `7D X else X if (ch == PAD) X `7B X STAND_ADD(screen, scr_i, j, ch); X `7D X else X mvwaddch(screen, scr_i, j, ch); X `7D X `7D X wrefresh(screen); X LastLegalY = SCR_ADJ(0); X LastLegalX = 0; X Old_Y = Old_X = -1; X `7D X`20 Xint MoveLander(screen, land_y, land_x) X`20 XWINDOW *screen; Xdouble land_y, land_x; X`20 X `7B X int y, x, touchup = 0, screen_y, new_legal; X double y_real, x_real; X char ch; X`20 X y_real = (ALTITUDE_INIT - land_y) / ALTITUDE_INIT * (double) SCR_Y; X x_real = land_x / LANDSCAPE_WIDTH * (double) SCR_X; X y = y_real + 0.5; X x = x_real + 0.5; X new_legal = LEGAL_YX(y, x); X if (y != Old_Y `7C`7C x != Old_X) X `7B X if (LEGAL_YX(Old_Y, Old_X)) X `7B X mvwaddch(screen, SCR_ADJ(Old_Y), Old_X, '.'); X touchup = 1; X `7D X if (new_legal) X `7B X screen_y = SCR_ADJ(y); X#ifdef BSD X ALT_ADD(screen, screen_y, x, '$'); X#else X ALT_ADD(screen, screen_y, x, ACS_TTEE); X#endif X wmove(screen, screen_y, x); X LastLegalY = y; X LastLegalX = x; X touchup = 1; X `7D X `7D X if (touchup) X wrefresh(screen); X Old_Y = y; X Old_X = x; X if (new_legal) X `7B X ch = *(Template`5By`5D + x); X if (ch == PAD) X return LANDED; X if (ch != ' ') X return CRASH; X `7D X else X return CRASH; X return FLYING; X `7D X`20 Xstatic void zap() X`20 X `7B X printf("\033`5B?25h"); X endwin(); X#ifndef VMS X fcntl(fileno(stdin), F_SETFL, 0); X#endif X exit(1); X `7D X`20 Xstatic void dumpcore() X`20 X `7B X printf("\033`5B?25h"); X#ifndef VMS X fcntl(fileno(stdin), F_SETFL, 0); X#endif X endwin(); X signal(SIGQUIT, SIG_DFL); X kill(getpid(), SIGQUIT); X pause(); X `7D X`20 X#define L0 "Lunar Lander" X#ifdef VMS X#define L1 "The classic arcade game comes to VMS." X#else X#define L1 "The classic arcade game comes to Unix." X#endif X#define L2 "Controls:" X#define L3 "'0'-'9' - power level" X#define L4 "'z' - set left retro rocket to power level" X#define L5 "'x' - set vertical thrust to power level" X#define L6 "'c' - set right retro to power level" X#define L7 "--press space to start game--" X#define L8 "Stacey Campbell at HCR, 1989" X#define CENTRE(win, line, str) mvwaddstr(win, line, (COLS - sizeof(str)) / 2 V, \ X str) X`20 Xstatic void Introduction(screen) X`20 XWINDOW *screen; X`20 X `7B X werase(screen); X CENTRE(screen, 2, L0); X CENTRE(screen, 5, L1); X CENTRE(screen, 9, L2); X CENTRE(screen, 11, L3); X CENTRE(screen, 12, L4); X CENTRE(screen, 13, L5); X CENTRE(screen, 14, L6); X CENTRE(screen, 18, L8); X CENTRE(screen, 20, L7); X#ifdef BSD X wrefresh(screen); X#endif X while (wgetch(screen) != ' '); X `7D X X#ifdef BSD X`20 Xint flash() X`20 X `7B X#ifndef VMS X putchar(7); X#endif X `7D X`20 X#ifndef FNDELAY X#define FNDELAY O_NDELAY X#endif X Xint nodelay(win, flag) X`20 XWINDOW *win; Xint flag; X`20 X#ifdef VMS X`7B return 0; `7D X#else X `7B X int res; X`20 X res = fcntl(fileno(stdin), F_GETFL, 0); X if (flag) X `7B X res `7C= FNDELAY; X fcntl(fileno(stdin), F_SETFL, res); X `7D X else X `7B X res &= `7EFNDELAY; X fcntl(fileno(stdin), F_SETFL, res); X `7D X return 0; X `7D X#endif X#endif $ CALL UNPACK SCREEN.C;1 1836479668 $ v=f$verify(v) $ EXIT