unit Spiel;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 =
class(TForm)
usereingabe: TEdit;
OK1: TButton;
username1: TLabel;
leben1: TLabel;
vorne: TButton;
rechts: TButton;
links: TButton;
hinten: TButton;
Image: TImage;
username2: TLabel;
leben2: TLabel;
Spieler: TLabel;
spielnachricht: TLabel;
schuss: TButton;
procedure OK1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure vorneClick(Sender: TObject);
procedure rechtsClick(Sender: TObject);
procedure linksClick(Sender: TObject);
procedure hintenClick(Sender: TObject);
procedure schussClick(Sender: TObject);
procedure zug(
var zug,wid:integer);
procedure schuss2(schadenmax,schadenmin:integer; s:real;
var l1:integer);
procedure schuss1(schadenmax,schadenmin:integer; s:real;
var l2:integer);
procedure entfernung(p1,p2 :integer;
var s:real);
procedure FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
username:1..2;
end;
var
x1,x2,x3,x4,cx1,cx2,y1,y2,y3,y4,cy1,cy2,w1,w2,wid,zug,schadenmax,schadenmin:integer;
l1,l2:real;
s1,s2:
string;
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
l1 := 100;
l2 := 100;
x1 :=10;
x2 :=20;
x3 :=630;
x4 :=640;
cx1 := 15;
cx2 := 635;
cy1 := 15;
cy2 :=385;
y1 :=10;
y2 :=20;
y3 :=380;
y4 :=390;
w1 :=400;
w2 :=400;
schadenmax := 30;
schadenmin := 20;
username:= 1;
[Color=#00FF00]zug := 5;
end;
procedure TForm1.OK1Click(Sender: TObject);
var Bitmap : TBitmap;
begin
case username
of
1:
begin
s1 := usereingabe.Text;
if s1 ='
'
then
begin
showmessage('
Du hast keinen Usernamen eingegeben!');
exit;
end
else
begin
username1.caption :=s1;
leben1.caption := floattostr(l1);
Spieler.caption := '
Spieler 2';
username:=2;
end
end;
2:
begin
s2 := usereingabe.Text;
if s2 ='
'
then
begin
showmessage('
Du hast keinen Usernamen eingegeben!');
exit;
end
else
begin
//screeneigenschaften festlegen
username2.caption :=s2;
leben2.caption := floattostr(l2);
//eingabe verschwinden lassen
ok1.Visible := false;
usereingabe.Visible:=false;
Spieler.visible :=false;
//Bitmap create
Bitmap := TBitmap.Create;
Bitmap.Width := Image.Width;
Bitmap.Height := Image.Height;
Image.Picture.Graphic := Bitmap;
//Eigenschaften stift
Image.Canvas.pen.mode := pmBlack;
//Startrechteck zeichnen
//Spieler 1
Image.Canvas.Rectangle(X1, Y1, X2, Y2);
Image.Canvas.Pixels[cx1, cy1];
//Spieler 2
Image.Canvas.Rectangle(X3, Y3, X4, Y4);
Image.Canvas.Pixels[cx2, cy2];
//wid setzen
wid:= 2;
spielnachricht.caption :='
Spieler '+ floattostr(wid) +'
ist an der Reihe.';
end
end;
end;
end;
procedure TForm1.vorneClick(Sender: TObject);
begin
if wid = 1
then
begin
Image.Canvas.pen.mode := pmWhite;
Image.Canvas.Rectangle(X1, Y1, X2, Y2);
Image.Canvas.pen.mode := pmBlack;
X1 := X1;
X2 := X2;
Y1 := Y1-10;
Y2 := Y2-10;
Image.Canvas.Rectangle(X1, Y1, X2, Y2);
[Color=#00FF00zug(zug,wid);[color]
end
else
begin
Image.Canvas.pen.mode := pmWhite;
Image.Canvas.Rectangle(X3, Y3, X4, Y4);
Image.Canvas.pen.mode := pmBlack;
X3 := X3;
X4 := X4;
Y3 := Y3-10;
Y4 := Y4-10;
Image.Canvas.Rectangle(X3, Y3, X4, Y4);
[Color=#00FF00 zug(zug,wid);[color]
end;
end;
procedure TForm1.rechtsClick(Sender: TObject);
begin
if wid = 1
then
begin
Image.Canvas.pen.mode := pmWhite;
Image.Canvas.Rectangle(X1, Y1, X2, Y2);
Image.Canvas.pen.mode := pmBlack;
X1 := X1+10;
X2 := X2+10;
Y1 := Y1;
Y2 := Y2;
Image.Canvas.Rectangle(X1, Y1, X2, Y2);
[Color=#00FF00zug(zug,wid);[color]
end
else
begin
Image.Canvas.pen.mode := pmWhite;
Image.Canvas.Rectangle(X3, Y3, X4, Y4);
Image.Canvas.pen.mode := pmBlack;
X3 := X3+10;
X4 := X4+10;
Y3 := Y3;
Y4 := Y4;
Image.Canvas.Rectangle(X3, Y3, X4, Y4);
[Color=#00FF00zug(zug,wid);[color]
end;
end;
procedure TForm1.linksClick(Sender: TObject);
begin
if wid = 1
then
begin
Image.Canvas.pen.mode := pmWhite;
Image.Canvas.Rectangle(X1, Y1, X2, Y2);
Image.Canvas.pen.mode := pmBlack;
X1 := X1-10;
X2 := X2-10;
Y1 := Y1;
Y2 := Y2;
Image.Canvas.Rectangle(X1, Y1, X2, Y2);
[Color=#00FF00]zug(zug,wid);[color]
end
else
begin
Image.Canvas.pen.mode := pmWhite;
Image.Canvas.Rectangle(X3, Y3, X4, Y4);
Image.Canvas.pen.mode := pmBlack;
X3 := X3-10;
X4 := X4-10;
Y3 := Y3;
Y4 := Y4;
Image.Canvas.Rectangle(X3, Y3, X4, Y4);
[Color=#00FF00]zug(zug,wid);[color]
end;
end;
procedure TForm1.hintenClick(Sender: TObject);
begin
if wid = 1
then
begin
Image.Canvas.pen.mode := pmWhite;
Image.Canvas.Rectangle(X1, Y1, X2, Y2);
Image.Canvas.pen.mode := pmBlack;
X1 := X1;
X2 := X2;
Y1 := Y1+10;
Y2 := Y2+10;
Image.Canvas.Rectangle(X1, Y1, X2, Y2);
[Color=#00FF00]zug(zug,wid);[color]
end
else
begin
Image.Canvas.pen.mode := pmWhite;
Image.Canvas.Rectangle(X3, Y3, X4, Y4);
Image.Canvas.pen.mode := pmBlack;
X3 := X3;
X4 := X4;
Y3 := Y3+10;
Y4 := Y4+10;
Image.Canvas.Rectangle(X3, Y3, X4, Y4);
[Color=#00FF00]zug(zug,wid);[color]
end;
end;
procedure TForm1.schussClick(Sender: TObject);
var p1,p2:integer;s:real;
begin
if wid = 1
then
begin
if cy1<=cy2
then
begin
p1:=cy2-cy1;
if cx1<=cx2
then
begin
p2:=cx2-cx1;
entfernung(p1,p2,s);
end
else
begin
p2:=cx1-cx2;
entfernung(p1,p2,s);
end;
end
else
begin
p1:=cy1-cy2;
if cx1<=cx2
then
begin
p2:=cx2-cx1;
entfernung(p1,p2,s);
end
else
begin
p2:=cx1-cx2;
entfernung(p1,p2,s);
end
end;
end;
end;
procedure entfernung(p1,p2 :integer;
var s:real);
var pall:integer; nah:real;
begin
pall:=(sqr(p1))+(sqr(p2));
s :=sqrt(pall);
if wid = 1
then
begin
if s>w1
then
begin
nah := s-w1;
showmessage('
Du kannst nicht soweit schießen! '+floattostr(nah)+'
meter näher!');
exit;
end
else
begin
[Color=#00FF00]schuss1(schadenmax,schadenmin,s,l2);[color]
end;
end
else
begin
if s>w2
then
begin
nah := s-w2;
showmessage('
Du kannst nicht soweit schießen! '+floattostr(nah)+'
meter näher!');
exit;
end
else
begin
[Color=#00FF00]schuss2(schadenmax,schadenmin,s,l2);[color]
end;
end;
end;
procedure schuss1(schadenmax,schadenmin:integer; s:real;
var l2:integer);
var ab:integer;
begin
Randomize;
ab :=(random(schadenmax)+schadenmin);
s := s/10;
ab :=ab+s;
l2 := l2-ab;
leben2.Caption := floattostr(l2);
showmessage(s1+'
hat '+s2+'
'+floattostr(ab)+'
Lebenspunkte abgezogen');
end;
procedure schuss2(schadenmax,schadenmin:integer; s:real;
var l1:integer);
var ab:integer;
begin//Berechnung des Schadens
Randomize;
ab :=(random(schadenmax)+schadenmin);
s := s/10;
ab :=ab+s;
l1 := l1-ab;
leben1.Caption := floattostr(l1);
showmessage(s2+'
hat '+s1+'
'+floattostr(ab)+'
Lebenspunkte abgezogen');
end;
procedure [Color=#00FF00]zug(
var zug,wid:integer);[color]
begin
zug := zug-1;
if zug = 0
then
begin
if wid = 1
then
begin
wid := 2;
spielnachricht.caption :='
Spieler 2 ist an der Reihe.';
zug := 5;
end
else
begin
wid := 1;
spielnachricht.caption :='
Spieler 1 ist an der Reihe.';
zug := 5;
end;
end;
end;
[Color=#00FF00]
procedure TForm1.FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
begin
case Key
of
VK_LEFT:
begin
linksClick(Sender: TObject);
Key := 0;
end;
VK_RIGHT:
begin
rechtsClick(Sender: TObject);
Key := 0;
end;
VK_UP:
begin
vorneClick(Sender: TObject);
Key := 0;
end;
VK_DOWN:
begin
hinten;
Key := 0;
end;
end;
end;[color]
end.