generate random name

This commit is contained in:
Waylon Walker 2023-06-14 08:11:37 -05:00
parent c62facdb60
commit fa64c9aed1
No known key found for this signature in database
GPG key ID: 66E2BF2B4190EFE4
2 changed files with 27 additions and 25 deletions

View file

@ -13,15 +13,21 @@ class HeroFactory(ModelFactory[Hero]):
id = None id = None
pet_id = None pet_id = None
__random_seed__ = 10
@classmethod @classmethod
def name(cls) -> str: def name(cls) -> str:
return cls.__faker__.first_name() return (
cls.__faker__.word(part_of_speech="adjective")
+ "-"
+ cls.__faker__.word(part_of_speech="noun")
)
@classmethod @classmethod
def secret_name(cls) -> str: def secret_name(cls) -> str:
return cls.__faker__.name() return (
cls.__faker__.word(part_of_speech="adjective")
+ "-"
+ cls.__faker__.word(part_of_speech="noun")
)
@classmethod @classmethod
def age(cls) -> str: def age(cls) -> str:

View file

@ -1,13 +1,13 @@
import atexit import atexit
from faker import Faker
import pygame import pygame
from typer import Typer from typer import Typer
from websocket import create_connection from websocket import create_connection
from learn_sql_model.config import get_config from learn_sql_model.config import get_config
from learn_sql_model.console import console from learn_sql_model.console import console
from learn_sql_model.models.hero import Hero, HeroCreate, HeroDelete, HeroUpdate, Heros from learn_sql_model.factories.hero import HeroFactory
from learn_sql_model.models.hero import HeroCreate, HeroDelete, HeroUpdate, Heros
speed = 10 speed = 10
@ -19,9 +19,9 @@ config = get_config()
class Client: class Client:
def __init__(self, name, secret_name): def __init__(self):
self.hero = Hero(name=name, secret_name=secret_name, x=400, y=300, size=50) hero = HeroFactory().build(size=50, x=100, y=100)
self.hero = HeroCreate(**self.hero.dict()).post() self.hero = HeroCreate(**hero.dict()).post()
self.screen = pygame.display.set_mode((800, 600)) self.screen = pygame.display.set_mode((800, 600))
pygame.display.set_caption("Learn SQL Model") pygame.display.set_caption("Learn SQL Model")
@ -34,6 +34,7 @@ class Client:
self.moving_left = False self.moving_left = False
self.moving_right = False self.moving_right = False
self.ticks = 0 self.ticks = 0
self.others = []
atexit.register(self.quit) atexit.register(self.quit)
@ -81,23 +82,21 @@ class Client:
if self.moving_right: if self.moving_right:
self.hero.x += speed self.hero.x += speed
# if self.ticks % 1 == 0: if self.ticks % 5 == 0 or self.ticks == 0:
console.print("updating") console.print("updating")
update = HeroUpdate(**self.hero.dict(exclude_unset=True)) update = HeroUpdate(**self.hero.dict(exclude_unset=True))
console.print(update) console.print(update)
self.ws.send(update.json()) self.ws.send(update.json())
console.print("sent") console.print("sent")
raw_heros = self.ws.recv()
console.print(raw_heros)
self.others = Heros.parse_raw(raw_heros)
def render(self): def render(self):
self.screen.fill((0, 0, 0)) self.screen.fill((0, 0, 0))
raw_heros = self.ws.recv() for other in self.others.heros:
console.print(raw_heros)
others = Heros.parse_raw(raw_heros)
for other in others.heros:
if other.id != self.hero.id: if other.id != self.hero.id:
pygame.draw.circle( pygame.draw.circle(
self.screen, (255, 0, 0), (other.x, other.y), other.size self.screen, (255, 0, 0), (other.x, other.y), other.size
@ -176,10 +175,7 @@ game_app = Typer()
@game_app.command() @game_app.command()
def run(): def run():
f = Faker() client = Client()
name = "-".join(f.words(2))
secret_name = "-".join(f.words(2))
client = Client(name, secret_name)
client.run() client.run()