PEP 8 reformat + generate random data for mine_characteristics
This commit is contained in:
parent
d2820d872b
commit
213e6ce076
@ -15,7 +15,6 @@ class BFS:
|
|||||||
new_nodes = []
|
new_nodes = []
|
||||||
neighbours_list = self.agent.sensor(current_position[0], current_position[1])
|
neighbours_list = self.agent.sensor(current_position[0], current_position[1])
|
||||||
|
|
||||||
|
|
||||||
if current_position[2] == 180: # jesli patrzy na polnoc
|
if current_position[2] == 180: # jesli patrzy na polnoc
|
||||||
if neighbours_list[0][1] not in ['wall', 'cliff_south', 'cliff_east', 'cliff_north', 'cliff_west']:
|
if neighbours_list[0][1] not in ['wall', 'cliff_south', 'cliff_east', 'cliff_north', 'cliff_west']:
|
||||||
if neighbours_list[0][1] == 'grass':
|
if neighbours_list[0][1] == 'grass':
|
||||||
@ -33,7 +32,7 @@ class BFS:
|
|||||||
# cost = 2
|
# cost = 2
|
||||||
# elif neighbours_list[1][0] == 'mine':
|
# elif neighbours_list[1][0] == 'mine':
|
||||||
# cost = 0
|
# cost = 0
|
||||||
tmp = ('left', [current_position[0],current_position[1], 270], 1)
|
tmp = ('left', [current_position[0], current_position[1], 270], 1)
|
||||||
new_nodes.append(tmp)
|
new_nodes.append(tmp)
|
||||||
if neighbours_list[1][2] not in ['wall', 'cliff_south', 'cliff_east', 'cliff_north', 'cliff_west']:
|
if neighbours_list[1][2] not in ['wall', 'cliff_south', 'cliff_east', 'cliff_north', 'cliff_west']:
|
||||||
# if neighbours_list[1][2] == 'grass':
|
# if neighbours_list[1][2] == 'grass':
|
||||||
@ -100,7 +99,7 @@ class BFS:
|
|||||||
# cost = 2
|
# cost = 2
|
||||||
# elif neighbours_list[1][0] == 'mine':
|
# elif neighbours_list[1][0] == 'mine':
|
||||||
# cost = 0
|
# cost = 0
|
||||||
tmp = ('right', [current_position[0],current_position[1], 270], 1)
|
tmp = ('right', [current_position[0], current_position[1], 270], 1)
|
||||||
new_nodes.append(tmp)
|
new_nodes.append(tmp)
|
||||||
|
|
||||||
if current_position[2] == 270: # jesli patczy na wschod
|
if current_position[2] == 270: # jesli patczy na wschod
|
||||||
@ -111,7 +110,7 @@ class BFS:
|
|||||||
cost = 2
|
cost = 2
|
||||||
elif neighbours_list[1][0] == 'mine':
|
elif neighbours_list[1][0] == 'mine':
|
||||||
cost = 0
|
cost = 0
|
||||||
tmp = ('forward', [current_position[0] - 1,current_position[1], 270], cost)
|
tmp = ('forward', [current_position[0] - 1, current_position[1], 270], cost)
|
||||||
new_nodes.append(tmp)
|
new_nodes.append(tmp)
|
||||||
if neighbours_list[2][1] not in ['wall', 'cliff_south', 'cliff_east', 'cliff_north', 'cliff_west']:
|
if neighbours_list[2][1] not in ['wall', 'cliff_south', 'cliff_east', 'cliff_north', 'cliff_west']:
|
||||||
# if neighbours_list[2][1] == 'grass':
|
# if neighbours_list[2][1] == 'grass':
|
||||||
@ -134,8 +133,6 @@ class BFS:
|
|||||||
|
|
||||||
return new_nodes
|
return new_nodes
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# fringe = struktura danych przeszowyjąca wierchowki do odwiedzenia
|
# fringe = struktura danych przeszowyjąca wierchowki do odwiedzenia
|
||||||
# explored = lista odwiedzonych stanow
|
# explored = lista odwiedzonych stanow
|
||||||
# position_at_beginning = stan poczatkowy
|
# position_at_beginning = stan poczatkowy
|
||||||
@ -149,25 +146,22 @@ class BFS:
|
|||||||
|
|
||||||
self.window.pause(True)
|
self.window.pause(True)
|
||||||
|
|
||||||
position_at_beginning = [self.agent.position_x, self.agent.position_y, self.agent.rotation_degrees] # x, y, gdzie_patczy
|
position_at_beginning = [self.agent.position_x, self.agent.position_y,
|
||||||
|
self.agent.rotation_degrees] # x, y, gdzie_patczy
|
||||||
final_action_list = [] # lista co ma robic zeby dojechac do miny
|
final_action_list = [] # lista co ma robic zeby dojechac do miny
|
||||||
root = node.Node(None, None, position_at_beginning, 2) # parent, action, position, cost
|
root = node.Node(None, None, position_at_beginning, 2) # parent, action, position, cost
|
||||||
|
|
||||||
heapq.heappush(fringe, (0, root)) # add first node to fringe
|
heapq.heappush(fringe, (0, root)) # add first node to fringe
|
||||||
|
|
||||||
|
|
||||||
while len(fringe) != 0: # poki sa wezly do odwiedzenia(na fringe)
|
while len(fringe) != 0: # poki sa wezly do odwiedzenia(na fringe)
|
||||||
|
|
||||||
|
|
||||||
if len(fringe) == 0:
|
if len(fringe) == 0:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
# get node from fringe
|
# get node from fringe
|
||||||
tmp_node = heapq.heappop(fringe) # tuple(priority, node)
|
tmp_node = heapq.heappop(fringe) # tuple(priority, node)
|
||||||
tmp_node_position = tmp_node[1].get_position() # x, y , gdzie patczy
|
tmp_node_position = tmp_node[1].get_position() # x, y , gdzie patczy
|
||||||
|
|
||||||
|
|
||||||
# jesli tmp node to goaltest
|
# jesli tmp node to goaltest
|
||||||
if tmp_node_position[:2] == goaltest:
|
if tmp_node_position[:2] == goaltest:
|
||||||
print('Find')
|
print('Find')
|
||||||
@ -176,14 +170,12 @@ class BFS:
|
|||||||
final_action_list.append(tmp_node[1].get_action())
|
final_action_list.append(tmp_node[1].get_action())
|
||||||
tmp_node = tmp_node[1].get_parent()
|
tmp_node = tmp_node[1].get_parent()
|
||||||
final_action_list.reverse()
|
final_action_list.reverse()
|
||||||
#print(final_action_list)
|
# print(final_action_list)
|
||||||
self.window.pause(False)
|
self.window.pause(False)
|
||||||
return final_action_list
|
return final_action_list
|
||||||
|
|
||||||
explored.append(tmp_node[1]) # add node to array of visited nodes
|
explored.append(tmp_node[1]) # add node to array of visited nodes
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
neighbours_list_of_our_node = self.successor(tmp_node_position) # lista możliwych akcij
|
neighbours_list_of_our_node = self.successor(tmp_node_position) # lista możliwych akcij
|
||||||
print(neighbours_list_of_our_node)
|
print(neighbours_list_of_our_node)
|
||||||
|
|
||||||
@ -193,7 +185,6 @@ class BFS:
|
|||||||
notInFringe = True # false if node in fringe
|
notInFringe = True # false if node in fringe
|
||||||
notInExplored = True # false if node in explored
|
notInExplored = True # false if node in explored
|
||||||
|
|
||||||
|
|
||||||
p = manhattan(node_[1], goaltest) + node_[2]
|
p = manhattan(node_[1], goaltest) + node_[2]
|
||||||
# wyznacza jaki jest priorytet nastempnika
|
# wyznacza jaki jest priorytet nastempnika
|
||||||
# manchaten from node_ + cost of way from tmp_ode to node_
|
# manchaten from node_ + cost of way from tmp_ode to node_
|
||||||
@ -204,20 +195,20 @@ class BFS:
|
|||||||
|
|
||||||
for fringeNode in fringe: # isc po wszystkich wezlach ktore juz sa w fringe
|
for fringeNode in fringe: # isc po wszystkich wezlach ktore juz sa w fringe
|
||||||
# jesli nasz wezel juz jest w fringe
|
# jesli nasz wezel juz jest w fringe
|
||||||
if fringeNode[1].get_position()[0] == node_[1][0] and fringeNode[1].get_position()[1] == node_[1][1] and fringeNode[1].get_position()[2] == node_[1][2]:
|
if fringeNode[1].get_position()[0] == node_[1][0] and fringeNode[1].get_position()[1] == node_[1][
|
||||||
|
1] and fringeNode[1].get_position()[2] == node_[1][2]:
|
||||||
notInFringe = False
|
notInFringe = False
|
||||||
priority_in_fringe = fringeNode[0]
|
priority_in_fringe = fringeNode[0]
|
||||||
# number of element in fringe
|
# number of element in fringe
|
||||||
index_of_node_in_fringe = counter
|
index_of_node_in_fringe = counter
|
||||||
counter = counter + 1
|
counter = counter + 1
|
||||||
|
|
||||||
|
|
||||||
for exploredNode in explored: # isc po wszystkich wezlach z listy explored
|
for exploredNode in explored: # isc po wszystkich wezlach z listy explored
|
||||||
# jesli nasz wezel juz jest w explored
|
# jesli nasz wezel juz jest w explored
|
||||||
if exploredNode.get_position()[0] == node_[1][0] and exploredNode.get_position()[1] == node_[1][1] and exploredNode.get_position()[2] == node_[1][2]:
|
if exploredNode.get_position()[0] == node_[1][0] and exploredNode.get_position()[1] == node_[1][
|
||||||
|
1] and exploredNode.get_position()[2] == node_[1][2]:
|
||||||
notInExplored = False
|
notInExplored = False
|
||||||
|
|
||||||
|
|
||||||
# if node not in fringe and not in explored
|
# if node not in fringe and not in explored
|
||||||
if notInFringe and notInExplored:
|
if notInFringe and notInExplored:
|
||||||
x = node.Node(tmp_node, node_[0], node_[1], node_[2]) # parent, action, state_array, cost
|
x = node.Node(tmp_node, node_[0], node_[1], node_[2]) # parent, action, state_array, cost
|
||||||
@ -229,7 +220,5 @@ class BFS:
|
|||||||
tmp[0] = p
|
tmp[0] = p
|
||||||
tmp[1] = x
|
tmp[1] = x
|
||||||
fringe[index_of_node_in_fringe] = tuple(tmp)
|
fringe[index_of_node_in_fringe] = tuple(tmp)
|
||||||
self.window.draw_search([self.agent.position_x, self.agent.position_y], [node_[1][0], node_[1][1]],self.agent.current_map.tile_size, self.agent.current_map, self.agent)
|
self.window.draw_search([self.agent.position_x, self.agent.position_y], [node_[1][0], node_[1][1]],
|
||||||
|
self.agent.current_map.tile_size, self.agent.current_map, self.agent)
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,37 +7,17 @@ from numpy import random
|
|||||||
class DecisionTrees:
|
class DecisionTrees:
|
||||||
|
|
||||||
def return_predict(self):
|
def return_predict(self):
|
||||||
|
# Header looks like:
|
||||||
# header = ['Size(bigger_more_difficult)', 'Year(older_more_difficult)', 'Protection_from_defuse',
|
# header = ['Size(bigger_more_difficult)', 'Year(older_more_difficult)', 'Protection_from_defuse',
|
||||||
# 'Meters_under_the_ground', 'Random_detonation_chance', 'Detonation_power_in_m',
|
# 'Meters_under_the_ground', 'Random_detonation_chance', 'Detonation_power_in_m',
|
||||||
# 'Decision']
|
# 'Decision']
|
||||||
|
|
||||||
# read data
|
# read data
|
||||||
|
|
||||||
df = pd.read_csv("D:\\1 Python projects\Saper\data\db.txt")
|
df = pd.read_csv("D:\\1 Python projects\Saper\data\db.txt")
|
||||||
|
|
||||||
# print data
|
# print data
|
||||||
# print(df.head())
|
# print(df.head())
|
||||||
|
|
||||||
lines = []
|
|
||||||
|
|
||||||
with open('D:\\1 Python projects\Saper\data\db.txt') as f:
|
|
||||||
line = f.readline()
|
|
||||||
for i in range(0, 200):
|
|
||||||
line = f.readline()
|
|
||||||
line = line.rstrip()
|
|
||||||
line = line.replace(",detonate", "")
|
|
||||||
line = line.replace(",defuse", "")
|
|
||||||
lines.append(line)
|
|
||||||
|
|
||||||
ss = []
|
|
||||||
for line in lines:
|
|
||||||
ss.append(line.split(","))
|
|
||||||
|
|
||||||
normalized_data_for_predict = []
|
|
||||||
for i in ss:
|
|
||||||
normalized_data_for_predict.append(list(map(int, i)))
|
|
||||||
print(normalized_data_for_predict)
|
|
||||||
|
|
||||||
# ID3 config
|
# ID3 config
|
||||||
config = {'algorithm': 'ID3'}
|
config = {'algorithm': 'ID3'}
|
||||||
# create decision tree
|
# create decision tree
|
||||||
@ -46,5 +26,19 @@ class DecisionTrees:
|
|||||||
# print predict
|
# print predict
|
||||||
# print(chef.predict(model, [1, 2022, 0, 0, 0, 10]))
|
# print(chef.predict(model, [1, 2022, 0, 0, 0, 10]))
|
||||||
|
|
||||||
predict = normalized_data_for_predict[random.randint(0, 199)]
|
size = random.randint(1, 10)
|
||||||
return chef.predict(model, predict)
|
year = random.randint(1941, 2022)
|
||||||
|
protection = 0
|
||||||
|
if year >= 2000:
|
||||||
|
protection = random.choice([1, 0, 1])
|
||||||
|
m_under_the_ground = random.randint(0, 10)
|
||||||
|
detonation_chance = random.randint(0, 100)
|
||||||
|
detonation_power_in_m = random.randint(0, 10)
|
||||||
|
detonation_power_in_m = detonation_power_in_m - m_under_the_ground
|
||||||
|
if detonation_power_in_m <= 0:
|
||||||
|
detonation_power_in_m = 0
|
||||||
|
|
||||||
|
mine_characteristics = [size, year, protection, m_under_the_ground, detonation_chance, detonation_power_in_m]
|
||||||
|
|
||||||
|
print(mine_characteristics)
|
||||||
|
return chef.predict(model, mine_characteristics)
|
||||||
|
@ -5,25 +5,26 @@ from classes import decisionTrees
|
|||||||
|
|
||||||
pygame.mixer.init()
|
pygame.mixer.init()
|
||||||
|
|
||||||
#mina
|
|
||||||
|
# mina
|
||||||
class Mine:
|
class Mine:
|
||||||
position_x:int
|
position_x: int
|
||||||
position_y:int
|
position_y: int
|
||||||
size:int
|
size: int
|
||||||
image:pygame.surface.Surface
|
image: pygame.surface.Surface
|
||||||
image_text:pygame.surface.Surface
|
image_text: pygame.surface.Surface
|
||||||
timer_text:pygame.surface.Surface
|
timer_text: pygame.surface.Surface
|
||||||
timer_event:pygame.USEREVENT
|
timer_event: pygame.USEREVENT
|
||||||
font:pygame.font.Font
|
font: pygame.font.Font
|
||||||
|
|
||||||
difficulty:int = 1
|
difficulty: int = 1
|
||||||
weight:float = 1.0
|
weight: float = 1.0
|
||||||
explosion_timer:int = 100
|
explosion_timer: int = 100
|
||||||
|
|
||||||
def __init__(self,position_x, position_y, size, difficulty=1, weight=1.0, timer=100):
|
def __init__(self, position_x, position_y, size, difficulty=1, weight=1.0, timer=100):
|
||||||
self.position_x=position_x
|
self.position_x = position_x
|
||||||
self.position_y=position_y
|
self.position_y = position_y
|
||||||
self.size=size
|
self.size = size
|
||||||
self.weight = weight
|
self.weight = weight
|
||||||
self.explosion_timer = timer
|
self.explosion_timer = timer
|
||||||
self.difficulty = difficulty
|
self.difficulty = difficulty
|
||||||
@ -36,144 +37,146 @@ class Mine:
|
|||||||
else:
|
else:
|
||||||
self.image = pygame.image.load("assets/sprites/mine_fun_sized.png")
|
self.image = pygame.image.load("assets/sprites/mine_fun_sized.png")
|
||||||
self.image = pygame.transform.scale(self.image, (self.size, self.size))
|
self.image = pygame.transform.scale(self.image, (self.size, self.size))
|
||||||
self.font = pygame.font.SysFont('Comic Sans MS', int(self.size*0.4))
|
self.font = pygame.font.SysFont('Comic Sans MS', int(self.size * 0.4))
|
||||||
self.image_text = self.font.render(str(self.weight), False, (0, 0, 0))
|
self.image_text = self.font.render(str(self.weight), False, (0, 0, 0))
|
||||||
self.timer_text = self.font.render(str(self.explosion_timer), False, (255, 0, 0))
|
self.timer_text = self.font.render(str(self.explosion_timer), False, (255, 0, 0))
|
||||||
timer_interval = 1000
|
timer_interval = 1000
|
||||||
self.timer_event = pygame.USEREVENT + 1
|
self.timer_event = pygame.USEREVENT + 1
|
||||||
pygame.time.set_timer(self.timer_event , timer_interval)
|
pygame.time.set_timer(self.timer_event, timer_interval)
|
||||||
|
|
||||||
def draw(self, window):
|
def draw(self, window):
|
||||||
self.timer_text = self.font.render(str(self.explosion_timer), False, (255, 0, 0))
|
self.timer_text = self.font.render(str(self.explosion_timer), False, (255, 0, 0))
|
||||||
position_on_screen = (self.size*self.position_x, self.size*self.position_y)
|
position_on_screen = (self.size * self.position_x, self.size * self.position_y)
|
||||||
window.blit(self.image, position_on_screen)
|
window.blit(self.image, position_on_screen)
|
||||||
window.blit(self.image_text, (position_on_screen[0]+self.size/4, position_on_screen[1]+self.size/2))
|
window.blit(self.image_text, (position_on_screen[0] + self.size / 4, position_on_screen[1] + self.size / 2))
|
||||||
window.blit(self.timer_text, (position_on_screen[0]+self.size/4, position_on_screen[1]-self.size/8))
|
window.blit(self.timer_text, (position_on_screen[0] + self.size / 4, position_on_screen[1] - self.size / 8))
|
||||||
|
|
||||||
|
|
||||||
class Cliff:
|
class Cliff:
|
||||||
position_x:int
|
position_x: int
|
||||||
position_y:int
|
position_y: int
|
||||||
size:int
|
size: int
|
||||||
image:pygame.surface.Surface
|
image: pygame.surface.Surface
|
||||||
|
|
||||||
type:int
|
type: int
|
||||||
rotation:int
|
rotation: int
|
||||||
|
|
||||||
def __init__(self,position_x, position_y, size, rotation, type=0):
|
def __init__(self, position_x, position_y, size, rotation, type=0):
|
||||||
self.position_x=position_x
|
self.position_x = position_x
|
||||||
self.position_y=position_y
|
self.position_y = position_y
|
||||||
self.size=size
|
self.size = size
|
||||||
self.rotation = rotation
|
self.rotation = rotation
|
||||||
self.type = type
|
self.type = type
|
||||||
if self.type==0:
|
if self.type == 0:
|
||||||
self.image = pygame.image.load("assets/sprites/cliff.png")
|
self.image = pygame.image.load("assets/sprites/cliff.png")
|
||||||
elif self.type==1:
|
elif self.type == 1:
|
||||||
self.image = pygame.image.load("assets/sprites/cliff_corner.png")
|
self.image = pygame.image.load("assets/sprites/cliff_corner.png")
|
||||||
elif self.type==2:
|
elif self.type == 2:
|
||||||
self.image = pygame.image.load("assets/sprites/cliff_end1.png")
|
self.image = pygame.image.load("assets/sprites/cliff_end1.png")
|
||||||
elif self.type==3:
|
elif self.type == 3:
|
||||||
self.image = pygame.image.load("assets/sprites/cliff_end2.png")
|
self.image = pygame.image.load("assets/sprites/cliff_end2.png")
|
||||||
self.image = pygame.transform.scale(self.image, (self.size, self.size))
|
self.image = pygame.transform.scale(self.image, (self.size, self.size))
|
||||||
self.image = pygame.transform.rotate(self.image, self.rotation)
|
self.image = pygame.transform.rotate(self.image, self.rotation)
|
||||||
|
|
||||||
def draw(self, window):
|
def draw(self, window):
|
||||||
position_on_screen = (self.size*self.position_x, self.size*self.position_y)
|
position_on_screen = (self.size * self.position_x, self.size * self.position_y)
|
||||||
window.blit(self.image, position_on_screen)
|
window.blit(self.image, position_on_screen)
|
||||||
|
|
||||||
|
|
||||||
#mapa
|
# mapa
|
||||||
class Map:
|
class Map:
|
||||||
window:system.Window
|
window: system.Window
|
||||||
tile_size:int
|
tile_size: int
|
||||||
tiles_x:int
|
tiles_x: int
|
||||||
tiles_y:int
|
tiles_y: int
|
||||||
|
|
||||||
tile_palette:list
|
tile_palette: list
|
||||||
terrain_matrix:list
|
terrain_matrix: list
|
||||||
|
|
||||||
cliffs=[]
|
cliffs = []
|
||||||
mines=[]
|
mines = []
|
||||||
|
|
||||||
def __init__(self, window:system.Window, tile_size:int=64, tiles_x:int=8, tiles_y:int=8):
|
def __init__(self, window: system.Window, tile_size: int = 64, tiles_x: int = 8, tiles_y: int = 8):
|
||||||
self.window = window
|
self.window = window
|
||||||
self.tile_size = tile_size
|
self.tile_size = tile_size
|
||||||
self.tiles_x = tiles_x
|
self.tiles_x = tiles_x
|
||||||
self.tiles_y = tiles_y
|
self.tiles_y = tiles_y
|
||||||
|
|
||||||
#dodanie grafik wszystkich typów terenu do jednej listy
|
# dodanie grafik wszystkich typów terenu do jednej listy
|
||||||
self.tile_palette=[None]*20
|
self.tile_palette = [None] * 20
|
||||||
image = pygame.image.load("assets/sprites/sand.png")
|
image = pygame.image.load("assets/sprites/sand.png")
|
||||||
image = pygame.transform.scale(image, (tile_size,tile_size))
|
image = pygame.transform.scale(image, (tile_size, tile_size))
|
||||||
self.tile_palette[0]=image
|
self.tile_palette[0] = image
|
||||||
|
|
||||||
image = pygame.image.load("assets/sprites/stone.png")
|
image = pygame.image.load("assets/sprites/stone.png")
|
||||||
image = pygame.transform.scale(image, (tile_size,tile_size))
|
image = pygame.transform.scale(image, (tile_size, tile_size))
|
||||||
self.tile_palette[10]=image
|
self.tile_palette[10] = image
|
||||||
|
|
||||||
image = pygame.image.load("assets/sprites/grass.png")
|
image = pygame.image.load("assets/sprites/grass.png")
|
||||||
image = pygame.transform.scale(image, (tile_size,tile_size))
|
image = pygame.transform.scale(image, (tile_size, tile_size))
|
||||||
self.tile_palette[5]=image
|
self.tile_palette[5] = image
|
||||||
|
|
||||||
def generate(self):
|
def generate(self):
|
||||||
#generowanie terenu
|
# generowanie terenu
|
||||||
matrix = []
|
matrix = []
|
||||||
for i in range(self.tiles_y):
|
for i in range(self.tiles_y):
|
||||||
matrix.append([])
|
matrix.append([])
|
||||||
for j in range(self.tiles_x):
|
for j in range(self.tiles_x):
|
||||||
#sprawdza czy są tu jakieś klify
|
# sprawdza czy są tu jakieś klify
|
||||||
ok = True
|
ok = True
|
||||||
for cliff in self.cliffs:
|
for cliff in self.cliffs:
|
||||||
for i2 in range(i-1,i+2):
|
for i2 in range(i - 1, i + 2):
|
||||||
if (j, i2) == (cliff.position_x, cliff.position_y):
|
if (j, i2) == (cliff.position_x, cliff.position_y):
|
||||||
ok = False
|
ok = False
|
||||||
break
|
break
|
||||||
elif (j-1, i2) == (cliff.position_x, cliff.position_y):
|
elif (j - 1, i2) == (cliff.position_x, cliff.position_y):
|
||||||
ok = False
|
ok = False
|
||||||
break
|
break
|
||||||
elif (j+1, i2) == (cliff.position_x, cliff.position_y):
|
elif (j + 1, i2) == (cliff.position_x, cliff.position_y):
|
||||||
ok = False
|
ok = False
|
||||||
break
|
break
|
||||||
#od liczby zależy jaki teren, np. 0 - piasek
|
# od liczby zależy jaki teren, np. 0 - piasek
|
||||||
rng = randrange(10)
|
rng = randrange(10)
|
||||||
if ok and rng==0 and not (i<2 and j<3):
|
if ok and rng == 0 and not (i < 2 and j < 3):
|
||||||
matrix[i].append(10) #kamień
|
matrix[i].append(10) # kamień
|
||||||
elif ok and rng>6 and not (i<2 and j<3):
|
elif ok and rng > 6 and not (i < 2 and j < 3):
|
||||||
matrix[i].append(5) #trawa
|
matrix[i].append(5) # trawa
|
||||||
elif ok and rng<2 and not (i<2 and j<3):
|
elif ok and rng < 2 and not (i < 2 and j < 3):
|
||||||
matrix[i].append(0) #piasek
|
matrix[i].append(0) # piasek
|
||||||
rand_rotate = 0#randrange(4)*90
|
rand_rotate = 0 # randrange(4)*90
|
||||||
if rand_rotate==0 and j+3<self.tiles_x and not (i==0 or i==self.tiles_y-1 or j==0 or j==self.tiles_x-1):
|
if rand_rotate == 0 and j + 3 < self.tiles_x and not (
|
||||||
cliff = Cliff(j,i,self.tile_size, rand_rotate, type=2)
|
i == 0 or i == self.tiles_y - 1 or j == 0 or j == self.tiles_x - 1):
|
||||||
#self.cliffs.append(cliff)
|
cliff = Cliff(j, i, self.tile_size, rand_rotate, type=2)
|
||||||
cliff = Cliff(j+1,i,self.tile_size, rand_rotate, type=0)
|
# self.cliffs.append(cliff)
|
||||||
#self.cliffs.append(cliff)
|
cliff = Cliff(j + 1, i, self.tile_size, rand_rotate, type=0)
|
||||||
cliff = Cliff(j+2,i,self.tile_size, rand_rotate, type=3)
|
# self.cliffs.append(cliff)
|
||||||
#self.cliffs.append(cliff)
|
cliff = Cliff(j + 2, i, self.tile_size, rand_rotate, type=3)
|
||||||
|
# self.cliffs.append(cliff)
|
||||||
else:
|
else:
|
||||||
matrix[i].append(0)
|
matrix[i].append(0)
|
||||||
self.terrain_matrix = matrix
|
self.terrain_matrix = matrix
|
||||||
|
|
||||||
for i in range(self.tiles_y):
|
for i in range(self.tiles_y):
|
||||||
for j in range(self.tiles_x):
|
for j in range(self.tiles_x):
|
||||||
if matrix[i][j]<10:
|
if matrix[i][j] < 10:
|
||||||
ok = True
|
ok = True
|
||||||
for cliff in self.cliffs:
|
for cliff in self.cliffs:
|
||||||
if (j, i) == (cliff.position_x, cliff.position_y):
|
if (j, i) == (cliff.position_x, cliff.position_y):
|
||||||
ok = False
|
ok = False
|
||||||
break
|
break
|
||||||
if ok and randrange(10)==0 and not (i<2 and j<3):
|
if ok and randrange(10) == 0 and not (i < 2 and j < 3):
|
||||||
difficulty = randrange(0,4)+1
|
difficulty = randrange(0, 4) + 1
|
||||||
weight = randrange(10, 31)/10
|
weight = randrange(10, 31) / 10
|
||||||
timer = randrange(100, 200)
|
timer = randrange(100, 200)
|
||||||
mine = Mine(j, i, self.tile_size, difficulty, weight, timer)
|
mine = Mine(j, i, self.tile_size, difficulty, weight, timer)
|
||||||
self.mines.append(mine)
|
self.mines.append(mine)
|
||||||
|
|
||||||
def draw_tiles(self):
|
def draw_tiles(self):
|
||||||
#narysowanie na ekranie terenu
|
# narysowanie na ekranie terenu
|
||||||
for i in range(len(self.terrain_matrix)):
|
for i in range(len(self.terrain_matrix)):
|
||||||
for j in range(len(self.terrain_matrix[i])):
|
for j in range(len(self.terrain_matrix[i])):
|
||||||
self.window.window.blit(self.tile_palette[self.terrain_matrix[i][j]], (self.tile_size*j, self.tile_size*i))
|
self.window.window.blit(self.tile_palette[self.terrain_matrix[i][j]],
|
||||||
|
(self.tile_size * j, self.tile_size * i))
|
||||||
|
|
||||||
def draw_objects(self):
|
def draw_objects(self):
|
||||||
for mine in self.mines:
|
for mine in self.mines:
|
||||||
@ -181,217 +184,216 @@ class Map:
|
|||||||
for cliff in self.cliffs:
|
for cliff in self.cliffs:
|
||||||
cliff.draw(self.window.window)
|
cliff.draw(self.window.window)
|
||||||
|
|
||||||
#broń
|
|
||||||
|
# broń
|
||||||
class Weapon:
|
class Weapon:
|
||||||
size:int
|
size: int
|
||||||
image:pygame.surface.Surface
|
image: pygame.surface.Surface
|
||||||
rotated_image:pygame.surface.Surface
|
rotated_image: pygame.surface.Surface
|
||||||
|
|
||||||
owner:str
|
owner: str
|
||||||
weight:float
|
weight: float
|
||||||
weapon_type:int
|
weapon_type: int
|
||||||
|
|
||||||
#baza operacji
|
|
||||||
|
# baza operacji
|
||||||
class Base:
|
class Base:
|
||||||
position_x:int
|
position_x: int
|
||||||
position_y:int
|
position_y: int
|
||||||
size:int
|
size: int
|
||||||
image:pygame.surface.Surface
|
image: pygame.surface.Surface
|
||||||
|
|
||||||
weapon_level:int
|
weapon_level: int
|
||||||
weapons=[]
|
weapons = []
|
||||||
|
|
||||||
#schron
|
|
||||||
|
# schron
|
||||||
class Shelter:
|
class Shelter:
|
||||||
position_x:int
|
position_x: int
|
||||||
position_y:int
|
position_y: int
|
||||||
size:int
|
size: int
|
||||||
image:pygame.surface.Surface
|
image: pygame.surface.Surface
|
||||||
|
|
||||||
#składowisko
|
|
||||||
|
# składowisko
|
||||||
class Dumpster:
|
class Dumpster:
|
||||||
position_x:int
|
position_x: int
|
||||||
position_y:int
|
position_y: int
|
||||||
size:int
|
size: int
|
||||||
image:pygame.surface.Surface
|
image: pygame.surface.Surface
|
||||||
|
|
||||||
|
|
||||||
#cywile
|
# cywile
|
||||||
class NPC:
|
class NPC:
|
||||||
position_x:int
|
position_x: int
|
||||||
position_y:int
|
position_y: int
|
||||||
size:int
|
size: int
|
||||||
image:pygame.surface.Surface
|
image: pygame.surface.Surface
|
||||||
rotated_image:pygame.surface.Surface
|
rotated_image: pygame.surface.Surface
|
||||||
offset_x:int=0
|
offset_x: int = 0
|
||||||
offset_y:int=0
|
offset_y: int = 0
|
||||||
current_map:Map
|
current_map: Map
|
||||||
|
|
||||||
type:str
|
type: str
|
||||||
value:int
|
value: int
|
||||||
weight:float
|
weight: float
|
||||||
|
|
||||||
|
|
||||||
|
# saper
|
||||||
#saper
|
|
||||||
class Minesweeper:
|
class Minesweeper:
|
||||||
size:int
|
size: int
|
||||||
rotation_degrees:int
|
rotation_degrees: int
|
||||||
position_x:int
|
position_x: int
|
||||||
position_y:int
|
position_y: int
|
||||||
image:pygame.surface.Surface
|
image: pygame.surface.Surface
|
||||||
rotated_image:pygame.surface.Surface
|
rotated_image: pygame.surface.Surface
|
||||||
offset_x:int=0
|
offset_x: int = 0
|
||||||
offset_y:int=0
|
offset_y: int = 0
|
||||||
current_map:Map
|
current_map: Map
|
||||||
|
|
||||||
carried_objects=[]
|
carried_objects = []
|
||||||
|
|
||||||
speed=1
|
|
||||||
ability=1
|
|
||||||
max_carried_weight=5.0
|
|
||||||
|
|
||||||
|
speed = 1
|
||||||
|
ability = 1
|
||||||
|
max_carried_weight = 5.0
|
||||||
|
|
||||||
def __init__(self, position_x=0, position_y=0, size=64):
|
def __init__(self, position_x=0, position_y=0, size=64):
|
||||||
self.position_x=position_x
|
self.position_x = position_x
|
||||||
self.position_y=position_y
|
self.position_y = position_y
|
||||||
self.size = size
|
self.size = size
|
||||||
self.image = pygame.image.load("assets/sprites/saper_fun_sized.png")
|
self.image = pygame.image.load("assets/sprites/saper_fun_sized.png")
|
||||||
self.image = pygame.transform.scale(self.image, (self.size, self.size))
|
self.image = pygame.transform.scale(self.image, (self.size, self.size))
|
||||||
self.rotated_image = self.image
|
self.rotated_image = self.image
|
||||||
self.rotation_degrees=0
|
self.rotation_degrees = 0
|
||||||
|
|
||||||
def set_map(self, map:Map):
|
def set_map(self, map: Map):
|
||||||
self.current_map = map
|
self.current_map = map
|
||||||
|
|
||||||
def update_offset(self, delta:float):
|
def update_offset(self, delta: float):
|
||||||
dist=round(self.speed*delta/8)
|
dist = round(self.speed * delta / 8)
|
||||||
finished=False
|
finished = False
|
||||||
if self.offset_x>0:
|
if self.offset_x > 0:
|
||||||
self.offset_x-=dist
|
self.offset_x -= dist
|
||||||
if self.offset_x<=0:
|
if self.offset_x <= 0:
|
||||||
finished=True
|
finished = True
|
||||||
elif self.offset_x<0:
|
elif self.offset_x < 0:
|
||||||
self.offset_x+=dist
|
self.offset_x += dist
|
||||||
if self.offset_x>=0:
|
if self.offset_x >= 0:
|
||||||
finished=True
|
finished = True
|
||||||
if self.offset_y>0:
|
if self.offset_y > 0:
|
||||||
self.offset_y-=dist
|
self.offset_y -= dist
|
||||||
if self.offset_y<=0:
|
if self.offset_y <= 0:
|
||||||
finished=True
|
finished = True
|
||||||
elif self.offset_y<0:
|
elif self.offset_y < 0:
|
||||||
self.offset_y+=dist
|
self.offset_y += dist
|
||||||
if self.offset_y<-self.size and self.offset_y>-1.2*self.size:
|
if self.offset_y < -self.size and self.offset_y > -1.2 * self.size:
|
||||||
pygame.mixer.Channel(1).play(pygame.mixer.Sound("assets/sounds/ledge.wav"))
|
pygame.mixer.Channel(1).play(pygame.mixer.Sound("assets/sounds/ledge.wav"))
|
||||||
if self.offset_y>=0:
|
if self.offset_y >= 0:
|
||||||
finished=True
|
finished = True
|
||||||
|
|
||||||
if finished:
|
if finished:
|
||||||
pygame.mixer.Channel(1).stop()
|
pygame.mixer.Channel(1).stop()
|
||||||
self.offset_y=0
|
self.offset_y = 0
|
||||||
self.offset_x=0
|
self.offset_x = 0
|
||||||
if self.current_map.terrain_matrix[self.position_y][self.position_x]<5:
|
if self.current_map.terrain_matrix[self.position_y][self.position_x] < 5:
|
||||||
self.speed=1
|
self.speed = 1
|
||||||
|
|
||||||
|
def draw(self, window, delta: float):
|
||||||
def draw(self, window, delta:float):
|
position_on_screen = (self.size * self.position_x + self.offset_x, self.size * self.position_y + self.offset_y)
|
||||||
position_on_screen = (self.size*self.position_x + self.offset_x, self.size*self.position_y + self.offset_y)
|
|
||||||
window.blit(self.rotated_image, position_on_screen)
|
window.blit(self.rotated_image, position_on_screen)
|
||||||
self.update_offset(delta)
|
self.update_offset(delta)
|
||||||
|
|
||||||
def rotate(self, dir:str):
|
def rotate(self, dir: str):
|
||||||
dirr=0
|
dirr = 0
|
||||||
if dir=="N":
|
if dir == "N":
|
||||||
dirr=180
|
dirr = 180
|
||||||
elif dir=="S":
|
elif dir == "S":
|
||||||
dirr=0
|
dirr = 0
|
||||||
elif dir=="W":
|
elif dir == "W":
|
||||||
dirr=270
|
dirr = 270
|
||||||
elif dir=="E":
|
elif dir == "E":
|
||||||
dirr=90
|
dirr = 90
|
||||||
|
|
||||||
elif dir=="left":
|
elif dir == "left":
|
||||||
dirr = (self.rotation_degrees+90) % 360
|
dirr = (self.rotation_degrees + 90) % 360
|
||||||
elif dir=="right":
|
elif dir == "right":
|
||||||
dirr = (self.rotation_degrees-90) % 360
|
dirr = (self.rotation_degrees - 90) % 360
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.rotation_degrees=dirr
|
self.rotation_degrees = dirr
|
||||||
self.rotated_image = pygame.transform.rotate(self.image, dirr)
|
self.rotated_image = pygame.transform.rotate(self.image, dirr)
|
||||||
|
|
||||||
|
def move(self, dir: int = -1):
|
||||||
def move(self, dir:int=-1):
|
# południe - 0
|
||||||
#południe - 0
|
# wschód - 90
|
||||||
#wschód - 90
|
# północ - 180
|
||||||
#północ - 180
|
# zachód - 270
|
||||||
#zachód - 270
|
if self.offset_x != 0 or self.offset_y != 0:
|
||||||
if self.offset_x!=0 or self.offset_y!=0:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if dir==-1:
|
if dir == -1:
|
||||||
dir = self.rotation_degrees
|
dir = self.rotation_degrees
|
||||||
else:
|
else:
|
||||||
self.rotation_degrees=dir
|
self.rotation_degrees = dir
|
||||||
self.rotated_image = pygame.transform.rotate(self.image, dir)
|
self.rotated_image = pygame.transform.rotate(self.image, dir)
|
||||||
|
|
||||||
move_legal=True
|
move_legal = True
|
||||||
cliff_jump=False
|
cliff_jump = False
|
||||||
next_x=self.position_x
|
next_x = self.position_x
|
||||||
next_y=self.position_y
|
next_y = self.position_y
|
||||||
if dir==0:
|
if dir == 0:
|
||||||
next_y=self.position_y+1
|
next_y = self.position_y + 1
|
||||||
elif dir==180:
|
elif dir == 180:
|
||||||
next_y=self.position_y-1
|
next_y = self.position_y - 1
|
||||||
elif dir==270:
|
elif dir == 270:
|
||||||
next_x=self.position_x-1
|
next_x = self.position_x - 1
|
||||||
elif dir==90:
|
elif dir == 90:
|
||||||
next_x=self.position_x+1
|
next_x = self.position_x + 1
|
||||||
|
|
||||||
if next_x == self.current_map.tiles_x or next_x == -1:
|
if next_x == self.current_map.tiles_x or next_x == -1:
|
||||||
move_legal=False
|
move_legal = False
|
||||||
elif next_y == self.current_map.tiles_y or next_y == -1:
|
elif next_y == self.current_map.tiles_y or next_y == -1:
|
||||||
move_legal=False
|
move_legal = False
|
||||||
elif self.current_map.terrain_matrix[next_y][next_x]>9:
|
elif self.current_map.terrain_matrix[next_y][next_x] > 9:
|
||||||
move_legal=False
|
move_legal = False
|
||||||
|
|
||||||
for cliff in self.current_map.cliffs:
|
for cliff in self.current_map.cliffs:
|
||||||
if (next_x, next_y) == (cliff.position_x, cliff.position_y):
|
if (next_x, next_y) == (cliff.position_x, cliff.position_y):
|
||||||
if dir==0 and cliff.rotation==0:
|
if dir == 0 and cliff.rotation == 0:
|
||||||
cliff_jump=True
|
cliff_jump = True
|
||||||
else:
|
else:
|
||||||
move_legal=False
|
move_legal = False
|
||||||
|
|
||||||
if move_legal:
|
if move_legal:
|
||||||
if self.current_map.terrain_matrix[next_y][next_x]>4:
|
if self.current_map.terrain_matrix[next_y][next_x] > 4:
|
||||||
self.speed=0.5
|
self.speed = 0.5
|
||||||
pygame.mixer.Channel(1).set_volume(0.3)
|
pygame.mixer.Channel(1).set_volume(0.3)
|
||||||
pygame.mixer.Channel(1).play(pygame.mixer.Sound("assets/sounds/moving.wav"))
|
pygame.mixer.Channel(1).play(pygame.mixer.Sound("assets/sounds/moving.wav"))
|
||||||
if dir==0:
|
if dir == 0:
|
||||||
self.position_y+=1
|
self.position_y += 1
|
||||||
self.offset_y=-self.size
|
self.offset_y = -self.size
|
||||||
if cliff_jump:
|
if cliff_jump:
|
||||||
self.position_y+=1
|
self.position_y += 1
|
||||||
self.offset_y=-2*self.size
|
self.offset_y = -2 * self.size
|
||||||
elif dir==180:
|
elif dir == 180:
|
||||||
self.position_y-=1
|
self.position_y -= 1
|
||||||
self.offset_y=self.size
|
self.offset_y = self.size
|
||||||
elif dir==270:
|
elif dir == 270:
|
||||||
self.position_x-=1
|
self.position_x -= 1
|
||||||
self.offset_x=self.size
|
self.offset_x = self.size
|
||||||
elif dir==90:
|
elif dir == 90:
|
||||||
self.position_x+=1
|
self.position_x += 1
|
||||||
self.offset_x=-self.size
|
self.offset_x = -self.size
|
||||||
else:
|
else:
|
||||||
pygame.mixer.Channel(2).set_volume(0.5)
|
pygame.mixer.Channel(2).set_volume(0.5)
|
||||||
pygame.mixer.Channel(2).play(pygame.mixer.Sound("assets/sounds/collision.wav"))
|
pygame.mixer.Channel(2).play(pygame.mixer.Sound("assets/sounds/collision.wav"))
|
||||||
|
|
||||||
def pick_up(self):
|
def pick_up(self):
|
||||||
if self.offset_x!=0 or self.offset_y!=0:
|
if self.offset_x != 0 or self.offset_y != 0:
|
||||||
return
|
return
|
||||||
for mine in self.current_map.mines:
|
for mine in self.current_map.mines:
|
||||||
if (self.position_x, self.position_y) == (mine.position_x, mine.position_y):
|
if (self.position_x, self.position_y) == (mine.position_x, mine.position_y):
|
||||||
|
|
||||||
tree = decisionTrees.DecisionTrees()
|
tree = decisionTrees.DecisionTrees()
|
||||||
|
|
||||||
decision = tree.return_predict()
|
decision = tree.return_predict()
|
||||||
@ -408,40 +410,40 @@ class Minesweeper:
|
|||||||
def drop_civilians(self):
|
def drop_civilians(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def sensor(self, x:int=-1, y:int=-1):
|
def sensor(self, x: int = -1, y: int = -1):
|
||||||
if x==-1:
|
if x == -1:
|
||||||
x = self.position_x
|
x = self.position_x
|
||||||
if y==-1:
|
if y == -1:
|
||||||
y = self.position_y
|
y = self.position_y
|
||||||
sensor_list = [["","",""],["","",""],["","",""]]
|
sensor_list = [["", "", ""], ["", "", ""], ["", "", ""]]
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
for j in range(3):
|
for j in range(3):
|
||||||
posx = x-1+j
|
posx = x - 1 + j
|
||||||
posy = y-1+i
|
posy = y - 1 + i
|
||||||
if posx >= self.current_map.tiles_x or posx <= -1:
|
if posx >= self.current_map.tiles_x or posx <= -1:
|
||||||
sensor_list[i][j]="wall"
|
sensor_list[i][j] = "wall"
|
||||||
elif posy >= self.current_map.tiles_y or posy <= -1:
|
elif posy >= self.current_map.tiles_y or posy <= -1:
|
||||||
sensor_list[i][j]="wall"
|
sensor_list[i][j] = "wall"
|
||||||
elif self.current_map.terrain_matrix[posy][posx]>9:
|
elif self.current_map.terrain_matrix[posy][posx] > 9:
|
||||||
sensor_list[i][j]="wall"
|
sensor_list[i][j] = "wall"
|
||||||
elif self.current_map.terrain_matrix[posy][posx]>4:
|
elif self.current_map.terrain_matrix[posy][posx] > 4:
|
||||||
sensor_list[i][j]="grass"
|
sensor_list[i][j] = "grass"
|
||||||
else:
|
else:
|
||||||
sensor_list[i][j]="sand"
|
sensor_list[i][j] = "sand"
|
||||||
for cliff in self.current_map.cliffs:
|
for cliff in self.current_map.cliffs:
|
||||||
if (posx, posy) == (cliff.position_x, cliff.position_y):
|
if (posx, posy) == (cliff.position_x, cliff.position_y):
|
||||||
if cliff.rotation==0:
|
if cliff.rotation == 0:
|
||||||
sensor_list[i][j]="cliff_south"
|
sensor_list[i][j] = "cliff_south"
|
||||||
elif cliff.rotation==90:
|
elif cliff.rotation == 90:
|
||||||
sensor_list[i][j]="cliff_east"
|
sensor_list[i][j] = "cliff_east"
|
||||||
elif cliff.rotation==180:
|
elif cliff.rotation == 180:
|
||||||
sensor_list[i][j]="cliff_north"
|
sensor_list[i][j] = "cliff_north"
|
||||||
elif cliff.rotation==270:
|
elif cliff.rotation == 270:
|
||||||
sensor_list[i][j]="cliff_west"
|
sensor_list[i][j] = "cliff_west"
|
||||||
break
|
break
|
||||||
for mine in self.current_map.mines:
|
for mine in self.current_map.mines:
|
||||||
if (posx, posy) == (mine.position_x, mine.position_y):
|
if (posx, posy) == (mine.position_x, mine.position_y):
|
||||||
sensor_list[i][j]="mine"
|
sensor_list[i][j] = "mine"
|
||||||
break
|
break
|
||||||
|
|
||||||
return sensor_list
|
return sensor_list
|
@ -1,96 +1,97 @@
|
|||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
|
|
||||||
class Window:
|
class Window:
|
||||||
window:None
|
window: None
|
||||||
width:int
|
width: int
|
||||||
height:int
|
height: int
|
||||||
title:str
|
title: str
|
||||||
icon_path:str
|
icon_path: str
|
||||||
paused:bool
|
paused: bool
|
||||||
pause_menu:None
|
pause_menu: None
|
||||||
|
|
||||||
search: pygame.Surface
|
search: pygame.Surface
|
||||||
|
|
||||||
def __init__(self, width:int=640, height:int=480, title="", icon_path=""):
|
def __init__(self, width: int = 640, height: int = 480, title="", icon_path=""):
|
||||||
self.set_resolution(width,height)
|
self.set_resolution(width, height)
|
||||||
self.set_title(title)
|
self.set_title(title)
|
||||||
self.set_icon(icon_path)
|
self.set_icon(icon_path)
|
||||||
self.mount()
|
self.mount()
|
||||||
self.paused=False
|
self.paused = False
|
||||||
|
|
||||||
self.pause_menu = pygame.Surface((width, height))
|
self.pause_menu = pygame.Surface((width, height))
|
||||||
self.pause_menu.set_alpha(128)
|
self.pause_menu.set_alpha(128)
|
||||||
self.pause_menu.fill((0,0,0))
|
self.pause_menu.fill((0, 0, 0))
|
||||||
self.search = pygame.Surface((width, height), flags=pygame.SRCALPHA)
|
self.search = pygame.Surface((width, height), flags=pygame.SRCALPHA)
|
||||||
|
|
||||||
def set_resolution(self, width:int, height:int):
|
def set_resolution(self, width: int, height: int):
|
||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
|
|
||||||
def set_title(self, title:str):
|
def set_title(self, title: str):
|
||||||
self.title=title
|
self.title = title
|
||||||
|
|
||||||
def set_icon(self, icon_path:str):
|
def set_icon(self, icon_path: str):
|
||||||
self.icon_path= icon_path
|
self.icon_path = icon_path
|
||||||
|
|
||||||
def mount(self):
|
def mount(self):
|
||||||
self.window = pygame.display.set_mode((self.width,self.height))
|
self.window = pygame.display.set_mode((self.width, self.height))
|
||||||
pygame.display.set_caption(self.title)
|
pygame.display.set_caption(self.title)
|
||||||
if self.icon_path != "":
|
if self.icon_path != "":
|
||||||
icon = pygame.image.load(self.icon_path)
|
icon = pygame.image.load(self.icon_path)
|
||||||
pygame.display.set_icon(icon)
|
pygame.display.set_icon(icon)
|
||||||
|
|
||||||
def pause(self, paused:bool):
|
def pause(self, paused: bool):
|
||||||
self.paused=paused
|
self.paused = paused
|
||||||
if self.paused:
|
if self.paused:
|
||||||
self.window.blit(self.pause_menu,(0,0))
|
self.window.blit(self.pause_menu, (0, 0))
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
|
||||||
def draw_search(self, pos1:list=[0,0], pos2:list=[0,0], tile_size:int=64, map=None, saper=None):
|
def draw_search(self, pos1: list = [0, 0], pos2: list = [0, 0], tile_size: int = 64, map=None, saper=None):
|
||||||
map.draw_tiles()
|
map.draw_tiles()
|
||||||
map.draw_objects()
|
map.draw_objects()
|
||||||
saper.draw(self.window, 0.1)
|
saper.draw(self.window, 0.1)
|
||||||
self.window.blit(self.pause_menu,(0,0))
|
self.window.blit(self.pause_menu, (0, 0))
|
||||||
self.search = pygame.Surface((self.width, self.height), flags=pygame.SRCALPHA)
|
self.search = pygame.Surface((self.width, self.height), flags=pygame.SRCALPHA)
|
||||||
pos1 = [pos1[0]*tile_size+(tile_size/2), pos1[1]*tile_size+(tile_size/2)]
|
pos1 = [pos1[0] * tile_size + (tile_size / 2), pos1[1] * tile_size + (tile_size / 2)]
|
||||||
pos2 = [pos2[0]*tile_size+(tile_size/2), pos2[1]*tile_size+(tile_size/2)]
|
pos2 = [pos2[0] * tile_size + (tile_size / 2), pos2[1] * tile_size + (tile_size / 2)]
|
||||||
pygame.draw.line(self.search, pygame.Color(255,0,0), pos1, pos2, 5)
|
pygame.draw.line(self.search, pygame.Color(255, 0, 0), pos1, pos2, 5)
|
||||||
|
|
||||||
n = 10
|
n = 10
|
||||||
p1=0
|
p1 = 0
|
||||||
p2=0
|
p2 = 0
|
||||||
p3=0
|
p3 = 0
|
||||||
if (pos2[0] - pos1[0])!=0:
|
if (pos2[0] - pos1[0]) != 0:
|
||||||
a1 = (pos2[1] - pos1[1])/(pos2[0] - pos1[0])
|
a1 = (pos2[1] - pos1[1]) / (pos2[0] - pos1[0])
|
||||||
b1 = (pos1[1] - a1*pos1[0])
|
b1 = (pos1[1] - a1 * pos1[0])
|
||||||
if a1!=0:
|
if a1 != 0:
|
||||||
a2 = -(1/a1)
|
a2 = -(1 / a1)
|
||||||
b2 = pos2[1] - a2*pos2[0]
|
b2 = pos2[1] - a2 * pos2[0]
|
||||||
y = a2*(pos2[0]+n)+b2
|
y = a2 * (pos2[0] + n) + b2
|
||||||
p1 = (pos2[0]+n, y)
|
p1 = (pos2[0] + n, y)
|
||||||
y = a2*(pos2[0]-n)+b2
|
y = a2 * (pos2[0] - n) + b2
|
||||||
p2 = (pos2[0]-n, y)
|
p2 = (pos2[0] - n, y)
|
||||||
if pos1[0]>pos2[0]:
|
if pos1[0] > pos2[0]:
|
||||||
y = a1*(pos2[0]-n)+b1
|
y = a1 * (pos2[0] - n) + b1
|
||||||
p3 = (pos2[0]-n, y)
|
p3 = (pos2[0] - n, y)
|
||||||
else:
|
else:
|
||||||
y = a1*(pos2[0]+n)+b1
|
y = a1 * (pos2[0] + n) + b1
|
||||||
p3 = (pos2[0]+n, y)
|
p3 = (pos2[0] + n, y)
|
||||||
else:
|
else:
|
||||||
p1 = (pos2[0], pos2[1]+n)
|
p1 = (pos2[0], pos2[1] + n)
|
||||||
p2 = (pos2[0], pos2[1]-n)
|
p2 = (pos2[0], pos2[1] - n)
|
||||||
if pos1[0]>pos2[0]:
|
if pos1[0] > pos2[0]:
|
||||||
p3 = (pos2[0]-n, pos2[1])
|
p3 = (pos2[0] - n, pos2[1])
|
||||||
else:
|
else:
|
||||||
p3 = (pos2[0]+n, pos2[1])
|
p3 = (pos2[0] + n, pos2[1])
|
||||||
else:
|
else:
|
||||||
p1 = (pos2[0]-n, pos2[1])
|
p1 = (pos2[0] - n, pos2[1])
|
||||||
p2 = (pos2[0]+n, pos2[1])
|
p2 = (pos2[0] + n, pos2[1])
|
||||||
if pos1[1]>pos2[1]:
|
if pos1[1] > pos2[1]:
|
||||||
p3 = (pos2[0], pos2[1]-n)
|
p3 = (pos2[0], pos2[1] - n)
|
||||||
else:
|
else:
|
||||||
p3 = (pos2[0], pos2[1]+n)
|
p3 = (pos2[0], pos2[1] + n)
|
||||||
|
|
||||||
pygame.draw.polygon(self.search, pygame.Color(255,0,0), (p1,p2,p3))
|
pygame.draw.polygon(self.search, pygame.Color(255, 0, 0), (p1, p2, p3))
|
||||||
self.window.blit(self.search, (0,0))
|
self.window.blit(self.search, (0, 0))
|
||||||
pygame.display.update()
|
pygame.display.update()
|
6
main.py
6
main.py
@ -1,6 +1,7 @@
|
|||||||
# pygame - biblioteka do symulacji graficznych
|
# pygame - biblioteka do symulacji graficznych
|
||||||
from multiprocessing import freeze_support
|
from multiprocessing import freeze_support
|
||||||
import os
|
import os
|
||||||
|
|
||||||
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
|
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
|
||||||
import pygame
|
import pygame
|
||||||
# system - klasy związane z pygame
|
# system - klasy związane z pygame
|
||||||
@ -19,9 +20,10 @@ MUSIC = False
|
|||||||
# ustalenie FPS
|
# ustalenie FPS
|
||||||
FPS = 60
|
FPS = 60
|
||||||
|
|
||||||
#włączenie tekstu
|
# włączenie tekstu
|
||||||
pygame.font.init()
|
pygame.font.init()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if MUSIC:
|
if MUSIC:
|
||||||
pygame.mixer.init()
|
pygame.mixer.init()
|
||||||
@ -77,7 +79,7 @@ def main():
|
|||||||
pygame.quit()
|
pygame.quit()
|
||||||
elif event.type in [i.timer_event for i in map.mines]:
|
elif event.type in [i.timer_event for i in map.mines]:
|
||||||
for i in map.mines:
|
for i in map.mines:
|
||||||
i.explosion_timer-=1
|
i.explosion_timer -= 1
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user