Compare commits

...

4 Commits

8 changed files with 106 additions and 15 deletions

20
App.py
View File

@ -6,19 +6,22 @@ import time
import displayControler as dCon
import Image
import Osprzet
import Ui
pygame.init()
screen = pygame.display.set_mode((dCon.getScreenWidth(), dCon.getScreenHeihgt()))
show_console=True
screen = pygame.display.set_mode((dCon.getScreenWidth(show_console), 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 +30,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 +51,7 @@ def init(demo):
#TODO: Implement
def demo_move():
current_slot = traktor.slot
if current_slot:

View File

@ -55,5 +55,8 @@ class Pole:
def check_collision(self,mouse_x,mouse_y):
mouse_x=math.floor(mouse_x/dCon.CUBE_SIZE)
mouse_y=math.floor(mouse_y/dCon.CUBE_SIZE)
collided=self.get_slot_from_cord((mouse_x,mouse_y))
return collided.print_status()
if(mouse_x<20):
if(mouse_y<12):
collided=self.get_slot_from_cord((mouse_x,mouse_y))
return collided.print_status()
return ""

View File

@ -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()

View File

@ -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()

View File

@ -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}"

View File

@ -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):
@ -154,20 +156,48 @@ class Tractor:
self.current_tractor_image = self.tractor_images[self.direction]
# sprawdzenie czy następny slot jest dobry
self.do_move_if_valid(pole,next_slot_coordinates)
def do_move_if_valid(self,pole, next_slot_coordinates):
if next_slot_coordinates and pole.is_valid_move(next_slot_coordinates):
next_slot = pole.get_slot_from_cord(next_slot_coordinates)
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 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):

21
Ui.py
View File

@ -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)
textRect.center=(dCon.getGameWidth() // 2,dCon.getScreenHeihgt() // 2)
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+18
def break_string_to_console(self,string_to_print):
self.to_print=string_to_print.split(" ")

View File

@ -10,8 +10,25 @@ def isValidMove(x, y):
return False
return True
def getScreenWidth():
def getGameWidth():
return NUM_X * CUBE_SIZE
def getScreenHeihgt():
return NUM_Y * CUBE_SIZE
return NUM_Y * CUBE_SIZE
def getScreenWidth(show_console):
screen_width=getGameWidth()
if(show_console):
screen_width=screen_width+350
return screen_width
def getConsoleWidth():
return 350
def getConsoleWidthCenter():
return getScreenWidth()+getConsoleWidth()/2