@DoctorWelch said:
@JoxxOr said:
@DoctorWelch: There are a lot of things that are more important to learn as a total new beginner than memory managment. In all honesty as a c++ programmer where its my daily life is to remember where memory gets allocated(always pre-runtime, not during) its not fun at all. If you want some advice, pick up c# and make some awesome games in xna, its much more fun then creating whatever binary search tree you're doing there :).
So, basically xna uses c#? Cause I've always wondered what languages are used to make games.
Any language can be used to make games. Most games are made using C++, but XNA was based on C# to help get newer people introduced into programming. C# is a very easy and powerful language to learn and is based on .NET so you don't have to worry about cleaning up memory when you are done with things since the garbage collector handles that for you. Also when they introduced XNA, they were really pushing C# because it is one of their newer languages and this was the best way to get people exposed to it.
As for your question on what object oriented programming is, hopefully this will help you:
Say you are making a program to hold information on different people. You would make a Person class.
public class Person
{
public string FirstName {get; set;}
public string MiddileInitial {get; set;}
public string LastName {get; set;}
public string BuildDisplayName()
{
return string.Format("{0} {1}. {2}", FirstName, MiddleInitial, LastName);
}
}
Now this is a very basic class to just hold the name of the person and single method to build me the display name. So if the person's first name was John, middle initial was B, and the last name was Doe, the method would return me "John B. Doe". Because I have this one method, anywhere I want to display or work with the full name, I can just call a single method on the Person object I am working with. This allows me to update the code in 1 place even though I could be displaying the person's name in 50 different locations.
static void Main(string[] args)
{
//To use it, all you have to do is create an instance.
Person person = new Person();
//Now I can start assigning values.
person.FirstName = "John";
person.MiddleInitial = "B";
person.LastName = "Doe";
//If I wanted to print the full name I can just call my Person.BuildDisplayName() method
Console.WriteLine("The persons name is {0}.", person.BuildDisplayName());
//That is a lot cleaner than this. If this code was in 50 other locations, you would have to find those 50 locations and update them.
//For instance, maybe you no longer wanted to show the middle initial.
Console.WriteLine("The persons name is {0} {1}. {2}", person.FirstName, person.MiddleInitial, person.LastName);
}
There's a lot more to object oriented programming, but this was just a very high-level example of one of the things you can do. OOP is all about re-usability and is one of the great things about it. This was C# code (and useable), but you can do the same thing in any OOP language. The syntax and the class will be different, but the concept and goal would be the same. I hope that kind of helps you understand.
EDIT: I am sad... I formatted and spaced that code out perfectly. Damn you GB, stripping out my spaces! Get a damn code block in here!
Log in to comment