Jump to content

  • Log In with Google      Sign In   
  • Create Account

Multiple classes question, yay or nay


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 BlackHoleStorm   Members   -  Reputation: 102

Like
0Likes
Like

Posted 03 September 2013 - 05:53 PM

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?



Sponsor:

#2 stanirya   Members   -  Reputation: 771

Like
0Likes
Like

Posted 03 September 2013 - 06:14 PM

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.



#3 BlackHoleStorm   Members   -  Reputation: 102

Like
0Likes
Like

Posted 03 September 2013 - 06:29 PM

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?



#4 stanirya   Members   -  Reputation: 771

Like
0Likes
Like

Posted 03 September 2013 - 06:45 PM

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


Edited by stanirya, 03 September 2013 - 06:45 PM.


#5 BlackHoleStorm   Members   -  Reputation: 102

Like
0Likes
Like

Posted 03 September 2013 - 06:57 PM

Thanks I'll go grab it now, can't believe I didn't come here sooner, could have been a lot better by now laugh.png



#6 stanirya   Members   -  Reputation: 771

Like
0Likes
Like

Posted 03 September 2013 - 07:04 PM

You're welcome. Good luck!



#7 Paradigm Shifter   Crossbones+   -  Reputation: 5434

Like
0Likes
Like

Posted 03 September 2013 - 07:18 PM

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 ;)


"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

#8 menyo   Members   -  Reputation: 494

Like
0Likes
Like

Posted 06 September 2013 - 06:48 AM

Besides" yes you should create a class for each object" I can hand a more practical answer.

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.

Current Project: TechnoFlux read all about it on my

DEV BLOG





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS