Arena and Player start populating more basic methods of the object
This commit is contained in:
15
bot.py
15
bot.py
@@ -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:
|
||||
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()
|
||||
players= Arena.players
|
||||
weapons= Arena.weapons
|
||||
print(f'Ecco il mondo di gioco, questi sono i giocatori: {players}')
|
||||
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(f'Ecco la lista degli sfortunati avventurieri: {players}')
|
||||
await update.message.reply_text(f'Queste le armi che avranno a disposizione nell\'arena: {weapons}')
|
||||
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:\n{weapons}')
|
||||
context.application.bot_data['arena'] = Arena
|
||||
|
||||
chat_id = update.effective_chat.id
|
||||
context.job_queue.run_daily(
|
||||
loop_game,
|
||||
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:
|
||||
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():
|
||||
# Crea l'applicazione e passagli il token del tuo bot.
|
||||
@@ -46,6 +49,8 @@ def main():
|
||||
|
||||
# Gestisce il comando /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
|
||||
application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo))
|
||||
|
||||
|
||||
@@ -7,3 +7,5 @@ Tu e i tuoi compagni, sarete catapultati in questo mondo,
|
||||
ma solo 1 di voi riuscira' a salvarsi.
|
||||
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?"
|
||||
|
||||
@@ -29,3 +29,24 @@ class BrSimPlayer():
|
||||
|
||||
def get_inventory(self):
|
||||
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(),
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import random as _random
|
||||
from entities import weapon_syms as _syms
|
||||
|
||||
class BrSimPlayer():
|
||||
class BrSimWeapon():
|
||||
|
||||
def __init__(self, wtype):
|
||||
self.weapon= _syms.WEAPONS[wtype]
|
||||
|
||||
35
main.py
35
main.py
@@ -9,11 +9,19 @@ class BrSimArena():
|
||||
|
||||
def __init__(self, players, weapons):
|
||||
self.day= 1
|
||||
self.players= players
|
||||
self.weapons= weapons
|
||||
self.players= [_player.BrSimPlayer(p['name'], p.get('inventory')) for p in players]
|
||||
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):
|
||||
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):
|
||||
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
|
||||
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():
|
||||
players= [{'name': 'Crystal'}, {'name': 'Andrea'}]
|
||||
w= _wsyms.KNIFE
|
||||
weapons= [{_wsyms.WEAPONS[w]['name']: 1}]
|
||||
#weapons= [{_wsyms.WEAPONS[w]['name' ]: 1}]
|
||||
weapons= [{w: 1}]
|
||||
return BrSimArena(players, weapons)
|
||||
|
||||
|
||||
@@ -51,7 +76,7 @@ def run_event(Arena):
|
||||
|
||||
def local_debug():
|
||||
Arena= init_arena()
|
||||
print(Arena.players)
|
||||
print(Arena.weapons)
|
||||
print(f'Players: {Arena.get_players()}')
|
||||
print(f'Weapons: {Arena.get_weapons()}')
|
||||
run_event(Arena)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user