summaryrefslogtreecommitdiff
path: root/buchstabenunit.pas
blob: 42d7f331c3ff36ae8c298e9f91a98b69d973ca2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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.