U e5d@sddZddlTGdddeZGdddeZddZd d Zd d Ze d kr`eZ e e e dS)a turtle-example-suite: tdemo_minimal_hanoi.py A minimal 'Towers of Hanoi' animation: A tower of 6 discs is transferred from the left to the right peg. An imho quite elegant and concise implementation using a tower class, which is derived from the built-in type list. Discs are turtles with shape "square", but stretched to rectangles by shapesize() --------------------------------------- To exit press STOP button --------------------------------------- )*c@seZdZddZdS)DisccCsPtj|ddd||d|dd||ddd|d|dS) NZsquareF)shapeZvisibleg?g@r)Turtle__init__ZpuZ shapesizeZ fillcolorst)selfnr 0/usr/lib64/python3.8/turtledemo/minimal_hanoi.pyrs z Disc.__init__N)__name__ __module__ __qualname__rr r r r rsrc@s(eZdZdZddZddZddZdS) Towerz-Hanoi tower, a subclass of built-in type listcCs ||_dS)z-create an empty tower. x is x-position of pegN)x)r rr r r r szTower.__init__cCs0||j|ddt|||dS)Nij")Zsetxrsetylenappendr dr r r push#s z Tower.pushcCst|}|d|S)N)listpoprrr r r r's  z Tower.popN)rrr__doc__rrrr r r r rsrcCs>|dkr:t|d|||||t|d|||dS)Nrr)hanoirr)r Zfrom_Zwith_Zto_r r r r,srcCsJtddtz tdttttddddWntk rDYnXdS)Nspacezpress STOP button to exitcenterZCourierZboldZalignZfont)onkeyclearrt1t2t3writeZ Terminatorr r r r play2s  r+cCsptttddtdatdatdatdddD]}tt |q:t ddd d t t d t d S) Nriir zpress spacebar to start gamer!r"r$rZ EVENTLOOP)ZhtZpenupZgotorr'r(r)rangerrr*r%r+Zlisten)ir r r main<s  r0__main__N) rZturtlerrrrrr+r0rmsgprintZmainloopr r r r s