From 567b65ae92c5cf84c4682648b6403facc39abcea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kinga=20Jagodzi=C5=84ska?= Date: Tue, 28 Apr 2020 19:08:11 +0000 Subject: [PATCH] Zaktualizuj 'Traktorek/ran.py' --- Traktorek/ran.py | 274 ++++++++++++++++++++--------------------------- 1 file changed, 118 insertions(+), 156 deletions(-) diff --git a/Traktorek/ran.py b/Traktorek/ran.py index 0891bb7..6a9b456 100644 --- a/Traktorek/ran.py +++ b/Traktorek/ran.py @@ -1,156 +1,118 @@ -import pygame -import sys -import random -from Tractor import Tractor - -# dodać growth rate -# Dodać co jeśli pusta -# Pamiętać o zmianie algorytmu po dodaniu growth rate - - -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): - 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])) - # # growth rate - # temp.append(random) - # # cost - if temp[0] == "żyto": - temp.append(10) - elif temp[0] == "jęczmień": - temp.append(12) - elif temp[0] == "owies": - temp.append(8) - elif temp[0] == "marchew": - temp.append(14) - elif temp[0] == "rzodkiew": - temp.append(7) - elif temp[0] == "pietruszka": - temp.append(6) - elif temp[0] == "puste": - temp.append(2) - else: - temp.append(0) - - self.fields.append(temp) - - 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) - # if self.fields[z][1] == True: - # if self.fields[z][2] == True: - # return (255, 200, 55) - # elif self.fields[z][2] == False: - # return (255, 200, 100) - # elif self.fields[z][1] == False: - # if self.fields[z][2] == True: - # return (255, 170, 55) - # elif self.fields[z][2] == False: - # return (255, 170, 100) - elif self.fields[z][0] == 'jęczmień': - return (170, 150, 40) - # if self.fields[z][1] == True: - # if self.fields[z][2] == True: - # return (170, 150, 40) - # elif self.fields[z][2] == False: - # return (170, 150, 85) - # elif self.fields[z][1] == False: - # if self.fields[z][2] == True: - # return (170, 120, 40) - # elif self.fields[z][2] == False: - # return (170, 120, 85) - elif self.fields[z][0] == 'żyto': - return (100, 215, 80) - # if self.fields[z][1] == True: - # if self.fields[z][2] == True: - # return (100, 215, 80) - # elif self.fields[z][2] == False: - # return (100, 215, 125) - # elif self.fields[z][1] == False: - # if self.fields[z][2] == True: - # return (100, 185, 80) - # elif self.fields[z][2] == False: - # return (100, 185, 125) - 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() +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): + 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])) + # # growth rate + # temp.append(random) + # # cost + if temp[0] == "żyto": + temp.append(10) + elif temp[0] == "jęczmień": + temp.append(12) + elif temp[0] == "owies": + temp.append(8) + elif temp[0] == "marchew": + temp.append(14) + elif temp[0] == "rzodkiew": + temp.append(7) + elif temp[0] == "pietruszka": + temp.append(6) + elif temp[0] == "puste": + temp.append(2) + else: + temp.append(0) + + self.fields.append(temp) + + 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()