SHARE
TWEET

ship

a guest Sep 12th, 2019 132 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program ship;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   SysUtils,
  7.   Windows;
  8.  
  9. Type
  10.   TElev = record
  11.     Avail: Boolean;
  12.     NextFloor: Integer;
  13.   end;
  14.  
  15.   TStairs = record
  16.     Avail: Boolean;
  17.     NextFloor: Integer;
  18.   end;
  19.  
  20.   TWay = record
  21.     Color: string[50];
  22.     Window: Boolean;
  23.     Angle: integer;
  24.     Side: string;
  25.     Steps: integer;
  26.     ChRoom: integer; //1 - left; 2 - right
  27.  
  28.  
  29.     Room: Boolean;
  30.     Corridor: Boolean;
  31.     CurrFloor: integer;
  32.  
  33.     Elevator: TElev;
  34.     Stairs: TStairs;
  35.   end;
  36.   TArrWay = array[1..21] of TWay;
  37.  
  38. Var
  39.   i:integer;
  40.   check:boolean;
  41.   colornum, location:char;
  42.   myway:TArrWay;
  43.   startPos:integer;
  44.   color:string;
  45.  
  46. procedure fillArray(var way:TArrWay);
  47. var
  48.   i:integer;
  49. begin
  50.   //room without window
  51.   way[1].Color:='Green';      
  52.   way[1].Angle:=0; way[1].Steps:=10;
  53.   way[1].ChRoom:=-1; way[1].Room:=True;
  54.   way[1].CurrFloor:=5;
  55.  
  56.   way[2].Color:='Green'; way[2].Angle:=45; way[2].Side:='left';
  57.   way[2].Steps:=8; way[2].CurrFloor:=5;
  58.   way[2].Corridor:=True;
  59.  
  60.   //enter elevator fl5
  61.   way[3].Color:='Green';                
  62.   way[3].Elevator.Avail:=True; way[3].Elevator.NextFloor:=3;
  63.  
  64.   //exit elevator fl3
  65.   way[4].Color := 'Gray'; way[4].Angle:=0; way[4].Steps:=25;
  66.   way[4].ChRoom:=-1; way[4].Corridor:=True; way[4].CurrFloor:=3;  
  67.  
  68.   //laboratory
  69.   way[5].Room:=True; way[5].Window:=True;  
  70.   way[5].ChRoom:=2;
  71.   way[5].CurrFloor:=3; way[5].Color:='Gray';
  72.  
  73.   way[6].Color:='Gray'; way[6].Angle:=0; way[6].Steps:=10;
  74.   way[6].Corridor:=True; way[6].CurrFloor:=3;
  75.  
  76.   way[7].Color:='Gray'; way[7].Angle:=45; way[7].Side:='left';
  77.   way[7].Corridor:=True; way[7].CurrFloor:=3; way[7].Steps:=8;
  78.  
  79.   way[8].Color:='Gray'; way[8].Angle:=90; way[8].Side:='left';
  80.   way[8].Steps:=20; way[8].Corridor:=True; way[8].CurrFloor:=3;
  81.  
  82.   way[9].Color:='Gray'; way[9].Angle:=45; way[9].Side:='left';
  83.   way[9].Steps:=36; way[9].Corridor:=True; way[9].CurrFloor:=3;
  84.  
  85.   //black room
  86.   way[10].Color:='Black'; way[10].Window:=True; way[10].Room:=True;
  87.   way[10].ChRoom:=2; way[10].CurrFloor:=3;
  88.  
  89.   way[11].Color:='Metallic'; way[11].Angle:=0;
  90.   way[11].Steps:=12;way[11].Corridor:=True;
  91.   way[11].CurrFloor:=3;
  92.  
  93.   way[12].Color:='Metallic';way[12].Angle:=45;way[12].Side:='right';
  94.   way[12].Steps:=48;way[12].Corridor:=True;way[12].CurrFloor:=3;
  95.  
  96.   //enter stair fl3
  97.   way[13].Stairs.Avail:=True; way[13].Stairs.NextFloor:=2;  
  98.   way[13].Color:='Black';
  99.  
  100.   //exit stair fl2
  101.   way[14].Angle := 0; way[14].Color:='Black'; way[14].ChRoom:=1;
  102.   way[14].Corridor:=True; way[14].Steps:=50; way[14].CurrFloor:=2;
  103.  
  104.   way[15].Color:='Black'; way[15].Angle:=45; way[15].Side:='right';
  105.   way[15].Steps:=18; way[15].Corridor:=True; way[15].CurrFloor:=2;
  106.  
  107.   way[16].Color:='Black'; way[16].Angle:=90; way[16].Side:='right';
  108.   way[16].Steps:=18; way[16].Corridor:=True; way[16].CurrFloor:=2;
  109.  
  110.   way[17].Color:='Black'; way[17].Angle:=45; way[17].Side:='right';
  111.   way[17].Steps:=48; way[17].Corridor:=True; way[17].CurrFloor:=2;
  112.  
  113.   //enter elevator fl2
  114.   way[18].Color:='Black'; way[18].Elevator.Avail:=True;
  115.   way[18].Elevator.NextFloor:=1;
  116.  
  117.   //exit elevator fl1
  118.   way[19].Angle:=0; way[19].Color:='Dark'; way[19].Steps:=52;
  119.   way[19].Corridor:=True; way[19].CurrFloor:=1;
  120.  
  121.   //
  122.   way[20].Color:='Dark'; way[20].Steps:=60; way[20].Angle:=45;
  123.   way[20].Side:='right'; way[20].Corridor:=True;
  124.  
  125.   //exit
  126.   way[21].CurrFloor:=0;
  127. end;
  128.  
  129. procedure typeWay(way:TArrWay; startPos:integer);
  130. var
  131.   i:integer;
  132. begin
  133.   for i := startPos to length(way) do
  134.   begin
  135.     if (way[i].Room) and (not (way[i].ChRoom in [1,2])) then
  136.       writeln('Leave the room.')
  137.     else
  138.       if (way[i].Room) and (way[i].ChRoom in [1,2]) then
  139.         case way[i].ChRoom of
  140.           1: writeln('Leave the room through the left door.');
  141.           2: writeln('Leave the room through the right door.');
  142.         end;
  143.  
  144.     if way[i].Corridor then
  145.     begin
  146.       case way[i].Angle of
  147.         0: writeln('Walk ', way[i].Steps,' straight.');
  148.         45,90: writeln('Turn ',way[i].Angle,' degrees ',way[i].Side,' and walk ', way[i].Steps,' straight.');    
  149.       end;
  150.       if way[i+1].Room then
  151.         writeln('Enter the room.');
  152.     end;
  153.  
  154.     if way[i].Elevator.Avail then
  155.       writeln('Enter the elevator, go down to the ',way[i].Elevator.NextFloor,' floor and leave him.');
  156.  
  157.     if way[i].Stairs.Avail then
  158.       writeln('Go down the stairs to the ',way[i].Stairs.NextFloor,' floor.');
  159.   end;
  160.   writeln('Open the iron door.');
  161.   writeln('You are free!');
  162. end;
  163.  
  164. begin
  165.   fillArray(myway);
  166.   writeln('Once strolling in a grove, you discovered a new alien ship has just landed.');
  167.   writeln('Natural curiosity convinces you to go inside.');
  168.   writeln('The aliens who appeared, without showing the slightest friendliness..');
  169.   writeln('...silently lead you to an empty office and leave you there.');
  170.   writeln('One fine day you ran away from your room and started looking for a way out.');
  171.   writeln('After a couple of minutes, you realized that you were lost...');
  172.   writeln('===============================================================================');
  173.   writeln('                                                                               ');
  174.   writeln('                                 ESCAPE                                        ');
  175.   writeln('                                                                               ');
  176.   writeln('===============================================================================');
  177.   writeln('What the color of the walls on the floor?');
  178.   writeln('1 - Green');
  179.   writeln('2 - Black');
  180.   writeln('3 - Gray');
  181.   writeln('4 - Metallic');
  182.   writeln('5 - Dark');
  183.   repeat
  184.     readln(colornum);  
  185.   until (colornum in ['1'..'5']);
  186.  
  187.   case colornum of
  188.     '1': color := 'Green';  
  189.     '2': color := 'Black';
  190.     '3': color := 'Gray';
  191.     '4': color := 'Metallic';
  192.     '5': color := 'Dark';
  193.   end;
  194.   writeln('Where are you at?');
  195.   writeln('1 - Room');
  196.   writeln('2 - Corridore');
  197.   writeln('3 - Elevator');
  198.   writeln('4 - Stairs');
  199.  
  200.   repeat
  201.     readln(location);
  202.     case location of
  203.       '1':
  204.       begin  
  205.         for i := 1 to length(myway) do
  206.         begin
  207.           if (myway[i].Room) and (myway[i].Color <> color) then
  208.           begin
  209.             check := False;
  210.           end
  211.           else
  212.             if (myway[i].Room) and (myway[i].Color = color) then
  213.               check := True;
  214.         end;
  215.  
  216.         if check = False then
  217.           writeln('There are no any rooms with this color. Look more carefully.');
  218.       end;
  219.       '2':
  220.       begin
  221.         check := True;
  222.       end;
  223.       '3':
  224.       begin
  225.         for i := 1 to length(myway) do
  226.         begin
  227.           if (myway[i].Elevator.Avail) and (myway[i].Color <> color) then
  228.           begin
  229.             check := False;
  230.           end
  231.           else
  232.             if (myway[i].Elevator.Avail) and (myway[i].Color = color) then
  233.               check := True;
  234.         end;
  235.  
  236.         if check = False then
  237.           writeln('There are no any elevators with this color. Look more carefully.');
  238.       end;
  239.       '4':
  240.       begin
  241.         for i := 1 to length(myway) do
  242.         begin
  243.           if (myway[i].Stairs.Avail) and (myway[i].Color <> color) then
  244.           begin
  245.             check := False;
  246.           end
  247.           else
  248.             if (myway[i].Stairs.Avail) and (myway[i].Color = color) then
  249.               check := True;
  250.         end;
  251.  
  252.         if check = False then
  253.           writeln('There are no any stairs with this color. Look more carefully.');
  254.       end;
  255.     end;
  256.    
  257.   until (location in ['1'..'4']) and (check);
  258.  
  259.   for i := 1 to length(myway) do
  260.   begin
  261.     if (myway[i].Color = color) then
  262.       case location of
  263.         '1':
  264.         begin  
  265.           if myway[i].Room then
  266.           begin
  267.             startPos := i;
  268.             writeln(startPos);
  269.             break;
  270.           end;
  271.         end;
  272.         '2':
  273.         begin
  274.           if myway[i].Corridor then
  275.           begin
  276.             startPos := i;
  277.             writeln(startPos);
  278.             break;
  279.           end;
  280.         end;
  281.         '3':
  282.         begin
  283.           if myway[i].Elevator.Avail then
  284.           begin
  285.             startPos := i;
  286.             writeln(startPos);
  287.             break;
  288.           end;
  289.         end;
  290.         '4':
  291.         begin
  292.           if myway[i].Stairs.Avail then
  293.           begin
  294.             startPos := i;
  295.             writeln(startPos);
  296.             break;
  297.           end;
  298.         end;
  299.       end;
  300.   end;
  301.  
  302.   typeWay(myway, startPos);
  303.  
  304.   writeln('=======================================');
  305.   writeln('Press "Enter" to exit...');
  306.   readln;
  307. end.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top