home *** CD-ROM | disk | FTP | other *** search
- unit Unstrom;
- interface
- uses Obraz3D, Unhejb, Unobdel, Unfront;
-
- const
- __N = 0;
- __L = 1;
- __R = 2;
- __Lr = __L+__R;
- const Maxur = 5;
-
- type Typ_Spoj =
- object(Typ_Hejbaci)
- Typ : Byte;
- Velikost : Byte;
- procedure Vytvor(Ur : Typ_Souradnic; _L, _R : Boolean; Nbarva : Byte);
- procedure Pridej(Ur : Typ_Souradnic; _L, _R : Boolean; Nbarva : Byte);
- procedure _Zobraz; virtual;
- procedure _Zhasni; virtual;
- procedure _Presun_Rel(X, Y, Z : Typ_Souradnic);virtual;
- procedure Prazdny;
- constructor Init;
- end;
-
- Vtyp_Strom_Ptr = ^Vtyp_Strom;
- Vtyp_Strom =
- object(Typ_Hejbaci_Zaklad)
- Klic : Integer;
-
- Uroven : Byte;
- Koren : Typ_Line;
- Levy, Pravy : Vtyp_Strom_Ptr;
- Spoj : Typ_Spoj;
-
- function Vaha : Integer;
- function Hloubka : Integer;
-
- procedure _Neni_List;
- procedure _Je_List;
- procedure _Srovnat_List;
-
- procedure Vytvor(S : string; C1 : Byte);
- procedure set_Barva(_C : Byte);virtual;
-
- procedure Delej_Levy(Prvek : Typ_Obdelnik; _Klic : Integer);
- { vytvori levy list stromu a pripadne zobrazi }
- procedure Delej_Pravy(Prvek : Typ_Obdelnik; _Klic : Integer);
- { vytvori pravy list stromu a pripadne zobrazi }
-
- procedure Slevy(Prvek : Vtyp_Strom_Ptr);
- { priradi prvek jako levy podstrom, prvek nesmi byt jinde ve stromu ! }
- procedure Spravy(Prvek : Vtyp_Strom_Ptr);
-
- procedure Right_Rotation;
- procedure Left_Rotation;
-
- procedure Anim_Right_Rotation;
- procedure Anim_Left_Rotation;
-
- function Lpoloha : Ptr__Bod3D;
- function Ppoloha : Ptr__Bod3D;
-
- procedure Anim_Insert( Prvek : Integer);
-
- procedure Vinsert( Prvek : Integer );
- procedure Vanim_Insert( Prvek : Integer );
-
- procedure Anim_in_Rozmistit;
- procedure Anim_Obnov;
-
- procedure Zrus_Levy;
- procedure Zrus_Pravy;
-
- procedure Prohod(var Strom : Vtyp_Strom);
-
- procedure _Zobraz;virtual;
- procedure _Zhasni;virtual;
- procedure _Presun_Rel(X, Y, Z : Typ_Souradnic);virtual;
- procedure _Obnov; virtual;
- constructor Init;
- destructor Zrus;
- end;
-
- function __Velikost(Uroven : Integer): Integer;
- function Lpoloha( _Bod : _Bod3D; Rozkorx, Uroven : Integer):Ptr__Bod3D;
- function Ppoloha( _Bod : _Bod3D; Rozkorx, Uroven : Integer):Ptr__Bod3D;
-
- procedure set_Pocatek_Animace(X, Y, Z : Typ_Souradnic);
- procedure set_Velikost(Velikost : real);
-
- implementation
- uses Dos;
- const ___Pocatek : _Bod3D = (X:0;Y:0;Z:0);
- __Velikost_Stromu : real = 0.7;
-
- procedure Vtyp_Strom.Anim_Obnov;
- begin
- Koren.Zobraz;
- Stav := Stav or __Videt;
- Koren.set_Barvar(-3);
- Koren.Dodel_Anim_Posun_Bod(Poloha);
- _Srovnat_List;
- if Levy <> nil then
- begin
- Levy^.Uroven := Uroven+1;
- Levy^.Poloha := Lpoloha^;
- Levy^.Anim_Obnov;
- end;
- if Pravy <> nil then
- begin
- Pravy^.Uroven := Uroven+1;
- Pravy^.Poloha := Ppoloha^;
- Pravy^.Anim_Obnov;
- end;
- if (Levy <> nil) or (Pravy<>nil) then
- begin
- Spoj.Prazdny;
- Spoj.Vytvor( Uroven,
- Levy <> nil,
- Pravy <> nil,
- Koren.Dej_Bod(0)^.Obsah.Atrib);
- Spoj.Presun(Poloha.X+Koren.Rozmer.X+1,
- Poloha.Y+1,
- Poloha.Z);
-
-
- Spoj.Zobraz
- end;
- Stav := Stav or __Videt;
- end;
-
-
- procedure Vtyp_Strom.Anim_in_Rozmistit;
- var I : Integer;
- procedure Rekurse(Pom : Vtyp_Strom_Ptr);
- begin
- if Pom^.Levy <> nil then Rekurse(Pom^.Levy);
- if Pom^.Koren.Je_Tvar then
- begin
- if Pom^.Spoj.Je_Tvar then Pom^.Spoj.Zhasni;
- Pom^._Je_List;
- Pom^.Koren.set_Barvar(3);
- Pom^.Koren.Dodel_Anim_Posun_Bod(Hezky_Rozmistit(I)^);
- Inc(I)
- end;
- if Pom^.Pravy <> nil then Rekurse(Pom^.Pravy);
- end;
- begin
- I:= 1;
- Rekurse(@Self);
- end;
-
- procedure Vtyp_Strom.Anim_Insert( Prvek : Integer );
- var Obd : Typ_Line;
- S : string[10];
- Koncit : Boolean;
- Fn : Vtyp_Strom_Ptr;
- begin
- Obd.Init;
- Obd.Presun_Bod(___Pocatek);
- Str(Prvek, S);
- if Klic = Maxint then
- begin
- Vytvor(S, 10);
- Presun(0,Obrazovka.Y_Obr shr 1-1,0);
- Klic := Prvek;
- Zobraz
- end
- else
- begin
- Obd.Vytvor_string_Ram(S,Barva+1,Barva+2,Strom_Ram);
- Obd.Zobraz;
- Obd.Dodel_Anim_Posun_Bod(Poloha);
-
- Koncit := False;
- Fn := @Self;
- repeat { zatrideni }
-
- if Fn^.Klic > Prvek then
- begin
- if Fn^.Levy = nil then
- begin
- Obd.Dodel_Anim_Posun_Bod(Fn^.Lpoloha^);
- Obd.set_Barva(Barva);
- Fn^.Delej_Levy(Obd,Prvek);
- Koncit := True;
- end
- else
- begin
- Obd.Dodel_Anim_Posun_Bod(Fn^.Levy^.Poloha);
- Fn := Fn^.Levy;
- end;
- end
- else if Fn^.Klic < Prvek then
- begin
- if Fn^.Pravy = nil then
- begin
- Obd.Dodel_Anim_Posun_Bod(Fn^.Ppoloha^);
- Obd.set_Barva(Barva);
- Fn^.Delej_Pravy(Obd,Prvek);
- Koncit := True;
- end
- else
- begin
- Obd.Dodel_Anim_Posun_Bod(Fn^.Pravy^.Poloha);
- Fn := Fn^.Pravy;
- end;
- end
- else begin Koncit := True; end;
- until Koncit;
- end;
- Obd.Zrus;
- end;
-
- procedure Vtyp_Strom.Vanim_Insert( Prvek : Integer );
- var S : string;
- Je : Boolean;
- Tmp, Tmp1, Pom, _A, _B, Fa : Vtyp_Strom_Ptr;
- Obd : Typ_Line;
-
- begin
- Obd.Init;
- Obd.Presun_Bod(___Pocatek);
-
- Str(Prvek, S);
- Obd.Vytvor_string_Ram(S,Barva+1,Barva+1,Strom_Ram);
- Obd.Zobraz;
-
- Obd.Dodel_Anim_Posun_Bod(Poloha);
- if Klic = Maxint then
- begin
- Vytvor(S,10);
- Klic := Prvek;
- Zobraz
- end
- else
- begin
-
- Je := False;
- Tmp := @Self;
- Tmp1 := nil;
- _A := Tmp;
- Fa := nil;
-
- while not (Tmp = nil) and (not Je) do
- begin
- if Tmp^.Klic = Prvek then Je := True
- else
- begin
- if Prvek < Tmp^.Klic
- then
- begin
- Obd.Dodel_Anim_Posun_Bod(Tmp^.Lpoloha^);
- Pom := Tmp^.Levy
- end
- else
- begin
- Obd.Dodel_Anim_Posun_Bod(Tmp^.Ppoloha^);
- Pom := Tmp^.Pravy;
- end;
- if (not (Pom = nil)) then if (Pom^.Vaha <> 0) then
- begin _A := Pom; Fa := Tmp end;
- Tmp1 := Tmp;
- Tmp := Pom
- end;
- end;
- if not Je then
- if Tmp1 = nil then
- begin Tmp1 := Tmp1;
- end
- else
- begin
- Obd.set_Barva(Barva);
- if Prvek < Tmp1^.Klic
- then Tmp1^.Delej_Levy(Obd,Prvek)
- else Tmp1^.Delej_Pravy(Obd,Prvek);
- Obd.Zhasni;
-
- if _A^.Vaha = 2 then
- begin
- _B := _A^.Levy;
- if _B^.Klic < Prvek then _B^.Anim_Left_Rotation;
- _A^.Anim_Right_Rotation;
- end
- else if _A^.Vaha = -2 then
- begin
- _B := _A^.Pravy;
- if _B^.Klic > Prvek then _B^.Anim_Right_Rotation;
- _A^.Anim_Left_Rotation;
- end;
- end;
- end;
- Obd.Zrus;
- end;
-
- procedure Vtyp_Strom.Vinsert(Prvek : Integer);
- var S : string;
- Je : Boolean;
- Tmp, Tmp1, Pom, _A, _B, Fa : Vtyp_Strom_Ptr;
- Obd : Typ_Line;
-
- begin
- Obd.Init;
- Str(Prvek, S);
- if Klic = Maxint then
- begin
- Vytvor(S,10);
- Presun(0,Obrazovka.Y_Obr shr 1-1,0);
- Klic := Prvek;
- Zobraz
- end
- else
- begin
- Obd.Vytvor_string_Ram(S, 10,10,Strom_Ram);
-
- Je := False;
- Tmp := @Self;
- Tmp1 := nil;
- _A := Tmp;
- Fa := nil;
-
- while not (Tmp = nil) and (not Je) do
- begin
- if Tmp^.Klic = Prvek then Je := True
- else
- begin
- if Prvek < Tmp^.Klic
- then Pom := Tmp^.Levy
- else Pom := Tmp^.Pravy;
- if (not (Pom = nil)) then if (Pom^.Vaha <> 0) then
- begin _A := Pom; Fa := Tmp end;
- Tmp1 := Tmp;
- Tmp := Pom
- end;
- end;
- if not Je then
- if Tmp1 = nil then
- begin Tmp1 := Tmp1;
- end
- else
- begin
- if Prvek < Tmp1^.Klic
- then Tmp1^.Delej_Levy(Obd,Prvek)
- else Tmp1^.Delej_Pravy(Obd,Prvek);
- if _A^.Vaha = 2 then
- begin
- _B := _A^.Levy;
- if _B^.Klic < Prvek then _B^.Left_Rotation;
- _A^.Right_Rotation;
- end
- else if _A^.Vaha = -2 then
- begin
- _B := _A^.Pravy;
- if _B^.Klic > Prvek then _B^.Right_Rotation;
- _A^.Left_Rotation;
- end;
- end;
- end;
- Obd.Zrus;
- if (Koren.Stav and __Videt) = 0 then
- Koren.Stav := Koren.Stav+1-1
- end;
-
- function Lpoloha( _Bod : _Bod3D; Rozkorx, Uroven : Integer):Ptr__Bod3D;
- begin
- Lpoloha := @___Bod;
- ___Bod.X := _Bod.X+Rozkorx+2;
- ___Bod.Y := _Bod.Y-__Velikost(Uroven);
- ___Bod.Z := _Bod.Z;
- end;
-
- function Ppoloha( _Bod : _Bod3D; Rozkorx, Uroven : Integer):Ptr__Bod3D;
- begin
- Ppoloha := @___Bod;
- ___Bod.X := _Bod.X+Rozkorx+2;
- ___Bod.Y := _Bod.Y+__Velikost(Uroven);
- ___Bod.Z := _Bod.Z;
- end;
-
-
- function Vtyp_Strom.Lpoloha : Ptr__Bod3D;
- begin
- Lpoloha := @___Bod;
- ___Bod.X := Poloha.X+Koren.Rozmer.X+2;
- ___Bod.Y := Poloha.Y-__Velikost(Uroven);
- ___Bod.Z := Poloha.Z;
- end;
-
- function Vtyp_Strom.Ppoloha : Ptr__Bod3D;
- begin
- Ppoloha := @___Bod;
- ___Bod.X := Poloha.X+Koren.Rozmer.X+2;
- ___Bod.Y := Poloha.Y+__Velikost(Uroven);
- ___Bod.Z := Poloha.Z;
- end;
-
- function Vtyp_Strom.Vaha : Integer;
- begin
- if Levy = nil
- then if Pravy = nil
- then Vaha := 0
- else Vaha := -Pravy^.Hloubka
- else if Pravy = nil
- then Vaha := Levy^.Hloubka
- else Vaha := Levy^.Hloubka - Pravy^.Hloubka
- end;
-
- function Vtyp_Strom.Hloubka : Integer;
- function Max(A,B : Integer) : Integer;
- begin
- if A > B then Max := A else Max := B
- end;
-
- begin
- if (Levy = nil) and (Pravy = nil)
- then Hloubka := 1
- else if Levy = nil then Hloubka := Pravy^.Hloubka+1
- else if Pravy = nil then Hloubka := Levy^.Hloubka+1
- else Hloubka := Max(Levy^.Hloubka,Pravy^.Hloubka)+1;
- end;
-
- procedure Vtyp_Strom.Delej_Levy(Prvek : Typ_Obdelnik; _Klic : Integer);
- begin
- if Levy = nil then
- begin
- New(Levy, Init);
- Levy^.Presun_Bod(Lpoloha^);
-
- Levy^.Koren.Prirad(Prvek);
- Levy^.Stav := Levy^.Stav or __Existuje_Tvar;
-
- Levy^.Uroven := Uroven+1;
- Levy^.Klic := _Klic;
-
- Spoj.Pridej(Uroven, True, False, Koren.Barva);
- Spoj.Presun(Poloha.X+Koren.Rozmer.X+1, Poloha.Y+1, Poloha.Z);
- if (__Videt and Stav) <> 0 then
- begin
- Levy^.Zobraz;
- Spoj.Zobraz;
- end;
- end;
- _Neni_List;
- end;
-
- procedure Vtyp_Strom.Delej_Pravy(Prvek : Typ_Obdelnik; _Klic : Integer);
- begin
- if Pravy = nil then
- begin
- New(Pravy, Init);
- Pravy^.Presun_Bod(Ppoloha^);
-
- Pravy^.Koren.Prirad(Prvek);
- Pravy^.Stav := Pravy^.Stav or __Existuje_Tvar;
-
- Pravy^.Uroven := Uroven+1;
- Pravy^.Klic := _Klic;
-
- Spoj.Pridej( Uroven,
- False, True,
- Koren.Dej_Bod(0)^.Obsah.Atrib);
- Spoj.Presun(Poloha.X+Koren.Rozmer.X+1, Poloha.Y+1, Poloha.Z);
- if (__Videt and Stav) <> 0 then
- begin
- Pravy^.Zobraz;
- Spoj.Zobraz;
- end;
- end;
- _Neni_List;
- end;
-
- procedure Vtyp_Strom.Slevy(Prvek : Vtyp_Strom_Ptr);
- begin
- if Levy = nil then
- begin
- Levy := Prvek;
-
- Levy^.Uroven := Uroven+1;
-
- Levy^.Poloha := Lpoloha^;
-
- Spoj.Pridej( Uroven, True, False,
- Koren.Dej_Bod(0)^.Obsah.Atrib);
- Spoj.Presun(Poloha.X+Koren.Rozmer.X+1, Poloha.Y+1, Poloha.Z);
- if (__Videt and Stav) <> 0 then
- begin
- Levy^._Obnov;
- Spoj.Zobraz;
- end;
- end;
- _Neni_List;
- end;
-
- procedure Vtyp_Strom.Spravy(Prvek : Vtyp_Strom_Ptr);
- begin
- if Pravy = nil then
- begin
- Pravy := Prvek;
-
- Pravy^.Uroven := Uroven+1;
- Pravy^.Poloha := Ppoloha^;
-
- Spoj.Pridej( Uroven, False, True,
- Koren.Dej_Bod(0)^.Obsah.Atrib);
- Spoj.Presun(Poloha.X+Koren.Rozmer.X+1, Poloha.Y+1, Poloha.Z);
- if (__Videt and Stav) <> 0 then
- begin
- Pravy^._Obnov;
- Spoj.Zobraz;
- end;
- end;
- _Neni_List;
- end;
-
- procedure Vtyp_Strom.set_Barva(_C : Byte);
- begin
- if Levy <> nil then Levy^.set_Barva(_C);
- if Pravy <> nil then Pravy^.set_Barva(_C);
- Koren.set_Barva(_C);
- Spoj.set_Barva(_C);
- Barva := _C;
- end;
-
- procedure Vtyp_Strom.Right_Rotation;
- var _B, _D : Vtyp_Strom_Ptr;
- Pp : Vtyp_Strom;
-
- begin
- if Levy = nil then WriteLn('error right')
- else
- begin
- set_Barva(Koren.Dej_Bod(0)^.Obsah.Atrib+1);
- Pp.Init;
- Zhasni;
- _B := Levy;
- _D := _B^.Pravy;
-
- _B^.Zrus_Pravy; { ulozen v D }
- Zrus_Levy; { levy ulozen v B }
-
- Pp := Self;
- Self := _B^;
- _B^ := Pp;
-
-
- Pravy := _B;
- _B^.Levy := _D;
-
- Poloha := Pp.Poloha;
- Uroven := Pp.Uroven;
-
- _Srovnat_List;
- _B^._Srovnat_List;
-
- _Obnov;
- set_Barva(Koren.Dej_Bod(0)^.Obsah.Atrib-1);
- end;
- end;
-
- procedure Vtyp_Strom.Left_Rotation;
- var C, _D : Vtyp_Strom_Ptr;
- Pp : Vtyp_Strom;
-
- begin
- if Pravy = nil then WriteLn('error left')
- else
- begin
- set_Barva(Koren.Dej_Bod(0)^.Obsah.Atrib-1);
- Pp.Init;
-
- C := Pravy;
- _D := C^.Levy;
-
- C^.Zrus_Levy;
- Zrus_Pravy;
-
- Pp := Self;
- Self := C^;
- C^ := Pp;
-
- Levy := C;
- C^.Pravy := _D;
-
- Poloha := Pp.Poloha;
- Uroven := Pp.Uroven;
-
- _Srovnat_List;
- C^._Srovnat_List;
-
- _Obnov;
- set_Barva(Koren.Dej_Bod(0)^.Obsah.Atrib+1);
- end;
- end;
-
- procedure Vtyp_Strom.Anim_Right_Rotation;
- var _B, _D : Vtyp_Strom_Ptr;
- Pp : Vtyp_Strom;
- var Pom_Fronta : Typ_Hejb_Fronta;
- begin
- if Levy = nil then WriteLn('error right')
- else
- begin
- Pom_Fronta.Init;
-
- set_Barva(Koren.Dej_Bod(0)^.Obsah.Atrib+1);
- Pp.Init;
- Zhasni;
- _B := Levy;
- _D := _B^.Pravy;
-
- _B^.Zrus_Pravy; { ulozen v D }
- Zrus_Levy; { levy ulozen v B }
-
- _B^._Obnov;
- if _D <> nil then _D^._Obnov;
-
- if _D <> nil then
- begin
- _D^.Anim_Posun_Bod(Unstrom.Lpoloha(Ppoloha^,Koren.Rozmer.X,Uroven+1)^);
- Pom_Fronta.Zarad_Prvek(_D^);
- end;
-
- Dec(_B^.Uroven);
- _B^._Obnov;
- _B^.Anim_Posun_Bod(Poloha);
- Pom_Fronta.Zarad_Prvek(_B^);
-
- Anim_Posun_Bod(Ppoloha^);
- Pom_Fronta.Zarad_Prvek(Self);
- Inc(Uroven);
- _Obnov;
-
- Pom_Fronta.Dodelej_Pohyb;
-
- Pp := Self;
- Self := _B^;
- _B^ := Pp;
-
- Pravy := _B;
- _B^.Levy := _D;
-
- _Srovnat_List;
- _B^._Srovnat_List;
-
- _Obnov;
- set_Barva(Koren.Dej_Bod(0)^.Obsah.Atrib-1);
- Pom_Fronta.Zrus;
- end;
- end;
-
- procedure Vtyp_Strom.Anim_Left_Rotation;
- var C, _D : Vtyp_Strom_Ptr;
- Pp : Vtyp_Strom;
- Pom_Fronta : Typ_Hejb_Fronta;
- begin
- if Pravy = nil then WriteLn('error left')
- else
- begin
- if Uroven = 1 then
- Uroven := Uroven;
- Pom_Fronta.Init;
- set_Barva(Koren.Dej_Bod(0)^.Obsah.Atrib-1);
- Pp.Init;
-
- C := Pravy;
- _D := C^.Levy;
-
- C^.Zrus_Levy;
- Zrus_Pravy;
-
- if _D <> nil then
- begin
- _D^.Anim_Posun_Bod(Unstrom.Ppoloha(Lpoloha^,Koren.Rozmer.X,Uroven+1)^);
- Pom_Fronta.Zarad_Prvek(_D^);
- end;
- Dec(C^.Uroven);
- C^._Obnov;
- C^.Anim_Posun_Bod(Poloha);
- Pom_Fronta.Zarad_Prvek(C^);
-
- Anim_Posun_Bod(Lpoloha^);
- Pom_Fronta.Zarad_Prvek(Self);
-
- Inc(Uroven);
- _Obnov;
-
- Pom_Fronta.Dodelej_Pohyb;
-
- Pp := Self;
- Self := C^;
- C^ := Pp;
-
- Levy := C;
- C^.Pravy := _D;
-
- _Srovnat_List;
- C^._Srovnat_List;
-
- _Obnov;
- set_Barva(Koren.Dej_Bod(0)^.Obsah.Atrib+1);
- Pom_Fronta.Zrus;
- end;
- end;
-
- procedure Vtyp_Strom.Zrus_Levy;
- begin
- if Levy <> nil then begin
- Spoj.Prazdny;
- Spoj.Vytvor(Uroven, False, Pravy <> nil, Koren.Barva);
- Spoj.Presun(Poloha.X+Koren.Rozmer.X+1, Poloha.Y+1, Poloha.Z);
-
- if (__Videt and Stav) <> 0 then
- begin
- Levy^.Zhasni;
- Spoj.Zobraz;
- end;
- Levy := nil;
- if (Pravy = nil) then _Je_List;
- end;
- end;
-
- procedure Vtyp_Strom.Zrus_Pravy;
- begin
- if Pravy <> nil then begin
- Spoj.Prazdny;
- Spoj.Vytvor(Uroven, Levy <> nil, False, Koren.Barva);
- Spoj.Presun(Poloha.X+Koren.Rozmer.X+1, Poloha.Y+1, Poloha.Z);
-
- if (__Videt and Stav) <> 0 then
- begin
- Pravy^.Zhasni;
- Spoj.Zobraz;
- end;
- Pravy := nil;
- if (Levy = nil) then _Je_List;
- end;
- end;
-
- procedure Vtyp_Strom._Presun_Rel(X, Y, Z : Typ_Souradnic);
- begin
- if Levy <> nil then Levy^.Presun_Rel(X,Y,Z);
- if Pravy <> nil then Pravy^.Presun_Rel(X,Y,Z);
- Koren.Presun_Rel(X,Y,Z);
- Spoj.Presun_Rel(X,Y,Z);
- Inc(Poloha.X, X);
- Inc(Poloha.Y, Y);
- Inc(Poloha.Z, Z);
- end;
-
- procedure Vtyp_Strom._Zobraz;
- begin
- if (Stav and __Videt) = 0 then
- begin
- Koren.Poloha := Poloha;
- Koren.Zobraz;
- if Levy <> nil then
- begin
- Levy^.Uroven := Uroven+1;
- Levy^.Zhasni;
- Levy^.Poloha := Lpoloha^;
- Levy^.Zobraz;
- end;
- if Pravy <> nil then
- begin
- Pravy^.Uroven := Uroven+1;
- Pravy^.Zhasni;
- Pravy^.Poloha := Ppoloha^;
- Pravy^.Zobraz;
- end;
- if (Levy <> nil) or (Pravy <> nil) then
- begin
- Spoj.Zhasni;
- Spoj.Poloha := Lpoloha^;
-
- Spoj.Poloha.X := Koren.Poloha.X+Koren.Rozmer.X+1;
- Spoj.Poloha.Y := Koren.Poloha.Y+1-Spoj.Velikost;
- Spoj.Poloha.Z := Koren.Poloha.Z;
-
- Spoj.Zobraz
- end;
- end;
- Stav := Stav or __Videt;
- end;
-
- procedure Vtyp_Strom._Obnov;
- begin
- Koren.Zhasni;
- Koren.Poloha := Poloha;
- Koren.Zobraz;
- if Levy <> nil then
- begin
- Levy^.Uroven := Uroven+1;
- Levy^.Zhasni;
- Levy^.Poloha := Lpoloha^;
- Levy^._Obnov;
- end;
- if Pravy <> nil then
- begin
- Pravy^.Uroven := Uroven+1;
- Pravy^.Zhasni;
- Pravy^.Poloha := Ppoloha^;
- Pravy^._Obnov;
- end;
- if (Levy <> nil) or (Pravy <> nil) then
- begin
- Spoj.Prazdny;
- Spoj.Vytvor(Uroven, Levy <> nil, Pravy <> nil, Koren.Barva);
- Spoj.Presun(Poloha.X+Koren.Rozmer.X+1, Poloha.Y+1, Poloha.Z);
- Spoj.Zobraz
- end;
- Stav := Stav or __Videt;
- end;
-
- procedure Vtyp_Strom._Zhasni;
- begin
- Koren.Zhasni;
- if Levy <> nil then Levy^.Zhasni;
- if Pravy <> nil then Pravy^.Zhasni;
- if (Levy <> nil) or (Pravy <> nil) then Spoj.Zhasni
- end;
-
- constructor Vtyp_Strom.Init;
- begin
- Typ_Hejbaci_Zaklad.Init;
- Koren.Init;
- Spoj.Init;
-
- Levy := nil;
- Pravy := nil;
- Uroven := 0;
- Klic := Maxint;
- end;
-
- destructor Vtyp_Strom.Zrus;
- begin
- Typ_Hejbaci_Zaklad.Zrus;
- Koren.Zrus;
- Spoj.Zrus;
- if Levy <> nil then Levy^.Zrus;
- if Pravy <> nil then Pravy^.Zrus;
- if Uroven <> 0 then Dispose(Vtyp_Strom_Ptr(@Self));
- end;
-
- procedure Vtyp_Strom._Neni_List;
- begin
- if Koren.Je_Tvar then
- begin
- Koren.set_Bod_Znak((Koren.Rozmer.X+1)*2-1, '╟'); {'╟'}
- Koren.Obnov
- end;
- end;
-
- procedure Vtyp_Strom._Je_List;
- begin
- if Koren.Je_Tvar then
- begin
- Koren.set_Bod_Znak((Koren.Rozmer.X+1)*2-1, '║'); {'║'}
- Koren.Obnov
- end;
- end;
-
- procedure Vtyp_Strom._Srovnat_List;
- var Pp : Char;
- begin
- if (Levy = nil) and (Pravy = nil)
- then Pp := '║'
- else Pp := '╟';
- if Koren.Je_Tvar then
- begin
- Koren.set_Bod_Znak((Koren.Rozmer.X+1)*2-1, Pp);
- Koren.Obnov
- end;
- end;
-
- procedure Vtyp_Strom.Vytvor(S : string; C1 : Byte);
- begin
- Koren.Vytvor_string_Ram(S, C1, C1, Strom_Ram);
- { Poloha := Koren.Poloha;}
- Stav := Stav or __Existuje_Tvar;
- Barva := C1;
- end;
-
-
- procedure Vtyp_Strom.Prohod(var Strom : Vtyp_Strom);
- var Pom_Bod : _Bod3D;
- Pom_Ur : Integer;
-
- begin
- Zhasni;
- Strom.Zhasni;
-
- Pom_Bod := Strom.Poloha;
- Strom.Poloha := Poloha;
- Poloha := Pom_Bod;
-
- Pom_Ur := Strom.Uroven;
- Strom.Uroven := Uroven;
- Uroven := Pom_Ur;
-
- _Obnov;
- Strom._Obnov;
- end;
-
-
-
-
-
-
-
-
-
-
- { ************************************************************************* }
- { typ spoj }
- procedure Typ_Spoj.Vytvor(Ur : Typ_Souradnic; _L, _R : Boolean; Nbarva : Byte);
- var I, Pomvel : Word;
- Pom : Bod_Fyz_Obrazu;
-
- begin
- if Typ = __N then
- begin
- Zhasni;
- _Cisti_Tvar;
-
- Velikost := __Velikost(Ur);
- if Velikost < 1 then Velikost := Velikost;
- if (_L and _R) then
- begin
- Typ := __Lr;
- Pomvel := (Velikost shl 1)+1;
- _Get_Mem_Tvar(Pomvel);
- set_Bod_Znak(0, '┌'); {218}
-
- for I := 1 to (Velikost shl 1) -1 do
- set_Bod_Znak(I, '|'); {124}
-
- set_Bod_Znak(Velikost shl 1, '╚'); {200}
-
- set_Bod_Znak(Velikost, '╢'); {182}
- end
- else if _L then
- begin
- Typ := __L;
- Pomvel := Velikost+1;
- _Get_Mem_Tvar(Pomvel);
- set_Bod_Znak(0, '┌'); {218}
-
- for I := 1 to Velikost - 1 do
- set_Bod_Znak(I, '|'); {124}
-
- set_Bod_Znak(Velikost, '┘'); {}
- end
- else if _R then
- begin
- Typ := __R;
- Pomvel := Velikost+1;
- _Get_Mem_Tvar(Pomvel);
- set_Bod_Znak(0, '┐'); {}
- for I := 1 to Velikost - 1 do
- set_Bod_Znak(I, '|'); {124}
-
- set_Bod_Znak(Velikost, '╚'); {200}
- end;
-
- if not (_L or _R)
- then Prazdny
- else for I := 0 to Pomvel -1 do
- set_Bod_Barva(I, Nbarva);
- end;
- end;
-
- procedure Typ_Spoj.Pridej(Ur : Typ_Souradnic; _L, _R : Boolean; Nbarva : Byte);
- var I, Fn : Integer;
- Pom : Bod_Fyz_Obrazu;
-
- begin
- Zhasni;
- if Typ = __N then Vytvor(Ur,_L,_R,Nbarva)
- else if (Typ = __L) and _L then begin Typ := __N; Vytvor(Ur, True,False,Nbarva) end
- else if (Typ = __R) and _R then begin Typ := __N; Vytvor(Ur, False,True,Nbarva) end
- else begin Typ := __N; Vytvor(Ur, True,True,Nbarva) end;
- Zobraz;
- end;
-
- constructor Typ_Spoj.Init;
- begin
- Typ_Hejbaci.Init;
- Typ := __N;
- Velikost := 0;
- end;
-
- procedure Typ_Spoj.Prazdny;
- begin
- Zhasni;
- Konec_Pohybu;
- _Cisti_Tvar;
- Typ := __N;
- Velikost := 0;
- end;
-
- procedure Typ_Spoj._Zobraz;
- var Pom : Typ_Bod_3D;
- var X, Y, Z, H, S : Typ_Souradnic;
-
- begin
- Pom := Dej_Bod(0);
- X := Poloha.X{&&-Poloha.Z};
- Y := Poloha.Y{&&+Poloha.Z};
- Z := Poloha.Z;
- H := Y-Velikost;
- S := Y+Velikost;
- case Typ of
- __L : S := Y;
- __R : H := Y;
- __N : Exit
- end;
- for Y := H to S do
- begin
- Pom^.Z := Z;
- Obrazovka.Zobraz_Bod_Xy(X, Y , Pom);
- Inc(Word(Pom), Pamet_Bod_3D);
- end;
- end;
-
- procedure Typ_Spoj._Zhasni;
- var Pom : Typ_Bod_3D;
- var X, Y, Z, H, S : Typ_Souradnic;
-
- begin
- Pom := Dej_Bod(0);
- X := Poloha.X{&&-Poloha.Z};
- Y := Poloha.Y{&&+Poloha.Z};
- Z := Poloha.Z;
- H := Y-Velikost;
- S := Y+Velikost;
- case Typ of
- __L : S := Y;
- __R : H := Y;
- __N : Exit
- end;
- for Y := H to S do
- begin
- Pom^.Z := Z;
- Obrazovka.Zhasni_Bod_Xy(X, Y , Pom);
- Inc(Word(Pom), Pamet_Bod_3D);
- end;
- end;
-
- procedure Typ_Spoj._Presun_Rel(X, Y, Z : Typ_Souradnic);
- var Pom : Typ_Bod_3D;
- var _X, _Y, _Z, H, S, _Xn, _Yn : Typ_Souradnic;
-
- begin
- Pom := Dej_Bod(0);
- _X := Poloha.X{&&-Poloha.Z};
- _Y := Poloha.Y{&&+Poloha.Z};
-
- _Xn := _X+X{&&-Z};
- _Yn := Y{&&+Z};
-
- _Z := Poloha.Z{&&+Z};
- H := _Y-Velikost;
- S := _Y+Velikost;
- case Typ of
- __L : S := _Y;
- __R : H := _Y;
- __N : Exit
- end;
-
- for _Y := H to S do
- begin
- Pom^.Z := _Z;
- Obrazovka.Presun_Bod_Xy(_X, _Y, _Xn, _Y+_Yn, Pom);
- Inc(Word(Pom), Pamet_Bod_3D);
- end;
- Inc(Poloha.X, X);
- Inc(Poloha.Y, Y);
- Inc(Poloha.Z, Z);
- end;
-
-
- procedure set_Velikost(Velikost : real);
- begin
- __Velikost_Stromu := Velikost;
- end;
-
- function __Velikost(Uroven : Integer): Integer;
- var A : Integer;
- begin
- Asm
- Mov Ax, 1
- Mov Cx, Maxur
- Sub Cx, Uroven
- Dec Cx
- shl Ax, Cl
-
- Mov A, Ax
- end;
- A := Round(A*__Velikost_Stromu);
- if A < 1 then A := 1;
- __Velikost := A;
- end;
-
- procedure set_Pocatek_Animace(X, Y, Z : Typ_Souradnic);
- begin
- ___Pocatek.X := X;
- ___Pocatek.Y := Y;
- ___Pocatek.Z := Z;
- end;
-
- begin
- end.