Curseyou is a Python Rogue style game that's intended to be small and simple. You can take this and turn it into your own game, but keep in mind it's built in stages based on the content of Learn Python the Hard Way 6th Edition.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
curseyou-python-rogue/first_hack.py

67 lines
1.4 KiB

import curses
MAP = [
"####################",
"###....#############",
"###....#############",
"###...........######",
"#############....###",
"#############....###",
"####################"]
def update(win, status, player_y, player_x):
win.erase()
win.box()
status.hline(0,0, curses.ACS_HLINE, 78)
map_line = 1
for line in MAP:
win.addstr(map_line, 1, line)
map_line += 1
win.addstr(player_y, player_x, '@', curses.A_BOLD)
status.addstr(1, 1, "PLAYER STATS")
win.refresh()
def main(stdscr):
curses.curs_set(0)
stdscr.clear()
begin_x = 0
begin_y = 0
height = 26
width = 80
win = curses.newwin(height, width, begin_y, begin_x)
status = win.subwin(5, 78, height-6, begin_x+1)
win.keypad(True)
player_x = 4
player_y = 4
while True:
new_x = player_x
new_y = player_y
update(win, status, player_y, player_x)
ch = win.getch()
if ch == ord('q'):
break
elif ch == curses.KEY_UP:
new_y = (player_y - 1) % 26
elif ch == curses.KEY_DOWN:
new_y = (player_y + 1) % 26
elif ch == curses.KEY_RIGHT:
new_x = (player_x + 1) % 80
elif ch == curses.KEY_LEFT:
new_x = (player_x - 1) % 80
if MAP[new_y - 1][new_x - 1] != '#':
player_x, player_y = new_x, new_y
curses.wrapper(main)