Compare commits

...

3 Commits

4 changed files with 69 additions and 42 deletions

View File

@@ -5,6 +5,7 @@ from PIL import Image as _Image
from PIL import ImageDraw as _ImageDraw
from utils import logs as _logs
from bot_libs import syms as _bot_syms
from entities import resource as _resource
class BrSimMap():
@@ -44,7 +45,8 @@ class BrSimMap():
for i in range(self.world_width):
#if i == 0 or i == self.world_width - 1: width.append(self.mountain_sym)
#else: width.append(self.field_sym)
width.append(self.field_sym)
width.append(None)
#width.append(self.field_sym)
for i in range(self.world_height):
#if i == 0 or i == self.world_height - 1: self.game_map.append(mon)
#else: self.game_map.append(_copy.deepcopy(width))
@@ -53,23 +55,27 @@ class BrSimMap():
def populate_map(self):
for player in self.players:
p_coord_x, p_coord_y= player.get_player_coordinates()
if not player.is_alive(): self.game_map[p_coord_y][p_coord_x]= self.dead_player_sym
elif player.player_gender_is_male(): self.game_map[p_coord_y][p_coord_x]= self.player_male_sym
elif player.player_gender_is_female(): self.game_map[p_coord_y][p_coord_x]= self.player_female_sym
else: self.game_map[p_coord_y][p_coord_x]= self.player_nonbinary_sym
p_coord_x, p_coord_y= player.get_coordinates()
self.game_map[p_coord_y][p_coord_x]= player
#if not player.is_alive(): self.game_map[p_coord_y][p_coord_x]= self.dead_player_sym
#elif player.player_gender_is_male(): self.game_map[p_coord_y][p_coord_x]= self.player_male_sym
#elif player.player_gender_is_female(): self.game_map[p_coord_y][p_coord_x]= self.player_female_sym
#else: self.game_map[p_coord_y][p_coord_x]= self.player_nonbinary_sym
for item in self.items:
i_coord_x, i_coord_y= item.get_item_coordinates()
self.game_map[i_coord_y][i_coord_x]= self.item_sym
i_coord_x, i_coord_y= item.get_coordinates()
self.game_map[p_coord_y][p_coord_x]= item
#self.game_map[i_coord_y][i_coord_x]= self.item_sym
def _set_coordinates(self, target):
x= _random.randint(1, self.world_width -2) # from 1 to width-2 because 1 cell is occupied by the mountain
y= _random.randint(1, self.world_height -2)
while self.get_map_matrix()[y][x] != self.field_sym:
resource= self.get_map_matrix()[y][x]
while resource:
#while self.get_map_matrix()[y][x] != self.field_sym:
_logs.log_debug('_set_coordinates: collision, regenerate coordinates')
x= _random.randint(1, self.world_width -2)
y= _random.randint(1, self.world_height -2)
target.set_player_coordinates(x, y)
target.set_coordinates(x, y)
def init_players_coordinates(self):
for player in self.players:
@@ -109,7 +115,15 @@ class BrSimMap():
game_map= self.get_map_matrix()
for y in game_map:
for x in y:
res+= x
if not x: el= self.field_sym
#XXX how to manage mountains?
elif x.is_player():
if x.player_gender_is_male(): el= self.player_male_sym
elif x.player_gender_is_female(): el= self.player_female_sym
else: el= self.player_nonbinary_sym
elif x.is_item():
el= self.item_sym
res+= el
res+= '\n'
return res
@@ -125,21 +139,23 @@ class BrSimMap():
for y in range(self.world_height):
for x in range(self.world_width):
pixel= self.game_map[y][x]
if pixel == self.field_sym:
resource= self.game_map[y][x]
if not resource:
pixel_color= _bot_syms.MAP_IMAGE_FIELD
elif pixel == self.mountain_sym:
pixel_color= _bot_syms.MAP_IMAGE_MOUNTAIN
elif pixel == self.item_sym:
# XXX how to manage mountains? maybe another class?
#elif resource == self.mountain_sym:
#pixel_color= _bot_syms.MAP_IMAGE_MOUNTAIN
elif resource.is_item():
pixel_color= _bot_syms.MAP_IMAGE_ITEM
elif pixel == self.player_male_sym:
pixel_color= _bot_syms.MAP_IMAGE_PLAYER_MALE
elif pixel == self.player_female_sym:
pixel_color= _bot_syms.MAP_IMAGE_PLAYER_FEMALE
elif pixel == self.player_nonbinary_sym:
pixel_color= _bot_syms.MAP_IMAGE_PLAYER_NONBINARY
elif pixel == self.dead_player_sym:
pixel_color= _bot_syms.MAP_IMAGE_DEATH_PLAYER
elif resource.is_player():
if not resource.is_alive():
pixel_color= _bot_syms.MAP_IMAGE_DEATH_PLAYER
elif resource.player_gender_is_male():
pixel_color= _bot_syms.MAP_IMAGE_PLAYER_MALE
elif resource.player_gender_is_female():
pixel_color= _bot_syms.MAP_IMAGE_PLAYER_FEMALE
elif resource.player_gender_is_not_binary():
pixel_color= _bot_syms.MAP_IMAGE_PLAYER_NONBINARY
scaled_x_coord= x * scale_x
scaled_y_coord= y * scale_y

View File

@@ -1,12 +1,16 @@
import random as _random
from entities import resource as _resource
class BrSimItem():
class BrSimItem(_resource.BrSimResource):
# test
def __init__(self):
self.coord_x= 0
self.coord_y= 0
def is_item(self):
return True
def get_name(self):
return self.name
@@ -21,10 +25,3 @@ class BrSimItem():
def is_cure(self):
return False
def get_item_coordinates(self):
return self.coord_x, self.coord_y
def set_item_coordinates(self, x, y):
self.coord_x= x
self.coord_y= y

View File

@@ -1,9 +1,11 @@
import random as _random
import uuid as _uuid
from entities import resource as _resource
class BrSimPlayer():
class BrSimPlayer(_resource.BrSimResource):
def __init__(self, name, inventory= None):
super()
self.id= str(_uuid.uuid4())
self.name= name
self.stats= ''
@@ -19,18 +21,12 @@ class BrSimPlayer():
self.equipped_weapon= None
self.gender= _random.sample(['m', 'f', '-'], 1)[0] # for now get a random gender
self.reputation= 50 #Like RDR2 the player can be evil(0) or good(100). This should influence the sponsors and internal alliance
self.coord_x= 0
self.coord_y= 0
def is_player(self):
return True
### control methods
def get_player_coordinates(self):
return self.coord_x, self.coord_y
def set_player_coordinates(self, x, y):
self.coord_x= x
self.coord_y= y
def get_name_and_stats(self):
health= '♥️' * self.health or '☠️'
strength= '⚔️' * self.damage

18
entities/resource.py Normal file
View File

@@ -0,0 +1,18 @@
class BrSimResource():
def __init__(self):
self.coord_x= 0
self.coord_y= 0
def is_player(self):
return False
def is_item(self):
return False
def get_coordinates(self):
return self.coord_x, self.coord_y
def set_coordinates(self, x, y):
self.coord_x= x
self.coord_y= y