Building and Playing Shadow LandShadow Land is the only game so far that is almost totally portable. This is due to the fact that the game is text only. The only two things that might change this statement are that Shadow Land uses kbhit() and the ANSI color text driver. The ANSI color driver was used back in DOS days to allow special escape sequences to be used to change colors in pure text applications. To enable it, simply add the line DEVICE=C:\WINDOWS\COMMAND\ANSI.SYS to your config.sys file. If there's a problem, then simply search on your system for ANSI.SYS and use the proper path. Other than that, the code is straight C/C++ without any graphics or machine-dependent calls. To build the program, use the source module called SHADOW.CPP, compile it as a CONSOLE application (not a win32 .EXE), and link it with the standard C/C++ libraries and that's all you need to do. I have created an executable called SHADOW.EXE for you already, if you don't want to do this. You already know just about everything you need to know to play. However, here are a few tips. The game will begin by asking for your name. Then it will ask you what you want to do. At this point in the game, you are standing in the entryway to my apartment. To your left is a kitchen and to the north is a hallway. Move around in the environment with the "move" command and be sure to listen and smell everything. Remember "move" by itself will always move you in the direction you are currently facing, and "look" needs to be qualified by a nautical direction if you wish to see the objects in the room. Shadow's Game LoopThe game loop for Shadow Land is extremely simple since it's not in real-time. Here it is in Listing 14.12. Listing 14.12 The Game Loop of Shadow Landvoid main(void) { // call up intro Introduction(); printf("\n\nWelcome to the world of S H A D O W L A N D...\n\n\n"); // obtain users name to make game more personal printf("\nWhat is your first name?"); scanf("%s",you.name); // main event loop,note: it is NOT real-time while(!global_exit) { // put up an input notice to user printf("\n\nWhat do you want to do?"); // get the line of text Get_Line(global_input); printf("\n"); // break the text down into tokens and build up a sentence Extract_Tokens(global_input); // parse the verb and execute the command Verb_Parser(); } // end main event loop printf("\n\nExiting the universe of S H A D O W L A N D... see you later %s.\n",you.name); // restore screen color printf("%c%c37;40m",27,91); } // end main The main() begins by printing an introduction screen and then asking the player for his name. At this point, the game falls into the main event loop, which is static. The loop will wait for the user to type in a string which is returned from Get_Line(). Then the string is tokenized by Extract_Tokens() and finally parsed and acted upon the verb parser named Verb_Parser(). That's all there is to it. This cycle will occur every time the player enters a line of text until he types "exit". Winning the GameI think I already told you how to do this, but if I didn't, then good luck figuring it out! Also, try adding features to the game. For example, more objects, verbs, a help system. And if you're really up to it, create a graphical display of the room, player, position, and so forth and update the game to a graphic adventure! |