Aug-25-2017, 01:31 PM
Two ways to do this come to mind. You can store the board as a list of lists, or you can build the board as you display it. Here's a couple examples on a 5 x 5 board:
Keep in mind that if you are using the list version, you have to remove the old positions when you put the players in a new position.
Note that both of these will have the player move down the board, visually. If you want them to move up the board, you would have to reverse the rows in the list when printing them, or run the row loop from 4 to 0 when building the board.
This is not the limit of the ways you can build a board, but just some quick ideas.
board = [['.'] * 5 for row in range(5)] board[1][2] = '1' # player 1 position board[3][4] = '2' # player 2 position print('\n'.join([''.join(row) for row in board]))Or building as you go along:
text = '' for row in range(5): for column in range(5): if row * 5 + column == player1position: text += '1' elif row * 5 + column == player2position: text += '2' else: text += '.' text += '\n'I'm using a calculation in the building version, but you can do sort of the reverse calculation in the list of lists:
board[player1position // 5][player1position % 5]
.Keep in mind that if you are using the list version, you have to remove the old positions when you put the players in a new position.
Note that both of these will have the player move down the board, visually. If you want them to move up the board, you would have to reverse the rows in the list when printing them, or run the row loop from 4 to 0 when building the board.
This is not the limit of the ways you can build a board, but just some quick ideas.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures