Exemple #1
0
def life(width, height):
    """ will become John Conway's Game of Life... """
    print(
        "Welcome to John Conway's Game of Life \n To Begin: press and hold 's' on your keyboard while you click on the cells you want to bring to life. Then close the grid window to start the game. \n press 'p' to pause \n press 'r' to resume \n press 'q' to quit \n press '1' to step through one life"
    )
    B = createBoard(width, height)
    csplot.showAndClickInIdle(B)
    pause = False

    while True:  # run forever
        csplot.show(B)  # show current B
        time.sleep(0.25)  # pause a bit
        keysList = csplot.getKeysDown()
        if not pause:
            oldB = B  #  just a reminder for us humans
            B = createBoard(width, height)  # creates a new board
            updateNextLife(oldB, B)  # sets the new board correctly
        if 'p' in keysList:  # pauses game
            print("Game Paused")
            pause = True
        if 'r' in keysList:  # resumes game
            print("Game Resumed")
            pause = False
        if 'q' in keysList:  # ends the game
            print("The Game has Ended")
            break
        if '1' in keysList:  # allows the game to step through one life
            oldB = B  #  just a reminder for us humans
            B = createBoard(width, height)  # creates a new board
            updateNextLife(oldB, B)  # sets the new board correctly
            pause = True
Exemple #2
0
def life2(B):
    
    """ will become John Conway's Game of Life... """
    csplot.showAndClickInIdle(B)
    # hold s and click on the grid to bring a cell to life
    # then close the grid and life will play

    while True:
	csplot.show(B)                   # show B
	time.sleep(0.25)                 # pause a bit
	B = updateNextLife(oldB)         # sets the new board correctly
Exemple #3
0
def life2(B):
    
    # is John Conway's Game of Life...
    csplot.showAndClickInIdle(B.board)
    # hold s and click on the grid to bring a cell to life
    # then close the grid and life will play

    while True:
	csplot.show(B.board)             # show B
	time.sleep(0.25)                 # pause a bit
	B = updateNextLife(B)            # sets the new board correctly
	
	if B.board == B.blank().board:
	    break
	
    csplot.show(B.board)
    csplot.done()