I have a starts of a program (from the command line GUI next) that will build an xml file that contains all the information for a text based adventure game (think 1980's)
The ideal is to break the file into room's with the following information for each room
What room numbers are to each side (N,S,E,W) along with a description of the room and if there are hidden items in the room
At the end expand to allow monsters, or other NPC or items that are not apart of rooms.
The goal is to allow others to make the game engine that uses this file (I will make one in C# mono and .net)
If you have input or would like to help let me know..
Here is the code as it stands..
/*
* Created by SharpDevelop.
* User: huskeyw
* Date: 7/19/2006
* Time: 10:05 AM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
//using System.Xml.XPath;
namespace AdventureBuild
{
class adventureBuild
{
//--------------------------BUILD FILE----------------------------------------------------
//method to build xml file from questions asked user
public static void buildFile(int room, string filename)
{
XmlTextWriter gameFile = new XmlTextWriter(filename,null);
gameFile.Formatting = Formatting.Indented;
gameFile.Indentation = 3;
gameFile.WriteStartDocument();
gameFile.WriteComment("Test XML write");
gameFile.WriteStartElement("adventuregame");
for (int x = 1; x <= room;x++)
{
string decription = "";
string rn = "";//room north
string rs = "";//room south
string re = "";//room east
string rw = "";//room west
System.Console.WriteLine("enter Description of room:");
decription = System.Console.ReadLine();
System.Console.WriteLine("What Room is to the north?");
rn = System.Console.ReadLine();
System.Console.WriteLine("What Room is to the south?");
rs = System.Console.ReadLine();
System.Console.WriteLine("What Room is to the east?");
re = System.Console.ReadLine();
System.Console.WriteLine("What Room is to the west?");
rw = System.Console.ReadLine();
gameFile.WriteStartElement("room"+x);
gameFile.WriteElementString("Description", decription);
gameFile.WriteElementString("hiding", "Gold Key");
gameFile.WriteElementString("North",rn );
gameFile.WriteElementString("South", rs);
gameFile.WriteElementString("East", re);
gameFile.WriteElementString("West", rw);
gameFile.WriteEndElement();
}//end writeing file data loop
gameFile.WriteEndElement();
gameFile.Flush();
gameFile.Close();
}//end build fild method
//-----------------------------------------------------------------------------------------------
//---------------------MAIN METHOD-----------------------------------------------------------
public static int Main(string[] args)
{
//create list to store information
//store name of game file
string filename = "";
//store number of rooms to be built
int rooms = 0;
//example is for output to user
string example = "\"c:\\myfile.xml\"";
if ((args.Length == 0) || (args.Length > 2))
{
System.Console.WriteLine("adventureBuild must be ran with the following arguments.");
System.Console.WriteLine("Usage: adventureBuilder.exe <filename> <number of rooms> ");
System.Console.WriteLine("NOTE: file name needs to be in quotes if it \nincludes the path and end file with .xml");
System.Console.WriteLine("Example: adventureBuild.exe " + example + " 3");
return 1;
}//end if on args length check
try
{
filename = args[0];
rooms = Convert.ToInt16(args[1]);
}//end try
catch (System.FormatException)
{
System.Console.WriteLine("the argument format is incorrect.");
System.Console.WriteLine("Command adventureBuild must be ran with the following arguments.");
System.Console.WriteLine("Usage: adventureBuilder.exe <filename> <number of rooms> ");
System.Console.WriteLine("NOTE: file name needs to be in quotes if it includes the path and end file with .xml");
return 1;
}//end catch
buildFile(rooms,filename);
return 0;
}//end main
}//end class
}//end Namespacean example of the output file:
<?xml version="1.0"?> <!--Test XML write--> <adventuregame> <room1> <Description>room1 green well lit smells nice</Description> <hiding>Gold Key</hiding> <North>0</North> <South>9</South> <East>2</East> <West>0</West> </room1> <room2> <Description>this room is damp, smells like old socks</Description> <hiding>Gold Key</hiding> <North>0</North> <South>10</South> <East>3</East> <West>1</West> </room2> </adventuregame>
This post has been edited by iccaros: 09 September 2006 - 07:28 PM

Sign In »
Register Now!
Help


Back to top
MultiQuote