----------------------- Exercise #8 for NET2003 due March 7, 2005 ----------------------- -Ian! D. Allen - idallen@idallen.ca Global weight: 1% of your total mark this term Due date: in-lab live demo March 7 Marks: 1% -------------------------------- C Language and Makefile practice - Tetris game -------------------------------- Do this work locally on your Knoppix desktop and demonstrate it on your Knoppix desktop in your weekly Lab. Do not log in to the Course Linux Server. Work locally on Knoppix. You can save your modified tetris game on the server when you are done, if you wish. (You can actually practice doing all the work on the Course Linux Server or other Linux machine; but, unless you are sitting in front of a machine running an X11 Window Server, you will not be able to run tetris or play the game. The running game needs an X11 window server, such as you have in Knoppix.) You will download a compressed Unix tar archive, unpack it, build the Tetris game, fix the game, customize the game, and then play it. --------------------------------- Research: Finding the Tetris game --------------------------------- If you do a Google search for these two things: tetris .tar.gz one of the first links you come to is this: http://sunsite.utk.edu/Solaris-X86/prgms2-6/tetris-3.2.1-admin.html The "Open Group Desktop Technologies" link on that page leads to this directory of X11 games: ftp://ftp.x.org/contrib/games/ under which you will find this tar archive: tetris.3.2.1.tar.Z This .tar.Z archive is compressed using an old compression utility named "compress", which is why it has a .Z suffix instead of .gz (gzip) or .bz2 (bzip2). Linux tar and gzip both understand how to de-compress .Z files. If you cannot fetch the file from the ftp.x.org site (because the FTP site is busy), you can fetch (using wget) the same tetris compressed tar archive file name from this HTTP site: http://idallen.com/ --------------- Building Tetris --------------- 1. Use FTP or wget to fetch the tetris compressed tar archive to your Knoppix home directory. (Do not work on the course linux server.) 2. Unpack the tar archive. (Expand it and extract all the files.) 3. Change into the tetris.3.2.1 directory that was created. Look at the file names that are in this directory. How many C language files are there? How many header files (*.h)? 4. In the tetris README file under the heading "HOW TO BUILD", it gives two commands that you must run to create a Makefile and then use the Makefile to compile and build the tetris executable. Run these two commands. (Ignore the part about editing the SCOREFILE and RANDOM for the moment.) 5. Execute the tetris program in the current directory. It may complain about a missing font file 12x24 that is not present on Knoppix. Locate this 12x24 string in the source code and change the string to be 9x15 and then re-run "make" to rebuild tetris. 6. Read the README for how to play the tetris game. Re-run tetris and see that it now works, using the 9x15 font. 7. Find the "TETRIS" string that prints in the game window when it runs. Change the string to have your name in front, e.g. Ian's TETRIS Rebuild and re-run tetris to make sure it works. 8. You will find that tetris is unable to write a score file when it finishes. Under "HOW TO BUILD" it says you should edit the Imakefile and change the SCOREFILE. Edit the file Imakefile and change the SCOREFILE file name to /tmp/scorefile. You must then re-run xmkmf to re-create the Makefile for tetris. (If you are working on the Course Linux Server, the file /tmp/scorefile can only be owned by one userid, so you may not be able to use this name for your score file if some other student uses it first. On the Linux Server, pick some other name for your file.) Note that even though the Makefile has been updated by xmkmf, if you now run "make" it will not rebuild tetris, since the compiled program is still newer than the source files. To get the program to rebuild, you have to clean away the existing executable and the object code files. The Makefile can do this if you type "make clean". After doing "make clean" to remove all the object files, typing "make" will rebuild tetris with the new score file location. If this doesn't work, please remember you must run xmkmf after you have edited the Imakefile. 9. In the Makefile there are several "cleandir::" targets. These are called up when you say "make clean". (Near the bottom of the Makefile you will find that the "clean::" target depends on the "cleandir::" target.) Customize the first "cleandir::" target in the Makefile so that it echoes the line "Now cleaning" before doing the file removal. Make sure that when you say "make clean", your echo command works. 10. In the Makefile the first occurrence of "gcc" has the -m32 option specified. (This line is a definition of the CC variable inside the Makefile.) Add to the end of this line an option to turn on all gcc warnings. Run "make clean" followed by "make" again. What warnings are issued? 11. Demonstrate your working customized tetris to your instructor. Show that you have customized the "make clean" target. Show that the score file /tmp/scorefile works. 12. BONUS CHALLENGE: You will note that no matter how many times you run the game, only a few score lines are ever shown for your userid. Examine the source code and find out how to change the limit to be, say, 10 score lines. Make the change and demonstrate this for your instructor. This will require some detective work on your part!