snake_move #16
17
App.py
17
App.py
@ -6,19 +6,21 @@ import time
|
||||
import displayControler as dCon
|
||||
import Image
|
||||
import Osprzet
|
||||
import Ui
|
||||
|
||||
|
||||
pygame.init()
|
||||
screen = pygame.display.set_mode((dCon.getScreenWidth(), dCon.getScreenHeihgt()))
|
||||
|
||||
FPS=5
|
||||
clock=pygame.time.Clock()
|
||||
image_loader=Image.Image()
|
||||
image_loader.load_images()
|
||||
pole=Pole.Pole(screen,image_loader)
|
||||
pole.draw_grid() #musi byc tutaj wywołane ponieważ inicjalizuje sloty do slownika
|
||||
|
||||
ui=Ui.Ui(screen)
|
||||
#Tractor creation
|
||||
traktor_slot = pole.get_slot_from_cord((0, 0))
|
||||
traktor = Tractor.Tractor(traktor_slot, screen, Osprzet.plug)
|
||||
traktor = Tractor.Tractor(traktor_slot, screen, Osprzet.plug,clock)
|
||||
|
||||
|
||||
def init_demo(): #Demo purpose
|
||||
@ -27,8 +29,14 @@ def init_demo(): #Demo purpose
|
||||
time.sleep(2)
|
||||
pole.randomize_colors()
|
||||
traktor.draw_tractor()
|
||||
start_flag=True
|
||||
while True:
|
||||
time.sleep(0.5)
|
||||
clock.tick(FPS)
|
||||
if(start_flag):
|
||||
ui.render_text_to_console(string_to_print="Przejazd inicjalizujacy- traktor sprawdza poziom nawodnienia")
|
||||
traktor.initial_move(pole)
|
||||
traktor.reset_pos(pole)
|
||||
start_flag=False
|
||||
demo_move()
|
||||
old_info=get_info(old_info)
|
||||
for event in pygame.event.get():
|
||||
@ -42,6 +50,7 @@ def init(demo):
|
||||
#TODO: Implement
|
||||
|
||||
|
||||
|
||||
def demo_move():
|
||||
current_slot = traktor.slot
|
||||
if current_slot:
|
||||
|
@ -78,5 +78,11 @@ class Roslina:
|
||||
self.stan.checkStan()
|
||||
return
|
||||
|
||||
def return_stan(self):
|
||||
return self.stan
|
||||
|
||||
def get_hydrate_stats(self):
|
||||
return self.stan.return_hydrate()
|
||||
|
||||
def report_status(self):
|
||||
return f"Nazwa rosliny: {self.nazwa} "+self.stan.report_all()
|
9
Slot.py
9
Slot.py
@ -42,6 +42,13 @@ class Slot:
|
||||
|
||||
def random_plant(self): #Probably will not be used later only for demo purpouse
|
||||
return self.image_loader.return_random_plant()
|
||||
|
||||
def return_plant(self):
|
||||
return self.plant
|
||||
|
||||
def get_hydrate_stats(self):
|
||||
return self.plant.get_hydrate_stats()
|
||||
|
||||
def print_status(self):
|
||||
return f"wspolrzedne: (X:{self.x_axis} Y:{self.y_axis}) "+self.plant.report_status()
|
||||
return f"wspolrzedne: (X:{self.x_axis} Y:{self.y_axis}) "+self.plant.report_status()
|
||||
|
3
Stan.py
3
Stan.py
@ -44,5 +44,8 @@ class Stan:
|
||||
self.akcja = None
|
||||
return
|
||||
|
||||
def return_hydrate(self):
|
||||
return self.nawodnienie
|
||||
|
||||
def report_all(self):
|
||||
return f"Nawodnienie: {self.nawodnienie} Zyznosc: {self.zyznosc} Wzrost: {self.wzrost} Choroba: {self.choroba}"
|
32
Tractor.py
32
Tractor.py
@ -92,7 +92,7 @@ class Tractor:
|
||||
DIRECTION_SOUTH = 'S'
|
||||
DIRECTION_WEST = 'W'
|
||||
DIRECTION_EAST = 'E'
|
||||
def __init__(self,slot,screen, osprzet):
|
||||
def __init__(self,slot,screen, osprzet,clock):
|
||||
self.tractor_images = {
|
||||
Tractor.DIRECTION_NORTH: pygame.transform.scale(pygame.image.load('images/traktorN.png'),
|
||||
(dCon.CUBE_SIZE, dCon.CUBE_SIZE)),
|
||||
@ -108,6 +108,8 @@ class Tractor:
|
||||
self.screen=screen
|
||||
self.slot=slot
|
||||
self.osprzet = osprzet
|
||||
self.clock=clock
|
||||
self.slot_hydrate_dict={}
|
||||
|
||||
|
||||
def draw_tractor(self):
|
||||
@ -162,18 +164,40 @@ class Tractor:
|
||||
self.slot.redraw_image()
|
||||
self.slot = next_slot
|
||||
self.draw_tractor()
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def random_move(self, pole):
|
||||
self.clock.tick(2)
|
||||
# losowanie skrętu
|
||||
turn_direction = random.choice([self.turn_left, self.turn_right])
|
||||
turn_direction()
|
||||
time.sleep(0.5)
|
||||
self.clock.tick(5)
|
||||
# wykonanie ruchu do przodu z uwzględnieniem aktualnej orientacji
|
||||
self.move_forward(pole)
|
||||
|
||||
def snake_move(self,pole):
|
||||
pass
|
||||
def reset_pos(self,pole):
|
||||
self.do_move_if_valid(pole,(0,0))
|
||||
|
||||
def initial_move(self,pole):
|
||||
for y in range (0,12):
|
||||
if(y%2==0):
|
||||
for x in range(0,20):
|
||||
self.snake_move(pole,x,y)
|
||||
else:
|
||||
for x in range(20,0,-1):
|
||||
self.snake_move(pole,x,y)
|
||||
|
||||
|
||||
def snake_move(self,pole,x,y):
|
||||
next_slot_coordinates=(x,y)
|
||||
if(self.do_move_if_valid(pole,next_slot_coordinates)):
|
||||
self.slot_hydrate_dict[(x,y)]= pole.get_slot_from_cord((x,y)).get_hydrate_stats() #Budowanie slownika slotow z poziomem nawodnienia dla traktorka
|
||||
self.clock.tick(10)
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
quit()
|
||||
|
||||
#to tak zrobiłam już na później, może się przyda
|
||||
def change_osprzet(self, new_osprzet):
|
||||
|
19
Ui.py
19
Ui.py
@ -7,10 +7,25 @@ class Ui:
|
||||
def __init__(self,screen):
|
||||
self.screen=screen
|
||||
self.font='freesansbold.ttf' #Feel free to change it :D
|
||||
self.font_size=int(32)
|
||||
self.font_size=int(16)
|
||||
def render_text(self,string_to_print):
|
||||
font=pygame.font.Font(self.font,self.font_size)
|
||||
text=font.render(string_to_print,True,Colors.BLACK,Colors.WHITE)
|
||||
textRect=text.get_rect()
|
||||
textRect.center=(dCon.getScreenWidth() // 2,dCon.getScreenHeihgt() // 2)
|
||||
self.screen.blit(text,textRect)
|
||||
self.screen.blit(text,textRect)
|
||||
|
||||
def render_text_to_console(self,string_to_print):
|
||||
font=pygame.font.Font(self.font,self.font_size)
|
||||
self.break_string_to_console(string_to_print)
|
||||
line=10
|
||||
for string in self.to_print:
|
||||
text=font.render(string,True,Colors.BLACK,Colors.WHITE)
|
||||
textRect=text.get_rect()
|
||||
textRect.center=(dCon.getGameWidth()+350/2,line)
|
||||
textRect.scale_by(x=350,y=100)
|
||||
self.screen.blit(text,textRect)
|
||||
line=line+10
|
||||
|
||||
def break_string_to_console(self,string_to_print):
|
||||
self.to_print=string_to_print.split(" ")
|
||||
|
@ -10,8 +10,18 @@ def isValidMove(x, y):
|
||||
return False
|
||||
return True
|
||||
|
||||
def getScreenWidth():
|
||||
return NUM_X * CUBE_SIZE
|
||||
|
||||
def getScreenHeihgt():
|
||||
return NUM_Y * CUBE_SIZE
|
||||
return NUM_Y * CUBE_SIZE
|
||||
|
||||
def getGameWidth():
|
||||
return NUM_X * CUBE_SIZE
|
||||
|
||||
def getScreenWidth():
|
||||
return getGameWidth()+350
|
||||
|
||||
def getConsoleWidth():
|
||||
return 350
|
||||
|
||||
def getConsoleWidthCenter():
|
||||
return getScreenWidth()+getConsoleWidth()/2
|
Loading…
Reference in New Issue
Block a user