Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame, time
- # ---------------
- # initialization
- pygame.init()
- display_width = 800
- display_height = 600
- gameDisplay = pygame.display.set_mode((display_width, display_height))
- pygame.display.set_caption("Vypis souboru")
- black = (0, 0, 0)
- white = (255, 255, 255)
- red = (255, 0, 0)
- green = (0, 255, 0)
- blue = (0, 0, 255)
- light_blue = (0, 200, 255)
- clock = pygame.time.Clock()
- lines = []
- data = [[]]
- matches_played = 0
- # -----------------
- # functions
- def load_file(filename="Career_list1_e.csv"):
- global lines, matches_played
- file = open(filename, "r")
- oldstr = file.readline()
- matches_played = oldstr.replace(";", "").replace("\n", "")
- for i in file:
- temp = []
- temp = i.split(";")
- for f in temp:
- lines.append(f.replace("\n", ""))
- def load_database(no_cat):
- global lines
- id = 1
- line_id = 0
- for i in lines:
- if id%no_cat == 0:
- id = 1
- line_id = line_id + 1
- data[line_id].append(i)
- id = id + 1
- print(data)
- def print_array(array, no=1, max=2):
- text = ""
- for i in array:
- text.join(i)
- text.join(" | ")
- text = text[:-3]
- largeText = pygame.font.Font('freesansbold.ttf', 15)
- TextSurf, TextRect = text_objects(text, largeText)
- TextRect.center = ((display_width / 2), (display_height / (max + 1) * no))
- gameDisplay.blit(TextSurf, TextRect)
- pygame.display.update()
- def rects(rectx, recty, rectw, recth, color):
- pygame.draw.rect(gameDisplay, color, [rectx, recty, rectw, recth])
- def color_background(color, border=20):
- rects(border, border, display_width - (2 * border), display_height - (2 * border), color)
- def text_objects(text, font, color=black):
- textSurface = font.render(text, True, color)
- return textSurface, textSurface.get_rect()
- def message_display(text, no=1, max=2):
- largeText = pygame.font.Font('freesansbold.ttf', 15)
- TextSurf, TextRect = text_objects(text, largeText)
- TextRect.center = ((display_width / 2), (display_height / (max + 1) * no))
- gameDisplay.blit(TextSurf, TextRect)
- pygame.display.update()
- def print_file(filename):
- file1 = open(filename, "r")
- pocet = 0
- no = 0
- for i in file1:
- pocet += 1
- file1.close()
- file = open(filename, "r")
- for i in file:
- no += 1
- ii = ""
- for f in i:
- if ord(f) == 10:
- f = ""
- ii = ii + f
- message_display(ii, no, pocet)
- file.close()
- def main_function(kind=1):
- exit_var = False
- while not exit_var:
- for event in pygame.event.get():
- gameDisplay.fill(light_blue)
- color_background(white, 15)
- if event.type == pygame.QUIT:
- pygame.quit()
- quit()
- if event.type == pygame.KEYDOWN and kind == 1:
- if event.key == pygame.K_SPACE:
- print_file("file.txt")
- elif kind == 0:
- print_file("file.txt")
- time.sleep(0.2)
- pygame.display.update()
- clock.tick(60)
- def main_fun():
- exit_var = False
- while not exit_var:
- load_file()
- load_database(7)
- for event in pygame.event.get():
- gameDisplay.fill(light_blue)
- color_background(white, 15)
- if event.type == pygame.QUIT:
- pygame.quit()
- quit()
- if event.type == pygame.KEYDOWN:
- if event.key == pygame.K_SPACE:
- print_array(data[3])
- else:
- print_array(data[3])
- time.sleep(0.2)
- pygame.display.update()
- clock.tick(60)
- # 1=pouziva to spacebar, 0=pouziva to pohyb mysi
- # main_function(0)
- main_fun()
- # load_file()
- # load_database(7)
- # print_array(data)
- # pygame.quit()
- quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement