Advertisement
Guest User

Console Invaders

a guest
Mar 26th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 9.28 KB | None | 0 0
  1. program Q1_1;
  2.  
  3. uses Crt;
  4. var i, Health, Ammo, MaxAmmo, t, ChY, ShotVar, UpdateTime, enY, Score, Point, GLanguage, UpdateTimeTemp, GLanguageTemp: integer;
  5.     Button: Char;
  6.     ShotX, enX: real;
  7.     Game, Menu, EnemyOnScreen: boolean;
  8.     SettingsFile, LanguagesFile: text;
  9.     langs: array[1..50] of string;
  10.  
  11. procedure InitStatistics();
  12. var i: integer;
  13. begin
  14.     gotoXY(1, 1);
  15.     textColor(LightRed);  
  16.     for i := 1 to Health div 10 do
  17.       write('▓');
  18.      
  19.     gotoXY(13, 1);
  20.     textColor(LightCyan);
  21.     write(Health);
  22.    
  23.     gotoXY(11, 1);
  24.     write('▌');
  25.    
  26.     gotoXY(17, 1);
  27.     write(langs[1], '   ▌', '  ', langs[3], ' ', Score);
  28.    
  29.     gotoXY(1, 2);
  30.     textColor(White);
  31.     for i := 1 to Ammo div 20 do
  32.       write('▌');
  33.    
  34.     textColor(LightCyan);
  35.     gotoXY(11, 2);
  36.     write('▌');
  37.    
  38.     if GLanguage = 2 then
  39.       gotoXY(28, 2)
  40.     else if GLanguage = 1 then
  41.       gotoXY(26, 2);
  42.     write('▌');
  43.      
  44.     gotoXY(13, 2);  
  45.     textColor(LightCyan);
  46.     write(Ammo);
  47.    
  48.     gotoXY(17, 2);
  49.     write(langs[2]);
  50. end;
  51.  
  52. function ZPressed(): boolean;
  53. begin
  54.   if (Button = #122) or (Button = #1103) or (Button = #53) then
  55.     result := true;
  56. end;
  57.  
  58. function OPressed(): boolean;
  59. begin
  60.   if (Button = #111) or (Button = #1097) or (Button = #56) then
  61.     result := true;
  62. end;
  63.  
  64. function LPressed(): boolean;
  65. begin
  66.   if (Button = #108) or (Button = #1076) or (Button = #50) then
  67.     result := true;
  68. end;
  69.  
  70. function APressed(): boolean;
  71. begin
  72.   if (Button = #97) or (Button = #1092) or (Button = #48) then
  73.     result := true;
  74. end;
  75.  
  76. function KPressed(): boolean;
  77. begin
  78.   if (Button = #107) or (Button = #1083) or (Button = #52) then
  79.     result := true;
  80. end;
  81.  
  82. function DVPressed(): boolean;
  83. begin
  84.   if (Button = #59) or (Button = #1078) or (Button = #54) then
  85.     result := true;
  86. end;
  87.  
  88. procedure Shot();
  89. begin
  90.   gotoXY(round(ShotX), ChY);
  91.   write('*');
  92.   if ShotVar = 1 then
  93.     ShotX:= ShotX + 0.5;
  94. end;
  95.  
  96. procedure NoAmmo();
  97. begin
  98.   textColor(Cyan);
  99.   gotoXY(25, 2);
  100.   write(langs[4]);
  101. end;
  102.  
  103. procedure Character(y: integer);
  104. begin
  105.   textColor(Green);
  106.   gotoXY(3, y);
  107.   write('╠►');
  108. end;
  109.  
  110. procedure CharacterMove(UpOrDown: integer);
  111. begin
  112.   case UpOrDown of
  113.     1: begin
  114.          ChY := ChY - 1;
  115.        end;
  116.     2: begin
  117.          ChY := ChY + 1;
  118.        end;
  119.     0: begin
  120.          ChY := ChY;
  121.        end;
  122.   end;
  123.   if ChY < 5 then
  124.     ChY := 5;
  125.   if ChY > 24 then
  126.     Chy := 24;
  127. end;
  128.  
  129. procedure TestEnemies();
  130. begin
  131.   if EnemyOnScreen then
  132.   begin
  133.     textColor(LightMagenta);
  134.     gotoXY(round(enX), enY);
  135.     write('◄╡');
  136.     EnX := EnX - 0.01;
  137.     if EnX <= 2 then
  138.     begin
  139.       Health := Health - 10;
  140.       EnX := 79;
  141.       EnemyOnScreen := false;
  142.     end;
  143.   end;
  144. end;
  145.  
  146. procedure AboutCycle();
  147. begin
  148.   clrScr;
  149.   while true do
  150.     begin
  151.       if KeyPressed then
  152.         Button := ReadKey
  153.       else
  154.         Button := #0;
  155.       textColor(LightGreen);
  156.       gotoXY(1, 1);
  157.       write(langs[5], #10, langs[6], #10, #10, langs[7]);
  158.       gotoXY(1, 10);
  159.       textColor(Green);
  160.       write(langs[8]);
  161.       if (APressed) then
  162.         break;
  163.     end;
  164. end;
  165.  
  166. procedure SettingsCursor();
  167. begin
  168.   if LPressed then
  169.     Point := Point + 1;
  170.   if OPressed then
  171.     Point := Point - 1;
  172.   if Point > 2 then
  173.     Point := 1;
  174.   if Point < 1 then
  175.     Point := 2;
  176.  
  177.   textColor(Yellow);
  178.   case Point of
  179.     1: begin
  180.          gotoXY(5, 7);
  181.          write('*');
  182.          
  183.          if KPressed then
  184.          begin
  185.            if UpdateTimeTemp <= 50 then
  186.              UpdateTimeTemp := UpdateTimeTemp - 1
  187.            else if UpdateTimeTemp > 50 then
  188.              UpdateTimeTemp := UpdateTimeTemp - 10;
  189.            if UpdateTimeTemp < 1 then
  190.              UpdateTimeTemp := 1;
  191.          end;
  192.          
  193.          if DVPressed then
  194.          begin
  195.            if UpdateTimeTemp < 50 then
  196.              UpdateTimeTemp := UpdateTimeTemp + 1
  197.            else if UpdateTimeTemp >= 50 then
  198.              UpdateTimeTemp := UpdateTimeTemp + 10;
  199.            if UpdateTimeTemp > 1000 then
  200.              UpdateTimeTemp := 1000;
  201.          end;
  202.        end;
  203.     2: begin
  204.          gotoXY(5, 9);
  205.          write('*');
  206.          if KPressed then
  207.          begin
  208.            GLanguageTemp := GLanguageTemp - 1;
  209.            if GLanguageTemp < 1 then
  210.              GLanguageTemp := 2;
  211.          end;
  212.          if DVPressed then
  213.          begin
  214.            GLanguageTemp := GLanguageTemp + 1;
  215.            if GLanguageTemp > 2 then
  216.              GLanguageTemp := 1;
  217.          end;
  218.        end;
  219.   end;
  220. end;
  221.  
  222. procedure SettingsCycle();
  223. var i: integer;
  224. begin
  225.   clrScr;
  226.   Point := 1;
  227.   while true do
  228.   begin
  229.     if KeyPressed then
  230.       Button := ReadKey
  231.     else
  232.       Button := #0;
  233.     t := t + 1;
  234.     SettingsCursor;
  235.    
  236.     textColor(Yellow);
  237.     gotoXY(5, 3);
  238.     write(langs[14]);
  239.    
  240.     textColor(White);
  241.     gotoXY(7, 7);
  242.     write(langs[13], ' >> ', UpdateTimeTemp);
  243.     gotoXY(7, 9);
  244.     write(langs[17],  ' >> ');
  245.     if GLanguageTemp = 1 then
  246.       write('EN');
  247.     if GLanguageTemp = 2 then
  248.       write('РУС');
  249.      
  250.     gotoXY(5, 18);
  251.     textColor(LightGray);
  252.     write(langs[18]);
  253.     gotoXY(5, 20);
  254.     textColor(Magenta);
  255.     write(langs[19]);
  256.    
  257.     if APressed then
  258.     begin
  259.       close(SettingsFile);
  260.       rewrite(SettingsFile);
  261.       writeln(SettingsFile, UpdateTimeTemp);
  262.       writeln(SettingsFile, GLanguageTemp);
  263.       close(SettingsFile);
  264.       reset(SettingsFile);
  265.       readln(SettingsFile, UpdateTime, GLanguage);
  266.       break;
  267.     end;
  268.    
  269.     if t mod UpdateTime = 0 then
  270.       clrScr;
  271.   end;
  272. end;
  273.  
  274. procedure MenuCursor();
  275. var About: boolean;
  276. begin
  277.   if LPressed then
  278.     Point := Point + 1;
  279.   if OPressed then
  280.     Point := Point - 1;
  281.   if Point > 4 then
  282.     Point := 1;
  283.   if Point < 1 then
  284.     Point := 4;
  285.    
  286.   textColor(Yellow);
  287.   case Point of
  288.     1: begin
  289.          gotoXY(5, 8);
  290.          write('*');
  291.          if ZPressed then
  292.          begin
  293.            Game := true;
  294.            Menu := false;
  295.          end;
  296.        end;
  297.     2: begin
  298.          gotoXY(5, 10);
  299.          write('*');
  300.          if ZPressed then
  301.          begin
  302.            SettingsCycle;
  303.          end;
  304.        end;
  305.     3: begin
  306.          gotoXY(5, 12);
  307.          write('*');
  308.          if ZPressed then
  309.            AboutCycle();
  310.        end;
  311.     4: begin
  312.          gotoXY(5, 14);
  313.          write('*');
  314.          if ZPressed then
  315.          begin
  316.            clrscr;
  317.            halt;
  318.          end;
  319.        end;
  320.    
  321.   end;
  322.     gotoXY(5, 19);
  323.     textColor(LightCyan);
  324.     write(langs[15]);
  325.     textColor(Magenta);
  326.     gotoXY(5, 21);
  327.     write(langs[16]);
  328. end;
  329.  
  330. begin
  331.   assign(SettingsFile, 'settings.cis');
  332.   reset(SettingsFile);
  333.   readln(SettingsFile, UpdateTime, GLanguage);
  334.  
  335.   UpdateTimeTemp := UpdateTime;
  336.   GLanguageTemp := GLanguage;
  337.  
  338.   if GLanguage = 1 then
  339.   begin
  340.     assign(LanguagesFile, 'langEN.cil');
  341.     reset(LanguagesFile);
  342.     for i := 1 to 50 do
  343.       readln(LanguagesFile, langs[i]);
  344.   end;
  345.  
  346.   if GLanguage = 2 then
  347.   begin
  348.     assign(LanguagesFile, 'langRUS.cil');
  349.     reset(LanguagesFile);
  350.     for i := 1 to 50 do
  351.       readln(LanguagesFile, langs[i]);
  352.   end;
  353.  
  354.   setWindowCaption('Console Invaders');
  355.   hideCursor;
  356.   ChY := 5;
  357.   Health := 100;
  358.   Ammo := 200;
  359.   t := 0;
  360.   ShotX := 4;
  361.  
  362.   Menu := true;
  363.   Game := false;
  364.   EnemyOnScreen := false;
  365.   enX := 79;
  366.   Score := 0;
  367.   Point := 1;
  368.  
  369. while true do
  370. begin
  371.  
  372.   while Menu do
  373.   begin
  374.     t := t + 1;
  375.     if KeyPressed then
  376.       Button := ReadKey
  377.     else
  378.       Button := #0;
  379.    
  380.     textColor(Yellow);
  381.     gotoXY(5, 3);
  382.     write('╠► *** CONSOLE INVADERS --- ◄╡');
  383.    
  384.     textColor(White);
  385.     gotoXY(7, 8);
  386.     write(langs[9]);
  387.    
  388.     gotoXY(7, 10);
  389.     write(langs[10]);
  390.    
  391.     gotoXY(7, 12);
  392.     write(langs[11]);
  393.    
  394.     gotoXY(7, 14);
  395.     write(langs[12]);
  396.    
  397.     MenuCursor();
  398.    
  399.     if t mod UpdateTime = 0 then
  400.       ClrScr;
  401.   end;
  402.  
  403.   while Game do
  404.   begin
  405.     t := t + 1;
  406.     if KeyPressed then
  407.       Button := ReadKey
  408.     else
  409.       Button := #0;
  410.      
  411.     InitStatistics;
  412.    
  413.     if (ZPressed) and (Ammo > 0) and (ShotVar = 0) then
  414.     begin
  415.       ShotVar := 1;
  416.       Ammo := Ammo - 1;
  417.     end;
  418.     if ShotVar = 1 then
  419.     begin
  420.       Shot;
  421.     end;
  422.     if ShotX >= 80 then
  423.     begin
  424.       ShotVar := 0;
  425.       ShotX := 4;
  426.     end;
  427.     if Ammo <= 0 then
  428.       NoAmmo;
  429.    
  430.     if OPressed then
  431.       CharacterMove(1)
  432.     else if LPressed then
  433.       CharacterMove(2)
  434.     else
  435.       CharacterMove(0);
  436.      
  437.     Character(ChY);
  438.    
  439.     if EnemyOnScreen = false then
  440.     begin
  441.       enY := random(19) + 5;
  442.       EnemyOnScreen := true;
  443.     end;
  444.       TestEnemies;
  445.      
  446.     if Health <= 0 then
  447.     begin
  448.       Menu := true;
  449.       Game := false;
  450.       halt;
  451.     end;
  452.    
  453.     if (ShotX >= EnX) and (ChY = EnY) then
  454.     begin
  455.       EnemyOnScreen := false;
  456.       Score := Score + 10;
  457.       EnX := 79;
  458.     end;
  459.    
  460.     if Score >= 500 then
  461.     begin
  462.       clrScr;
  463.       while true do
  464.       begin
  465.         gotoXY(5, 5);
  466.         textColor(random(2) + 13);
  467.         write(langs[20]);
  468.       end;
  469.     end;
  470.    
  471.     if t mod UpdateTime = 0 then
  472.       clrScr;
  473.   end;  
  474. end;
  475. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement