Einzelnen Beitrag anzeigen

Benutzerbild von heel213
heel213

Registriert seit: 23. Jan 2017
Ort: Authority
10 Beiträge
 
#1

Ressourcen pro Sekunde generieren

  Alt 27. Jan 2017, 10:42
Ja moin, hier ist wieder euer Heel.
Und zwar will ich für das "Spiel", welches ich im Rahmen unseres Schulprojekts zusammenbasteln will eine Funktion einbauen, welche Ressourcen/s generiert, bisher habe ich mir das so vorgestellt:
Code:
repeat
      begin
      timer1.enabled:=true;
      Luxusgueter:=Luxusgueter+Luxusgueterproduktion;
      Stein:=Stein+Steinproduktion;
      Nahrung:=Nahrung+Nahrungproduktion;
      Gold:=Gold+Goldproduktion;
      label13.caption:=floattostrf(Stein,fffixed,10,0);
      label14.caption:=floattostrf(luxusgueter,fffixed,10,0);
      label15.caption:=floattostrf(Nahrung,fffixed,10,0);
      label16.caption:=floattostrf(gold,fffixed,10,0);
      label17.caption:=inttostr(einwohner);
      i:=i+1;
      end;
  until i=100000000;
Allerdings musste ich feststellen, dass es erst die Funktion bis zum Ende durchläuft und man dann erst weiterspielen kann.
Die Funktion soll im Optimalfall natürlich nebenher weiterlaufen und den Ressourcenstand immer updaten.
Den ganzen Quelltext findet ihr unten.
Vielen Dank schonmal für die Hilfe,
mit heelischen Grüßen, euer heel213







Code:
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  ExtCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Image1: TImage;
    Label1: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    ScrollBar1: TScrollBar;
    ScrollBar2: TScrollBar;
    ScrollBar3: TScrollBar;
    ScrollBar4: TScrollBar;
    ScrollBar5: TScrollBar;
    Timer1: TTimer;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ScrollBar1Change(Sender: TObject);

    procedure ScrollBar2Change(Sender: TObject);

    procedure ScrollBar3Change(Sender: TObject);

    procedure ScrollBar4Change(Sender: TObject);

    procedure ScrollBar5Change(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);

  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;
  timer1: ttimer;
  Einwohner : UInt64;
  Zusammenrechnung, i: Integer;
  Stein,Nahrung,Luxusgueter,Gold,Goldproduktion, Nahrungproduktion, Steinproduktion, Holzproduktion, Luxusgueterproduktion : real;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.ScrollBar1Change(Sender: TObject);
begin
   Label8.caption:=inttostr(Scrollbar1.position);
end;

procedure TForm1.ScrollBar2Change(Sender: TObject);
begin
    Label9.caption:=inttostr(scrollbar2.position);
end;

procedure TForm1.ScrollBar3Change(Sender: TObject);
begin
   label10.caption:=inttostr(scrollbar3.position);
end;


procedure TForm1.ScrollBar4Change(Sender: TObject);
begin
   label11.caption:=inttostr(scrollbar4.position);
end;

procedure TForm1.ScrollBar5Change(Sender: TObject);
begin
    label12.caption:=inttostr(scrollbar5.position);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
   timer1.Interval:=1000;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Zusammenrechnung:=Scrollbar1.position+Scrollbar2.position+Scrollbar3.position+
  scrollbar4.position+scrollbar5.position;
   If Zusammenrechnung=100 then
  begin
    label6.Visible:=false;
    label7.visible:=false;
    Goldproduktion:=(scrollbar1.position/100)*Einwohner;
    Nahrungproduktion:=(scrollbar2.position/100)*Einwohner;
    Steinproduktion:=(scrollbar3.position/100)*Einwohner;
    Holzproduktion:=(scrollbar4.position/100)*Einwohner;
    Luxusgueterproduktion:=(scrollbar5.position/100)*Einwohner;
  end
  else
  begin
    if Zusammenrechnung<100 then
    begin
      label7.visible:=true;
      label6.visible:=false;
      end
    else
    begin
      label6.visible:=true;
      label7.visible:=false;
      end;
end;
  label18.caption:='Momentane Produktion: Stein='+floattostr(Steinproduktion)+'/s Luxusgüter='+floattostr(Luxusgueterproduktion)+'/s Nahrung='+floattostr(Nahrungproduktion)+'/s Gold='+floattostr(Goldproduktion)+'/s';
  repeat
      begin
      timer1.enabled:=true;
      Luxusgueter:=Luxusgueter+Luxusgueterproduktion;
      Stein:=Stein+Steinproduktion;
      Nahrung:=Nahrung+Nahrungproduktion;
      Gold:=Gold+Goldproduktion;
      label13.caption:=floattostrf(Stein,fffixed,10,0);
      label14.caption:=floattostrf(luxusgueter,fffixed,10,0);
      label15.caption:=floattostrf(Nahrung,fffixed,10,0);
      label16.caption:=floattostrf(gold,fffixed,10,0);
      label17.caption:=inttostr(einwohner);
      i:=i+1;
      end;
  until i=100000000;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  i:=1;
  label6.visible:=false;
  label7.visible:=false;
  Einwohner:=5000;
  end;
end.

end.
Der, der die Company zerstören wird aka der Heelischste von allen.
  Mit Zitat antworten Zitat