import pygame, sys
import Snake_Game

class HighScore():
  def runfile(runfilename):
    with open(runfilename,"r") as rnf:
      exec(rnf.read())

  def text(text,fontStyle,fontSize,color,coord,surface):
    font = pygame.font.SysFont(fontStyle,fontSize)
    text = font.render(text,True,color)
    surface.blit(text,coord)

  def button(Surface, color,Rect,width):
    pygame.draw.rect(Surface, color,Rect,width)

  def findHighscore():
    infile = open("highscore.txt","r")
    mylist = []
    for line in infile:
      a = line.strip()
      mylist.append(a)
    return max(mylist)

def main():
    pygame.init()
    red = [255,0,0]
    while True:
      mousepos = pygame.mouse.get_pos() #checking mouse position
      mouseclick = pygame.mouse.get_pressed()#checking mouse pressed
      highscore = pygame.display.set_mode((300, 150))
      #highscore.fill([213, 219, 219])
      pygame.display.set_caption("Highscore")

      HighScore.text('Highest Score: ' + str(HighScore.findHighscore()),"comicsansms", 30,[0, 0, 200],(10,20),highscore)

      HighScore.button(highscore,[0,0,0], [90,70,120,26], 0)
      HighScore.text('Main Menu',"times", 25,red,(90,70),highscore)
      if (90 <= mousepos[0] <= 90+120 and 70 <= mousepos[1] <= 70+27 ):
          if mouseclick[0] == 1:
              #HighScore.runfile('Snake_Game.py')
            Snake_Game.main()

      HighScore.button(highscore,[0,0,0], [125,105,45,27], 0)
      HighScore.text('Quit',"times", 25,red,(125,105),highscore)
      if (125 <= mousepos[0] <= 125+45 and 105 <= mousepos[1] <= 105+27 ):
            if mouseclick[0] == 1:
              pygame.quit()
              sys.exit()
              
      pygame.display.update()

#main()