This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass | |
import datetime | |
import doctest | |
import logging | |
from random import randrange | |
from typing import Sequence | |
# some of this was--sadly--cribbed from Bing AI. | |
# https://www.reddit.com/r/learnpython/comments/17oblv2/class_method_vs_instance_method/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# map.py | |
# modified from https://www.roguebasin.com/index.php?title=Python_Curses_Example_of_Dungeon-Building_Algorithm | |
# https://roguebasin.com/index.php/Dungeon_builder_written_in_Python/Examples | |
# FIXME: 2d maze generator output doesn't match examples | |
# TODO: get height/width of map, if > screen height/width, display quadrants or something | |
# TODO: display room names underneath? | |
# https://lvngd.com/blog/generating-and-solving-mazes-with-python/# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is based on dot_commands.py | |
# some interesting ideas here: | |
# https://colab.research.google.com/github/interactive-fiction-class/interactive-fiction-class.github.io/blob/master/homeworks/text-adventure-game/Text_Adventure_Game.ipynb#scrollTo=8Cug7Bs3Qpdd | |
from dataclasses import dataclass | |
from typing import Callable, Any, Union | |
import re as regex | |
@dataclass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
def show_keymap(): | |
for value, key_name in keymap.items(): | |
print(f"{value:3} {key_name}") | |
if value % 20 == 0: | |
_ = input("Pause ('Q' quits): ") | |
if _.lower() == "q": | |
print("Aborted.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: | |
import getch | |
except ImportError as e: | |
print(f"Can't import getch: {e}.") | |
def get_character(): | |
""" | |
Wait for a character to be typed | |
return tuple: 'in_char': character, 'asc': ascii value | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# file path: server/run/server/player-a.json | |
{ | |
"name": "Mr. X", | |
"id": "x", | |
"connection_id": 29, | |
"gender": "male", | |
"stat": { | |
"chr": 10, | |
"con": 10, | |
"dex": 10, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# help for https://www.reddit.com/r/learnpython/comments/z86k01/im_trying_to_make_a_chose_your_own_adventure_game/ | |
# game rewritten to use functions for areas, and a simple state machine: | |
def ask_to_play(): | |
while True: | |
answer = input("would you like to play (yes/no) ") | |
if answer.lower().strip() == "yes": | |
state = "forest path" | |
# exit while loop |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# if '__name__' == '__main__': | |
import logging | |
flag = [ | |
{'name': 'dungeon_master', | |
'status': True, | |
'type': 'yes/no'}, | |
{'name': "room_descriptions", | |
'status': True, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A note about positional parameters: | |
https://www.reddit.com/r/learnpython/comments/yptsyp/comment/ivkydz0/?utm_source=share&utm_medium=web2x&context=3 | |
""" | |
import random | |
from datetime import datetime | |
from dataclasses import dataclass | |
from typing import Tuple |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A note about positional parameters: | |
https://www.reddit.com/r/learnpython/comments/yptsyp/comment/ivkydz0/?utm_source=share&utm_medium=web2x&context=3 | |
""" | |
from dataclasses import dataclass | |
from typing import Tuple | |