fill out creatures file and implement loadCreatures

This commit is contained in:
2026-10-06 23:56:14 -04:00
parent be3516f9c7
commit 9d14bc56b2
3 changed files with 37 additions and 13 deletions
+17 -2
View File
@@ -19,14 +19,29 @@ from cmu_graphics import *
# the data source (TSV path, save path) can change without touching gameplay.
# =============================================================================
def loadCreatures(path):
def loadCreatures(path="creatures.tsv"):
# Read creatures.tsv (tab-separated) and parse it into a usable structure.
# Suggested return: a list of dicts, one per creature, with keys matching
# the header row: name, description, price, sprite-file, difficulty,
# length, weight. Convert numeric columns (price, difficulty, length,
# weight) from strings to int/float here; leave missing fields as sensible
# defaults so partially-filled rows (like the current TSV) don't crash.
pass
creatures = []
with open(path) as f:
lines = f.readlines()
for line in lines[1:]: #ignore header
data = line.split("\t")
creatures.append({
"name": data[0],
"description": data[1],
"price": float(data[2]),
"sprite-file": data[3],
"difficulty": int(data[4]),
"length": float(data[5]), #inches
"weight": float(data[6]) #pounds
})
return creatures
def loadSave(path):