Compare commits
8 Commits
1009851475
...
7c30177bf1
Author | SHA1 | Date | |
---|---|---|---|
|
7c30177bf1 | ||
|
09b65e9fd1 | ||
|
ff7e5c4b99 | ||
|
7de410c59a | ||
|
8ce604df46 | ||
|
eaaac9f277 | ||
|
af87ff2475 | ||
|
8dceac3ebe |
@ -7,6 +7,7 @@ Wymagane biblioteki do pobrania:
|
||||
```
|
||||
pip install pygame
|
||||
pip install python-dotenv
|
||||
pip install pytholog
|
||||
```
|
||||
|
||||
Stwórz plik `.env` w głównym folderze projektu o poniższej treści:
|
||||
|
23
src/tile.py
23
src/tile.py
@ -1,20 +1,29 @@
|
||||
import os
|
||||
import pygame
|
||||
from dotenv import find_dotenv, load_dotenv
|
||||
from kb import tractor_kb
|
||||
import pytholog as pl
|
||||
import random
|
||||
|
||||
class Tile(pygame.sprite.Sprite):
|
||||
def __init__(self, id, type, field):
|
||||
def __init__(self, id, field, type):
|
||||
super().__init__()
|
||||
self.id = id
|
||||
x = id%16
|
||||
y = id//16
|
||||
self.type = type
|
||||
|
||||
self.field = field
|
||||
self.set_type(type)
|
||||
self.rect = self.image.get_rect()
|
||||
|
||||
vegetables = tractor_kb.query(pl.Expr("warzywo(Nazwa_warzywa)"))
|
||||
random_vegetable = vegetables[random.randint(0, len(vegetables)-1)]['Nazwa_warzywa']
|
||||
self.set_type(random_vegetable)
|
||||
|
||||
self.faza = 'posadzono'
|
||||
|
||||
# you can set TILE_SIZE in the .env file to adjust the window size
|
||||
load_dotenv(find_dotenv())
|
||||
TILE_SIZE = int(os.getenv("TILE_SIZE"))
|
||||
self.rect = self.image.get_rect()
|
||||
self.rect.topleft = (x * TILE_SIZE, y * TILE_SIZE)
|
||||
|
||||
def draw(self, surface):
|
||||
@ -22,8 +31,10 @@ class Tile(pygame.sprite.Sprite):
|
||||
|
||||
def set_type(self, type):
|
||||
self.type = type
|
||||
if self.type == 'grass':
|
||||
self.image = pygame.image.load("images/grass.png").convert()
|
||||
# if self.type == 'grass':
|
||||
# self.image = pygame.image.load("images/grass.png").convert()
|
||||
self.image = pygame.image.load("images/grass.png").convert()
|
||||
|
||||
# you can set TILE_SIZE in the .env file to adjust the window size
|
||||
load_dotenv(find_dotenv())
|
||||
TILE_SIZE = int(os.getenv("TILE_SIZE"))
|
||||
|
@ -1,6 +1,8 @@
|
||||
import pygame
|
||||
import os
|
||||
from dotenv import find_dotenv, load_dotenv
|
||||
from kb import ile_podlac
|
||||
from tile import Tile
|
||||
|
||||
class Tractor(pygame.sprite.Sprite):
|
||||
def __init__(self, field):
|
||||
@ -15,6 +17,8 @@ class Tractor(pygame.sprite.Sprite):
|
||||
x, y = 0, 0
|
||||
self.rect.topleft = (x, y)
|
||||
|
||||
self.water = 200
|
||||
|
||||
def draw(self, surface):
|
||||
surface.blit(self.image, self.rect)
|
||||
|
||||
@ -23,14 +27,26 @@ class Tractor(pygame.sprite.Sprite):
|
||||
load_dotenv(find_dotenv())
|
||||
TILE_SIZE = int(os.getenv("TILE_SIZE"))
|
||||
|
||||
if direction == "up":
|
||||
if direction == "up" and self.rect.y > 0:
|
||||
self.rect.y -= TILE_SIZE
|
||||
elif direction == "down":
|
||||
self.print_tile_type()
|
||||
elif direction == "down" and self.rect.y < 15 * TILE_SIZE:
|
||||
self.rect.y += TILE_SIZE
|
||||
elif direction == "left":
|
||||
self.print_tile_type()
|
||||
elif direction == "left" and self.rect.x > 0:
|
||||
self.rect.x -= TILE_SIZE
|
||||
elif direction == "right":
|
||||
self.print_tile_type()
|
||||
elif direction == "right" and self.rect.x < 15 * TILE_SIZE:
|
||||
self.rect.x += TILE_SIZE
|
||||
self.print_tile_type()
|
||||
|
||||
curent_tile = self.get_current_tile()
|
||||
water_needed = ile_podlac(curent_tile.type, curent_tile.faza)[0]['Woda']
|
||||
if self.water >= water_needed:
|
||||
print(f"watered {curent_tile.type} with {water_needed} liters\n")
|
||||
self.water -= water_needed
|
||||
else:
|
||||
print(f"{water_needed - self.water} more litres of water needed to water {curent_tile.type}\n")
|
||||
|
||||
def update(self):
|
||||
keys = pygame.key.get_pressed()
|
||||
@ -42,3 +58,21 @@ class Tractor(pygame.sprite.Sprite):
|
||||
self.move('up')
|
||||
if keys[pygame.K_DOWN]:
|
||||
self.move('down')
|
||||
|
||||
def print_tile_type(self):
|
||||
load_dotenv(find_dotenv())
|
||||
TILE_SIZE = int(os.getenv("TILE_SIZE"))
|
||||
|
||||
x = self.rect.x // TILE_SIZE
|
||||
y = self.rect.y // TILE_SIZE
|
||||
tile_type = self.field.tiles.sprites()[y * 16 + x].type
|
||||
print(f"The tractor is on a {tile_type} tile.")
|
||||
|
||||
def get_current_tile(self):
|
||||
load_dotenv(find_dotenv())
|
||||
TILE_SIZE = int(os.getenv("TILE_SIZE"))
|
||||
|
||||
x = self.rect.x // TILE_SIZE
|
||||
y = self.rect.y // TILE_SIZE
|
||||
current_tile = self.field.tiles.sprites()[y * 16 + x]
|
||||
return current_tile
|
||||
|
Loading…
Reference in New Issue
Block a user