define a resource class for every entity that needs to be controlled on the game map

This commit is contained in:
andrea
2025-08-01 22:05:03 +02:00
parent e0dc558c27
commit a5831085ba
4 changed files with 31 additions and 25 deletions

View File

@@ -52,13 +52,13 @@ class BrSimMap():
def populate_map(self): def populate_map(self):
for player in self.players: for player in self.players:
p_coord_x, p_coord_y= player.get_player_coordinates() p_coord_x, p_coord_y= player.get_coordinates()
if not player.is_alive(): self.game_map[p_coord_y][p_coord_x]= self.dead_player_sym 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_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 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 else: self.game_map[p_coord_y][p_coord_x]= self.player_nonbinary_sym
for item in self.items: for item in self.items:
i_coord_x, i_coord_y= item.get_item_coordinates() i_coord_x, i_coord_y= item.get_coordinates()
self.game_map[i_coord_y][i_coord_x]= self.item_sym self.game_map[i_coord_y][i_coord_x]= self.item_sym
def _set_coordinates(self, target): def _set_coordinates(self, target):
@@ -68,7 +68,7 @@ class BrSimMap():
_logs.log_debug('_set_coordinates: collision, regenerate coordinates') _logs.log_debug('_set_coordinates: collision, regenerate coordinates')
x= _random.randint(1, self.world_width -2) x= _random.randint(1, self.world_width -2)
y= _random.randint(1, self.world_height -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): def init_players_coordinates(self):
for player in self.players: for player in self.players:

View File

@@ -1,10 +1,10 @@
import random as _random import random as _random
from entities import resource as _resource
class BrSimItem(): class BrSimItem(_resource.BrSimResource):
def __init__(self): def is_item(self):
self.coord_x= 0 return True
self.coord_y= 0
def get_name(self): def get_name(self):
return self.name return self.name
@@ -20,10 +20,3 @@ class BrSimItem():
def is_cure(self): def is_cure(self):
return False 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,7 +1,8 @@
import random as _random import random as _random
import uuid as _uuid import uuid as _uuid
from entities import resource as _resource
class BrSimPlayer(): class BrSimPlayer(_resource.BrSimResource):
def __init__(self, name, inventory= None): def __init__(self, name, inventory= None):
self.id= str(_uuid.uuid4()) self.id= str(_uuid.uuid4())
@@ -19,18 +20,12 @@ class BrSimPlayer():
self.equipped_weapon= None self.equipped_weapon= None
self.gender= _random.sample(['m', 'f', '-'], 1)[0] # for now get a random gender 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.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 ### 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): def get_name_and_stats(self):
health= '♥️' * self.health or '☠️' health= '♥️' * self.health or '☠️'
strength= '⚔️' * self.damage 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