Adventure Builder Code
//This has been tested on Iccaros-Linux, Gentoo and Windows Using Mono 2.0
// Aventure Build Creates XML files to be read by an adventure game engine
// Copyright (C) 2006-2007 William S. Huskey
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
using System;
using System.Collections.Generic;
using System.Xml;
namespace Adv_File_builder_console
{
class adventureBuild
{
//————————–BUILD FILE—————————————————-
//method to build xml file from questions asked user
public static void buildFile(int room, string filename)
{
//——–Create File and Header information————–
XmlTextWriter gameFile = new XmlTextWriter(filename,null);
gameFile.Formatting = Formatting.Indented;
gameFile.Indentation = 3;
gameFile.WriteStartDocument();
gameFile.WriteComment(”Test XML write”);
gameFile.WriteStartElement(”adventuregame”);
//————Header and File created
//————–loop thourgh number of rooms to create—-
for (int x = 1; x <= room ;x++)
{
//-----Loop variables used for eash pass--------------
string decription = "";
string rn = "";//room north
string rs = "";//room south
string re = "";//room east
string rw = "";//room west
//----------------USER QUESTIONS-----------------------
//note this will be better from a GUI as formating can be applied better
//now the user could use the standard escape symbols.
System.Console.WriteLine("enter Description of room " + x + ":");
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();
//--------------END USER QUESTIONS--------------------
//---------------Write Data to File in XML format---------
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 data write-------------------------
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 “);
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 “);
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

