Загрузка данных


program Roulette;

uses SysUtils;

var
  balance, bet, result: Integer;
  choice: string;
  color: string;
  win: Boolean;
  red: array[1..18] of Integer = (1,3,5,7,9,12,14,16,18,19,21,23,25,27,30,32,34,36);
  i: Integer;
  isRed: Boolean;

function IsRedNumber(num: Integer): Boolean;
var
  j: Integer;
begin
  IsRedNumber := False;
  for j := 1 to 18 do
    if red[j] = num then
    begin
      IsRedNumber := True;
      Exit;
    end;
end;

begin
  Randomize;
  balance := 100;
  WriteLn('Добро пожаловать в рулетку! Баланс: ', balance);

  while balance > 0 do
  begin
    WriteLn;
    WriteLn('Баланс: ', balance);
    Write('Ставка (число): ');
    ReadLn(bet);

    if (bet <= 0) or (bet > balance) then
    begin
      WriteLn('Некорректная ставка');
      Continue;
    end;

    Write('На что ставим? (число 0-36 / red / black / even / odd): ');
    ReadLn(choice);
    choice := LowerCase(choice);

    result := Random(37); // 0..36

    isRed := IsRedNumber(result);
    if result = 0 then
      color := 'green'
    else if isRed then
      color := 'red'
    else
      color := 'black';

    WriteLn('Выпало: ', result, ' (', color, ')');

    win := False;

    if (TryStrToInt(choice, i)) and (i = result) then
    begin
      balance := balance + bet * 35;
      win := True;
    end
    else if (choice = 'red') and (color = 'red') then
    begin
      balance := balance + bet;
      win := True;
    end
    else if (choice = 'black') and (color = 'black') then
    begin
      balance := balance + bet;
      win := True;
    end
    else if (choice = 'even') and (result <> 0) and (result mod 2 = 0) then
    begin
      balance := balance + bet;
      win := True;
    end
    else if (choice = 'odd') and (result mod 2 = 1) then
    begin
      balance := balance + bet;
      win := True;
    end;

    if win then
      WriteLn('Выигрыш!')
    else
    begin
      balance := balance - bet;
      WriteLn('Проигрыш');
    end;
  end;

  WriteLn('Баланс закончился. Игра окончена.');
end.