Dodano sprawdzenie czy szukane pole występuje w macierzy
This commit is contained in:
parent
c2237e1eba
commit
4138753bb0
8
field.py
8
field.py
@ -33,4 +33,10 @@ class field():
|
||||
self.field_matrix[position[1],position[0]] += value
|
||||
|
||||
def get_value(self,position):
|
||||
return self.field_matrix[position[1],position[0]]
|
||||
return self.field_matrix[position[1],position[0]]
|
||||
|
||||
def if_value(self,value):
|
||||
for i in value:
|
||||
if i in self.field_matrix:
|
||||
return 1
|
||||
return 0
|
4
main.py
4
main.py
@ -2,7 +2,7 @@ import pygame, sys
|
||||
import tractor,pathfinding,field,ui,Justyna,Kamila,Marcin,Piotrek
|
||||
from pygame.locals import *
|
||||
|
||||
pole = field.field()
|
||||
pole = field.field(1)
|
||||
path = pathfinding.pathfinding()
|
||||
traktor = tractor.tractor(pole)
|
||||
UI = ui.game_ui(traktor,pole)
|
||||
@ -41,6 +41,8 @@ while True:
|
||||
traktor.set_mode(3)
|
||||
if key[K_p]:
|
||||
path.pathfinding(traktor,pole,UI)
|
||||
if key[K_F9]:
|
||||
print(pole.if_value(traktor.get_modes_values()))
|
||||
if key[K_F10]:
|
||||
print(traktor.get_poz())
|
||||
if key[K_F11]:
|
||||
|
@ -33,10 +33,13 @@ class pathfinding():
|
||||
self.avaiable_value = [0,1,4,5]
|
||||
elif self.activity == 3:
|
||||
self.avaiable_value = [8]
|
||||
self.end_point = self.search(self.start_position,self.avaiable_value)
|
||||
if self.end_point == None:
|
||||
if self.field.if_value(self.traktor.get_modes_values()) == 0:
|
||||
print("Brak pola")
|
||||
elif self.start_position == self.end_point:
|
||||
return 0
|
||||
else:
|
||||
self.end_point = self.search(self.start_position,self.avaiable_value)
|
||||
|
||||
if self.start_position == self.end_point:
|
||||
self.traktor.work()
|
||||
else:
|
||||
self.route = self.a_star(self.start_position,self.end_point)
|
||||
|
10
tractor.py
10
tractor.py
@ -27,6 +27,16 @@ class tractor():
|
||||
def get_mode(self):
|
||||
return self.mode_value
|
||||
|
||||
def get_modes_values(self):
|
||||
if self.mode_value == 0:
|
||||
return [0, 1, 2, 3]
|
||||
elif self.mode_value == 1:
|
||||
return [1, 3, 5, 7]
|
||||
elif self.mode_value == 2:
|
||||
return [0, 1, 4, 5]
|
||||
elif self.mode_value == 3:
|
||||
return [8]
|
||||
|
||||
def get_mode_name(self):
|
||||
return self.modes[self.mode_value]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user