Python Forum
Lunar Lander Text Game
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lunar Lander Text Game
#1
Making the classic Lunar Lander game... But with a twist! Instead of using pygame or other graphics, I went completely old-school! Hope you enjoy!

# PLEASE CHANGE THE SPEED, FUEL, AND ALTITUDE VARIABLES TO YOUR LIKING
# you are the pilot and need to control how much fuel you burn in the
# retro rockets so that your descent speed slows to zero just as your
# altitude above the moon's surface reaches zero. If you impact the moon
# more than 5 m below the surface, or your speed on impact is
# greater than 5 m/s then you have considered to have crashed.
# else, it is considered to be a 'done' landing.
# If you run out of fuel, the spaceship will accelerate towards the moon by gravity.
# set up the initial parameters
speed = 20      # speed approaching the moon
fuel = 1500     # how much fuel is left
altitude = 100 # altitude above moon
gravity = 1 # acceleration due to gravity
burn = 0        # initial rate of burning fuel in rockets
# while ship is above the moon's surface,
# calculate flight data and take input from user
while altitude > 0:
   # calculate how long until ship will impact moon at current speed (impact)
   if speed <= 0:
       impact = 1000
   else:
       impact = altitude / speed
   # display flight data
   print('Altitude = ', altitude, 'Speed = ', speed, 'Fuel = ', fuel, 'Impact = ', impact, 'Previous burn', burn)
   burn = float(input("Enter fuel to burn (0-50)?"))
   # ensure rate of fuel burning is within rocket's capability and doesn't exceed remaining fuel
   if burn < 0:
       burn = 0
   if burn > 50:
       burn = 50
   if burn > fuel:
       burn = fuel
   #calculate new flight data
   altitude -= speed
   speed += gravity - burn/10
   fuel -= burn
# Hit moon surface
# display good landing or not
print('Altitude = ', altitude, 'Speed = ', speed, 'Fuel = ', fuel, 'Impact = ', impact, 'Previous burn', burn)
if altitude <- 5 or speed > 5:
   print("You have crashed")
else:
   print("You have landed")
Reply
#2
Nice. took 3 tries to not crash. Reminds me of this BASIC game from 1979.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Text Adventure Game Nave5 1 2,222 Mar-30-2020, 05:06 AM
Last Post: SheeppOSU
  Text base adventure game ForbNovak 12 7,300 Aug-29-2018, 03:11 PM
Last Post: Nwb
  My first 'GAME' It is a simple text adventure jackspendiff942003 3 3,796 Aug-08-2017, 10:22 PM
Last Post: jackspendiff942003

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020