Skip to content

Commit

Permalink
Переход на новую локацию по нажатию на кнопку.
Browse files Browse the repository at this point in the history
  • Loading branch information
devapromix committed Jul 22, 2018
1 parent 13589e6 commit ef5d698
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 20 deletions.
7 changes: 5 additions & 2 deletions sources/BearURQ.Buttons.pas
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ TButtons = class

implementation

uses
SysUtils;

{ TButtons }

procedure TButtons.Append(const ALabel, AName: string);
Expand Down Expand Up @@ -50,8 +53,8 @@ constructor TButtons.Create;

destructor TButtons.Destroy;
begin
FLabelList.Free;
FNameList.Free;
FreeAndNil(FLabelList);
FreeAndNil(FNameList);
inherited;
end;

Expand Down
6 changes: 0 additions & 6 deletions sources/BearURQ.Location.pas
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ TLocation = class(TObject)
property Content: string read FContent write FContent;
procedure Append(const S: string);
procedure Clear;
procedure Render;
end;

implementation
Expand Down Expand Up @@ -43,9 +42,4 @@ destructor TLocation.Destroy;
inherited;
end;

procedure TLocation.Render;
begin

end;

end.
62 changes: 50 additions & 12 deletions sources/BearURQ.Scenes.pas
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ TSceneGame = class(TScene)
constructor Create(AEngine: TEngine);
procedure Render; override;
procedure Update(var Key: Word); override;
procedure Jump(const Index: Integer);
end;

var
Expand All @@ -69,14 +70,14 @@ implementation

{ TScene }

procedure TScene.Print(const X, Y: Word; const S: string);
constructor TScene.Create(AEngine: TEngine);
begin
terminal_print(X, Y, S);
FEngine := AEngine;
end;

constructor TScene.Create(AEngine: TEngine);
procedure TScene.Print(const X, Y: Word; const S: string);
begin
FEngine := AEngine;
terminal_print(X, Y, S);
end;

procedure TScene.Print(const Y: Word; const S: string);
Expand Down Expand Up @@ -170,27 +171,64 @@ constructor TSceneGame.Create(AEngine: TEngine);
inherited Create(AEngine);
end;

// Ïåðåõîä ïî êíîïêå
procedure TSceneGame.Jump(const Index: Integer);
var
CurrButText, CurrLoc: string;
begin
// Ññûëêà íà òåêóùóþ ëîêàöèþ
CurrLoc := Trim(Engine.Buttons.GetLabel(Index));
// Ñîõðàíÿåì â ïåðåìåííîé òåêñò ïîñëåäíåé íàæàòîé êíîïêè
CurrButText := Trim(Engine.Buttons.GetName(Index));
Engine.Vars.SetVarValue('last_btn_caption', CurrButText);
// Ïåðåõîä íà ëîêàöèþ
Engine.Clear;

// Ñîõðàíÿåì â ïåðåìåííûõ èìåíà òåêóùåé è ïîñëåäíåé ëîêàöèé
if (Trim(Engine.Vars.GetVarValue('previous_loc', '')) = '') then
Engine.Vars.SetVarValue('previous_loc', CurrLoc)
else
Engine.Vars.SetVarValue('previous_loc',
Engine.Vars.GetVarValue('current_loc', ''));
Engine.Vars.SetVarValue('current_loc', CurrLoc);
Engine.Location.Title := CurrButText;
Self.Render;
end;

procedure TSceneGame.Render;
var
I: Integer;
I, T: Integer;
begin
//
Print(0, Engine.Location.Title);
T := 0;
// Òåêñò ïîñëåäíåé íàæàòîé êíîïêè
if (Engine.Location.Title <> '') then
begin
T := 2;
Print(0, Engine.Location.Title);
end;
// Ïîêàçûâàåì ñîäåðæèìîå îêíà ëîêàöèè
Print(0, 2, Engine.Location.Content);
Print(0, T, Engine.Location.Content);
// Ïîêàçûâàåì èíâåíòàðü

// Ïîêàçûâàåì âñå êíîïêè íà ëîêàöèè
for I := 0 to Engine.Buttons.Count - 1 do
begin
Print(0, Engine.Terminal.Height - (Engine.Buttons.Count - I), IntToStr(I + 1) + '. ' +
Engine.Buttons.GetName(I));
Print(0, Engine.Terminal.Height - (Engine.Buttons.Count - I),
IntToStr(I + 1) + '. ' + Engine.Buttons.GetName(I));
end;
end;

procedure TSceneGame.Update(var Key: Word);
begin

var
Index: Integer;
begin
case Key of
TK_1 .. TK_9:
begin
Index := Key - TK_1;
Self.Jump(Index);
end;
end;
end;

end.

0 comments on commit ef5d698

Please sign in to comment.