Entri Populer

Jumat, 27 April 2012

Game Ular tangga

unit ulartangga;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, jpeg;

type
pemain = class
    nama: string;
    nyawa: integer;
    posisi: integer;
    end;

  kotak = class
  status: integer;
  step: integer;
  posx: integer;
  posy: integer;
  end;

  TForm1 = class(TForm)
    Image1: TImage;
    Label1: TLabel;
    Shape1: TShape;
    Shape2: TShape;
    Button1: TButton;
    RadioGroup1: TRadioGroup;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    Button3: TButton;
    Timer1: TTimer;
    Timer2: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  aku: pemain;
  kamu: pemain;
  dadu: integer;
  papan: array [0..99] of kotak;
  tujuanku: integer;
  tujuanmu: integer;
  tanda: integer;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
begin
  tanda:=0;
  dadu:=0;
  tujuanku:=0;
  tujuanmu:=0;
  aku:=pemain.Create;
  aku.posisi:=0;
  kamu:= pemain.Create;
  kamu.posisi:=0;
   for i:=0 to 99 do
   begin
      papan[i]:=kotak.Create;
      if (((i div 10) mod 2) = 0) then
        papan[i].posx:=(i mod 10)*70+30
      else
        papan[i].posx:=670 - (i mod 10)*70;

      if (i>=0) and (i<10) then
        papan[i].posy:=660
      else if (i>=10) and (i<20) then
        papan[i].posy:=590
      else if (i>=20) and (i<30) then
        papan[i].posy:=520
      else if (i>=30) and (i<40) then
        papan[i].posy:=450
      else if (i>=40) and (i<50) then
        papan[i].posy:=380
      else if (i>=50) and (i<60) then
        papan[i].posy:=310
      else if (i>=60) and (i<70) then
        papan[i].posy:=240
      else if (i>=70) and (i<80) then
        papan[i].posy:=170
      else if (i>=80) and (i<90) then
        papan[i].posy:=100
      else if (i>=90) and (i<100) then
        papan[i].posy:=30;

      papan[i].status:=0;
      papan[i].step:=0;
   end;
  papan[5].status:=1;
  papan[5].step:=52;
  papan[9].status:=1;
  papan[9].step:=11;
  papan[15].status:=1;
  papan[15].step:=45;
  papan[19].status:=1;
  papan[19].step:=1;
  papan[20].status:=1;
  papan[20].step:=58;
  papan[23].status:=1;
  papan[23].step:=2;
  papan[29].status:=1;
  papan[29].step:=7;
  papan[36].status:=1;
  papan[36].step:=80;
  papan[49].status:=1;
  papan[49].step:=27;
  papan[50].status:=1;
  papan[50].step:=71;
  papan[53].status:=1;
  papan[53].step:=25;
  papan[55].status:=1;
  papan[55].step:=85;
  papan[76].status:=1;
  papan[76].step:=94;
  papan[78].status:=1;
  papan[78].step:=38;
  papan[82].status:=1;
  papan[82].step:=65;
  papan[87].status:=1;
  papan[87].step:=65;
  papan[89].status:=1;
  papan[89].step:=91;
  papan[93].status:=1;
  papan[93].step:=70;
  papan[96].status:=1;
  papan[96].step:=44;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  randomize;
  dadu:= random(6)+1;
  label1.Caption:= inttostr(dadu);
  if(radiobutton1.Checked)then
  begin
      tujuanku:=aku.posisi+dadu;
  end
  else
  begin
      tujuanmu:=kamu.posisi+dadu;
  end;
  timer2.Enabled:=true;
  Button1.Enabled:=false;
  radiobutton1.Enabled:=false;
  radiobutton2.Enabled:=false;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if(radiobutton1.Checked)then
  begin
      aku.posisi:=papan[tujuanku].step;
      shape1.Top:=papan[aku.posisi].posy;
      shape1.Left:=papan[aku.posisi].posx;
      tujuanku:=aku.posisi;
  end
  else
  begin
      kamu.posisi:=papan[tujuanmu].step;
      shape2.Top:=papan[kamu.posisi].posy;
      shape2.Left:=papan[kamu.posisi].posx;
      tujuanmu:=kamu.posisi;
  end;
  Timer1.Enabled:= false;
  button1.Enabled :=true;
  radiobutton1.Enabled:=true;
  radiobutton2.Enabled:=true;
end;

procedure TForm1.Timer2Timer(Sender: TObject);
begin
  if (aku.posisi=99) and (tujuanku=99) then
  begin
      shape1.Top:=papan[99].posy;
      shape1.Left:=papan[99].posx;
      showMessage('I WIN !');
      Timer2.Enabled:= false;
      exit;
  end
  else if (kamu.posisi=99) and (tujuanmu=99) then
  begin
      shape2.Top:=papan[99].posy;
      shape2.Left:=papan[99].posx;
      showMessage('YOU WIN !');
      Timer2.Enabled:= false;
      exit;
  end;

  if (aku.posisi>99) then
  begin
    aku.posisi:=99;
    tujuanku := 99 - (tujuanku - 99);
  end
  else if (kamu.posisi>99) then
  begin
    kamu.posisi:=99;
    tujuanmu := 99 - (tujuanmu - 99);
  end;

  if ((aku.posisi = tujuanku) and radiobutton1.Checked) or ((kamu.posisi = tujuanmu) and radiobutton2.Checked) then
  begin
    Timer2.Enabled := false;
    if ((papan[tujuanku].status>0) and radiobutton1.Checked) or ((papan[tujuanmu].status>0) and radiobutton2.Checked) then
    begin
      Timer1.Enabled := true;
    end
    else
    begin
        button1.Enabled :=true;
        radiobutton1.Enabled:=true;
        radiobutton2.Enabled:=true;
    end;
  end;

  if(radiobutton1.Checked)then
  begin
  if aku.posisi <= tujuanku then
  begin
    shape1.Top:=papan[aku.posisi].posy;
    shape1.Left:=papan[aku.posisi].posx;
    if aku.posisi < tujuanku then
      aku.posisi:=aku.posisi+1;
  end
  else if aku.posisi > tujuanku then
  begin
    shape1.Top:=papan[aku.posisi].posy;
    shape1.Left:=papan[aku.posisi].posx;
    if aku.posisi > tujuanku then
      aku.posisi:=aku.posisi-1;
  end;
  end
  else
  begin
  if kamu.posisi <= tujuanmu then
  begin
    shape2.Top:=papan[kamu.posisi].posy;
    shape2.Left:=papan[kamu.posisi].posx;
    if kamu.posisi < tujuanmu then
      kamu.posisi:=kamu.posisi+1;
  end
  else if kamu.posisi > tujuanmu then
  begin
    shape2.Top:=papan[kamu.posisi].posy;
    shape2.Left:=papan[kamu.posisi].posx;
    if kamu.posisi > tujuanmu then
      kamu.posisi:=kamu.posisi-1;
  end;
  end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
application.Terminate;
end;



end.

                                          Gambar Games Ular Tangga