Aller au contenu principal

Magic Perfect Assistant

06/10/2013

It has been a while since I have worked on this application. To be honest, I was blocked by a very stupid issue about ListView. Meanwhile, I did not play to Magic a lot. However, this spring Google announced Android Studio and I wanted to test this new IDE dedicated to Android. I have started to look into my issue about ListView which was a very stupid mistake and then I was able to let my imagination improve this application. In my opinion, I have reached my goal and even more! It is truly an assistant.

Before I start the programming I wanted to oblige myself with a limit: I had one month to improve the application and see the result.

So now the month is over, and it is time to summarise what’s new!

SQL

The first part I wanted to do again, was the database. And the new one has nothing to do with the previous version. This means I had to rewrite a lot of code to let the application compile, run and works again. Here is the database schema:

The database schema

The database schema

  • Player: contains all the players of the application with a unique name and a colour.
  • Record details: represents a game with the date, if it is finished and the winner’s ID (foreign key of the Player’s table).
  • Record details player: represents a player of a game. That’s why it holds a player’s ID and the record_details’ ID. Moreover you can see an ID to the Deck’s table and all the counters required (life, cards, poison).
  • Deck: should represent a specific deck chosen for the game. At this time, this is not implemented but this table lets implement this feature in the future without upgrading the database.
  • Marker: represents a marker created during the game by a player (the owner_id). It contains a name, the number of marker and its type (0 for an artefact or a planeswalker, 1 for a creature). If it is a creature, you have the number of endurance markers (nb_marker_dfs) and either if the marker is engaged or not.

Layouts

Now it is time to work on the layouts. And once again, everything was refreshed. The first thing we can notice is the abandon of tabs for thinner title page indicator. It takes less space and I find this a little more modern, but this is only my opinion. Also, you have full control on the customisation and you can change the colour, the position, the size and the shape of the indicator, the titles, the background, etc…

Second, you would notice this help button at the top of each page: it shows a message to understand how works each panel.

A clip on the help button gives some information about the current panel.

A clip on the help button gives some information about the current panel.

Finally, all of my lists are animated when a new item is added. The game list uses alpha while the marker list uses a bottom-right transition.

Select players

This is where all starts and so, I have decided to show the Magic’s logo instead of the EditText to create a new player. Indeed, you need to click on the + button at the top to open a simple dialog with an EditText to let you create a new player.

It is simple to add a new player

It is simple to add a new player

The name has to be correct

The name must be correct

The player is unique

The player is unique

Fortunately, if you make a mistake, you can edit or delete a player by long clicking on its name.

By long clicking on a player these two options appear

By long clicking on a player these two options appear

Edit option:

Just like if you added a new player

Just like if you added a new player

Delete option (with its confirmation dialog):

You have to be sure before deleting everything

You have to be sure before deleting everything

Finally, there is two coloured squares on the right of the spinners. They let you choose a colour for the player selected. This is a convenient way to quickly distinguish the players visually. A simple tap on one of the square will show you the colours’ dialog:

Player JORIS is red, player JULIE is green

Player JORIS is red, player JULIE is green

It just take few seconds to choose another colour (from green to blue here)

It just take few seconds to choose another colour

Now JULIE is blue

Now JULIE is blue

Select game

Sometimes, you do not have the time to finish a game and this is frustrating. This came to an end! When you exit the application, if the game is not finished, it is automatically recorded in the database to let you continue it later. The list displays the date you exited the game, the players with their respective colours and the current score. Of course, it is possible to remove a recorded game by simply swiping over it. The refresh button at the top forces the list to refresh (the CursorAdapter swaps its cursor). If you click on a game you can continue it.

We have one game not yet finished

We have one game not yet finished

A swype allows to delete the game and you have 3 seconds to change your mind

Swype to delete a game and you have 3s to change your mind

Or you can continue it

Or just tap on the game in the list to continue it

Game

This is where you play! The two players are displayed with their colours and you can see all the counters. This is very simple to use. Before you start to play, you can open the menu to discover a “Random player” option which let the application choose the first player to play for you. If the life or cards counter reach 0, the game is finished. Same case if the poison counter reaches the limit. Once the game is finished, the counters are reset and you can start over a new game.

Click on "Random player"

Click on « Random player »…

to let the application decide who can start to play

… to know who starts

Once the game is finished

Once the game is finished…

All the counters are reset

… all the counters are reset

To add some colour to the dialogs, I have written my own “SimpleDialog” with its own interface “OnClickListener”. You can choose if the dialog has a negative button, the behaviour of each button through the interface and the message to display. Because I wanted to put the player’s colour in the message, I have decided to parameterize the message passed to the dialog. First, I put the message I want to display and place a “?” where I want to insert a special message. Then, I call a method from the dialog which takes 3 arguments: index, message and colour. The dialog adds in a map the message and the colour and uses the index as a key. When I parse the main message, I look for any question mark. Each time I find a question mark, its order (the first one is 0, then 1, 2, 3, etc…) is used to select the correct message in the map. This way, I can also display a question mark anywhere in the text. A “SpannableStringBuilder” is used to display the entire message.

Marker

While you are playing, you may need some markers. You can use the traditional paper with a pen, put some coins on your cards or some other objects, or simply swipe the screen to reach the marker panel!

There, tap on the + button at the top to open up the dialog.

All the information required to create a new marker

All the information required to create a new marker

First, you have to enter a name (it is not required to be unique), then the owner, its type and the number of markers. The second “NumberPicker” is only displayed if it is a creature.

When you click the “OK” button, the marker is added to the list:

When the marker is closed you can see its name with its owner's colour and if it is engaged or not

When the marker is closed you can see its name with its owner’s colour and if it is engaged or not

Once opened, you can alter the counters, edit or delete the marker

Once opened, you can alter the counters, edit or delete the marker

Each item in the list is expandable. The title view shows the name of the name with its owner’s colour and a button to engage the marker. If you click on a blank space of the marker, the details appear and you can alter the counters (the second one is only displayed because it is a creature) and you have two buttons to edit or remove the marker. The edit button will open the same dialog as the + button with the current values.

Chronicle

Each time a game is finished, it is listed here. First you will see an overall score which is the number of victories. Below is the list of all the games played between the two players, order by date in descending order and grouped by month + year. As you can see, there is a header in the list to display the month and the year, this is the same behaviour than the contact application. Also, the winner has its name in green while the looser is red.

The list is grouped by date

The list is grouped by date

Settings

Finally, you can modify a bit the behaviour of the application. If these settings, you can set the initial life and cards numbers when you start a game, the limit of the poison counter and if you want to display or not the cards and poison counters.

Credits

StickyListHeader library: https://github.com/emilsjolander/StickyListHeaders
ListViewAnimations library: https://github.com/nhaarman/ListViewAnimations

Laissez un commentaire

Laisser un commentaire