473,322 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Binary "Database" for a game - please help

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
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 16 '05 #1
4 1687
Daedric <ac****@comcast-dot-net.no-spam.invalid> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
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.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
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.

Nov 16 '05 #4
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" <ac****@comcast-dot-net.no-spam.invalid> wrote in message
news:42********@127.0.0.1...
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
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Yasso Picasso | last post by:
Greetings, I have to admit that I'm still a beginner in the database field, but I'm actively studying, and this is why I will be utterly grateful for the proper, accurate, and wise guidance to...
1
by: Kenjis Kaan | last post by:
I had to run DB2 on Win2k. After installation it puts a directory under c:\DB2 and c:\DB2Log and C:\Program Files\SQLLIB Now am all confused which is instance home, db2 home etc. I had to...
0
by: David P. Donahue | last post by:
I'm using C# to create an ASP .NET website backed by a MySQL database. One of the things I do often on the site is populate a DataList by binding it to a DataSet pulled from the database. However,...
8
by: Maxi | last post by:
Hello, i'm sorry my bad english :( I have CR9 Webservice, how to change databadse name and User_name into Webservice method? (not Viewer Control) Tks!! -- --------------------------
1
by: Pedro Leite | last post by:
hello. got stalled at at point that i can no longer get my thoughts together. the point, is in classic asp, stream an excel file from a firebird database. temporarly save it if necessary...
0
by: serge | last post by:
I have 2 SQL Enterprise Editions running SP2 and same collation. When i try to start database mirroring I get the following error message: "The remote copy of database "ABC" has not been...
2
by: alberto | last post by:
I am Very new to .net but have experience with C++ and other languages. Can somebody point me to a "hello world" database program? Create one table (managed to do that with an .mdf database file...
0
by: vaibhavsumant | last post by:
<project name="DBCreate" default="usage" basedir="."> <property name="user" value="db2admin"/> <property name="passwd" value="db2admin"/> <property name="dbprefix" value=""/> <property...
2
by: elgin | last post by:
I have a split Access 2003 database. I have signed the database with a Code Signing Certificate from Small Business Server. This works fine and users can have Access macro security on high or...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.