home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug017.arc / STARSHOT.PAS < prev    next >
Pascal/Delphi Source File  |  1979-12-31  |  6KB  |  260 lines

  1. Program StarShot(Input,Output);
  2. {Writen by Peter Billing   14 - 6 - 1985}
  3.  
  4. Const
  5.   on   = '*';
  6.   off  = 'o';
  7.  
  8. Var
  9.   board    : array[1..3,1..5] of char;
  10.   i,j      : integer;
  11.   quit     : boolean;
  12.   move     : integer;
  13.  
  14.   Procedure Initialize;
  15.   begin
  16.     move :=0;
  17.     for i := 1 to 3 do
  18.     for j := 1 to 5 do
  19.     board[i,j] := off;
  20.     board[2,3] := on;
  21.     for i := 1 to 3 do
  22.     begin
  23.       board[i,2] := ' ';
  24.       board[i,4] := ' ';
  25.     end;
  26.     gotoxy(20,16); writeln('1 2 3');
  27.     gotoxy(20,17); writeln('4 5 6');
  28.     gotoxy(20,18); writeln('7 8 9');
  29.     gotoxy(34,14);
  30.     writeln('               ');
  31.     gotoxy(25,23);
  32.     writeln('                              ');
  33.   end;
  34.  
  35.   Procedure Instruction;
  36.   begin
  37.     gotoxy(1,1);
  38.     writeln('S T A R    S H O O T':48);
  39.     writeln;
  40.     writeln('You may only shoot at stars that are turned on. eg "on" The star will turn off');
  41.     writeln('eg "o", and depending on its position will turn on stars adjacent to itself.');
  42.     writeln('The object of the game is to reverse the initial pattern.');
  43.     writeln;
  44.     writeln('             INITIAL                              FINAL');
  45.     writeln('              o o o                               * * *');
  46.     writeln('              o * o                               * o *');
  47.     writeln('              o o o                               * * *');
  48.     writeln;
  49.     writeln(' Best possible score is 11 moves.  Enter 0 to start again, Q to Quit.');
  50.     writeln(' Press D for a DEMONSTRATION in 11 moves.');
  51.   end;
  52.  
  53.   Procedure Display;
  54.   var
  55.     y,i,j : integer;
  56.   begin
  57.     gotoxy(30,15); write('Move >',move:2);
  58.     y := 15;
  59.     for i := 1 to 3 do
  60.     begin
  61.       writeln;
  62.       gotoxy(38,y+i);
  63.       for j := 1 to 5 do
  64.       write(board[i,j]);
  65.     end;
  66.   end;
  67.  
  68.   Procedure Horizontal(x : integer);
  69.   var
  70.     y : integer;
  71.   begin
  72.     y := 1;
  73.     repeat
  74.       if board[x,y] =on
  75.         then board[x,y] := off
  76.         else board[x,y] := on;
  77.       y := y + 2;
  78.     until y = 7;
  79.     move := move +1;
  80.   end;
  81.  
  82.   Procedure Vertical(y : integer);
  83.   var
  84.     x : integer;
  85.   begin
  86.     for x := 1 to 3 do
  87.     if board[x,y] =on
  88.       then board[x,y] := off
  89.       else board[x,y] := on;
  90.     move := move +1;
  91.   end;
  92.  
  93. Procedure Center;
  94. begin
  95.   horizontal(2);
  96.   if board[1,3] =on
  97.      then board[1,3] := off
  98.      else board[1,3] := on;
  99.   if board[3,3] =on
  100.      then board[3,3] := off
  101.      else board[3,3] := on;
  102. end;
  103.  
  104.   Procedure Corner(x,y : integer);
  105.   var
  106.     temp : integer;
  107.   begin
  108.     temp := y;
  109.     for i := x to x+1 do
  110.     begin
  111.       y := temp;
  112.       repeat
  113.         if board[i,y] =on
  114.           then board[i,y] := off
  115.           else board[i,y] := on;
  116.         y := y+2;
  117.       until temp+4 = y;
  118.     end;
  119.     move := move +1;
  120.   end;
  121.  
  122.   Function Check(x,y :integer) :boolean;
  123.   begin
  124.     if board[x,y] = on
  125.       then check := true
  126.       else check := false;
  127.   end;
  128.  
  129.   Function Win :boolean;
  130.   var
  131.     z,x,y :integer;
  132.   begin
  133.     z := 0;
  134.     x := 1;
  135.     repeat
  136.       y := 1;
  137.       repeat
  138.         if board[x,y] = off
  139.           then z := 1;
  140.         y := y+2;
  141.       until y=7;
  142.       x := x+2
  143.     until x = 5;
  144.     if board[2,1] = off
  145.       then z := 1;
  146.     if board[2,5] = off
  147.       then z := 1;
  148.     if board[2,3] = on
  149.       then z := 1;
  150.     if z=1
  151.       then win := false
  152.       else win := true;
  153.   end;
  154.  
  155. Procedure p;
  156. begin
  157.   delay (1000)
  158. end;
  159.  
  160. Procedure Demo;
  161. begin
  162.   center;       display;p;
  163.   horizontal(3);display;p;
  164.   corner(2,1);  display;p;
  165.   corner(2,3);  display;p;
  166.   horizontal(1);display;p;
  167.   corner(1,1);  display;p;
  168.   center;       display;p;
  169.   corner(1,3);  display;p;
  170.   horizontal(1);display;p;
  171.   horizontal(3);display;p;
  172.   center;       display;p;
  173. end;
  174.  
  175.  
  176.   Procedure Command;
  177.   var
  178.     x,y,k : integer;
  179.     ch : char;
  180.   begin
  181.     gotoxy(25,22);
  182.     write('Command > ');
  183.     read(kbd,ch);
  184.     write(ch);
  185.     case ch of
  186.       '5'  :
  187.             if check(2,3)
  188.               then center;
  189.       '4'  :
  190.             if check(2,1)
  191.               then vertical(1);
  192.       '6'  :
  193.             if check(2,5)
  194.               then vertical(5);
  195.       '2'  :
  196.             if check(1,3)
  197.               then horizontal(1);
  198.       '8'  :
  199.             if check(3,3)
  200.               then horizontal(3);
  201.       '1'  :
  202.             if check(1,1)
  203.               then corner(1,1);
  204.       '3'  :
  205.             if check(1,5)
  206.               then corner(1,3);
  207.       '7'  :
  208.             if check(3,1)
  209.               then corner(2,1);
  210.       '9'  :
  211.             if check(3,5)
  212.               then corner(2,3);
  213.       '0'  :
  214.              Initialize;
  215.       'd','D' :
  216.                if move < 1
  217.                 then demo;
  218.       'q','Q' :
  219.              quit := true;
  220.       else command
  221.     end;
  222.     display;
  223.     if win
  224.       then
  225.         begin
  226.           gotoxy(34,14);
  227.           writeln('You have won!!!');
  228.           gotoxy(25,23);
  229.           writeln('Do you wish to try again? Y/N ');
  230.           gotoxy(25,22);write('Command > ');
  231.           repeat
  232.             read(kbd,ch);
  233.           until upcase(ch) in ['Y','N'];
  234.           if upcase(ch) = 'Y'
  235.             then
  236.               begin
  237.                 quit := false;
  238.                 initialize;
  239.                 display
  240.               end
  241.             else
  242.               begin
  243.                 quit := true;
  244.                 clrscr
  245.               end
  246.             end;
  247.        if (ch ='D') or (ch ='d') then quit := false;
  248.   end;
  249.  
  250. begin
  251.   ClrScr;
  252.   Initialize;
  253.   Instruction;
  254.   Display;
  255.   Quit := false;
  256.   Repeat
  257.     Command;
  258.   Until quit;
  259. end.
  260.