Advertisement
Guest User

load1.1

a guest
Feb 25th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.92 KB | None | 0 0
  1. import pygame, time
  2.  
  3. # ---------------
  4. # initialization
  5.  
  6. pygame.init()
  7.  
  8. display_width = 800
  9. display_height = 600
  10.  
  11. gameDisplay = pygame.display.set_mode((display_width, display_height))
  12. pygame.display.set_caption("Vypis souboru")
  13.  
  14. black = (0, 0, 0)
  15. white = (255, 255, 255)
  16. red = (255, 0, 0)
  17. green = (0, 255, 0)
  18. blue = (0, 0, 255)
  19. light_blue = (0, 200, 255)
  20.  
  21. clock = pygame.time.Clock()
  22.  
  23. lines = []
  24. data = [[]]
  25. matches_played = 0
  26.  
  27.  
  28. # -----------------
  29. # functions
  30.  
  31. def load_file(filename="Career_list1_e.csv"):
  32.     global lines, matches_played
  33.     file = open(filename, "r")
  34.     oldstr = file.readline()
  35.     matches_played = oldstr.replace(";", "").replace("\n", "")
  36.     for i in file:
  37.         temp = []
  38.         temp = i.split(";")
  39.         for f in temp:
  40.             lines.append(f.replace("\n", ""))
  41.  
  42.  
  43. def load_database(no_cat):
  44.     global lines
  45.     id = 1
  46.     line_id = 0
  47.     for i in lines:
  48.         if id%no_cat == 0:
  49.             id = 1
  50.             line_id = line_id + 1
  51.         data[line_id].append(i)
  52.         id = id + 1
  53.     print(data)
  54.  
  55. def print_array(array, no=1, max=2):
  56.     text = ""
  57.     for i in array:
  58.         text.join(i)
  59.         text.join(" | ")
  60.     text = text[:-3]
  61.     largeText = pygame.font.Font('freesansbold.ttf', 15)
  62.     TextSurf, TextRect = text_objects(text, largeText)
  63.     TextRect.center = ((display_width / 2), (display_height / (max + 1) * no))
  64.     gameDisplay.blit(TextSurf, TextRect)
  65.     pygame.display.update()
  66.  
  67.  
  68.  
  69. def rects(rectx, recty, rectw, recth, color):
  70.     pygame.draw.rect(gameDisplay, color, [rectx, recty, rectw, recth])
  71.  
  72.  
  73. def color_background(color, border=20):
  74.     rects(border, border, display_width - (2 * border), display_height - (2 * border), color)
  75.  
  76.  
  77. def text_objects(text, font, color=black):
  78.     textSurface = font.render(text, True, color)
  79.     return textSurface, textSurface.get_rect()
  80.  
  81.  
  82. def message_display(text, no=1, max=2):
  83.     largeText = pygame.font.Font('freesansbold.ttf', 15)
  84.     TextSurf, TextRect = text_objects(text, largeText)
  85.     TextRect.center = ((display_width / 2), (display_height / (max + 1) * no))
  86.     gameDisplay.blit(TextSurf, TextRect)
  87.     pygame.display.update()
  88.  
  89.  
  90. def print_file(filename):
  91.     file1 = open(filename, "r")
  92.     pocet = 0
  93.     no = 0
  94.     for i in file1:
  95.         pocet += 1
  96.     file1.close()
  97.     file = open(filename, "r")
  98.     for i in file:
  99.         no += 1
  100.         ii = ""
  101.         for f in i:
  102.             if ord(f) == 10:
  103.                 f = ""
  104.             ii = ii + f
  105.         message_display(ii, no, pocet)
  106.     file.close()
  107.  
  108.  
  109. def main_function(kind=1):
  110.     exit_var = False
  111.     while not exit_var:
  112.         for event in pygame.event.get():
  113.             gameDisplay.fill(light_blue)
  114.             color_background(white, 15)
  115.             if event.type == pygame.QUIT:
  116.                 pygame.quit()
  117.                 quit()
  118.             if event.type == pygame.KEYDOWN and kind == 1:
  119.                 if event.key == pygame.K_SPACE:
  120.                     print_file("file.txt")
  121.             elif kind == 0:
  122.                 print_file("file.txt")
  123.                 time.sleep(0.2)
  124.         pygame.display.update()
  125.         clock.tick(60)
  126.  
  127. def main_fun():
  128.     exit_var = False
  129.     while not exit_var:
  130.         load_file()
  131.         load_database(7)
  132.         for event in pygame.event.get():
  133.             gameDisplay.fill(light_blue)
  134.             color_background(white, 15)
  135.             if event.type == pygame.QUIT:
  136.                 pygame.quit()
  137.                 quit()
  138.             if event.type == pygame.KEYDOWN:
  139.                 if event.key == pygame.K_SPACE:
  140.                     print_array(data[3])
  141.             else:
  142.                 print_array(data[3])
  143.                 time.sleep(0.2)
  144.         pygame.display.update()
  145.         clock.tick(60)
  146.  
  147.  
  148. # 1=pouziva to spacebar, 0=pouziva to pohyb mysi
  149. # main_function(0)
  150. main_fun()
  151. # load_file()
  152. # load_database(7)
  153. # print_array(data)
  154. # pygame.quit()
  155. quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement