void car::setGas(double newGasLevel) { // If newGasLevel is between 0 and the tank capacity, // sets the private variable keeping track of // the amount of gas in the car to be the number // in newGasLevel. Nothing happens if newGasLevel // is a negative number or greater than the tank capacity. } void car::displayDistanceGraph() const { // Displays the total forward distance that the // car has gone as a horizontal bar graph. Use // asterisks (*) to represent distance the // car has traveled and dashes (-) to represent // distance not traveled yet. Each * or - represents // 20 miles. For example: // // 100 200 300 400 500 600 700 800 900 1000 // *******------------------------------------------- // // this bar graph shows the car has gone 140 miles out // of 1000. Be sure to include the mile labels as I do // above. } ostream& operator << (ostream& outs, const car& someCar) { // This function overloads the << operator so // that you can use it with cars. It will be a // replacement for the showDashboard function // you wrote in assignment 7. Note that this function // is a friend of the car class. You'll // need to use the friend keyword // when you write the prototype in the header file. // Use the examples in class and in the book to guide you. // Once this function is written, you'll be able to // do the following: // // car c1; // cout << c1; // // and it will print the car's owner, remaining gas, // distance traveled, and current gear to cout. }Write a small main function to test these out before going on!
Card Name | Meaning |
---|---|
drain gas from opponent | decreases opponent car's gas supply by 5 gallons. If opponent's car has less than 5 gallons to start with, opponent's gas supply is set to zero |
opponent out of gas | sets opponent car's gas supply to zero |
opponent stop | sets opponent car's gear to park |
opponent reverse | sets opponent car's gear to reverse |
roll | sets your own car's gear to forward |
gas can | adds one gallon of gas to your own tank (do nothing if tank already full) |
fill tank | fills your own car's gas tank to maximum |
move 50 miles | moves your own car 50 miles (or as many miles as remaining gas allows) |
move 100 miles | moves your own car 100 miles (or as many miles as remaining gas allows) |
move 200 miles | moves your own car 200 miles (or as many miles as remaining gas allows) |
Note: for the "move 50 miles", "move 100 miles", and "move 200 miles" cards, movement decreases the car's remaining gas, just as it did back in assignment 7.
Each time a player draws a card, whatever the card says will occur for that player as long as it is legal. For example, if a player draws a "move 50 miles" card, but that player's car gear is still in park, nothing should happen except an explanatory message. The car will go forward only if the car has gas remaining and is in forward gear (that is, if the player previously drew a "roll" card). Note that if a player draws a "move 50 miles" card while the car is in reverse, the car will move backward 50 miles! But remember, you already performed these error checks in assignment 7. So you won't have to do any more work to ensure that the card is legal. The class takes care of it. If the player gets a "move 50 miles" card, you need simply call the go function for that car with 50 as an argument.
Players continue taking turns drawing cards until one car goes forward over 1000 miles.
As always, you should use functions to make this program easier to write, debug, and read. The required ones are:
As always, you are encouraged to use other functions to help make the program easier to manage. Other functions you might consider using are playGame that contains the code for the main algorithm of the game so that the main function won't be too long and getRandom that returns a random number.
You will get a full 5 points of extra credit (that's an extra 10%!) for implementing this interactive version of Mille Bornes. The interactive version is also on BlackBoard and you can try it out to see how something closer to the real game plays. Do NOT attempt the extra credit until you've got the regular assignment working. You will get more points for a working regular assignment than for a non-working or late extra credit attempt.
You can also gain extra credit (2 pts max) by expanding the original assignment. Here are a couple of ideas:
Turn in both a hard copy and an electronic copy. Like last week, you will have three files in your project, so please put them into a folder named with your name and zip them up into a single file using a utility like winZip and then upload that single file to BlackBoard. In the Olin 110 lab, you can do this by right-clicking on the folder that you want to zip up and then choosing the "Add to Zip" command in the menu that pops up. See me if you're having problems doing this.
This is an individual project. I encourage you to talk to others about the general nature of the project and ideas about how to pursue it. However, the technical work, the writing, and the inspiration behind these must be substantially your own. If any person besides you contributes in any way to the project, you must credit their work in your report. Similarly, if you include information that you have gleaned from other published sources, you must cite them as references. Looking at, and/or copying, other people's programs or written work is inappropriate, and will be considered cheating.