This repository has been archived on 2024-12-25. You can view files and clone it, but cannot push or open issues or pull requests.
OldPascalProjects/Games/Matches.pas
2024-03-10 20:32:51 +03:00

46 lines
1.1 KiB
ObjectPascal
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Игра "Спички"
const InitialCount=15;
var
/// Текущее количество спичек
Count: integer;
/// Количество спичек, которое берет игрок
Num: integer;
/// Номер текущего игрока
Player: integer;
begin
Player := 1;
Count := InitialCount;
repeat
if Player=1 then
begin
var Correct: boolean;
repeat
Write('Ваш ход. На столе ',Count,' спичек. ');
Write('Сколько спичек Вы берете? ');
Readln(Num);
Correct := (Num>=1) and (Num<=3) and (Num<=Count);
if not Correct then
writeln('Неверно! Повторите ввод!');
until Correct;
end
else
begin
Num := Random(1,3);
if Num>Count then
Num := Count;
Writeln('Мой ход. Я взял ',Num,' спичек');
end;
Count -= Num;
if Player=1 then
Player := 2
else Player := 1;
until Count=0;
if Player=1 then
Writeln('Вы победили!')
else Writeln('Вы проиграли!');
end.