diff --git a/Kinga/ran.py b/Kinga/ran.py deleted file mode 100644 index 57fc80f..0000000 --- a/Kinga/ran.py +++ /dev/null @@ -1,173 +0,0 @@ -import pygame -import sys -import random -from Tractor import Tractor -from Genetyczny import Gen - -# 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) - - self.gen = Gen(self) - self.sadzenie = self.gen.algorytm() - - - 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) - - def neighbours(self): - self.neighbours = list(range(25)) - self.neighbours[0] = [1, 5] - self.neighbours[4] = [3, 9] - self.neighbours[20] = [15, 21] - self.neighbours[24] = [19, 23] - for x in range(1, 4): - self.neighbours[x] = [x - 1, x + 5, x + 1] - for x in range(5, 16, 5): - self.neighbours[x] = [x - 5, x + 1, x + 5] - for x in range(9, 20, 5): - self.neighbours[x] = [x - 5, x - 1, x + 5] - for x in range(21, 24): - self.neighbours[x] = [x - 1, x - 5, x + 1] - for x in [6, 7, 8, 11, 12, 13, 16, 17, 18]: - self.neighbours[x] = [x - 5, x - 1, x + 1, x + 5] - - -if __name__ == "__main__": - Game()