Hi
I'm pretty new to developing (started with Game Maker last year, Unity with JS this year and C# with XNA last week sometime) and I was just wondering, if I made a game would it be easier to give each object its own class then set their own functions in those classes then call them in the main class, or would this cause problems later on down the line?
Multiple classes question, yay or nay
The exact answer to this question depends on what you want to do and should become clearer as you become more familiar with object-oriented programming.
Generally, 10,000 foot view: you can think of classes as blueprints for objects, and objects as concrete instances of classes. You will run into situations where, from some classes you only make one or two objects because you do not need more (example: ItemFactory), and from some other classes you make many thousands of objects (example: Item).
You do not generally want to call into every single object from the same main method, instead you create some objects and call into them, and they might have some other objects in their variables and they will work on those, and those objects might be composed of other objects who they can call as needed, etc, etc.
I think the best thing you can do right now, if you want to stick to C# and XNA (which is a good choice for a game programming language and platform IMHO), is read a book about general object oriented programming written specifically for C#. Things will then very quickly become much clearer.
The exact answer to this question depends on what you want to do and should become clearer as you become more familiar with object-oriented programming.
Generally, 10,000 foot view: you can think of classes as blueprints for objects, and objects as concrete instances of classes. You will run into situations where, from some classes you only make one or two objects because you do not need more (example: ItemFactory), and from some other classes you make many thousands of objects (example: Item).
You do not generally want to call into every single object from the same main method, instead you create some objects and call into them, and they might have some other objects in their variables and they will work on those, and those objects might be composed of other objects who they can call as needed, etc, etc.
I think the best thing you can do right now, if you want to stick to C# and XNA (which is a good choice for a game programming language and platform IMHO), is read a book about general object oriented programming written specifically for C#. Things will then very quickly become much clearer.
Thanks man! Have you got any recommendations on good books to study with?
I'm more of a Java guy and not that closely familiar with C#. I have not read any C# books but I think the C# Yellow Book might be worth a look to start with. It's a university level text, it's supposedly written for people with no programming experience, the latest update was just last year, and you can't argue with the fact that it's free
Thanks I'll go grab it now, can't believe I didn't come here sooner, could have been a lot better by now
I read the yellow book it was ok as an introduction (although I read it to get myself up to speed with C# and already knew C and C++). Bloke who wrote it thinks himself hilarious though, I bet he wears "groovy" ties ;)
For a game like pong you need a paddle and ball class. The behavior of these "objects" is programmed in these classes. When a player caims a paddle it will give control for it otherwise it takes your ai. When you need multiple balls you just create another object from the ball class.
Fot each object in the real world you would create a class. Take a car for example. The car would be a class it could be very practical to create a class for the wheels too since you have a lot of different wheels and it could hold things like wearing and presure too. The car class should ave access to the wheel class.
Using many classes gives you a lot more control over your program. If there is a problem with a certain part it is easy to look up.