Question
Objectives 1. To learn how to use 2 dimensional arrays to store and retrieve data to help solving problems. Introduction: Who doesnt love dragons? Movies
Objectives
1. To learn how to use 2 dimensional arrays to store and retrieve data to help solving problems.
Introduction: Who doesnt love dragons?
Movies about dragons and dragon training were very popular this summer. Your friend has not stopped talking about how awesome dragons are and how cool it would be to train them. To amuse your friend, you have decided to create a series of programs about dragons.
Problem: Race to Become the First Dragon Rider (dragonrider.c)
Now that your dragon has participated in the Celebration of the First Flight, they are a fully recognized dragon! Youve just found out that several of your friends just had their dragons pass their Celebration too. Now its a race to see which of you will become the first dragon rider. To start riding a dragon, you need the following items:
0) Fleece Blanket
1) Saddle
2) Leather Jacket
3) Flight Harness
4) Goggles
5) Helmet
At night, you and your friends will try to sneak out and obtain these pieces from the Dragon Island equipment shed. Each of you will take turns trying to gain a piece of equipment, simulated by a randomly generated number from 0 to 6. Six of those numbers (0-5) correspond to the numbers above, while 6 corresponds to Youve been caught! Lost a piece of equipment.
If you get a number that corresponds to an item you already have, nothing happens. If you get a saddle (item 1), you may only pick up the item if you already have a blanket (item 0). If you get a flight harness (item 3), you may only pick up the item if you already have a jacket (item 2). This is because you cannot put a saddle on your dragon without the blanket underneath and you cannot put a flight harness on yourself without a jacket underneath.
If you land on Youve been caught!, then you must choose which piece of equipment to discard. If you have no pieces to begin with, then you dont lose anything. If you have a saddle(1), then you cannot discard the blanket(0) and if you have a harness(3), then you cannot discard the jacket(2).
The first person to obtain all six items will become the first dragonrider!
Program Specification
You must use a 2D array to solve the problem.
There will be no more than 6 people trying to borrow equipment.
Sample Data Items
You may wish to use these data structures to help you solve the problem.
int cont = 1;
int riders[6][6];
char ITEMS[6][20] = {BLANKET, SADDLE, JACKET, HARNESS, GOGGLES, HELMET};
The values in ITEMS are strings and may be printed with %s. For example, to print SADDLE we could use printf(%s, ITEMS[1]);
Program Format
Beginning the program
Start by asking how many people will be trying to gain equipment from the equipment shed.
Beginning of Each Turn
Each turn should begin with a prompt with the following format:
Rider X, it is your turn. Enter 0 to look for an item.
where X is the number given to the current prospective dragon rider, starting at 1. (Note: Internally, the player numbers will start at 0, so when you print this out, just add 1 to the variable storing the player number.)
Finding an Item
After the random number is generated, check what it corresponds to. If a value other than 6 (Youve been caught!) is generated, a statement of the following form should be printed:
Rider X, you found a S.
where S is the name of the item the number matches.
If the player does not yet have the item and is allowed to obtain it, follow this with a statement of the form:
Congrats, you now have a S.
If the player is not allowed to obtain the item because they dont yet have another necessary item, print out a statement of the form:
Sorry, you cant obtain S.
If the player lands on a square for a piece they already have, then print the following:
You already have that item.
Landing on Youve been caught!
If the player gets this number they must choose a piece to lose. First print the warning:
Youve been caught!
If they have any items, prompt them with the question:
Which piece would you like to lose?
Follow this with a numbered list of items that are valid for the player to discard. (Namely, this list will NOT contain the blanket if the rider has a saddle and it will not contain the jacket if the rider has a harness) The numbering of the list should correspond to the numbering of each item listed on page 1. Thus, the numbering wont necessarily be sequential. For example, if the possible pieces a player can lose are the blanket, harness, and a helmet, the print out would appear as follows:
0. BLANKET
3. HARNESS
5. HELMET
You may assume the user will select a valid item. Then, print out a message of the following format:
You have selected the S to discard.
where S is the item to discard.
If the player has no pieces to lose, then print the following:
There is no equipment for you to lose. Lucky you, sort of.
Final Printout for Each Turn
At the end of each persons turn, print out a complete list of their items. The first line will be:
Rider X, here is what you currently have:
Follow this with a blank line and then a numbered list (as previously described), with each item the player currently has.
End of the Game
The game ends when one person has all the items. If you are using the sample data structure cont, then you can use this as a flag for continuing the game or not. The default is 1 for continuing the game. When a person has all the items, change the flag to 0.
At the end of the game, simply print a message with the following format:
Congratulations Rider X, you are the first dragon rider!
Optional Modification
If you prefer, you can use the names of you and your friends instead of Rider X by storing names in an array of strings. You can either ask the user to enter these names or hardcode them (but you must still ask how many potential riders are participating at the beginning of the program).
Deliverables
One source file: dragonrider.c
Restrictions
Although you may use other compilers, your program must compile and run using Code::Blocks. Your program should include a header comment. Also, make sure you include comments throughout your code describing the major steps in solving the problem.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started