Example #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
Example #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
Example #3
0
def life(width, height=None):
    # will become John Conway's Game of Life... 
    
    if height is None: height = width 
    
    B = randomBoard(createBoard(width, height))

    while True:     			# run forever
	csplot.show(B)  		# show current B
	time.sleep(0.25)	   	# pause a bit
	B = randomBoard(B)              # sets the new board correctly
Example #4
0
def life( width, height ):
    """ will become John Conway's Game of Life... """
    B = createBoard( width, height )
    updateRandom( B )
    #csplot.showAndClickInIdle( B )
    if pause == False:
        B = createNextLifeBoard( oldB )
        keysList = csplot.getKeysDown()
        if 'p' in keysList:
            pause = True    
 
    while True:                      # run forever
        csplot.show(B)               # show current B
        time.sleep(0.25)              # pause a bit
        oldB = B       #  just a reminder for us humans
        B = createBoard(width, height)   #  creates a new board
        updateNextLife( oldB, B )  #  sets the new board correctly
Example #5
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()
Example #6
0
 def showBoard(self):
     csplot.show(self.board, ConnectFour.repToColor)
Example #7
0
 def showBoard(self):
     csplot.show(self.board, ConnectFour.repToColor)