Forbade stepping on the mines, deleted event_interpreter.py
This commit is contained in:
parent
8d29c7078f
commit
a61e1c03b3
@ -1,30 +0,0 @@
|
|||||||
import pygame
|
|
||||||
import minefield as mf
|
|
||||||
import project_constants as pc
|
|
||||||
import main as mai
|
|
||||||
|
|
||||||
def interpret( event ):
|
|
||||||
|
|
||||||
# remove this after adding code
|
|
||||||
pass
|
|
||||||
|
|
||||||
# key press interpretation here
|
|
||||||
# add calls to sapper object's movement functions
|
|
||||||
# TODO : key press interpretation goes here
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# TINY SAMPLE FROM MY PYGAME TEST
|
|
||||||
# (had trouble with figuring this out)
|
|
||||||
#
|
|
||||||
# # this part is true, when you press a key down
|
|
||||||
# # there's also a KEYUP for letting go
|
|
||||||
#if event.type == pygame.KEYDOWN:
|
|
||||||
#
|
|
||||||
# # this part is true, when a key u pressed down is the left arrow
|
|
||||||
#if event.key == pygame.K_RIGHT:
|
|
||||||
# mf.sapper_position[0] += 10
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
41
minefield.py
41
minefield.py
@ -22,9 +22,6 @@ mine_asset_options = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def calculate_screen_position(x, y):
|
def calculate_screen_position(x, y):
|
||||||
coords = (
|
coords = (
|
||||||
consts.V_SCREEN_PADDING + consts.V_TILE_SIZE * x,
|
consts.V_SCREEN_PADDING + consts.V_TILE_SIZE * x,
|
||||||
@ -86,17 +83,31 @@ class Minefield:
|
|||||||
# draw the sapper
|
# draw the sapper
|
||||||
sapper_screen_coords = calculate_screen_position(self.sapper_position[0], self.sapper_position[1])
|
sapper_screen_coords = calculate_screen_position(self.sapper_position[0], self.sapper_position[1])
|
||||||
window.blit(consts.ASSET_SAPPER, sapper_screen_coords)
|
window.blit(consts.ASSET_SAPPER, sapper_screen_coords)
|
||||||
|
|
||||||
|
# Make sure that sapper won't step on the mine.
|
||||||
|
def check_legal_move(self, target):
|
||||||
|
if self.matrix[target[1]][target[0]].mine is None:
|
||||||
|
return target
|
||||||
|
else:
|
||||||
|
return self.sapper_position
|
||||||
|
|
||||||
# Here are defined functions that move our agent. They are being called in main when certain key is pressed
|
# Here are defined functions that move our agent. They are being called in main when certain key is pressed
|
||||||
def go_right(self):
|
def go_right(self):
|
||||||
if self.sapper_position[0] != 9:
|
if self.sapper_position[0] < consts.V_GRID_HOR_TILES - 1:
|
||||||
self.sapper_position = (int(self.sapper_position[0])+1, int(self.sapper_position[1]))
|
self.sapper_position = self.check_legal_move(
|
||||||
def go_left (self):
|
(int(self.sapper_position[0]) + 1, int(self.sapper_position[1])))
|
||||||
if self.sapper_position[0] != 0:
|
|
||||||
self.sapper_position = (int(self.sapper_position[0])-1, int(self.sapper_position[1]))
|
def go_left(self):
|
||||||
def go_up (self):
|
if self.sapper_position[0] > 0:
|
||||||
if self.sapper_position[1] != 0:
|
self.sapper_position = self.check_legal_move(
|
||||||
self.sapper_position = (int(self.sapper_position[0]), int(self.sapper_position[1])-1)
|
(int(self.sapper_position[0]) - 1, int(self.sapper_position[1])))
|
||||||
def go_down (self):
|
|
||||||
if self.sapper_position[1] != 9:
|
def go_up(self):
|
||||||
self.sapper_position = (int(self.sapper_position[0]), int(self.sapper_position[1])+1)
|
if self.sapper_position[1] > 0:
|
||||||
|
self.sapper_position = self.check_legal_move(
|
||||||
|
(int(self.sapper_position[0]), int(self.sapper_position[1]) - 1))
|
||||||
|
|
||||||
|
def go_down(self):
|
||||||
|
if self.sapper_position[1] < consts.V_GRID_VER_TILES - 1:
|
||||||
|
self.sapper_position = self.check_legal_move(
|
||||||
|
(int(self.sapper_position[0]), int(self.sapper_position[1]) + 1))
|
||||||
|
Loading…
Reference in New Issue
Block a user