Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.12 KB | None | 0 0
  1. program KP;
  2. uses dos,crt;
  3.  
  4. const
  5. ncnt:integer = 222;
  6. notes: array[0..221] of integer =(659, 0,659,  0,659, 0,523, 0,659,  0,784,  0,392,  0,523,  0,392,  0,330,  0,440,  0,494, 0,
  7. 466, 0,440,  0,392, 0,659, 0,784, 0,880,  0,698, 0,784, 0,659,  0,523, 0,587, 0,494,  0,523,  0,392,  0,330,  0,440,  0,494,
  8.   0,466, 0,440,  0,392, 0,659, 0,784, 0,880,  0,698, 0,784, 0,659,  0,523, 0,587, 0,494,  0,
  9.   0,784, 0,740, 0,698, 0,622,  0,659,  0,415, 0,440, 0,523,  0,440, 0,523, 0,587, 0,
  10.   0,784, 0,740, 0,698, 0,622,  0,659,  0,1046,  0,1046, 0,1046,  0,
  11.   0,784, 0,740, 0,698, 0,622,  0,659,  0,415, 0,440, 0,523,  0,440, 0,523, 0,587, 0,
  12.   0,622,  0,587,  0,523,   0,
  13.   0,784, 0,740, 0,698, 0,622,  0,659,  0,415, 0,440, 0,523,  0,440, 0,523, 0,587, 0,
  14.   0,784, 0,740, 0,698, 0,622,  0,659,  0,1046,  0,1046, 0,1046,  0,
  15.   0,784, 0,740, 0,698, 0,622,  0,659,  0,415, 0,440, 0,523,  0,440, 0,523, 0,587, 0,
  16.   0,622,  0,587,  0,523,   0);
  17.  
  18. pause: array[0..221] of integer =(180,20,180,200,360,20,180,20,180,200,360,380,360,380,360,200,180,380,180,380,180,200,180,200,
  19. 180,20,180,200,180,20,180,20,180,20,180,200,180,20,360,20,180,200,180,20,180,20,180,380,360,200,180,380,180,380,180,200,180,
  20. 200,180,20,180,200,180,20,180,20,180,20,180,200,180,20,360,20,180,200,180,20,180,20,180,380,
  21. 360,180,10,180,10,180,10,180,200,180,200,180,20,180,20,180,200,180,20,180,20,180,20,
  22. 360,180,10,180,10,180,10,180,200,180,200, 180,200, 180,20, 180,560,
  23. 360,180,10,180,10,180,10,180,200,180,200,180,20,180,20,180,200,180,20,180,20,180,20,
  24. 360,180,380,180,380,180,1000,
  25. 360,180,10,180,10,180,10,180,200,180,200,180,20,180,20,180,200,180,20,180,20,180,20,
  26. 360,180,10,180,10,180,10,180,200,180,200, 180,200, 180,20, 180,560,
  27. 360,180,10,180,10,180,10,180,200,180,200,180,20,180,20,180,200,180,20,180,20,180,20,
  28. 360,180,380,180,380,180,1000);
  29.  
  30.  
  31.  
  32. var
  33. i:integer;
  34.  
  35. curnote:integer;
  36. play:boolean;
  37. len:integer;
  38.  
  39. PreTime:Longint;
  40.  
  41. Tick:integer;
  42.  
  43. C:char;
  44.  
  45.  
  46. MAINLOOP:boolean;
  47.  
  48.  
  49. function GetMSecs:LongInt;
  50. var
  51. H,M,S,SS:word;
  52. begin
  53. gettime(h,m,s,ss);
  54. GetMSecs:=ss + 100*s + 100*60*m;
  55. end;
  56.  
  57. function GetTicks:LongInt;
  58. var
  59. now:Longint;
  60. begin
  61. now:=GetMsecs;
  62. GetTicks:=abs(now - PreTime);
  63. PreTime:=now;
  64. end;
  65.  
  66.  
  67. procedure UpdateMusic;
  68. begin
  69. if (play) then
  70.    begin
  71.    len:=len-(GetTicks*18);
  72.    if(len <= 0) then
  73.       begin
  74.       curnote:=curnote+1;
  75.       if (curnote >= ncnt) then
  76.          curnote:=0;
  77.       len:=pause[curnote];
  78.       if (notes[curnote] = 0) then
  79.          nosound
  80.       else
  81.          sound (notes[curnote]);
  82.  
  83.       end;
  84.    end;
  85.  
  86. end;
  87.  
  88. procedure PausePlay;
  89. begin
  90. play:= not play;
  91. if (play) then
  92.    begin
  93.      if (notes[curnote] = 0) then
  94.         nosound
  95.      else
  96.         sound(notes[curnote]);
  97.    end
  98. else
  99.    nosound;
  100. end;
  101.  
  102.  
  103. begin
  104.  
  105. PreTime:=GetMSecs;
  106. curnote:=ncnt;
  107. len:=0;
  108. play:=true;
  109. MAINLOOP:=true;
  110.  
  111. while( MAINLOOP ) do
  112. begin
  113.  
  114. UpdateMusic;
  115.  
  116. if (KeyPressed) then
  117.    begin
  118.         C:=ReadKey;
  119.         if (C = #0) then C:=ReadKey;
  120.         writeln(ord(C));
  121.  
  122.         if (C = #$20) then PausePlay;
  123.         if (C = #$1B) then MAINLOOP:=false;
  124.    end;
  125. Delay(10);
  126. end;
  127.  
  128. nosound;
  129.  
  130.  
  131.  
  132. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement