fork(1) download
  1. uses crt;
  2.  
  3. label
  4. habis, lanjut;
  5.  
  6. const
  7. max_panjang = 100;
  8. batas_x = 80;
  9. batas_y = 25;
  10. speed = 200;
  11.  
  12. type
  13. tempat = record
  14. x, y : integer;
  15. end;
  16.  
  17. var
  18. ekor : array[1..max_panjang] of tempat;
  19. ujung, makanan : tempat;
  20. tkn : char;
  21. i,pjg,skor,spd : integer;
  22. mati : boolean;
  23.  
  24. procedure atur_posisi;
  25. begin
  26. ujung.x := ekor[pjg].x;
  27. ujung.y := ekor[pjg].y;
  28. for i:=pjg downto 2 do begin
  29. ekor[i].x := ekor[i-1].x;
  30. ekor[i].y := ekor[i-1].y;
  31. end;
  32. gotoxy(ekor[2].x, ekor[2].y); write('@');
  33. gotoxy(ekor[3].x, ekor[3].y); write('&');
  34. gotoxy(ekor[pjg-1].x, ekor[pjg-1].y); write('#');
  35. gotoxy(ujung.x, ujung.y); write(' ');
  36. for i:=3 to pjg do if((ekor[2].x=ekor[i].x) and (ekor[2].y=ekor[i].y)) then mati:=true;
  37. delay(speed-spd);
  38. end;
  39.  
  40. procedure makan;
  41. var beda : boolean;
  42. begin
  43. inc(skor,5);
  44. gotoxy(10,26); write('Skor = ',skor);
  45. repeat
  46. beda := true;
  47. makanan.x := random(batas_x-2)+2;
  48. makanan.y := random(batas_y-2)+2;
  49. for i:=1 to pjg do
  50. if((makanan.x=ekor[i].x) and (makanan.y=ekor[i].y)) then beda:=false;
  51. until beda;
  52. gotoxy(makanan.x, makanan.y); write('o');
  53. inc(pjg);
  54. inc(spd,2);
  55. end;
  56.  
  57. procedure bergerak(c : char);
  58. begin
  59. if c = 'd' then begin
  60. repeat
  61. if((ekor[1].x = makanan.x) and (ekor[1].y = makanan.y)) then makan;
  62. ekor[1].x := ekor[1].x+1;
  63. atur_posisi;
  64. if (ekor[1].x = batas_x) or (ekor[1].y = batas_y) or (ekor[1].x = 1) or (ekor[1].y = 1) then mati := true;
  65. until keypressed or mati;
  66. if mati then exit;
  67. tkn:=readkey;
  68. if tkn = 'a' then tkn:='d';
  69. end
  70. else if c = 's' then begin
  71. repeat
  72. if((ekor[1].x = makanan.x) and (ekor[1].y = makanan.y)) then makan;
  73. ekor[1].y := ekor[1].y+1;
  74. atur_posisi;
  75. if (ekor[1].x = batas_x) or (ekor[1].y = batas_y) or (ekor[1].x = 1) or (ekor[1].y = 1) then mati := true;
  76. until keypressed or mati;
  77. if mati then exit;
  78. tkn:=readkey;
  79. if tkn = 'w' then tkn:='s';
  80. end
  81. else if c = 'w' then begin
  82. repeat
  83. if((ekor[1].x = makanan.x) and (ekor[1].y = makanan.y)) then makan;
  84. ekor[1].y := ekor[1].y-1;
  85. atur_posisi;
  86. if (ekor[1].x = batas_x) or (ekor[1].y = batas_y) or (ekor[1].x = 1) or (ekor[1].y = 1) then mati := true;
  87. until keypressed or mati;
  88. if mati then exit;
  89. tkn:=readkey;
  90. if tkn = 's' then tkn:='w';
  91. end
  92. else if c = 'a' then begin
  93. repeat
  94. if((ekor[1].x = makanan.x) and (ekor[1].y = makanan.y)) then makan;
  95. ekor[1].x := ekor[1].x-1;
  96. atur_posisi;
  97. if (ekor[1].x = batas_x) or (ekor[1].y = batas_y) or (ekor[1].x = 1) or (ekor[1].y = 1) then mati := true;
  98. until keypressed or mati;
  99. if mati then exit;
  100. tkn:=readkey;
  101. if tkn = 'd' then tkn:='a';
  102. end;
  103. end;
  104.  
  105. begin
  106. tkn:='d';
  107. mati := false;
  108. randomize;
  109. pjg := 10; spd := 0;
  110. makanan.x := random(batas_x-2)+2;
  111. makanan.y := random(batas_y-2)+2;
  112. ekor[1].x := 40;
  113. ekor[1].y := 3;
  114. for i:=2 to pjg do begin
  115. ekor[i].x := ekor[i-1].x;
  116. ekor[i].y := 3;
  117. end;
  118. lanjut:
  119. clrscr;
  120. gotoxy(10,26); write('Skor = ',skor);
  121. for i:=1 to 80 do begin
  122. gotoxy(i,1); write('-');
  123. gotoxy(i,25); write('-');
  124. end;
  125. for i:=2 to 24 do begin
  126. gotoxy(1,i); write('|');
  127. gotoxy(80,i); write('|');
  128. end;
  129. for i:=1 to pjg do begin
  130. gotoxy(ekor[i].x, ekor[i].y);
  131. write('&');
  132. end;
  133. gotoxy(makanan.x, makanan.y); write('o');
  134. repeat
  135. if((tkn='w') or (tkn='a') or (tkn='s') or (tkn='d')) then bergerak(tkn)
  136. else begin
  137. repeat
  138. gotoxy(20,10); write(' Lagi Galau..??');
  139. gotoxy(20,11); write(' ..Paused Game..');
  140. repeat
  141. gotoxy(20,13); write('..Press w, a, s or d to lanjut..'); delay(200);
  142. gotoxy(20,13); write(' '); delay(200);
  143. until keypressed;
  144. tkn:=readkey;
  145. until((tkn='w') or (tkn='a') or (tkn='s') or (tkn='d')); goto lanjut;
  146. end;
  147. if mati then goto habis;
  148. until (tkn = #27) or mati;
  149.  
  150. habis:
  151. gotoxy(20,10); write(' Lagi Galau..??');
  152. gotoxy(20,11); write(' ..Paramex obatnya..');
  153. gotoxy(20,12); write(' ..wkwkwkwkwk..');
  154. readln;
  155. end.
  156.  
Time limit exceeded #stdin #stdout 5s 616KB
stdin
Standard input is empty
stdout
Skor = 0----------------------------------------------------------------------------------------------------------------------------------------------------------------||
||
||
||
||
||
||
||
||
||
||
||
||
||
||
||
||
||
||
||
||
||
||&&&&&&&&&&o@&#            Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..                                           Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..                                           Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..                                           Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..                                           Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..                                           Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..                                           Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..                                           Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..                                           Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..                                           Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..                                           Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..                                           Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..                                           Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..                                           Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..                                           Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..                                           Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..                                           Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..                                           Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..                                           Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..                                           Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..                                           Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..                                           Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..                                           Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..                                           Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..                                           Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..                                           Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..                                           Lagi Galau..??
          ..Paused Game....Press w, a, s or d to lanjut..