CSE201 Advanced Programming Section-A Lab Assignment 04 solution

$30.00

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (5 votes)

Hop-n-Win
Pictorial Representation of how you can play Hop-n-Win
Assignment Description
Although we are providing a simple test case, it is really simple to play this game. The rules of
the game are exactly as shown in the above picture.
You must use the following OOP concepts in this assignment to obtain marks: a) classes and
objects, b) class relationships, c) exception handling at all appropriate places, d) object
cloning and e) generic programming. Whenever an exception is generated, you should
catch that exception and redo the execution step that generated the exception.
This is a single-player game with a really simple objective: the player gets 5 chances to hop and
land on the carpet of tiles. Every time the player lands on a random tile, s/he may win a soft toy.
The player stores all the soft toys he has won in a bucket. Once the player has hopped five
times, the game ends after listing out the details of the soft toys won by the player.
1. Tile Carpet
As shown in the picture, the carpet has 20 tiles. Each tile contains a unique soft toy. You can
use your imagination to have a unique soft toy stored at each tile. If the player lands on an
even-numbered tile, he directly wins the soft toy stored at that tile, otherwise, the player has to
solve a question. In this case, the soft toy is won only in case the player’s answer was correct.
There is also a possibility that the player is too energetic and jumps really long to land into the
muddy puddles at the end of the tile carpet.
2. Question Solving using a Calculator
The game contains a generic calculator for calculating either the result of the division of two
integers or for calculating the result of the concatenation of two strings. It doesn’t work on any
other data types. If the player lands on an odd-numbered tile, the game asks the player if he
would like to answer a question based on integer operation or string operation. If the player’s
choice is an integer operation, the game will generate a pair of random integers (all integers
supported). The game will then ask the player to enter the result of the division of these two
integers. The game will then pass these two integers to the generic calculator to verify the
player’s result. If the player’s choice is string operation, the game will generate a pair of random
strings of length four. The game will then ask the player to enter the result of the concatenation
of these two strings. The game will then pass these two strings to the generic calculator to verify
the player’s result. If the player’s calculation matches that of the calculator, the player will win
the soft toy.
3. Bucket to Store Soft Toys
Every time the player wins a soft toy at any tile, the tile will create a clone of its soft toy and then
hand it over to the player to store it in his bucket. At the end of the game, the game will simply
display all the soft toys collected by the player.
—————————————————————
Sample test case:
Hit enter to initialize the game
Game is ready
Hit enter for your first hop
You are too energetic and zoomed past all the tiles. Muddy Puddle Splash!
Hit enter for your second hop
You landed on tile 5
Question answer round. Integer or strings?
integer
Calculate the result of 2000 divided by 100
20
Correct answer
You won a Jerry soft toy
Hit enter for your third hop
You landed on tile 2
You won a Donald Duck soft toy
Hit enter for your fourth hop
You landed on tile 1
Question answer round. Integer or strings?
string
Calculate the concatenation of strings abCD and ZxyL
abcdZxyL
Incorrect answer
You did not win any soft toy
Hit enter for your fifth hop
You landed on tile 4
You won a Mickey Mouse soft toy
Game Over
Soft toys won by you are:
Jerry, Donald Duck, Mickey Mouse