|
| 1 | +if version.hostName == "Mini Micro" then clear |
| 2 | +print " "*30 + "Rocket" |
| 3 | +print " "*15 + "Creative Computing Morristown, New Jersey" |
| 4 | +print; print; print |
| 5 | +print "Lunar Landing Simulation" |
| 6 | +print "----- ------- ----------"; print |
| 7 | +yn = input("Do you want instructions (yes or no)? ").lower |
| 8 | +if not yn or yn[0] != "n" then |
| 9 | + print |
| 10 | + print "You are landing on the moon and and have taken over manual" |
| 11 | + print "control 1000 feet above a good landing spot. You have a down-" |
| 12 | + print "ward velocity of 50 feet/sec. 150 units of fuel remain." |
| 13 | + print |
| 14 | + print "Here are the rules that govern your Apollo space-craft" |
| 15 | + print "(Press Return after each one):"; print |
| 16 | + print "(1) After each second the height, velocity, and remaining fuel" |
| 17 | + print " will be reported via Digby your on-board computer." |
| 18 | + input |
| 19 | + print "(2) After the report a '?' will appear. Enter the number" |
| 20 | + print " of units of fuel you wish to burn during the next" |
| 21 | + print " second. Each unit of fuel will slow your descent by" |
| 22 | + print " 1 foot/sec." |
| 23 | + input |
| 24 | + print "(3) The maximum thrust of your engine is 30 feet/sec/sec" |
| 25 | + print " or 30 units of fuel per second." |
| 26 | + input |
| 27 | + print "(4) When you contact the lunar surface, your descent engine" |
| 28 | + print " will automatically shut down and you will be given a" |
| 29 | + print " report of your landing speed and remaining fuel." |
| 30 | + input |
| 31 | + print "(5) If you run out of fuel the '?' will no longer appear" |
| 32 | + print " but your second by second report will continue until" |
| 33 | + print " you contact the lunar surface."; print |
| 34 | + input |
| 35 | +end if |
| 36 | + |
| 37 | +pad = function(s, width=10) |
| 38 | + return (s + " "*width)[:width] |
| 39 | +end function |
| 40 | + |
| 41 | +// Bonus little feature when running in Mini Micro: display a header bar |
| 42 | +// always at the top of the screen. |
| 43 | +drawHeaders = function |
| 44 | + display(2).mode = displayMode.text; td = display(2) |
| 45 | + td.color = text.color; td.backColor = color.black |
| 46 | + td.row = 25; td.column = 0 |
| 47 | + td.print "sec feet speed fuel plot of distance" + " "*21 |
| 48 | +end function |
| 49 | + |
| 50 | +while true |
| 51 | + print "Beginning landing procedure.........."; print |
| 52 | + print "G O O D L U C K ! ! !" |
| 53 | + print; print |
| 54 | + print "sec feet speed fuel plot of distance" |
| 55 | + drawHeaders |
| 56 | + print |
| 57 | + t=0; h=1000; v=50; fuel=150 |
| 58 | + while true |
| 59 | + print pad(t,5) + pad(h,7) + pad(v, 10) + pad(fuel,8) + "|" + " "*floor(h/30) + "*" |
| 60 | + if fuel <= 0 then |
| 61 | + burn = 0 |
| 62 | + wait 0.5 // (slight pause for drama and legibility) |
| 63 | + else |
| 64 | + burn = input("?").val |
| 65 | + if burn < 0 then burn = 0 |
| 66 | + if burn > 30 then burn=30 |
| 67 | + if burn > fuel then |
| 68 | + burn = fuel |
| 69 | + print "**** out of fuel ****" |
| 70 | + end if |
| 71 | + end if |
| 72 | + v1 = v - burn + 5 |
| 73 | + fuel -= burn |
| 74 | + h -= .5*(v+v1) |
| 75 | + if h <= 0 then break |
| 76 | + t += 1 |
| 77 | + v = v1 |
| 78 | + end while |
| 79 | + print "***** CONTACT *****" |
| 80 | + h = h+ .5*(v1+v) |
| 81 | + if burn == 5 then |
| 82 | + d = h/v |
| 83 | + else |
| 84 | + d = (-v+sqrt(v*v+h*(10-2*burn)))/(5-burn) |
| 85 | + end if |
| 86 | + v1 = v + (5-burn)*d |
| 87 | + print "Touchdown at " + (t+d) + " seconds." |
| 88 | + print "Landing velocity = " + round(v1,1) + " feet/sec." |
| 89 | + print fuel + " units of fuel remaining." |
| 90 | + if v1 == 0 then |
| 91 | + print "Congratulations! a perfect landing!!" |
| 92 | + print "Your license will be renewed.......later." |
| 93 | + else if abs(v1) >= 2 then |
| 94 | + print "***** Sorry, but you blew it!!!!" |
| 95 | + print "Appropriate condolences will be sent to your next of kin." |
| 96 | + end if |
| 97 | + print; print; print |
| 98 | + yn = input("Another mission? ").lower |
| 99 | + if not yn or yn[0] != "y" then break |
| 100 | +end while |
| 101 | +print; print "Control out."; print |
0 commit comments