define a resource class for every entity that needs to be controlled on the game map
This commit is contained in:
@@ -52,13 +52,13 @@ class BrSimMap():
|
||||
|
||||
def populate_map(self):
|
||||
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
|
||||
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()
|
||||
i_coord_x, i_coord_y= item.get_coordinates()
|
||||
self.game_map[i_coord_y][i_coord_x]= self.item_sym
|
||||
|
||||
def _set_coordinates(self, target):
|
||||
@@ -68,7 +68,7 @@ class BrSimMap():
|
||||
_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:
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import random as _random
|
||||
from entities import resource as _resource
|
||||
|
||||
class BrSimItem():
|
||||
class BrSimItem(_resource.BrSimResource):
|
||||
|
||||
def __init__(self):
|
||||
self.coord_x= 0
|
||||
self.coord_y= 0
|
||||
def is_item(self):
|
||||
return True
|
||||
|
||||
def get_name(self):
|
||||
return self.name
|
||||
@@ -20,10 +20,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
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
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):
|
||||
self.id= str(_uuid.uuid4())
|
||||
@@ -19,18 +20,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
18
entities/resource.py
Normal 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
|
||||
Reference in New Issue
Block a user