I'm writing a small RPG in Python, and I want my different world objects to have varying colors. I've tried exploring colorama and some similar modules; however, the string always prints as a small box with some numbers and letters in it, instead of, let's say, a blue '~' character for a water tile.
I create my world arrays with a variable that looks like this:
worldArray = [[' ' for i in range(10)] for i in range(10)]
I then add world objects to it through a few different functions, to structure a random-esque world environment, like this one:
def replacetiles(self, grid, row, a, b, char, count):
while count:
aShift = 2
row_col_dict = {row: (a, b)}
for row in row_col_dict.keys():
startPos, endPos = row_col_dict[row]
for i in range(startPos, endPos):
grid[row][i] = char
row -= 1
if aShift == 0:
a += random.randint(1, 2)
if count < 3:
b -= (b / 2)
b += random.randint(0, 1)
aShift -=1
count -= 1
This is of course all stored within a class object. This function is how I create randomized oceans within the world, by calling replacetiles(gamemap, 9, 0, 5, '~', 3)
which would replace a few of the indexes with '~'
.
How would I be able to change the output color of the '~'
within the game map?
EDIT: My question seems much more specific than the other thread listed. The problem I am having, is when I print text through colorama, or any of the answers below or in the other thread, in a stand alone file simply printing colored text, it works. However, when I use that same code to change the color of the char
argument in replacetiles
, I get this odd box icon, regardless of the method I used to change the color of the string text.