CTEC1903 Computer Programming Assignment

Assignment Help Programming Languages
Reference no: EM132854331

CTEC1903 Computer Programming - De Montfort University

The coursework is about writing a simple game.This explanation sheet will help you to better understand the required functionality. Some features are more advanced, and it is expected you will attempt to complete as much of the game as possible. The mark you receive will be based upon how many unit tests you pass - the tests are designed to assess that the features work correctly.

You have been given a class Game, which consists of a field of size 10x10. The field is numbered as follows:

                                x

                                0              1              2              3              4              5              6              7              8              9

Y              0              p             .               w            .               .               .               .               .               .               .

1              .               .               w            .               .               .               .               .               .               .

2              .               .               w            .               .               .               .               .               .               .

3              .               b             .               .               .               .               .               .               .               .

4              .               .               .               .               .               .               .               .               .               .

5              .               .               .               .               .               .               .               .               .               .

6              .               .               .               .               .               .               .               .               .               .

7              .               .               .               .               .               .               .               .               .               .

8              .               .               .               .               .               .               .               .               .               .

9              .               .               .               .               .               .               .               .               .               .

The grid above should help you to visualise this scenario, and we have used p to show the current player position and w to show a wall. Coordinates are given as pairs in the form (x,y). Although different conventions can be used, here we define the origin as being in the upper left corner (which is common in computer graphics). Moving in the x direction would go right (or left) and moving in the y direction would go down (or up).

Therefore, in the snapshot shown above, the player is positioned in (0,0) at the origin.In the Game class you have been provided, the current position of the player is stored in positionX and positionY.

The use of "left", "right", "up", and "down" allows the player to be moved around in the field. You cannot move diagonally.

You will note the variable called field which is of type Array[Array[Int]] - this represents the grid shown above, where each cell is either empty (-1), a wall (0), or a bounty (positive number). In the above example, there are walls in (2,0), (2,1), and(2,2). The player can move within the field. If the player tries moving into a wall or off the field, nothing happens. So, in the example above, the player could move right or down, but not up or left. If the player has moved right once, it cannot move right again (because of the wall).In these examples we use the symbols . for empty cell, w for wall, and b for bountybecause they are easier to read. In the field, they are represented by the aforementioned numbers.

There are also bounties to collect, represented by positive numbers. If the player moves onto a bounty, the scoreis increased by the amount of the bounty and the bounty is erased (the cell becomes -1). This is done by the checkBounty method. For example, if the score is 0 and the player moves onto position(1,3) - this contains a bounty in the field above, suppose of value 5.This means the score would increase to 5. Any further moves onto (1,3) would not change the score, as the bounty would have been removed.

You can generally compare cells of the grid to determine if there is a wall or a bounty. So something like if(field(5)(6)==0) would check if there is a wall at this position. if(field(5)(6)>0) would check for a bounty (any value greater than 0 is a bounty).Of course, you may wish to look at several cells using loops etc.

The player can also save the current position to saveX and saveYby calling save(). If the player continues moving, the covered positions are evaluated by the checkBounties method. Covered positions are those inside a rectangle where the current position and the saved positions form two opposite corners of the rectangle. As soon as 9 or more positions are covered, the saved position is reset to -1, -1, indicating no saved position (these are the initial values of saveX and saveY as well) and all bounties in the covered positions are collected. For example, the player is in position(0,0), save is applied, and the player then moves right (parts of the field have been left out to save space, the same is true in other examples further down):

                                x

                                0              1              2              3              4              5              6              7              8              9

Y              0              s              p             w            .               .               .               .               .               .               .

1              .               .               w            .               .               .               .               .               .               .

2              .               b             w            .               .               .               .               .               .               .

3              b             .               .               .               .               .               .               .               .               .

Here, the player (p) is in(1,0), the saved position (s) is in (0,0). There are two positions (grey) covered. The player moves down one position. There are now 4 positions covered. With a further movedown, 6 positions are covered and the bounty at (1,2) will be collected. A further movedown would result in 8 positions being covered. Nothing happens here. However, with a further move down, the situation is this (note the player is now at (1,4)):

                                x

                                0              1              2              3              4              5              6              7              8              9

Y              0              s              .               w            .               .               .               .               .               .               .

1              .               .               w            .               .               .               .               .               .               .

2              .               .               w            .               .               .               .               .               .               .

3              b             .               .               .               .               .               .               .               .               .

4              .               p             .               .               .               .               .               .               .               .

5              .               .               .               .               .               .               .               .               .               .

There are now 10 positions covered. Since 9 or more are covered, we now collect all remaining bounties in here, which would include(0,1), (0,2), (0,3), and (0,4), even though these positions were not touched by the player - note (0,3) contains a bounty, which will therefore be collected. It would also reset the saved position to -1,-1, which indicates no saved position. Walls count as covered positions as well, if they are in the rectangle, however, you cannot move through them of course.

The method move takes a string where left, right, up, and down are encoded as l, r, u, and d respectively. The moves are executed according to the string, so "llrru" would move to the left twice, to the right twice and up once. If there is a wall, an individual move (but not the complete string) is not executed. After each individual move a bounty is collected if moved onto and the saved position is evaluated to see if 9 or more positions have been covered. This is the same as happens after moving left, right, up, or down.

The method suggestMovereturns a string in the same format as noted for themove method, which moves the player from the current position to position (x,y). No specific requirements for the efficiency of the solution exist. The move cannot jump walls. The method is restricted to finding a path which followstwo sides of a rectangle defined by the current position and the target. This means there is a given number of moves in one direction first, followed by a given number of moves in another direction. If the first move was horizontal, the second is vertical, and vice versa. If this is not possible due to walls, the method returns an empty string. If two paths are possible, any of them can be returned. No actual move is done. For example, below the two potential paths to get from (0,0) to (3,3) are indicated:

                                x

                                0              1              2              3              4              5              6              7              8              9

Y              0              v> p       >             >w          v              .               .               .               .               .               .

1              v              .               w            v              .               .               .               .               .               .

2              v              .               w            v              .               .               .               .               .               .

3              >             >             >             .               .               .               .               .               .               .

4              .               .               .               .               .               .               .               .               .               .

Since the move "rrrddd" is blocked by a wall, it is not possible, so the method would return "dddrrr". If this pathway would be blocked as well, an empty string would be returned.

The file Game.scala also contains an object GameBuilderwhich allows the initialisation of predefined game scenarios, such as those shown throughout this explanation. This object could go in its own file, but has been placed within the same file as the Game class as we want you to be able to submit a single file. There are three ways in which the game can be initialised, and the first has been completed for you. Use the comments above the other initialisation methods to helpcomplete them (we suggest you do this at an early stage as the unit tests refer to these).Lists of Tuples are used to provide coordinates. Remember that a tuple like (3,3) represents a single value of type tuple - in this case a 2-tuple (pair), whereas (4,5,7) is a 3-tuple (triplet).

Attachment:- Computer Programming.rar

Reference no: EM132854331

Questions Cloud

What is Jamie tax liability and her average tax rate : Jamie has taxable income of $68,000. She is single, and her tax rates are 15% on the first $26,250 of taxable income. What is Jamie tax liability
Ci on the difference in mean batch viscosity : Find a 90% CI on the difference in mean batch viscosity resulting from the process change. What is the practical meaning of this interval?
What type of education is required : What type of education is required? Do you have a preference for degree specialization? Human Resources? Business Management?
Identify the reasons for performing air monitoring : Identify the reasons for performing air monitoring. What are the most common causes of death in confined spaces?
CTEC1903 Computer Programming Assignment : CTEC1903 Computer Programming Assignment Help and Solution, De Montfort University - Assessment Writing Service
Calculating descriptive statistics : Give an example of how calculating descriptive statistics may be useful for a company?
What was the holding period return for the stock : A stock has had returns of 17.22 percent, 12.30 percent, 6.21 percent, 27.46 percent, and -13.74 percent. What was the holding period return for the stock
Evaluate an article from the centers for disease control : Evaluate an article from the Centers for Disease Control and Prevention on obesity, cardiovascular disease, diabetes, or burnout.
What percentage of students have a gpa : To determine the percentage of Z-scores BELOW Z, P(

Reviews

len2854331

4/11/2021 10:22:06 PM

I am really struggling with this coursework. Please help me finish this. (programming software is eclipse Scala)

Write a Review

Programming Languages Questions & Answers

  Calculate students average test scores and their grades

Write a program to calculate students average test scores and their grades -  dimensional array to store the test score, and a parallel one-dimensional array to store grades.

  Create a very basic calculator map out the numeric keypad

Create a very basic calculator, map out the numeric keypad (17 buttons) and an EditText view. If text is given, prompt the user with a message that complains about the error.

  Create a very simple four function integer calculator

Create a very simple four function integer calculator with buttons for Add, Subtract, Multiply, and Divide, and with two text-type input fields. When the user enters two numbers and clicks one of the buttons, the answer is displayed where shown.

  Correct syntax of a common programming language

Palindromes and Anagrams - Fundamentals of Programming - Explain the importance of programming style concepts (documentation, mnemonic names, indentation)

  Provide a measure of accuracy of your prediction

Explain how you computed your prediction from the estimates and be sure to provide a measure of accuracy of your prediction.

  Provide example of array and how it could be used

Provide the example of the Array and how it could be used. Then look over sections on ArrayLists. Would an ArrayList be better suited for your use?

  Prepare class to include three data member

Prepare Class called Employee that includes three pieces of information as data members - first name (type string), last name (type string) and monthly salary (type float).

  Write a program that substitutes an overloaded

Write a program that substitutes an overloaded += operator for the overloaded + operator in the STRPLUS program in this chapter.

  Comparative overview of the languages

comparative overview of the languages highlighting how they were suitable or not suitable for the creating this type of application is also required.

  Create a SCL file for given situation

Create a SCL file for this situation - Coding should be done in visual C++ and the report should be clearly explaining to me how it is created

  Create internal representation of polynomial is array

Create class Polynomial. The internal representation of a Polynomial is an array of terms. Each term contains a coefficient and an exponent.

  Explain calling functions and pass functions by value

I need to create 2 functions which passe their values when they are called in main.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd