Table of Contents
- Review file IO syntax.
- Start getting ready for the final exam.
Read the Scholastic Honesty Policy and Quest and Lab Integrity policies of the syllabus. Here are some clarifications for this particular lab:
- This is a solo lab that you must complete individually.
- You may discuss the code with other students for this lab.
- You must type all the code yourself and not copy from another student.
- Make sure you have completed the exercises from lesson 14.
- Complete the Extra: File I/O exercises in CodeLab. These are review exercises and you have all the information needed to complete them. If you have questions, please contact the instructor.
- Complete the following problems and make sure your final project has in-game instructions, which could be like the instructions part of this lab.
You may make modifications to the above lab as long as the lab grading criteria below is met.
A. Starting a scenario
Complete the following steps to create a new scenario:
- Review lessons:
- Open Greenfoot and start a new Java scenario named:
- Add your name to the README.TXT accessed by following the Scenario menu to the Scenario Information window.
- Change the name of the world to LabWorld with a background image of your choosing. Make the world size 600 pixels wide by 400 pixels high and a cell size of one. Compile your code to verify it works.
- When complete, your scenario screen should show a world background image.
B. Create Instructions
- Review 13.2.6: Reading a Text File.
- Save the following text file to the main scenario folder: gameuser.txt.
- Create an
Actor subclass named
Instructions with no image.
- In the constructor of the
Instructions class, create a
Scanner object named "in" that reads the file "gameuser.txt" from a JAR file.
- After opening the stream, use a while loop like the following to read each line of text from the file into a
String variable named "text":
String text = "";
text += in.nextLine() + "\n";
\n" adds an end-of-line (newline) character for each line of text read from the file.
- After the loop is completed, close the file.
- Use the text to construct a new
Hint: the easy way to create the image is to use the
GreenfootImage constructor made for text that we discussed in lesson 10.3.2 under the subheading Creating a Label. Feel free to choose appropriate foreground and background colors, set borders and add other features to your instructions.
- Set the image for the
Instructions objects to the image created in the prior step.
- In the
act() method of the
Instructions class, add a statement to remove this object from the world.
You may add fading effects if desired, but simply disappearing is acceptable.
- In the
World subclass for your scenario, add an
Instructions object to the scenario.
- Test your scenario to verify the instructions appear when the scenario loads and then disappears when pressing the Run button.
The instructor will evaluate your lab using the following criteria. Thus you should check your lab against these criteria to maximize your XP.
Lesson Exercises (from Class)
- 2: All lesson exercises attempted and turned in
- 1: Some lesson exercises not completed and turned in or other problems found
- 0: No lesson exercises turned in or wrong folder name
Number completed correctly / number exercises * 8 and rounded up to the nearest integer.
Lab 14 Exercises
Everyone starts with 4 points and points are subtracted for the following problems.
- -3: No Instructions object.
- -2: No stream opened to read from a JAR file.
- -2: Instructions not visible in the scenario.
- -1: Instructions/title not visible before scenario starts.
- -1: Missing the "gameuser.txt" file in the scenario.
- -1: Not reading from the "gameuser.txt" file in the scenario.
- -1: Not closing the file stream.
Maximum XP: 14
CodeLab is submitted automatically, but other lab work must be submitted as described below.
- On your computer, create a folder for the lesson exercises named "lesson" (no extra characters) and place all the exercise files from Lesson 14 into this folder. The exercises include the platformer scenario with these files included:
- Create a second folder named "tutorial" (no extra characters) and place the entire scenario from this lab into the folder. There should be only one scenario. Do not include any files from previous labs.
- Submit one or more zip files containing both scenarios to the Lab 14 slot of Canvas.
Please do not add any extra characters to the above folder names. Also, do not put any spaces or special characters like #, : or $ in zip file or folder names. Your crafted code must work as submitted. Remember to test and double check your files before and after submitting them. If you make a mistake, you can resubmit up to the deadline but must resubmit all your lab files.
Last Updated: December 05 2018 @13:09:37