MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / askForBoardSize

Function askForBoardSize

src/gamesbyexample/hexapawn.py:63–85  ·  view source on GitHub ↗

Returns a (width, height) tuple of the board dimensions the player has requested.

()

Source from the content-addressed store, hash-verified

61
62
63def askForBoardSize():
64 """Returns a (width, height) tuple of the board dimensions the
65 player has requested."""
66 for dimension in [WIDTH, HEIGHT]:
67 while True: # Keep looping until the user enters a valid size.
68 print('Enter the board', dimension, ' (3 to 26) to play on:')
69 response = input('> ')
70
71 if response.isdecimal() and (3 <= int(response) <= 26):
72 if dimension == WIDTH:
73 width = int(response)
74 elif dimension == HEIGHT:
75 height = int(response)
76 break # The user has entered a valid size.
77
78 print('Please enter a number between 3 and 26.')
79
80 # Display a warning if the user choose a size larger than 10.
81 if width > 8 or height > 8:
82 print('WARNING: You may have to resize the terminal window to')
83 print('view a board this big.')
84
85 return (width, height)
86
87
88def getNewBoard(width, height):

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected