From d81c2373be6697e2ebcfd082831115c4f182b6a0 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Sun, 30 Sep 2018 21:29:21 +0200 Subject: buchstabenunit.pas & hochhausunit.pas neu --- buchstabenunit.pas | 108 ++++++++++++++++++++++++++++++++++++ hochhausunit.pas | 82 +++++++++++++++++++++++++++ raetsel.lpi | 10 +++- raetsel.lpr | 2 +- raetsel.lps | 131 ++++++++++++++++++++++++------------------- raetselunit.pas | 160 +---------------------------------------------------- unit1.lfm | 2 +- unit1.pas | 2 +- 8 files changed, 277 insertions(+), 220 deletions(-) create mode 100644 buchstabenunit.pas create mode 100644 hochhausunit.pas diff --git a/buchstabenunit.pas b/buchstabenunit.pas new file mode 100644 index 0000000..718a70d --- /dev/null +++ b/buchstabenunit.pas @@ -0,0 +1,108 @@ +unit buchstabenunit; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, raetselunit, Forms; + +type + tBuchstabenRaetsel = class(tFelderRaetsel) + private + procedure relativeInhaltsAenderung(diff: longint); override; + function absoluteInhaltsAenderung(key: word): boolean; override; + public + constructor create(aOwner: tForm); + destructor destroy; override; + function _loesen(lm: tFelderLoesMeta): longint; override; + end; + +function buchstabenAlphabetFunktion(i: longint): string; + +implementation + +uses + math; + +function buchstabenAlphabetFunktion(i: longint): string; +begin + if i<0 then + result:='' + else if i=0 then + result:='-' + else begin + result:=''; + while i>0 do begin + dec(i); + result:=char(ord('A')+(i mod 26))+result; + i:=i div 26; + end; + end; +end; + +// tBuchstabenRaetsel ********************************************************** + +constructor tBuchstabenRaetsel.create(aOwner: tForm); +begin + inherited create(aOwner,2,@buchstabenAlphabetFunktion); + spinEdits[1].showHint:=true; + spinEdits[1].hint:='Anzahl Buchstaben'; + spinEdits[1].value:=5; + spinEdits[2].showHint:=true; + spinEdits[2].hint:='Anzahl Leerfelder'; + spinEdits[2].value:=1; + aktualisiereGroesze; +end; + +destructor tBuchstabenRaetsel.destroy; +begin + inherited destroy; +end; + +procedure tBuchstabenRaetsel.relativeInhaltsAenderung(diff: longint); +begin + if (cursorPosition<0) or (cursorPosition>=dim*dim) then exit; + inhalt[cursorPosition]:=min(max(-1,inhalt[cursorPosition]+diff),groeszen[0]); +end; + +function tBuchstabenRaetsel.absoluteInhaltsAenderung(key: word): boolean; +begin + result:=true; + if (key>=ord('A')) and (key<=min(ord('A')+groeszen[0]-1,ord('Z'))) then begin + inhalt[cursorPosition]:=key-ord('A')+1; + exit; + end; + if (key=ord(' ')) or (key=46) or (key=8) then begin + inhalt[cursorPosition]:=-1; + exit; + end; + if (key=189) then begin + inhalt[cursorPosition]:=0; + exit; + end; + result:=false; +end; + +function tBuchstabenRaetsel._loesen(lm: tFelderLoesMeta): longint; +begin + if not lm.fwd then begin + result:=1; + exit; + end; + if inhalt[lm.posi]>=0 then begin + result:=_loesen(lm); + exit; + end; + + result:=0; + //for + + if not lm.inhaltBehalten then begin + inhalt[lm.posi]:=-1; + lm.aktualisiereInhalt(lm.posi); + end; +end; + +end. + diff --git a/hochhausunit.pas b/hochhausunit.pas new file mode 100644 index 0000000..7a98f6a --- /dev/null +++ b/hochhausunit.pas @@ -0,0 +1,82 @@ +unit hochhausunit; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, raetselunit, Forms; + +type + tHochhausRaetsel = class(tFelderRaetsel) + private + procedure relativeInhaltsAenderung(diff: longint); override; + function absoluteInhaltsAenderung(key: word): boolean; override; + public + constructor create(aOwner: tForm); + destructor destroy; override; + function _loesen(lm: tFelderLoesMeta): longint; override; + end; + +function zahlenAlphabetFunktion(i: longint): string; + +implementation + +uses + math; + +function zahlenAlphabetFunktion(i: longint): string; +begin + if i<0 then + result:='' + else if i=0 then + result:='-' + else + result:=inttostr(i); +end; + +// tHochhausRaetsel ************************************************************ + +constructor tHochhausRaetsel.create(aOwner: tForm); +begin + inherited create(aOwner,1,@zahlenAlphabetFunktion); + spinEdits[1].showHint:=true; + spinEdits[1].hint:='Anzahl Spalten'; + spinEdits[1].value:=5; + aktualisiereGroesze; +end; + +destructor tHochhausRaetsel.destroy; +begin + inherited destroy; +end; + +procedure tHochhausRaetsel.relativeInhaltsAenderung(diff: longint); +begin + if (cursorPosition<0) or (cursorPosition>=dim*dim) then exit; + if inhalt[cursorPosition]=-1 then inhalt[cursorPosition]:=0; + inhalt[cursorPosition]:=min(max(0,inhalt[cursorPosition]+diff),groeszen[0]); + if inhalt[cursorPosition]=0 then inhalt[cursorPosition]:=-1; +end; + +function tHochhausRaetsel.absoluteInhaltsAenderung(key: word): boolean; +begin + result:=true; + if (key>=ord('1')) and (key<=min(ord('1')+groeszen[0]-1,ord('9'))) then begin + inhalt[cursorPosition]:=key-ord('1')+1; + exit; + end; + if (key=ord(' ')) or (key=46) or (key=8) then begin + inhalt[cursorPosition]:=-1; + exit; + end; + result:=false; +end; + +function tHochhausRaetsel._loesen(lm: tFelderLoesMeta): longint; +begin + +end; + +end. + diff --git a/raetsel.lpi b/raetsel.lpi index 618272c..0b62fb2 100644 --- a/raetsel.lpi +++ b/raetsel.lpi @@ -29,7 +29,7 @@ - + @@ -53,6 +53,14 @@ + + + + + + + + diff --git a/raetsel.lpr b/raetsel.lpr index 839a24b..92f798f 100644 --- a/raetsel.lpr +++ b/raetsel.lpr @@ -7,7 +7,7 @@ uses cthreads, {$ENDIF}{$ENDIF} Interfaces, // this includes the LCL widgetset - Forms, unit1, Unit2, raetselunit + Forms, unit1, Unit2, raetselunit, buchstabenunit, hochhausunit { you can add units after this }; {$R *.res} diff --git a/raetsel.lps b/raetsel.lps index 3b8bb0d..9ca4488 100644 --- a/raetsel.lps +++ b/raetsel.lps @@ -3,13 +3,13 @@ - + - + @@ -17,9 +17,9 @@ - - - + + + @@ -30,20 +30,19 @@ - + - + - - - - + + + @@ -92,132 +91,148 @@ - + - + + + + + + + + + + + + + + + + + + - - + + - - + + - - + + - - + + - - + + - + - - + + - - + + - - + + - - + + - - + - + - + - + - - + + - + - + - + - + - - - + + - + - + - + - - + + - + + - - + + - - + + - - + + diff --git a/raetselunit.pas b/raetselunit.pas index a5c63d5..2d60340 100644 --- a/raetselunit.pas +++ b/raetselunit.pas @@ -43,11 +43,11 @@ type procedure erzeugeOnClick(sender: tObject); procedure loeschen; dynamic; abstract; function loesen(inhaltBehalten: boolean): longint; dynamic; abstract; - function _loesen(lm: tFelderLoesMeta): longint; dynamic; abstract; procedure leeren; dynamic; abstract; public constructor create(aOwner: tForm); destructor destroy; override; + function _loesen(lm: tFelderLoesMeta): longint; dynamic; abstract; procedure zeichnen; dynamic; abstract; end; @@ -78,32 +78,9 @@ type procedure zeichnen; override; end; - tBuchstabenRaetsel = class(tFelderRaetsel) - private - procedure relativeInhaltsAenderung(diff: longint); override; - function absoluteInhaltsAenderung(key: word): boolean; override; - function _loesen(lm: tFelderLoesMeta): longint; override; - public - constructor create(aOwner: tForm); - destructor destroy; override; - end; - - tHochhausRaetsel = class(tFelderRaetsel) - private - procedure relativeInhaltsAenderung(diff: longint); override; - function absoluteInhaltsAenderung(key: word): boolean; override; - function _loesen(lm: tFelderLoesMeta): longint; override; - public - constructor create(aOwner: tForm); - destructor destroy; override; - end; - const spacing = 2; -function buchstabenAlphabetFunktion(i: longint): string; -function zahlenAlphabetFunktion(i: longint): string; - implementation uses @@ -386,6 +363,7 @@ begin lm.aktualisiereRand(p[i]); end; end; + lm.free; end; procedure tFelderRaetsel.aktualisiereZeichenflaechenGroesze; @@ -473,139 +451,5 @@ begin schreibeZentriert(i mod dim,i div dim,inhalt[i]); end; -// tBuchstabenRaetsel ********************************************************** - -constructor tBuchstabenRaetsel.create(aOwner: tForm); -begin - inherited create(aOwner,2,@buchstabenAlphabetFunktion); - spinEdits[1].showHint:=true; - spinEdits[1].hint:='Anzahl Buchstaben'; - spinEdits[1].value:=5; - spinEdits[2].showHint:=true; - spinEdits[2].hint:='Anzahl Leerfelder'; - spinEdits[2].value:=1; - aktualisiereGroesze; -end; - -destructor tBuchstabenRaetsel.destroy; -begin - inherited destroy; -end; - -procedure tBuchstabenRaetsel.relativeInhaltsAenderung(diff: longint); -begin - if (cursorPosition<0) or (cursorPosition>=dim*dim) then exit; - inhalt[cursorPosition]:=min(max(-1,inhalt[cursorPosition]+diff),groeszen[0]); -end; - -function tBuchstabenRaetsel.absoluteInhaltsAenderung(key: word): boolean; -begin - result:=true; - if (key>=ord('A')) and (key<=min(ord('A')+groeszen[0]-1,ord('Z'))) then begin - inhalt[cursorPosition]:=key-ord('A')+1; - exit; - end; - if (key=ord(' ')) or (key=46) or (key=8) then begin - inhalt[cursorPosition]:=-1; - exit; - end; - if (key=189) then begin - inhalt[cursorPosition]:=0; - exit; - end; - result:=false; -end; - -function tBuchstabenRaetsel._loesen(lm: tFelderLoesMeta): longint; -begin - if not lm.fwd then begin - result:=1; - exit; - end; - if inhalt[lm.posi]>=0 then begin - result:=_loesen(lm); - exit; - end; - - result:=0; - //for - - if not lm.inhaltBehalten then begin - inhalt[lm.posi]:=-1; - lm.aktualisiereInhalt(lm.posi); - end; -end; - -// tHochhausRaetsel ************************************************************ - -constructor tHochhausRaetsel.create(aOwner: tForm); -begin - inherited create(aOwner,1,@zahlenAlphabetFunktion); - spinEdits[1].showHint:=true; - spinEdits[1].hint:='Anzahl Spalten'; - spinEdits[1].value:=5; - aktualisiereGroesze; -end; - -destructor tHochhausRaetsel.destroy; -begin - inherited destroy; -end; - -procedure tHochhausRaetsel.relativeInhaltsAenderung(diff: longint); -begin - if (cursorPosition<0) or (cursorPosition>=dim*dim) then exit; - if inhalt[cursorPosition]=-1 then inhalt[cursorPosition]:=0; - inhalt[cursorPosition]:=min(max(0,inhalt[cursorPosition]+diff),groeszen[0]); - if inhalt[cursorPosition]=0 then inhalt[cursorPosition]:=-1; -end; - -function tHochhausRaetsel.absoluteInhaltsAenderung(key: word): boolean; -begin - result:=true; - if (key>=ord('1')) and (key<=min(ord('1')+groeszen[0]-1,ord('9'))) then begin - inhalt[cursorPosition]:=key-ord('1')+1; - exit; - end; - if (key=ord(' ')) or (key=46) or (key=8) then begin - inhalt[cursorPosition]:=-1; - exit; - end; - result:=false; -end; - -function tHochhausRaetsel._loesen(lm: tFelderLoesMeta): longint; -begin - -end; - -// allgemeine Funktionen ******************************************************* - -function buchstabenAlphabetFunktion(i: longint): string; -begin - if i<0 then - result:='' - else if i=0 then - result:='-' - else begin - result:=''; - while i>0 do begin - dec(i); - result:=char(ord('A')+(i mod 26))+result; - i:=i div 26; - end; - end; -end; - -function zahlenAlphabetFunktion(i: longint): string; -begin - if i<0 then - result:='' - else if i=0 then - result:='-' - else - result:=inttostr(i); -end; - end. diff --git a/unit1.lfm b/unit1.lfm index 9d5b43d..e06801d 100644 --- a/unit1.lfm +++ b/unit1.lfm @@ -8,5 +8,5 @@ object Form1: TForm1 OnCreate = FormCreate OnDestroy = FormDestroy OnShow = FormShow - LCLVersion = '1.6.0.4' + LCLVersion = '1.8.4.0' end diff --git a/unit1.pas b/unit1.pas index 795ecf3..d9e333a 100644 --- a/unit1.pas +++ b/unit1.pas @@ -31,7 +31,7 @@ implementation {$R *.lfm} uses - unit2; + unit2, hochhausunit, buchstabenunit; // tForm1 ********************************************************************** -- cgit v1.2.3-70-g09d2