(Noob) Why I can't use only Game1 class to develop my game?

I’m developing a scrolling tank battle simulator with monogame in c#. Why I can’t use only Game1 class to develop my game and what happens if I do that?

You should be able to. Especially for a small game - it should be fine.

It will get very messy very fast. I recommend trying to use just the Game1 class for everything, it’s a very good learning experience on why you shouldn’t use the Game1 class for everything.

You will see why splitting things up into classes actually simplifies things.

3 Likes

You can do this if you don’t mind if the code is very complex and difficult to read after a while. An object-oriented language will not prevent you from writing your code in the traditional way. You’ll only soon realize how much easier the whole thing is when you group it into classes. But in the very first step, I think that’s how everyone starts programming.

1 Like

For example in web programming you can put the styles and javascript in the html file and it will work fine. But most people move them out into separate files for readability, easy maintenance and reusability.

The scope of this question has little to do with monogame and everything to do with good coding practices.

You can do this. If you’re new to programming, you probably should make a very simple first game. But for experienced programmers on real projects of all kinds, not just games, there’s huge advantage in making each file represent one core idea. If you don’t, you run into certain kinds of problems.

Imagine you had a nice, small 600 line game. And you realized how you wanted to update the tank controls to be more smooth, it’s a lot easier to open a 50 line file called “tank.cs” and find the right spot than scroll through everything to find the part where it says “if(control.x>0) tankspriteX+=10”

True object oriented programming is not really a novice skill though. So if you’re starting out, one file won’t hurt you.

Thanks :slight_smile: I think i will use more classes for my game.