Today I built a character file reader as part of my card
C#(XNA) card game engine. I learned the importance and usefulness for reader and
writer classes. They are my favorite!
Summary:
Each character in my card game has a deck of cards and
each deck of cards has a list of cards. To do this, I started by creating a
file reader object that read in text from a text file and a text parser which
broke up a string into variables wherever it saw the ‘#’ symbol. Then I created
three reader classes; one for characters, one for decks, and one for cards. The
reader classes used the file reader and text parser to pull in data from a text
file and create an object with it. For example: the card reader created a full
card object from the data in a text file. After I had a way to create the objects,
I made three writers classes, one for characters, one for decks, one for cards,
and used them to fill a list of objects.
So, in the end, I have a card writer fill a list of every
card in the game, a deck writer fill a list of every deck in the game, and a
character writer fill a list of every character in the game.
Why is this method amazing?
This method is amazing because it’s safe and efficient.
Every variable is protected and accessible with getters, some with setters.
Each object is a utility that can be used on its own (does not rely on the
other classes, independent). All your data is in text files and even
non-programmers can edit them and change them and create them! Adding content
to the game now is as simple as mass-producing text files and some graphics.
Comment about a time when you worked hard to build a tool
that made content creation a breeze!
No comments:
Post a Comment