So for a school assignment, we had to create some kind of game with at least two self-defined classes while using object-oriented programming. However, I’m finding it quite hard to implement this OOP way of thinking. The game I created is just a complete copy of the Flappy Birds game.
The problem is, that i didn’t really find use for classes since i could just write all the code on the main page. I just got some feedback for the teacher and she said my code was very disorganized and that i needed an extra class to fulfill requirements.
Can anybody give me some tips or help me with how to organize my code and maybe come up with some ideas on what my two classes could be?
OOP is basically an approach of how to organize code as objects.
Each object requires variables to describe its characteristics & current state.
Those variables become fields (a.K.a. properties) of the class which describes that object.
Then we write functions which deal w/ those field variables.
Those functions become methods of that object’s class.
Here’s a simple game that got classes for the player (Beaver), the grass animation (Grass), the player’s objective (Stick) and 1 more to save how many sticks the player caught (Score): sketchpad
I love the title to this discussion, “Thinking Object Oriented” because it says it all.
OO requires you to identify the entities (classes) that make up your application before you start writing source code. To retrofit classes into a procedural program is very messy and will probably involve you re-writing most of the original code.
I assume you have been taught the basics of classes and objects so I am not going to rehash it here but in the case of a Flappy Birds type program there are two obvious entities that could be represented as classes