mirror of
https://github.com/ProgramSnail/python_curses_game_2021.git
synced 2025-12-11 20:48:42 +00:00
fixes
This commit is contained in:
parent
b0190cd8dc
commit
f2a1c26910
2 changed files with 84 additions and 83 deletions
100
proj/main.py
100
proj/main.py
|
|
@ -2,71 +2,7 @@ import curses
|
||||||
import random
|
import random
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
MAP_POS_X = 16
|
from var_config import *
|
||||||
MAP_POS_Y = 2
|
|
||||||
|
|
||||||
WEAPON_SPEED = 1
|
|
||||||
|
|
||||||
PLAYER = 'P'
|
|
||||||
MONSTER = 'M'
|
|
||||||
EMPTY = ' '
|
|
||||||
DOOR = '>'
|
|
||||||
MARK = '!'
|
|
||||||
WALL = '#'
|
|
||||||
GOLD = '$'
|
|
||||||
WEAPON = '/'
|
|
||||||
ACTIVE_WEAPON = '.'
|
|
||||||
ADD_HEALTH = '+'
|
|
||||||
SCORE = '@'
|
|
||||||
|
|
||||||
SIMPLE_COLOR = 1
|
|
||||||
ACTIVE_COLOR = 2
|
|
||||||
WALL_COLOR = 3
|
|
||||||
GOLD_COLOR = 4
|
|
||||||
WEAPON_COLOR = 5
|
|
||||||
HIGHLIGHTED_COLOR = 6
|
|
||||||
PLAYER_COLOR = 7
|
|
||||||
DOOR_COLOR = 8
|
|
||||||
MONSTER_COLOR = 9
|
|
||||||
ADD_HEALTH_COLOR = 10
|
|
||||||
SCORE_COLOR = 11
|
|
||||||
ACTIVE_WEAPON_COLOR = 12
|
|
||||||
|
|
||||||
MONSTER_DAMAGE = 1
|
|
||||||
|
|
||||||
P_POS = 0
|
|
||||||
P_HEALTH = 1
|
|
||||||
P_WEAPON = 2
|
|
||||||
P_GOLD = 3
|
|
||||||
P_ACTIVE_DOOR = 4
|
|
||||||
P_SCORE = 5
|
|
||||||
|
|
||||||
MOVE_UP_ACTION = "KEY_UP"
|
|
||||||
MOVE_DOWN_ACTION = "KEY_DOWN"
|
|
||||||
MOVE_LEFT_ACTION = "KEY_LEFT"
|
|
||||||
MOVE_RIGHT_ACTION = "KEY_RIGHT"
|
|
||||||
|
|
||||||
ATTACK_UP_ACTION = 'w'
|
|
||||||
ATTACK_DOWN_ACTION = 's'
|
|
||||||
ATTACK_LEFT_ACTION = 'a'
|
|
||||||
ATTACK_RIGHT_ACTION = 'd'
|
|
||||||
|
|
||||||
NEXT_DOOR_ACTION = 'q'
|
|
||||||
PREV_DOOR_ACTION = 'e'
|
|
||||||
|
|
||||||
DIRECTIONS = [
|
|
||||||
[0, -1],
|
|
||||||
[0, 1],
|
|
||||||
[-1, 0],
|
|
||||||
[1, 0]
|
|
||||||
]
|
|
||||||
|
|
||||||
EXTENDED_DIRECTIONS = DIRECTIONS + [
|
|
||||||
[1, 1],
|
|
||||||
[1, -1],
|
|
||||||
[-1, 1],
|
|
||||||
[-1, -1]
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def begin_curses():
|
def begin_curses():
|
||||||
|
|
@ -192,11 +128,9 @@ def generate_monsters(map, rand_range, rand_monster):
|
||||||
monsters = []
|
monsters = []
|
||||||
for i in range(len(map)):
|
for i in range(len(map)):
|
||||||
for j in range(len(map[i])):
|
for j in range(len(map[i])):
|
||||||
if (map[i][j][0] == EMPTY):
|
if map[i][j][0] == EMPTY and \
|
||||||
if random.randint(1, rand_range) <= rand_monster:
|
random.randint(1, rand_range) <= rand_monster:
|
||||||
|
|
||||||
monsters.append([[i, j], random_direction()])
|
monsters.append([[i, j], random_direction()])
|
||||||
# position, move direction
|
|
||||||
|
|
||||||
return monsters
|
return monsters
|
||||||
|
|
||||||
|
|
@ -351,17 +285,6 @@ def use_weapon(map, active_weapon, player_state, direction):
|
||||||
|
|
||||||
|
|
||||||
def player_actions(map, doors, active_weapon, player_state, player_action):
|
def player_actions(map, doors, active_weapon, player_state, player_action):
|
||||||
if doors[player_state[P_ACTIVE_DOOR]]:
|
|
||||||
if player_action == NEXT_DOOR_ACTION:
|
|
||||||
player_state[P_ACTIVE_DOOR] += 1
|
|
||||||
player_state[P_ACTIVE_DOOR] %= len(doors)
|
|
||||||
player_state[P_POS] = copy.deepcopy(
|
|
||||||
doors[player_state[P_ACTIVE_DOOR]])
|
|
||||||
elif player_action == PREV_DOOR_ACTION:
|
|
||||||
player_state[P_ACTIVE_DOOR] = (player_state[P_ACTIVE_DOOR]
|
|
||||||
+ len(doors) - 1) % len(doors)
|
|
||||||
player_state[P_POS] = copy.deepcopy(
|
|
||||||
doors[player_state[P_ACTIVE_DOOR]])
|
|
||||||
k = -1
|
k = -1
|
||||||
if player_action == ATTACK_UP_ACTION:
|
if player_action == ATTACK_UP_ACTION:
|
||||||
k = 0
|
k = 0
|
||||||
|
|
@ -375,6 +298,19 @@ def player_actions(map, doors, active_weapon, player_state, player_action):
|
||||||
if k >= 0:
|
if k >= 0:
|
||||||
use_weapon(map, active_weapon, player_state, DIRECTIONS[k])
|
use_weapon(map, active_weapon, player_state, DIRECTIONS[k])
|
||||||
|
|
||||||
|
if not doors[player_state[P_ACTIVE_DOOR]]:
|
||||||
|
return
|
||||||
|
|
||||||
|
if player_action == NEXT_DOOR_ACTION:
|
||||||
|
player_state[P_ACTIVE_DOOR] += 1
|
||||||
|
player_state[P_ACTIVE_DOOR] %= len(doors)
|
||||||
|
player_state[P_POS] = copy.deepcopy(
|
||||||
|
doors[player_state[P_ACTIVE_DOOR]])
|
||||||
|
elif player_action == PREV_DOOR_ACTION:
|
||||||
|
player_state[P_ACTIVE_DOOR] = (player_state[P_ACTIVE_DOOR]
|
||||||
|
+ len(doors) - 1) % len(doors)
|
||||||
|
player_state[P_POS] = copy.deepcopy(
|
||||||
|
doors[player_state[P_ACTIVE_DOOR]])
|
||||||
|
|
||||||
|
|
||||||
def move_weapon(map, active_weapon, player_state): # needed to test
|
def move_weapon(map, active_weapon, player_state): # needed to test
|
||||||
|
|
@ -466,5 +402,5 @@ def main():
|
||||||
else:
|
else:
|
||||||
print("You lose(")
|
print("You lose(")
|
||||||
|
|
||||||
|
if (__name__ == "__main__"):
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
65
proj/var_config.py
Normal file
65
proj/var_config.py
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
MAP_POS_X = 16
|
||||||
|
MAP_POS_Y = 2
|
||||||
|
|
||||||
|
WEAPON_SPEED = 1
|
||||||
|
|
||||||
|
PLAYER = 'P'
|
||||||
|
MONSTER = 'M'
|
||||||
|
EMPTY = ' '
|
||||||
|
DOOR = '>'
|
||||||
|
MARK = '!'
|
||||||
|
WALL = '#'
|
||||||
|
GOLD = '$'
|
||||||
|
WEAPON = '/'
|
||||||
|
ACTIVE_WEAPON = '.'
|
||||||
|
ADD_HEALTH = '+'
|
||||||
|
SCORE = '@'
|
||||||
|
|
||||||
|
SIMPLE_COLOR = 1
|
||||||
|
ACTIVE_COLOR = 2
|
||||||
|
WALL_COLOR = 3
|
||||||
|
GOLD_COLOR = 4
|
||||||
|
WEAPON_COLOR = 5
|
||||||
|
HIGHLIGHTED_COLOR = 6
|
||||||
|
PLAYER_COLOR = 7
|
||||||
|
DOOR_COLOR = 8
|
||||||
|
MONSTER_COLOR = 9
|
||||||
|
ADD_HEALTH_COLOR = 10
|
||||||
|
SCORE_COLOR = 11
|
||||||
|
ACTIVE_WEAPON_COLOR = 12
|
||||||
|
|
||||||
|
MONSTER_DAMAGE = 1
|
||||||
|
|
||||||
|
P_POS = 0
|
||||||
|
P_HEALTH = 1
|
||||||
|
P_WEAPON = 2
|
||||||
|
P_GOLD = 3
|
||||||
|
P_ACTIVE_DOOR = 4
|
||||||
|
P_SCORE = 5
|
||||||
|
|
||||||
|
MOVE_UP_ACTION = "KEY_UP"
|
||||||
|
MOVE_DOWN_ACTION = "KEY_DOWN"
|
||||||
|
MOVE_LEFT_ACTION = "KEY_LEFT"
|
||||||
|
MOVE_RIGHT_ACTION = "KEY_RIGHT"
|
||||||
|
|
||||||
|
ATTACK_UP_ACTION = 'w'
|
||||||
|
ATTACK_DOWN_ACTION = 's'
|
||||||
|
ATTACK_LEFT_ACTION = 'a'
|
||||||
|
ATTACK_RIGHT_ACTION = 'd'
|
||||||
|
|
||||||
|
NEXT_DOOR_ACTION = 'q'
|
||||||
|
PREV_DOOR_ACTION = 'e'
|
||||||
|
|
||||||
|
DIRECTIONS = [
|
||||||
|
[0, -1],
|
||||||
|
[0, 1],
|
||||||
|
[-1, 0],
|
||||||
|
[1, 0]
|
||||||
|
]
|
||||||
|
|
||||||
|
EXTENDED_DIRECTIONS = DIRECTIONS + [
|
||||||
|
[1, 1],
|
||||||
|
[1, -1],
|
||||||
|
[-1, 1],
|
||||||
|
[-1, -1]
|
||||||
|
]
|
||||||
Loading…
Add table
Add a link
Reference in a new issue