Hi. I am currently working on a windows form text base game. Im using C# to program it. I am stuck on one point though i need to know how to pull in text files to a string then output them into a text box for the player to read. And if there is a way that I can section off the document to display one section at a time the would be helpful too for example I write two paragraphs and I want to display one then do some other stuff for a while and then display the second one. answers to these questions would be greatly appreciated.
Thank you.
Also is there any way to play .wav files and loop them?
C# Text base Game Help.
Started by AealOfDarkness, Jan 15 2008 04:59 PM
7 replies to this topic
#1
Posted 15 January 2008 - 04:59 PM
|
|
|
#2
Posted 15 January 2008 - 08:53 PM
to load the text from a file, use something like this:
That will give you the whole content at once. If you want to mark sections that will be something you do when you are creating the txt file to start with, then you can process the string object to find the different sections.
For playing .wav files I think there was an API call that did just that, and I think one of the nice/bad things about it is that it looped until the program closed.
using System.IO; //... StreamReader r = new StreamReader(@"C:\somefile.txt"); string text = r.ReadToEnd(); r.Close();
That will give you the whole content at once. If you want to mark sections that will be something you do when you are creating the txt file to start with, then you can process the string object to find the different sections.
For playing .wav files I think there was an API call that did just that, and I think one of the nice/bad things about it is that it looped until the program closed.
Visual C# Kicks - Everything C#.NET programming related
#3
Posted 16 January 2008 - 03:38 AM
Thank you very much this is a big help. i also have one other question. My code is starting to become a bit cluttered. I Have the main syntax of my game down but i still need to implement an experience system and a battle system. I was wondering if i could have two separate classes from the one I have now (so I have a total of three) And make cross class function calls.
So When you are moving around you would call a Random number generator It would check to see if you had a battle this move the it would call a function in the battle class go through the code in that class and then give you exp and call the exp class to see if you gain a level. I knew how to do this in c++ but i guess I forgot how to do it or its different in c#...
So When you are moving around you would call a Random number generator It would check to see if you had a battle this move the it would call a function in the battle class go through the code in that class and then give you exp and call the exp class to see if you gain a level. I knew how to do this in c++ but i guess I forgot how to do it or its different in c#...
#4
Posted 16 January 2008 - 12:49 PM
you can definitely have separate classes, then you can either have static methods in each class so you can access methods directly, or you could create a new instance of each class at the game's load.
Visual C# Kicks - Everything C#.NET programming related
#5
Posted 16 January 2008 - 02:01 PM
Well I want to Separate the main game form the battle and exp system. basically i want to be able to call the Functions from the battle class in the Main game Class and then go from the battle class to the exp class and then back to the game. Which of those methods would be best suited for what I want to do? and could you Direct me in the direction of how i could implement that method of where i could find how to implement it.
#6
Posted 16 January 2008 - 02:09 PM
I heres what i want to be able to do
Public partial class Form:Form1
{
//main game stuff goes here
Somefunction();
}
//new Class in a separate window
Public partial class Battle
{
Public void Somefunction()
{
//insert fuction stuff here
}
}
Public partial class Form:Form1
{
//main game stuff goes here
Somefunction();
}
//new Class in a separate window
Public partial class Battle
{
Public void Somefunction()
{
//insert fuction stuff here
}
}
#7
Posted 16 January 2008 - 02:13 PM
sry
#8
Posted 17 January 2008 - 08:05 PM
Quote
Public partial class Form:Form1
{
//main game stuff goes here
Somefunction();
}
//new Class in a separate window
Public partial class Battle
{
Public void Somefunction()
{
//insert fuction stuff here
}
}
{
//main game stuff goes here
Somefunction();
}
//new Class in a separate window
Public partial class Battle
{
Public void Somefunction()
{
//insert fuction stuff here
}
}
Ok with your example, you would so something like
Battle battleClass = new Battle(); battleClass.Somefunction();
if you are saving any values within the Battle class itself, then you might want to create the "new Battle()" part in a global variable, otherwise just doing that will be okay.
Visual C# Kicks - Everything C#.NET programming related


Sign In
Create Account

Back to top









