AlkantarClanX12

Your IP : 18.119.106.66


Current Path : /usr/lib64/python2.7/Demo/curses/
Upload File :
Current File : //usr/lib64/python2.7/Demo/curses/life.pyc

�
Afc@s�ddlZddlZddlZddlZdd	d��YZd�Zd�Zd�Zd�Ze	dkr�ej
e�ndS(
i����Nt	LifeBoardcBsPeZdZed�d�Zd�Zd�Zd�Zed�Z	d�Z
RS(s�Encapsulates a Life board

    Attributes:
    X,Y : horizontal and vertical size of the board
    state : dictionary mapping (x,y) to 0 or 1

    Methods:
    display(update_board) -- If update_board is true, compute the
                             next generation.  Then display the state
                             of the board and refresh the screen.
    erase() -- clear the entire board
    makeRandom() -- fill the board randomly
    set(y,x) -- set the given cell to Live; doesn't refresh the screen
    toggle(y,x) -- change the given cell from live to dead, or vice
                   versa, and refresh the screen display

    t*cCs
i|_||_|jj�\}}|d|dd|_|_||_|jj�d|jdd}|jjdd|�|jj|jdd|�xUtd|j�D]A}|jjd|dd�|jjd||jdd�q�W|jj	�dS(s�Create a new LifeBoard instance.

        scr -- curses screen object to use for display
        char -- character used to render live cells (default: '*')
        iit+t-it|N(
tstatetscrtgetmaxyxtXtYtchartcleartaddstrtrangetrefresh(tselfRR
R	Rtborder_linety((s(/usr/lib64/python2.7/Demo/curses/life.pyt__init__)s			
%cCsc|dks6|j|ks6|dks6|j|krLtd||f�nd|j||f<dS(sSet a cell to the live stateisCoordinates out of range %i,%iiN(RR	t
ValueErrorR(RRtx((s(/usr/lib64/python2.7/Demo/curses/life.pytset?s6cCs�|dks6|j|ks6|dks6|j|krLtd||f�n|jj||f�r�|j||f=|jj|d|dd�n4d|j||f<|jj|d|d|j�|jj�dS(s+Toggle a cell's state between live and deadisCoordinates out of range %i,%iit N(	RR	RRthas_keyRtaddchR
R(RRR((s(/usr/lib64/python2.7/Demo/curses/life.pyttoggleEs6!!cCsi|_|jdt�dS(s3Clear the entire board and update the board displaytupdate_boardN(RtdisplaytFalse(R((s(/usr/lib64/python2.7/Demo/curses/life.pyteraseQs	cCsw|j|j}}|s�x�td|�D]z}xqtd|�D]`}|jj||f�r�|jj|d|d|j�q?|jj|d|dd�q?Wq)W|jj�dSi}d|_	x�td|�D]�}tt
d|d�t||d��}xPtd|�D]?}d}|jj||f�}	xgtt
d|d�t||d��D]<}
x3|D]+}|jj||
f�rq|d7}qqqqWqdW||	8}|dkrd|||f<|jj|d|d|j�|	sUd|_	qUq|dkr%|	r%d|||f<q|	r|jj|d|dd�d|_	qqWq�W||_|jj�dS(s<Display the whole board, optionally computing one generationiiRNii(RR	R
RRRRR
Rtboringtmaxtmin(RRtMtNtitjtdtLtstlivetktl((s(/usr/lib64/python2.7/Demo/curses/life.pyRVsB$&
	)0

!	cCsli|_x\td|j�D]H}x?td|j�D]+}tj�dkr5|j||�q5q5WqWdS(s$Fill the board with a random patternig�?N(RR
RR	trandomR(RR#R$((s(/usr/lib64/python2.7/Demo/curses/life.pyt
makeRandom|s
	(t__name__t
__module__t__doc__tordRRRRtTrueRR,(((s(/usr/lib64/python2.7/Demo/curses/life.pyRs			&cCs<|j|d�|j�|j|dd�|j�dS(s&Clear the space where the menu residesiiN(tmovetclrtoeol(tstdscrtmenu_y((s(/usr/lib64/python2.7/Demo/curses/life.pyt
erase_menu�s
cCs;t||�|j|dd�|j|ddd�dS(s/Display the menu of possible keystroke commandsisAUse the cursor keys to move, and space or Enter to toggle a cell.isBE)rase the board, R)andom fill, S)tep once or C)ontinuously, Q)uitN(R6R(R4R5((s(/usr/lib64/python2.7/Demo/curses/life.pytdisplay_menu�s

c	Cs�|j�|j�\}}|dd}t||�|j|d|dd�}t|dtd��}|jdt�|jd|j	d}}xR|j
d|d|�|j�}d|ko�dknr9t|�}|d	kr|j
||�q�|d
kr�t||�|j|dd�|j�|jd�xd|j�}|d
krfPn|jddd�|j�|j�|jddd�|j�qJW|jd�t||�q�|dkr�|j�q�|dkr�Pq�|dkr|j�|jdt�q�|dkr�|j�q�q�|tjkra|dkra|d8}q�|tjkr�||j	dkr�|d7}q�|tjkr�|dkr�|d8}q�|tjkr�||jdkr�|d7}q�q�WdS(NiiiR
RRiis 
tCcis6 Hit any key to stop continuously updating the screen.i����t/RtEetQqtRrtSs(RRR7tsubwinRR0RRRR	R2tgetchtchrRR6RRtnodelayRR,tcursestKEY_UPtKEY_DOWNtKEY_LEFTt	KEY_RIGHT(	R4tstdscr_ytstdscr_xR5R>tboardtxpostypostc((s(/usr/lib64/python2.7/Demo/curses/life.pytkeyloop�sd











"

"
cCst|�dS(N(RM(R4((s(/usr/lib64/python2.7/Demo/curses/life.pytmain�st__main__((R+tstringt	tracebackRBRR6R7RMRNR-twrapper(((s(/usr/lib64/python2.7/Demo/curses/life.pyt<module>s$n			?