# [Solved] CMPE150 Assignment2-program to play a board game

30 \$

SKU: [Solved] CMPE150 Assignment2-program to play a board game Category: Tag:

You will write an interactive program to play a board game. The board is of size 4∗4 and is made of cells that contain letters and a ∗. Below is the default configuration of the board:

|A|B|G|G|

|R|T|F|P|

|P|K|V|I|

|G|V|J|*|

The cells of the board can be identified using coordinates. The cell in the top left corner has coordinate (1,1) whereas the lower right corner has coordinates (4,4). For example, in the picture, J has coordinates (4,3); A has coordinates (1,1), and T has coordinates (2, 2).

The user plays the gave by moving the ∗ to horizontally or vertically adjacent cells. The user collects points if she can move the ∗ to a cell that contains P or G. The user moves the ∗ by giving directions to the computer about which direction ∗ is to be moved. There are four allowed moves: Right, Left, Up, and Down. The ∗ can move one cell at a time. Since the cell that ∗ is trying to move is already occupied, i.e., there is another character there, the ∗ swaps places with that character. There are two additional rules: If the swapped character is P or G, after swapping, they are replaced with I. If the swapped character is G, the user earns 5 points and if the swapped character is P, the user earns 1 point.

Example 1 The user does Up. Since ∗ is in location (4,4), ∗ will swap places with I, which is located at (3,4). Hence, the new board configuration will be:

|A|B|G|G|

|R|T|F|P|

|P|K|V|*|

|G|V|J|I|

Example 2 The user does Right. Since there is nowhere to go on the right, this action will not have any influence on the board configuration.

Example 3 The user does Up. The ∗ is swapped with P, resulting in 1 point for the user and replacement of P with I (after swapping). Hence, the new board configuration will be:

|A|B|G|G|

|R|T|F|*|

|P|K|V|I|

|G|V|J|I|

The user can choose the initial configuration of the board. If that is the case, you need to ask the user for four strings, where each string corresponds to a row of the board. Assume that the users will enter the correct number of strings in correct form. For example, in the above board configuration, the first row can be represented with ”ABGG”. When the user enters the rows, she needs to make sure that there is exactly one ∗ in all of the strings that she enters. Sample Outputs:

Welcome to this weird game of P*G?

Do you want to use the default board configuration?No

Enter row 1 of the board: PPGG

Enter row 2 of the board: *XXO

Enter row 3 of the board: GOPP Enter row 4 of the board: KJHG

This is the board configuration now:

PPGG

∗XXO GOPP KJHG

How many moves do you want to make? 3

Make a move and press enter. After each move, the board configuration and your total points will be printed. Use A for Left, S for Right, W for Up, and Z for Down.

Z

This is the board configuration now:

PPGG

IXXO

∗OPP

KJHG

A

This is the board configuration now:

PPGG

IXXO

∗OPP

KJHG

S

This is the board configuration now:

PPGG

IXXO

O∗PP

KJHG

Thank you for playing this game.

Welcome to this weird game of P*G?

Do you want to use the default board configuration?Yes

This is the board configuration now:

ABGG

RTFP PKVI GVJ∗

How many moves do you want to make? 2

Make a move and press enter. After each move, the board configuration and your total points will be printed. Use A for Left, S for Right, W for Up, and Z for Down.

W

This is the board configuration now:

ABGG

RTFP

PKV∗ GVJI

W

This is the board configuration now:

ABGG

RTF∗

PKVI GVJI

Thank you for playing this game.

Bonus: At the end of the game, print the maximum possible score that the user could have achieved with the number of moves that she proposed to make. For example, in the first game, with three moves, the maximum points she could have gotten was 6.

1. Your program should have at least two static methods in addition to your main method. Thesemethods have to take at least one parameter and return a value.
2. All your board drawings should be done by the same method.
3. You are not allowed to use arrays or while loops. You can use for loops and if statements ofany kind as well as any methods of the String class.

Submission: You will submit a project report and your code over Moodle. Your program should be named with your initials and your student number together (e.g., OS2013800027). Project report should consist of five sections. These are:

1. Problem Description: In this section, you should describe the problem in your words.
2. Problem Solution: In this section, you should specify the concepts (methods, for loop, etc.) that you use in your program. Explain each one (i.e. why you need it, what you accomplish by using it, so on.). Report how many for loops you use.
3. Implementation: This section will include your whole code with comments. You need to payattention to indentation in order to improve readability.
• Do not forget to explain each variable that you use (i.e. int count=0; // count is the number of items).
• Before each method, specify what the method does (i.e. /* This method . */)
4. Output of the program: A screen-shot of your program output should be put in this section.
5. Conclusion: You should evaluate your work here. State whether you have solved the problemcorrectly. If not, state what is missing, what could have been improved, and so on.

## Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CMPE150 Assignment2-program to play a board game
30 \$