o
    JAf                     @   sh   d Z ddlT G dd deZG dd deZdd Zd	d
 Zdd Ze	dkr2e Z
ee
 e  dS dS )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                   @   s   e Zd Zdd ZdS )Discc                 C   sP   t j| ddd |   | d|d d | |d dd|d   |   d S )	NZsquareF)shapeZvisibleg      ?   g      @r      )Turtle__init__ZpuZ	shapesizeZ	fillcolorst)selfn r   //usr/lib/python3.10/turtledemo/minimal_hanoi.pyr      s
   zDisc.__init__N)__name__
__module____qualname__r   r   r   r   r   r      s    r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	Towerz-Hanoi tower, a subclass of built-in type listc                 C   s
   || _ dS )z-create an empty tower. x is x-position of pegN)x)r
   r   r   r   r   r       s   
zTower.__init__c                 C   s0   | | j |ddt|    | | d S )Nij"   )Zsetxr   setylenappendr
   dr   r   r   push#   s   z
Tower.pushc                 C   s   t | }|d |S )N   )listpopr   r   r   r   r   r   '   s   

z	Tower.popN)r   r   r   __doc__r   r   r   r   r   r   r   r      s
    r   c                 C   sB   | dkrt | d ||| ||  t | d ||| d S d S )Nr   r   )hanoir   r   )r   Zfrom_Zwith_Zto_r   r   r   r   ,   s
   r   c                   C   sH   t d d t  ztdttt tdddd W d S  ty#   Y d S w )Nspace   zpress STOP button to exitcenterZCourier   ZboldZalignZfont)onkeyclearr   t1t2t3writeZ
Terminatorr   r   r   r   play2   s   
r+   c                  C   sp   t   t  tdd tdatdatdatdddD ]	} tt	|  qt
ddd	d
 ttd t  dS )Nr   ii   r    zpress spacebar to start gamer!   r"   r$   r   Z	EVENTLOOP)ZhtZpenupZgotor   r'   r(   r)   ranger   r   r*   r%   r+   listen)ir   r   r   main<   s   
r1   __main__N)r   Zturtler   r   r   r   r   r+   r1   r   msgprintZmainloopr   r   r   r   <module>   s   

