Justification
Wondered whether to write on Habr himself! about such an Android-craft. As a result, I decided that it would be interesting for anyone to read it, and who would not - leaf through it. And bad in the end no one will. I deliberately almost hid the entire post under the cat, so that those who are not interested in it even more thought that this post is not here.
I made the game a couple of weeks ago (I wrote it over 1 day off), but now I have free time to bring it to mind and put it in the Play Market.
The whole story is divided into a description of the game, a description of the implementation and a description of the nuances that are not directly related to the game.
1. The essence of the game

This is a logical puzzle, with the help of turning circles and shifting chips into an empty cell, you need to put the chips of the same color in one row. It is possible to choose a different number of colors and a different number of circles, the more - the more difficult. With the increasing complexity of the puzzle to be solved, the points multiplier increases. The final points depend on the difficulty of the puzzle and the number of moves made.
2. Some technical issues
2.1 Graphics
The game is implemented on pure Canvas, without the use of engines and even without the use of bitmap.
Architecturally, this is a CustomView, which contains a list of all the chips. It also contains a list of circles, each of which refers to those chips that are drawn on it. CustomView catches all click events and passes them down the hierarchy (circles and counters).
All drawing is rather banal, except perhaps for turning the circles - here we had to figure out the required angle of rotation through arctg.
And yet she turns!

2.2 Preservation
Saving the game as quickly as possible was implemented using the settings (such as the Prefferences). It is clear that it was possible to use the database or file cache, but since it was done, it was really faster. The solution without Google is written in minutes 5 from memory. That's the way it is:
Java codepublic class PrefsManager { private static final String PREFS_TAG = "prefs_tag"; public static void save(Context c, String tag, String val) { SharedPreferences p = c.getSharedPreferences(PREFS_TAG, Context.MODE_PRIVATE); Editor e = p.edit(); e.putString(tag, val); e.apply(); } public static String get(Context c, String tag, String defVal) { SharedPreferences p = c.getSharedPreferences(PREFS_TAG, Context.MODE_PRIVATE); return p.getString(tag, defVal); } public static void delete(Context c, String tag) { SharedPreferences p = c.getSharedPreferences(PREFS_TAG, Context.MODE_PRIVATE); Editor e = p.edit(); e.remove(tag); e.apply(); } }
2.3 Dialogue raising a rating
A little trick, really long used. When the application starts unnumbered, a dialog appears, displaying RatingBar (it represents 5 stars) and asking the user to rate the application. And then there are 2 options:
- The user chose 5 - we display a dialog with a request to repeat it in the Play Market.
- The user chose 4 or less - ask the user to write to the support email in which, in fact, the point.
The number of application launches is stored in the same Preferens for sending the user to the Market || Email is used simply by intent.
')
3. Interesting things
Since The implementation of the application itself is quite simple, I decided to use two new technologies:
Since the game did not consume the proper amount of man-hours, then it would be wrong to embed advertising in it. The same, naturally, applies to the paid version to an even greater extent. That is why I decided to look towards alternative types of monetization and found Playhaven. In addition to standard advertising, they offer to install the More games widget. The user, seeing this button, with high probability will not perceive it for advertising, and, therefore, the mood of all will remain wonderful.
The integration of this advertising affiliate program is generally very remarkable in terms of the amount of code, but I did not immediately find an example of this code, to be honest.
Here is an example of the display code. More Games Widget private void prepareMoreGamesRequest() { moreGamesRequest = new PHPublisherContentRequest(this, MORE_GAMES_PLACEMENT); moreGamesRequest.preload(); } findViewById(R.id.moreGames).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { moreGamesRequest.send(); prepareMoreGamesRequest(); } });
In general, everyone is happy with this platform, except that in terms of income, there is no way to evaluate it - the application from the very beginning turned out to be so low that only I and I, my whole family, installed it.
Scoreloop pleased me not so much. On the one hand, they provide a free server with a database. On the other - I would like to integrate something more ready, integrated. I will explain. Previously, I often watched applications with Scoreloop, which looked like this:

Those. This is a fairly standardized look. And there are still examples of the implementation of the Leaderboards Activity on the Internet. Just one intent challenge and there is a comprehensive record board in your application. But this Activity is not in the new SDK. As a result, you have to fence your own ListView, write queries, show ProgressBars, etc., etc. I don’t understand why it was done. But probably the Germans know better.
What else did not like in Scoreloop - in order to display a normal list of users with points scored and a position in the rating - 2 requests must be made. In one, get a list of users, and in the other get a Rank (position in the rating) for some one of the users. After I implemented Leaderboard in this way:

It became doubly unclear to me why it was to remove the finished Activity from the SDK. But ... the Germans know better.
PS
If someone else is interested in some other implementation details - ask. Not just the way I started it all.