-
-
Save anonymous/83e787eba8e9a6a24f67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
def onePlayer(): | |
aLunarLander = LunarLander(40, 25, 1000) | |
graphic() | |
while aLunarLander.get_altitude() > 0: | |
print " welcome to Classy Lunar Lander!" | |
print "current status:" | |
print "Velocity", aLunarLander.get_velocity() | |
print "Fuel", aLunarLander.get_fuel() | |
print "Altitude", aLunarLander.get_altitude() | |
fuelUnits = thrustinput(1) | |
aLunarLander.do_one_second(fuelUnits) | |
graphic() | |
if aLunarLander.get_velocity() >= 5: | |
quips = [ | |
" you crashed the lunar lander!", | |
" you made an amazing crater!", | |
" this is going to be awkward to explain to NASA", | |
" you are going to lose your license over this"] | |
print quips[randint(0, len(quips) -1)] | |
exit(1) | |
else: | |
print "you win!" | |
winners(1) | |
exit(0) | |
def winners(players): | |
choice = raw_input("would you like your win recorded?") | |
if choice == "Y" or "y": | |
if players == 1: | |
players = raw_input("please enter your name: ") | |
out_file = open("winnersfile.txt", "a") | |
out_file.write(players) | |
out_file.write("\n") | |
out_file.close() | |
exit(0) | |
def twoPlayer(): | |
graphic() | |
print " welcome to Classy Lunar Lander!" | |
print "Player 1! enter your name:" | |
playerOne = raw_input("--> ") | |
graphic() | |
print " welcome to Classy Lunar Lander!" | |
print " Player 2! enter your name:" | |
playerTwo = raw_input(" --> ") | |
aLunarLander = LunarLander(40, 25, 1000) | |
bLunarLander = LunarLander(40, 25, 1000) | |
while aLunarLander.get_altitude() > 0 and bLunarLander.get_altitude() > 0: | |
graphic() | |
print "current status for %s's Lander" % playerOne | |
print "Velocity", aLunarLander.get_velocity() | |
print "Fuel", aLunarLander.get_fuel() | |
print "Altitude", aLunarLander.get_altitude() | |
fuelUnits = thrustinput(1) | |
aLunarLander.do_one_second(fuelUnits) | |
graphic() | |
# the spaces make it appear to the right of the lander for player 2 | |
print " current status for %s's Lander" % playerTwo | |
print " Velocity", bLunarLander.get_velocity() | |
print " Fuel", bLunarLander.get_fuel() | |
print " Altitude", bLunarLander.get_altitude() | |
fuelUnits = thrustinput(2) | |
bLunarLander.do_one_second(fuelUnits) | |
if aLunarLander.get_velocity() >= 5: | |
print "%s crashes, %s wins!" % (playerOne, playerTwo) | |
winners(playerTwo) | |
elif bLunarLander.get_velocity() >= 5: | |
print "%s crashes, %s wins!" % (playerTwo, playerOne) | |
winners(playerOne) | |
else: | |
print "you draw!" | |
exit(0) | |
def graphic(): | |
# uses either clear or cls depending on OS. Should be checked at the start of the program | |
osspecific.clear() | |
print """ ____ | |
/___.`--.____ .--. ____.--( | |
.'_.- ( ) -._'. | |
.'.' |'..'| '.'. | |
.-. .' /'--.__|____|__.--'\ '. .-. | |
(O).)-| | \ | | / | |-(.(O) | |
`-' '-'-._'-./ \.-'_.-'-' `-' | |
_ | | '-.________.-' | | _ | |
.' _ | | | __ | | | _ '. | |
/ .' ''.| | / \ | |.'' '.\\ | |
| |( )| '. || || .' |( )| | | |
\ '._.' '. | \ / | .' '._.' / | |
'.__ ______'.|__'--'__|.'______ __.' | |
.'_.-| |------| |-._'. | |
//\\\\ | |--::--| | //\\\\ | |
// \\\\ | |--::--| | // \\\\ | |
// \\\\| /|--::--|\ |// \\\\ | |
/ '._.-'/|_______/ |--::--| \_______|\`-._.-\\\\ | |
/ __..--' /__|--::--|__\ `--..__\\\\ | |
/ / '-.|--::--|.-' \\\\ | |
/ / |--::--| \\\\ | |
/ / |--::--| \\\\ | |
_.-' `-._ _..||.._ _.-` '-._ | |
'--..__..--' LGB '-.____.-' '--..__..-' | |
""" | |
def thrustinput(player): | |
flag = 0 | |
while flag == 0: | |
if player == 2: | |
fuelUnits = raw_input(" thrust? --> ") | |
elif player == 1: | |
fuelUnits = raw_input("thrust? --> ") | |
if fuelUnits.isdigit(): | |
flag = 1 | |
fuelUnits = int(fuelUnits) | |
if fuelUnits < 0: | |
fuelUnits = 0 | |
flag = 1 | |
elif fuelUnits == "\r" or "\n": | |
fuelUnits = 0 | |
flag = 1 | |
return fuelUnits | |
def main(): | |
graphic() | |
print " welcome to Classy Lunar Lander!" | |
while True: | |
choice = raw_input(" one player or two player? (1 or 2) ") | |
if choice == "1": | |
onePlayer() | |
elif choice == "2": | |
twoPlayer() | |
else: | |
graphic() | |
print " enter a number!" | |
from random import randint | |
from lunlan import LunarLander | |
import osspecific | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LunarLander(object): | |
def __init__(self, velocity, fuel, altitude): | |
self.__velocity = velocity | |
self.__fuel = fuel | |
self.__altitude = altitude | |
def get_velocity(self): | |
return self.__velocity | |
def get_fuel(self): | |
return self.__fuel | |
def get_altitude(self): | |
return self.__altitude | |
def thrust(self): | |
self.__velocity = self.__velocity - 4 | |
def do_one_second(self, fuelUnits): | |
if fuelUnits > self.__fuel: | |
print " not enough fuel! burning all remaining fuel" | |
import time | |
time.sleep(1) | |
fuelUnits = self.__fuel | |
self.__fuel = self.__fuel - fuelUnits | |
while fuelUnits > 0: | |
self.thrust() | |
fuelUnits = fuelUnits - 1 | |
self.__velocity = self.__velocity + 2 | |
self.__altitude = self.__altitude - (self.__velocity) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import os | |
import sys | |
def clear(): | |
whichos = sys.platform | |
if whichos == "win32": | |
os.system('cls') | |
else: | |
subprocess.call('clear') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment