diff options
author | Erich Eckner <git@eckner.net> | 2016-09-21 15:29:25 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2016-09-21 15:29:25 +0200 |
commit | af27d71dff86ca1f21a242f05b00852f3fa59e2f (patch) | |
tree | e5118c8a773c9d6769a8f75c00721e73a4e039f3 | |
parent | a0b9d3beeb68e0213275d93c74b1137fd0afc017 (diff) | |
download | Raetsel-af27d71dff86ca1f21a242f05b00852f3fa59e2f.tar.xz |
weiteres fertig
-rw-r--r-- | raetsel.lpi | 7 | ||||
-rw-r--r-- | raetsel.lpr | 3 | ||||
-rw-r--r-- | raetsel.lps | 200 | ||||
-rw-r--r-- | raetselunit.pas | 319 | ||||
-rw-r--r-- | unit1.lfm | 11 | ||||
-rw-r--r-- | unit1.pas | 36 | ||||
-rw-r--r-- | unit2.lfm | 20 | ||||
-rw-r--r-- | unit2.pas | 12 |
8 files changed, 523 insertions, 85 deletions
diff --git a/raetsel.lpi b/raetsel.lpi index 4f62b02..4ed092d 100644 --- a/raetsel.lpi +++ b/raetsel.lpi @@ -32,7 +32,7 @@ <PackageName Value="LCL"/> </Item1> </RequiredPackages> - <Units Count="3"> + <Units Count="4"> <Unit0> <Filename Value="raetsel.lpr"/> <IsPartOfProject Value="True"/> @@ -48,9 +48,14 @@ <Filename Value="unit2.pas"/> <IsPartOfProject Value="True"/> <ComponentName Value="Form2"/> + <HasResources Value="True"/> <ResourceBaseClass Value="Form"/> <UnitName Value="Unit2"/> </Unit2> + <Unit3> + <Filename Value="raetselunit.pas"/> + <IsPartOfProject Value="True"/> + </Unit3> </Units> </ProjectOptions> <CompilerOptions> diff --git a/raetsel.lpr b/raetsel.lpr index 22187bf..839a24b 100644 --- a/raetsel.lpr +++ b/raetsel.lpr @@ -7,7 +7,7 @@ uses cthreads, {$ENDIF}{$ENDIF} Interfaces, // this includes the LCL widgetset - Forms, unit1, Unit2 + Forms, unit1, Unit2, raetselunit { you can add units after this }; {$R *.res} @@ -16,7 +16,6 @@ begin RequireDerivedFormResource:=True; Application.Initialize; Application.CreateForm(TForm1, Form1); - Application.CreateForm(TForm2, Form2); Application.Run; end. diff --git a/raetsel.lps b/raetsel.lps index d287696..0cfa3ac 100644 --- a/raetsel.lps +++ b/raetsel.lps @@ -3,15 +3,13 @@ <ProjectSession> <Version Value="9"/> <BuildModes Active="Default"/> - <Units Count="7"> + <Units Count="10"> <Unit0> <Filename Value="raetsel.lpr"/> <IsPartOfProject Value="True"/> <EditorIndex Value="-1"/> - <WindowIndex Value="-1"/> - <TopLine Value="-1"/> - <CursorPos X="-1" Y="-1"/> - <UsageCount Value="25"/> + <CursorPos Y="18"/> + <UsageCount Value="35"/> </Unit0> <Unit1> <Filename Value="unit1.pas"/> @@ -19,31 +17,44 @@ <ComponentName Value="Form1"/> <HasResources Value="True"/> <ResourceBaseClass Value="Form"/> - <IsVisibleTab Value="True"/> - <CursorPos X="24" Y="38"/> - <UsageCount Value="25"/> + <TopLine Value="21"/> + <CursorPos Y="61"/> + <UsageCount Value="35"/> <Loaded Value="True"/> <LoadedDesigner Value="True"/> </Unit1> <Unit2> + <Filename Value="unit2.pas"/> + <IsPartOfProject Value="True"/> + <ComponentName Value="Form2"/> + <HasResources Value="True"/> + <ResourceBaseClass Value="Form"/> + <UnitName Value="Unit2"/> + <EditorIndex Value="2"/> + <CursorPos X="20" Y="12"/> + <UsageCount Value="34"/> + <Loaded Value="True"/> + <LoadedDesigner Value="True"/> + </Unit2> + <Unit3> <Filename Value="Unit1.pas"/> <EditorIndex Value="-1"/> <CursorPos X="3" Y="17"/> - <UsageCount Value="10"/> - </Unit2> - <Unit3> + <UsageCount Value="9"/> + </Unit3> + <Unit4> <Filename Value="RaetselFileUnit.pas"/> <UnitName Value="raetselFileUnit"/> <EditorIndex Value="-1"/> - <UsageCount Value="10"/> - </Unit3> - <Unit4> + <UsageCount Value="9"/> + </Unit4> + <Unit5> <Filename Value="raetselFileUnit.pas"/> <EditorIndex Value="-1"/> <CursorPos X="28" Y="11"/> - <UsageCount Value="10"/> - </Unit4> - <Unit5> + <UsageCount Value="9"/> + </Unit5> + <Unit6> <Filename Value="ori_Unit1.pas"/> <ComponentName Value="Form1"/> <HasResources Value="True"/> @@ -51,62 +62,153 @@ <UnitName Value="Unit1"/> <EditorIndex Value="-1"/> <CursorPos X="15" Y="13"/> - <UsageCount Value="10"/> - </Unit5> - <Unit6> - <Filename Value="unit2.pas"/> + <UsageCount Value="9"/> + </Unit6> + <Unit7> + <Filename Value="raetselunit.pas"/> <IsPartOfProject Value="True"/> - <ComponentName Value="Form2"/> - <ResourceBaseClass Value="Form"/> - <UnitName Value="Unit2"/> + <IsVisibleTab Value="True"/> <EditorIndex Value="1"/> - <TopLine Value="6"/> - <CursorPos X="35" Y="45"/> - <UsageCount Value="24"/> + <TopLine Value="157"/> + <CursorPos X="37" Y="170"/> + <UsageCount Value="29"/> <Loaded Value="True"/> - <LoadedDesigner Value="True"/> - </Unit6> + </Unit7> + <Unit8> + <Filename Value="/usr/share/lazarus/lcl/stdctrls.pp"/> + <UnitName Value="StdCtrls"/> + <EditorIndex Value="-1"/> + <TopLine Value="1255"/> + <CursorPos X="3" Y="1277"/> + <UsageCount Value="9"/> + </Unit8> + <Unit9> + <Filename Value="/usr/share/lazarus/lcl/dialogs.pp"/> + <UnitName Value="Dialogs"/> + <EditorIndex Value="-1"/> + <TopLine Value="487"/> + <CursorPos X="10" Y="509"/> + <UsageCount Value="10"/> + </Unit9> </Units> - <JumpHistory Count="10" HistoryIndex="9"> + <JumpHistory Count="30" HistoryIndex="29"> <Position1> - <Filename Value="unit1.pas"/> - <Caret Line="9" Column="4"/> + <Filename Value="raetselunit.pas"/> + <Caret Line="155" Column="45" TopLine="120"/> </Position1> <Position2> - <Filename Value="unit1.pas"/> - <Caret Line="8" Column="83"/> + <Filename Value="raetselunit.pas"/> </Position2> <Position3> - <Filename Value="unit1.pas"/> - <Caret Line="18" Column="3"/> + <Filename Value="raetselunit.pas"/> + <Caret Line="29" Column="13"/> </Position3> <Position4> - <Filename Value="unit1.pas"/> - <Caret Line="35" Column="6"/> + <Filename Value="raetselunit.pas"/> + <Caret Line="122" Column="39" TopLine="86"/> </Position4> <Position5> - <Filename Value="unit1.pas"/> - <Caret Line="30" Column="3"/> + <Filename Value="raetselunit.pas"/> + <Caret Line="134" Column="15" TopLine="99"/> </Position5> <Position6> - <Filename Value="unit2.pas"/> + <Filename Value="raetselunit.pas"/> + <Caret Line="155" Column="45" TopLine="119"/> </Position6> <Position7> - <Filename Value="unit1.pas"/> - <Caret Line="37" Column="7"/> + <Filename Value="raetselunit.pas"/> + <Caret Line="167" Column="24" TopLine="131"/> </Position7> <Position8> - <Filename Value="unit2.pas"/> - <Caret Line="38" Column="33"/> + <Filename Value="raetselunit.pas"/> </Position8> <Position9> - <Filename Value="unit2.pas"/> - <Caret Line="40" Column="33"/> + <Filename Value="raetselunit.pas"/> + <Caret Line="31" Column="25"/> </Position9> <Position10> - <Filename Value="unit2.pas"/> - <Caret Line="45" Column="35" TopLine="6"/> + <Filename Value="raetselunit.pas"/> + <Caret Line="135" Column="18" TopLine="102"/> </Position10> + <Position11> + <Filename Value="raetselunit.pas"/> + <Caret Line="161" Column="26" TopLine="147"/> + </Position11> + <Position12> + <Filename Value="raetselunit.pas"/> + </Position12> + <Position13> + <Filename Value="raetselunit.pas"/> + <Caret Line="31" Column="25"/> + </Position13> + <Position14> + <Filename Value="raetselunit.pas"/> + <Caret Line="29" Column="13"/> + </Position14> + <Position15> + <Filename Value="raetselunit.pas"/> + <Caret Line="121" Column="41" TopLine="85"/> + </Position15> + <Position16> + <Filename Value="raetselunit.pas"/> + <Caret Line="133" Column="10" TopLine="97"/> + </Position16> + <Position17> + <Filename Value="raetselunit.pas"/> + <Caret Line="121" TopLine="98"/> + </Position17> + <Position18> + <Filename Value="raetselunit.pas"/> + <Caret Line="122" Column="21" TopLine="98"/> + </Position18> + <Position19> + <Filename Value="raetselunit.pas"/> + <Caret Line="135" Column="15" TopLine="99"/> + </Position19> + <Position20> + <Filename Value="raetselunit.pas"/> + <Caret Line="161" Column="85" TopLine="121"/> + </Position20> + <Position21> + <Filename Value="raetselunit.pas"/> + <Caret Line="172" Column="22" TopLine="136"/> + </Position21> + <Position22> + <Filename Value="raetselunit.pas"/> + <Caret Line="185" Column="51" TopLine="149"/> + </Position22> + <Position23> + <Filename Value="raetselunit.pas"/> + <Caret Line="29" Column="13" TopLine="7"/> + </Position23> + <Position24> + <Filename Value="raetselunit.pas"/> + <Caret Line="122" Column="21" TopLine="86"/> + </Position24> + <Position25> + <Filename Value="raetselunit.pas"/> + <Caret Line="135" Column="15" TopLine="99"/> + </Position25> + <Position26> + <Filename Value="raetselunit.pas"/> + <Caret Line="161" Column="50" TopLine="125"/> + </Position26> + <Position27> + <Filename Value="raetselunit.pas"/> + <Caret Line="170" Column="30" TopLine="134"/> + </Position27> + <Position28> + <Filename Value="raetselunit.pas"/> + <Caret Line="171" Column="13" TopLine="135"/> + </Position28> + <Position29> + <Filename Value="raetselunit.pas"/> + <Caret Line="172" Column="22" TopLine="136"/> + </Position29> + <Position30> + <Filename Value="raetselunit.pas"/> + <Caret Line="140" TopLine="109"/> + </Position30> </JumpHistory> </ProjectSession> </CONFIG> diff --git a/raetselunit.pas b/raetselunit.pas new file mode 100644 index 0000000..bdeb19b --- /dev/null +++ b/raetselunit.pas @@ -0,0 +1,319 @@ +unit raetselunit; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, Forms, Spin, Controls, StdCtrls, ExtCtrls; + +type + tAlphabetFunktion = function(i: longint): string; + + tRaetsel = class + private + besitzer: tForm; + zeichenflaeche: tImage; + function besitzerHoehe: longint; dynamic; + function besitzerBreite: longint; dynamic; + procedure zeichenFlaecheNeuKreieren; + public + constructor create(aOwner: tForm); + destructor destroy; override; + procedure zeichnen; dynamic; abstract; + end; + + tFelderRaetsel = class(tRaetsel) + spinEdits: array of tSpinEdit; + diagonalenCB: tCheckBox; + groeszen: array of longint; + felder,rand: array of longint; + dim,schriftGroesze: longint; + zellGroesze: extended; + uebersetze: tAlphabetFunktion; + procedure anzSEsOnChange(sender: tObject); + procedure aktualisiereGroesze; + procedure aktualisiereZeichenflaechenGroesze; + function besitzerHoehe: longint; override; + function besitzerBreite: longint; override; + procedure schreibeZentriert(x,y,i: longint); + public + constructor create(aOwner: tForm; anzInhTypen: longint; alphabetFunktion: tAlphabetFunktion); + destructor destroy; override; + procedure zeichnen; override; + end; + + tBuchstabenRaetsel = class(tFelderRaetsel) + private + public + constructor create(aOwner: tForm); + destructor destroy; override; + end; + + tHochhausRaetsel = class(tFelderRaetsel) + private + public + constructor create(aOwner: tForm); + destructor destroy; override; + end; + +const + spacing = 2; + +function buchstabenAlphabetFunktion(i: longint): string; +function zahlenAlphabetFunktion(i: longint): string; + +implementation + +uses + math; + +// tRaetsel ******************************************************************** + +constructor tRaetsel.create(aOwner: tForm); +begin + inherited create; + besitzer:=aOwner; + zeichenflaeche:=tImage.create(besitzer); + zeichenflaeche.parent:=besitzer; +end; + +destructor tRaetsel.destroy; +begin + zeichenflaeche.free; + inherited destroy; +end; + +function tRaetsel.besitzerHoehe: longint; +begin + result:=zeichenflaeche.height+zeichenflaeche.top+spacing; +end; + +function tRaetsel.besitzerBreite: longint; +begin + result:=zeichenflaeche.width+zeichenflaeche.left+spacing; +end; + +procedure tRaetsel.zeichenFlaecheNeuKreieren; +var + i: tImage; +begin + i:=tImage.create(besitzer); + i.parent:=zeichenflaeche.parent; + i.left:=zeichenflaeche.left; + i.top:=zeichenflaeche.top; + i.width:=zeichenflaeche.width; + i.height:=zeichenflaeche.height; + i.canvas.font.size:=zeichenflaeche.canvas.font.size; + zeichenflaeche.free; + zeichenflaeche:=i; +end; + +// tFelderRaetsel ************************************************************** + +constructor tFelderRaetsel.create(aOwner: tForm; anzInhTypen: longint; alphabetFunktion: tAlphabetFunktion); +var + i: longint; +begin + inherited create(aOwner); + uebersetze:=alphabetFunktion; + setlength(spinEdits,anzInhTypen+1); + setlength(groeszen,length(spinEdits)-1); + for i:=0 to length(spinEdits)-1 do begin + spinEdits[i]:=tSpinEdit.create(besitzer); + with spinEdits[i] do begin + parent:=besitzer; + top:=spacing; + if i>0 then + left:=spinEdits[i-1].left + spinEdits[i-1].width; + left:=left+spacing; + onChange:=@anzSEsOnChange; + tag:=i; + end; + if i>0 then + groeszen[i-1]:=-1; + end; + spinEdits[0].showHint:=true; + spinEdits[0].hint:='Schriftgröße'; + spinEdits[0].value:=7; + diagonalenCB:=tCheckBox.create(besitzer); + diagonalenCB.parent:=besitzer; + diagonalenCB.caption:='Diagonalen'; + diagonalenCB.top:=spacing; + diagonalenCB.left:=spinEdits[length(spinEdits)-1].left+spinEdits[length(spinEdits)-1].width+spacing; + zeichenflaeche.left:=spacing; + zeichenflaeche.top:=diagonalenCB.top+diagonalenCB.height+spacing; + aktualisiereGroesze; +end; + +destructor tFelderRaetsel.destroy; +begin + inherited destroy; +end; + +procedure tFelderRaetsel.anzSEsOnChange(sender: tObject); +begin + if ((sender as tSpinEdit).tag = 0) and + ((sender as tSpinEdit).value <> schriftGroesze) then begin + schriftGroesze:=(sender as tSpinEdit).value; + aktualisiereZeichenflaechenGroesze + end + else if (sender as tSpinEdit).value <> groeszen[(sender as tSpinEdit).tag-1] then + aktualisiereGroesze; +end; + +procedure tFelderRaetsel.aktualisiereGroesze; +var + i: longint; +begin + dim:=0; + schriftGroesze:=spinEdits[0].value; + for i:=0 to length(groeszen)-1 do begin + groeszen[i]:=spinEdits[i+1].value; + dim:=dim+groeszen[i]; + end; + setlength(felder,dim*dim); + for i:=0 to length(felder)-1 do + felder[i]:=random(dim+1)-1; // 0; + setlength(rand,4*dim); + for i:=0 to length(rand)-1 do + rand[i]:=random(dim+1)-1; // 0; + aktualisiereZeichenflaechenGroesze; +end; + +procedure tFelderRaetsel.aktualisiereZeichenflaechenGroesze; +begin + zeichenflaeche.canvas.font.size:=schriftGroesze; + zellGroesze:= + 2*spacing + zeichenflaeche.canvas.pen.width + + max( + zeichenflaeche.canvas.textWidth(uebersetze(dim)), + zeichenflaeche.canvas.textHeight(uebersetze(dim)) + ); + zeichenflaeche.height:=(dim+2)*round(2*zellGroesze); + zeichenflaeche.width:=zeichenflaeche.height; + zeichenFlaecheNeuKreieren; + besitzer.height:=besitzerHoehe; + besitzer.width:=besitzerBreite; + zeichnen; +end; + +function tFelderRaetsel.besitzerHoehe: longint; +var + i: longint; +begin + result:=max(inherited besitzerHoehe,diagonalenCB.top+diagonalenCB.height+spacing); + for i:=0 to length(spinEdits)-1 do + result:=max(result,spinEdits[i].top+spinEdits[i].height+spacing); +end; + +function tFelderRaetsel.besitzerBreite: longint; +var + i: longint; +begin + result:=max(inherited besitzerBreite,diagonalenCB.left+diagonalenCB.width+spacing);; + for i:=0 to length(spinEdits)-1 do + result:=max(result,spinEdits[i].left+spinEdits[i].width+spacing); +end; + +procedure tFelderRaetsel.schreibeZentriert(x,y,i: longint); +var + br,ho: longint; + s: string; +begin + s:=uebersetze(i); + with zeichenflaeche.canvas do begin + br:=textWidth(s); + ho:=textHeight(s); + textOut( + round(2*(x+1.5)*zellGroesze-br/2), + round(2*(y+1.5)*zellGroesze-ho/2), + s + ); + end; +end; + +procedure tFelderRaetsel.zeichnen; +var + i: longint; +begin + zeichenflaeche.canvas.brush.color:=$ffffff; + zeichenflaeche.canvas.rectangle(-10,-10,zeichenflaeche.width+10,zeichenflaeche.height+10); + zeichenflaeche.canvas.pen.width:=3; + for i:=0 to dim do + with zeichenflaeche.canvas do begin + moveTo(round((i+1)*2*zellGroesze),round(2*zellGroesze)); + lineTo(round((i+1)*2*zellGroesze),round((dim+1)*2*zellGroesze)); + moveTo(round(2*zellGroesze),round((i+1)*2*zellGroesze)); + lineTo(round((dim+1)*2*zellGroesze),round((i+1)*2*zellGroesze)); + end; + for i:=0 to dim-1 do begin + schreibeZentriert(i,-1,rand[i]); + schreibeZentriert(dim,i,rand[dim+i]); + schreibeZentriert(i,dim,rand[2*dim+i]); + schreibeZentriert(-1,i,rand[3*dim+i]); + end; + for i:=0 to length(felder)-1 do + schreibeZentriert(i mod dim,i div dim,felder[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; + +// 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; + +// 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. + @@ -1,9 +1,12 @@ object Form1: TForm1 - Left = 1690 - Height = 240 - Top = 197 - Width = 320 + Left = 1722 + Height = 313 + Top = 389 + Width = 426 + BorderStyle = bsSingle Caption = 'Rätsel' OnCreate = FormCreate + OnDestroy = FormDestroy + OnShow = FormShow LCLVersion = '1.6.0.4' end @@ -5,18 +5,22 @@ unit unit1; interface uses - Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, raetselFileUnit; + Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, + raetselunit; type - { TForm1 } + { tForm1 } - TForm1 = class(TForm) + tForm1 = class(tForm) procedure FormCreate(Sender: TObject); + procedure FormDestroy(Sender: TObject); + procedure FormShow(Sender: TObject); private { private declarations } public { public declarations } + raetsel: tRaetsel; end; var @@ -29,15 +33,33 @@ implementation uses unit2; -{ TForm1 } +// tForm1 ********************************************************************** -procedure TForm1.FormCreate(Sender: TObject); +procedure tForm1.formCreate(sender: tObject); begin + application.createForm(tForm2, form2); case form2.showmodal of - mrBuchstabenraetsel: ; - mrHochhausraetsel: ; + mrBuchstabenraetsel: + raetsel:=tBuchstabenRaetsel.create(form1); + mrHochhausraetsel: + raetsel:=tHochhausRaetsel.create(form1); + else begin + raetsel:=nil; + application.terminate; + end; end; end; +procedure tForm1.FormDestroy(Sender: TObject); +begin + raetsel.free; +end; + +procedure tForm1.FormShow(Sender: TObject); +begin + if assigned(raetsel) then + raetsel.zeichnen; +end; + end. @@ -1,28 +1,28 @@ object Form2: TForm2 Left = 1690 - Height = 240 + Height = 94 Top = 197 - Width = 320 + Width = 192 Caption = 'Form2' - ClientHeight = 240 - ClientWidth = 320 + ClientHeight = 94 + ClientWidth = 192 LCLVersion = '1.6.0.4' object Button1: TButton - Left = 80 + Left = 16 Height = 25 - Top = 16 + Top = 56 Width = 160 Caption = 'Hochhausrätsel' - OnClick = Button1Click + ModalResult = 314 TabOrder = 0 end object Button2: TButton - Left = 80 + Left = 16 Height = 25 - Top = 76 + Top = 16 Width = 160 Caption = 'Buchstabenrätsel' - OnClick = Button2Click + ModalResult = 315 TabOrder = 1 end end @@ -14,8 +14,6 @@ type TForm2 = class(TForm) Button1: TButton; Button2: TButton; - procedure Button1Click(Sender: TObject); - procedure Button2Click(Sender: TObject); private { private declarations } public @@ -35,15 +33,5 @@ implementation { TForm2 } -procedure TForm2.Button1Click(Sender: TObject); -begin - modalResult:=mrHochhausraetsel; -end; - -procedure TForm2.Button2Click(Sender: TObject); -begin - modalResult:=mrBuchstabenraetsel; -end; - end. |