Assignment Supports Objectives

Value: 20%

Topics: Control flow, Arrays.

Objectives: This assignment supports objectives 1-5.

Graduate attributes: A1, B2 and B5.


The goal of Assignment 2 is to create a simple game using arrays called the L game. The following description of the rules of the game is from Wikipedia.


The L game is a two-player game played on a board of 4×4 squares. Each player has a 3×2 L-shaped piece, and there are two 1×1 neutral pieces (black discs in the diagram).


On each turn, a player must first move their L piece, and then may optionally move one of the neutral pieces. The game is won by leaving the opponent unable to move his L piece to a new position.

Pieces may not overlap or cover other pieces. On moving the L piece, it is picked up and then placed in empty squares anywhere on the board. It may be rotated or even flipped over in doing so; the only rule is that it must end in a different position from the position it started—thus covering at least one square it did not previously cover. To move a neutral piece, a player simply picks it up then places it in an empty square anywhere on the board.

You will implement this game by printing the board to System.out (as ASCII characters), and read moves from the user via (using a Scanner). Sample output will be given in the task descriptions below.

Minimum requirements

To receive any marks, your solution must meet the following minimum requirements:

  1. 1. You must regularly submit to PLATE while developing your solut You should definitely NOT suddenly submit a completely working solution on the due date without submitting your progress, because there will be no evidence that you developed your solution. Any student who submits a substantial solution without an equally substantial record of previous submissions during development will receive ZERO.
  1. 2. Individual tasks will not receive marks unless your solution?s output exactly matches the benchmark solution?s output that is shown when submitting to PLATE.
  1. 3. PLATE will require you to complete some tasks before continuing on to later ta Therefore, you will need to submit frequently to PLATE to see whether PLATE allows you to skip over the current task, or whether it forces you to complete the task before continuing.

Specification and Tasks

This section describes each piece of functionality you must implement, and the order in which they must be implemented. These tasks must be completed in the order listed Please read Section “Marking Scheme” for more details on how these tasks would be marked.

Task 1: Slide (50 marks)

While there are many ways to implement this game, in this assignment, the game should be conceived of as a set of 4 moving “slides”, each slide depicting a different game piece within a 4×4 area which is to be represented by a 2D array. For example, a slide representing the blue L piece in the above picture might be represented by the following array:


{ ‘ ‘,’ ‘,’ ‘,’ ‘ },

{ ‘ ‘,’o’,’ ‘,’ ‘ },

{ ‘ ‘,’o’,’ ‘,’ ‘ },

{ ‘ ‘,’o’,’o’,’ ‘ }


In this array, the colour blue is represented by the character „o?, and empty space is represented by the ASCII space character.

Each slide has the ability to be moved around, rotated or flipped (but for now we will just focus on moving). In this task, you need to define class Slide with the following structure:

public class Slide{

private char[][] cells;

public Slide() …

public Slide(char[][] cells) …

public void print() …

public void clear() …

public void project(Slide other) …

public void move(int row, int col) …


The first constructor should initialise field “cells” with a new blank 4×4 array. The second constructor should initialise field “cells” with the parameter cells.

The print() method should print each row of the cells on a separate line (row 0 at the top). Each cell in the same row should be printed with a space after each cell. Note that each cell in the array should be

accessed by cells[rowPosition][colPosition].

The clear() method should set each of the cells to an ASCII space character.

The project(other) method should take another slide as a parameter, and copy each non-space cell from this slide into the other slide (i.e. like a projector projecting slides onto a screen).

The move(row, col) method should shift the contents of the array vertically and horizontally so that the top-left visible corner of the piece is at cells[row][col].

Here is a simple test that you can try in the BlueJ code pad:

Slide slide = new Slide(new char[][] {

{ ‘x’,’x’,’ ‘,’ ‘ },

{ ‘x’,’x’,’ ‘,’ ‘ },

{ ‘ ‘,’ ‘,’ ‘,’ ‘ },

{ ‘ ‘,’ ‘,’ ‘,’ ‘ }



(You should now see the following output)

x x x x

Now type this in the code pad:

slide.move(2, 1);


(You should now see the following output)

x x x x

You can assume that the move() method is always given valid parameters such that the piece will never be moved outside of the 4×4 box.

Task 2: LGame (20 marks)

In this task, you will write the game program. The entry point to your program must be a class called LGame and this class must define a standard main() method. You should create 4 slides representing the 4 pieces arranged in the following relative positions using the following character symbols:

A i i o i o i

o o B

Each slide should contain only the characters representing one piece. The two neutral slides are

represented by the character symbols „A? and „B? while the two L-piece slides use the symbols „o? and „i?.

Create a 5th slide called “screen”. Since each of the 4 pieces are represented by 4 different slides, in order to print everything onto the screen, you should first clear the screen, project each of the 4 slides onto the screen, and then print the screen.

Your game should involve a loop where you read the next move from the player, and then perform the move, and then print the changed slides. The user should enter a move in the following format:

Move: o12

Here, the user types in a string with length 3 characters. The first character indicates which piece/slide the user wants to move. This can be „o? or „i? or „A? or „B? representing the symbols for each piece described above. The second and third characters represent the row and column position to move the piece respectively.

When your program is run via its main method, it should match the following input/output format:

A i i o i o i

o o B Move: o10

A i i o   i o   i

o o   B Move: A11

i i o A i o   i

o o   B

Move: B00

B i i o A i

o   i o o

Move: i12


o A i i

o     i

o o   i Move: end Game over

Your program does not need to detect a winning position. You simply end the program when the user

types “end”, and it will be the user?s responsibility to follow the game rules.

Task 3: Improvements (30 marks)

Improve your program in the following ways:

  • If the user attempts to move a piece to a position on the 4×4 board that is already occupied, print

“Invalid move” and do not perform the move.

  • If the user inputs a move with a 4th character, the 4th character indicates whether the piece should be flipped over from left to right. For example, the move “i001” means flip the L-piece with symbol „i? and move it to row 0 and column 0. The move “i000” does no flip and has the same effect as “i00”.
  • If the user inputs a move with a 5th character, the 5th character is interpreted as an amount to rotate the piece. 0 means don?t rotate. 1 means rotate 90 degrees clockwise. 2 means rotate 2*90 degrees clockwise and 3 means rotate 3*90 degrees clockwise. Obviously 4 has the same effect as 0. For example, the move “o1102” will rotate the piece 180 degrees and move it into row 1, column 1. It is possible to specify both a flip and a rotation in the same move, and both should be performed.

Your program should match the input/output of the following example:

A i i o i o i

o o B

Move: i00

Invalid move

A i i o i o i

o o B Move: i02

A i i o i

o   i o o B

Move: o101

A i i o i o i

o o   B

Move: o100

A i i o i o i

o o   B Move: o1002

A   i i o o   i o     i o     B

Move: B01

A B i i

o o   i o     i o

Move: i2113

A B o o o i

o i i i

Move: A03

B   A

o o o i

o i i i Move: end Game over

You are not required to check that the user is taking turns appropriately; It is up to the players of the game to take turns moving their own piece.

Marking scheme

Your solution will be marked according to the following scheme:

Task 1: Slide(50%)
Task 2: LGame(20%)
Task 3: Improvements(30%)
Indentation consistency1% is subtracted from your total for each

indentation mistake.

To indent properly, code should be shifted right by one tab between { and } and within nested control structures such as if statements, switch statements and loop statements. In a switch statement, the code within each case should also be indented.

Assignment submission and return

Your assignment must be submitted as a JAR file to PLATE during and after completing each task, and before the due date. You may submit and resubmit as many times as you wish, before the due date. Your marks for Assignment 2 will be available through PLATE within 2 weeks after the due date.

David Marks

Dear sir/Ma'am

Our dedication and hard work towards developing quality content has made us competent to provide excellent services to the clients as per their needs. We ensure plagiarism free writing obeying academic integrity and honesty making us a dedicated team towards developing original content helping students to ensure high grades. Our services are hassle free, timely yet at an affordable rate driving clients to avail it for a longer period of time making them loyal and satisfied towards us.

Services we offer:
Essay writing
Report writing
Assignment writing
Reflective writing
Proposal writing
Dissertation writing
Thesis writing
CDR writing
Annotated bibliography
PowerPoint presentation
Article/book review
Why us?
Plagiarism free original content
On-time services maintaining deadlines
Experienced writers
Plagiarism and Grammarly report
Dedicate Team Leaders and Quality Checkers
Subjects we cover:
Marketing management
Human resource management
Environmental science
Business studies
Political science
Journalism and Masscommunication

Declaration: Working with us will give you the opportunity to avail divergent range of academic services at affordable rates in assistance with the dedicated team having members from different disciplines holding high degrees in their respective domains. We are experienced in developing B-plan, writing dissertations and theses having employed highly qualified and experienced writers.

You can reach us at-
Oz Paper Help
1 Step 1