lesson4.py 1.52 KB
Newer Older
raptor's avatar
lesson4  
raptor committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
import os, sys

def _find_getch():
	try:
		import termios
	except ImportError:
		# Non-POSIX. Return msvcrt's (Windows') getch.
		import msvcrt
		return msvcrt.getch
	# POSIX system. Create and return a getch that manipulates the tty.
	import sys, tty
	def _getch():
		fd = sys.stdin.fileno()
		old_settings = termios.tcgetattr(fd)
		try:
			tty.setraw(fd)
			ch = sys.stdin.read(1)
		finally:
			termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
		return ch
	return _getch

getch = _find_getch()

Mario = [
	'     RRRRR      ',
	'    RRRRRRRRR   ',
	'    HHH--0-     ',
	'   H-H---0---   ',
	'   H-HH---0---- ',
	'   HH----00000  ',
	'     --------   ',
	'  RRRRBBRRR     ',
	'--RRRRBBBRRRR---',
	'--- RRBYBBBBRR--',
	'-- BBBBBBBBBB   ',
	'  BBBBBBBBBBBB  ',
	' BBBBB    BBBB  ',
	'HHBBB      BBB  ',
	'HHHH       HHHH ',
	' HHHHH     HHHHH',
]

BLACK = '30'
RED = '31'
GREEN = '32'
YELLOW = '33'
BLUE = '34'
GRAY = '90'
WHITE = '37'

ECODE = '\033[%sm█\033[0m'

mx = 0
my = 0
def drawmario():
	os.system("clear")
	offset = ' ' * mx
	for i in range (my):
		print()

	for ln in Mario:
		ln = ln.replace( '0', ECODE % BLACK )
		ln = ln.replace( 'R', ECODE % RED )
		ln = ln.replace( 'B', ECODE % BLUE )
		ln = ln.replace( '-', ECODE % YELLOW )
		ln = ln.replace( 'H', ECODE % GRAY )
		ln = ln.replace( 'Y', ECODE % WHITE )
		print( offset + ln)

drawmario()

RUNNING = True
while True:
	a = getch()
	if a is 'q':
		RUNNING = False
		break
	elif a is 'a':
		mx -= 1
	elif a is 'd':
		mx += 1

	if a is 'w':	
		my -= 1
	elif my < 8:
		my +=1
	drawmario()