I want to develop an Android 2D Game, with a playing field full of rectangles and circles.
The rectangles and circles will be displaying objects, consisting of numbers, that have to be compared at some point.
Furthermore, all the objects (rect and circle) need to be dragable. I want to drag one object to another position, and then the surrounding objects-values should be compared with the value in the dragged object.
What I have so far is one abstract base class, and two sub classes, that represent the objects displayed in the rectangles and circles.
Furthermore the base class extends View, so that I can override the onDraw method for each of the two subclasses. Now I draw a rectangle of the one object, and a circle for the other object, furthermore i draw text containing the numbers of each object.
My question is, am I on the correct path concerning the development of an application like this, or would there be a better approach?
Thank you very much in advance.
Regarding your class-hierarchy I would say you are on the correct path. That is assuming that the base-class has implemented the drag-mechanism. Also your base class should define the method for comparing two objects, so that the sub-classes have it as well. The place for actual logic of object comparison depends on the algorithm. You can either let the parent class compare the objects, but that only works if you only need members of the base-class and the actual object types for the comparison. If you need anything specific to the distinct sub-classes, you would need to override the comparison method in each sub-class.
What you also need is a mechanism to find the neighbouring objects. This could be done with a simple coordinate-check (if you can drag around freely) on a List of all game objects, or with the base-class containing references to all adjacent objects that is updated whenever a piece is dragged around (if it is more like a jigsaw puzzle game).
However, I would strongly recommend using OpenGL for any complex game. Unfortunately, I only hava a good tutorial in German, but I’m sure there are many English tutorials available also.
If you have any more detailed questions let me know.