Plagiarism will be treated seriously. All assignments that have been found involved wholly or partly in plagiarism (no matter these assignments are from the original authors or from the plagiarists) will score Zero marks.

computer science

Description

Assignment Due Date: 3 January, 11:00am

 

Instructions to Students

1.       This assignment should be done by each individual student.

2.       You are required to apply Object-Oriented Programming Techniques in this assignment.

3.       Plagiarism will be treated seriously. All assignments that have been found involved wholly or partly in plagiarism (no matter these assignments are from the original authors or from the plagiarists) will score Zero marks. You will be asked a random question on your program to verify that your submission is your own work.

4.       Your program must use JDK 1.8 or above to develop.

5.       Your program must be structured and well documented. The first few lines in the source file must be a comment stating the name of the source file, and the name, course, class, student number as well as the main methods of the program. Marks will be deducted if such comments are not included.

6.       You are required to submit your program code (java files), game file(s), documentation and checklist to moodle before deadline.  Late submission is NOT accepted.

7.       Weight of this Assignment: 50% of module (100% of EA)

 

 

Set All to Zero

 

Problem Specification

In this assignment, you are required to implement a board game.  The game board is a 2-D matrix of integer loaded from file.  The goal of the game is to set all the integers in the matrix to zero by applying different items to the game board, different items have different properties and cost (step count).  There is no limit in steps taken, but if the item set any value in the matrix to negative number, the game will over.

 

 

Game Flow

A game file is required to specify in the command line to start the game, following is an example:

> java Game game01.txt

 

The file described the height, width, content and target step of the game, following is an example:

game01.txt

5

5

1 1 1 1 0

1 0 0 1 0

1 0 2 4 2

1 1 4 1 2

0 0 2 2 2

4

remark

// height of the matrix

// width of the matrix

// line 0 of the matrix

// line 1 of the matrix

// line 2 of the matrix

// line 3 of the matrix

// line 4 of the matrix

// target step

 

After the game is initialized, it starts to ask user to apply different items to the game board.  Item can be described by a 2-D matrix of integer, the default setting of an Item will print the number stored on screen, except 0 will be replaced by a space.  For example,

data stored in item

 

1 1 1 1

1 0 0 1

1 0 0 1

1 1 1 1

the way to display item

 

1 1 1 1

1     1

1     1

1 1 1 1

 

 

but it can be overridden according to the needs of different item type (will be explained in detail later).  There are two types of item, they are Bomb and SuperBomb,

 

Bomb shared the same display property of Item, it costs 1 step to apply Bomb on game board.  When a Bomb is applied to the game board, the value in the game board will be reduced by the corresponding value in the Bomb.  For example,

If          is applied to 2,1 of the game board

    1 1 1                                        2 2 2 2 2

    1 2 1                                        2 2 2 2 2

    1 1 1                                        2 2 2 2 2

                                                 2 2 2 2 2

                                                 2 2 2 2

 

i.e. row is 2 and col is 1, the game board will become

 

2 2 2 2 2

2 2 2 2 2

2 1 1 1 2

2 1 0 1 2

2 1 1 1 2

 

SuperBomb behave differently, it costs 2 steps to apply SuperBomb on game board.  When a SuperBomb is applied to the game board, the value in the game board will be divided by the corresponding value in the SuperBomb.  For example, 

 

If          is applied to 2,1 of the game board

    2 2 2                                        3 2 3 4 3

    2 1 2                                        3 2 3 4 3

    2 2 2                                        3 1 2 3 3

                                                 3 3 4 4 3

                                                 3 5 6 7

 

i.e. row is 2 and col is 1, the game board will become

 

3 2 3 4 3

3 2 3 4 3

3 0 1 1 3

3 1 4 2 3

3 2 3 3 3

 

In this version, SuperBomb only stored 2 values, either 2 or 1.  The display property of SuperBomb is different from the Item’s default.  2 will be displayed as * and 1 will be displayed as space.  For example, the SuperBomb above will be displayed as follow:

data stored in item

 

2 2 2

2 1 2

2 2 2

the way to display item

 

* * *

*   *

* * *

 

Player is asked to apply an item to the game board repeatedly until the player win the game or the game is over. Player wins the game when all the values in the game board are zero and the game is over when there is a negative number in the game board.

 

There are two conditions when player wins:

            Condition 1:     Step count <= target step count

            Condition 2:     Step count > target step count

 

For Condition 1, it displays "Congratulation, well done!" and the game will be ended.  For Condition 2, it displays "Congratulation, you have finished the game... but you can do even better!" and player will be asked if he/she want to play again.

 

When the game is over (player lose), it displays "Game Over!" and also the game board.  Note that, negative value will be replaced as "X" and player will be asked if he/she want to play again too.

 

If the player choose to play again, the game including the step count will be reset and start again.  Otherwise the game will be ended.  Note that, "Bye Bye!" will be printed when the game ends.

 

To simplify the game, the item list is fixed in this version, there are 6 Bombs and 3 SuperBombs, their matrix and id are stated as follow:

Items

0        1      2      3      4    5  6      7      8

-----------------------------------------------------------

1 1 1 1  1 1 1  1   1    1    1 1  1  * * *  * * *    *

1     1  1   1    1    1 2 1  1 1     *   *  * * *  * * *

1     1  1 1 1  1   1    1            * * *  * * *    *

1 1 1 1

Player can use the items as many time as they wanted.

 

 

 

Following are some sample output without error and exception handling.


 

Instruction Files

Related Questions in computer science category