Files
Guessing-game/Guessing.pas
T

127 lines
2.5 KiB
ObjectPascal
Raw Normal View History

2018-06-16 14:57:41 +02:00
program Guessing;
2018-06-19 19:28:18 +02:00
uses crt;
2018-06-16 14:57:41 +02:00
var myRnd, entry, i, choice : integer;
2018-06-19 19:28:18 +02:00
dialog : string;
2018-06-16 14:57:41 +02:00
procedure Easy;
begin
randomize();
myRnd := random(100);
writeln('Take a guess');
i := 1;
for i := 1 to 10 do
begin
readln(entry);
if (entry = myRnd) then
begin
writeln('BINGO!!!!');
2018-06-19 20:44:01 +02:00
break;
2018-06-16 14:57:41 +02:00
end
else
if (entry < myRnd) and (i <> 10) then
begin
write('aim higher');
end
else
if (entry > myRnd) and (i <> 10) then
begin
write('aim lower');
end;
end;
2018-06-19 20:44:01 +02:00
if (i = 10) then
begin
writeln('GAME OVER!');
end;
2018-06-19 19:28:18 +02:00
writeln();
writeln('Do you want to retry? [Y/N]');
readln(dialog);
2018-06-16 14:57:41 +02:00
end;
procedure Medium;
begin
randomize();
myRnd := random(100);
writeln('Take a guess');
i := 1;
for i := 1 to 5 do
begin
readln(entry);
if (entry = myRnd) then
begin
writeln('BINGO!!!!');
2018-06-19 20:44:01 +02:00
break;
2018-06-16 14:57:41 +02:00
end
else
if (entry < myRnd) and (i <> 5) then
begin
write('aim higher');
end
else
if (entry > myRnd) and (i <> 5) then
begin
write('aim lower');
end;
end;
2018-06-19 20:44:01 +02:00
if (i = 5) then
begin
writeln('GAME OVER!');
end;
2018-06-19 19:28:18 +02:00
writeln();
writeln('Do you want to retry? [Y/N]');
readln(dialog);
2018-06-16 14:57:41 +02:00
end;
procedure Hard;
begin
randomize();
myRnd := random(100);
writeln('Take a guess');
i := 1;
for i := 1 to 3 do
begin
readln(entry);
if (entry = myRnd) then
begin
writeln('BINGO!!!!');
2018-06-19 20:44:01 +02:00
break;
2018-06-16 14:57:41 +02:00
end
else
if (entry < myRnd) and (i <> 3) then
begin
write('aim higher');
end
else
if (entry > myRnd) and (i <> 3) then
begin
write('aim lower');
end;
end;
2018-06-19 20:44:01 +02:00
if (i = 3) then
begin
write('GAME OVER!');
end;
2018-06-19 19:28:18 +02:00
writeln();
writeln('Do you want to retry? [Y/N]');
readln(dialog);
2018-06-16 14:57:41 +02:00
end;
begin
writeln('Hi and welcome to my first guessing game :)');
writeln('the program will pick a random number between 1 and 100 and you have to guess it');
writeln('Good luck!');
2018-06-19 19:28:18 +02:00
readln();
repeat
clrscr;
writeln('Select Difficulty');
writeln('[1] Press 1 for Easy mode (10 tries)');
writeln('[2] Press 2 for Medium mode (5 tries)');
writeln('[3] Press 3 for Hard mode (3 tries)');
readln(choice);
case (choice) of
1 : Easy;
2 : Medium;
3 : Hard;
end;
until (dialog = 'n') or (dialog = 'N');
2018-06-16 14:57:41 +02:00
end.