hari ini aku share kepada kalian ingin memposting cara membuat game sederhana menggunakan delphi langsung aja y gan,gax perlu basa basi lagi
unit U_Ular;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, jpeg;
type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Panel4: TPanel;
Panel5: TPanel;
Panel6: TPanel;
Panel7: TPanel;
Panel8: TPanel;
Panel9: TPanel;
Panel10: TPanel;
Panel11: TPanel;
Panel12: TPanel;
Panel13: TPanel;
Panel14: TPanel;
Panel15: TPanel;
Panel16: TPanel;
Panel17: TPanel;
Panel18: TPanel;
Panel19: TPanel;
Panel20: TPanel;
Panel21: TPanel;
Panel22: TPanel;
Panel23: TPanel;
Panel24: TPanel;
Panel25: TPanel;
Panel26: TPanel;
Panel27: TPanel;
Panel28: TPanel;
Panel29: TPanel;
Panel30: TPanel;
Panel31: TPanel;
Panel32: TPanel;
Panel33: TPanel;
Panel34: TPanel;
Panel35: TPanel;
Panel36: TPanel;
AA: TPanel;
BB: TPanel;
Dadu1: TPanel;
MULAI: TButton;
Play1: TButton;
Play2: TButton;
Keluar: TButton;
Dadu2: TPanel;
Panel37: TPanel;
Image1: TImage;
procedure MULAIClick(Sender: TObject);
procedure Play1Click(Sender: TObject);
procedure Play2Click(Sender: TObject);
procedure KeluarClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Player1,Player2 : String;
Nil1,Nil2,I : Integer;
implementation
{$R *.DFM}
procedure TForm1.MULAIClick(Sender: TObject);
begin
Nil1:=0;
Nil2:=0;
AA.LEFT := 248;
AA.TOP := 8;
BB.LEFT := 288;
BB.TOP := 8;
Player1:= InputBox('Nama Pemain','Nama Player 1','');
Player2:= InputBox('Nama Pemain','Nama Player 2','');
Play1.Caption := Player1;
Play2.Caption := Player2;
Play2.Visible := False;
Dadu1.Caption := '0';
Dadu2.Caption := '0';
Play1.Visible := True;
end;
procedure TForm1.Play1Click(Sender: TObject);
begin
Randomize;
Dadu1.Caption := IntToStr(Random(6)+1);
If StrToInt(Dadu1.Caption) = 6 Then
Begin
Play1.Visible:=True;
Play2.Visible:=False;
End
Else If StrToInt(Dadu1.Caption) < 6 Then
begin
Play1.Visible:=False;
Play2.Visible:=True;
end;
Nil1 := Nil1 + StrToInt(Dadu1.Caption);
If Nil1 = 36 Then
BEGIN
MessageDlg('SELAMAT '+Play1.Caption+' MENANG',mtInformation,[mbOk],0);
Play1.Visible:=False;
Play2.Visible:=False;
END;
If Nil1 > 36 Then Nil1:=(36-(Nil1-36));
If (Nil1>=1) and (Nil1<=6) Then AA.Top := 208
Else If (Nil1>=7) and (Nil1<=12) Then AA.Top := 168
Else If (Nil1>=13) and (Nil1<=18) Then AA.Top := 128
Else If (Nil1>=19) and (Nil1<=24) Then AA.Top := 88
Else If (Nil1>=25) and (Nil1<=30) Then AA.Top := 48
Else If (Nil1>=31) and (Nil1<=36) Then AA.Top := 8;
If (Nil1=1) or (Nil1=12) or (Nil1=13) or (Nil1=24) or (Nil1=25) or (Nil1=36) Then AA.Left := 8
Else If (Nil1=2) or (Nil1=11) or (Nil1=14) or (Nil1=23) or (Nil1=26) or (Nil1=35) Then AA.Left := 48
Else If (Nil1=3) or (Nil1=10) or (Nil1=15) or (Nil1=22) or (Nil1=27) or (Nil1=34) Then AA.Left := 88
Else If (Nil1=4) or (Nil1=9) or (Nil1=16) or (Nil1=21) or (Nil1=28) or (Nil1=33) Then AA.Left := 128
Else If (Nil1=5) or (Nil1=8) or (Nil1=17) or (Nil1=20) or (Nil1=29) or (Nil1=32) Then AA.Left := 168
Else If (Nil1=6) or (Nil1=7) or (Nil1=18) or (Nil1=19) or (Nil1=30) or (Nil1=31) Then AA.Left := 208;
If Nil1=Nil2 Then
Begin
BB.Top :=8;
BB.Left := 288;
Nil2 := 0;
Dadu2.Caption := '0';
End;
end;
procedure TForm1.Play2Click(Sender: TObject);
begin
Randomize;
Dadu2.Caption := IntToStr(Random(6)+1);
If StrToInt(Dadu2.Caption) = 6 Then
Begin
Play2.Visible:=True;
Play1.Visible:=False;
End
Else If StrToInt(Dadu2.Caption) < 6 Then
begin
Play2.Visible:=False;
Play1.Visible:=True;
end;
Nil2 := Nil2 + StrToInt(Dadu2.Caption);
If Nil2 = 36 Then
BEGIN
MessageDlg('SELAMAT '+Play2.Caption+' MENANG',mtInformation,[mbOk],0);
Play1.Visible:=False;
Play2.Visible:=False;
END;
If Nil2 > 36 Then Nil2:=(36-(Nil2-36));
If (Nil2>=1) and (Nil2<=6) Then BB.Top := 208
Else If (Nil2>=7) and (Nil2<=12) Then BB.Top := 168
Else If (Nil2>=13) and (Nil2<=18) Then BB.Top := 128
Else If (Nil2>=19) and (Nil2<=24) Then BB.Top := 88
Else If (Nil2>=25) and (Nil2<=30) Then BB.Top := 48
Else If (Nil2>=31) and (Nil2<=36) Then BB.Top := 8;
If (Nil2=1) or (Nil2=12) or (Nil2=13) or (Nil2=24) or (Nil2=25) or (Nil2=36) Then BB.Left := 8
Else If (Nil2=2) or (Nil2=11) or (Nil2=14) or (Nil2=23) or (Nil2=26) or (Nil2=35) Then BB.Left := 48
Else If (Nil2=3) or (Nil2=10) or (Nil2=15) or (Nil2=22) or (Nil2=27) or (Nil2=34) Then BB.Left := 88
Else If (Nil2=4) or (Nil2=9) or (Nil2=16) or (Nil2=21) or (Nil2=28) or (Nil2=33) Then BB.Left := 128
Else If (Nil2=5) or (Nil2=8) or (Nil2=17) or (Nil2=20) or (Nil2=29) or (Nil2=32) Then BB.Left := 168
Else If (Nil2=6) or (Nil2=7) or (Nil2=18) or (Nil2=19) or (Nil2=30) or (Nil2=31) Then BB.Left := 208;
If Nil1=Nil2 Then
Begin
AA.Top :=8;
AA.Left := 248;
Nil1 := 0;
Dadu1.Caption := '0';
End;
end;
procedure TForm1.KeluarClick(Sender: TObject);
begin
Close;
end;
end.
0 komentar:
Posting Komentar