CISC124 : Using and creating classes - IT Assignment Help

Download Solution Order New Solution
Assignment Task:

Task:

Submitting your work

Submit your work on onq by submitting the following files:

  • Dabble.java
  • Location.java
  • Board.java

DO NOT submit a zip file.

DO NOT submit the file .class files.

Marking

80% for correctness, 20% for programming style, both problems weighted equally.

Javadoc comments are included for you in this assignment.

Background information: Dabble

The word game Dabble is a word game that was designed fairly recently (2011) by George Weiss. The app version of the game was Kotaku’s gaming app of the day in 2012. A sample gameplay video can be viewed here.

The game Dabble is made up of five English words of lengths 2, 3, 4, 5, and 6 (these five words make up a solution for the puzzle). The letters of the all of the words are randomly scrambled together to produce five scrambled puzzle words of lengths 2, 3, 4, 5, and 6. For example, the five solution words:

it, you, here, batch, burner

might produce the five scrambled words:

un, uei, ytrc, bahrt, obrehe

A player attempts to unscramble the words by repeatedly exchanging a letter from one scrambled word with the letter in a second scrambled word.

The puzzle is solved when the player has formed five English words of lengths 2, 3, 4, 5, and 6 (not necessarily the same words as the original solution because there is often multiple solutions).

Background information: Sokoban

Sokoban is a Japanese puzzle video game created in 1981. The game is played on a grid where each each square is a floor or wall. There are n boxes arranged on the floor and n floor locations are marked as being storage locations.

The player can move to any grid location adjacent to the player’s current position in the left, right, up, and down directions according to the following rules:

  • if the adjacent location is unoccupied (no wall or box) then the player can move to that location
  • if the adjacent location contains a box and there is an unoccupied location on the other side of the box then the player can move to that location and the box is pushed in the direction that the player is moving in
  • if the adjacent location contains a box and if the location on the other side of the box is occupied (by another box or a wall) then the player cannot move to that location (and the box does not move either)

The player’s goal is to push boxes around on the floor so that each box ends up on a storage location.

Sokoban GIF

Question 1

You are given the class DabbleGUI that implements a simple graphical user interface for the game Dabble. Click the image below to watch a short video of the completed assignment problem:

 

Begin by reviewing the Map notebook. You need to understand how to use a Map to solve this problem.

Review the documentation for the class dict.Dictionary. The Dictionary class is already implemented for you, and you will need to use it in this question.

Review the documentation for the class dabble.Dabble. This is the class that represents a game of Dabble, and it is the class that you need to complete. The documentation contains many clues about how to implement the class.

Edit the class Dabble.java. Review the fields used to implement the class. Then review the first constructor in the class that is already implemented for you to see what the two Map fields represent. You can use this first constructor for debugging and testing purposes.

Next, complete the toString method. Use the main method to test that your toString method works with a Dabble object constructed using the first constructor. NEVERMIND: The assignment gives you a working version of toString.

One of the two constructors that you need to implement starts with:

public Dabble(String... words)

The syntax String... means that the caller can provide a comma separated sequence of strings (0 or more strings) or an array of strings. Inside the constructor, words is treated as an array. For example, to test if there are the correct number of strings in words you can write something like:

public Dabble(String... words) {

    if (words.length != Dabble.NUMBER_OF_WORDS) {

        throw new IllegalArgumentException("expected 5 words, got " + Arrays.toString(words));

    }

    // now test if each string in words has the correct length

 

}

The no-argument constructor requires you to pick words at random from the dictionary (i.e., the constructor should pick random words of length 2, 3, 4, 5, and 6). The dictionary has a method that returns a list of all of the words in the dictionary having a specified length; to pick a random word from such a list, create a random number generator object and ask the generator for a random integer between 0 and the length of the dictionary. For example, to get a random word of length 3 you could use the following:

// the random number generator

Random rng = new Random();

int len = 3;

// get all words of length 3

List<String> t = Dabble.DICT.getWordsByLength(len);

// get a random index for t

int index = rng.nextInt(t.size());

// get a random word from t

String word = t.get(index);

Next, implement either one of the remaining two constructors. A key problem that you need to solve when implementing the constructor is how to scramble the letters of the solution words to form the scrambled words. One solution is take all of the letters of the solution words (20 letters in total), put them into a list, randomly shuffle the list (use Collections.shuffle), and then form the scrambled words using the letters of the shuffled list. Because you have to do this twice (once for each constructor), it would be a good idea to create a private method that accomplishes the task.

Next, implement the third constructor.

Use the main method along with toString to test if your constructors work correctly.

Next, complete the isSolved method.

Finally, complete the exchange method. A key problem that you need to solve in this method is that strings are immutable, but this method needs to exchange a pair of letters in two strings. One solution is to use the StringBuilder class which represents a mutable string.

StringBuilder b = new StringBuilder(s);

will create a StringBuilder object having the characters in the string s. You can then use char c = b.charAt(i) to get the character at index ib.setCharAt(i, newChar) to set the character at index i to newChar, and b.toString() to get the string represented by the builder.

Instead of using a StringBuilder you could also use the string method substring to get the parts of the string that you want to keep and concatenate them together with the character that you want to replace.

Use the main method along with toString to test if your exchange method work correctly.

Once you are done, you can run the DabbleGUI class to play the completed game.

Question 2

You are given the class SokobanGUI that implements a simple graphical user interface for the game Sokoban. Click the image below to watch a short video of the completed assignment problem:

 

This problem involves several classes:

  • Location: a class that represents a grid location (x,y) where x and y are integer coordinates. The positive x direction points to the right, and the positive y direction points down.
  • Wall: a class that represents a wall square
    • already implemented for you
  • Storage: a class that represents a storage location square
    • already implemented for you
  • Box: a class that represents a box
    • already implemented for you
  • Player: a class that represents the player
    • already implemented for you
  • Board: a class that represents a game of Sokoban; it manages all of the wall, storage, box, and player objects

Begin by reviewing the documentation for the class Location. It is very similar to the Point2 class from the course notebooks.

Complete the implementation of the class Location. You should probably add a main method to the class (or create one in a different class) to test your implementation.

Review the implementation of the classes WallStorageBox, and Player. You should pay attention to the methods that the classes provide. Also notice how similar the classes are to one another.

Edit the file Board.java. Begin by deciding what fields you will use to manage the walls, boxes, and storage sites, and add these fields to the class. You need some type of collection for each of the walls, boxes, and storage sites; any collection type can be made to work, but your choice of collection type will affect how other methods in the class are implemented. Arrays, lists, sets, and maps are all workable.

Next, implement the first constructor which creates a simple board. Use the main method and the provided toString method to test your constructor.

Next, implement the second constructor which reads in a board level from a file. The file is a plain-text file where:

  • space is an empty square
  • # is a wall
  • @ is the player
  • $ is a box
  • . is a storage location
  • + is the player on a storage location
  • * is a box on a storage location

The level shown in the animated GIF near the beginning of the assignment looks like:

  #####

###   #

#.@$  #

### $.#

#.##$ #

# # . ##

#$ *$$.#

#   .  #

########

There are eight different level files included in the project in the sokoban package directory.

The number of rows in the file is the height of the board. The widest row is the width of the board. The upper-left corner is the location (0,0) and the bottom-right corner is (width−1,height−1).

To implement the second constructor, initialize your fields in the constructor then call the method readLevel. The first two lines of readLevel opens the level file and reads the contents into a list named level. The size of the list is equal to the height of the board. The longest string in the list defines the width of the board.

You need to complete the implementation of readLevel by parsing the strings in the list level to compute the locations of the wall, box, storage, and player objects. Much of the implementation has been done for you; you need to fill the bodies of the if statements.

Use the main method and the provided toString method to test your constructor.

Next, implement the remaining methods in the order that they appear in the class. Depending on what collection type you chose to store the walls, boxes, and storage sites, you may find yourself writing a loop or two for every method.

When your class is complete, run the class SokobanGUI to play a game of Sokoban.

 

This CISC124 - IT Assignment has been solved by our IT Experts at My Uni Papers. Our Assignment Writing Experts are efficient to provide a fresh solution to this question. We are serving more than 10000+Students in Australia, UK & US by helping them to score HD in their academics. Our Experts are well trained to follow all marking rubrics & referencing style.

Be it a used or new solution, the quality of the work submitted by our assignment Experts remains unhampered. You may continue to expect the same or even better quality with the used and new assignment solution files respectively. There’s one thing to be noticed that you could choose one between the two and acquire an HD either way. You could choose a new assignment solution file to get yourself an exclusive, plagiarism (with free Turnitin file), expert quality assignment or order an old solution file that was considered worthy of the highest distinction.

Get It Done! Today

Country
Applicable Time Zone is AEST [Sydney, NSW] (GMT+11)
+

Every Assignment. Every Solution. Instantly. Deadline Ahead? Grab Your Sample Now.