hi everyone, remember @DefendyPug? he’s made a new Python Repl and published it. it’s a text-based game engine. here’s the link:
https://replit.com/@DefendyPug/Definitely-A-Game-Engine-DAGE
maybe leave a comment so more people can see it
hi everyone, remember @DefendyPug? he’s made a new Python Repl and published it. it’s a text-based game engine. here’s the link:
https://replit.com/@DefendyPug/Definitely-A-Game-Engine-DAGE
maybe leave a comment so more people can see it
Seems cool, an interesting idea. I’m pretty sure I’ve seen something similar before.
Um, I don’t know who to contact or whatever, but I’ve pretty much rewritten most of the code. I’ve added more detailed descriptions to the class names, function names, and their arguments, etc. I’ve also fixed some possible errors, bugs, and just made the code look better overall.
I was in the process of creating an engine from scratch for pure text-based games, such as a clicking game where you press “Enter” and receive a response. However, I became somewhat bored with the project. If anyone is interested in picking up where I left off, here is my current code:
from dataclasses import dataclass
import json
from typing import Union, List, Tuple, Dict
@dataclass
class NewValue:
name: str
value: Union[int, str]
class Engine:
def __init__(self, title: str, data_type: str):
self.type = 'json' if data_type == 'json' else 'text' if data_type in ('txt', 'text') else None
self.title = title
self.stats = {}
@property
def data_type(self) -> str:
return self.type
@classmethod
def create_value(cls, name: str, value: Union[int, str], data_type: str) -> NewValue:
if name and value:
return NewValue(name=name, value=json.dumps(value) if data_type == "json" else str(value))
def add_value(self, new_value: NewValue) -> None:
if new_value:
self.stats[new_value.name] = new_value.value
def edit_value(self, name: str, value: Union[int, str], data_type: str) -> bool:
if name in self.stats:
new_value = self.create_value(name, value, data_type)
if new_value:
self.stats[name] = new_value.value
return True
return False
def remove_value(self, name: str) -> bool:
if name in self.stats:
del self.stats[name]
return True
return False
def add_bulk_values(self, values: List[Tuple[str, Union[int, str], str]]) -> None:
for name, value, data_type in values:
new_value = self.create_value(name, value, data_type)
if new_value:
self.stats[name] = new_value.value
def delete_bulk_values(self, names: List[str]) -> None:
for name in names:
if name in self.stats:
del self.stats[name]
def view_bulk_values(self) -> Dict[str, Union[int, str]]:
result = {}
for name, value in self.stats.items():
result[name] = json.loads(value) if self.type == 'json' else value
return result
def store_values_in_file(self, filename: str) -> None:
with open(filename, 'w') as file:
json.dump(self.stats, file)
@staticmethod
def from_file(filename: str, title: str, data_type: str) -> 'Engine':
with open(filename, 'r') as file:
data = json.load(file)
engine = Engine(title, data_type)
engine.stats = data
return engine
def __repr__(self) -> str:
return f"Engine(title='{self.title}', type='{self.type}', stats={self.stats})"
def __str__(self) -> str:
return f"Engine: {self.title}, Type: {self.type}, Stats: {self.stats}"
def to_dict(self) -> dict:
return self.__dict__