Aller au contenu principal

Magic Perfect Assistant (WIP) – Android

04/02/2013

      Magic The Gathering is a cards game I really like. Unfortunately, it requests some things we do not always have with us: a paper and a pen. This could be frustrating to remember how much life each player have, how much markers all of these creatures have, etc… (this application received a big update. Read this article)

Since I always have my Galaxy Note 2 with me, I have searched on the Google Play Store an application for this game; And I have found one. However, well, since this application is as simple as a life counter, it was a kind of useless – or at least, not as useful as the application I was looking for. In this kind of cases, if you want something done, do it yourself!

First of all, it was the very first time I tried to use the Android SDK itself. I have started some other projects about mobile games programming with a friend, and we have tried some cross-platform development environments to target Android, iOS, Windows Phone, Windows, Linux, web, etc… (These projects were left for some reasons) So, there was an abstract layer for each platforms.
This time, it was the opportunity to use a specific SDK and learn the fundamentals of Android development. I admit, I thought it would be a lot easier, I never was comfortable with layouts.

Features

So let’s see the features of the application:

  • Life counter
  • Markers’ system
  • Games’ chronicle
  • Victories’ counter by player

The first version of the application was designed like a personal assistant: choose your opponent and keep a track of all games. But the point is, what if you are at least three players? Just like a private tournament with your friends. Each player has to take his phone? Only one phone has to be needed to play, and in order to do that, you have to select two players. This is no more a personal assistant.

Architecture

Here is the architecture: a SelectPlayersActivity is launched with its layout (relative) which owns two spinners to display the list of players available, and an editText to create new players. Each player is recorded in a database (SQLite) with its id (auto-incremented integer) and a unique name. When you have selected the two players, the game is launched with a TabsActivity. The two players are passed between activities by the Intent.
The TabsActivity creates and manages all the tabs of the application; these tabs are Android fragments with their own layouts:

  • Game Tab:

The life’s counters with some buttons to in/decrease the counters.
The name of each player.
If one counter reaches zero, they are reset and the results are recorded in the database.
(Poison counter, cards counter, etc…)

  • Markers Tab:

This fragment gives the ability to add a card with an editText.
Each time the number of markers changes, the players can use the buttons added with the card to increase or decrease the counter.
When the counter falls to zero, the card is removed.

  • Chronicle Tab:

This fragment is composed of multiple layouts. The first one is a relative layout to display the number of victories each player has against the other.
Then, you have a list layout (plus a scrollView) of all games played between these two players with the date.
Each row uses a layout to display the date and the score. The winner has its name in green and the loser, in red.

The general layout of the application is a work in progress since I prefer to concentrate myself on the code before.

Screenshot_2013-02-04-11-37-44 Screenshot_2013-02-04-11-39-19  2013-07-11-15-52-28 Screenshot_2013-07-11-15-54-00 Screenshot_2013-07-11-15-53-39 Screenshot_2013-07-11-15-53-44

Storage

All the records are kept in a database with three tables. The current game is stored in the Android SharedPreferences which can keep basic values with a key. So, if you decide to stop the game before the end, you could play later just from where you left it. And it works for all possible game (PLAYER1 against PLAYER2 will not erase the game PLAYER2 against PLAYER3).

The three tables are:

  • TablePlayers: _id integer primary key autoincrement, name text not null
  • TableSummary: _id integer primary key autoincrement, player1 integer foreign key, player2 integer foreign key, nbVictories1 integer not null, nbVictories2 integer not null
  • TableChronicle: _id integer primary key autoincrement, player1 integer foreign key, player2 integer foreign key, score1 integer not null, score2 integer not null, date text not null

Settings

Because everybody plays a game just like they want to, it is important to let them customize the rules. The settings menu permits to set the default life and poison values.
It is a placeholder for future ideas.

Ads Banner

The first purpose of adding an ads banner is for money. Of course, you’ll not gonna be rich with this kind of revenue especially with low download rate. So the reason why I have put one is the challenge. To be able to do it again and again whatever the project is. The main issue is to not disturb the users with the ad, and the banner is the smallest (and probably the one which earn the less money) way to display ads. Also, it drains some precious battery power so it is a good thing to not put hundreds of ads banner. Naturally I have chosen the place where the users will stay the most on: the game tab.

Conclusion

I have to admit, it was not an easy start. However, once the working of Android applications is well understood, it was a pleasure to play with. I have just scratched the possibilities for now but the complexity of this application will increase with embedded layouts and some other stuffs I would like to experiment, like the animations. The next step with Android will be a game. When? Well, when I will have enough time for this.

Laissez un commentaire

Laisser un commentaire