Class hierarchy/relationship issues

Hello,

I am in the process of making a game, and generally have a good concept of what I want to do but I always think there is a better way to program it, and end up scrapping everything and starting again!

The aim is to have the game on multiple platforms, and that controls for each action are user selected (from a selection) and that those inputs would also be associated with the appropriate game object.

What I am struggling with is how to do this…I have created a class called “inputmethod” which has a member function to setInput() which I imagined was going to then set an enum to determine what was pressed.

I also have an object class lets say its called “Shape”, and there are 5 child classes of shape called “Circle, Square, Triangle, Diamond, Cross”.

What I want to do on screen is have a selection screen come up with all 5 shapes, when selected I want an instance of that shape created and inputbuttons to be assigned to that class based on how it was selected.

I think an enum is best for the assignment, so if(input.getkeydown(“F1”){circle.assigninput(enum.whateveraction)}

which means I would declare the enum in the “inputmethod” class I think!

I seem to delay myself a lot due to wanting to have the perfect code but I don’t want to cause myself a lot of rework down the line, and this is my first game with unity.

My main problem is knowing what needs a class and what doesn’t, I don’t want to create a class for the sake of it, but I don’t want my code to be messy and all in one class either.

If anyone can make any sense out of what I was trying to say then input would be good! (no pun intended!)

I think you’re worrying too much. You’ll always have a clearer idea of what code you want to write after you’ve written it once or twice. There’s no harm in rewriting parts of your project — over time, you’ll do this less because you’ll be better at anticipating problems, but there’s really no shortcut for getting that experience the fun way (i.e. by just doing it).

So I’d say, get in there and write something; then modify it until you have something that works; then consider whether you’ve done it the cleanest way you can think of, or whether (now that you’ve done it once) you see a better way to do it. Repeat until satisfied, then move on!

Try creating a pen and paper prototype. This will not only help you save time but it will also help you recognize potential issues. For example, let’s say I wanted to figure out how to move a shape, I would start with:

Move shape

  • Get input
  • Apply input to shape

As you can see the idea is there but I don’t know how to implement it. So, I break things down.

Move shape

  • Get input from mouse,
    If mouse is being moved, get change in mouse position
  • Apply mouse change to shape position

And I just keep doing that until I have a working concept in paper.