Adventure Builder


Recommended Posts

Ok I am looking for input.

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 Namespace

an 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>

Edited by iccaros
Link to post
Share on other sites

can someone compile this in mono for me and let me know if it runs. My company gave me a new laptop and I don't have Linux up and running due to encryption they put on the harddrive.. Waiting ot buy new drive and fix this problem..

But I wanted ot make sure It would run..

Link to post
Share on other sites

thanks JCL. I just installed mono on windows.. I had to remove

using System.Collections;

using System.Collections.Generic;

to get it to build, but it worked and those are not needed and just left over from tring to use arrayList..

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...