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 gleichzeitigMoeglich(num: longint): longint; 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.gleichzeitigMoeglich(num: longint): longint; begin if num=0 then result:=groeszen[0] // so viele Leerzeichen else result:=1; // jeder Buchstabe nur ein Mal end; function tBuchstabenRaetsel._loesen(lm: tFelderLoesMeta): longint; var w: 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 w:=inhalt[lm.posi]; inhalt[lm.posi]:=-1; lm.aktualisiereInhalt(lm.posi,w); end; end; end.