Game Development Reference
In-Depth Information
27. # print the numbers across the bottom
28. print()
29. print(' ' + ('0123456789' * 6))
30. print(hline)
31.
32.
33. def getRow(board, row):
34. # Return a string from the board data structure at a
certain row.
35. boardRow = ''
36. for i in range(60):
37. boardRow += board[i][row]
38. return boardRow
39.
40. def getNewBoard():
41. # Create a new 60x15 board data structure.
42. board = []
43. for x in range(60): # the main list is a list of 60
lists
44. board.append([])
45. for y in range(15): # each list in the main list
has 15 single-character strings
46. # use different characters for the ocean to
make it more readable.
47. if random.randint(0, 1) == 0:
48. board[x].append('~')
49. else:
50. board[x].append('`')
51. return board
52.
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
59.
60. def isValidMove(x, y):
61. # Return True if the coordinates are on the board,
otherwise False.
62. return x >= 0 and x <= 59 and y >= 0 and y <= 14
63.
64. def makeMove(board, chests, x, y):
65. # Change the board data structure with a sonar device
character. Remove treasure chests
66. # from the chests list as they are found. Return False
if this is an invalid move.
67. # Otherwise, return the string of the result of this
move.
68. if not isValidMove(x, y):
69. return False
70.
Search WWH ::




Custom Search