Project 2: Adventure Game. == PART 2 == (DUE: 7/28 Tuesday) GETTING STARTED To start, copy the following file into your directory: ~cs61a/lib/adv/story2.scm * * -- You do not need to read/understand these programs You will also need all the files you used from part I. **NOTE: Both people in this project will heavily modify the PERSON class. Be sure to write-down every change you make to the PERSON class to ensure a smooth merging process at the end. PERSON A: A5a. We are going to invent restaurant class. People will interact with the restaurants by buying food there. Make it possible for people to buy stuff by giving PERSON class a MONEY instance variable. Note we do not implement MONEY as a THING or as an attribute in the table for convenience. Given everyone $100 to start out. Create a method PAY-MONEY for PERSON that takes a positive number and removes that amount from the person's money. PAY-MONEY should return #f if the person does not have enough money, otherwise, it should return #t. Tell person B how you implemented money; person B will implement a job system and allow people to earn money. A5b. Our restaurants will only sell one type of food. Create a restaurant class. A restaurant is a type of PLACE that has takes a NAME, FOOD-CLASS, and FOOD-PRICE as instantiation variable and has one method: SELL which takes a PERSON and if the PERSON can pay enough MONEY for the food, the SELL method will then instantiate new object of FOOD-CLASS and return it. If the person does not have enough MONEY, the SELL method should return #f. Notice that the restaurant takes a Class as an instantiation argument. Which means that if the user were to create a restaurant, the user would first define a class: So if a user wants to make the restaurant Noahs, the user would first do > (define-class (bagel) (parent (food "Bagel" 100))) > (define Noahs (instantiate restaurant "Noahs" bagel 10)) Your implementation can assume that the user will provide the correct class definition. A5c. Implement a BUY method for PERSON. BUY should take no argument. It should first check to see if the place is a restaurant. If so, it will attempt to buy the FOOD that the restaurant sells. If the person cannot afford the food, you should print an error message. A6a. We would like for one person in the world to be able to give things to others as gift. But you shouldn't trust everyone and take every gift that come you way. For the first part, give every PERSON a friend-list as instance variable. Implement an ACCEPT method for PERSON that takes a THING that is in no one's possession and a PERSON, the giver, as arguments. If the THING input is a FOOD, then ACCEPT will take the food item and add the giver into the friend-list if the giver is not there already. If the input thing is not FOOD, then ACCEPT will accept the thing if and only if the giver is in the friend-list. If ACCEPT refuses a gift, you should print a message saying so and then return #f. A6b. Implement a OFFER method for PERSON that takes a THING in the person's possession and a PERSON as argument. OFFER should first relinquish your own possession of the thing and then ask the input PERSON to accept the gift. If the other PERSON refuses, then OFFER should put the THING back in your possession. Don't forget to check that the person you are offering a thing to is in the same place as you. --- END of Part II for person A --- PART II, PERSON B: B8a. In the previous part, you have implemented an attribute table. Give everyone an attribute called Intelligence that starts off at 0. We are going to allow people to increase Intelligence by doing exercises. First, define a PROBLEM class. It is not a sub-class of anything. It has one instantiation variable: difficulty, which is a number. It also has one instance variable, a procedure with no argument which represent the content the problem. This procedure should return #t if the problem is successfully solved and #f if not. Initialize the procedure with a function that just returns #t with 1/2 probabilility and #f else. Give PROBLEM a method called ACTIVATE-PROBLEM, which takes no argument. It should just return the result of calling the content-procedure. Build another method called SET-CONTENT, which takes a new procedure and changes the procedure instance variable to be the new input procedure. B8b. We will make it so that people can only do problems on a computer. Build a COMPUTER class that is a type of THING. A computer should have NAME as instantiation variable. It should also have a list of problems as INSTANCE variable representing the problems stored in the computer. The computer will have method ADD-PROBLEM which takes a new problem and adds it to the list of problems. The computer should also have a method GIVE-PROBLEM. GIVE-PROBLEM takes no argument, picks the first problem in the problem list and activates the problem. If the problem is successfully solved, GIVE-PROBLEM should return the difficulty of the problem. Otherwise, it should return #f. Finally, GIVE-PROBLEM should then remove the problem that was just given from the problem-list. B8c. implement a procedure DO-PROBLEM for PERSON. DO-PROBLEM should take a computer in the same place as the PERSON as argument. DO-PROBLEM will ask the computer to give-problem and increase the intelligence of the person by the difficulty of the problem if the problem is correctly solved. Otherwise, DO-PROBLEM should display a message indicating failure. B9a. Now, we will implement a job system and allow people to earn money. Ask person A about how MONEY is implemented. Define a job class that has NAME, PAY-RATE, PREREQ-INTELLIGENCE as instantiation arguments and no instance variables nor methods. Create a class-variable ALL-JOBS for PERSON that contains a list of 5 job OBJECTS ordered by prereq-intelligence. - Unemployed: 0 pay-rate, 0 prereq-intelligence - Student: 0 pay-rate, 10 prereq-intelligence - Lab Assistant: 0 pay-rate, 20 prereq-intelligence - Reader: 10 pay-rate, 40 prereq-intelligence - TA: 20 pay-rate, 80 prereq-intelligence Each person should also have a JOB-LEVEL instance variable indicating what job the person currently have. You may decide how to represent JOB-LEVEL but it should be initialized to the worst job possible. B9b. We would like people to be able to get promoted to better jobs. For this exercise, we will make the idealistic assumption that a better job will always have higher prereq-intelligence. Implement a method ATTEMPT-PROMOTION for PERSON that will take the person's intelligence and adjust the person's JOB-LEVEL to fit the best job possible. You should not assume that ALL-JOBS will only contain the 5 jobs described above since we might add additional jobs in the future. B9c. Give everyone an HOURS-WORKED instance variable. Implement a method WORK that takes the number of hours as argument and increments the hour-worked by the input amount. Now, implement a method GET-PAID for PERSON that takes no argument. GET-PAID should check the hours-worked and the pay-rate of the current job and increase the amount of money the person has by pay-rate*hours-worked. You should then reset the hours-worked to 0 and print a message indicating that the person has gotten paid. --- END of Part II for Person B --- You should now combine your work with your partner. You can also now load story2.scm for the second chapter of the Marvelous Misadventure of Michael Matloob to test your code. You only need to turn in one code file, the modified adv.scm file. Name your file LOGIN1.LOGIN2.adv2.scm For example, if your login is cs61a-xy and your partner's is cs61a-uv, then you should turn in xy.uv.adv2.scm. The order of logins do not matter. IMPORTANT: you also need to turn in a transcript file, called LOGIN1.LOGIN2.transcript. You should show that you have adequately tested your project in the transcript file.