- Reset Game
- Book
- BASIC
-
Pizza
Original Resources
Download the original BASIC code. Check out the original page the text below was taken from in the Book.
Instructions From the Book
In this game, you take orders for pizzas from people living in Hyattsville. Armed with a map of the city, you must then tell your delivery boy the address where the pizza is to be delivered. If the pizza is delivered to the correct address, the customer phones you and thanks you; if not, you must give the driver the correct address until the pizza gets delivered.
Some interesting modifications suggest themselves for this program such as pizzas getting cold after two incorrect delivery attempts or taking three or more orders at a time and figuring the shortest delivery route. Send us your modifications!
This program seems to have surfaced originally at the University of Georgia in Athens, Georgia. The author is unknown.
Modifications For This Version
The original book version always had a 4 x 4 grid, and the letters of the alphabet are always in the same spot. My modification allows the grid to be as large as 15 x 15, and randomizes the location of the "addresses" (i.e., the letters). Additionally, due to the fact that there are only 26 letters of the alphabet, when using grids that are larger than 26 total squares, double letters are used (e.g., BA, BC, AE, etc.)
The user may choose the grid size. Additionally, there is a final score at the end of the game letting the user know how many times they got the answer correct, wrong, and invalid (i.e., they entered something other than x,y style input).
Technical Stuff
This was a lot trickier than expected. Becuase I used PHP to hide the data from the users, post and session variables abound. That being the case, I had to build a relatively elaborate system to keep track of which form to display and which one has been proccessed.
Further, the game starts by drawing a 4 x 4 grid, but the user can change that before play starts, so there was a little bit of juggling involved to reset the session variables and re-store a new city grid.
I may, someday, allow the user to choose how many questions they must answer. Currently the default is 10, but everything is in place to allow user input to change that number. Probably the trickiest part of the game was the feedback validation. Validating is easy enough, but preventing the system from reseting the question was a bit of fun. In other words, if the game is asking for Q's location, and the user entered an invalid entry, I didn't want it to switch to asking for W's location. I wanted it to stay on Q.
One more thing I may change in the future is to prevent the user from getting asked the same question more than once. Currently they can be asked the location of Q, and then the next question or another one later in the game could be Q again. At the moment it doesn't bother me enough to worry about changing it, but someday, I may. :)
Using a little CSS trickery I added some visual elements to the grid and made the "Good Job" message briefly animate so that the user gets some visual feedback. One thing that was annoying me was the while filling out the fields, the browser autocomplete would kick in which, due to the GUI, made for a less-than-ideal experience. I was hoping for a CSS solution, but instead I found autocomplete="off" to be the best solution. Rather than manually adding it to all of the input fields, I could have used JavaScript to take care of that, but I'd rather have that kind of stuff already in the HTML before it's delivered to the browser.
Lastly, I've tried playing this with a 15 x 15 grid. It's a lot harder than you'd think. You have to search through 225 "addresses" to find the one you're looking for. Challenge yourself and play the 15 x 15. Regardless, however, of the grid size, be sure to . . .
Enjoy Pizza!