In this assignment, you are to make a turn-based game which will allow you to play against the computer. The description below relates to building sandcastles, but you can re-frame the game in any way you like as long as you implement the functions as described below.The game is played in turns. Each turn, the user and the computer decide which tool they will use (Bucket, pail, shovel etc) to add sand to the castle. The first player to build a 100-foot-high sandcastle wins!(Alternatively, if this were a fighting game, you would choose a weapon which would do a random amount of damage. Each player starts with 100 health points, and the first to lose all of their health points loses the game. )Each tool will add a random amount of sand to the castle, between a minimum amount and a maximum amount.Information about the tools available should be stored in two arrays:int minSand[]
int MaxSand[]The index for these arrays is the tool you are using. for example, Tool 0 (some kind of bucket, perhaps) might add at least 2 feet and at most 5 feet to your sandcastle. In this case, minSand[0] would be 2 and maxSand[0] would be 5. Note: your choice for these values will influence the balance of the game. For example, if there is a tool that adds between 15 and 20 feet to the castle, the user will likely use that tool all the time as it is the best. Tools with large maximum values should have large minimum values (and vice versa), so the user can take a risk on a higher-payoff tool, or play it safe with a tool with a lower maximum but higher minimum valueA third array (toolName[]) should be used to store the name of the tool, as a string. In this case, toolName[3] = bucketThese three arrays are related, and known as parallel arraysThe game logic should be implemented using the following main game loop:while(!Winner())
{
DoUserTurn();
DoComputerTurn();
DisplayInfo();
}Each of these functions may or may not have parameters. This should be determined by you.bool Winner() should check the state of the game and determine if there is a winner. If not, another round should be played.
void DoUserTurn() should ask the user which tool they want to use, randomly add sand to their castle based on that tool.
void DoComputerTurn() should use a random number to pick a tool for the computer, and add sand to the computers castle just as in the players turn.
void DisplayInfo() should report the current game state to the user.In addition to these four functions, You should implement the following:void PromptUser() should be called from within DoUserTurn() to handle the interaction with the user to select a tool. Additionally, within this function or as another function, you should go through the arrays to list all of the tools and the range of sand they can add to a castle.int RandomBetween(int low, int high) should return a random number between (and including) low and high. This function will be used to determine exactly how much sand is added to each sandcastle using the tools from the previous arrays. It can also be used to allow the computer player to randomly choose one of the available tools.
The general formula for random numbers in a range is rand() % range + min, so your first task in this function should be to determine the range from the high and low integers. Dont forget to seed your random number only once at the beginning of the program.You will need to determine which parameters and of what type you need to send to each function. You may choose to use global variables for some things, but you should justify your decision.Make sure to adhere to functional cohesion and functional equivalence. Generalize wherever possible. Dont write the code as if there is only and will always be 4 tools. Use a global constant variable for the number of tools available, and create your arrays based on that.Create a module structure chart showing the above listed functions and how they relate to each other, as well as any other functions you are using. Submit this structure chart as an image file (.jpg, .gif, .pdf etc.)?Sample Output:
Welcome to the Sandcastles in the Sand game.
Your opponent is Robin. Good luck!
==Round 1==
Which tool would you like to use? (1-4, 0 to list) -> 0
[1] shovel ( 1 to 42 feet)
[2] spade ( 4 to 20 feet)
[3] bucket ( 2 to 30 feet)
[4] pail ( 12 to 15 feet)
Which tool would you like to use? (1-4, 0 to list) -> 1
You picked shovel. It added 32 feet to the height of your castle.
Robin picked spade. It added 20 feet to the height of her castle.
Your castle is 32 feet high, and Robins castle is 20 feet high.
You are winning!
==Round 2==
Which tool would you like to use? (1-4, 0 to list) -> 9
You only have 4 tools to choose from.
Which tool would you like to use? (1-4, 0 to list) -> 3
You picked bucket. It added 20 feet to the height of your castle.
Robin picked shovel. It added 39 feet to the height of her castle.
Your castle is 52 feet high, and Robins castle is 59 feet high.
Robin is winning!
==Round 3==
Which tool would you like to use? (1-4, 0 to list) -> 2
You picked spade. It added 12 feet to the height of your castle.
Robin picked shovel. It added 42 feet to the height of her castle.
Your castle is 64 feet high, and Robins castle is 101 feet high.
Robin won! You are sad.Cool expansions you could add for fun:
You should play around with the amounts that the different tools can add to a sandcastle, in order to make the game fun. Some tools (like the pail) should be a sure-thing but not worth much, while some tools (like the shovel) should have a high potential payoff but also risk adding almost nothing. My numbers are just a guess, you may find a better balance. Try to be creative with your tool choice as well. Maybe yours is a heavy-machinery sandcastle contest, with dump trucks or something.
Use an array to store multiple opponents, each with their own castle. (each slot is an opponents castle height).
As the user constructs their castle, maybe they find more tools that have different characteristics
Allow the players to use tools against their opponents to knock down their castle. For example, you might use your shovel against your opponents castle, removing a random amount of sand in the range appropriate to the tool. Can a castle have negative sand?
Allow the player to level up: The more castles they build, the better they are at using the tools and so the tools might move more sand, by multiplying the amount of sand by a skill modifier.
Maybe there are more qualities to the sandcastle rather than just height. Maybe you win by being the first player to 100 feet with at least three turrets? Turrets could be made by a special tool.
Maybe there are different types of sand? Maybe you need to mix sand with the right amount of water before you add it to the castle?
Fighting game
August 10th, 2017 admin