Skip to content
Snippets Groups Projects
theme.py 3.45 KiB
Newer Older
  • Learn to ignore specific revisions
  • 's avatar
    committed
    import pygame, sys
    
    's avatar
    committed
    from random import randint
    
    's avatar
    committed
    import Gameplay
    
    Hameed Andy's avatar
    Hameed Andy committed
    import init
    
    's avatar
    committed
    
    
    Hameed Andy's avatar
    Hameed Andy committed
    theme = 0
    
    
    's avatar
    committed
    class Themes():
    
      ## @brief A function for running other files
      #  @details Executes another python file when this is selected, Given that the file is in same folder.
      #  @param runfilename The name of the file to be executed 
      def runfile(runfilename):
        with open(runfilename,"r") as rnf:
          exec(rnf.read())
    
      ## @brief A method to create a button
      #  @details This method will make a box on the interface
      #  @param surface The background (surface) the box should be made on
      #  @param color The color of the button to be made
      #  @param Rect The coordinate of the button with the length and width
      #  @param width The width of the sides of button
      def button(Surface, color,Rect,width):
        pygame.draw.rect(Surface, color,Rect,width)
    
      ## @brief A method to display text
      #  @details This function will print the text on the interface
      #  @param text The text to be printed
      #  @param fontStyle The font Style of the text to be displayed
      #  @param fontSize The size of the text written
      #  @param color The color of the text
      #  @param coord The coordinate at which the text should start displaying
      #  @param surface The background (surface) the text should be printed on
      def text(text,fontStyle,fontSize,color,coord,surface):
        font = pygame.font.SysFont(fontStyle,fontSize)
        text = font.render(text,True,color)
        surface.blit(text,coord)
    
    
    Hameed Andy's avatar
    Hameed Andy committed
      def custom_text(text,fontName,fontSize,color,coord,surface):
        font = pygame.font.Font(fontName,fontSize)
        text = font.render(text,True,color)
        surface.blit(text,coord)
    
    
    's avatar
    committed
      def themes(speed):
    
    Hameed Andy's avatar
    Hameed Andy committed
          lightBlue = (89,131,146)
    
    Hameed Andy's avatar
    Hameed Andy committed
          black1 = (48,47,47)
    
    Hameed Andy's avatar
    Hameed Andy committed
          white_green = (239,246,224)
          white = (255,255,255)
    
          lightR  = [220,128,128]
          lightB = [29,85,145]
    
    's avatar
    committed
          pygame.init()
          run = True
          while run:
    
    's avatar
    committed
              theme = pygame.display.set_mode((500, 500))
    
    Hameed Andy's avatar
    Hameed Andy committed
              theme.fill(white_green)
    
    's avatar
    committed
              mousepos = pygame.mouse.get_pos() #checking mouse position
              mouseclick = pygame.mouse.get_pressed()#checking mouse pressed
    
              pygame.display.set_caption("Snake 2.o")
    
    's avatar
    committed
    
    
    Hameed Andy's avatar
    Hameed Andy committed
              Themes.custom_text('Choose Your Theme',"Roboto-Light.ttf",45,[96,96,96],(70,50),theme)
    
    's avatar
    committed
    
    
    Hameed Andy's avatar
    Hameed Andy committed
              Themes.button(theme,lightBlue, [75,150,150,100], 0)
    
    Hameed Andy's avatar
    Hameed Andy committed
              Themes.custom_text('Regular',"Roboto-Light.ttf", 30,white_green,(95,180),theme)        
    
    's avatar
    committed
              if (75 <= mousepos[0] <= 75+150 and 150 <= mousepos[1] <= 150+100 ):
    
    's avatar
    committed
                  if mouseclick[0] == 1:
    
                      Gameplay.game(speed, lightB,lightR, white)
    
    's avatar
    committed
    
    
    Hameed Andy's avatar
    Hameed Andy committed
              Themes.button(theme,black1, [280,150,150,100], 0)
    
    Hameed Andy's avatar
    Hameed Andy committed
              Themes.custom_text('Dark',"Roboto-Light.ttf", 30,white,(325,180),theme)        
    
    's avatar
    committed
              if (280 <= mousepos[0] <= 280+150 and 150 <= mousepos[1] <= 150+100 ):
    
    's avatar
    committed
                  if mouseclick[0] == 1:
    
    Hameed Andy's avatar
    Hameed Andy committed
                      Gameplay.game(speed,white,[255,255,0],black1)
    
    's avatar
    committed
    
    
    Hameed Andy's avatar
    Hameed Andy committed
              Themes.button(theme,[255,255,255], [175,300,160,100], 0)
              Themes.custom_text('Random',"Roboto-Light.ttf", 30,[0, 0, 0],(200,330),theme)        
    
    's avatar
    committed
              if (180 <= mousepos[0] <= 180+160 and 315 <= mousepos[1] <= 315+100 ):
                  if mouseclick[0] == 1:
                    x = randint(0, 1)
    
                    if(x == 1): Gameplay.game(speed,lightB,lightR,white)
    
    Hameed Andy's avatar
    Hameed Andy committed
                    else: Gameplay.game(speed,white,[255,255,0],black1)
    
    's avatar
    committed
            
              pygame.display.update()
    
    's avatar
    committed