Ex45 -- Structuring JSON Data

I’m working on Exercise 45 – “You Make a Game”, and I’m trying to create a text-based version of the Cave of Ordeals from Legend of Zelda: Twilight Princess. Granted, it’s only going to be a few floors of combat, as opposed to 45 – dear God that’s a lot, but it’s still quite the endeavor. I skipped ahead a bit to Ex47 to work with automated testing, and I’m slowly figuring out how to make things work and pass tests and such.

However, I need a way to store data, such as enemy and item attributes. I did some poking around on the Game Dev Stack Exchange and saw that some people recommended JSON for this purpose. In reading up on it, I found it makes a lot of sense and the syntax is pretty straightforward. However, I’m not sure how to best structure the file, and I can’t find a resource that explains it clearly.

Here’s what I have so far:

{
    "Bokoblin":
    {
        "max_hp": 16,
        "atk": 4,
        "defense": 0
    }
}

Are the top-level braces strictly necessary? I saw this structure in this article, and so I assumed it was necessary, but of course, that might not be the case. Can someone with JSON experience please explain this to me or at least point me to a resource that can?

I think JSON is nice. But because you do a Python project I would suggest that you store your data in a Dictionary. It’s very similar to JSON but it’s a native Python citizen. You can write your dicts to a file on your hard drive (like you would with a JSON File).

@DidierCH, well that would simplify the file-reading process. I’ll try that and see how it goes.

Good first test, but I’m going to warn you:

Everyone wants to do a video game and add a combat system, but they usually end up failing at it since that’s a bit harder than your current skills can handle. Give your idea a try, but if you can’t make it work, then scale back and just do a simple game like mine but with your new theme. No combat.

Just a quick question, does that mean database skills like SQL should be used IF there was a combat system?

Noooooooooooo. That is WAY beyond the requirements. I think the only thing you’re going to need is dicts and lists, and maybe the global keyword. Take those as hints and try it out, but then drastically scale that back if you can’t figure it out. No shame in not making that work as a full combat system takes a while and is sort of beyond your pay grade at this point (but possible).

1 Like