import pygame import sys import random from Tractor import Tractor class Game(object): def __init__(self): # Config self.max_tps = 2.0 self.res = (720, 720) self.fields = [] self.randomize_field() # Initialization pygame.init() self.screen = pygame.display.set_mode(self.res) pygame.display.set_caption('Traktorek') self.clock = pygame.time.Clock() self.dt = 0.0 self.player = Tractor(self) while True: # Handle events for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit(0) elif event.type == pygame.K_ESCAPE: sys.exit(0) # Ticking self.dt += self.clock.tick() / 1000.0 while self.dt > 1 / self.max_tps: self.tick() self.dt -= 1 / self.max_tps # Rendering self.screen.fill((0, 0, 0)) self.draw() pygame.display.flip() def tick(self): self.player.tick() def draw(self): self.screen.fill((0, 0, 0)) self.draw_field() self.draw_net() self.player.draw() pygame.display.update() def draw_net(self): color = (255, 255, 255) for i in range(1, 5): krat = int(720 / 5 * i) # linia pozioma pygame.draw.line(self.screen, color, (0, krat), (720, krat), 1) # linia pionowa pygame.draw.line(self.screen, color, (krat, 0), (krat, 720), 1) def randomize_field(self): ileDni = [] uprawaDni = [] woda = [] czyPada = [] kiedyPadalo =[] pada = random.choice([True, False]) kiedyPada = random.randrange(9) for x in range(25): temp = [] # nasiona temp.append(random.choice(["żyto", "jęczmień", "owies", "marchew", "rzodkiew", "pietruszka", "puste"])) # gleba temp.append(random.choice([True, False])) # woda temp.append(random.choice([True, False])) # ile dni temu pole bylo podlewane temp.append(random.randrange(7)) # czy ma padac temp.append(pada) # kiedy padalo temp.append(kiedyPada) # nawoz temp.append(random.choice([True, False])) # # growth rate # temp.append(random) # # cost + co ile dni nalezy podlewac dana uprawe if temp[0] == "żyto": temp.append(10) temp.append(4) elif temp[0] == "jęczmień": temp.append(12) temp.append(3) elif temp[0] == "owies": temp.append(8) temp.append(2) elif temp[0] == "marchew": temp.append(14) temp.append(5) elif temp[0] == "rzodkiew": temp.append(7) temp.append(5) elif temp[0] == "pietruszka": temp.append(6) temp.append(1) elif temp[0] == "puste": temp.append(2) temp.append(6) else: temp.append(0) self.fields.append(temp) woda.append(temp[2]) ileDni.append(temp[3]) uprawaDni.append(temp[8]) czyPada.append(temp[4]) kiedyPadalo.append(temp[5]) def draw_field(self): for x in range(25): self.screen.fill(self.color(x), (144 * (x % 5), 144 * (x // 5), 144 * (x % 5 + 1), 144 * (x // 5 + 1))) def color(self, z): if self.fields[z][0] == 'owies': return (255, 200, 55) elif self.fields[z][0] == 'jęczmień': return (170, 150, 40) elif self.fields[z][0] == 'żyto': return (100, 215, 80) elif self.fields[z][0] == 'marchew': return (224, 60, 14) elif self.fields[z][0] == 'rzodkiew': return (142, 24, 104) elif self.fields[z][0] == 'pietruszka': return (254, 247, 246) else: return (0,0,0) if __name__ == "__main__": Game()