Q&A Q1: What is the purpose of a
Q&A Q1: What is the purpose of a file handle? A1: Similar to other handles in Windows, such as window handles and bitmap handles, a file handle is a reference to a location in memory that stores information about a file. More importantly, a file handle serves as your interface to a file, and is required in all file operations. You can think of a file handle as working a lot like a key for a locker in an airport terminal. When you open the file, you receive the handle (key) that you must then use in order to read from or write to the file. When you’re finished with the file, you close the file, which returns the handle to Windows. Q2: Why exactly can’t I read and write the scores as integers in the Space Out 4 game? A2: The reason for having to convert the integer scores to characters has to do with the fact that characters are a little easier to manipulate when it comes to reading and writing files. Because the number of digits in a score actually varies, it becomes difficult to parse a number from a data file if it is stored as a raw integer. Therefore, it’s easier to convert the integers into readable text that can be read from and written to files a character at a time. A side benefit of this approach is that you can open the HiScores.dat file and see the scores. Of course, this could also be perceived as a drawback because technically people could cheat and change the scores in the data file, but only you know this secret! Workshop The Workshop is designed to help you anticipate possible questions, review what you’ve learned, and begin learning how to put your knowledge into practice. The answers to the quiz can be found in Appendix A, “Quiz Answers.” Quiz 1: What is the name of the Win32 function used to open and create files? 2: How do you read and write data using files in Windows? 3: How do you clear the high score list in the Space Out 4 game? Exercises 1. Try opening the HiScores.dat file in a text editor and modifying the high score list by hand. Although this isn’t a very honest way to register a high score, you might have some fun tweaking a high score to play a trick on a friend. 2. Modify the Space Out 4 game so that it includes more than the top five scores in the high score list. You’ll need to modify the splash screen image to make room for the new scores, as well as modify the storage of the scores, and how they are read from and written to a file.
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Clan Web Hosting services