In this assignment, you'll make a simple game where a duck, a mouse, and a turtle...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
In this assignment, you'll make a simple game where a duck, a mouse, and a turtle are on some island with 2 cats. Each animal will be given a set of directions to move around the board and you need to output the result of its movement as one of the following: - Eaten by the cat. - Escape through the bridge. Drowns outside the island. - Stuck inside the board. Requirements: Class Animal (Abstract Class) Attributes: • protected variables: rowPosition (integer) columnPosition (integer) public variables boardSize (static integer) Board (static 2D dynamic array) Methods (all public): pure virtual functions .getType()→ receives nothing and returns a string. • move(char c) → receives a character and returns a bool. • getRow() → receives nothing and returns an int. getColumn() → receives nothing and returns an int. Static functions • getBoardCell(int r, int c) → returns the char value inside the cell at row r and column c on the board array. .setBoard (int c1r, int c1c, int c2r, int c2c) o initializes the array to be boardSize x boardSize. o initializes the whole board array to the value '-' except for three cells: ■2 cell will contain the value 'C' representing the 2 cats at row c1r and column c1c, and at row c2c and column c2c respectively. 1 cell will contain the value 'B' representing the bridge to the exit, which is always at the last column and the middle row. setBoard(int cir, int c1c, int c2r, int c2c) o initializes the array to be boardSize x boardSize. o initializes the whole board array to the value '-' except for three cells: ■ 2 cell will contain the value 'C' representing the 2 cats at row c1r and column c1c, and at row c2c and column c2c respectively. ■ 1 cell will contain the value 'B' representing the bridge to the exit, which is always at the last column and the middle row. Class Duck (Inherits from Animal) Class Mouse (Inherits from Animal) Class Turtle (Inherits from Animal) Methods (all are public): default constructor sets the rowPosition and columnPosition to 0. constructor → takes two parameters to set rowPosition and column Position. getType() Implementation → returns "duck", "mouse", or "turtle". move(char c) Implementation updates rowPosition or columnPosition based on the character c which can have any of the values (U, D, L, and R). The function returns false if the movement in the specified direction will lead to going out of the bounds of the board, i.e. array, otherwise, it returns true. getRow() Implementation getColumn() Implementation Main File 1. Initialize the boardSize static attribute to 9. 2. Create three objects, one of type Duck, one of type Mouse, and one of type Turtle, and give each object its initial position using its constructor. 3. Create an array called of pointers to Animal that stores the addresses of the previous objects. 4. Call setBoard and give it any numbers as the positions of the two cats. 5. Iterate through the array to take in each iteration a string from the user representing the characters an object will move, for example "UDLD". You should iterate through this string to know what will happen to each object. It's guaranteed that the string would always be 4 characters long. 6. Based on the result of the movement, the program prints the type of the object followed by on the messages below: "escaped" If the object encounters the bridge. "got eaten" If the object encounters any cat. "drowned" If the object moved out of the board. "Starved" otherwise, i.e. If the object is still in the board. Sample Run: Assume that the positions of the cats are (3, 5) and (4, 1). Assume that the initial position of the Duck is (1, 1), and that of the Mouse is (2, 2), and that of the Turtle is (5, 5). If the user enters: DDDD RRUL URRR If the user enters: UURR RRRD LDRL Output: The duck got eaten. The mouse is stuck. The turtle escaped. Output: The duck drowned. The mouse got eaten. The turtle is stuck. In this assignment, you'll make a simple game where a duck, a mouse, and a turtle are on some island with 2 cats. Each animal will be given a set of directions to move around the board and you need to output the result of its movement as one of the following: - Eaten by the cat. - Escape through the bridge. Drowns outside the island. - Stuck inside the board. Requirements: Class Animal (Abstract Class) Attributes: • protected variables: rowPosition (integer) columnPosition (integer) public variables boardSize (static integer) Board (static 2D dynamic array) Methods (all public): pure virtual functions .getType()→ receives nothing and returns a string. • move(char c) → receives a character and returns a bool. • getRow() → receives nothing and returns an int. getColumn() → receives nothing and returns an int. Static functions • getBoardCell(int r, int c) → returns the char value inside the cell at row r and column c on the board array. .setBoard (int c1r, int c1c, int c2r, int c2c) o initializes the array to be boardSize x boardSize. o initializes the whole board array to the value '-' except for three cells: ■2 cell will contain the value 'C' representing the 2 cats at row c1r and column c1c, and at row c2c and column c2c respectively. 1 cell will contain the value 'B' representing the bridge to the exit, which is always at the last column and the middle row. setBoard(int cir, int c1c, int c2r, int c2c) o initializes the array to be boardSize x boardSize. o initializes the whole board array to the value '-' except for three cells: ■ 2 cell will contain the value 'C' representing the 2 cats at row c1r and column c1c, and at row c2c and column c2c respectively. ■ 1 cell will contain the value 'B' representing the bridge to the exit, which is always at the last column and the middle row. Class Duck (Inherits from Animal) Class Mouse (Inherits from Animal) Class Turtle (Inherits from Animal) Methods (all are public): default constructor sets the rowPosition and columnPosition to 0. constructor → takes two parameters to set rowPosition and column Position. getType() Implementation → returns "duck", "mouse", or "turtle". move(char c) Implementation updates rowPosition or columnPosition based on the character c which can have any of the values (U, D, L, and R). The function returns false if the movement in the specified direction will lead to going out of the bounds of the board, i.e. array, otherwise, it returns true. getRow() Implementation getColumn() Implementation Main File 1. Initialize the boardSize static attribute to 9. 2. Create three objects, one of type Duck, one of type Mouse, and one of type Turtle, and give each object its initial position using its constructor. 3. Create an array called of pointers to Animal that stores the addresses of the previous objects. 4. Call setBoard and give it any numbers as the positions of the two cats. 5. Iterate through the array to take in each iteration a string from the user representing the characters an object will move, for example "UDLD". You should iterate through this string to know what will happen to each object. It's guaranteed that the string would always be 4 characters long. 6. Based on the result of the movement, the program prints the type of the object followed by on the messages below: "escaped" If the object encounters the bridge. "got eaten" If the object encounters any cat. "drowned" If the object moved out of the board. "Starved" otherwise, i.e. If the object is still in the board. Sample Run: Assume that the positions of the cats are (3, 5) and (4, 1). Assume that the initial position of the Duck is (1, 1), and that of the Mouse is (2, 2), and that of the Turtle is (5, 5). If the user enters: DDDD RRUL URRR If the user enters: UURR RRRD LDRL Output: The duck got eaten. The mouse is stuck. The turtle escaped. Output: The duck drowned. The mouse got eaten. The turtle is stuck.
Expert Answer:
Answer rating: 100% (QA)
include include include class Animal protected int rowPosition int columnPosition public static int boardSize static stdvector Board virtual stdstring getType 0 virtual bool movechar c 0 int getRow re... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
The norm of a linear transformation TA: Rn Rn can be defined by where the maximum is taken over all nonzero x in Rn. (The subscript indicates that the norm of the linear transformation on the left is...
-
Suppose that f: Rn R and g: Rn Rn are differentiable on Rn and that there exist r > 0 and a Rn such that Dg(x) is the identity matrix, I, for all x Br(a). Prove that there is a function h: Br(a) {a}...
-
Let 5: Rn Rn and T: Rn Rn be linear transformations with matrices A and B respectively. [Theorem 3.] (a) Show that B2 = B if and only if T2 = 7 (where T2 means T o T). (b) Show that B2 = 1 if and...
-
How to respond to the following? Cycle stock, pipeline inventory, buffer stock, and in-transit inventory all have associated carrying costs. Interest rates on inventory values, warehousing expenses,...
-
In Problem 14.6 on page 583, you used radio advertising and newspaper advertising to predict sales (stored in Advertise). Develop a regression model to predict sales that includes radio advertising,...
-
What is the decision variable for this problem?
-
What are the various types of shafts?
-
For the past several years, Derrick Epstein has operated a part-time consulting business from his home. As of June 1, 2008, Derrick decided to move to rented quarters and to operate the business,...
-
K(s-2) (s-3) Find the jw-crossing for the negative unity feedback system where G(s) = s(s+2) (s+3) Fill in the a value:
-
1. Tesla uses lease accounting for automotive sales under its resale value guarantee program. Assume that instead of using lease accounting for automotive sales under its resale value guarantee...
-
Urinary System Anatomy - Practice on models 1. Name this structure that is the functional unit of the kidney. 2. Name the region that surrounds the apex of the renal pyramid. 6. 3. Name the region...
-
A commercial diffraction grating has 500 lines per mm. When a student shines a 530 nm laser through this grating, how many bright spots could be seen on a screen behind the grating?
-
Describe the basic function, structure, and powers of the executive branch of government?
-
Describe the concepts of policy and policymaking?
-
Discuss how interlocking directorates can reduce environmental uncertainty and help manage resource dependence.
-
If you were asked to distill, down to their most essential parts, the constitutional right to privacy and the right to privacy as it applies to abortion, what elements would you include?
-
In a proportionate liquidating distribution, Ashleigh receives a distribution of $30,000 cash, accounts receivable (basis of $0, fair market value of $40,000), and land (basis of $40,000, fair market...
-
Carlton Stokes owns and operates a car-detailing business named SuperShine & Detailing. For $150, Carltons business will hand wash and wax customers cars, vacuum the interior, and thoroughly clean...
-
Calculate s for these data, which have a mean of 3.30: 1.4, 2.2, 4.5, 4.1, and 4.3.
-
If F Rows = 2.87, df Rows = 2, df Within = 171, and F cv Rows = 3.053, write the results in APA format. Use = .05.
-
Students often gain a few pounds when they move away to college and start eating institutional food. A nutritionist weighed first-year students at the start of the semester, right before...
-
What methods can a company use to raise capital?
-
Does higher expected inflation increase, decrease, or have no effect on the required rate of return?
-
You have been asked to consult for an entrepreneur who is assembling investors for a new professional sport league. A critical decision for the league will be whether to organize under a...
Study smarter with the SolutionInn App