Binary "Database" for a game - please help

  • Thread starter Thread starter Daedric
  • Start date Start date
D

Daedric

Hello and thanks in advance to anyone who offers help.

To make this simple, let's say I have a game which has 100 different
monsters. I want a binary data file to hold all of these. It would
have the index number of the mob, name, size, attributes, etc. I can
easily create an editor to edit the records in this file, as soon as
I know how to create this file and be able to find a specific monster
in the file and fill, say, text boxes full of the information
regarding that specific monster.

I hope I am writing this in a way that you can understand fully what I
mean. Let's say I have a data file full of monsters, and the one I
want to know about is in the middle of the file, say record number
33. I want to be able have my program look for the monster named
"Dragon" and then retrieve all information that goes with that
monster.

I was able to do this easily in VB6. I even made an editor that could
go through the different monsters, with their information populating
text boxes as I browsed through them. but for the life of me I
can't figure out how to do this in C#. I know how to read and write
binary files, but that's about it.

So, to my question. How could I do this? I want all records in a
single binary file and the ability to locate specific ones and get
their info.

Thanks in advance. I apologize for the book I wrote. I just wanted
to make sure it was clear what I was looking for.

Daedric
 
Daedric said:
Hello and thanks in advance to anyone who offers help.

To make this simple, let's say I have a game which has 100 different
monsters. I want a binary data file to hold all of these. It would
have the index number of the mob, name, size, attributes, etc. I can
easily create an editor to edit the records in this file, as soon as
I know how to create this file and be able to find a specific monster
in the file and fill, say, text boxes full of the information
regarding that specific monster.

I hope I am writing this in a way that you can understand fully what I
mean. Let's say I have a data file full of monsters, and the one I
want to know about is in the middle of the file, say record number
33. I want to be able have my program look for the monster named
"Dragon" and then retrieve all information that goes with that
monster.

I was able to do this easily in VB6. I even made an editor that could
go through the different monsters, with their information populating
text boxes as I browsed through them. but for the life of me I
can't figure out how to do this in C#. I know how to read and write
binary files, but that's about it.

It sounds like you really should be separating the concerns of storage
from editing. You can store the details however you like, so long as
you can load them and save them. Load them into a collection of some
description, and then you can edit them, then save them. Unless you
think the file's going to get *really* big, I wouldn't worry about the
hit of loading the whole thing even if you only want access to one
monster.
 
It is even easier in C#. Just create a Hashtable of monster objects and
serialize them to a file.

http://www.geocities.com/jeff_louie/OOP/oop22.htm

private bool Serialize(string pathToFile)
{
Stream outStream= null;
// returns false if pathToFile is null
if (!File.Exists(pathToFile)) {return false;}
outStream = File.OpenWrite(pathToFile);
if(outStream == null){return false;}
// Code to write the stream goes here.
try
{
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(outStream, serilizationVersion);
formatter.Serialize(outStream, monstersHash);
return true;
}
catch (Exception e)
{
System.Console.WriteLine(e);
return false;
}
finally
{
outStream.Close();
}
}

Regards,
Jeff
So, to my question. How could I do this? I want all records in a single
binary file and the ability to locate specific ones and get their info.
 
Now, if we're talking about a lot of monsters... maybe you can't hold
all of them in memory at one time.

In that case I think you have two options:
use a database (MySql, for instance, but if you have the money you can
look at SqlServer, or Oracle), or
make your own 'database', as you describe. If you do that, though, I
suggest you look up B-Trees and such things, since, with large set of
records, a linear file such as you describe will result in slow
performance.

HTH,
F.O.R.
 
Sounds like MS Access be a perfect fit. It not only does a good job of
storing and indexing information, but provides forms to edit the
information. However, if this is some sort of school project and must be
done in C#, then you can still use Access database via ADO.NET and C# as the
front end.

Daedric said:
Hello and thanks in advance to anyone who offers help.

To make this simple, let's say I have a game which has 100 different
monsters. I want a binary data file to hold all of these. It would
have the index number of the mob, name, size, attributes, etc. I can
easily create an editor to edit the records in this file, as soon as
I know how to create this file and be able to find a specific monster
in the file and fill, say, text boxes full of the information
regarding that specific monster.

I hope I am writing this in a way that you can understand fully what I
mean. Let's say I have a data file full of monsters, and the one I
want to know about is in the middle of the file, say record number
33. I want to be able have my program look for the monster named
"Dragon" and then retrieve all information that goes with that
monster.

I was able to do this easily in VB6. I even made an editor that could
go through the different monsters, with their information populating
text boxes as I browsed through them. but for the life of me I
can't figure out how to do this in C#. I know how to read and write
binary files, but that's about it.

So, to my question. How could I do this? I want all records in a
single binary file and the ability to locate specific ones and get
their info.

Thanks in advance. I apologize for the book I wrote. I just wanted
to make sure it was clear what I was looking for.

Daedric
 
Back
Top