mirror of
https://github.com/ulfgebhardt/delphi_snake.git
synced 2025-12-13 01:35:49 +00:00
init commit
This commit is contained in:
commit
8387033441
35
Snake.cfg
Normal file
35
Snake.cfg
Normal file
@ -0,0 +1,35 @@
|
||||
-$A8
|
||||
-$B-
|
||||
-$C+
|
||||
-$D+
|
||||
-$E-
|
||||
-$F-
|
||||
-$G+
|
||||
-$H+
|
||||
-$I+
|
||||
-$J-
|
||||
-$K-
|
||||
-$L+
|
||||
-$M-
|
||||
-$N+
|
||||
-$O+
|
||||
-$P+
|
||||
-$Q-
|
||||
-$R-
|
||||
-$S-
|
||||
-$T-
|
||||
-$U-
|
||||
-$V+
|
||||
-$W-
|
||||
-$X+
|
||||
-$YD
|
||||
-$Z1
|
||||
-cg
|
||||
-AWinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;
|
||||
-H+
|
||||
-W+
|
||||
-M
|
||||
-$M16384,1048576
|
||||
-K$00400000
|
||||
-LE"d:\programming\delphi\delphi6\Projects\Bpl"
|
||||
-LN"d:\programming\delphi\delphi6\Projects\Bpl"
|
||||
87
Snake.dof
Normal file
87
Snake.dof
Normal file
@ -0,0 +1,87 @@
|
||||
[FileVersion]
|
||||
Version=6.0
|
||||
[Compiler]
|
||||
A=8
|
||||
B=0
|
||||
C=1
|
||||
D=1
|
||||
E=0
|
||||
F=0
|
||||
G=1
|
||||
H=1
|
||||
I=1
|
||||
J=0
|
||||
K=0
|
||||
L=1
|
||||
M=0
|
||||
N=1
|
||||
O=1
|
||||
P=1
|
||||
Q=0
|
||||
R=0
|
||||
S=0
|
||||
T=0
|
||||
U=0
|
||||
V=1
|
||||
W=0
|
||||
X=1
|
||||
Y=1
|
||||
Z=1
|
||||
ShowHints=1
|
||||
ShowWarnings=1
|
||||
UnitAliases=WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;
|
||||
[Linker]
|
||||
MapFile=0
|
||||
OutputObjs=0
|
||||
ConsoleApp=1
|
||||
DebugInfo=0
|
||||
RemoteSymbols=0
|
||||
MinStackSize=16384
|
||||
MaxStackSize=1048576
|
||||
ImageBase=4194304
|
||||
ExeDescription=
|
||||
[Directories]
|
||||
OutputDir=
|
||||
UnitOutputDir=
|
||||
PackageDLLOutputDir=
|
||||
PackageDCPOutputDir=
|
||||
SearchPath=
|
||||
Packages=
|
||||
Conditionals=
|
||||
DebugSourceDirs=
|
||||
UsePackages=0
|
||||
[Parameters]
|
||||
RunParams=
|
||||
HostApplication=
|
||||
Launcher=
|
||||
UseLauncher=0
|
||||
DebugCWD=
|
||||
[Language]
|
||||
ActiveLang=
|
||||
ProjectLang=
|
||||
RootDir=
|
||||
[Version Info]
|
||||
IncludeVerInfo=0
|
||||
AutoIncBuild=0
|
||||
MajorVer=1
|
||||
MinorVer=0
|
||||
Release=0
|
||||
Build=0
|
||||
Debug=0
|
||||
PreRelease=0
|
||||
Special=0
|
||||
Private=0
|
||||
DLL=0
|
||||
Locale=1031
|
||||
CodePage=1252
|
||||
[Version Info Keys]
|
||||
CompanyName=
|
||||
FileDescription=
|
||||
FileVersion=1.0.0.0
|
||||
InternalName=
|
||||
LegalCopyright=
|
||||
LegalTrademarks=
|
||||
OriginalFilename=
|
||||
ProductName=
|
||||
ProductVersion=1.0.0.0
|
||||
Comments=
|
||||
13
Snake.dpr
Normal file
13
Snake.dpr
Normal file
@ -0,0 +1,13 @@
|
||||
program Snake;
|
||||
|
||||
uses
|
||||
Forms,
|
||||
uMain in 'uMain.pas' {fMain};
|
||||
|
||||
{$R *.res}
|
||||
|
||||
begin
|
||||
Application.Initialize;
|
||||
Application.CreateForm(TfMain, fMain);
|
||||
Application.Run;
|
||||
end.
|
||||
44
uMain.dfm
Normal file
44
uMain.dfm
Normal file
@ -0,0 +1,44 @@
|
||||
object fMain: TfMain
|
||||
Left = 259
|
||||
Top = 212
|
||||
Width = 870
|
||||
Height = 640
|
||||
HorzScrollBar.Visible = False
|
||||
VertScrollBar.Visible = False
|
||||
Caption = 'Snake'
|
||||
Color = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -11
|
||||
Font.Name = 'MS Sans Serif'
|
||||
Font.Style = []
|
||||
Menu = MainMenu
|
||||
OldCreateOrder = False
|
||||
OnCreate = FormCreate
|
||||
OnKeyDown = FormKeyDown
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
object Label1: TLabel
|
||||
Left = 0
|
||||
Top = 8
|
||||
Width = 37
|
||||
Height = 13
|
||||
Caption = 'Punkte:'
|
||||
end
|
||||
object timer: TTimer
|
||||
Interval = 100
|
||||
OnTimer = timerTimer
|
||||
Top = 48
|
||||
end
|
||||
object MainMenu: TMainMenu
|
||||
Left = 128
|
||||
Top = 112
|
||||
object mSnake: TMenuItem
|
||||
Caption = 'Snake'
|
||||
object Spielneustarten1: TMenuItem
|
||||
Caption = 'Spiel neu starten'
|
||||
OnClick = Spielneustarten1Click
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
197
uMain.pas
Normal file
197
uMain.pas
Normal file
@ -0,0 +1,197 @@
|
||||
unit uMain;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||||
Dialogs, ExtCtrls, Menus, StdCtrls;
|
||||
|
||||
type
|
||||
TfMain = class(TForm)
|
||||
timer: TTimer;
|
||||
MainMenu: TMainMenu;
|
||||
mSnake: TMenuItem;
|
||||
Spielneustarten1: TMenuItem;
|
||||
Label1: TLabel;
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure StartGame;
|
||||
procedure FormKeyDown(Sender: TObject; var Key: Word;
|
||||
Shift: TShiftState);
|
||||
procedure timerTimer(Sender: TObject);
|
||||
procedure Spielneustarten1Click(Sender: TObject);
|
||||
private
|
||||
{ Private declarations }
|
||||
public
|
||||
{ Public declarations }
|
||||
Points:Integer;
|
||||
Snake: array of TShape;
|
||||
Snakehor: Integer;
|
||||
Snakever: Integer;
|
||||
Dots: array of TShape;
|
||||
LastPosX:Integer;
|
||||
LastPosY:Integer;
|
||||
end;
|
||||
|
||||
var
|
||||
fMain: TfMain;
|
||||
|
||||
const
|
||||
SnakeHead = clBlue;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.dfm}
|
||||
|
||||
procedure TfMain.FormCreate(Sender: TObject);
|
||||
begin
|
||||
|
||||
Randomize;
|
||||
|
||||
DoubleBuffered:=True;
|
||||
|
||||
StartGame;
|
||||
|
||||
end;
|
||||
|
||||
procedure TfMain.StartGame;
|
||||
var i:Integer;
|
||||
begin
|
||||
|
||||
Snakehor:= 1;
|
||||
Snakever:= 0;
|
||||
Points := 0;
|
||||
for i:=0 to Length(Snake)-1 do Snake[i].Free;
|
||||
SetLength(Snake,0);
|
||||
for i:=0 to 2 do
|
||||
begin
|
||||
SetLength(Snake,Length(Snake)+1);
|
||||
Snake[Length(Snake)-1]:=TShape.create(fMain);
|
||||
Snake[Length(Snake)-1].Parent:=fMain;
|
||||
Snake[Length(Snake)-1].Shape:=stRoundRect;
|
||||
Snake[Length(Snake)-1].Width:=10;
|
||||
Snake[Length(Snake)-1].Height:=10;
|
||||
if i=0 then
|
||||
begin
|
||||
Snake[Length(Snake)-1].Top:=fMain.Height div 2;
|
||||
Snake[Length(Snake)-1].Left:=fMain.Width div 2;
|
||||
Snake[Length(Snake)-1].Brush.Color:=Snakehead;
|
||||
end else
|
||||
begin
|
||||
Snake[Length(Snake)-1].Top:=Snake[Length(Snake)-2].Top;
|
||||
Snake[Length(Snake)-1].Left:=Snake[Length(Snake)-2].Left-10;
|
||||
end;
|
||||
end;
|
||||
|
||||
timer.Enabled:=True;
|
||||
|
||||
end;
|
||||
|
||||
procedure TfMain.FormKeyDown(Sender: TObject; var Key: Word;
|
||||
Shift: TShiftState);
|
||||
begin
|
||||
|
||||
if Key = vk_up then
|
||||
begin
|
||||
Snakever:= -1;
|
||||
Snakehor:= 0;
|
||||
end;
|
||||
if Key = vk_down then
|
||||
begin
|
||||
Snakever:= 1;
|
||||
Snakehor:= 0;
|
||||
end;
|
||||
if Key = vk_left then
|
||||
begin
|
||||
Snakever:= 0;
|
||||
Snakehor:= -1;
|
||||
end;
|
||||
if Key = vk_right then
|
||||
begin
|
||||
Snakever:= 0;
|
||||
Snakehor:= 1;
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
procedure TfMain.timerTimer(Sender: TObject);
|
||||
var i,tempt,templ:Integer;
|
||||
begin
|
||||
|
||||
for i:=0 to length(Snake)-1 do
|
||||
begin
|
||||
if i=0 then
|
||||
begin
|
||||
LastPosY:=Snake[0].Top;
|
||||
LastPosX:=Snake[0].Left;
|
||||
Snake[0].Top:= Snake[0].Top + Snakever*Snake[0].Height;
|
||||
Snake[0].Left:= Snake[0].Left + Snakehor*Snake[0].Width;
|
||||
end else
|
||||
begin
|
||||
tempt:=Snake[i].Top;
|
||||
templ:=Snake[i].Left;
|
||||
Snake[i].Top:= LastPosY;
|
||||
Snake[i].Left:= LastPosX;
|
||||
LastPosY:=tempt;
|
||||
LastPosX:=templ;
|
||||
end;
|
||||
end;
|
||||
|
||||
snake[0].BringToFront;
|
||||
|
||||
if Length(Dots)=0 then
|
||||
begin
|
||||
setlength(Dots,1);
|
||||
Dots[Length(Dots)-1]:=TShape.create(fMain);
|
||||
Dots[Length(Dots)-1].Parent:=fMain;
|
||||
Dots[Length(Dots)-1].Shape:=stCircle;
|
||||
Dots[Length(Dots)-1].Width:=7;
|
||||
Dots[Length(Dots)-1].Height:=7;
|
||||
Dots[Length(Dots)-1].Brush.Color:=clRed;
|
||||
Dots[Length(Dots)-1].Top:=40+Random(fMain.Height-180);
|
||||
Dots[Length(Dots)-1].Left:=40+Random(fMain.Width-80)
|
||||
end;
|
||||
|
||||
//kollision
|
||||
|
||||
//Wände
|
||||
if (Snake[0].left<0) then timer.Enabled:=False;
|
||||
if (Snake[0].Left+Snake[0].Width*2>fMain.Width) then timer.Enabled:=False;
|
||||
if (Snake[0].Top<10) then timer.Enabled:=False;
|
||||
if (Snake[0].Top+Snake[0].Height+60>fMain.Height) then timer.Enabled:=False;
|
||||
|
||||
//Self
|
||||
for i:=1 to Length(Snake)-1 do
|
||||
if (Snake[0].Top=Snake[i].Top) and (Snake[0].Left=Snake[i].Left) then timer.Enabled:=False;
|
||||
|
||||
//Dot
|
||||
if (Snake[0].Left+Snake[0].width>=Dots[0].Left) and (Snake[0].Left<=Dots[0].Left+Dots[0].Width) and (Snake[0].Top+Snake[0].Height>=Dots[0].Top) and (Snake[0].Top<=Dots[0].Top+Dots[0].Height) then
|
||||
begin
|
||||
Inc(Points,1000+random(1000));
|
||||
Dots[0].Free;
|
||||
SetLength(Dots,0);
|
||||
//Neues Schlangenglied
|
||||
SetLength(Snake,Length(Snake)+1);
|
||||
Snake[Length(Snake)-1]:=TShape.create(fMain);
|
||||
Snake[Length(Snake)-1].Parent:=fMain;
|
||||
Snake[Length(Snake)-1].Shape:=stRoundRect;
|
||||
Snake[Length(Snake)-1].Width:=10;
|
||||
Snake[Length(Snake)-1].Height:=10;
|
||||
Snake[Length(Snake)-1].Top:=LastPosY;
|
||||
Snake[Length(Snake)-1].Left:=LastPosX;
|
||||
end;
|
||||
|
||||
|
||||
Inc(Points,Random(2));
|
||||
|
||||
label1.Caption:='Punkte: '+inttostr(Points);
|
||||
|
||||
end;
|
||||
|
||||
procedure TfMain.Spielneustarten1Click(Sender: TObject);
|
||||
begin
|
||||
|
||||
StartGame;
|
||||
|
||||
end;
|
||||
|
||||
end.
|
||||
Loading…
x
Reference in New Issue
Block a user