Skip to content

Instantly share code, notes, and snippets.

View Pinacolada64's full-sized avatar

Ryan Sherwood Pinacolada64

View GitHub Profile
@Pinacolada64
Pinacolada64 / player-x.json
Created February 9, 2023 06:52
Valid player JSON file
# 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,
# 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
@Pinacolada64
Pinacolada64 / flag_operations.py
Last active November 29, 2022 21:01
Manipulating flags
# if '__name__' == '__main__':
import logging
flag = [
{'name': 'dungeon_master',
'status': True,
'type': 'yes/no'},
{'name': "room_descriptions",
'status': True,
@Pinacolada64
Pinacolada64 / object_classes.py
Last active November 23, 2022 23:48
Getting object classes working.
"""
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
@Pinacolada64
Pinacolada64 / scratch_20.py
Created November 9, 2022 07:17
Trying a different way of instantiating a character
"""
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
@Pinacolada64
Pinacolada64 / scratch_19.py
Created November 7, 2022 22:19
try/catch, random.choice
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:
@Pinacolada64
Pinacolada64 / scratch_15.py
Last active May 18, 2022 05:01
doctest test
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
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
@Pinacolada64
Pinacolada64 / map_file_2.py
Created February 19, 2022 22:58
Trying to read in items
#!/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
@Pinacolada64
Pinacolada64 / player.json
Created January 11, 2022 04:52
Player JSON data
{
"id": "x",
"name": "Mr. X",
"map_level": 1,
"room": 1,
"money": 1000,
"health": 100,
"xp": 100,
"flag": {
"room_descs": true,