7 Replies - 2291 Views - Last Post: 05 January 2009 - 11:11 PM Rate Topic: -----

#1 s3thst4  Icon User is offline

  • a * a = (b * b) + (c * c) - 2(b)(c)cos(A)
  • member icon

Reputation: 10
  • View blog
  • Posts: 587
  • Joined: 20-November 08

Need Help Using Seperate CS Files For 1 Project

Post icon  Posted 05 January 2009 - 10:30 AM

I'm working on an RPG in Console (text-based of course) and I need to put a large amount of code into another CS file to be more organized. But I don't know how to call the information from the new CS file. And also, I have all my variables declared in the main CS file, can I use those variables in the seperate CS files ? And also I'd like to know how to get the information from the other CS file from the main CS file.

~Thanks in advance,
Seth.

Is This A Good Question/Topic? 0
  • +

Replies To: Need Help Using Seperate CS Files For 1 Project

#2 djkitt  Icon User is offline

  • D.I.C Head

Reputation: 29
  • View blog
  • Posts: 189
  • Joined: 22-May 08

Re: Need Help Using Seperate CS Files For 1 Project

Posted 05 January 2009 - 03:11 PM

I'm not sure what you are doing. If you could post some code it would help, but...

If you are just using one class then you can use 'partial class' to just move code to another file but still keep it within your curent class. This would maintain access to variables within your current class.

If you are already using more than one class just put each class in a seperate file under the same namespace.

Hope this helps,

Kitt
Was This Post Helpful? 0
  • +
  • -

#3 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: Need Help Using Seperate CS Files For 1 Project

Posted 05 January 2009 - 03:12 PM

You could create some separate classes in the secondary C# source file, so you could call the class members (as long as the source file is included in the same project) through:

className.Member


This post has been edited by Core: 05 January 2009 - 03:15 PM

Was This Post Helpful? 0
  • +
  • -

#4 s3thst4  Icon User is offline

  • a * a = (b * b) + (c * c) - 2(b)(c)cos(A)
  • member icon

Reputation: 10
  • View blog
  • Posts: 587
  • Joined: 20-November 08

Re: Need Help Using Seperate CS Files For 1 Project

Posted 05 January 2009 - 07:33 PM

View Postdjkitt, on 5 Jan, 2009 - 02:11 PM, said:

I'm not sure what you are doing. If you could post some code it would help, but...

If you are just using one class then you can use 'partial class' to just move code to another file but still keep it within your curent class. This would maintain access to variables within your current class.

If you are already using more than one class just put each class in a seperate file under the same namespace.

Hope this helps,

Kitt


I do need to use the same class, that would be very helpful. Do you know how to use 'partial classes' because I've never heard of it.
Was This Post Helpful? 0
  • +
  • -

#5 badjava  Icon User is offline

  • Lux Ex Tenebris
  • member icon

Reputation: 14
  • View blog
  • Posts: 540
  • Joined: 30-October 08

Re: Need Help Using Seperate CS Files For 1 Project

Posted 05 January 2009 - 08:07 PM

View Posts3thst4, on 5 Jan, 2009 - 06:33 PM, said:

View Postdjkitt, on 5 Jan, 2009 - 02:11 PM, said:

I'm not sure what you are doing. If you could post some code it would help, but...

If you are just using one class then you can use 'partial class' to just move code to another file but still keep it within your curent class. This would maintain access to variables within your current class.

If you are already using more than one class just put each class in a seperate file under the same namespace.

Hope this helps,

Kitt


I do need to use the same class, that would be very helpful. Do you know how to use 'partial classes' because I've never heard of it.


Did you google it?

Understanding and Using .NET Partial Classes

Scroll down to this line; "The syntax of partial classes in VB.NET and C# differs slightly. The following shows the implementation of partial classes in C#:"

Hey s3thst4, btw I happen to be working on something almost exactly like you are it sounds. Well I am a few steps behind in the design phase still but I would love to hear how you are doing things. I am trying to perfect a movement system right now and I would especially like to hear how you did that.

This post has been edited by badjava: 05 January 2009 - 08:11 PM

Was This Post Helpful? 1
  • +
  • -

#6 s3thst4  Icon User is offline

  • a * a = (b * b) + (c * c) - 2(b)(c)cos(A)
  • member icon

Reputation: 10
  • View blog
  • Posts: 587
  • Joined: 20-November 08

Re: Need Help Using Seperate CS Files For 1 Project

Posted 05 January 2009 - 09:18 PM

View Postbadjava, on 5 Jan, 2009 - 07:07 PM, said:

View Posts3thst4, on 5 Jan, 2009 - 06:33 PM, said:

View Postdjkitt, on 5 Jan, 2009 - 02:11 PM, said:

I'm not sure what you are doing. If you could post some code it would help, but...

If you are just using one class then you can use 'partial class' to just move code to another file but still keep it within your curent class. This would maintain access to variables within your current class.

If you are already using more than one class just put each class in a seperate file under the same namespace.

Hope this helps,

Kitt


I do need to use the same class, that would be very helpful. Do you know how to use 'partial classes' because I've never heard of it.


Did you google it?

Understanding and Using .NET Partial Classes

Scroll down to this line; "The syntax of partial classes in VB.NET and C# differs slightly. The following shows the implementation of partial classes in C#:"

Hey s3thst4, btw I happen to be working on something almost exactly like you are it sounds. Well I am a few steps behind in the design phase still but I would love to hear how you are doing things. I am trying to perfect a movement system right now and I would especially like to hear how you did that.


Thanks a lot for the link. It should help me a lot.

Mine is text-based, no graphics at all. I apologize for misleading you.
Was This Post Helpful? 0
  • +
  • -

#7 badjava  Icon User is offline

  • Lux Ex Tenebris
  • member icon

Reputation: 14
  • View blog
  • Posts: 540
  • Joined: 30-October 08

Re: Need Help Using Seperate CS Files For 1 Project

Posted 05 January 2009 - 10:11 PM

View Posts3thst4, on 5 Jan, 2009 - 08:18 PM, said:

Thanks a lot for the link. It should help me a lot.

Mine is text-based, no graphics at all. I apologize for misleading you.


No misleading at all. If it is text based you still might need a method of going from 'place to place' yes? Or is your version more of a story board where people get to choose things to do and see the results but not necessarily go from room x to room y and back to room x if they choose to?

And ty for the ty :)

This post has been edited by badjava: 05 January 2009 - 10:24 PM

Was This Post Helpful? 0
  • +
  • -

#8 s3thst4  Icon User is offline

  • a * a = (b * b) + (c * c) - 2(b)(c)cos(A)
  • member icon

Reputation: 10
  • View blog
  • Posts: 587
  • Joined: 20-November 08

Re: Need Help Using Seperate CS Files For 1 Project

Posted 05 January 2009 - 11:11 PM

View Postbadjava, on 5 Jan, 2009 - 09:11 PM, said:

View Posts3thst4, on 5 Jan, 2009 - 08:18 PM, said:

Thanks a lot for the link. It should help me a lot.

Mine is text-based, no graphics at all. I apologize for misleading you.


No misleading at all. If it is text based you still might need a method of going from 'place to place' yes? Or is your version more of a story board where people get to choose things to do and see the results but not necessarily go from room x to room y and back to room x if they choose to?

And ty for the ty :)


Ah, I understand where you're getting. What I do is, here is some example code.

do
 {
   Console.WriteLine("Would you like to \n1) Go to town \n2) Do a quest \n3) Go to the shop");
   whattodo = Console.ReadLine();
 } while (whattodo == "" || whattdo != "1" && whattdo != "2" && whattodo != "3");

if (whattdo == "1")
{
  Town(); // A custom method I created.
}
if (whattdo == "2")
{
  Quest(); // A custom method I created.
}
if (whattodo == "3")
{
  Store(); // A custom method I created.
}


And in the methods I create, I give information what to do in 'Town' and the Town reverts back to the method that you just saw with the same with this reverted to Town.

Hope I was helpful.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1