ITECH3229 – Mobile Device Programming (2018) CRICOS Provider No. 00103D Page 1 of 15 Assignment 2 – Game 15 Due Date: 11 pm, Sunday of Week 11 This assignment will test your Android development skills...

1 answer below »
Mobile device programming


ITECH3229 – Mobile Device Programming (2018) CRICOS Provider No. 00103D Page 1 of 15 Assignment 2 – Game 15 Due Date: 11 pm, Sunday of Week 11 This assignment will test your Android development skills and is worth 20% (Type A) of your overall course mark. Android Development This assignment requires you to develop a simple Android application which uses a number of Activities which are related through the use of Intents. To write the application you will need to use the Android Studio Integrated Development Environment (IDE). Your application must perform all tasks listed in this document, and be capable of running on any Android device with a minimum API 21: Android 5.0 (Lollipop). Your application should be created to display correctly on an emulated Nexus 4 (4.7" screen, 768x1280 pixels in portrait orientation) - however, by using sizes specified in "density independent pixels" (dp) the application should also be able to display correctly on any Android device with any sized screen and resolution. Do not add any additional activities or features that are not outlined by the specifications to follow. You will not be marked higher for additional functionality, instead you will be penalized for not matching the program specifications! Plagiarism Policy The Federation University policy on plagiarism can be found at the following location: http://policy.federation.edu.au/university/student_plagiarism/ch01.php I highly recommend that you familiarise yourself with what is and what is not considered plagiarism, but I'll summarise the key aspects below: • Do NOT share code with fellow students. I mean it. These are individual assignments, not group projects. If the same code is found in multiple students’ projects, you’ll be called in for a chat and risk getting zero for the assignment and having a plagiarism flag put on your record. • You may, and are in fact encouraged to, discuss the project with your fellow students. The goal being that you understand how to create good, high-quality Android applications – and that understanding then flows into the exams where you'll be asked questions on Android application development. Just don't share projects/code – code it yourself, learn from your mistakes, and become a great developer. http://policy.federation.edu.au/university/student_plagiarism/ch01.php ITECH3229 – Mobile Device Programming (2018) CRICOS Provider No. 00103D Page 2 of 15 Application Specification Project Settings Your Android application should have the following settings: Minimum SDK: API 21 Target / Compilation SDK: API 27 Project/Application Name: Game_15 For example, Game_15 12345678 Company URL: federation.edu.au ITECH3229 – Mobile Device Programming (2018) CRICOS Provider No. 00103D Page 3 of 15 0. Introduction The following information and images were taken from https://en.wikipedia.org/wiki/15_puzzle The Game of Fifteen, or 15-Puzzle is a sliding puzzle that consists of a frame of numbered square tiles in random order with one tile missing. The object of the puzzle is to place the tiles in order by making sliding moves that use the empty space. Fig1. Game of Fifteen Fig2. A Solved Puzzle Half of the starting positions for the n-puzzle are impossible to resolve, no matter how many moves are made. For example, the following puzzle is unsolvable: https://en.wikipedia.org/wiki/15_puzzle https://en.wikipedia.org/wiki/Sliding_puzzle ITECH3229 – Mobile Device Programming (2018) CRICOS Provider No. 00103D Page 4 of 15 Fig3. An Unsolvable Puzzle By the way (and this is not from Wikipedia), if the 15-Puzzle does not have a left-to-right solution (like in the Fig2), then it has a right-to-left solution, and vice versa. ITECH3229 – Mobile Device Programming (2018) CRICOS Provider No. 00103D Page 5 of 15 1. Application Description In this assignment, you are required to develop an android app that allows you to play The Game of Fifteen on a mobile device. (a) When the application starts, it should look similar to the following: (b) When you click the “START NEW GAME” button, a random puzzle will be generated (you will be provided with the method that generates a random puzzle): ITECH3229 – Mobile Device Programming (2018) CRICOS Provider No. 00103D Page 6 of 15 • The TextView at the top of the activity, tells you if the puzzle is solvable or not (you will be provided with the method that calculates solvability). • You can play the game by clicking on the cell adjacent to the empty cell to move it to the empty space. For example, if you click the cell labelled “9” in the figure above you will get the following: ITECH3229 – Mobile Device Programming (2018) CRICOS Provider No. 00103D Page 7 of 15 • Please note, that the TextView at the top of the app has changed and now shows the number of moves (clicks on the cells) made. • When you solve the puzzle, and in case your result (the number of moves made to solve the puzzle) is less than the previous record, the following CustomDialog appears on the screen: ITECH3229 – Mobile Device Programming (2018) CRICOS Provider No. 00103D Page 8 of 15 • If you want to save the result, enter your name and click SAVE RECORD button. Otherwise, click cancel. After saving the result you will get something like: ITECH3229 – Mobile Device Programming (2018) CRICOS Provider No. 00103D Page 9 of 15 • The Best Result should be saved permanently, use SharedPreferences for that. • To play another game click START NEW GAME button. ITECH3229 – Mobile Device Programming (2018) CRICOS Provider No. 00103D Page 10 of 15 • This time, as you can see, the puzzle is unsolvable. So you, probably, will want to start another game. • If someone else’s Best Result irritates you, click CLEAR BEST RESULT button. The record will be erased from the SharedPreferences, and you will get the following picture: ITECH3229 – Mobile Device Programming (2018) CRICOS Provider No. 00103D Page 11 of 15 • In this case, the next puzzle solution (yours) will be the best. ITECH3229 – Mobile Device Programming (2018) CRICOS Provider No. 00103D Page 12 of 15 2. Glass Model15 (4 marks) The game model should be presented in the class named “Model15”. It has two instance variables: • int [] cells – integer array representing the game board. You should initialise it as follows: int [] cells = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; Array element with the value 0, represents the empty cell, the rest represent game pieces with labels equal to their value. When you move a piece adjacent to the empty cell, corresponding array elements swap values. This is a linear representation of a 2-dimensional board, so, you need to figure out, which cells are neighbours. • int moves – represents the number of moves made in the game. At the beginning of a new game should be set to 0. And the methods: • public boolean moveCellAt(int i) – moves piece at index i to the empty cell, if they are neighbours, if they are not – nothing happens. Increases the value of variable moves by 1. Returns true if the resulting array configuration is a solution, i.e. the array is {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0}, and false otherwise. This is how you will know if the game finished or not. • shuffle – method that generates a random game (permutation of the array cells). The code is provided: public void shuffle() { Random random = new Random(); for (int i = 16; i > 1; i--) { int j = random.nextInt(i); swap(i - 1, j); } } • isSolvable – returns true if the game has a solution, false otherwise. The code is provided: public boolean isSolvable() { int[] temp = {cells[0], cells[1], cells[2], cells[3], cells[7], cells[6], cells[5], cells[4], cells[8], cells[9], cells[10], cells[11], cells[15], cells[14], cells[13], cells[12]}; ArrayList temp1 = new ArrayList(); for (int k = 0; k < 16;="" k++)="" {="" if="" (temp[k]="" !="0)" {="" temp1.add(temp[k]);="" }="" }="" int="" parity="0;" for="" (int="" i="0;" i="">< 15;="" i++)="" {="" for="" (int="" j="i" +="" 1;="" j="">< 15;="" j++)="" {="" if="" (temp1.get(i)=""> temp1.get(j)) { parity++; } } } if (parity % 2 == 1) { return true; } ITECH3229 – Mobile Device Programming (2018) CRICOS Provider No. 00103D Page 13 of 15 return false; } • private void swap(int i, int j) – a private method, that swaps values of elements of the array cells
Answered Same DayMay 10, 2020ITECH3229

Answer To: ITECH3229 – Mobile Device Programming (2018) CRICOS Provider No. 00103D Page 1 of 15 Assignment 2 –...

Snehil answered on May 16 2020
129 Votes
Game_15YOUR_STUDENT_ID_NUMBER/.gitignore
*.iml
.gradle
/local.properties
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
.DS_Store
/build
/captures
.externalNativeBuild
Game_15YOUR_STUDENT_ID_NUMBER/app/.gitignore
/build
Game_15YOUR_STUDENT_ID_NUMBER/app/build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "au.edu.federation.game_15"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Game_15YOUR_STUDENT_ID_NUMBER/app/proguard-rules.pro
# Add project specific ProGuard rules here.
# You can control the
set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Game_15YOUR_STUDENT_ID_NUMBER/app/src/androidTest/java/au/edu/federation/game_15/ExampleInstrumentedTest.java
Game_15YOUR_STUDENT_ID_NUMBER/app/src/androidTest/java/au/edu/federation/game_15/ExampleInstrumentedTest.java
package au.edu.federation.game_15;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
 * Instrumented test, which will execute on an Android device.
 *
 * @see Testing documentation
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    @Test
    public void useAppContext() {
        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getTargetContext();
        assertEquals("au.edu.federation.game_15", appContext.getPackageName());
    }
}
Game_15YOUR_STUDENT_ID_NUMBER/app/src/main/AndroidManifest.xml









Game_15YOUR_STUDENT_ID_NUMBER/app/src/main/java/au/edu/federation/game_15/MainActivity.java
Game_15YOUR_STUDENT_ID_NUMBER/app/src/main/java/au/edu/federation/game_15/MainActivity.java
package au.edu.federation.game_15;
import android.app.Dialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
    private Button clearResultButton;
    private Button newGameButton;
    private ArrayList
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here