summaryrefslogtreecommitdiff
path: root/hochhausunit.pas
blob: 7a98f6af402d9780f382b587df514c720a6a2c1b (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
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.