Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

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 »
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
elated 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 co
ectly 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 co
ectly 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
e 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_ XXXXXXXXXX
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
andom 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 i
itates 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 a
ay 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};
A
ay 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, co
esponding
a
ay 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 a
ay configuration is a
solution, i.e. the a
ay 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 a
ay cells). The code is
provided:
public void shuffle() {
Random random = new Random();
for (int i = 16; i > 1; i--) {
XXXXXXXXXXint j = random.nextInt(i);
XXXXXXXXXXswap(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],
XXXXXXXXXXcells[7], cells[6], cells[5], cells[4],
XXXXXXXXXXcells[8], cells[9], cells[10], cells[11],
XXXXXXXXXXcells[15], cells[14], cells[13], cells[12]};
A
ayList temp1 = new A
ayList();
for (int k = 0; k < 16; k++) {
XXXXXXXXXXif (temp[k] != 0) {
XXXXXXXXXXtemp1.add(temp[k]);
}
}
int parity = 0;
for (int i = 0; i < 15; i++) {
XXXXXXXXXXfor (int j = i + 1; j < 15; j++) {
XXXXXXXXXXif (temp1.get(i) > temp1.get(j)) {
XXXXXXXXXXparity++;
}
}
}
if (parity % 2 == 1) {
XXXXXXXXXXreturn 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 a
ay cells
Answered Same Day May 10, 2020 ITECH3229

Solution

Snehil answered on May 16 2020
99 Votes
Game_15YOUR_STUDENT_ID_NUMBER/.gitignore
*.iml
.gradle
local.properties
.idea/li
aries
.idea/modules.xml
.idea/workspace.xml
.DS_Store
uild
captures
.externalNativeBuild
Game_15YOUR_STUDENT_ID_NUMBER/app/.gitignore
uild
Game_15YOUR_STUDENT_ID_NUMBER/app
uild.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 fo
# 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 d.android.com/tools/testing">Testing documentation
a
 *
@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.A
ayList;
public class MainActivity extends AppCompatActivity {
    private Button clearResultButton;
    private Button newGameButton;
    private A
ayList
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here