A mirror of my blog that I host. Mirroring it here just to provide an additional backup. Check out the real deal at http://www.justinandrewfincher.com/

Wednesday, March 28, 2012

Getting back into Android Programming: Dart Scorer

The other day I played a few rounds of darts at Corner Pocket and found myself really wishing that I had a dartboard of my own.  I recalled that we used to have one in the basement in Bristol, and I didn't think it was being used so I asked Mom and she said it was all mine. I get to pick it up next weekend, and I am pumped! Knowing that I will soon have access to throw a round of darts whenever I like, I thought it would be cool to go a little above and beyond the normal chalk or whiteboard scoreboard. I searched the Android Market (or Play store or whatever it is called now) and downloaded and tested no less than 5 apps made for dart scoring. Now I am not sure what is most popular in the dart throwing world, but apparently everyone plays 301 or some variant thereof.  Of the apps I tried, only 1 even claimed to score cricket (the game my friends and I always play) and it turned out to be pretty much non-functional.  I decided that the situation presented completely embodied one of the primary advantages of Android that I laud to those around me: at a cost of $0 I can write the app I need myself! Most of the time, apps I am looking for are either too complicated to really tackle or the apps available are close enough but not perfect. This time, there was a complete lack of any app providing the function that I needed AND it seemed like it would be a pretty simple app to put together. So I downloaded all the necessary development software (as I will point out again, at no cost) and tried to revive the Java programming portion of my brain. After programming almost solely in Python for the past couple of years, I was definitely a little rusty. Also, because I hacked it out starting yesterday, there are definitely some conventions I used that I am sure could be done way more efficiently and elegantly. Mayhaps I will continue to revise and improve, but first iteration was all about functioning! I got it to a place that I am pretty happy with and that seems to be functional and error free enough to serve my purpose.
[caption id="attachment_1172" align="aligncenter" width="187" caption="Let's get the game started!"][/caption] [caption id="attachment_1170" align="aligncenter" width="187" caption="MC is looking good"]MC is looking good[/caption] [caption id="attachment_1171" align="aligncenter" width="187" caption="And she takes the win!"][/caption]
So the first picture is basically the opening screen (no fanfare here). After you choose the number of players, you see a scoreboard similar to the one in picture 2. The names start out with default names, but when you tap on a name it brings up a dialog to change it. Then you just tap on the space where you would typically make your mark and it marks it! To keep it simple, I just used text so first mark is a slash, two is an X and the empty set symbol means that number is closed out. Tapping on a closed out number gives points to all other players who have not closed out that number. It has a one play history so a rogue finger poke can easily be undone, and it automatically checks to see if the last score marked resulted in someone winning the game (Picture 3). New game resets all the scores, but keeps the names. The only real issue that I am having so far is that the way I set things up in a TableLayout seems to give a little play in the row sizes.  So it will start out with a spacing that I like, then, for example, if player 1 and player 2 each mark a 20, the 20 row will tighten up and get a little shorter pulling everything below up with it.  I've tried giving more absolute dimensions for the rows, but that messes with the display and response to touch so I decided not to worry about it right now. I will call this my Beta Version 0.1 and hopefully it is something I can improve whenever I have some free moments (not that I see many of those in my near future). To do list for the future:
  • Fix formatting issue to keep scoreboard static
  • See if I can simplify some of the functions I put together
  • Increase history so that more than one play can be undone
  • Store and display statistics based on player name
  • Allow for other dart games


No comments:

Post a Comment