Cleans code
- Check only arrow key, for playing, otherwise quit - Quit game when maze exit is reached - Sop using movement status - Reverse the maze elements checking
This commit is contained in:
parent
b3d6122b32
commit
1a9daca08d
16
main.py
16
main.py
|
@ -12,13 +12,14 @@ details
|
|||
"""
|
||||
from os import system
|
||||
import pygame
|
||||
from pygame.locals import K_ESCAPE, KEYDOWN, QUIT
|
||||
from pygame.locals import K_UP, K_DOWN, K_RIGHT, K_LEFT, KEYDOWN, QUIT
|
||||
from map import Map
|
||||
|
||||
pygame.init()
|
||||
SCREEN = pygame.display.set_mode((100, 100))
|
||||
|
||||
MAP_FILE = '01.map'
|
||||
GAME_KEYS = [K_UP, K_DOWN, K_RIGHT, K_LEFT]
|
||||
|
||||
# Loading map
|
||||
MAP_GAME = Map(MAP_FILE)
|
||||
|
@ -34,11 +35,12 @@ while MAP_GAME.status:
|
|||
MAP_GAME.status = False
|
||||
|
||||
if event.type == KEYDOWN:
|
||||
if event.key == K_ESCAPE:
|
||||
MAP_GAME.status = False
|
||||
if event.key in GAME_KEYS:
|
||||
MAP_GAME.move_to(event.key)
|
||||
|
||||
else:
|
||||
system('clear')
|
||||
print("move_status:{}".format(MAP_GAME.move_to(event.key)))
|
||||
print("status_message:{}".format(MAP_GAME.status_message))
|
||||
MAP_GAME.map_print()
|
||||
MAP_GAME.status = False
|
||||
|
||||
system('clear')
|
||||
print("status_message:{}".format(MAP_GAME.status_message))
|
||||
MAP_GAME.map_print()
|
29
map.py
29
map.py
|
@ -30,9 +30,7 @@ MOVE_STATUS_MSG = {
|
|||
'ok': "Jusqu'ici, tout va bien…"
|
||||
}
|
||||
|
||||
MSG_DISCLAMER = "MSG_DISCLAMER"
|
||||
MSG_START_GAME = "MSG_START_GAME"
|
||||
MSG_END_GAME = "MSG_END_GAME"
|
||||
MSG_START_GAME = "Welcome in OCP3.\nUse arrow keys to play, any other key to quit."
|
||||
|
||||
|
||||
# CLASS
|
||||
|
@ -139,29 +137,24 @@ class Map:
|
|||
if next_position >= 0 and next_position <= self._MAXIM:
|
||||
next_char = self._map_in_a_string[next_position]
|
||||
|
||||
if next_char == MAZE_ELEMENTS['wall'] or next_char == MAZE_ELEMENTS['nlin']:
|
||||
move_status = 1
|
||||
if next_char == MAZE_ELEMENTS['void']:
|
||||
self._player_position = next_position
|
||||
self.status_message = MOVE_STATUS_MSG['ok']
|
||||
|
||||
elif next_char == MAZE_ELEMENTS['exit']:
|
||||
self._player_position = next_position
|
||||
move_status = 2
|
||||
self.status = False
|
||||
self.status_message = MOVE_STATUS_MSG['exit']
|
||||
|
||||
# elif next_char == MAZE_ELEMENTS['door']:
|
||||
# self._player_position = next_position
|
||||
# self._element_under_player = MAZE_ELEMENTS['door']
|
||||
# move_status = 3
|
||||
|
||||
else:
|
||||
self._player_position = next_position
|
||||
move_status = 4
|
||||
else: # MAZE_ELEMENTS wall, door or nline
|
||||
self.status_message = MOVE_STATUS_MSG['wall']
|
||||
else:
|
||||
move_status = 1
|
||||
self.status_message = MOVE_STATUS_MSG['wall']
|
||||
|
||||
# place le plyr sur sa nouvelle position
|
||||
self.place_element(MAZE_ELEMENTS['plyr'])
|
||||
self.status_message = MOVE_STATUS_MSG[MOVE_STATUS[move_status]]+"|"+str(self._player_position)+"|"+str(self._MAXIM)
|
||||
|
||||
return move_status
|
||||
# Debug
|
||||
self.status_message += "|"+str(self._player_position)+"|"+str(self._MAXIM)
|
||||
|
||||
def place_element(self, element):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue