Simulate a file directory
Hi all (long time reader, first time poster ;) )
Basically, I'm developing a game on hacking and want to simulate a file directory that the player will see and search for particular files - a little like Uplink.
But I'm not sure how best to do this, I'm thinking along the lines of using external files holding the file structure and coding a search through these to give the impression of connecting to a remote site and viewing the directories. But is is best to use xml/plain text/some other format?
I know that you can do a DOS command (tree > file.txt) to print a file directory and it looks like it could be useful, but basically wondered if anyone has done something similar and which is the best method to use.
Any pointers, muchly appreciated.
There's no shortage of ways to do this, but using XML files with a DOM-compliant parser such as TinyXML will involve very little overhead while (as a side benefit) teaching you about XML/DOM stuff. The nice thing about DOM is that it already uses a tree structure to represent the document, which is nearly ideal for the sort of stuff you're looking for.
Do you mean simulated directory structure (something entirely in the context of the game), or
a display of a real directory / .zip file somewhere on their computer that you want to let them browse in a safe simulated environment?
a display of a real directory / .zip file somewhere on their computer that you want to let them browse in a safe simulated environment?
Yeah, sorry if that wasn't clear, I wanted a simulated directory enclosed in the program - entirely in the context of the game. I think it could get a bit dodgy letting players access real files!
Well, OOP is your friend, as in
Of course you could collapse all 3 classes into one class and name it Inode or something. Just have a look at wikipedia on filesystems and be inspired [smile]
Ah, btw, for serialisation, you could usee boost. Though it won't actually be that hard with c++ filefunctions, especially because this is a self contained recursive structure.
class Permissions {}class File { Permissions permissions; // permissions for this file};class Directory { Permissions permissions; // permissions for this directory vector <Directory> subDirectories; vector <File> files;};
Of course you could collapse all 3 classes into one class and name it Inode or something. Just have a look at wikipedia on filesystems and be inspired [smile]
Ah, btw, for serialisation, you could usee boost. Though it won't actually be that hard with c++ filefunctions, especially because this is a self contained recursive structure.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement