Changeset 84 for trunk/Engine.pas


Ignore:
Timestamp:
May 17, 2024, 5:16:27 PM (6 weeks ago)
Author:
chronos
Message:
  • Added: A new settings page where number of players can be adjusted.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Engine.pas

    r83 r84  
    169169    function GetAliveCount: Integer;
    170170    function GetWinner: TPlayer;
     171    function GetEnabledCount: Integer;
     172    procedure EnableMore;
     173    procedure EnableLess;
    171174  end;
    172175
     
    198201
    199202  TGameState = (gsMenu, gsGame, gsNewRound, gsMap, gsInformation,
    200     gsInstructions);
     203    gsInstructions, gsSettings);
    201204
    202205  { TEngine }
     
    230233    procedure DrawInformation;
    231234    procedure DrawInstructions;
     235    procedure DrawSettings;
    232236    procedure DrawNewRound;
    233237    procedure DrawMap;
     
    306310  SInformationDetails2 = 'This is a public domain open source program: feel free to copy it for friends and study the source code. \n ' +
    307311    'Homepage: https://app.zdechov.net/Tunneler';
     312  SSettings = 'Settings';
    308313  SWorldReady = 'World ready';
    309314  SExit = 'Exit';
     
    323328  SOrange = 'Orange';
    324329  SGray = 'Gray';
     330  SMorePlayers = 'More players';
     331  SLessPlayers = 'Less players';
     332  SBack = 'Back';
     333  SPlayersCount = 'Players count';
    325334
    326335{ TBullets }
     
    409418    TopScore := Score;
    410419    Result := Items[I];
     420  end;
     421end;
     422
     423function TPlayers.GetEnabledCount: Integer;
     424var
     425  I: Integer;
     426begin
     427  Result := 0;
     428  for I := 0 to Count - 1 do begin
     429    if Items[I].Enabled then Inc(Result);
     430  end;
     431end;
     432
     433procedure TPlayers.EnableMore;
     434var
     435  I: Integer;
     436begin
     437  for I := 0 to Count - 1 do begin
     438    if not Items[I].Enabled then begin
     439      Items[I].Enabled := True;
     440      Break;
     441    end;
     442  end;
     443end;
     444
     445procedure TPlayers.EnableLess;
     446var
     447  I: Integer;
     448begin
     449  if GetEnabledCount > 2 then
     450  for I := Count - 1 downto 0 do begin
     451    if Items[I].Enabled then begin
     452      Items[I].Enabled := False;
     453      Break;
     454    end;
    411455  end;
    412456end;
     
    13011345end;
    13021346
     1347procedure TEngine.DrawSettings;
     1348var
     1349  Text: string;
     1350  MenuWidth: Integer;
     1351begin
     1352  with Bitmap.Canvas do begin
     1353    ClearBackground;
     1354
     1355    if FShowMenuStats then begin
     1356      MenuWidth := Bitmap.Width div 2;
     1357      DrawStats;
     1358    end else MenuWidth := Bitmap.Width;
     1359
     1360    Brush.Style := bsClear;
     1361    Pen.Style := psSolid;
     1362    Pen.Color := clWhite;
     1363    Font.Color := clTuna;
     1364    Font.Size := 30;
     1365    Text := SSettings;
     1366    TextOut((MenuWidth - TextWidth(Text)) div 2, Bitmap.Height div 10, Text);
     1367
     1368    Pen.Color := clPurple;
     1369    Pen.Width := 6;
     1370    Frame((MenuWidth - 400) div 2, Bitmap.Height div 10 * 4 - 40,
     1371      (MenuWidth + 400) div 2, Bitmap.Height div 10 * 4 + 240);
     1372
     1373    Font.Color := clPurple;
     1374    Font.Size := 20;
     1375
     1376    ShowMenuItem('F1', SMorePlayers, MenuWidth div 2 - 180, Bitmap.Height div 10 * 4, Bitmap.Canvas);
     1377    ShowMenuItem('F2', SLessPlayers, MenuWidth div 2 - 180, Bitmap.Height div 10 * 4 + 40, Bitmap.Canvas);
     1378    ShowMenuItem('ESC', SBack, MenuWidth div 2 - 180, Bitmap.Height div 10 * 4 + 80, Bitmap.Canvas);
     1379
     1380    Font.Color := clDarkGreen;
     1381    Font.Size := 20;
     1382    Text := SPlayersCount + ': ' + IntToStr(PlayerPool.GetEnabledCount);
     1383    TextOut((MenuWidth - TextWidth(Text)) div 2, Bitmap.Height div 10 * 6, Text);
     1384  end;
     1385end;
     1386
    13031387procedure TEngine.DrawNewRound;
    13041388var
     
    16491733    Pen.Width := 6;
    16501734    Frame((MenuWidth - 400) div 2, Bitmap.Height div 10 * 4 - 40,
    1651       (MenuWidth + 400) div 2, Bitmap.Height div 10 * 4 + 200);
     1735      (MenuWidth + 400) div 2, Bitmap.Height div 10 * 4 + 240);
    16521736
    16531737    Font.Color := clPurple;
     
    16571741    ShowMenuItem('F2', SInstructions, MenuWidth div 2 - 180, Bitmap.Height div 10 * 4 + 40, Bitmap.Canvas);
    16581742    ShowMenuItem('F3', SInformation, MenuWidth div 2 - 180, Bitmap.Height div 10 * 4 + 80, Bitmap.Canvas);
    1659     ShowMenuItem('F10', SExit, MenuWidth div 2 - 180, Bitmap.Height div 10 * 4 + 120, Bitmap.Canvas);
     1743    ShowMenuItem('F4', SSettings, MenuWidth div 2 - 180, Bitmap.Height div 10 * 4 + 120, Bitmap.Canvas);
     1744    ShowMenuItem('F10', SExit, MenuWidth div 2 - 180, Bitmap.Height div 10 * 4 + 160, Bitmap.Canvas);
    16601745
    16611746    Font.Color := clDarkGreen;
     
    18851970      gsInformation: DrawInformation;
    18861971      gsInstructions: DrawInstructions;
     1972      gsSettings: DrawSettings;
    18871973      gsMap: DrawMap;
    18881974      gsNewRound: DrawNewRound;
     
    19532039  KeyF3 = 114;
    19542040  KeyF4 = 115;
     2041  KeyF5 = 116;
    19552042  KeyF10 = 121;
    19562043  KeyEsc = 27;
     
    19712058      State := gsInformation;
    19722059    end else
     2060    if Key = KeyF4 then begin
     2061      State := gsSettings;
     2062    end else
    19732063    if Key = KeyF10 then begin
    19742064      if Assigned(FOnClose) then FOnClose(Self);
     
    19862076    end;
    19872077  end else
     2078  if State = gsSettings then begin
     2079    if Key = KeyF1 then begin
     2080      PlayerPool.EnableMore;
     2081      Redraw;
     2082    end else
     2083    if Key = KeyF2 then begin
     2084      PlayerPool.EnableLess;
     2085      Redraw;
     2086    end else
     2087    if Key = KeyEsc then begin
     2088      State := gsMenu;
     2089    end;
     2090  end else
    19882091  if State = gsGame then begin
    19892092     if Key = KeyEsc then begin
     
    19932096
    19942097  {$IFDEF DEBUG}
    1995   if (State = gsGame) and (Key = KeyF4) then begin
     2098  if (State = gsGame) and (Key = KeyF5) then begin
    19962099    // Destroy first alive player
    19972100    for I := 0 to Players.Count - 1 do
Note: See TracChangeset for help on using the changeset viewer.