mirror of
https://github.com/ProgramSnail/python_curses_game_2021.git
synced 2025-12-08 19:18:43 +00:00
items added
This commit is contained in:
parent
31ae63fa68
commit
9396b569ab
1 changed files with 34 additions and 15 deletions
49
proj/main.py
49
proj/main.py
|
|
@ -1,6 +1,5 @@
|
||||||
import curses
|
import curses
|
||||||
import random
|
import random
|
||||||
import time
|
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
MAP_POS_X = 16
|
MAP_POS_X = 16
|
||||||
|
|
@ -12,6 +11,9 @@ EMPTY = ' '
|
||||||
DOOR = '>'
|
DOOR = '>'
|
||||||
MARK = '!'
|
MARK = '!'
|
||||||
WALL = '#'
|
WALL = '#'
|
||||||
|
GOLD = '$'
|
||||||
|
WEAPON = '/'
|
||||||
|
ADD_HEALTH = '+'
|
||||||
|
|
||||||
SIMPLE_COLOR = 1
|
SIMPLE_COLOR = 1
|
||||||
ACTIVE_COLOR = 2
|
ACTIVE_COLOR = 2
|
||||||
|
|
@ -121,7 +123,7 @@ def generate_map(map, sz_x, sz_y, map_symbols,
|
||||||
|
|
||||||
|
|
||||||
def map_mark_dfs(map, i, j):
|
def map_mark_dfs(map, i, j):
|
||||||
if map[i][j][0] != EMPTY:
|
if map[i][j][0] == WALL or map[i][j][0] == MARK:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
positions = [(i, j)]
|
positions = [(i, j)]
|
||||||
|
|
@ -205,6 +207,12 @@ def draw(stdscr, map, monsters, player_state):
|
||||||
stdscr.addstr(MAP_POS_Y - 1, 0, "Lives: " + str(player_state[1]),
|
stdscr.addstr(MAP_POS_Y - 1, 0, "Lives: " + str(player_state[1]),
|
||||||
curses.color_pair(HIGHLIGHTED_COLOR))
|
curses.color_pair(HIGHLIGHTED_COLOR))
|
||||||
|
|
||||||
|
stdscr.addstr(MAP_POS_Y, 0, "Weapon: " + str(player_state[2]),
|
||||||
|
curses.color_pair(HIGHLIGHTED_COLOR))
|
||||||
|
|
||||||
|
stdscr.addstr(MAP_POS_Y + 1, 0, "Gold: " + str(player_state[3]),
|
||||||
|
curses.color_pair(HIGHLIGHTED_COLOR))
|
||||||
|
|
||||||
for i in range(len(map)):
|
for i in range(len(map)):
|
||||||
stdscr.addstr(MAP_POS_Y - 1, i + MAP_POS_X,
|
stdscr.addstr(MAP_POS_Y - 1, i + MAP_POS_X,
|
||||||
'-', curses.color_pair(SIMPLE_COLOR))
|
'-', curses.color_pair(SIMPLE_COLOR))
|
||||||
|
|
@ -236,13 +244,13 @@ def input(stdscr): # not work
|
||||||
|
|
||||||
try:
|
try:
|
||||||
key = stdscr.getkey()
|
key = stdscr.getkey()
|
||||||
if key == 'w':
|
if key == 'w' or key == "KEY_UP":
|
||||||
m[1] -= 1
|
m[1] -= 1
|
||||||
elif key == 's':
|
elif key == 's' or key == "KEY_DOWN":
|
||||||
m[1] += 1
|
m[1] += 1
|
||||||
elif key == 'a':
|
elif key == 'a' or key == "KEY_LEFT":
|
||||||
m[0] -= 1
|
m[0] -= 1
|
||||||
elif key == 'd':
|
elif key == 'd' or key == "KEY_RIGHT":
|
||||||
m[0] += 1
|
m[0] += 1
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
@ -253,29 +261,40 @@ def input(stdscr): # not work
|
||||||
|
|
||||||
|
|
||||||
def move_player(map, player_state, pos_change):
|
def move_player(map, player_state, pos_change):
|
||||||
new_player_pos = copy.deepcopy(player_state[0])
|
p = copy.deepcopy(player_state[0])
|
||||||
|
|
||||||
new_player_pos[0] += pos_change[0]
|
p[0] += pos_change[0]
|
||||||
new_player_pos[1] += pos_change[1]
|
p[1] += pos_change[1]
|
||||||
|
|
||||||
if map[new_player_pos[0]][new_player_pos[1]][0] != WALL:
|
x = map[p[0]][p[1]][0]
|
||||||
player_state[0] = new_player_pos
|
|
||||||
|
if x != WALL:
|
||||||
|
player_state[0] = p
|
||||||
|
if x == ADD_HEALTH:
|
||||||
|
player_state[1] += 1
|
||||||
|
map[p[0]][p[1]] = [EMPTY, SIMPLE_COLOR]
|
||||||
|
elif x == WEAPON:
|
||||||
|
player_state[2] += 1
|
||||||
|
map[p[0]][p[1]] = [EMPTY, SIMPLE_COLOR]
|
||||||
|
elif x == GOLD:
|
||||||
|
player_state[3] += 1
|
||||||
|
map[p[0]][p[1]] = [EMPTY, SIMPLE_COLOR]
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
map_symbols = [
|
map_symbols = [
|
||||||
[[EMPTY, SIMPLE_COLOR], 30],
|
[[EMPTY, SIMPLE_COLOR], 30],
|
||||||
[[WALL, WALL_COLOR], 10],
|
[[WALL, WALL_COLOR], 10],
|
||||||
[['$', GOLD_COLOR], 1],
|
[[GOLD, GOLD_COLOR], 1],
|
||||||
[['/', WEAPON_COLOR], 2],
|
[[WEAPON, WEAPON_COLOR], 2],
|
||||||
[['+', ADD_HEALTH_COLOR], 1]
|
[[ADD_HEALTH, ADD_HEALTH_COLOR], 1]
|
||||||
]
|
]
|
||||||
|
|
||||||
stdscr = begin_curses()
|
stdscr = begin_curses()
|
||||||
|
|
||||||
map_size = [20, 20]
|
map_size = [20, 20]
|
||||||
|
|
||||||
player_state = [[0, 0], 10] # pos, lives
|
player_state = [[0, 0], 10, 0, 0] # pos, lives, weapon, money
|
||||||
|
|
||||||
map = []
|
map = []
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue