home *** CD-ROM | disk | FTP | other *** search
- program stars;
- {*
- ** PROGRAM TITLE: SHOOTING STARS
- **
- ** WRITTEN BY: MARK J. BORGERSON
- ** DATE WRITTEN: July, 1976
- **
- ** WRITTEN FOR: PERSONAL ENJOYMENT
- **
- ** TRANSLATED: Translated from BASIC
- ** by Ray Penley, SEPT 1979
- **
- ** HISTORY: Originally from Pascal/Z Users' Group
- ** CP/M Users' Group volume 71
- ** Modified for TURBO Pascal -- Wm Meacham, 6/5/84
- ** Adapted for Facilis -- Anthony Marcy, Mar 1985
- *}
-
- type
- vector = array[1..9] of integer;
- str80 = string[80];
-
- var
- seed1,seed2: integer;
- stars,f5: vector;
- c: integer;
- done,reply: boolean;
- hole: char;
-
- { -------------------- Screen handling routines -------------------- }
-
- procedure keyin(var cix: char);
- begin
- read(cix)
- end;
-
-
- procedure write_str (st: str80; col,row: integer);
- begin
- gotoxy(col,row);
- write(st)
- end;
-
-
- procedure pause; {Prints message on line 24, waits for user response}
- var ch: char;
- begin
- write_str('PRESS SPACE BAR TO CONTINUE',21,24);
- repeat
- keyin(ch)
- until ch = chr($20);
- write_str(' ',21,24)
- end;
-
-
- procedure read_bool(var bool: boolean; col,row: integer);
- { Inputs "Y" OR "N" to boolean at row and column specified,
- prints "YES" or "NO"}
-
- var ch: char;
-
- begin
- gotoxy(col,row);
- write(' ') ;
- gotoxy(col,row);
- repeat
- keyin(ch)
- until (ch='Y') or (ch='y') or (ch='N') or (ch='n');
- gotoxy(col,row);
- if (ch = 'Y') or (ch = 'y')
- then begin
- write ('YES');
- bool := true
- end
- else begin
- write('NO ');
- bool := false
- end
- end; {read_bool}
-
-
- procedure clreos;
- begin
- write_str(' ',21,14);
- write_str(' ',21,17);
- write_str(' ',21,20);
- write_str(' ',21,22);
- end;
-
-
- procedure skip(lines: integer);
- var i: integer;
- begin
- for i := 1 to lines do writeln;
- end;
-
- { -------------------- Routines for the game as such -------------------- }
-
- procedure instructions;
- var i: integer;
- begin
- clrscr;
- writeln('If you like brain teasers then you''re in for some fun.');
- writeln('The object of this puzzle is to solve a 3 X 3 matrix to make');
- textcolor(6); write('*'); textcolor(3);
- write('s appear in all positions except in the center which will be ');
- textcolor(9); write(hole); textcolor(3);
- writeln('.');
- writeln('The positions on the matrix board are referred to as follows:');
- writeln(' 7 8 9');
- writeln(' 4 5 6');
- writeln(' 1 2 3 -- just like your numeric keypad.');
- write('When you shoot a ');
- textcolor(6); write('*'); textcolor(3);
- write(' it becomes a ');
- textcolor(9); write(hole); textcolor(3);
- writeln(', and its immediate neighbors change state;');
- write('that is, ');
- textcolor(6); write('*'); textcolor(3);
- write('s become ');
- textcolor(9); write(hole); textcolor(3);
- writeln('s and vice versa.');
- writeln('In addition, changing a corner position also changes the center position;');
- writeln('changing the center position also changes the outside middle positions.');
- write('You lose the game when there are no more ');
- textcolor(6); write('*'); textcolor(3);
- writeln('s to shoot.');
- writeln('It can always be done in fewer than a dozen shots.');
- writeln;
- writeln('Make sure NumLock is in numeric mode.');
- writeln;
- writeln;
- writeln('Have fun, and good luck!');
- pause;
- end;
-
-
- procedure heading;
- var ans: boolean;
- begin
- hole := chr(249); { black hole symbol }
- clrscr;
- textcolor(3);
- writeln(' ':20, '*** SHOOTING STARS ***');
- skip(2);
- write('Do you want instructions? (Y/N)');
- read_bool(ans,33,4);
- if ans then instructions;
- end;
-
-
- function randm: integer; { RANDM will return numbers from 0 to 32767 }
- begin
- randm := random(maxint);
- end;
-
-
- procedure initialize;
- begin
- clrscr;
- c := 0 ; { shot counter }
- stars[1] := -23; f5[1] := 1518;
- stars[2] := -3; f5[2] := 1311;
- stars[3] := -19; f5[3] := 570;
- stars[4] := -11; f5[4] := 3289;
- stars[5] := 2; f5[5] := 2310;
- stars[6] := -5; f5[6] := 1615;
- stars[7] := -13; f5[7] := 2002;
- stars[8] := -7; f5[8] := 1547;
- stars[9] := -17; f5[9] := 1190;
- write_str('7 8 9',21,14);
- write_str('4 5 6',21,17);
- write_str('1 2 3',21,20);
- write_str('0 - Quit',21,22);
- end;
-
-
- procedure load;
- var i,x7,sum: integer;
- begin
- repeat
- sum := 0;
- for i := 1 to 9 do begin
- x7 := randm div 100;
- if x7 > 200 then stars[i] := -stars[i];
- sum := sum + stars[i];
- end
- until (sum<>96) and (sum<>-100);
- end;
-
-
- procedure board;
- var j: integer;
- begin
- gotoxy(1,1);
- write(' ':20);
- for j := 7 to 9 do begin
- if stars[j] < 0 then begin textcolor(9); write(hole+' '); end
- else begin textcolor(6); write('* '); end
- end;
- skip(3);
- write(' ':20);
- for j := 4 to 6 do begin
- if stars[j] < 0 then begin textcolor(9); write(hole+' '); end
- else begin textcolor(6); write('* '); end
- end;
- skip(3);
- write(' ':20);
- for j := 1 to 3 do begin
- if stars[j] < 0 then begin textcolor(9); write(hole+' '); end
- else begin textcolor(6); write('* '); end
- end;
- skip(4);
- textcolor(3);
- end;
-
-
- procedure playthegame;
-
- var
- d,x: integer;
- endofgame,quit: boolean;
-
- function check: integer;
-
- { Check to if the F value for the shot can be evenly
- divided by the stars value for each position. If the
- stars value divides into F without a remainder, the
- STAR or black hole is inverted (its sign is changed). }
-
- var b1,k,z5: integer;
- begin
- b1 := 0;
- for k := 1 to 9 do begin
- z5 := (f5[x] div stars[k]) * stars[k];
- if z5 = f5[x] then stars[k] := -stars[k]
- end;
- for k := 1 to 9 do
- b1 := b1 + stars[k];
- check := b1
- end;
-
-
- procedure input;
-
- var
- cix: char;
- error: boolean;
- i: integer;
-
- begin
- repeat
- error := false;
- write_str(' ',1,11);
- write_str('Your Shot ',1,11);
- keyin(cix);
- if cix='0'
- then quit := true
- else
- begin
- x := (ord(cix) - ord('0'));
- writeln;
- c := c + 1;
- if (x<1) or (x>9)
- then error := true
- else if stars[x] <= 0 then
- begin
- write_str('You can only Shoot Stars',1,12);
- sound(60);
- delay(500);
- nosound;
- delay(400);
- write_str(' ',1,12);
- error := true
- end
- end
- until not error;
- writeln;
- end; { of input }
-
-
-
- begin { playthegame }
- endofgame := false;
- quit := false;
- repeat
- input;
- if quit
- then begin
- write_str(' ',1,11); writeln;
- writeln('GAME TERMINATED ');
- endofgame := true
- end
- else begin
- d := check;
- board;
- if d = -100
- then begin
- writeln('You lost!!!');
- endofgame := true
- end
- else if d=96
- then begin
- textcolor(12); writeln('You WIN!!! ') ; textcolor(3);
- writeln('You fired ', c:1, ' shots.');
- endofgame := true
- end
- end
- until endofgame
- end; { of playthegame }
-
- { -------------------- The main program -------------------- }
-
- begin { stars }
- done := false;
- repeat
- heading;
- initialize;
- load;
- board;
- playthegame;
- clreos;
- write_str('Would you like to play again?', 1, 13);
- read_bool(reply, 31, 13);
- if not reply then done := true;
- until done
- end.
- uld you like to play again?', 1, 13);
-