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 random | |
def ask_name(): | |
is_ok = False | |
while is_ok is False: | |
my_name = input("What is your name? ") | |
if my_name.lower() == "michelle": | |
print("You answered correctly!") | |
return my_name.title() | |
else: |
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 doctest | |
import logging | |
def add_two_numbers(a, b): | |
""" | |
Add two numbers, a and b, together. Return the total. | |
:param a: first number to add | |
:param b: second number to add |
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
C:\Users\ryan-\AppData\Local\Programs\Python\Python38\python.exe "D:\Program Files\JetBrains\PyCharm Community Edition 2020.3.2\plugins\python-ce\helpers\pydev\pydevd.py" --multiproc --qt-support=auto --client 127.0.0.1 --port 56514 --file D:/Documents/C64/TADA/server/client.py | |
Connected to pydev debugger (build 213.6777.50) | |
client connected (localhost:5000) | |
Welcome to: | |
Totally | |
Awesome | |
Dungeon | |
Adventure | |
Please log in. | |
user? >? a |
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 | |
# + encode map data as JSON. why: | |
# + don't need to write own parser, | |
# + flexible for adding/changing fields (including optional fields) | |
# + use 'dataclass' for Room. why: | |
# + convenient for class with many fields mostly stored as data | |
# + use 'textwrap' for formatting multiline text. why: | |
# + can store text without all the format |
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
{ | |
"id": "x", | |
"name": "Mr. X", | |
"map_level": 1, | |
"room": 1, | |
"money": 1000, | |
"health": 100, | |
"xp": 100, | |
"flag": { | |
"room_descs": 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
class Player(object): | |
def __init__(self, age: int): | |
self.age = age | |
def print_age(self): | |
# FIXME: can calling p.print_age() be simplified by instead using a __str__ method? | |
if self.age == 0: | |
return 'Unknown' | |
else: | |
return f'{self.age} years' |
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 |
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
# 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
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=}') |