inteligentny-traktor/main.py

107 lines
4.9 KiB
Python
Raw Normal View History

2023-03-16 21:29:09 +01:00
import pygame
class Field:
2023-03-30 22:30:40 +02:00
def __init__(self, fieldType, plantType, isWet, wetTime, isFertilized, fertilizedTime):
self.fieldType = fieldType # good/bad
self.plantType = plantType # wheat/carrot/cabbage
self.isWet = isWet # yes/no
self.wetTime = wetTime # number
self.isFertilized = isFertilized # yes/no
self.fertilizedTime = fertilizedTime # number
class Plant:
def __init__(self, plantType, growthState):
self.plantType = plantType # wheat/carrot/cabbage
self.growthState = growthState # growing/grown
class Fertilizer:
def __init__(self, fertilizerType):
self.fertilizerType = fertilizerType # wheat/carrot/cabbage
2023-03-16 21:29:09 +01:00
class Player:
x = 0
y = 0
rotation = 0
2023-03-30 22:30:40 +02:00
T = [[Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
[Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
[Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
[Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
[Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
[Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
[Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
[Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
[Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
[Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)]]
2023-03-16 21:29:09 +01:00
pygame.init()
player = Player()
2023-03-30 22:30:40 +02:00
screen = pygame.display.set_mode([600, 600])
2023-03-16 21:29:09 +01:00
running = True
clock = pygame.time.Clock()
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
if player.x > 0:
player.x = player.x - 1
2023-03-30 22:30:40 +02:00
if event.key == pygame.K_UP:
2023-03-16 21:29:09 +01:00
if player.y > 0:
player.y = player.y - 1
2023-03-30 22:30:40 +02:00
if event.key == pygame.K_RIGHT:
if player.x < 9:
2023-03-16 21:29:09 +01:00
player.x = player.x + 1
2023-03-30 22:30:40 +02:00
if event.key == pygame.K_DOWN:
if player.y < 9:
2023-03-16 21:29:09 +01:00
player.y = player.y + 1
2023-03-30 22:30:40 +02:00
screen.fill((175, 255, 50))
imgWheat = pygame.image.load('img/wheat.png')
imgCarrot = pygame.image.load('img/carrot.png')
imgCabbage = pygame.image.load('img/cabbage.png')
imgPlayer = pygame.image.load('img/player.png')
2023-03-16 21:29:09 +01:00
i = 0
while i < len(T):
j = 0
while j < len(T[i]):
color = (0, 0, 0)
if T[i][j].isWet == 0:
2023-03-30 22:30:40 +02:00
color = (160, 80, 40)
2023-03-16 21:29:09 +01:00
else:
2023-03-30 22:30:40 +02:00
color = (50, 25, 0)
2023-03-16 21:29:09 +01:00
pygame.draw.rect(screen, color, pygame.Rect(50 + 50 * i, 50 + 50 * j, 50, 50))
2023-03-30 22:30:40 +02:00
if T[i][j].plantType == 1:
screen.blit(imgWheat, (50 + 50 * i, 50 + 50 * j))
if T[i][j].plantType == 2:
screen.blit(imgCarrot, (50 + 50 * i, 50 + 50 * j))
if T[i][j].plantType == 3:
screen.blit(imgCabbage, (50 + 50 * i, 50 + 50 * j))
2023-03-16 21:29:09 +01:00
j = j + 1
i = i + 1
i = 0
while i < len(T)+1:
2023-03-30 22:30:40 +02:00
pygame.draw.line(screen, (0, 0, 0), (50 + i * 50, 50), (50 + i * 50, 50 + len(T) * 50), 5)
pygame.draw.line(screen, (0, 0, 0), (50, 50 + i * 50), (50 + len(T) * 50, 50 + i * 50), 5)
2023-03-16 21:29:09 +01:00
i = i + 1
2023-03-30 22:30:40 +02:00
2023-03-16 21:29:09 +01:00
tmpImg = pygame.transform.rotate(imgPlayer, player.rotation)
screen.blit(tmpImg, (55 + 50 * player.x, 55 + 50 * player.y))
pygame.display.flip()
# clock.tick(30)
# Done! Time to quit.
pygame.quit()