|
| 1 | +print " "*33 + "Pizza" |
| 2 | +print " "*15 + "Creative Computing Morristown, New Jersey" |
| 3 | +print; print; print |
| 4 | +print "Pizza Delivery Game"; print |
| 5 | +name = input("What is your first name? "); print |
| 6 | +print "Hi, " + name + ". In this game you are to take orders" |
| 7 | +print "for pizzas. Then you are to tell a delivery boy" |
| 8 | +print "where to deliver the ordered pizzas."; print; print |
| 9 | + |
| 10 | +// Convert a house name like "G" into coordinates like [3,2]. |
| 11 | +nameToCoords = function(name) |
| 12 | + idx = name.code - "A".code |
| 13 | + row = floor(idx / 4) |
| 14 | + col = idx % 4 |
| 15 | + return [col+1, row+1] |
| 16 | +end function |
| 17 | + |
| 18 | +// Convert house coordinates like [3,2] into a house name like "G". |
| 19 | +coordsToName = function(coords) |
| 20 | + idx = (coords[1]-1)*4 + (coords[0]-1) |
| 21 | + return char("A".code + idx) |
| 22 | +end function |
| 23 | + |
| 24 | +askYesNo = function(prompt) |
| 25 | + while true |
| 26 | + yn = input(prompt + "? ").lower + " " |
| 27 | + if yn[0] == "y" then return "yes" |
| 28 | + if yn[0] == "n" then return "no" |
| 29 | + print "'Yes' or 'no' please, now then," |
| 30 | + end while |
| 31 | +end function |
| 32 | + |
| 33 | +input "(Press Return.)"; print |
| 34 | + |
| 35 | +print "Map of the city of Hyattsville"; print |
| 36 | +print " -----1-----2-----3-----4-----" |
| 37 | +for row in range(4, 1) |
| 38 | + print "-"; print "-"; print "-" |
| 39 | + s = row + " " |
| 40 | + for col in range(1, 4) |
| 41 | + s += coordsToName([col, row]) + " " |
| 42 | + end for |
| 43 | + s += row |
| 44 | + print s |
| 45 | +end for |
| 46 | +print "-"; print "-"; print "-" |
| 47 | +print " -----1-----2-----3-----4-----" |
| 48 | + |
| 49 | +input |
| 50 | +print "The output is a map of the homes where" |
| 51 | +print "you are to send pizzas."; print |
| 52 | +print "Your job is to give a truck driver" |
| 53 | +print "the location or coordinates of the" |
| 54 | +print "home ordering the pizza."; print |
| 55 | +if askYesNo("Do you need more directions") == "yes" then |
| 56 | + print; print "Somebody will ask for a pizza to be" |
| 57 | + print "delivered. Then a delivery boy will" |
| 58 | + print "ask you for the location."; |
| 59 | + print " Example:" |
| 60 | + print "This is J. Please send a pizza." |
| 61 | + print "Driver to " + name + ". Where does j live?" |
| 62 | + print "Your answer would be 2,3"; print |
| 63 | + if askYesNo("Understand") == "no" then |
| 64 | + print "This job is definitely too difficult for you. Thanks anyway" |
| 65 | + exit |
| 66 | + end if |
| 67 | + print "Good. you are now ready to start taking orders."; print |
| 68 | + print "Good luck!!"; print |
| 69 | +end if |
| 70 | + |
| 71 | +while true |
| 72 | + for turn in range(1,5) |
| 73 | + coords = [floor(rnd*4+1), floor(rnd*4+1)] |
| 74 | + buyer = coordsToName(coords) |
| 75 | + print "Hello " + name + "'s Pizza. This is " + buyer + |
| 76 | + ". Please send a pizza." |
| 77 | + while true |
| 78 | + while true |
| 79 | + inp = input(" Driver to " + name + ": Where does " + buyer + " live? ") |
| 80 | + inp = inp.replace(",", " ").replace(" ", " ") |
| 81 | + inp = inp.split + [0,0] |
| 82 | + guess = [inp[0].val, inp[1].val] |
| 83 | + if 1 <= guess[0] <= 4 and 1 <= guess[1] <= 4 then break |
| 84 | + end while |
| 85 | + if guess == coords then |
| 86 | + print "Hello " + name + ". This is " + buyer + ", thanks for the pizza." |
| 87 | + break |
| 88 | + else |
| 89 | + print "This is " + coordsToName(guess) + ". I did not order a pizza." |
| 90 | + print "I live at " + guess.join(",") |
| 91 | + end if |
| 92 | + end while |
| 93 | + print |
| 94 | + end for |
| 95 | + if askYesNo("Do you want to deliver more pizzas") == "no" then break |
| 96 | +end while |
| 97 | + |
| 98 | +print; print "O.K. " + name + ", see you later!"; print |
0 commit comments