Subversion Repositories spacemission

Compare Revisions

Regard whitespace Rev HEAD → Rev 1

/LevSpeicherung.pas
4,7 → 4,7
 
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Spin, ComCtrls{$IF CompilerVersion >= 23.0}, System.UITypes{$IFEND};
StdCtrls, ExtCtrls, Spin, ComCtrls;
 
type
TSpeicherungForm = class(TForm)
52,15 → 52,20
var
SpeicherungForm: TSpeicherungForm;
 
const
FCompVersion = '1.0';
 
implementation
 
uses
Global, LevMain, ComLevelReader;
LevMain;
 
{$R *.DFM}
 
procedure TSpeicherungForm.SearchLevels;
var
{sr: TSearchRec;
res: integer;}
i: integer;
begin
//SpinEdit.Value := 1;
74,10 → 79,21
liw.visible := true;
LadenBtn.enabled := false;
LoeschenBtn.enabled := false;
{res := FindFirst(mainform.fdirectory+'Levels\*.lev', 0, sr);
try
while (res = 0) do
begin
if (sr.name <> '.') and (sr.name <> '..') then
LevelListBox.items.Add(copy(sr.Name, 0, length(sr.name)-4));
res := FindNext(sr);
end;
finally
FindClose(sr);
end;}
for i := 1 to 9999 do
begin
if fileexists(GetLevelFileName(i)) then
LevelListBox.items.Add(ExtractFileName(GetLevelFileName(i)));
if fileexists(mainform.fdirectory+'Levels\Level '+inttostr(i)+'.lev') then
LevelListBox.items.Add('Level ' + inttostr(i));
end;
end;
 
104,7 → 120,7
liw.visible := true;
LadenBtn.enabled := false;
LoeschenBtn.enabled := false;
deletefile(IncludeTrailingPathDelimiter(ExtractFilePath(GetLevelFileName(1)))+
deletefile(mainform.FDirectory+'Levels\'+
LevelListBox.Items.strings[LevelListBox.itemindex]+'.lev');
SearchLevels;
end;
114,7 → 130,8
var
Markiert: boolean;
i, TempArtMain, TempLiveMain: integer;
LevelData: TLevelData;
SavGame: textfile;
Ergebnis: array[1..5] of string;
begin
Markiert := false;
for i := 0 to LevelListBox.items.Count-1 do
140,37 → 157,35
// Vorbereiten
MainForm.DestroyLevel;
MainForm.LevChanged := false;
 
LevelData := TLevelData.Create;
try
LevelData.Load(IncludeTrailingPathDelimiter(ExtractFilePath(GetLevelFileName(1)))+
// Öffnen
AssignFile(SavGame, mainform.FDirectory+'Levels\'+
LevelListBox.Items.strings[LevelListBox.itemindex]+'.lev');
MainForm.ScrollBar.Max := LevelData.LevelEditorLength;
Reset(SavGame);
// Laden
ReadLN(SavGame); // --> Copyrightinfo
ReadLN(SavGame); // --> Copyrightinfo
ReadLN(SavGame, Ergebnis[5]); // --> Länge der Karte
MainForm.ScrollBar.Max := strtoint(Ergebnis[5]);
MainForm.Enemys.Clear;
TempArtMain := MainForm.ArtChecked;
TempLiveMain := MainForm.LiveEdit;
MainForm.NumEnemys := Length(LevelData.EnemyAdventTable);
for i := 0 to MainForm.NumEnemys-1 do
while not seekEoF(SavGame) do
begin
MainForm.EnemyAdd(
LevelData.EnemyAdventTable[i].x,
LevelData.EnemyAdventTable[i].y,
Ord(LevelData.EnemyAdventTable[i].enemyType),
LevelData.EnemyAdventTable[i].lifes
);
MainForm.ArtChecked := Ord(LevelData.EnemyAdventTable[i].enemyType);
MainForm.LiveEdit := LevelData.EnemyAdventTable[i].lifes;
MainForm.EnemyCreate(
LevelData.EnemyAdventTable[i].x,
LevelData.EnemyAdventTable[i].y
);
if LevelData.EnemyAdventTable[i].enemyType = etEnemyBoss then MainForm.Boss := true;
ReadLN(SavGame, Ergebnis[3]);
ReadLN(SavGame, Ergebnis[1]);
ReadLN(SavGame, Ergebnis[2]);
ReadLN(SavGame, Ergebnis[4]);
MainForm.EnemyAdd(strtoint(Ergebnis[1]), strtoint(Ergebnis[2]), strtoint(Ergebnis[3]), strtoint(Ergebnis[4]));
MainForm.ArtChecked := strtoint(Ergebnis[3]);
MainForm.LiveEdit := strtoint(Ergebnis[4]);
MainForm.EnemyCreate(strtoint(Ergebnis[1]), strtoint(Ergebnis[2]));
inc(MainForm.NumEnemys);
if Ergebnis[3] = '7' then MainForm.Boss := true;
end;
finally
FreeAndNil(LevelData);
end;
MainForm.LiveEdit := TempLiveMain;
MainForm.ArtChecked := TempArtMain;
// Schließen
CloseFile(SavGame);
// Nacharbeiten
MainForm.AnzeigeAct;
close;
238,7 → 253,7
 
procedure TSpeicherungForm.SpeichernBtnClick(Sender: TObject);
var
LevelData: TLevelData;
SavGame: textfile;
i, j: integer;
puffer: string;
begin
270,8 → 285,10
if MessageDlg('Level ist bereits vorhanden. Ersetzen?', mtConfirmation, [mbYes, mbNo], 0) = mrNo then
exit;
end;
 
// Sortierung (wichtig)
// Öffnen oder erstellen
AssignFile(SavGame, mainform.FDirectory+'Levels\Level '+inttostr(SpinEdit.Position)+'.lev');
Rewrite(SavGame);
// Sortierung
for j := 0 to mainform.enemys.Count - 2 do
begin
for i := 0 to mainform.enemys.Count - 2 do
284,24 → 301,19
end;
end;
end;
 
// Speichern
LevelData := TLevelData.Create;
try
LevelData.LevelEditorLength := MainForm.ScrollBar.Max;
SetLength(LevelData.EnemyAdventTable, mainform.enemys.count);
WriteLN(SavGame, '; SpaceMission ' + FCompVersion);
WriteLN(SavGame, '; LEV-File');
WriteLN(SavGame, inttostr(MainForm.ScrollBar.Max)); // --> Länge der Karte
for i := 0 to mainform.enemys.count-1 do
begin
LevelData.EnemyAdventTable[i].enemyType := TEnemyType(StrToInt(filter(3, mainform.enemys.Strings[i])));
LevelData.EnemyAdventTable[i].x := StrToInt(filter(1, mainform.enemys.Strings[i]));
LevelData.EnemyAdventTable[i].y := StrToInt(filter(2, mainform.enemys.Strings[i]));
LevelData.EnemyAdventTable[i].lifes := StrToInt(filter(4, mainform.enemys.Strings[i]));
WriteLN(SavGame, filter(3, mainform.enemys.Strings[i]));
WriteLN(SavGame, filter(1, mainform.enemys.Strings[i]));
WriteLN(SavGame, filter(2, mainform.enemys.Strings[i]));
WriteLN(SavGame, filter(4, mainform.enemys.Strings[i]));
end;
LevelData.Save(GetLevelFileName(SpinEdit.Position));
finally
FreeAndNil(LevelData);
end;
 
// Schließen
CloseFile(SavGame);
// Nacharbeiten
MainForm.LevChanged := false;
MainForm.AnzeigeAct;
310,11 → 322,9
 
procedure TSpeicherungForm.LevelListBoxClick(Sender: TObject);
var
LevelData: TLevelData;
boss: boolean;
i: Integer;
temp: string;
anzahlEinheiten: integer;
Ergebnis, boss, l, temp: string;
SavGame: textfile;
x, a: integer;
begin
li1a.visible := false;
li2a.visible := false;
333,27 → 343,45
end;
temp := LevelListBox.Items.strings[LevelListBox.itemindex];
SpinEdit.Position := strtoint(RightStr(temp, length(temp)-6));
 
LevelData := TLevelData.Create;
try
try
LevelData.Load(IncludeTrailingPathDelimiter(ExtractFilePath(GetLevelFileName(1)))+
AssignFile(SavGame, mainform.FDirectory+'Levels\'+
LevelListBox.Items.strings[LevelListBox.itemindex]+'.lev');
except
Reset(SavGame);
ReadLN(SavGame, Ergebnis);
if Ergebnis <> '; SpaceMission '+FCompVersion then
begin
liu.visible := true;
LadenBtn.enabled := false;
CloseFile(SavGame);
exit;
end;
 
boss := false;
anzahlEinheiten := Length(LevelData.EnemyAdventTable);
for i := 0 to anzahlEinheiten - 1 do
ReadLN(SavGame, Ergebnis);
if Ergebnis <> '; LEV-File' then
begin
if LevelData.EnemyAdventTable[i].enemyType = etEnemyBoss then
liu.visible := true;
LadenBtn.enabled := false;
CloseFile(SavGame);
exit;
end;
ReadLN(SavGame, l);
x := 0;
a := 0;
boss := 'Nein';
while not SeekEOF(SavGame) do
begin
boss := true;
ReadLN(SavGame, Ergebnis);
inc(a);
if a = 5 then a := 1;
if (a = 1) and (Ergebnis = '7') then boss := 'Ja';
inc(x);
end;
end;
 
CloseFile(SavGame);
if a <> 4 then
begin
liu.visible := true;
LadenBtn.enabled := false;
end
else
begin
li1a.visible := true;
li2a.visible := true;
li3a.visible := true;
362,14 → 390,9
li3b.visible := true;
LadenBtn.enabled := true;
LoeschenBtn.enabled := true;
li1b.caption := inttostr(anzahlEinheiten);
if boss then
li2b.caption := 'Ja'
else
li2b.caption := 'Nein';
li3b.caption := IntToStr(LevelData.LevelEditorLength) + ' Felder';
finally
FreeAndNil(LevelData);
li1b.caption := inttostr(trunc(x / 4));
li2b.caption := boss;
li3b.caption := l + ' Felder';
end;
end;
 
418,11 → 441,7
procedure TSpeicherungForm.SpinEditEdtKeyPress(Sender: TObject;
var Key: Char);
begin
{$IFDEF UNICODE}
if not CharInSet(Key, [#13, #08, '0'..'9']) then
{$ELSE}
if not (Key in [#13, #08, '0'..'9']) then
{$ENDIF}
Key := #0;
end;