Game Development Reference
In-Depth Information
Figure 13-4: The indexes of a list of lists.
51. return board
Finally, we return the board variable. Remember that in this case, we are returning a
reference to the list that we made. Any changes we made to the list (or the lists inside the
list) in our function will still be there outside of the function.
Creating the Random Treasure Chests
53. def getRandomChests(numChests):
54. # Create a list of chest data structures (two-item
lists of x, y int coordinates)
55. chests = []
56. for i in range(numChests):
57. chests.append([random.randint(0, 59),
random.randint(0, 14)])
58. return chests
Another task we need to do at the start of the game is decide where the hidden treasure
chests are. We will represent the treasure chests in our game as a list of lists of two
integers. These two integers will be the X and Y coordinates. For example, if the chest data
structure was [[2, 2], [2, 4], [10, 0]] , then this would mean there are three
treasure chests, one at 2, 2, another at 2, 4, and a third one at 10, 0.
Search WWH ::




Custom Search