Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 19th, 2005, 01:00 PM
Registered User
 
Join Date: Feb 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Binary "Database" for a game - Need a how-to =)

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
 
Old February 20th, 2005, 05:19 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

you can make a data structure(class) for your file which includes all the fields like name,size,attribute,and represent your fields as properties,...then make another class for handling that structure,you should have a kind of collection which stores your records(instantiated class)I think the best one could be HashTable,give its key the name of the monsters...
your collection behaves like a cache object you can always work on it instead of underlying stream,every time you need to update your file you should update your collection and also work on the stream through BinaryReader or BinaryWriter for updating the underlying file...

_____________
Mehdi.
software student.
 
Old March 6th, 2005, 05:17 AM
Registered User
 
Join Date: Mar 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear Daedric
i have encounter the same problem as you have only u did manage to do it in vb6.
basically, i want to store my game properties in a text file in a binary way (sets of property=value) that i can load at the beginning
of the game and update them respectively.

can i have a sample code (vb6) of what you did?

10x
gamgam







Similar Threads
Thread Thread Starter Forum Replies Last Post
Old game review guti Need help with your homework? 0 March 20th, 2007 11:28 AM
text game 132591 C++ Programming 18 December 15th, 2006 09:12 AM
Save BINARY FILE in ACCESS database gasma1975 Access 4 February 10th, 2005 12:16 PM
SQL 2000 database / text file / binary file pallone Javascript How-To 3 January 28th, 2005 01:26 PM
retrieve word/excel from database as binary fitchic77 .NET Framework 2.0 1 December 7th, 2004 03:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.