formatiert

This commit is contained in:
Michael S. 2024-02-23 17:31:58 +01:00
parent 1971b72419
commit e3078e876f

29
main.py
View file

@ -3,7 +3,10 @@ import pygame
import pygame.gfxdraw import pygame.gfxdraw
import copy import copy
import random import random
pygame.init() pygame.init()
## funktionen ## funktionen
def get_debug_text(): def get_debug_text():
def text(text, line_counter): def text(text, line_counter):
@ -16,30 +19,40 @@ def get_debug_text():
text(f"{str(a)} = {str(globalvars[a])}", line_counter) text(f"{str(a)} = {str(globalvars[a])}", line_counter)
line_counter += 1 line_counter += 1
def centered_text(text=str, pos=tuple, color=tuple): def centered_text(text=str, pos=tuple, color=tuple):
text = default_font.render(str(text), True, color, (255, 255, 255)) text = default_font.render(str(text), True, color, (255, 255, 255))
screen.blit(text, (pos[0] - text.get_width() / 2, pos[1])) screen.blit(text, (pos[0] - text.get_width() / 2, pos[1]))
def draw_feld(feld, color_key, block_size): def draw_feld(feld, color_key, block_size):
# print(feld) # print(feld)
for a in range(len(feld[0])): for a in range(len(feld[0])):
for b in range(len(feld)): for b in range(len(feld)):
if feld[b][a] != " ": if feld[b][a] != " ":
pygame.draw.rect(screen,color_key[feld[b][a]], pygame.draw.rect(
(a*block_size, screen,
b*block_size, color_key[feld[b][a]],
block_size, (a * block_size, b * block_size, block_size, block_size),
block_size)) )
def get_block_size(): def get_block_size():
return 20, 20 return 20, 20
def get_meightboars(feld, position): def get_meightboars(feld, position):
nachtbaren = [] nachtbaren = []
return nachtbaren return nachtbaren
def save_list(liste, index1, index2): def save_list(liste, index1, index2):
if index2 > len(liste[0]) and index1 > len(liste): if index2 > len(liste[0]) and index1 > len(liste):
return liste[index1][index2] return liste[index1][index2]
else: else:
return "a" return "a"
def verarbeite_feld(feld): def verarbeite_feld(feld):
feld2 = copy.deepcopy(feld) feld2 = copy.deepcopy(feld)
for y in range(len(feld)): for y in range(len(feld)):
@ -64,6 +77,7 @@ def verarbeite_feld(feld):
feld2[(y + 1) % feldy][(x + direction) % feldx] = feld[y][x] feld2[(y + 1) % feldy][(x + direction) % feldx] = feld[y][x]
return feld2 return feld2
def make_feld(size, mode): def make_feld(size, mode):
x = screensize[0] // size x = screensize[0] // size
y = screensize[1] // size y = screensize[1] // size
@ -72,6 +86,8 @@ def make_feld(size,mode):
for x in range(x): for x in range(x):
feld[y - 1][x] = "#" feld[y - 1][x] = "#"
return feld, x, y return feld, x, y
## klassen ## klassen
@ -144,8 +160,7 @@ if __name__ == "__main__":
if b == 0: if b == 0:
wechselfarbe = "r" wechselfarbe = "r"
acolor = r, g, b acolor = r, g, b
color_key = {"#":(100,100,100), color_key = {"#": (100, 100, 100), "a": acolor}
"a":acolor}
draw_feld(feld, color_key, pixelsize) draw_feld(feld, color_key, pixelsize)
mx, my = pygame.mouse.get_pos() mx, my = pygame.mouse.get_pos()
mousepressed = pygame.mouse.get_pressed()[0] mousepressed = pygame.mouse.get_pressed()[0]