1
0

Arena and Player start populating more basic methods of the object

This commit is contained in:
Crystal
2025-07-23 23:43:26 +02:00
parent 7710bebdbe
commit 7697b91ec8
5 changed files with 64 additions and 11 deletions

15
bot.py
View File

@@ -16,18 +16,19 @@ async def loop_game(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
async def bot_start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: async def bot_start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
await update.message.reply_text(_botsyms.START_MSG) await update.message.reply_text(_botsyms.START_MSG)
print('Sto costruendo il mondo di gioco...') chat_id = update.effective_chat.id
print(f'{chat_id}: Sto costruendo il mondo di gioco...')
Arena= _brsim.init_arena() Arena= _brsim.init_arena()
players= Arena.players players= Arena.players
weapons= Arena.weapons weapons= Arena.weapons
print(f'Ecco il mondo di gioco, questi sono i giocatori: {players}') print(f'Ecco il mondo di gioco, questi sono i giocatori: {players}')
print(f'Ecco le armi disponibili nel mondo: {weapons}') print(f'Ecco le armi disponibili nel mondo: {weapons}')
await update.message.reply_text('Ho creato il mondo di gioco') await update.message.reply_text('Ho creato il mondo di gioco')
await update.message.reply_text(f'Ecco la lista degli sfortunati avventurieri: {players}') await update.message.reply_text(f'Ecco la lista degli sfortunati avventurieri:\n{players}')
await update.message.reply_text(f'Queste le armi che avranno a disposizione nell\'arena: {weapons}') await update.message.reply_text(f'Queste le armi che avranno a disposizione nell\'arena:\n{weapons}')
context.application.bot_data['arena'] = Arena context.application.bot_data['arena'] = Arena
chat_id = update.effective_chat.id
context.job_queue.run_daily( context.job_queue.run_daily(
loop_game, loop_game,
time=datetime.time(hour=0, minute=0, second=5, tzinfo=datetime.timezone.utc), time=datetime.time(hour=0, minute=0, second=5, tzinfo=datetime.timezone.utc),
@@ -38,7 +39,9 @@ async def bot_start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
testo_ricevuto = update.message.text testo_ricevuto = update.message.text
await update.message.reply_text(f'Ehi, mio padre mi sta ancora finendo di creare, abbi pazienza, che fretta hai di entrare in questo mondo per morire?') await update.message.reply_text(_botsyms.WIP_MSG)
async def add_player(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
def main(): def main():
# Crea l'applicazione e passagli il token del tuo bot. # Crea l'applicazione e passagli il token del tuo bot.
@@ -46,6 +49,8 @@ def main():
# Gestisce il comando /start # Gestisce il comando /start
application.add_handler(CommandHandler('start', bot_start)) application.add_handler(CommandHandler('start', bot_start))
# Gestisce il comando /addplayer
application.add_handler(CommandHandler('addplayer', add_player))
# Gestisce tutti gli altri messaggi di testo # Gestisce tutti gli altri messaggi di testo
application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo)) application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo))

View File

@@ -7,3 +7,5 @@ Tu e i tuoi compagni, sarete catapultati in questo mondo,
ma solo 1 di voi riuscira' a salvarsi. ma solo 1 di voi riuscira' a salvarsi.
Uccidi o sarai tu ad essere ucciso Uccidi o sarai tu ad essere ucciso
""" """
WIP_MSG= "Ehi, mio padre mi sta ancora finendo di creare, abbi pazienza, che fretta hai di entrare in questo mondo per morire?"

View File

@@ -29,3 +29,24 @@ class BrSimPlayer():
def get_inventory(self): def get_inventory(self):
return self.inventory return self.inventory
def get_name(self):
return self.name
def get_health(self):
return self.health
def get_damage(self):
return self.damage
def get_agility(self):
return self.agility
def get_data(self):
return {
'name': self.get_name(),
'inventory': self.get_inventory(),
'health': self.get_health(),
'damage': self.get_damage(),
'agility': self.get_agility(),
}

View File

@@ -1,7 +1,7 @@
import random as _random import random as _random
from entities import weapon_syms as _syms from entities import weapon_syms as _syms
class BrSimPlayer(): class BrSimWeapon():
def __init__(self, wtype): def __init__(self, wtype):
self.weapon= _syms.WEAPONS[wtype] self.weapon= _syms.WEAPONS[wtype]

35
main.py
View File

@@ -9,11 +9,19 @@ class BrSimArena():
def __init__(self, players, weapons): def __init__(self, players, weapons):
self.day= 1 self.day= 1
self.players= players self.players= [_player.BrSimPlayer(p['name'], p.get('inventory')) for p in players]
self.weapons= weapons self.weapons= []
for weapon in weapons:
for wtype, quantity in weapon.items():
for i in range(quantity): self.weapons.append(_weapons.BrSimWeapon(wtype))
def next_day(self): def next_day(self):
self.day+= 1 self.day+= 1
print(f'Giorno: {self.day}')
print(f'Giocatori vivi: {self.get_alive_players()}')
death_players= self.get_death_players()
if (death_players):
print(f'Giocatori morti: {death_players}')
def get_alive_players(self): def get_alive_players(self):
res= [] res= []
@@ -38,11 +46,28 @@ class BrSimArena():
#TODO maybe in future a player can have charism stats that can influence the chance to get a donation #TODO maybe in future a player can have charism stats that can influence the chance to get a donation
pass pass
def add_player(self, name, inventory= None):
player= _player.BrSimPlayer(name, inventory)
self.players.append(player)
def get_players(self):
res= []
for p in self.players:
res.append(p.get_data())
return res
def get_weapons(self):
res= []
for w in self.weapons:
#XXX implement me
res.append(w)
return res
def init_arena(): def init_arena():
players= [{'name': 'Crystal'}, {'name': 'Andrea'}] players= [{'name': 'Crystal'}, {'name': 'Andrea'}]
w= _wsyms.KNIFE w= _wsyms.KNIFE
weapons= [{_wsyms.WEAPONS[w]['name']: 1}] #weapons= [{_wsyms.WEAPONS[w]['name' ]: 1}]
weapons= [{w: 1}]
return BrSimArena(players, weapons) return BrSimArena(players, weapons)
@@ -51,7 +76,7 @@ def run_event(Arena):
def local_debug(): def local_debug():
Arena= init_arena() Arena= init_arena()
print(Arena.players) print(f'Players: {Arena.get_players()}')
print(Arena.weapons) print(f'Weapons: {Arena.get_weapons()}')
run_event(Arena) run_event(Arena)