Thread: C# Interactive Fiction -- Need some ideas on something

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    17

    C# Interactive Fiction -- Need some ideas on something

    As a learning project I thought I'd start with an Interactive Fiction game in C#. As it's progressing, I think I'm doing a fairly good job (but this may be relative). However, I've reached something where I need some ideas on how to handle some things.

    So far all the player information is stored line by line in a file that is encrypted (so the players can't just go in and change what they want at will). This may work, and is working, for players but when it comes to rooms and NPCs I really want them to be contained in their own files, and then later added to the resources (again, so players can't get access to them).

    When I was younger I grew up learning how to script in mIRC's language. It's fairly close to C, but it does a lot of things that I really took for granted. One of those things is reading and writing INI files. When I was writing my own mIRC DCC MUD I used INI files to store everything (room information, NPC information, player information, etc) and would recall the information needed when a player moved from room to room or interacted with the world. I'd like to do something similar in this game, but I'm learning that INI reading/writing is extremely dificult (I originally tried to learn it in C++ and failed miserably at it). Is there an easy way to read/write INI files in C#? Really all I'd need is reading, since I'd be writing the rooms and such by hand anyway. But I need it to read a specific section, and an item under that section. Like..

    [00001]
    Name=Town Square
    Exits=North:South:East:West (this would be turned into a token and split apart in the program)
    North=00002
    South=00003
    West=000004
    etc etc


    I would need a command, using mIRC as an example $readini(rooms.db, 00001, Name) to return the room name, or whatever I'd need to return. Already the room the player is in is encrypted into the player file, so I'd be using that to grab the information of the room as the player moves from place to place.

    Or is there a better way of doing it with C# other than INIs? Any and all help/ideas are extremely welcome. I thank everyone in advance, and hope this posts make some kind of sense.

    Oh, and if anyone is interested in seeing how it's progressing, here's some images.

    The Login screen
    Create a New User screen (the player icons aren't finished, so that's why it's blank)
    The current game screen (the grey blobs on the left will eventually be replaced with a picture of what the character looks like, just the graphics aren't done yet).

  2. #2
    Call me AirBronto
    Join Date
    Sep 2004
    Location
    Indianapolis, Indiana
    Posts
    195
    This is what i would do, for what ever thing you are using for objects in your game, that being structures or classes ect, make a variable for the coefficent of static friction, remember this needs to be below 1. You should also make a mass variable for all your objects. To calculate for the coefficent of static friction you need to find the axis parrallel to the surface that an object is colliding with. Take you objects mass and multiply by your gravitational constant. Then take the y axis, and the parallel axis that you found and take the dot product of them. This will give you the normal force on your object with respect to the axis you are on. You system should have a good physics system and not just a velocity so that you can add forces and things like that. Make sure that if your object is not moving then just ignore this force, and if it is moving, then add the force but have a little if check for both componets of your force that make sure your force is opposite to your movment compontes. O yea, before you add you force multiply it by the coefficent of friction in your object.

  3. #3
    Call me AirBronto
    Join Date
    Sep 2004
    Location
    Indianapolis, Indiana
    Posts
    195
    lol i did not read your post and just quickly thought i saw the word 'friction' and not 'fiction' sorry

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    17
    lol I was going to say.. that made absolutely no sense towards my problem.

    Are there no ideas out there on how to do this? Anyone? I've been stuck on this problem for awhile now. :\

  5. #5
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    499
    What about making a simple binary file? Aren't those hard to read?

  6. #6
    Registered User
    Join Date
    Mar 2006
    Posts
    17
    Quote Originally Posted by joeprogrammer
    What about making a simple binary file? Aren't those hard to read?
    Wouldn't that be hard to edit/create as well?

  7. #7
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    499
    Maybe.....lol. I don't know much about them.

  8. #8
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    Well, binary I/O isn't too complicated, but you definately couldn't do it with a text editor, meaning you'd need to create an editor for the files, as well as a reader.
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  9. #9
    Code Ripper
    Join Date
    Jun 2004
    Posts
    30
    Iyouboushi,

    i dont know c#, but if you can use windows APIs (as in C/C++), you should try GetPrivateProfileStringA() and similars.

    i hope this help

    jmgk

  10. #10
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    If you want to store in text, and your using C#, then XML should be a good option.

    The System.Xml namespace has lots of helpful classes

  11. #11
    Registered User
    Join Date
    Mar 2006
    Posts
    17
    I'm sorry for bumping this old thread but I recently started working on this again and have come up with a new problem/question for everyone here.

    I decided to go back and change the way the characters are stored. In the past they were plain-text, one line = one value with no descriptions. They are now XML. This is my first time working with XML (in any language) but I think the character file is working 100% because there's no repeating value.

    I want to create the world file as XML too. However, I have a problem. Let's say the world file looks something like this:

    Code:
    <world>
     <0001>
      <Description>A description of the first room</description>
      <exits>north, south</exits>
      <north exit>0002</north exit>
      <south exit>0003</south exit>
     </0001>
     <0002>
      <Description>A description of the second room</description>
      <exits>south</exits>
      <south exit>0001</south exit>
     </0002>
    
    . . .
    </world>
    And so on, and so forth. From what I understand, when I do a search of the XML file it's going to stop at the first match. So if I search for "description" it's going to come to 0001's, read that description and that's it. It'll stop even if I want 0002's, or any other's. Same with any of the other values.


    This is how I have it set up to return a value from the character file. The incoming String node is what value I'm looking for (strength, health, password, name, whatever).

    Code:
            public String getData(String node)
            {
    
                characterReader = new XmlTextReader(file);
                characterReader.WhitespaceHandling = WhitespaceHandling.None;
                characterReader.Namespaces = false;
                String data = "";
                
                while (characterReader.Read())
                {
                    if (characterReader.NodeType == XmlNodeType.Element)
                    {
                        if (characterReader.LocalName.Equals(node))
                        {
                            data = characterReader.ReadString();
                            break;
                        }
                    }
                }
    
                characterReader.Close();
                
                // Finally, return with the data we were after.
                return data;
            }


    So, does anyone know how to overcome the problem I'm going to face designing the world file in XML?

  12. #12
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Without addressing your problem specifically, you should never use IDs as tag names. There are various reasons for this: it's not semantic ("What the hell is a 0001?"), some parsers have problems (Xerces in Java, for example, is liable to run out of memory when there are too many different tag names), etc.
    A better structure would use <room id="0001">
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  13. #13
    Registered User
    Join Date
    Mar 2006
    Posts
    17
    Interesting.

    Okay, so let's say I go back and change my char file to do the same thing (since I structured the char file very similar to my world idea example). How would I modify the XML reading code to read the tag?

    Like for <room id="0001">

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Interactive Fiction?
    By ThyJuggla in forum Game Programming
    Replies: 12
    Last Post: 05-15-2009, 03:20 PM
  2. Ideas, how do you get them? xD
    By Akkernight in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 01-22-2009, 03:53 AM
  3. cool ideas for a game
    By Shadow12345 in forum Game Programming
    Replies: 7
    Last Post: 05-18-2004, 08:37 PM
  4. idea's idea's idea's
    By mithrandir in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 04-29-2002, 12:30 AM
  5. Small app ideas
    By dirkduck in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 02-15-2002, 08:57 PM