Advertisement
Guest User

zgadywanka

a guest
Aug 21st, 2011
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.75 KB | None | 0 0
  1. program zgadywanka3;
  2. uses Crt;
  3.  
  4. var
  5.   liczba: integer;
  6.   liczbaGracza: integer;
  7.   przedzial: integer;
  8.   liczbaProb: integer;
  9.   dzialanie: boolean;
  10. procedure policzProby(a:integer);
  11. begin
  12.    if a = 9 then
  13.    begin
  14.         Writeln('Skoczyly Ci sie proby, przegrales.');
  15.         dzialanie:= false;
  16.    end
  17. end;
  18. function sprawdzLiczbe(a,b:integer):string;
  19. begin
  20.      if a > b then
  21.      begin
  22.           Result:='Podana liczba jest za duza';
  23.           Inc(liczbaProb);
  24.      end;
  25.      if a < b then
  26.      begin
  27.           Result:='Podana liczba jest za mala';
  28.           Inc(liczbaProb);
  29.      end;
  30.      if a = b then
  31.         begin
  32.         Result:='Brawo ! To jest ta liczba!';
  33.         Inc(liczbaProb);
  34.         dzialanie:= false;
  35.      end;
  36. end;
  37. function ustalPrzedzial(a:integer):integer;
  38. begin
  39.      randomize;
  40.      case a of
  41.           1:
  42.             Result:=random(11);
  43.           2:
  44.             Result:=random(21);
  45.           3:
  46.             Result:=random(31);
  47.      end;
  48. end;
  49. begin
  50.      liczbaProb:=0;
  51.      dzialanie:= true;
  52.      Writeln('Witam w zgadywance liczbowej! Program wlasnie wylosowal liczbe z wybranego przez Ciebie przedzialo.');
  53.      Writeln('Twoim zadaniem jest odgadnac ta liczbe w 10 probach na podstawie wskazowek podanych przez komputer.');
  54.      Writeln('Podaj z jakiego przedzialu chcesz zgadywac liczbe:');
  55.      Writeln('1. 1-10');
  56.      Writeln('2. 1-20');
  57.      Writeln('3. 1-30');
  58.      read(przedzial);
  59.      liczba:=ustalPrzedzial(przedzial);
  60.      repeat
  61.            Writeln('Liczba prob: ', liczbaProb);
  62.            Writeln('Podaj liczbe: ');
  63.            read(liczbaGracza);
  64.            policzProby(liczbaProb);
  65.            writeln(sprawdzLiczbe(liczbaGracza,liczba));
  66.      until dzialanie = false;
  67.      readkey;
  68. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement