Unconfigured Ad Widget

Collapse

Anúncio

Collapse
No announcement yet.

[ Avancado ] Criei um Jogo de Carro no Delphi !

Collapse
X
 
  • Filter
  • Tempo
  • Show
Clear All
new posts

  • Font Size
    #1

    Delphi [ Avancado ] Criei um Jogo de Carro no Delphi !

    unit FrmTopCar;

    interface

    uses
    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
    StdCtrls, Spin, ExtCtrls, Gauges;

    type
    TForm1 = class(TForm)
    Timer1: TTimer;
    Carro1: TImage;
    Piloto: TImage;
    Carro2: TImage;
    Carro3: TImage;
    Carro4: TImage;
    Carro5: TImage;
    Carro6: TImage;
    Carro7: TImage;
    Image9: TImage;
    Image10: TImage;
    Timer2: TTimer;
    Timer3: TTimer;
    Timer4: TTimer;
    Timer5: TTimer;
    Timer6: TTimer;
    Timer7: TTimer;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    BatidoVerde: TImage;
    BatidoAzul: TImage;
    BomVerde: TImage;
    BomAzul: TImage;
    Label3: TLabel;
    Pista1: TImage;
    Timer8: TTimer;
    VermelhoBatido: TImage;
    VermelhoBom: TImage;
    Largada: TImage;
    Gauge1: TGauge;
    Label6: TLabel;
    Trofel: TImage;
    Label4: TLabel;
    VoltasCompletas: TLabel;
    CheckBox1: TCheckBox;
    procedure Timer1Timer(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure Timer3Timer(Sender: TObject);
    procedure Timer4Timer(Sender: TObject);
    procedure Timer5Timer(Sender: TObject);
    procedure Timer6Timer(Sender: TObject);
    procedure Timer7Timer(Sender: TObject);
    procedure Label3Click(Sender: TObject);
    procedure Timer8Timer(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    private
    { Private declarations }
    public
    procedure Fase;
    end;

    var
    Form1: TForm1;
    C1: integer;
    C2: integer;
    C3: integer;
    C4: integer;
    C5: integer;
    C6: integer;
    C7: integer;
    V1: integer;
    V2: integer;
    V3: integer;
    V4: integer;
    V5: integer;
    V6: integer;
    V7: integer;
    Pontos: integer;
    Velocidade: Integer;
    Voltas: integer;
    Completas: integer;

    implementation
    uses unit2;
    {$R *.DFM}

    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
    if carro1.Top >= 360 then//Se chegou ao final da pista.
    begin
    if carro1.Visible = true then Fase;//sSe estiver visível marca ponto.
    carro1.Top := -32;//Move para o inicio da pista.
    c1 := random(2);//Passagem Randônica.
    if CheckBox1.Checked = true then c1 := 1;// Força o carrinho estar sempre vivível.
    if (C1 = 1) then carro1.Visible := true else carro1.Visible := false;//Passagem Randônica.
    V1 := random(100); //proteção para não zerar propriedade Interval.
    IF V1 < Velocidade then V1 := Velocidade + 1; //proteção para não zerar propriedade Interval.
    timer1.Interval := v1;//proteção para não zerar propriedade Interval.
    end;
    if (carro1.Top >= 264) and (carro1.Top <= 328) and (piloto.Left = 32) and
    (carro1.Visible = true) then //Se está na frente, atrás ou aos lados do piloto.
    begin
    timer1.Enabled := false;// Desativa o Timer porque bateu.
    carro1.Picture := BatidoAzul.Picture;// Coloca figura de batida no concorrente.
    piloto.Picture := BatidoVerde.Picture;// Coloca figura de batida no piloto.
    Velocidade := -30; //Inverte o sentido do movimento dos concorrentes.
    end;
    carro1.Top := carro1.Top + Velocidade;//produz o movimento para baixo.
    end;

    procedure TForm1.Timer2Timer(Sender: TObject);
    begin
    if carro2.Top >= 360 then
    begin
    if carro2.Visible = true then Fase;
    carro2.Top := -32;
    c2 := random(2);
    if CheckBox1.Checked = true then c2 := 1;
    if (C2 = 1) then carro2.Visible := true else carro2.Visible := false;
    V2 := random(100);
    IF V2 < Velocidade then V2 := Velocidade + 1;
    timer2.Interval := v2;
    end;
    if (carro2.Top >= 264) and (carro2.Top <= 328) and (piloto.Left = 64) and
    (carro2.Visible = true) then
    begin
    timer2.Enabled := false;
    carro2.Picture := VermelhoBatido.Picture;
    piloto.Picture := BatidoVerde.Picture;
    Velocidade := -30;
    end;
    carro2.Top := carro2.Top + Velocidade;
    end;

    procedure TForm1.Timer3Timer(Sender: TObject);
    begin
    if carro3.Top >= 360 then
    begin
    if carro3.Visible = true then Fase;
    carro3.Top := -32;
    c3 := random(2);
    if CheckBox1.Checked = true then c3 := 1;
    if (C3 = 1) then carro3.Visible := true else carro3.Visible := false;
    V3 := random(100);
    IF V3 < Velocidade then V3 := Velocidade + 1;
    timer3.Interval := v3;
    end;
    if (carro3.Top >= 264) and (carro3.Top <= 328) and (piloto.Left = 96) and
    (carro3.Visible = true) then
    begin
    timer3.Enabled := false;
    carro3.Picture := BatidoAzul.Picture;
    piloto.Picture := BatidoVerde.Picture;
    Velocidade := -30;
    end;
    carro3.Top := carro3.Top + Velocidade;
    end;

    procedure TForm1.Timer4Timer(Sender: TObject);
    begin
    if carro4.Top >= 360 then
    begin
    if carro4.Visible = true then Fase;
    carro4.Top := -32;
    c4 := random(2);
    if CheckBox1.Checked = true then c4 := 1;
    if (C4 = 1) then carro4.Visible := true else carro4.Visible := false;
    V4 := random(100);
    IF V4 < Velocidade then V4 := Velocidade + 1;
    timer4.Interval := v4;
    end;
    if (carro4.Top >= 264) and (carro4.Top <= 328) and (piloto.Left = 128) and
    (carro4.Visible = true) then
    begin
    timer4.Enabled := false;
    carro4.Picture := BatidoAzul.Picture;
    piloto.Picture := BatidoVerde.Picture;
    Velocidade := -30;
    end;
    carro4.Top := carro4.Top + Velocidade;
    end;

    procedure TForm1.Timer5Timer(Sender: TObject);
    begin
    if carro5.Top >= 360 then
    begin
    if carro5.Visible = true then Fase;
    carro5.Top := -32;
    c5 := random(2);
    if CheckBox1.Checked = true then c5 := 1;
    if (C5 = 1) then carro5.Visible := true else carro5.Visible := false;
    V5 := random(100);
    IF V5 < Velocidade then V5 := Velocidade + 1;
    timer5.Interval := v5;
    end;
    if (carro5.Top >= 264) and (carro5.Top <= 328) and (piloto.Left = 160) and
    (carro5.Visible = true) then
    begin
    timer5.Enabled := false;
    carro5.Picture := VermelhoBatido.Picture;
    piloto.Picture := BatidoVerde.Picture;
    Velocidade := -30;
    end;
    carro5.Top := carro5.Top + Velocidade;
    end;

    procedure TForm1.Timer6Timer(Sender: TObject);
    begin
    if carro6.Top >= 360 then
    begin
    if carro6.Visible = true then Fase;
    carro6.Top := -32;
    c6 := random(2);
    if CheckBox1.Checked = true then c6 := 1;
    if (C6 = 1) then carro6.Visible := true else carro6.Visible := false;
    V6 := random(100);
    IF V6 < Velocidade then V6 := Velocidade + 1;
    timer6.Interval := v6;
    end;
    if (carro6.Top >= 264) and (carro6.Top <= 328) and (piloto.Left = 192) and
    (carro6.Visible = true) then
    begin
    timer6.Enabled := false;
    carro6.Picture := BatidoAzul.Picture;
    piloto.Picture := BatidoVerde.Picture;
    Velocidade := -30;
    end;
    carro6.Top := carro6.Top + Velocidade;
    end;

    procedure TForm1.Timer7Timer(Sender: TObject);
    begin
    if carro7.Top >= 360 then
    begin
    if carro7.Visible = true then Fase;
    carro7.Top := -32;
    c7 := random(2);
    if CheckBox1.Checked = true then c7 := 1;
    if (C7 = 1) then carro7.Visible := true else carro7.Visible := false;
    V7 := random(100);
    IF V7 < Velocidade then V7 := Velocidade + 1;
    timer7.Interval := v7;
    end;
    if (carro7.Top >= 264) and (carro7.Top <= 328) and (piloto.Left = 224) and
    (carro7.Visible = true) then
    begin
    timer7.Enabled := false;
    carro7.Picture := BatidoAzul.Picture;
    piloto.Picture := BatidoVerde.Picture;
    Velocidade := -30;
    end;
    carro7.Top := carro7.Top + Velocidade;
    end;

    procedure TForm1.Fase;
    begin
    if (timer1.Enabled = false) or (timer2.Enabled = false) or
    (timer3.Enabled = false) or (timer4.Enabled = false) or
    (timer5.Enabled = false) or (timer6.Enabled = false) or
    (timer7.Enabled = false) then exit;
    case Velocidade of
    5: pontos := pontos + 1;
    10: pontos := pontos + 2;
    15: pontos := pontos + 4;
    20: pontos := pontos + 8;
    25: pontos := pontos + 16;
    30: pontos := pontos + 32;
    35: pontos := pontos + 64;
    40: pontos := pontos + 64;
    end;
    label1.Caption := 'Pontos: ' + inttostr(pontos);
    end;

    procedure TForm1.Label3Click(Sender: TObject);
    begin
    carro1.Picture := BomAzul.Picture;
    carro2.Picture := VermelhoBom.Picture;
    carro3.Picture := BomAzul.Picture;
    carro4.Picture := BomAzul.Picture;
    carro5.Picture := VermelhoBom.Picture;
    carro6.Picture := BomAzul.Picture;
    carro7.Picture := BomAzul.Picture;
    piloto.Picture := BomVerde.Picture;
    carro1.Top := 0;
    carro2.Top := 0;
    carro3.Top := 0;
    carro4.Top := 0;
    carro5.Top := 0;
    carro6.Top := 0;
    carro7.Top := 0;
    carro1.Visible := true;
    carro2.Visible := true;
    carro3.Visible := true;
    carro4.Visible := true;
    carro5.Visible := true;
    carro6.Visible := true;
    carro7.Visible := true;
    timer1.Enabled := false;
    timer2.Enabled := false;
    timer3.Enabled := false;
    timer4.Enabled := false;
    timer5.Enabled := false;
    timer6.Enabled := false;
    timer7.Enabled := false;
    timer8.Enabled := false;
    Velocidade := 5;
    pontos := 0;
    label1.Caption := 'Pontos: 0';
    label2.Caption := '1° Marcha';
    voltascompletas.Caption := 'Voltas 0/10';
    largada.Top := 264;
    voltas := 0;
    largada.Visible := true;
    trofel.visible := false;
    completas := 0;
    Gauge1.Progress := 0;
    Randomize;
    end;

    procedure TForm1.Timer8Timer(Sender: TObject);
    begin
    if voltas = 1600 then
    begin
    timer8.Enabled := false;
    trofel.Visible := true;
    largada.top := 264;
    Velocidade := -30;

    end;
    if pista1.Top >= 368 then pista1.top := -72;
    if (timer1.Enabled = false) or (timer2.Enabled = false) or
    (timer3.Enabled = false) or (timer4.Enabled = false) or
    (timer5.Enabled = false) or (timer6.Enabled = false) or
    (timer7.Enabled = false) then timer8.Enabled := false;
    pista1.top := pista1.Top + Velocidade * 2;
    voltas := voltas + 1;
    //testar final do jogo
    if largada.Top >= 376 then largada.Visible := false;
    if (voltas = 200) or (voltas = 400) or (voltas = 600) or
    (voltas = 800) or (voltas = 1000) or (voltas = 1200) or
    (voltas = 1300) or (voltas = 1400) or (voltas = 1500) or
    (voltas = 1600) then
    begin
    largada.Top := 0;
    largada.Visible := true;
    completas := completas + 1;
    VoltasCompletas.Caption := 'Voltas ' + inttostr(completas) + '/10';
    end;
    largada.Top := Largada.Top + Velocidade * 2;
    gauge1.Progress := voltas;
    end;



    procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
    begin
    if (timer1.Enabled = false) and (timer2.Enabled = false) and
    (timer3.Enabled = false) and (timer4.Enabled = false) and
    (timer5.Enabled = false) and (timer6.Enabled = false) and
    (timer7.Enabled = false) then
    begin
    Randomize;
    timer1.Interval := random(100);
    timer2.Interval := random(100);
    timer3.Interval := random(100);
    timer4.Interval := random(100);
    timer5.Interval := random(100);
    timer6.Interval := random(100);
    timer7.Interval := random(100);
    timer1.Enabled := true;
    timer2.Enabled := true;
    timer3.Enabled := true;
    timer4.Enabled := true;
    timer5.Enabled := true;
    timer6.Enabled := true;
    timer7.Enabled := true;
    timer8.Enabled := true;
    Velocidade := 5;
    exit;
    end;

    if (key = 'n') or (key = 'N') then Label3Click(Sender);
    if (timer1.Enabled = false) or (timer2.Enabled = false) or
    (timer3.Enabled = false) or (timer4.Enabled = false) or
    (timer5.Enabled = false) or (timer6.Enabled = false) or
    (timer7.Enabled = false) then exit;
    if (piloto.Left > 32) and (key = '4') then piloto.Left := piloto.Left - 32;
    if (piloto.Left < 224) and (key = '6') then piloto.Left := piloto.Left + 32;
    if (Velocidade <= 35) and (key = '8') then Velocidade := Velocidade + 5;
    if (Velocidade >=5 ) and (key = '5') then Velocidade := Velocidade - 10;
    if Velocidade <= 0 then Velocidade := 5;
    //if Velocidade < 5 then Velocidade := 5;
    timer8.Interval := Velocidade + 2;
    case Velocidade of
    5: label2.Caption := '1° Marcha';
    10: label2.Caption := '2° Marcha';
    15: label2.Caption := '3° Marcha';
    20: label2.Caption := '4° Marcha';
    25: label2.Caption := '5° Marcha';
    30: label2.Caption := '6° Marcha';
    35: label2.Caption := 'Turbo';
    40: label2.Caption := 'Super Turbo';
    end;
    end;

    end.
    Acima eu citei o codigo, entao os interessados modifiquem , facam a esculhambacao ae e depois postem o resultado .

    Creditos Pelo Jogo : Lucasss

    Att,
    ex_SheL$
    Last edited by .IndependentResearch.; 18-12-2009, 19:32.

  • Font Size
    #2
    UAShahsuahsas
    rox ^^

    Comment


    • Font Size
      #3
      Era pra vc postar o jogo e o código man...
      Só uma sugestão ai
      sigpic

      Comment


      • Font Size
        #4
        Cup1m , eu escrevi errado cara , não fui eu que criei , eu escrevi errado no título , era para ser , Crie um Jogo de Carro no Delphi , hehe .

        Comment

        X
        Working...
        X