Skip to content

Help for Developers

SaskiaJacob edited this page Sep 10, 2018 · 6 revisions

On this page, you can find some background information about how this app is implemented.

Important classes

  • Element: This class extends the android.support.v7.widget.AppCompatButton class and represents a box on the game field. This element contains different features like the presented value (number) and the position of this value in the playing field (posX, posY). Because of the animation a distinction is made between the calculated value and the displayed value. Furthermore there are more features like the color of the box and the font size of the value.

  • GameState: This class represents the game status for the different modes of the game, which implements the java.io.Serializable. Because of this, the GameState can be saved via streams. The GameState contains the last numbers on the game field, as well as the previous game status, which can be reached with the undo button in the game. Furthermore there is a variable undo, which define, if it is possible to execute a undo.

  • Gestures: This class handels the recognition of the user input. Therefore a mesurement of the touch input is made. With this information an interpretation of the movement is executed to define in wich direction the user wants the boxes to move in the game field (left, right, up, down).

  • GameStatistics: The current statistics in each modes is defined in this class. It contains the highest reached number, the amount of swipes (total and for each direction), playing time, highest score and the amount of using the undo button. For saving this data in a file, the interface java.io.Serializable is implemented.

Activities

  • BaseActivity: This acitivity is a basic function in the SECUSO app. For example the menu navigation and the navigation bar are implemented in this class. All other activities extends this class.

  • BaseActivityWithoutNavBar: The same function are implemented as in the BaseActivity, but without the navigation bar.

  • MainActivity: The MainActivity is the activity from which the game in each modes is started. Therefore a ViewPager is used to depict pictures of the four modes. At the bottom of the activity there are two buttons, which start a new game (START NEW GAME) and continue the previous game (CONTINUE GAME). The CONTINUE GAME button is greyed out and is not selectable, if there is no previous played game available in this mode.

  • GameActivity: This activity contains the entire game and draws the game field depending on the selected mode and the screen size. Also the Intent influences, when a new game is generated or a previous game status is loaded. Therefore a two dimensional field named elements is filled with instances of the class Element depending on the selected mode (4x4, 5x5, 6x6, 7x7). The function of the two buttons restart and undo are also implemented. With the help of the class Gesture the user inputs are recognized and the corresponding method is retrieved. This method contains the important game logic for 2048. With loops the values of the elements will be added and the whole elements will be moved in the selected direction. After each move (only if something has been moved) a new element appears on the game field with the help of the method addNumber(). This new element is placed randomly on a free spot of the game field. If the activity is paused or stopped, the game status is saved in the GameState and the GameStatistics will be updated.

  • StatsActivity: The game statistics of the four modes are loaded and shown with a ViePager in this activity.

  • SettingsActivity: As the name suggests the settings for the app are located in this activity. Here you can change options like the color set of the game, activate or deactivate the animations and the screen locker.

  • SplashActivity: The goal of this activity is to start the tutorial in case the app is started for the first time. After that the app should show the MainActivity.

  • HelpActivity: The HelpActivity is a standard activity provided by all SECUSO apps. Here you can find some FAQs with an adequate answer.

  • AboutActivity: This activity shows the important information about the app. Information like the developers, the version and the superior project for which this app was implemented, are presented in this activity.

  • TutorialActivity: In this activity a ViewPager is filled with the four pages of the tutorial. The buttons at the bottom differ depending on the current position in the ViewPager.

Dependencies

  • Glide (see https://github.com/bumptech/glide): Image caching library. Used for loading a bitmap image inside the MainActivity, StatsActivity and TutorialActivity (This is done to prevent a drawing cache error as a result of a too large size.)
Clone this wiki locally