Skip to content

Instantly share code, notes, and snippets.

@IliaSky
Last active December 17, 2015 06:09
Show Gist options
  • Save IliaSky/5563445 to your computer and use it in GitHub Desktop.
Save IliaSky/5563445 to your computer and use it in GitHub Desktop.
A simple console game printer for a simple snake game - http://github.com/fmi/python-homework/tree/master/2013/06 - homework for a python course
from msvcrt import getch
import os
from solution_6 import *
IMAGES = {'NoneType': '..', 'Food': 'FF',
'PythonHead': '@@', 'PythonPart': '##'}
CONTROLS = {'w': Python.UP, 'a': Python.LEFT,
's': Python.DOWN, 'd': Python.RIGHT}
def world_print(python_world):
os.system('cls')
#os.system('clear') # on linux / os x
print('Welcome to the Python World - controls: wasd, quit: q')
output = ''
for column in zip(*python_world.matrix):
for cell in column:
output += IMAGES[cell.contents.__class__.__name__]
output += '\n'
print(output)
def play_game():
a = World(10)
p = Python(a, Vec2D(5, 5), 3, Python.UP)
a[2][2].contents = Food()
a[3][3].contents = Food()
a[4][4].contents = Food()
world_print(a)
while True:
i = getch()
# i = raw_input('Your move:')
if i == 'q':
return 0
try:
p.move(CONTROLS[i])
world_print(a)
except Exception as e:
print(e)
play_game()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment