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:
| unit mTron;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls;
type TCan = class(TImage) Canvas2: TCanvas; public constructor Create(AOwner:TComponent); override; end;
type TTron = class(TForm) Timer1: TTimer; ImBild: TCan; Label1: TLabel; Label2: TLabel; procedure FormActivate(Sender: TObject); procedure FormKeyPress(Sender: TObject; var Key: Char); procedure Timer1Timer(Sender: TObject); private public end;
var Tron: TTron; L,R,O,U,L2,R2,O2,U2,Score1,Score2: Integer; Spiel: Boolean;
implementation
{$R *.DFM}
constructor TCan.Create(AOwner:TComponent); begin inherited Create(AOwner); end;
procedure TTron.FormActivate(Sender: TObject); begin Spiel := False; Windowstate := wsMaximized; Label1.Left := Round(Width/4) -26; Label2.Left := Round(3*Width/4) -26; Label1.Top := Round(Height/2) -60; Label2.Top := Round(Height/2) -60; ImBild := TCan.Create(Tron); ImBild.Parent := Tron; ImBild.Align := alClient; ImBild.Canvas.Pen.Width := 10; ImBild.Canvas.Brush.Style := bssolid; ImBild.Canvas.Brush.Color := clblack; ImBild.Canvas.Rectangle (0,0,ImBild.Width,ImBild.Height); ImBild.Canvas.Brush.Style := bsclear; ImBild.Canvas.Pen.Color := clred; ImBild.Canvas.Rectangle (0,0,ImBild.Width,ImBild.Height); ImBild.Canvas.Pen.Width := 4; R := 3; R2 := 3; Score1 := 0; Score2 := 0; end;
procedure TTron.FormKeyPress(Sender: TObject; var Key: Char); begin If Spiel = False then begin Label1.Visible := False; Label2.Visible := False; ImBild.Visible := True; ImBild.Canvas.Pen.Width := 10; ImBild.Canvas.Brush.Style := bssolid; ImBild.Canvas.Brush.Color := clblack; ImBild.Canvas.Rectangle (0,0,ImBild.Width,ImBild.Height); ImBild.Canvas.Brush.Style := bsclear; ImBild.Canvas.Pen.Color := clred; ImBild.Canvas.Rectangle (0,0,ImBild.Width,ImBild.Height); ImBild.Canvas.Pen.Width := 4; ImBild.Canvas.Pen.Color := clLime; ImBild.Canvas.Moveto(Round(Width/4),Round(Height/2)); ImBild.Canvas.LineTo(Round(Width/4),Round(Height/2)); ImBild.Canvas2.Pen.Color := clFuchsia; ImBild.Canvas2.Moveto(Round(3*Width/4),Round(Height/2)); ImBild.Canvas2.LineTo(Round(3*Width/4),Round(Height/2)); Spiel := True; Timer1.Enabled := True; end; If Key = 'w' then begin O := 3; U := 0; L := 0; R := 0; end else if Key = 's' then begin O := 0; U := 3; L := 0; R := 0; end else if Key = 'a' then begin O := 0; U := 0; L := 3; R := 0; end else if Key = 'd' then begin O := 0; U := 0; L := 0; R := 3; end; If Key = '5' then begin O2 := 3; U2 := 0; L2 := 0; R2 := 0; end else if Key = '2' then begin O2 := 0; U2 := 3; L2 := 0; R2 := 0; end else if Key = '1' then begin O2 := 0; U2 := 0; L2 := 3; R2 := 0; end else if Key = '3' then begin O2 := 0; U2 := 0; L2 := 0; R2 := 3; end; end;
procedure TTron.Timer1Timer(Sender: TObject); begin If ImBild.Canvas.Pixels[ImBild.Canvas.Penpos.x-L+R,ImBild.Canvas.Penpos.y-O+U] <> clBlack then begin Timer1.Enabled := False; Score2 := Score2 + 1; Label2.Caption := inttostr(Score2); Spiel := False; Label1.Visible := True; Label2.Visible := True; ImBild.Visible := False; end; If ImBild.Canvas2.Pixels[ImBild.Canvas2.Penpos.x-L2+R2,ImBild.Canvas2.Penpos.y-O2+U2] <> clBlack then begin Timer1.Enabled := False; Score1 := Score1 + 1; Label1.Caption := inttostr(Score1); Spiel := False; Label1.Visible := True; Label2.Visible := True; ImBild.Visible := False; end;} ImBild.Canvas.lineto(ImBild.Canvas.PenPos.x-L+R,ImBild.Canvas.penpos.y-O+U); ImBild.Canvas2.lineto(ImBild.Canvas2.PenPos.x-L2+R2,ImBild.Canvas2.penpos.y-O2+U2); end;
end. |