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 time | |
import logging | |
# https://docs.python.org/3/library/decimal.html?#recipes | |
# this does not work for me | |
def comma_delimited_value(value=0, right_justify=False): | |
""" |
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
class Player: | |
def __init__(self, name, player_id, stats, silver): | |
self.name = name | |
self.player_id = player_id | |
self.stats = {"constitution": 0, "dexterity": 0, "ego": 0, "intelligence": 0, | |
"strength": 0, "wisdom": 0} # creates a new stats dict for each Player | |
self.silver = {"in_hand": 0, "in_bank": 0, "in_bar": 0} # creates a new silver dict for each Player | |
# test that it works | |
print("Silver in hand: " + str(self.silver["in_hand"])) |
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
def grammatical_list(item_list): | |
print("Entered function") | |
for item in item_list: | |
if item[:-1] == 's': | |
item = "some " + item | |
if item.startswith(('a', 'e', 'i', 'o', 'u')): | |
item = "an " + item | |
# print(item, sep="and, ", end='') | |
print(item) | |
print("Exited function") |
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 prompt_toolkit import prompt | |
# Test walking around on a map | |
""" | |
# * Room number (rm) | |
# * Location name (lo$) | |
# * items: monster, item, weapon, food | |
# * exits: north, east, south, west | |
# RC (room command: 1=move up, |
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
direction_names = ['North', 'East', 'South', 'West', 'Up', 'Down'] | |
def show_exits(exits): | |
"""list room exits""" | |
exit_list = [] | |
if exits[0]: | |
exit_list.append("North") | |
if exits[1]: |
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 prompt_toolkit import prompt # this doesn't work on Windows | |
# Test walking around on a map | |
""" | |
Data format on C64: | |
* Room number (rm) | |
* Location name (lo$) | |
* items: monster, item, weapon, food | |
* exits: north, east, south, west |
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
class Exit(object): | |
def __init__(self, room_number: int, exit_list: list): | |
""" | |
Exits are contained in a list, exit_list | |
:param room_number: this Exit's room number | |
:param exit_list: list of 5 exits per room: north, east, south, west, room_connection, room_transport | |
""" | |
self.room_number = room_number | |
self.exits = exit_list | |
logging.info(f'Exit.__init__: created new exit: {room_number=} {exit_list=}') |
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 text based RPG | |
# from http://pythonfiddle.com/text-based-rpg-code-python/ | |
# ryan made a few IDE-suggested tweaks: | |
# 'if IsDaggerEquipped == True:' -> 'if IsDaggerEquipped:' | |
# Import required modules | |
import jsonpickle # FIXME: this does not exist on python 3.x, so causes an error when used | |
import os | |
import sys | |
import time |
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
#!/bin/env python3 | |
import socketserver | |
import json | |
from dataclasses import dataclass, field | |
import enum | |
import net_common as nc | |
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 cmd | |
import textwrap | |
import logging | |
import pyreadline3 # for tab-completion and command line editing | |
# PyCharm had me rename worldItems -> world_items, but camelCase variables are legal in Python | |
# there is an option in the IDE to ignore camelCase variables, so I set that | |
# class design resources: | |
# https://codereview.stackexchange.com/questions/91069/simple-text-rpg-in-python |