Compare commits
No commits in common. "9ca821bab87006e541cc6754e1645933c02a8c5d" and "999f28a405249882601625bbd082af1dc0988461" have entirely different histories.
9ca821bab8
...
999f28a405
20
App.py
20
App.py
@ -6,22 +6,19 @@ import time
|
||||
import displayControler as dCon
|
||||
import Image
|
||||
import Osprzet
|
||||
import Ui
|
||||
|
||||
|
||||
pygame.init()
|
||||
show_console=True
|
||||
screen = pygame.display.set_mode((dCon.getScreenWidth(show_console), dCon.getScreenHeihgt()))
|
||||
FPS=5
|
||||
clock=pygame.time.Clock()
|
||||
screen = pygame.display.set_mode((dCon.getScreenWidth(), dCon.getScreenHeihgt()))
|
||||
|
||||
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,clock)
|
||||
traktor = Tractor.Tractor(traktor_slot, screen, Osprzet.plug)
|
||||
|
||||
|
||||
def init_demo(): #Demo purpose
|
||||
@ -30,14 +27,8 @@ def init_demo(): #Demo purpose
|
||||
time.sleep(2)
|
||||
pole.randomize_colors()
|
||||
traktor.draw_tractor()
|
||||
start_flag=True
|
||||
while True:
|
||||
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
|
||||
time.sleep(0.5)
|
||||
demo_move()
|
||||
old_info=get_info(old_info)
|
||||
for event in pygame.event.get():
|
||||
@ -51,7 +42,6 @@ def init(demo):
|
||||
#TODO: Implement
|
||||
|
||||
|
||||
|
||||
def demo_move():
|
||||
current_slot = traktor.slot
|
||||
if current_slot:
|
||||
|
7
Pole.py
7
Pole.py
@ -55,8 +55,5 @@ 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)
|
||||
if(mouse_x<20):
|
||||
if(mouse_y<12):
|
||||
collided=self.get_slot_from_cord((mouse_x,mouse_y))
|
||||
return collided.print_status()
|
||||
return ""
|
||||
collided=self.get_slot_from_cord((mouse_x,mouse_y))
|
||||
return collided.print_status()
|
@ -78,11 +78,5 @@ 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,13 +42,6 @@ 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,8 +44,5 @@ 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}"
|
34
Tractor.py
34
Tractor.py
@ -92,7 +92,7 @@ class Tractor:
|
||||
DIRECTION_SOUTH = 'S'
|
||||
DIRECTION_WEST = 'W'
|
||||
DIRECTION_EAST = 'E'
|
||||
def __init__(self,slot,screen, osprzet,clock):
|
||||
def __init__(self,slot,screen, osprzet):
|
||||
self.tractor_images = {
|
||||
Tractor.DIRECTION_NORTH: pygame.transform.scale(pygame.image.load('images/traktorN.png'),
|
||||
(dCon.CUBE_SIZE, dCon.CUBE_SIZE)),
|
||||
@ -108,8 +108,6 @@ class Tractor:
|
||||
self.screen=screen
|
||||
self.slot=slot
|
||||
self.osprzet = osprzet
|
||||
self.clock=clock
|
||||
self.slot_hydrate_dict={}
|
||||
|
||||
|
||||
def draw_tractor(self):
|
||||
@ -156,48 +154,20 @@ 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()
|
||||
self.clock.tick(5)
|
||||
time.sleep(0.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
21
Ui.py
@ -7,25 +7,10 @@ class Ui:
|
||||
def __init__(self,screen):
|
||||
self.screen=screen
|
||||
self.font='freesansbold.ttf' #Feel free to change it :D
|
||||
self.font_size=int(16)
|
||||
self.font_size=int(32)
|
||||
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.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(" ")
|
||||
textRect.center=(dCon.getScreenWidth() // 2,dCon.getScreenHeihgt() // 2)
|
||||
self.screen.blit(text,textRect)
|
@ -10,25 +10,8 @@ def isValidMove(x, y):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def getGameWidth():
|
||||
def getScreenWidth():
|
||||
return NUM_X * CUBE_SIZE
|
||||
|
||||
|
||||
|
||||
|
||||
def getScreenHeihgt():
|
||||
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
|
||||
return NUM_Y * CUBE_SIZE
|
Loading…
Reference in New Issue
Block a user