Compare commits

...
2 Commits
Author SHA1 Message Date
lockeshor 9eaff2d837 define most app variables and begin working on skill check logic 2026-10-07 00:29:07 -04:00
lockeshor 1fad510038 add saveState management 2026-10-07 00:03:06 -04:00
3 changed files with 85 additions and 7 deletions
+20 -1
View File
@@ -1,9 +1,28 @@
###############################################
Prompt to Kiro AI (Default):
from now on, I will mostly be asking questions about approach, so please do not perform any actions or code edits unless explicitly requested. also, please be less verbose - I want nice, quick answers that provide the necessary context. How can I check if a file exists/isreadable for my loadSave function?
Response:
Two clean options:
os.path.exists(path) — checks the file is there before opening.
python
import os
if os.path.exists(path):
# open and read
try/except — just attempt to open and catch the failure. This is the more Pythonic approach and also handles the "exists but unreadable/corrupt" case in one shot:
python
try:
with open(path) as f:
...
except (FileNotFoundError, IOError):
return defaultState()
For loadSave, the try/except is the better fit since you also want to catch bad JSON — wrap json.load in the same block and catch json.JSONDecodeError too, falling back to a fresh default state on any failure.
###############################################
+5
View File
@@ -8,4 +8,9 @@ Description: The main AI agent in kiro, used for most if not all of the promptin
###############################################
Source: Google Search / Google Search AI
Description: Used infrequently just for general questions regarding python or graphics, no specific usage (and google search AI is just kind of always there)
###############################################
###############################################
Source: CMU Graphics Documentation (https://academy.cs.cmu.edu/cpcs-docs)
Description: Refferred to for implementation and MVC architecture along with how to interface with graphics
###############################################
+60 -6
View File
@@ -10,6 +10,7 @@
# =============================================================================
from cmu_graphics import *
import json
# =============================================================================
@@ -44,19 +45,31 @@ def loadCreatures(path="creatures.tsv"):
return creatures
def loadSave(path):
def loadSave(path="save.json"):
# Load save.json and return the player's saved state (money, owned baits,
# owned upgrades, current bait, caught log, etc.). If the file is missing
# or unreadable, return a fresh default-state dict so a first-time player
# starts cleanly. This is the only place that reads the save file.
pass
defaultState = {
"cash": 0,
"owned_baits": [],
"owned_upgrades": [],
"current_bait": "worm",
"catch_log": []
}
try:
with open(path, "r") as f:
return json.load(f)
except (FileNotFoundError, IOError):
return defaultState
def writeSave(path, saveState):
def writeSave(saveState, path="save.json"):
# Serialize the current player state to save.json. Call this at key moments
# (after a sale, after a purchase, on quit) so progress persists between
# sessions. Keep the written structure identical to what loadSave expects.
pass
with open(path, "w") as f: #overwrite existing
f.write(json.dumps(saveState))
# =============================================================================
@@ -66,17 +79,52 @@ def writeSave(path, saveState):
# No drawing and no event handling here - just state.
# =============================================================================
AVAILABLE_UPGRADES = [ # (name, bonus_type, bonus_modifier, price)
#power mods
("Smart Rod", "power", 2, 100),
("Clever Rod", "power", 7, 350),
("Intelligent Rod", "power", 10, 1500),
("Genius Rod", "power", 20, 20000)
]
def onAppStart(app):
# cmu_graphics entry point. Initialize ALL app.* state here:
# - window/layout constants (width, height, dock/water/grass regions)
# - app.creatures (from loadCreatures)
# - app.save (from loadSave) and derived player values
# - app.scene (which screen is active: 'dock', 'shop', 'catch', ...)
# - fishing state (idle / waiting-for-bite / skill-check / result)
# - skill-check state placeholders (cursor angle, bars, speed, result)
# - app.stepsPerSecond for the game loop cadence
# Delegates to the smaller setup helpers below to keep this readable.
pass
#DRAWING CONSTANTS
app.width = 600
app.height = 400
app.background = 'lightSkyBlue'
app.waterColor = 'midnightBlue'
app.grassColor = 'seaGreen'
app.waterHeight = app.height // 3
app.waterBottom = app.height = app.waterHeight
app.grassHeight = 20
app.grassBottom = app.height - app.waterHeight - app.grassHeight
#GAME STATE/SETUP
app.stepsPerSecond = 30
app.creatures = loadCreatures()
app.save = loadSave()
app.scene = "idle" # idle, waiting-for-bite, skill-check, result, shopping, menu
#SKILL CHECK
app.skillCheckAngle = 0
app.skillCheckSpeed = 1
app.skillCheckBars = []
app.skillCheckSpeed = 1
app.skillCheckFailed = False
#FISHING
app.fishingTimer = 0
app.hookedFish = None
def resetFishingState(app):
@@ -102,6 +150,12 @@ def startSkillCheck(app, creature):
# bar length/width. Also apply any owned upgrades that modify these values
# (e.g. slower cursor, wider bars, extra forgiveness). Stores the resulting
# parameters on app for the controller/view to use.
app.scene = "skill-check"
difficulty = creature["difficulty"]
fishingPower = 1 + sum(upgrade[2] for upgrade in AVAILABLE_UPGRADES if (upgrade[0] in app.save["owned_upgrades"] and upgrade[1] == "power"))
app.skillCheckSpeed = difficulty / fishingPower
pass