forked from Cryz/battle_royale_sim
arena as class
This commit is contained in:
64
entities/arena.py
Normal file
64
entities/arena.py
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
from entities import player as _player
|
||||||
|
from entities import weapons as _weapons
|
||||||
|
from entities import weapon_syms as _wsyms
|
||||||
|
|
||||||
|
class BrSimArena():
|
||||||
|
|
||||||
|
# players = [{'name': name, 'inventory': default_inventory, other_stats}]
|
||||||
|
# weapons = [{WEAPON.KNIFE: quantity}, etc...] # this is the whole quantity of the items available on the world
|
||||||
|
|
||||||
|
def __init__(self, players, weapons):
|
||||||
|
self.day= 1
|
||||||
|
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= []
|
||||||
|
for p in self.players:
|
||||||
|
if not p.is_alive(): continue
|
||||||
|
res.append(p)
|
||||||
|
return res
|
||||||
|
|
||||||
|
def get_death_players(self):
|
||||||
|
res= []
|
||||||
|
for p in self.players:
|
||||||
|
if p.is_alive(): continue
|
||||||
|
res.append(p)
|
||||||
|
return res
|
||||||
|
|
||||||
|
def do_random_event(self):
|
||||||
|
#XXX random player does random action according to his inventory health, wounds, available weapons on the world, etc...
|
||||||
|
pass
|
||||||
|
|
||||||
|
def supporter_donation(self):
|
||||||
|
#XXX supporter donate a random item or weapon to a random player
|
||||||
|
#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
|
||||||
78
main.py
78
main.py
@@ -1,82 +1,26 @@
|
|||||||
from entities import player as _player
|
import random as _random
|
||||||
from entities import weapons as _weapons
|
from entities import arena as _arena
|
||||||
from entities import weapon_syms as _wsyms
|
|
||||||
|
|
||||||
class BrSimArena():
|
|
||||||
|
|
||||||
# players = [{'name': name, 'inventory': default_inventory, other_stats}]
|
|
||||||
# weapons = [{WEAPON.KNIFE: quantity}, etc...] # this is the whole quantity of the items available on the world
|
|
||||||
|
|
||||||
def __init__(self, players, weapons):
|
|
||||||
self.day= 1
|
|
||||||
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= []
|
|
||||||
for p in self.players:
|
|
||||||
if not p.is_alive(): continue
|
|
||||||
res.append(p)
|
|
||||||
return res
|
|
||||||
|
|
||||||
def get_death_players(self):
|
|
||||||
res= []
|
|
||||||
for p in self.players:
|
|
||||||
if p.is_alive(): continue
|
|
||||||
res.append(p)
|
|
||||||
return res
|
|
||||||
|
|
||||||
def do_random_event(self):
|
|
||||||
#XXX random player does random action according to his inventory health, wounds, available weapons on the world, etc...
|
|
||||||
pass
|
|
||||||
|
|
||||||
def supporter_donation(self):
|
|
||||||
#XXX supporter donate a random item or weapon to a random player
|
|
||||||
#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():
|
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}]
|
weapons= [{w: 1}]
|
||||||
return BrSimArena(players, weapons)
|
return _arena.BrSimArena(players, weapons)
|
||||||
|
|
||||||
|
|
||||||
def run_event(Arena):
|
def run_events(Arena):
|
||||||
|
#A event for each player:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def local_debug():
|
def local_debug():
|
||||||
Arena= init_arena()
|
Arena= init_arena()
|
||||||
print(f'Players: {Arena.get_players()}')
|
print(f'Players: {Arena.get_players()}')
|
||||||
print(f'Weapons: {Arena.get_weapons()}')
|
print(f'Weapons: {Arena.get_weapons()}')
|
||||||
run_event(Arena)
|
while (len(Arena.get_alive_players()) > 1)
|
||||||
|
#Start a day
|
||||||
|
run_events(Arena)
|
||||||
|
|
||||||
|
#At 23:59:
|
||||||
|
Arena.next_day()
|
||||||
|
#End of day
|
||||||
|
|||||||
Reference in New Issue
Block a user