BestTechie Forums: Adventure Builder - BestTechie Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Adventure Builder


Rate Topic: -----

#1 User is offline   iccaros 

  • UberTechie
  • Group: Linux Experts
  • Posts: 1292
  • Joined: 31-August 04
  • Location:Great State of Washingtion
  • Operating System:Gentoo,Iccaros-Linux(of course),Slackware,GentooX,Red Hat, Windows (3.1 to VISTA BETA), MAC OSX (10.4 currently),LFS, Solaris 8,9,10, Trusted Solaris, FreeBSD, OPENBSD, NETBSD

Posted 09 September 2006 - 07:25 PM

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>

This post has been edited by iccaros: 09 September 2006 - 07:28 PM


#2 User is offline   iccaros 

  • UberTechie
  • Group: Linux Experts
  • Posts: 1292
  • Joined: 31-August 04
  • Location:Great State of Washingtion
  • Operating System:Gentoo,Iccaros-Linux(of course),Slackware,GentooX,Red Hat, Windows (3.1 to VISTA BETA), MAC OSX (10.4 currently),LFS, Solaris 8,9,10, Trusted Solaris, FreeBSD, OPENBSD, NETBSD

Posted 09 September 2006 - 10:24 PM

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

#3 User is offline   jcl 

  • UberTechie
  • Group: Linux Experts
  • Posts: 1304
  • Joined: 30-August 04
  • Location:The Internet
  • Operating System:Arch

Posted 09 September 2006 - 11:02 PM

Builds and runs with Mono.

#4 User is offline   iccaros 

  • UberTechie
  • Group: Linux Experts
  • Posts: 1292
  • Joined: 31-August 04
  • Location:Great State of Washingtion
  • Operating System:Gentoo,Iccaros-Linux(of course),Slackware,GentooX,Red Hat, Windows (3.1 to VISTA BETA), MAC OSX (10.4 currently),LFS, Solaris 8,9,10, Trusted Solaris, FreeBSD, OPENBSD, NETBSD

Posted 11 September 2006 - 01:26 AM

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

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users