Вы находитесь на странице: 1из 8

CST338 Final Project

Michael Loeser

Lucky Dice Roller (Android Application)


Problem Description:
I sometimes play board and roleplaying games that require various types of dice rolls. I tend to
lose my dice often, hate carrying them when I am going to play somewhere outside my home,
and through talking and other distractions, commonly forget what my rolls are, bringing looks
of distrust from whoever is running the game.

Solution? Create an Android application to do the work for me!

Requirements:
Write an android application in Java to handle rolling dice using a random generator.

The application must support the following functionality:


- Allow for rolling common dice types (20 sided, 12 sided, 8 sided, 6 sided, 4 sided)
- The application must allow the user to select the sides, then roll
- The application must stay within the boundaries of the selected dice sides (1 – total
sides)
- The application must use a non-weighted random generator to ensure as random of
results as possible
- The application must store the history of rolls, including the selected dice type and
result
- The application must use separate activity screens in the mobile applications for
displaying and supporting the different functions
o Roll the dice (default view)
o Select the dice type
o Show the roll history
- The application will use one of the standard navigation elements supported by Android
o Slide-out drawer (preferred)
o Bottom buttons
o Top buttons
o Fixed tabs

Technical requirements:
- The application must have its functionality written in Java
- The application must use a controller that encapsulates the bulk of the roll and roll
management functionality to allow for easy porting to other mobile OSs
- The application must use the android native navigation systems and display objects
- The Android native UI elements must use the functionality exposed by the controller
class and should handle only the display code and event management
- The application must pass the controller object between the views to ensure selections
for the dice type and the history of rolls can be maintained

Result:

I created a fully working application in Android Studio that supported my needs above. I took a
couple of short-cuts and didn’t add much for graphics to the application, which leads to a very
stark UI, but the functionality is all here.

The user is able to open the app and is brought into the roll screen by default. The default dice
side selection is 20 sided. The user is able to immediately start rolling by pushing the “Let’s
Roll!” button on this activity screen.

App Navigation:

A standard Android hamburger style menu icon is displayed at the top of the application. The
user selects this to expand the navigation drawer, giving access to all functionality of the
application. Only 3 activities are available. The Roll screen, the Dice Sides selection screen, and
the History screen, which is used to display all rolls made in this session. A standard Android
dice vector graphic and “home”, “setup”, and “item selection” icons are displayed in the nav
drawer to make a bit better display.
Selection of any of the activities in the menu will repopulate the content area on the underlying
screen with that view (standard Android Fragment display). The controller object is passed
from the main activity, which contains object instances, the controlling code for the navigation,
and the display frame used for the display pages, using a Bundle object. All classes referenced
by the Controller class, as well as the controller itself, must be Serializable to support this. The
user is then able to interact with that element.

Vector graphics from the standard library were used for the navigation slide-out panel and for
an application image at the top of the Navigation Drawer.

Images of the Roll screen:

Each click of the “Let’s Roll!” button calls a method in the controller to retrieve a new dice roll
value. The code validates to make sure the rules for the selected dice sides were met, then the
controller puts the new result in the history. A RollHistory object containing an ArrayList of Roll
objects was created to keep track of the history and keep the values in order.

A large display of the result is updated at the end of each roll process.

The current dice sides selection is also displayed on this view to let the user know what they are
currently rolling.
Image of the Dice Side selection screen:

This screen takes the user selection, updates the display to show the click, then records the
value of the selected user dice sides selection in the controller.

When the user navigates away from this page the main panel code ensures that the updated
controller is put into a Bundle and passed to the new view fragment.
Image of the History screen:

The history is a simple display containing only the page heading and a scrolling textbox showing
the list of rolls made within the current session. When the application is closed or restarted the
history will be cleared. All elements in this history are stored in a RollHistory object in the
Controller. The page retrieves the ArrayList of Roll objects from the RollHistory and loops
through them, printing the roll result and dice type in each line.

The order of the items in the ArrayList cannot be changed, ensuring that the display shows the
order in which the rolls were awarded.
List of Classes and Related Files in IDE:
UML Diagram:

Challenges:

The relative layouts and styling for the Android UI elements is difficult to work through. Many
parameters are available and a deep understanding of these params and their use is necessary.
I feel I will get better at this over time.

Though the tools available to help with the navigation menus is pretty good, getting the
navigation to work properly is difficult. Each click of an object in the drawer or any nav area
(bottom, top, fixed) using the standard controls must be handled as an event. All of the
plumbing necessary to retrieve an object of the view, populate its necessary data values, and
display in the content window must be coded. I was surprised at how complex this was to
manage as there are other Google created libraries for the web, such as Angular, which do a lot
more of this work for you.
Passing data from view to view using the Bundle object is inelegant but works well. This object
works as a property bag, which can have any serializable element added to the collection. The
methods for creating the view fragment allow for this Bundle to be passed to the constructor.
The fragment is then able to receive the bundle object when executing its OnCreate event
handler.

Further Enhancements:

I plan to continue work on the app to do some additional clean-up to the UIs as I figure out how
to position and expand the elements in the panels properly.

The app will also have its text value display changed to showing images as soon as I can find a
free library of dice images for all of the types I need.

I would like to research how a local data store can be created and used, so may enhance to
store the history between sessions. This would also require giving the user the ability to clear
the history.

Lastly, I’d like to clean up the navigation panel and do more research into how other UI
elements can be placed in the navigation drawer and managed. The drawer works just like any
other view, so there are a few things to learn there.

Вам также может понравиться