1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;
type TForm1 = class(TForm) Panel1: TPanel; Label1: TLabel; Timer1: TTimer; Button1: TButton; Spieler: TPanel; Ball: TPanel; CPU: TPanel; stand: TLabel; Label2: TLabel; Edit1: TEdit; Edit2: TEdit; Label4: TLabel; Label5: TLabel; CheckBox1: TCheckBox; CheckBox2: TCheckBox; procedure Button1Click(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Edit1KeyPress(Sender: TObject; var Key: Char); procedure Edit2KeyPress(Sender: TObject; var Key: Char); private public end;
var Form1: TForm1; var CPU_top,Spieler_top : integer; var ball_top,ball_left, ball_x, ball_y : integer; var limit_oben,limit_unten,limit_links,limit_rechts : integer; var geschwindigkeit, differenz, schwierigkeit : integer; var b, bMehrspieler : boolean; implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject); begin b:=false; if not (checkbox1.Checked=true) then b:=true; if checkbox2.Checked=true then bMehrspieler:=true; if checkbox2.Checked=false then bMehrspieler:=false; geschwindigkeit:=StrToInt(edit1.text); ball_x:=StrToInt(edit1.text); ball_y:=StrToInt(edit1.text); Stand.Caption:='0:0'; sleep(500); Timer1.Enabled:=true; end;
procedure TForm1.Timer1Timer(Sender: TObject); begin if ball_top < 8 then begin ball_top:=8; ball_y:= - ball_y; end; if ball_top > 568 then begin ball_top:=568; ball_y:= - ball_y; end; ball_top:=ball_top + ball_y; ball.Top:=ball_top; if ((ball_left < 49) and (ball_top>CPU_top-1) and (ball_top<CPU_top+153)) then begin geschwindigkeit:=geschwindigkeit+1; ball_y:=ball_y+1; ball_x:=ball_x+1; b:=true; end; if (ball_left > 975) and (ball_top>Spieler_top-1) and (ball_top<Spieler_top+153) then begin geschwindigkeit:=geschwindigkeit+1; ball_y:=ball_y+1; ball_x:=ball_x+1; b:=false; end; if (ball_left>1020) or (ball_left<4) then begin if ball_left > 1020 then stand.caption:=IntToStr(StrToInt(copy(stand.Caption, 0, pos(':', stand.Caption)-1)) + 1) + copy(stand.Caption, pos(':', stand.Caption), MaxInt); if ball_left < 4 then stand.caption:=copy(stand.Caption, 0, pos(':', stand.Caption)) + IntToStr(StrToInt(copy(stand.Caption, pos(':', stand.Caption)+1, MaxInt)) + 1); ball.top:=240; ball.Left:=512; CPU.Top:=200; Spieler.Top:=200; CPU_top:=200; Spieler_Top:=200; ball_top:=240; ball_left:=512; geschwindigkeit:=StrToInt(edit1.text); ball_x:=StrToInt(edit1.text); ball_y:=StrToInt(edit1.text); differenz:=0; b:=false; if not (checkbox1.Checked=true) then b:=true; timer1.Enabled:=false; if (copy(stand.Caption, pos(':', stand.Caption)+1, MaxInt)=edit2.text) then begin showmessage('Spiel zuende du hast gewonnen'); exit; end; if (copy(stand.Caption, 0, pos(':', stand.Caption)-1)=edit2.text) then begin showmessage('Spiel zuende du hast verloren'); exit;
end; sleep(500); timer1.Enabled:=true; exit; end; if b=false then ball_left:=ball_left - ball_x; if b=true then ball_left:=ball_left + ball_x; ball.left:=ball_left; if bMehrspieler=false then begin if(ball_left < 350) then begin differenz := CPU_top+76 - ball_top; if(differenz < 0) then CPU_top := CPU_top + geschwindigkeit else CPU_top := CPU_top - geschwindigkeit; if (CPU_top < 8) then CPU_top := 8; if (CPU_top > 440) then CPU_top := 440; CPU.Top := CPU_top; end; end; if GetAsyncKeystate(VK_UP) < 0 then begin Spieler_top := Spieler_top - geschwindigkeit; if (Spieler_top < 8) then Spieler_top := 8; if (Spieler_top > 440) then Spieler_top := 440; Spieler.Top := Spieler_top; end; if GetAsyncKeystate(VK_DOWN) < 0 then begin Spieler_top := Spieler_top + geschwindigkeit; if (Spieler_top < 8) then Spieler_top := 8; if (Spieler_top > 440) then Spieler_top := 440; Spieler.Top := Spieler_top; end; if bMehrspieler=true then begin if GetAsyncKeystate(VK_CAPITAL) < 0 then begin CPU_top := CPU_top - geschwindigkeit; if (CPU_top < 8) then CPU_top := 8; if (CPU_top > 440) then CPU_top := 440; CPU.Top := CPU_top; end; if GetAsyncKeystate(VK_SHIFT) < 0 then begin CPU_top := CPU_top + geschwindigkeit; if (CPU_top < 8) then CPU_top := 8; if (CPU_top > 440) then CPU_top := 440; CPU.Top := CPU_top; end; end; end;
procedure TForm1.FormCreate(Sender: TObject); begin randomize; b:=false; DoubleBuffered := true; CPU_top:=200; Spieler_Top:=200; ball_top:=240; ball_left:=512; ball_x:=5; ball_y:=5; geschwindigkeit:=5; differenz:=0; end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if not (key in [#48..#57, #8, #44, #13, #46]) then key := #0; end;
procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char); begin if not (key in [#48..#57, #8, #44, #13, #46]) then key := #0; end;
end. |